From 8ef3da8df0615920fd5fc48f5d02392b5fc5afe5 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 13 Apr 2023 19:04:57 +0200 Subject: [PATCH] Added the Vacuum Doc Station, which can refresh vacuum container_filling level + add sprite of Doc Station + display Doc Station on screen --- domain/commands/vacuum_move_command.py | 3 +++ domain/entities/vacuum.py | 5 ++++- domain/world.py | 8 +++++++- main.py | 2 ++ view/renderer.py | 5 +++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/domain/commands/vacuum_move_command.py b/domain/commands/vacuum_move_command.py index 6138e9b..2248b26 100644 --- a/domain/commands/vacuum_move_command.py +++ b/domain/commands/vacuum_move_command.py @@ -34,5 +34,8 @@ class VacuumMoveCommand(Command): self.vacuum.increase_container_filling() self.world.dust[end_x][end_y].pop() + if self.world.is_docking_station_at(end_x, end_y): + self.vacuum.dump_trash() + self.vacuum.x = end_x self.vacuum.y = end_y diff --git a/domain/entities/vacuum.py b/domain/entities/vacuum.py index 4a6e919..3d90409 100644 --- a/domain/entities/vacuum.py +++ b/domain/entities/vacuum.py @@ -12,4 +12,7 @@ class Vacuum(Entity): def increase_container_filling(self) -> None: self.container_filling += 10 - # TODO VACUUM: add more properties + def dump_trash(self) -> None: + self.container_filling = 0 + + # TODO VACUUM: add more properties diff --git a/domain/world.py b/domain/world.py index 7ea72a4..d2b3f02 100644 --- a/domain/world.py +++ b/domain/world.py @@ -10,12 +10,15 @@ class World: self.vacuum = None self.cat = None + self.doc_station = None def add_entity(self, entity: Entity): if entity.type == "PEEL": self.dust[entity.x][entity.y].append(entity) elif entity.type == "VACUUM": self.vacuum = entity + elif entity.type == "DOC_STATION": + self.doc_station = entity elif entity.type == "CAT": self.cat = entity self.obstacles[entity.x][entity.y].append(entity) @@ -26,4 +29,7 @@ class World: return bool(self.obstacles[x][y]) def is_garbage_at(self, x: int, y: int) -> bool: - return bool(self.dust[x][y]) \ No newline at end of file + return bool(self.dust[x][y]) + + def is_docking_station_at(self, x: int, y: int) -> bool: + return bool(self.doc_station.x == x and self.doc_station.y == y) diff --git a/main.py b/main.py index 52690b9..e9ad34d 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ from domain.commands.vacuum_move_command import VacuumMoveCommand from domain.entities.cat import Cat from domain.entities.entity import Entity from domain.entities.vacuum import Vacuum +from domain.entities.docking_station import Doc_Station from domain.world import World from view.renderer import Renderer @@ -75,6 +76,7 @@ def generate_world(tiles_x: int, tiles_y: int) -> World: temp_y = randint(0, tiles_y - 1) world.add_entity(Entity(temp_x, temp_y, "PEEL")) world.vacuum = Vacuum(1, 1) + world.doc_station = Doc_Station(9, 9) world.cat = Cat(7, 8) world.add_entity(world.cat) world.add_entity(Entity(2, 8, "PLANT1")) diff --git a/view/renderer.py b/view/renderer.py index 5376a3d..ab3d8de 100644 --- a/view/renderer.py +++ b/view/renderer.py @@ -36,6 +36,8 @@ class Renderer: self.sprites = { "VACUUM": pygame.transform.scale(pygame.image.load("media/sprites/vacuum.png"), (self.tile_width, self.tile_height)), + "DOC_STATION": pygame.transform.scale(pygame.image.load("media/sprites/docking_station.png"), + (self.tile_width, self.tile_height)), "WALL": pygame.transform.scale(pygame.image.load("media/sprites/wall.png"), (self.tile_width, self.tile_height)), "TILE": pygame.transform.scale(pygame.image.load("media/sprites/tile_cropped.jpeg"), @@ -77,6 +79,7 @@ class Renderer: for entity in world.obstacles[x][y]: self.draw_entity(entity) self.draw_entity(world.vacuum) + self.draw_entity(world.doc_station) self.draw_entity(world.cat) pygame.display.update() @@ -104,6 +107,8 @@ class Renderer: text_surface = self.font.render(f"Filling: {entity.container_filling}%", True, Color("black")) text_pos = (draw_pos[0] + self.tile_width / 2 - text_surface.get_width() / 2, draw_pos[1] + self.tile_height) self.screen.blit(text_surface, text_pos) + if "DOC_STATION" in entity.type: + draw_pos = ((entity.x - 0.1) * self.tile_width, (entity.y - 0.25) * self.tile_height) self.screen.blit(sprite, draw_pos) def draw_sprite(self, x: int, y: int, sprite_name: str):