import pygame class Object: def __init__(self, agent_role, position, orientation, square_size, screen_size): self.agent_role = agent_role self.position = position self.orientation = orientation % 4 self.square_size = square_size self.screen_size = screen_size self.square_count = screen_size[0] // square_size self.image = pygame.image.load( 'src/img/{0}.png'.format(self.agent_role)) self.image = pygame.transform.scale( self.image, (self.square_size, self.square_size)) self.rect = pygame.Rect(position[0] * square_size, position[1] * square_size, square_size, square_size) def change_role(self, new_role): self.agent_role = new_role self.image = pygame.image.load('src/img/{0}.png'.format(new_role)) self.image = pygame.transform.scale( self.image, (self.square_size, self.square_size)) def get_angle(self): ''' orientation = 0 -> up\n orientation = 1 -> left\n orientation = 2 -> down\n orientation = 3 -> right\n ''' return self.orientation * 90 def collide_test(self, obj) -> bool: return False def blit(self, screen: pygame.Surface): image = pygame.transform.rotate(self.image, self.get_angle()) self.rect.x = self.position[0] * self.square_size self.rect.y = self.position[1] * self.square_size screen.blit(image, self.rect) def compare_pos(self, pos) -> bool: return self.position == pos def distance_to(self, pos) -> int: x = abs(self.position[0] - pos[0]) y = abs(self.position[1] - pos[1]) self.h = x + y return self.h def action(self, obj): pass def updateState(self, current_time): pass