sprite group w level.py zamienilem na LayeredUpdates() oraz dodałem do każdego sprite'a layer, wiec nie beda na siebie nachodzic nigdy

This commit is contained in:
XsedoX 2022-04-28 10:18:17 +02:00
parent 1998f94c3d
commit 0f6f2354d3
6 changed files with 10 additions and 6 deletions

View File

@ -35,7 +35,7 @@ class Game:
menu.display_screen() menu.display_screen()
def game(self): def game(self):
stats = Stats() stats = Stats(self.screen)
# setup clock for rounds # setup clock for rounds
NEXT_TURN = pygame.USEREVENT + 1 NEXT_TURN = pygame.USEREVENT + 1
@ -63,9 +63,8 @@ class Game:
if event.type == NEXT_TURN: # is called every 'TURN_INTERVAL' milliseconds if event.type == NEXT_TURN: # is called every 'TURN_INTERVAL' milliseconds
self.level.handle_turn() self.level.handle_turn()
stats.draw(self.screen) stats.draw()
self.logs.draw() self.logs.draw()
self.level.update() self.level.update()
if print_numbers_flag: if print_numbers_flag:

View File

@ -18,7 +18,7 @@ class Level:
self.screen = screen self.screen = screen
self.logs = logs self.logs = logs
# sprite group setup # sprite group setup
self.sprites = pygame.sprite.Group() self.sprites = pygame.sprite.LayeredUpdates()
self.map = [['g' for _ in range(COLUMNS)] for y in range(ROWS)] self.map = [['g' for _ in range(COLUMNS)] for y in range(ROWS)]
@ -154,3 +154,5 @@ class Level:
# update and draw the game # update and draw the game
self.sprites.draw(self.screen) self.sprites.draw(self.screen)

View File

@ -6,6 +6,7 @@ from common.helpers import parse_cord
class Castle(pygame.sprite.Sprite): class Castle(pygame.sprite.Sprite):
def __init__(self, position, group): def __init__(self, position, group):
super().__init__(group) super().__init__(group)
self._layer = 1
self.image = pygame.image.load("./resources/textures/castle.png").convert_alpha() self.image = pygame.image.load("./resources/textures/castle.png").convert_alpha()
self.image = pygame.transform.scale(self.image, (78, 78)) self.image = pygame.transform.scale(self.image, (78, 78))
self.position = position self.position = position

View File

@ -28,6 +28,7 @@ class Knight(pygame.sprite.Sprite):
self.image = self.states[self.direction.value] self.image = self.states[self.direction.value]
self.position = position self.position = position
self._layer = 1
position_in_px = (parse_cord(position[0]), parse_cord(position[1])) position_in_px = (parse_cord(position[0]), parse_cord(position[1]))
self.rect = self.image.get_rect(topleft=position_in_px) self.rect = self.image.get_rect(topleft=position_in_px)
@ -37,7 +38,6 @@ class Knight(pygame.sprite.Sprite):
self.defense = random.randint(1, 4) self.defense = random.randint(1, 4)
self.points = 1 self.points = 1
self.health_bar = HealthBar(screen, self.rect, self.health, self.health) self.health_bar = HealthBar(screen, self.rect, self.health, self.health)
self.health_bar.update()
def rotate_left(self): def rotate_left(self):
self.direction = self.direction.left() self.direction = self.direction.left()

View File

@ -14,6 +14,7 @@ monster_images = [
class Monster(pygame.sprite.Sprite): class Monster(pygame.sprite.Sprite):
def __init__(self, position, group): def __init__(self, position, group):
super().__init__(group) super().__init__(group)
self._layer = 1
self.image = random.choice(monster_images) self.image = random.choice(monster_images)
self.image = pygame.transform.scale(self.image, (40, 40)) self.image = pygame.transform.scale(self.image, (40, 40))
position_in_px = (parse_cord(position[0]), parse_cord(position[1])) position_in_px = (parse_cord(position[0]), parse_cord(position[1]))

View File

@ -7,6 +7,7 @@ class Tile(pygame.sprite.Sprite):
def __init__(self, position, image, group, tile_type=' '): def __init__(self, position, image, group, tile_type=' '):
super().__init__(group) super().__init__(group)
self.image = image self.image = image
self._layer = 0
position_in_px = (parse_cord(position[0]), parse_cord(position[1])) position_in_px = (parse_cord(position[0]), parse_cord(position[1]))
self.rect = self.image.get_rect(topleft=position_in_px) self.rect = self.image.get_rect(topleft=position_in_px)
self.tile_type = tile_type self.tile_type = tile_type