diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-30 13:58:02 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-30 13:58:02 +0200 |
commit | 5874005e58d0f26b4393845b3b18160658ece160 (patch) | |
tree | 428f315dbd99e3f77677107586cac493d000cac7 /src/sliceitoff/game/level.py | |
parent | acfac65f17a274d6d7f73cb44ed9476032241134 (diff) |
refactor game.level
Diffstat (limited to 'src/sliceitoff/game/level.py')
-rw-r--r-- | src/sliceitoff/game/level.py | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/src/sliceitoff/game/level.py b/src/sliceitoff/game/level.py index 0742213..085cbc9 100644 --- a/src/sliceitoff/game/level.py +++ b/src/sliceitoff/game/level.py @@ -1,28 +1,26 @@ +""" game.level - This is what runs invidual levels """ import pygame -from display import Display from status import Status from player import Player from field import Field from enemies import Enemies from screens import levelup_screen, gameover_screen, level_screen from .gameplay import Gameplay -from .anykey import anykey from .show import Show - -class Level: +class Level(pygame.sprite.Group): """ One level that can be played """ - def __init__(self, display = None, stats = None): - self.display = display + def __init__(self, stats = None): + super().__init__() self.stats = stats self.status = Status(stats = self.stats) self.field = Field(stats = self.stats) self.enemies = Enemies(count = self.stats.enemies) self.player = Player() self.level_info = Show(level_screen(stats.level)) - self.ended = False + self.active = True self.endscreen = None self.gameplay = Gameplay( @@ -30,28 +28,27 @@ class Level: field = self.field, enemies = self.enemies, stats = self.stats) - self.obj_classes = [ - self.status, - self.field, - self.enemies, - self.level_info, - self.player] - - def step(self, dt): + + def update(self, dt = 0): + """ Updates groups, calls gameplay and adds sprites for drawing """ + self.empty() self.status.update(dt = dt) self.field.update(dt = dt) - self.enemies.update(dt = dt, field_rects = self.field.active_rects() ) + self.enemies.update(dt = dt, field_rects = self.field.active_rects()) + self.add(self.status, self.field, self.enemies) if self.level_info.active: self.level_info.update(dt = dt) + self.add(self.level_info) elif self.ended: if self.endscreen.active: self.endscreen.update(dt = dt) + self.add(self.endscreen) else: - return False - + self.active = False else: + self.add(self.player) self.stats.update_bonus(dt) if self.gameplay.step(): self.ended = True @@ -59,8 +56,3 @@ class Level: self.endscreen = Show(levelup_screen(self.stats)) else: self.endscreen = Show(gameover_screen()) - self.obj_classes.append(self.endscreen) - - self.display.update(self.obj_classes) - - return True |