2024-03-13 23:25:49 +01:00
|
|
|
import pygame
|
|
|
|
import prefs
|
|
|
|
class Agent:
|
2024-03-14 13:53:26 +01:00
|
|
|
def __init__(self, x, y, cells, baseScore=0):
|
|
|
|
self.sprite = pygame.image.load("sprites/BartenderNew64.png").convert_alpha()
|
2024-03-13 23:25:49 +01:00
|
|
|
self.sprite = pygame.transform.scale(self.sprite, (prefs.CELL_SIZE, prefs.CELL_SIZE))
|
|
|
|
self.current_cell = cells[x][y]
|
|
|
|
self.moved=False
|
2024-03-14 14:22:16 +01:00
|
|
|
self.last_move_time = pygame.time.get_ticks()
|
2024-03-14 13:53:26 +01:00
|
|
|
self.last_interact_time = pygame.time.get_ticks()
|
2024-03-14 14:33:51 +01:00
|
|
|
self.last_update_time = pygame.time.get_ticks()
|
2024-03-13 23:25:49 +01:00
|
|
|
self.cells = cells
|
2024-03-14 13:53:26 +01:00
|
|
|
self.score = baseScore
|
2024-03-14 14:22:16 +01:00
|
|
|
self.multiplier = 1
|
2024-03-13 23:25:49 +01:00
|
|
|
|
|
|
|
def move_up(self):
|
|
|
|
if pygame.time.get_ticks()-self.last_move_time > 125 and self.current_cell.Y > 0 and not self.cells[self.current_cell.X][self.current_cell.Y-1].blocking_movement:
|
|
|
|
self.current_cell = self.cells[self.current_cell.X][self.current_cell.Y-1]
|
|
|
|
self.moved=True
|
|
|
|
self.last_move_time=pygame.time.get_ticks()
|
|
|
|
|
|
|
|
def move_down(self):
|
|
|
|
if pygame.time.get_ticks()-self.last_move_time > 125 and self.current_cell.Y < prefs.GRID_SIZE-1 and not self.cells[self.current_cell.X][self.current_cell.Y+1].blocking_movement:
|
|
|
|
self.current_cell = self.cells[self.current_cell.X][self.current_cell.Y+1]
|
|
|
|
self.moved=True
|
|
|
|
self.last_move_time=pygame.time.get_ticks()
|
|
|
|
|
|
|
|
def move_left(self):
|
|
|
|
if pygame.time.get_ticks()-self.last_move_time > 125 and self.current_cell.X > 0 and not self.cells[self.current_cell.X-1][self.current_cell.Y].blocking_movement:
|
|
|
|
self.current_cell = self.cells[self.current_cell.X-1][self.current_cell.Y]
|
|
|
|
self.moved=True
|
|
|
|
self.last_move_time=pygame.time.get_ticks()
|
|
|
|
|
|
|
|
def move_right(self):
|
|
|
|
if pygame.time.get_ticks()-self.last_move_time > 125 and self.current_cell.X < prefs.GRID_SIZE-1 and not self.cells[self.current_cell.X+1][self.current_cell.Y].blocking_movement:
|
|
|
|
self.current_cell = self.cells[self.current_cell.X+1][self.current_cell.Y]
|
|
|
|
self.moved=True
|
|
|
|
self.last_move_time=pygame.time.get_ticks()
|
|
|
|
|
2024-03-14 14:33:51 +01:00
|
|
|
def update(self, surface):
|
2024-03-13 23:25:49 +01:00
|
|
|
surface.blit(self.sprite, (self.current_cell.X * prefs.CELL_SIZE,
|
|
|
|
self.current_cell.Y * prefs.CELL_SIZE))
|
2024-03-14 14:33:51 +01:00
|
|
|
|
|
|
|
current_update_time = pygame.time.get_ticks()
|
2024-03-14 14:22:16 +01:00
|
|
|
# różnca czasu między wyoływaniami, używa do uniezależnienia od ilości wywołań funkcji
|
2024-03-14 14:33:51 +01:00
|
|
|
delta_time = ((current_update_time - self.last_update_time)/1000)
|
|
|
|
self.increase_multiplier(-(1 / 16) * delta_time)
|
|
|
|
|
2024-03-14 14:22:16 +01:00
|
|
|
|
|
|
|
|
2024-03-14 14:33:51 +01:00
|
|
|
self.last_update_time = current_update_time
|
2024-03-14 13:53:26 +01:00
|
|
|
|
|
|
|
def increase_score(self, amount):
|
2024-03-14 14:22:16 +01:00
|
|
|
self.score += amount * round(self.multiplier,2)
|
|
|
|
print("Agent score changed from {} to {} (multiplied by {}!)".format(self.score - amount, self.score, round(self.multiplier,2)))
|
2024-03-14 13:53:26 +01:00
|
|
|
|
2024-03-14 14:22:16 +01:00
|
|
|
def increase_multiplier(self, amount):
|
|
|
|
self.multiplier += amount
|
2024-03-14 14:33:51 +01:00
|
|
|
if self.multiplier > 2:
|
|
|
|
self.multiplier = 2
|
|
|
|
print("Agent score changed from {} to {}".format(self.multiplier , self.multiplier + amount if self.multiplier + amount <= 2 else 2))
|
|
|
|
return
|
|
|
|
if self.multiplier < 1:
|
|
|
|
self.multiplier = 1
|