diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-29 00:30:39 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-29 00:30:39 +0200 |
commit | 5c5df6e068b2957987cb51b34d6930769424f8ca (patch) | |
tree | 1f6ce6ff479ee787a3da6f51a9c337bcd24b841a /src/sliceitoff/game | |
parent | 27c7e16e4bd808ce1176f18b7a78c02ff4fa88ee (diff) |
stats as object
Diffstat (limited to 'src/sliceitoff/game')
-rw-r--r-- | src/sliceitoff/game/game.py | 23 | ||||
-rw-r--r-- | src/sliceitoff/game/gameplay.py | 14 | ||||
-rw-r--r-- | src/sliceitoff/game/level.py | 23 |
3 files changed, 29 insertions, 31 deletions
diff --git a/src/sliceitoff/game/game.py b/src/sliceitoff/game/game.py index 146e34e..bcb04e7 100644 --- a/src/sliceitoff/game/game.py +++ b/src/sliceitoff/game/game.py @@ -21,12 +21,10 @@ class Game: pygame.init() self.clock = pygame.time.Clock() self.display = Display() - - pygame.mouse.set_visible(False) - - Fonts.load_fonts( Path(__file__).parent.parent.resolve() ) - + self.stats = None self.hiscores = HiScores() + Fonts.load_fonts( Path(__file__).parent.parent.resolve() ) + pygame.mouse.set_visible(False) def welcome(self): ws = Show(welcome_screen()) @@ -43,15 +41,14 @@ class Game: self.display.update( [his] ) def newgame(self): - Stats.new_game() - - while Stats.lives: - level = Level(display = self.display) + self.stats = Stats() + while self.stats.lives: + level = Level(display = self.display, stats = self.stats) dt = 0 while level.step(dt): dt = self.clock.tick() - if Stats.lives: - Stats.level_up() + if self.stats.lives: + self.stats.level_up() def initials(self): initials = Initials() @@ -64,8 +61,8 @@ class Game: def run(self): self.welcome() self.newgame() - if self.hiscores.high_enough(Stats.score): - self.hiscores.add( Stats.score, self.initials()) + if self.hiscores.high_enough(self.stats.score): + self.hiscores.add( self.stats.score, self.initials()) self.show_highscores() diff --git a/src/sliceitoff/game/gameplay.py b/src/sliceitoff/game/gameplay.py index 028536c..ef708c4 100644 --- a/src/sliceitoff/game/gameplay.py +++ b/src/sliceitoff/game/gameplay.py @@ -1,8 +1,6 @@ """ Reads user input and does actions when game play is on. """ import pygame -from stats import Stats - class Gameplay: """ Logic of the playfield """ def __init__( @@ -10,11 +8,13 @@ class Gameplay: player = None, field = None, status = None, - enemies = None): + enemies = None, + stats = None): self.status = status self.player = player self.field = field self.enemies = enemies + self.stats = stats def fire(self): """ Lazer is fired. Actions to be taken. """ @@ -24,16 +24,16 @@ class Gameplay: 4_000) if not zap_sprite: return False - Stats.add_score(-500) + self.stats.add_score(-500) if pygame.sprite.spritecollideany(zap_sprite, self.enemies): - if Stats.lose_life(): + if self.stats.lose_life(): return True self.field.kill_if_not_colliding(self.enemies.sprites()) self.field.update_stats() - return Stats.percent < 20 + return self.stats.percent < 20 def quit(self): - Stats.lives = 0 + self.stats.lives = 0 return True def step(self): diff --git a/src/sliceitoff/game/level.py b/src/sliceitoff/game/level.py index ada29d2..a711b0d 100644 --- a/src/sliceitoff/game/level.py +++ b/src/sliceitoff/game/level.py @@ -5,7 +5,6 @@ from status import Status from player import Player from field import Field from enemies import Enemies -from stats import Stats from screens import levelup_screen, gameover_screen, level_screen from .gameplay import Gameplay from .anykey import anykey @@ -14,23 +13,25 @@ from .show import Show class Level: """ One level that can be played """ - def __init__(self, display = None): + def __init__(self, display = None, stats = None): self.display = display - self.status = Status() - self.field = Field() - self.enemies = Enemies() + 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.player_single = pygame.sprite.Group() - self.level_info = Show(level_screen()) + self.level_info = Show(level_screen(stats.level)) self.ended = False - self.endscreen = pygame.sprite.Group() + self.endscreen = None self.gameplay = Gameplay( player = self.player, status = self.status, field = self.field, - enemies = self.enemies) + enemies = self.enemies, + stats = self.stats) self.obj_classes = [ self.status, self.field, @@ -55,12 +56,12 @@ class Level: else: self.player_single = pygame.sprite.GroupSingle( sprite = self.player.get_top_sprite()) - Stats.update_bonus(dt) + self.stats.update_bonus(dt) if self.gameplay.step(): self.player_single = pygame.sprite.Group() self.ended = True - if Stats.lives: - self.endscreen = Show(levelup_screen()) + if self.stats.lives: + self.endscreen = Show(levelup_screen(self.stats)) else: self.endscreen = Show(gameover_screen()) self.obj_classes.append(self.endscreen) |