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

Added viz for tomatoes and cutting process.

parent c509030b
No related branches found
No related tags found
1 merge request!3Resolve "Interaction with objects"
overcooked_simulator/images/tomato_cut.png

16.7 KiB

import numpy as np
import pygame
from overcooked_simulator.counters import CuttingBoard
from overcooked_simulator.game_items import ProgressibleItem
from overcooked_simulator.game_items import Tomato
from overcooked_simulator.overcooked_environment import Action
from overcooked_simulator.simulation_runner import Simulator
......@@ -16,6 +18,7 @@ BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)
BACKGROUND_COLOR = GREY
BACKGROUND_LINES_COLOR = (200, 200, 200)
KNIFE_COLOR = (120, 120, 120)
class PlayerKeyset:
......@@ -160,12 +163,31 @@ class PyGameGUI:
def draw_item(self, pos, item):
"""Visualisation of an item at the specified position. On a counter or in the hands of the player."""
if isinstance(item, Tomato):
IMAGE = pygame.image.load(
"overcooked_simulator/images/tomato.png"
).convert_alpha() # or .convert_alpha()
if item.finished:
IMAGE = pygame.image.load(
"overcooked_simulator/images/tomato_cut.png"
).convert_alpha() # or .convert_alpha()
else:
IMAGE = pygame.image.load(
"overcooked_simulator/images/tomato.png"
).convert_alpha() # or .convert_alpha()
rect = IMAGE.get_rect()
rect.center = pos
self.screen.blit(IMAGE, rect)
if isinstance(item, ProgressibleItem) and not item.finished:
self.draw_progress_bar(pos, item.progressed_steps, item.steps_needed)
def draw_progress_bar(self, pos, current, needed):
if current != 0:
bar_height = self.counter_size * 0.2
progress_width = (current / needed) * self.counter_size
progress_bar = pygame.Rect(
pos[0] - (self.counter_size / 2),
pos[1] - (self.counter_size / 2) + self.counter_size - bar_height,
progress_width,
bar_height,
)
pygame.draw.rect(self.screen, GREEN, progress_bar)
def draw_counter(self, counter):
"""Visualisation of a counter at its position. If it is occupied by an item, it is also shown.
......@@ -173,6 +195,7 @@ class PyGameGUI:
Args:
counter: The counter to visualize.
"""
counter_rect_outline = pygame.Rect(
counter.pos[0] - (self.counter_size / 2),
counter.pos[1] - (self.counter_size / 2),
......@@ -181,6 +204,20 @@ class PyGameGUI:
)
pygame.draw.rect(self.screen, COUNTERCOLOR, counter_rect_outline)
if isinstance(counter, CuttingBoard):
board_size = 30
board_rect = pygame.Rect(
counter.pos[0] - (board_size / 2),
counter.pos[1] - (board_size / 2),
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 counter.occupied_by is not None:
self.draw_item(counter.pos, counter.occupied_by)
......
......@@ -77,7 +77,7 @@ def test_movement():
expected = start_pos + do_moves_number * (move_direction * player1.move_dist)
assert (
np.linalg.norm(expected - sim.env.players[player_name].pos) == 0
np.linalg.norm(expected - sim.env.players[player_name].pos) == 0
), "Should be here?"
......
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