diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-18 12:41:49 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-18 12:41:49 +0200 |
commit | 6eff6d1d8779480c5fb56a9b7fa619209da45423 (patch) | |
tree | 46732aeae2b8c07b74f01cc581ed09a86f66b494 | |
parent | 0442a8e0836c57418375a1f1f923ba4b9f84d01e (diff) |
status -> no get_sprites, separate update
-rw-r--r-- | src/sliceitoff/__main__.py | 18 | ||||
-rw-r--r-- | src/sliceitoff/game/game.py | 3 | ||||
-rw-r--r-- | src/sliceitoff/status/status.py | 28 |
3 files changed, 25 insertions, 24 deletions
diff --git a/src/sliceitoff/__main__.py b/src/sliceitoff/__main__.py index df4ba22..68fca86 100644 --- a/src/sliceitoff/__main__.py +++ b/src/sliceitoff/__main__.py @@ -30,18 +30,24 @@ def sliceitoff(): game = Game(player = player) clock = pygame.time.Clock() - - for _ in range(6000): - if game.step(): - break + + + while True: + + dt = clock.tick(60) + for fun in (status, status): + fun.update(dt) + display.update( [ - status.get_sprites(), + status.sprites, field.get_sprites(), enemies.get_sprites(), player.get_sprites() ]) - clock.tick(60) + + if game.step(): + break sleep(2) pygame.quit() diff --git a/src/sliceitoff/game/game.py b/src/sliceitoff/game/game.py index 4a4722b..16c42b4 100644 --- a/src/sliceitoff/game/game.py +++ b/src/sliceitoff/game/game.py @@ -13,6 +13,9 @@ class Game: match event.key: case pygame.K_ESCAPE | pygame.K_q: return True + case pygame.K_SPACE: + if self.player.fire_lazer(): + return True case pygame.QUIT: return True case pygame.MOUSEMOTION: diff --git a/src/sliceitoff/status/status.py b/src/sliceitoff/status/status.py index bf0e864..5390299 100644 --- a/src/sliceitoff/status/status.py +++ b/src/sliceitoff/status/status.py @@ -18,26 +18,18 @@ class Status(): self.updated = True self.sprites = pygame.sprite.Group() - - def __update_sprites(self): - self.sprites.empty() - y = 28_000 - score_str="{:010d}".format(self.score) - for letter, x in zip(score_str, range(30_000,40_000,1_000)): - self.sprites.add(LetterSprite( - Images.surfaces[f"letter_{letter}"], - Scaling.scale_to_display((x,y)) )) - self.updated = False - def add_score(self, score_to_add): self.updated = True self.score += score_to_add - def get_sprites(self): + def update(self, dt): + """ Update sprites basis of dt. dt = milliseconds from last update """ if self.updated: - self.__update_sprites() - return self.sprites - - def __del__(self): - pass -
\ No newline at end of file + self.sprites.empty() + y = 28_000 + score_str="{:010d}".format(self.score) + for letter, x in zip(score_str, range(30_000,40_000,1_000)): + self.sprites.add(LetterSprite( + Images.surfaces[f"letter_{letter}"], + Scaling.scale_to_display((x,y)) )) + self.updated = False |