feat: agent rotates now

This commit is contained in:
MlodyJacky 2024-04-20 11:05:31 +02:00
parent c90ebb0aee
commit c088f1104e
5 changed files with 42 additions and 3 deletions

10
app.py
View File

@ -3,7 +3,7 @@ import prefs
from classes.beerKeg import BeerKeg
from classes.coffeMachine import CoffeMachine
from classes.table import Table
from pygame.locals import K_w, K_s, K_a, K_d
from pygame.locals import K_w, K_s, K_a, K_d, K_q, K_e
from classes.cell import Cell
from classes.agent import Agent
from collections import deque
@ -57,7 +57,7 @@ agent = Agent(prefs.SPAWN_POINT[0], prefs.SPAWN_POINT[1], cells)
#Wpisujemy miejsce w ktorym znajduje sie agent i miejsce docelowe do funkcji znajdujacej najkrotsza sciezke
start_cell = cells[5][5]
target_cell = cells[9][11]
target_cell = cells[5][5]
shortest_path = agent.bfs(start_cell, target_cell, cells)
if shortest_path:
@ -96,6 +96,12 @@ while running:
agent.move_right()
if not any([keys[K_w], keys[K_s], keys[K_a], keys[K_d]]):
agent.moved = False
if keys[K_q]:
agent.rotate_left()
if keys[K_e]:
agent.rotate_right()
if pygame.key.get_pressed()[pygame.K_e]:
if agent.current_cell.interactableItem and pygame.time.get_ticks() - agent.last_interact_time > 500:
agent.last_interact_time = pygame.time.get_ticks()

View File

@ -13,6 +13,14 @@ class Agent:
self.cells = cells
self.score = baseScore
self.multiplier = 1
self.direction = 0
self.textures = [
pygame.image.load("sprites/BartenderNew64.png").convert_alpha(),
pygame.image.load("sprites/AgentLewo.png").convert_alpha(),
pygame.image.load("sprites/AgentTyl.png").convert_alpha(),
pygame.image.load("sprites/AgentPrawo.png").convert_alpha()
]
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:
@ -126,4 +134,29 @@ class Agent:
def sciezkaAgenta(self, agent, path):
x,y = self.pop_first_coordinates(path)
if x is not None and y is not None:
agent.moveto(x,y)
agent.moveto(x,y)
def rotate_left(self):
if pygame.time.get_ticks()-self.last_move_time > 125:
self.direction +=1
if self.direction==4:
self.direction=0
self.sprite = self.textures[self.direction]
self.sprite = pygame.transform.scale(self.sprite, (prefs.CELL_SIZE, prefs.CELL_SIZE))
self.last_move_time=pygame.time.get_ticks()
print(self.direction)
def rotate_right(self):
if pygame.time.get_ticks()-self.last_move_time > 125:
self.direction-=1
if self.direction==-1:
self.direction=3
self.sprite = self.textures[self.direction]
self.sprite = pygame.transform.scale(self.sprite, (prefs.CELL_SIZE, prefs.CELL_SIZE))
self.last_move_time=pygame.time.get_ticks()
print(self.direction)

BIN
sprites/AgentLewo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 607 B

BIN
sprites/AgentPrawo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 617 B

BIN
sprites/AgentTyl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B