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