from random import randint import pygame from Interface.vacuum_render import initial_draw from domain.entities.cat import Cat from domain.entities.entity import Entity from domain.entities.vacuum import Vacuum from domain.world import World from view.renderer import Renderer # initial_draw(500, 10) class Main: def __init__(self): tiles_x = 10 tiles_y = 10 self.renderer = Renderer(800, 800, tiles_x, tiles_y) self.world = World(tiles_x, tiles_y) for _ in range(10): temp_x = randint(0, tiles_x - 1) temp_y = randint(0, tiles_y - 1) self.world.dust[temp_x][temp_y].append(Entity(temp_x, temp_y, "PEEL")) self.world.vacuum = Vacuum(1, 1, self.world) self.world.cat = Cat(7, 8, self.world) self.world.obstacles[7][8].append(self.world.cat) self.world.obstacles[2][8].append(Entity(2, 8, "PLANT1")) self.world.obstacles[4][1].append(Entity(4, 1, "PLANT1")) self.world.obstacles[3][4].append(Entity(3, 4, "PLANT2")) self.world.obstacles[8][8].append(Entity(8, 8, "PLANT2")) self.world.obstacles[9][3].append(Entity(9, 3, "PLANT3")) self.clock = pygame.time.Clock() self.running = True self.fps = 60 def run(self): while self.running: self.process_input() self.update() self.renderer.render(self.world) self.clock.tick(self.fps) pygame.quit() def process_input(self): for event in pygame.event.get(): if event.type == pygame.QUIT: self.running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: self.world.vacuum.move(-1, 0) if event.key == pygame.K_RIGHT: self.world.vacuum.move(1, 0) if event.key == pygame.K_UP: self.world.vacuum.move(0, -1) if event.key == pygame.K_DOWN: self.world.vacuum.move(0, 1) def update(self): now = pygame.time.get_ticks() # region cat random movement cat = self.world.cat if now - cat.last_tick >= cat.cooldown: if not cat.busy: while True: cat.direction = randint(0, 3) if not ((cat.direction == 0 and cat.y == 0) or (cat.direction == 1 and cat.x == self.world.width - 1) or (cat.direction == 2 and cat.y == self.world.height - 1) or (cat.direction == 3 and cat.x == 0)): break if cat.direction == 0: # up if cat.busy: cat.move(0, - 1) cat.busy = not cat.busy if cat.direction == 1: # right if cat.busy: cat.move(1, 0) cat.busy = not cat.busy if cat.direction == 2: # down if cat.busy: cat.move(0, 1) cat.busy = not cat.busy if cat.direction == 3: # left if cat.busy: cat.move(-1, 0) cat.busy = not cat.busy cat.last_tick = pygame.time.get_ticks() if __name__ == "__main__": app = Main() app.run()