obracanie obrazka + dodanie warstw
This commit is contained in:
parent
61d7ab2fe3
commit
6b5f4386bc
Binary file not shown.
Binary file not shown.
Binary file not shown.
31
agent.py
31
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,17 +66,30 @@ 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]:
|
||||
@ -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()
|
||||
|
@ -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
|
||||
AGENT_LAYER =2
|
||||
FLOWER_LAYER = 1
|
@ -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
|
||||
|
4
main.py
4
main.py
@ -72,6 +72,7 @@ class Game:
|
||||
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)
|
||||
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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user