Skip to content
Snippets Groups Projects
Commit 50b17d85 authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Cleaner layout file reading: character to counter map,

Cleaning up the gui
parent 2b3692fa
No related branches found
No related tags found
1 merge request!6Draft: Resolve "Ingredient dispenser, trashcan, plate return, serving window"
Pipeline #41435 passed
......@@ -16,11 +16,6 @@ def main():
simulator.register_player(Player(player_one_name, np.array([200, 200])))
simulator.register_player(Player(player_two_name, np.array([100, 200])))
# simulator.env.counters[3].occupied_by = Tomato()
# simulator.env.counters[4].occupied_by = Tomato()
# simulator.env.counters[6].occupied_by = Plate()
# simulator.env.counters[7].occupied_by = Plate()
# TODO maybe read the player names and keyboard keys from config file?
keys1 = [
pygame.K_LEFT,
......
......@@ -16,6 +16,16 @@ from overcooked_simulator.counters import (
PlateReturn,
)
SYMBOL_TO_CHARACTER_MAP = {
"C": Counter,
"B": CuttingBoard,
"X": Trash,
"W": ServingWindow,
"T": TomatoDispenser,
"P": PlateReturn,
"E": None,
}
class Action:
"""Action class, specifies player, action type and action itself."""
......@@ -70,27 +80,10 @@ class Environment:
for character in line:
character = character.capitalize()
pos = np.array([current_x, current_y])
match character:
case "C":
counter = Counter(pos)
counters.append(counter)
case "B":
counter = CuttingBoard(pos)
counters.append(counter)
case "X":
counter = Trash(pos)
counters.append(counter)
case "W":
counter = ServingWindow(pos)
counters.append(counter)
case "T":
counter = TomatoDispenser(pos)
counters.append(counter)
case "P":
counter = PlateReturn(pos)
counters.append(counter)
case "E":
pass
counter_class = SYMBOL_TO_CHARACTER_MAP[character]
if counter_class is not None:
counter = counter_class(pos)
counters.append(counter)
current_x += self.counter_side_length
current_y += self.counter_side_length
return counters
......@@ -203,9 +196,9 @@ class Environment:
Returns: True if the player is intersecting with any object in the environment.
"""
return (
self.detect_player_collision(player)
or self.detect_collision_counters(player)
or self.detect_collision_world_bounds(player)
self.detect_player_collision(player)
or self.detect_collision_counters(player)
or self.detect_collision_world_bounds(player)
)
def detect_player_collision(self, player: Player):
......
......@@ -25,6 +25,8 @@ YELLOW = (255, 255, 0)
BACKGROUND_COLOR = GREY
BACKGROUND_LINES_COLOR = (200, 200, 200)
KNIFE_COLOR = (120, 120, 120)
PLATE_RETURN_COLOR = (170, 170, 240)
BOARD_COLOR = (239, 193, 151)
class PlayerKeyset:
......@@ -57,10 +59,10 @@ class PyGameGUI:
"""Visualisation of the overcooked environmnent and reading keyboard inputs using pygame."""
def __init__(
self,
simulator: Simulator,
player_names: list[str],
player_keys: list[pygame.key],
self,
simulator: Simulator,
player_names: list[str],
player_keys: list[pygame.key],
):
self.FPS = 60
self.simulator = simulator
......@@ -232,14 +234,12 @@ class PyGameGUI:
board_size,
board_size,
)
BOARD_COLOR = (239, 193, 151)
pygame.draw.rect(self.screen, BOARD_COLOR, board_rect)
knife_rect = pygame.Rect(counter.pos[0] + 6, counter.pos[1] - 8, 5, 20)
pygame.draw.rect(self.screen, KNIFE_COLOR, knife_rect)
if isinstance(counter, PlateReturn):
RETURN = (170, 170, 240)
size = 38
inner = pygame.Rect(
counter.pos[0] - (size / 2),
......@@ -247,7 +247,7 @@ class PyGameGUI:
size,
size,
)
pygame.draw.rect(self.screen, RETURN, inner)
pygame.draw.rect(self.screen, PLATE_RETURN_COLOR, inner)
if isinstance(counter, Trash):
pygame.draw.circle(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment