Added the cleaning ability to vacuum and container_filling status now is visible.
This commit is contained in:
parent
2929495348
commit
3b761e41ab
@ -30,5 +30,9 @@ class VacuumMoveCommand(Command):
|
||||
if self.world.is_obstacle_at(end_x, end_y):
|
||||
return
|
||||
|
||||
if self.world.is_garbage_at(end_x, end_y):
|
||||
self.vacuum.increase_container_filling()
|
||||
self.world.dust[end_x][end_y].pop()
|
||||
|
||||
self.vacuum.x = end_x
|
||||
self.vacuum.y = end_y
|
||||
|
@ -9,4 +9,7 @@ class Vacuum(Entity):
|
||||
self.cleaning_detergent = 100
|
||||
self.container_filling = 0
|
||||
|
||||
def increase_container_filling(self) -> None:
|
||||
self.container_filling += 10
|
||||
|
||||
# TODO VACUUM: add more properties
|
||||
|
@ -2,7 +2,7 @@ from domain.entities.entity import Entity
|
||||
|
||||
|
||||
class World:
|
||||
def __init__(self, width: int, height: int):
|
||||
def __init__(self, width: int, height: int) -> object:
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.dust = [[[] for j in range(height)] for i in range(width)]
|
||||
@ -24,3 +24,6 @@ class World:
|
||||
|
||||
def is_obstacle_at(self, x: int, y: int) -> bool:
|
||||
return bool(self.obstacles[x][y])
|
||||
|
||||
def is_garbage_at(self, x: int, y: int) -> bool:
|
||||
return bool(self.dust[x][y])
|
@ -31,6 +31,7 @@ class Renderer:
|
||||
|
||||
pygame.display.set_caption("AI Vacuum Cleaner")
|
||||
self.screen = pygame.display.set_mode((self.width, self.height))
|
||||
self.font = pygame.font.SysFont('Arial', 26, bold=True)
|
||||
|
||||
self.sprites = {
|
||||
"VACUUM": pygame.transform.scale(pygame.image.load("media/sprites/vacuum.png"),
|
||||
@ -92,10 +93,17 @@ class Renderer:
|
||||
def draw_entity(self, entity: Entity):
|
||||
sprite = self.sprites.get(entity.type, None)
|
||||
draw_pos = (entity.x * self.tile_width, entity.y * self.tile_height)
|
||||
if "PEEL" in entity.type:
|
||||
draw_pos = ((entity.x - 0.1) * self.tile_width, (entity.y - 0.25) * self.tile_height)
|
||||
if "PLANT" in entity.type:
|
||||
draw_pos = ((entity.x - 0.1) * self.tile_width, (entity.y - 0.25) * self.tile_height)
|
||||
if "CAT" in entity.type and isinstance(entity, Cat):
|
||||
sprite = self.cat_direction_sprite[entity.direction]
|
||||
if "VACUUM" in entity.type:
|
||||
# Add text displaying container filling level
|
||||
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)
|
||||
self.screen.blit(sprite, draw_pos)
|
||||
|
||||
def draw_sprite(self, x: int, y: int, sprite_name: str):
|
||||
|
Loading…
Reference in New Issue
Block a user