diff --git a/__pycache__/agent.cpython-310.pyc b/__pycache__/agent.cpython-310.pyc index 9f226b8..562bc61 100644 Binary files a/__pycache__/agent.cpython-310.pyc and b/__pycache__/agent.cpython-310.pyc differ diff --git a/__pycache__/config.cpython-310.pyc b/__pycache__/config.cpython-310.pyc index e437e56..0331f11 100644 Binary files a/__pycache__/config.cpython-310.pyc and b/__pycache__/config.cpython-310.pyc differ diff --git a/__pycache__/health_flower.cpython-310.pyc b/__pycache__/health_flower.cpython-310.pyc index 2911eff..d596565 100644 Binary files a/__pycache__/health_flower.cpython-310.pyc and b/__pycache__/health_flower.cpython-310.pyc differ diff --git a/agent.py b/agent.py index 494c591..710c2d6 100644 --- a/agent.py +++ b/agent.py @@ -45,7 +45,7 @@ class Agent(pygame.sprite.Sprite): self.max_health = 1000 self.health_bar_length = 300 self.health_ratio = self.max_health/self.health_bar_length - + self._layer = AGENT_LAYER def update(self): @@ -57,9 +57,6 @@ class Agent(pygame.sprite.Sprite): #self.end_game() gra sie konczy gdy wie gdzie sa wszyscy self.disp_level() - - - self.rect.x += self.x_change self.collide_blocks('x') self.rect.y += self.y_change @@ -69,19 +66,32 @@ class Agent(pygame.sprite.Sprite): self.y_change = 0 + def rotate(self): + if self.direction == 0: + self.image = self.AGENT_RIGHT + elif self.direction == 1: + self.image = self.AGENT_DOWN + elif self.direction == 2: + self.image = self.AGENT_LEFT + elif self.direction == 3: + self.image = self.AGENT_UP + + + def movement(self): keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: self.direction=(self.direction-1)%4 print("DIRECTION: "+self.AGENT_IMAGES[self.direction]) + self.rotate() if keys[pygame.K_RIGHT]: self.direction=(self.direction+1)%4 print("DIRECTION: "+self.AGENT_IMAGES[self.direction]) + self.rotate() - if keys[pygame.K_UP]: if self.direction==0 and self.rect.x < 832 - 64: self.x_change += TILE_SIZE @@ -91,16 +101,7 @@ class Agent(pygame.sprite.Sprite): self.x_change -= TILE_SIZE if self.direction==3 and self.rect.y > 0: self.y_change -= TILE_SIZE - """ - if keys[pygame.K_LEFT] and self.rect.x > 0: - self.x_change -= TILE_SIZE - if keys[pygame.K_RIGHT] and self.rect.x < 832 - 64: - self.x_change += TILE_SIZE - if keys[pygame.K_UP] and self.rect.y > 0: - self.y_change -= TILE_SIZE - if keys[pygame.K_DOWN] and self.rect.y < 768 - 64: - self.y_change += TILE_SIZE - """ + def end_game(self): if (-1 in self.game.state)==False: pygame.quit() diff --git a/config.py b/config.py index 39fa0e4..1398b28 100644 --- a/config.py +++ b/config.py @@ -1,7 +1,10 @@ +import pygame + FRAMERATE = 30 WIDTH, HEIGHT = 832, 832 TILE_SIZE = 64 BLACK = ((0,0,0)) WHITE = ((255,255,255)) -#PLAYER_SPEED = 3 -NUM_ROWS = WIDTH//TILE_SIZE \ No newline at end of file +NUM_ROWS = WIDTH//TILE_SIZE +AGENT_LAYER =2 +FLOWER_LAYER = 1 \ No newline at end of file diff --git a/health_flower.py b/health_flower.py index fd001cf..684bce1 100644 --- a/health_flower.py +++ b/health_flower.py @@ -6,7 +6,7 @@ class Health_flower(pygame.sprite.Sprite): def __init__(self, game, x, y): self.game = game - self.groups = self.game.all_sprites, self.game.flowers + self.groups = self.game.flowers pygame.sprite.Sprite.__init__(self, self.groups) self.x = x * TILE_SIZE @@ -24,3 +24,5 @@ class Health_flower(pygame.sprite.Sprite): self.rect = self.image.get_rect() self.rect.x = self.x self.rect.y = self.y + + self._layer = FLOWER_LAYER diff --git a/main.py b/main.py index edecabf..8b6bf71 100644 --- a/main.py +++ b/main.py @@ -71,7 +71,8 @@ class Game: for y in range(0, 768, TILE_SIZE): self.SCREEN.blit(self.BACKGROUND,(x,y)) self.rect = pygame.Rect(x, y, TILE_SIZE, TILE_SIZE) - pygame.draw.rect(self.SCREEN, BLACK, self.rect, 1) + pygame.draw.rect(self.SCREEN, BLACK, self.rect, 1) + self.flowers.draw(self.SCREEN) self.all_sprites.draw(self.SCREEN) self.rock_sprites.draw(self.SCREEN) self.SCREEN.blit(self.LVL_ICON, (340 ,780)) @@ -94,7 +95,7 @@ class Game: self.open_queue.append(self.get_cell_number(self.agent.x,self.agent.y)) # tutaj dodaje siÄ™ cel agenta - goal_cell = self.get_cell_number(448,128) + goal_cell = self.get_cell_number(self.flower.x,self.flower.y) path = [] processing = True @@ -255,6 +256,7 @@ class Game: print("DIRECTION: "+self.agent.AGENT_IMAGES[self.agent.direction]) self.agent.y_change -= TILE_SIZE + self.agent.rotate() self.update() self.map()