feat: agent can move in the indicated direction

This commit is contained in:
MlodyJacky 2024-04-20 13:38:47 +02:00
parent c088f1104e
commit c5105d426d
2 changed files with 26 additions and 1 deletions

5
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, K_q, K_e
from pygame.locals import K_w, K_s, K_a, K_d, K_q, K_e, K_r
from classes.cell import Cell
from classes.agent import Agent
from collections import deque
@ -101,6 +101,9 @@ while running:
agent.rotate_left()
if keys[K_e]:
agent.rotate_right()
if keys[K_r]:
agent.move_direction()
if pygame.key.get_pressed()[pygame.K_e]:
if agent.current_cell.interactableItem and pygame.time.get_ticks() - agent.last_interact_time > 500:

View File

@ -156,6 +156,28 @@ class Agent:
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 move_direction(self):
if self.direction == 0 and 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()
if self.direction == 1 and 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()
if self.direction == 2 and 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()
if self.direction == 3 and 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()