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

Added plate which can hold a tomato.

parent f74fee07
No related branches found
No related tags found
No related merge requests found
Pipeline #41423 passed
......@@ -46,6 +46,8 @@ class Counter:
"""
if self.occupied_by is None:
self.occupied_by = item
elif self.occupied_by.can_combine(item):
self.occupied_by.combine(item)
def interact_start(self):
"""Starts an interaction by the player. Nothing happens for the standard counter."""
......
......@@ -3,6 +3,31 @@ class HoldableItem:
pass
def can_combine(self, other):
return False
def combine(self, other):
pass
class Plate(HoldableItem):
def __init__(self):
self.clean = True
self.holds = None
super().__init__()
def can_combine(self, other):
if self.holds is None:
if isinstance(other, HoldableItem):
return True
def combine(self, other):
self.holds = other
def __repr__(self):
return f"Plate({self.holds})"
class ProgressibleItem(HoldableItem):
"""Class for items which need to be processed (cut, cooked, ...)"""
......@@ -37,5 +62,8 @@ class CuttableItem(ProgressibleItem):
class Tomato(CuttableItem):
"""Item class representing a tomato. Can be cut on the cutting board"""
def can_combine(self, other):
return False
def __init__(self):
super().__init__(steps_needed=1500)
......@@ -4,7 +4,7 @@ from pathlib import Path
import numpy as np
import pygame
from overcooked_simulator.game_items import Tomato
from overcooked_simulator.game_items import Tomato, Plate
from overcooked_simulator.player import Player
from overcooked_simulator.pygame_gui.pygame_gui import PyGameGUI
from overcooked_simulator.simulation_runner import Simulator
......@@ -19,6 +19,8 @@ def main():
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 = [
......
......@@ -183,9 +183,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):
......
......@@ -79,6 +79,10 @@ class Player:
counter.drop_off(self.holding)
self.holding = None
elif self.holding.can_combine(counter.occupied_by):
returned_by_counter = counter.pick_up()
self.holding.combine(returned_by_counter)
def perform_interact_hold_start(self, counter: Counter):
"""Starts an interaction with the counter. Should be called for a
keydown event, for holding down a key on the keyboard.
......
......@@ -2,7 +2,7 @@ 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 ProgressibleItem, Plate
from overcooked_simulator.game_items import Tomato
from overcooked_simulator.overcooked_environment import Action
from overcooked_simulator.simulation_runner import Simulator
......@@ -177,6 +177,17 @@ class PyGameGUI:
rect.center = pos
self.screen.blit(image, rect)
if isinstance(item, Plate):
image = pygame.image.load(
"overcooked_simulator/pygame_gui/images/plate.png"
).convert_alpha() # or .convert_alpha()
rect = image.get_rect()
rect.center = pos
self.screen.blit(image, rect)
if item.holds is not None:
self.draw_item(pos, item.holds)
if isinstance(item, ProgressibleItem) and not item.finished:
self.draw_progress_bar(pos, item.progressed_steps, item.steps_needed)
......
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