fix: Minor fixes to names and debug logging

This commit is contained in:
Jager72 2024-03-14 14:33:51 +01:00
parent 1f8798b98c
commit 735867d51f
4 changed files with 22 additions and 20 deletions

12
app.py
View File

@ -22,21 +22,21 @@ def initBoard():
# Na potrzeby prezentacji tworzę sobie prostokatne sciany na które nie da się wejść
x1 = 3
y1 = 2
y1 = 6
for i in range(x1, x1+4):
for j in range(y1, y1+2):
cells[i][j].prepareTexture("sprites/wall.png")
cells[i][j].blocking_movement = True
cells[6][6].interactableItem = BeerKeg(cells[6][6], "Beer Keg")
cells[10][10].interactableItem = CoffeMachine(cells[10][10], "Coffe Machine")
cells[6][4].interactableItem = BeerKeg(cells[6][4], "Beer Keg")
cells[4][10].interactableItem = CoffeMachine(cells[4][10], "Coffe Machine")
def draw_grid(window, cells):
for i in range(prefs.GRID_SIZE):
for j in range(prefs.GRID_SIZE):
cells[i][j].draw(window)
cells[i][j].update(window)
if(cells[i][j].interactableItem):
cells[i][j].interactableItem.draw(window)
cells[i][j].interactableItem.update(window)
initBoard()
agent = Agent(prefs.SPAWN_POINT[0], prefs.SPAWN_POINT[1], cells)
@ -67,7 +67,7 @@ while running:
window.fill((255, 0, 0))
draw_grid(window, cells)
agent.draw(window)
agent.update(window)
pygame.display.update()
pygame.quit()

View File

@ -8,7 +8,7 @@ class Agent:
self.moved=False
self.last_move_time = pygame.time.get_ticks()
self.last_interact_time = pygame.time.get_ticks()
self.last_draw_time = pygame.time.get_ticks()
self.last_update_time = pygame.time.get_ticks()
self.cells = cells
self.score = baseScore
self.multiplier = 1
@ -37,20 +37,18 @@ class Agent:
self.moved=True
self.last_move_time=pygame.time.get_ticks()
def draw(self, surface):
def update(self, surface):
surface.blit(self.sprite, (self.current_cell.X * prefs.CELL_SIZE,
self.current_cell.Y * prefs.CELL_SIZE))
# TO nie powinno być tu ale trudno
current_draw_time = pygame.time.get_ticks()
current_update_time = pygame.time.get_ticks()
# różnca czasu między wyoływaniami, używa do uniezależnienia od ilości wywołań funkcji
delta_time = ((current_draw_time - self.last_draw_time)/1000)
if self.multiplier > 1:
self.multiplier = self.multiplier - (1 / 16) * delta_time
if self.multiplier < 1:
self.multiplier = 1
delta_time = ((current_update_time - self.last_update_time)/1000)
self.increase_multiplier(-(1 / 16) * delta_time)
self.last_draw_time = current_draw_time
self.last_update_time = current_update_time
def increase_score(self, amount):
self.score += amount * round(self.multiplier,2)
@ -58,5 +56,9 @@ class Agent:
def increase_multiplier(self, amount):
self.multiplier += amount
if self.multiplier > 0 : self.multiplier = 2
print("Agent score changed from {} to {}".format(self.multiplier - amount, self.multiplier))
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

View File

@ -16,7 +16,7 @@ class Cell:
preparedTexture = pygame.image.load(texture).convert_alpha()
preparedTexture = pygame.transform.scale(preparedTexture, (prefs.CELL_SIZE, prefs.CELL_SIZE))
self.texture = preparedTexture
def draw(self,window):
def update(self,window):
if(self.texture):
window.blit(self.texture, self.rect)
else:

View File

@ -7,6 +7,6 @@ class Interactable:
"""Ta metoda powinna być przysłonięta przez klasę dziedziczącą."""
raise NotImplementedError
def draw(self, surface):
def update(self, surface):
surface.blit(self.sprite, (self.cell.X * prefs.CELL_SIZE,
self.cell.Y * prefs.CELL_SIZE))