From c088f1104e2c49758f5c56b032865244e019dc25 Mon Sep 17 00:00:00 2001 From: MlodyJacky Date: Sat, 20 Apr 2024 11:05:31 +0200 Subject: [PATCH] feat: agent rotates now --- app.py | 10 ++++++++-- classes/agent.py | 35 ++++++++++++++++++++++++++++++++++- sprites/AgentLewo.png | Bin 0 -> 607 bytes sprites/AgentPrawo.png | Bin 0 -> 617 bytes sprites/AgentTyl.png | Bin 0 -> 703 bytes 5 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 sprites/AgentLewo.png create mode 100644 sprites/AgentPrawo.png create mode 100644 sprites/AgentTyl.png diff --git a/app.py b/app.py index 5f0b000..d8d36c8 100644 --- a/app.py +++ b/app.py @@ -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() diff --git a/classes/agent.py b/classes/agent.py index bd644f5..0dc2783 100644 --- a/classes/agent.py +++ b/classes/agent.py @@ -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) \ No newline at end of file + 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) + + + + diff --git a/sprites/AgentLewo.png b/sprites/AgentLewo.png new file mode 100644 index 0000000000000000000000000000000000000000..f07c216bba3b3a77a3bd4008457d6cb5145d7075 GIT binary patch literal 607 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!7>k44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O_~e1o(uw7BevP#CdF~j6L(_zk{}-y-zeJmy)cKO?pA|>kpqSt->?h%qC85 zVf_Dp?Y2EYO-54_wc)R&obj%A&I|L!?nxGGpDirKY#^y2?$y}3j3KtjlHu39 zbh8=W9^V_xc1XQg&1^58_^b86o%`WA|4R}c7%UdpaepuWL*a_|(M-&HL^u+EtakV` zo7s7X#E);YnO`YCn9X#Wbqkx5#Bsx)zKj_h9*lL-4EGgvmo$Xl;P<(_gi$1g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