Config for cat
This commit is contained in:
parent
e972dcfd83
commit
f5003e93fe
3
config.ini
Normal file
3
config.ini
Normal file
@ -0,0 +1,3 @@
|
||||
[APP]
|
||||
cat = False
|
||||
movment = human #(human, movment)
|
13
main.py
13
main.py
@ -1,6 +1,7 @@
|
||||
from random import randint
|
||||
|
||||
import pygame
|
||||
import configparser
|
||||
|
||||
from domain.commands.random_cat_move_command import RandomCatMoveCommand
|
||||
from domain.commands.vacuum_move_command import VacuumMoveCommand
|
||||
@ -12,7 +13,8 @@ from domain.world import World
|
||||
from view.renderer import Renderer
|
||||
|
||||
|
||||
# initial_draw(500, 10)
|
||||
config = configparser.ConfigParser()
|
||||
config.read("config.ini")
|
||||
|
||||
|
||||
class Main:
|
||||
@ -62,7 +64,8 @@ class Main:
|
||||
)
|
||||
|
||||
def update(self):
|
||||
self.commands.append(RandomCatMoveCommand(self.world, self.world.cat))
|
||||
if config.getboolean("APP", "cat"):
|
||||
self.commands.append(RandomCatMoveCommand(self.world, self.world.cat))
|
||||
for command in self.commands:
|
||||
command.run()
|
||||
self.commands.clear()
|
||||
@ -76,8 +79,10 @@ def generate_world(tiles_x: int, tiles_y: int) -> World:
|
||||
world.add_entity(Entity(temp_x, temp_y, "PEEL"))
|
||||
world.vacuum = Vacuum(1, 1)
|
||||
world.doc_station = Doc_Station(9, 8)
|
||||
world.cat = Cat(7, 8)
|
||||
world.add_entity(world.cat)
|
||||
print(config.getboolean("APP", "cat"))
|
||||
if config.getboolean("APP", "cat"):
|
||||
world.cat = Cat(7, 8)
|
||||
world.add_entity(world.cat)
|
||||
world.add_entity(Entity(2, 8, "PLANT1"))
|
||||
world.add_entity(Entity(4, 1, "PLANT1"))
|
||||
world.add_entity(Entity(3, 4, "PLANT2"))
|
||||
|
@ -1,2 +1,3 @@
|
||||
pygame
|
||||
configparser
|
||||
formaFormatting: Provider - black
|
138
view/renderer.py
138
view/renderer.py
@ -2,21 +2,24 @@ import random
|
||||
from random import randint
|
||||
|
||||
import pygame
|
||||
import configparser
|
||||
from pygame import Color
|
||||
|
||||
from domain.entities.cat import Cat
|
||||
from domain.entities.entity import Entity
|
||||
from domain.world import World
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read("config.ini")
|
||||
|
||||
|
||||
class Renderer:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
width=800,
|
||||
height=800,
|
||||
tiles_x=10,
|
||||
tiles_y=10,
|
||||
self,
|
||||
width=800,
|
||||
height=800,
|
||||
tiles_x=10,
|
||||
tiles_y=10,
|
||||
):
|
||||
self.width = width
|
||||
self.height = height
|
||||
@ -31,33 +34,66 @@ 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.font = pygame.font.SysFont("Arial", 26, bold=True)
|
||||
|
||||
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"),
|
||||
(self.tile_width, self.tile_height)),
|
||||
"PEEL": pygame.transform.scale(pygame.image.load("media/sprites/peel.webp"),
|
||||
(self.tile_width, self.tile_height)),
|
||||
"CAT_FRONT": pygame.transform.scale(pygame.image.load("media/sprites/cat/standing_front.png"),
|
||||
(self.tile_width, self.tile_height)),
|
||||
"CAT_BACK": pygame.transform.scale(pygame.image.load("media/sprites/cat/standing_back.png"),
|
||||
(self.tile_width, self.tile_height)),
|
||||
"CAT_LEFT": pygame.transform.scale(pygame.image.load("media/sprites/cat/standing_left.png"),
|
||||
(self.tile_width, self.tile_height)),
|
||||
"CAT_RIGHT": pygame.transform.scale(pygame.image.load("media/sprites/cat/standing_right.png"),
|
||||
(self.tile_width, self.tile_height)),
|
||||
"PLANT1": pygame.transform.scale(pygame.image.load("media/sprites/plants/plant1.png"),
|
||||
(self.tile_width + self.tile_width / 4, self.tile_height + self.tile_height / 4)),
|
||||
"PLANT2": pygame.transform.scale(pygame.image.load("media/sprites/plants/plant2.png"),
|
||||
(self.tile_width + self.tile_width / 4, self.tile_height + self.tile_height / 4)),
|
||||
"PLANT3": pygame.transform.scale(pygame.image.load("media/sprites/plants/plant3.png"),
|
||||
(self.tile_width + self.tile_width / 4, self.tile_height + self.tile_height / 4)),
|
||||
"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"),
|
||||
(self.tile_width, self.tile_height),
|
||||
),
|
||||
"PEEL": pygame.transform.scale(
|
||||
pygame.image.load("media/sprites/peel.webp"),
|
||||
(self.tile_width, self.tile_height),
|
||||
),
|
||||
"CAT_FRONT": pygame.transform.scale(
|
||||
pygame.image.load("media/sprites/cat/standing_front.png"),
|
||||
(self.tile_width, self.tile_height),
|
||||
),
|
||||
"CAT_BACK": pygame.transform.scale(
|
||||
pygame.image.load("media/sprites/cat/standing_back.png"),
|
||||
(self.tile_width, self.tile_height),
|
||||
),
|
||||
"CAT_LEFT": pygame.transform.scale(
|
||||
pygame.image.load("media/sprites/cat/standing_left.png"),
|
||||
(self.tile_width, self.tile_height),
|
||||
),
|
||||
"CAT_RIGHT": pygame.transform.scale(
|
||||
pygame.image.load("media/sprites/cat/standing_right.png"),
|
||||
(self.tile_width, self.tile_height),
|
||||
),
|
||||
"PLANT1": pygame.transform.scale(
|
||||
pygame.image.load("media/sprites/plants/plant1.png"),
|
||||
(
|
||||
self.tile_width + self.tile_width / 4,
|
||||
self.tile_height + self.tile_height / 4,
|
||||
),
|
||||
),
|
||||
"PLANT2": pygame.transform.scale(
|
||||
pygame.image.load("media/sprites/plants/plant2.png"),
|
||||
(
|
||||
self.tile_width + self.tile_width / 4,
|
||||
self.tile_height + self.tile_height / 4,
|
||||
),
|
||||
),
|
||||
"PLANT3": pygame.transform.scale(
|
||||
pygame.image.load("media/sprites/plants/plant3.png"),
|
||||
(
|
||||
self.tile_width + self.tile_width / 4,
|
||||
self.tile_height + self.tile_height / 4,
|
||||
),
|
||||
),
|
||||
}
|
||||
|
||||
self.cat_direction_sprite = {
|
||||
@ -80,7 +116,8 @@ class Renderer:
|
||||
self.draw_entity(entity)
|
||||
self.draw_entity(world.vacuum)
|
||||
self.draw_entity(world.doc_station)
|
||||
self.draw_entity(world.cat)
|
||||
if config.getboolean("APP", "cat"):
|
||||
self.draw_entity(world.cat)
|
||||
pygame.display.update()
|
||||
|
||||
def line(self, x_1, y_1, x_2, y_2, color=None):
|
||||
@ -88,33 +125,50 @@ class Renderer:
|
||||
|
||||
def render_board(self, color=Color("black")):
|
||||
for i in range(1, self.tiles_x):
|
||||
self.line(self.tile_width * i, 0, self.tile_width * i, self.height, color=color)
|
||||
self.line(
|
||||
self.tile_width * i, 0, self.tile_width * i, self.height, color=color
|
||||
)
|
||||
|
||||
for i in range(1, self.tiles_y):
|
||||
self.line(0, self.tile_height * i, self.width, self.tile_height * i, color=color)
|
||||
self.line(
|
||||
0, self.tile_height * i, self.width, self.tile_height * i, color=color
|
||||
)
|
||||
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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):
|
||||
self.screen.blit(
|
||||
self.sprites[sprite_name],
|
||||
(x * self.tile_width, y * self.tile_height)
|
||||
self.sprites[sprite_name], (x * self.tile_width, y * self.tile_height)
|
||||
)
|
||||
|
||||
def fill_grid_with_sprite(self, sprite):
|
||||
@ -123,4 +177,4 @@ class Renderer:
|
||||
self.draw_sprite(tile_x, tile_y, sprite)
|
||||
|
||||
def render_floor(self):
|
||||
self.fill_grid_with_sprite("TILE")
|
||||
self.fill_grid_with_sprite("TILE")
|
||||
|
Loading…
Reference in New Issue
Block a user