feat: Added Coffe machine which increases multiplier for gained score

This commit is contained in:
Jager72 2024-03-14 14:22:16 +01:00
parent 774bd87c63
commit 1f8798b98c
4 changed files with 41 additions and 3 deletions

2
app.py
View File

@ -1,6 +1,7 @@
import pygame
import prefs
from classes.beerKeg import BeerKeg
from classes.coffeMachine import CoffeMachine
from pygame.locals import K_w, K_s, K_a, K_d
from classes.cell import Cell
from classes.agent import Agent
@ -28,6 +29,7 @@ def initBoard():
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")
def draw_grid(window, cells):
for i in range(prefs.GRID_SIZE):

View File

@ -6,10 +6,12 @@ class Agent:
self.sprite = pygame.transform.scale(self.sprite, (prefs.CELL_SIZE, prefs.CELL_SIZE))
self.current_cell = cells[x][y]
self.moved=False
self.last_move_time=pygame.time.get_ticks()
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.cells = cells
self.score = baseScore
self.multiplier = 1
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:
@ -38,8 +40,23 @@ class Agent:
def draw(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()
# 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
self.last_draw_time = current_draw_time
def increase_score(self, amount):
self.score += amount
print("Agent score changed from {} to {}".format(self.score - amount, self.score))
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)))
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))

19
classes/coffeMachine.py Normal file
View File

@ -0,0 +1,19 @@
from classes.interactable import Interactable
import pygame
import prefs
from classes.agent import Agent
class CoffeMachine(Interactable):
def __init__(self, cell, name, sprite="sprites/CoffeeVendingMachine2.png"):
super().__init__(cell, sprite)
self.sprite = pygame.image.load(sprite).convert_alpha()
self.sprite = pygame.transform.scale(self.sprite, (prefs.CELL_SIZE, prefs.CELL_SIZE))
self.name = name
def interact(self,agent):
if not isinstance(agent, Agent):
print("Agent must be of type Agent")
return
agent.increase_multiplier(1)
print("Agent interacted with {}".format(self.name))

Binary file not shown.

After

Width:  |  Height:  |  Size: 532 B