diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-28 10:00:00 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-28 10:00:00 +0200 |
commit | da2bb3d8e7dcd7f7f0a0c2d2e214b422350d1993 (patch) | |
tree | 980bfb0445110ccb23c451b138edc3863bca7a46 /src/sliceitoff/game | |
parent | c835fbb83b61a5049bae969b6698d500a0c540d3 (diff) |
hiscore name - game.game
Diffstat (limited to 'src/sliceitoff/game')
-rw-r--r-- | src/sliceitoff/game/__init__.py | 1 | ||||
-rw-r--r-- | src/sliceitoff/game/game.py | 61 | ||||
-rw-r--r-- | src/sliceitoff/game/hiscore.py | 44 |
3 files changed, 106 insertions, 0 deletions
diff --git a/src/sliceitoff/game/__init__.py b/src/sliceitoff/game/__init__.py index d578385..cf0da1e 100644 --- a/src/sliceitoff/game/__init__.py +++ b/src/sliceitoff/game/__init__.py @@ -1,3 +1,4 @@ +from .game import Game from .gameplay import Gameplay from .level import Level from .show import Show diff --git a/src/sliceitoff/game/game.py b/src/sliceitoff/game/game.py new file mode 100644 index 0000000..fd796e9 --- /dev/null +++ b/src/sliceitoff/game/game.py @@ -0,0 +1,61 @@ +""" Slice It Off! - Game where you slice the area where enemies reside to + the minimum +""" + +from pathlib import Path + +import pygame + +from display import Display +from images import Images, Fonts +from stats import Stats +from screens import welcome_screen + +from .level import Level +from .show import Show +from .hiscore import HiScore + +class Game: + def __init__(self): + pygame.init() + self.clock = pygame.time.Clock() + self.display = Display() + + pygame.mouse.set_visible(False) + + Fonts.load_fonts( Path(__file__).parent.parent.resolve() ) + + def welcome(self): + ws = Show(welcome_screen()) + dt = 0 + while ws.step(dt): + dt = self.clock.tick() + self.display.update( [ws.sprites] ) + + def newgame(self): + Stats.new_game() + + while Stats.lives: + level = Level(display = self.display) + dt = 0 + while level.step(dt): + dt = self.clock.tick() + if Stats.lives: + Stats.level_up() + + def hiscore(self): + hs = HiScore() + dt = 0 + while hs.step(): + dt = self.clock.tick() + # hs.update(dt = dt) + self.display.update([hs]) + + def run(self): + self.welcome() + self.newgame() + self.hiscore() + + def __del__(self): + pygame.quit() + diff --git a/src/sliceitoff/game/hiscore.py b/src/sliceitoff/game/hiscore.py new file mode 100644 index 0000000..734ad5e --- /dev/null +++ b/src/sliceitoff/game/hiscore.py @@ -0,0 +1,44 @@ +import pygame + +from screens import hiscore_screen + +class HiScore(pygame.sprite.Group): + def __init__(self): + super().__init__() + self.add(hiscore_screen("")) + self.name = "" + + def update(self, **kwargs): + super().update(**kwargs) + + def step(self): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + return False + if event.type == pygame.KEYDOWN: + if event.key in ( + pygame.K_ESCAPE, + pygame.K_KP_ENTER, + pygame.K_RETURN): + return False + if event.key in ( + pygame.K_RSHIFT, + pygame.K_LSHIFT, + pygame.K_RCTRL, + pygame.K_LCTRL, + pygame.K_RALT, + pygame.K_LALT, + pygame.K_RMETA, + pygame.K_LMETA, + pygame.K_LSUPER, + pygame.K_RSUPER, + pygame.K_SPACE): + continue + if event.key in (pygame.K_BACKSPACE, pygame.K_DELETE): + self.name = self.name [:-1] + elif pygame.key.name(event.key): + self.name += pygame.key.name(event.key)[0].upper() + self.name = self.name[:8] + self.empty() + self.add(hiscore_screen(self.name)) + return True |