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.max_health = 1000
|
||||||
self.health_bar_length = 300
|
self.health_bar_length = 300
|
||||||
self.health_ratio = self.max_health/self.health_bar_length
|
self.health_ratio = self.max_health/self.health_bar_length
|
||||||
|
self._layer = AGENT_LAYER
|
||||||
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
@ -57,9 +57,6 @@ class Agent(pygame.sprite.Sprite):
|
|||||||
#self.end_game() gra sie konczy gdy wie gdzie sa wszyscy
|
#self.end_game() gra sie konczy gdy wie gdzie sa wszyscy
|
||||||
self.disp_level()
|
self.disp_level()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.rect.x += self.x_change
|
self.rect.x += self.x_change
|
||||||
self.collide_blocks('x')
|
self.collide_blocks('x')
|
||||||
self.rect.y += self.y_change
|
self.rect.y += self.y_change
|
||||||
@ -69,19 +66,32 @@ class Agent(pygame.sprite.Sprite):
|
|||||||
self.y_change = 0
|
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):
|
def movement(self):
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
if keys[pygame.K_LEFT]:
|
if keys[pygame.K_LEFT]:
|
||||||
self.direction=(self.direction-1)%4
|
self.direction=(self.direction-1)%4
|
||||||
print("DIRECTION: "+self.AGENT_IMAGES[self.direction])
|
print("DIRECTION: "+self.AGENT_IMAGES[self.direction])
|
||||||
|
self.rotate()
|
||||||
|
|
||||||
|
|
||||||
if keys[pygame.K_RIGHT]:
|
if keys[pygame.K_RIGHT]:
|
||||||
self.direction=(self.direction+1)%4
|
self.direction=(self.direction+1)%4
|
||||||
print("DIRECTION: "+self.AGENT_IMAGES[self.direction])
|
print("DIRECTION: "+self.AGENT_IMAGES[self.direction])
|
||||||
|
self.rotate()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if keys[pygame.K_UP]:
|
if keys[pygame.K_UP]:
|
||||||
if self.direction==0 and self.rect.x < 832 - 64:
|
if self.direction==0 and self.rect.x < 832 - 64:
|
||||||
self.x_change += TILE_SIZE
|
self.x_change += TILE_SIZE
|
||||||
@ -91,16 +101,7 @@ class Agent(pygame.sprite.Sprite):
|
|||||||
self.x_change -= TILE_SIZE
|
self.x_change -= TILE_SIZE
|
||||||
if self.direction==3 and self.rect.y > 0:
|
if self.direction==3 and self.rect.y > 0:
|
||||||
self.y_change -= TILE_SIZE
|
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):
|
def end_game(self):
|
||||||
if (-1 in self.game.state)==False:
|
if (-1 in self.game.state)==False:
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
FRAMERATE = 30
|
FRAMERATE = 30
|
||||||
WIDTH, HEIGHT = 832, 832
|
WIDTH, HEIGHT = 832, 832
|
||||||
TILE_SIZE = 64
|
TILE_SIZE = 64
|
||||||
BLACK = ((0,0,0))
|
BLACK = ((0,0,0))
|
||||||
WHITE = ((255,255,255))
|
WHITE = ((255,255,255))
|
||||||
#PLAYER_SPEED = 3
|
NUM_ROWS = WIDTH//TILE_SIZE
|
||||||
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):
|
def __init__(self, game, x, y):
|
||||||
self.game = game
|
self.game = game
|
||||||
self.groups = self.game.all_sprites, self.game.flowers
|
self.groups = self.game.flowers
|
||||||
pygame.sprite.Sprite.__init__(self, self.groups)
|
pygame.sprite.Sprite.__init__(self, self.groups)
|
||||||
|
|
||||||
self.x = x * TILE_SIZE
|
self.x = x * TILE_SIZE
|
||||||
@ -24,3 +24,5 @@ class Health_flower(pygame.sprite.Sprite):
|
|||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.rect.x = self.x
|
self.rect.x = self.x
|
||||||
self.rect.y = self.y
|
self.rect.y = self.y
|
||||||
|
|
||||||
|
self._layer = FLOWER_LAYER
|
||||||
|
6
main.py
6
main.py
@ -71,7 +71,8 @@ class Game:
|
|||||||
for y in range(0, 768, TILE_SIZE):
|
for y in range(0, 768, TILE_SIZE):
|
||||||
self.SCREEN.blit(self.BACKGROUND,(x,y))
|
self.SCREEN.blit(self.BACKGROUND,(x,y))
|
||||||
self.rect = pygame.Rect(x, y, TILE_SIZE, TILE_SIZE)
|
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.all_sprites.draw(self.SCREEN)
|
||||||
self.rock_sprites.draw(self.SCREEN)
|
self.rock_sprites.draw(self.SCREEN)
|
||||||
self.SCREEN.blit(self.LVL_ICON, (340 ,780))
|
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))
|
self.open_queue.append(self.get_cell_number(self.agent.x,self.agent.y))
|
||||||
# tutaj dodaje się cel agenta
|
# 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 = []
|
path = []
|
||||||
processing = True
|
processing = True
|
||||||
@ -255,6 +256,7 @@ class Game:
|
|||||||
print("DIRECTION: "+self.agent.AGENT_IMAGES[self.agent.direction])
|
print("DIRECTION: "+self.agent.AGENT_IMAGES[self.agent.direction])
|
||||||
self.agent.y_change -= TILE_SIZE
|
self.agent.y_change -= TILE_SIZE
|
||||||
|
|
||||||
|
self.agent.rotate()
|
||||||
self.update()
|
self.update()
|
||||||
self.map()
|
self.map()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user