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:
parent
1998f94c3d
commit
0f6f2354d3
@ -35,7 +35,7 @@ class Game:
|
||||
menu.display_screen()
|
||||
|
||||
def game(self):
|
||||
stats = Stats()
|
||||
stats = Stats(self.screen)
|
||||
|
||||
# setup clock for rounds
|
||||
NEXT_TURN = pygame.USEREVENT + 1
|
||||
@ -63,9 +63,8 @@ class Game:
|
||||
if event.type == NEXT_TURN: # is called every 'TURN_INTERVAL' milliseconds
|
||||
self.level.handle_turn()
|
||||
|
||||
stats.draw(self.screen)
|
||||
stats.draw()
|
||||
self.logs.draw()
|
||||
|
||||
self.level.update()
|
||||
|
||||
if print_numbers_flag:
|
||||
|
@ -18,7 +18,7 @@ class Level:
|
||||
self.screen = screen
|
||||
self.logs = logs
|
||||
# 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)]
|
||||
|
||||
@ -154,3 +154,5 @@ class Level:
|
||||
|
||||
# update and draw the game
|
||||
self.sprites.draw(self.screen)
|
||||
|
||||
|
||||
|
@ -6,6 +6,7 @@ from common.helpers import parse_cord
|
||||
class Castle(pygame.sprite.Sprite):
|
||||
def __init__(self, position, group):
|
||||
super().__init__(group)
|
||||
self._layer = 1
|
||||
self.image = pygame.image.load("./resources/textures/castle.png").convert_alpha()
|
||||
self.image = pygame.transform.scale(self.image, (78, 78))
|
||||
self.position = position
|
||||
|
@ -28,6 +28,7 @@ class Knight(pygame.sprite.Sprite):
|
||||
|
||||
self.image = self.states[self.direction.value]
|
||||
self.position = position
|
||||
self._layer = 1
|
||||
position_in_px = (parse_cord(position[0]), parse_cord(position[1]))
|
||||
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.points = 1
|
||||
self.health_bar = HealthBar(screen, self.rect, self.health, self.health)
|
||||
self.health_bar.update()
|
||||
|
||||
def rotate_left(self):
|
||||
self.direction = self.direction.left()
|
||||
|
@ -14,6 +14,7 @@ monster_images = [
|
||||
class Monster(pygame.sprite.Sprite):
|
||||
def __init__(self, position, group):
|
||||
super().__init__(group)
|
||||
self._layer = 1
|
||||
self.image = random.choice(monster_images)
|
||||
self.image = pygame.transform.scale(self.image, (40, 40))
|
||||
position_in_px = (parse_cord(position[0]), parse_cord(position[1]))
|
||||
|
@ -7,6 +7,7 @@ class Tile(pygame.sprite.Sprite):
|
||||
def __init__(self, position, image, group, tile_type=' '):
|
||||
super().__init__(group)
|
||||
self.image = image
|
||||
self._layer = 0
|
||||
position_in_px = (parse_cord(position[0]), parse_cord(position[1]))
|
||||
self.rect = self.image.get_rect(topleft=position_in_px)
|
||||
self.tile_type = tile_type
|
||||
self.tile_type = tile_type
|
||||
|
Loading…
Reference in New Issue
Block a user