Machine_learning_2023/domain/entities/cat.py

29 lines
762 B
Python
Raw Normal View History

2023-03-29 07:13:08 +02:00
import pygame
from domain.entities.entity import Entity
from domain.world import World
class Cat(Entity):
def __init__(self, x: int, y: int, world: World):
super().__init__(x, y, "CAT")
self.world = world
self.last_tick = pygame.time.get_ticks()
self.cooldown = 1000
self.velocity = 1
self.busy = False
self.direction = 0
def move(self, dx: int, dy: int):
end_x = self.x + dx
end_y = self.y + dy
if end_x > self.world.width - 1 or end_y > self.world.height - 1 or end_x < 0 or end_y < 0:
return
self.world.obstacles[self.x][self.y].remove(self)
self.x = end_x
self.y = end_y
self.world.obstacles[end_x][end_y].append(self)