import pygame class Agent: def __init__(self, x, y, image_path, grid_size): self.x = x self.y = y self.grid_size = grid_size self.image = pygame.image.load(image_path) self.image = pygame.transform.scale(self.image, (grid_size, grid_size)) def draw(self, screen): screen.blit(self.image, (self.x * self.grid_size, self.y * self.grid_size)) def move(self, dx, dy): self.x += dx self.y += dy def handle_event(self, event, grid_height,grid_width, animals): if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP and self.y > 0: self.move(0, -1) elif event.key == pygame.K_DOWN and self.y < grid_height - 1: self.move(0, 1) elif event.key == pygame.K_LEFT and self.x > 0: self.move(-1, 0) elif event.key == pygame.K_RIGHT and self.x < grid_width - 1: self.move(1, 0) for animal in animals: if self.x == animal.x and self.y == animal.y: if animal.feed()== 'True': animal.feed_animal() animal._feed = 0