feat: Added Coffe machine which increases multiplier for gained score
This commit is contained in:
parent
774bd87c63
commit
1f8798b98c
2
app.py
2
app.py
@ -1,6 +1,7 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import prefs
|
import prefs
|
||||||
from classes.beerKeg import BeerKeg
|
from classes.beerKeg import BeerKeg
|
||||||
|
from classes.coffeMachine import CoffeMachine
|
||||||
from pygame.locals import K_w, K_s, K_a, K_d
|
from pygame.locals import K_w, K_s, K_a, K_d
|
||||||
from classes.cell import Cell
|
from classes.cell import Cell
|
||||||
from classes.agent import Agent
|
from classes.agent import Agent
|
||||||
@ -28,6 +29,7 @@ def initBoard():
|
|||||||
cells[i][j].blocking_movement = True
|
cells[i][j].blocking_movement = True
|
||||||
|
|
||||||
cells[6][6].interactableItem = BeerKeg(cells[6][6], "Beer Keg")
|
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):
|
def draw_grid(window, cells):
|
||||||
for i in range(prefs.GRID_SIZE):
|
for i in range(prefs.GRID_SIZE):
|
||||||
|
@ -8,8 +8,10 @@ class Agent:
|
|||||||
self.moved=False
|
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_interact_time = pygame.time.get_ticks()
|
||||||
|
self.last_draw_time = pygame.time.get_ticks()
|
||||||
self.cells = cells
|
self.cells = cells
|
||||||
self.score = baseScore
|
self.score = baseScore
|
||||||
|
self.multiplier = 1
|
||||||
|
|
||||||
def move_up(self):
|
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:
|
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):
|
def draw(self, surface):
|
||||||
surface.blit(self.sprite, (self.current_cell.X * prefs.CELL_SIZE,
|
surface.blit(self.sprite, (self.current_cell.X * prefs.CELL_SIZE,
|
||||||
self.current_cell.Y * 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):
|
def increase_score(self, amount):
|
||||||
self.score += amount
|
self.score += amount * round(self.multiplier,2)
|
||||||
print("Agent score changed from {} to {}".format(self.score - amount, self.score))
|
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
19
classes/coffeMachine.py
Normal 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))
|
BIN
sprites/CoffeeVendingMachine2.png
Normal file
BIN
sprites/CoffeeVendingMachine2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 532 B |
Loading…
Reference in New Issue
Block a user