diff --git a/overcooked_simulator/game_content/item_info.yaml b/overcooked_simulator/game_content/item_info.yaml index 568929c1a1b8fc0504a30f401c488b139e962514..8f54e8e02ea3f33d4898f5ea26b013400dd0becf 100644 --- a/overcooked_simulator/game_content/item_info.yaml +++ b/overcooked_simulator/game_content/item_info.yaml @@ -1,18 +1,15 @@ Tomato: type: Ingredient - needs: Tomato is_cuttable: True steps_needed: 500 Lettuce: type: Ingredient - needs: Lettuce is_cuttable: True steps_needed: 500 RawPatty: type: Ingredient - needs: RawSteak Burger: type: Meal @@ -27,7 +24,7 @@ TomatoSoup: type: Meal finished_progress_name: TomatoSoup steps_needed: 500 - needs: [ Tomato, Tomato, Tomato ] + needs: [ Tomato, Tomato, Tomato , Tomato, Tomato, Tomato, Tomato, Tomato, Tomato, Tomato, Tomato , Tomato, Tomato, Tomato, Tomato, Tomato, Tomato, Tomato, Tomato , Tomato, Tomato, Tomato, Tomato, Tomato, Tomato ] equipment: Pot Plate: diff --git a/overcooked_simulator/main.py b/overcooked_simulator/main.py index d3cca5d832a9093259d30acadff4e0923ead2cc7..6b1de7e3fe88970d4181d3c23d7c568a17b15948 100644 --- a/overcooked_simulator/main.py +++ b/overcooked_simulator/main.py @@ -12,7 +12,7 @@ def main(): simulator = Simulator(ROOT_DIR / "game_content" / "layouts" / "basic.layout", 600) # simulator.register_player(Player(player_one_name, np.array([350.0, 200.0]))) # simulator.register_player(Player(player_two_name, np.array([100.0, 200.0]))) - number_player = 90 + number_player = 2 for i in range(number_player): simulator.register_player(Player(f"p{i}")) diff --git a/overcooked_simulator/pygame_gui/pygame_gui.py b/overcooked_simulator/pygame_gui/pygame_gui.py index e72c4b40382af1c39fec03eb0126e617dcd344f2..01999b3ea94fa90d553c3c20e9cd30235b0293b4 100644 --- a/overcooked_simulator/pygame_gui/pygame_gui.py +++ b/overcooked_simulator/pygame_gui/pygame_gui.py @@ -23,6 +23,25 @@ PLAYER_DEBUG_VIZ = True SHOW_INTERACTION_RANGE = False +def create_polygon(n, length): + if n == 0: + return np.array([0, 0]) + + vector = np.array([0, length]) + angle = (2 * np.pi) / n + + rot_matrix = np.array( + [[np.cos(angle), -np.sin(angle)], [np.sin(angle), np.cos(angle)]] + ) + + vecs = [vector] + for i in range(n - 1): + vector = np.dot(rot_matrix, vector) + vecs.append(vector) + + return vecs + + class PlayerKeySet: """Set of keyboard keys for controlling a player. First four keys are for movement. Order: Down, Up, Left, Right. @@ -217,7 +236,7 @@ class PyGameGUI: holding_item_pos = player.pos + (20 * player.facing_direction) self.draw_item(holding_item_pos, player.holding) - def draw_thing(self, pos: npt.NDArray[float], parts: list[dict[str]]): + def draw_thing(self, pos: npt.NDArray[float], parts: list[dict[str]], scale=1.0): """Draws an item, based on its visual parts specified in the visualization config. Args: @@ -232,7 +251,7 @@ class PyGameGUI: ).convert_alpha() size = parts[0]["size"] - image = pygame.transform.scale(image, (size, size)) + image = pygame.transform.scale(image, (size * scale, size * scale)) rect = image.get_rect() rect.center = pos @@ -266,7 +285,7 @@ class PyGameGUI: else: pygame.draw.circle(self.screen, color, pos, radius) - def draw_item(self, pos: npt.NDArray[float], item: Item): + def draw_item(self, pos: npt.NDArray[float], item: Item, scale=1.0): """Visualization of an item at the specified position. On a counter or in the hands of the player. The visual composition of the item is read in from visualization.yaml file, where it is specified as different parts to be drawn. @@ -278,7 +297,9 @@ class PyGameGUI: if not isinstance(item, Meal): if item.name in self.visualization_config: - self.draw_thing(pos, self.visualization_config[item.name]["parts"]) + self.draw_thing( + pos, self.visualization_config[item.name]["parts"], scale=scale + ) if isinstance(item, ProgressibleItem) and not item.finished: self.draw_progress_bar(pos, item.progressed_steps, item.steps_needed) @@ -300,22 +321,23 @@ class PyGameGUI: ).convert_alpha() size = self.visualization_config[item.name]["parts"][0]["size"] - image = pygame.transform.scale(image, (size, size)) + image = pygame.transform.scale( + image, (size * scale, size * scale) + ) rect = image.get_rect() rect.center = pos self.screen.blit(image, rect) elif item.parts: - match len(item.parts): - case 1: - pygame.draw.circle(self.screen, colors["red"], pos, 4) - case 2: - pygame.draw.circle(self.screen, colors["red"], pos, 8) - case 3: - pygame.draw.circle(self.screen, colors["red"], pos, 12) + triangle_offsets = create_polygon(len(item.parts), length=25) + print(triangle_offsets) + for idx, item in enumerate(item.parts): + self.draw_item(pos + triangle_offsets[idx], item, scale=0.6) + else: - for i, o in enumerate(item.parts): - self.draw_item(np.abs([pos[0], pos[1] - (i * 5)]), o) + for idx, o in enumerate(item.parts): + triangle_offsets = create_polygon(len(item.parts), length=25) + self.draw_item(pos + triangle_offsets[idx], o, scale=0.6) def draw_progress_bar(self, pos, current, needed): """Visualize progress of progressing item as a green bar under the item."""