2023-05-05 02:56:22 +02:00
|
|
|
import pygame
|
|
|
|
|
|
|
|
|
|
|
|
class Object:
|
2023-05-14 14:23:37 +02:00
|
|
|
def __init__(self, agent_role, position, orientation, square_size, screen_size):
|
2023-05-05 02:56:22 +02:00
|
|
|
self.agent_role = agent_role
|
|
|
|
self.position = position
|
|
|
|
self.orientation = orientation % 4
|
|
|
|
self.square_size = square_size
|
2023-05-14 14:23:37 +02:00
|
|
|
self.screen_size = screen_size
|
|
|
|
self.square_count = screen_size[0] // square_size
|
2023-05-05 02:56:22 +02:00
|
|
|
|
|
|
|
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)
|
2023-05-14 14:23:37 +02:00
|
|
|
|
|
|
|
def compare_pos(self, pos) -> bool:
|
|
|
|
return self.position == pos
|
2023-05-26 03:02:16 +02:00
|
|
|
|
|
|
|
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
|
2023-06-01 17:45:01 +02:00
|
|
|
|
|
|
|
def updateState(self, current_time):
|
|
|
|
pass
|