From da2bb3d8e7dcd7f7f0a0c2d2e214b422350d1993 Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Thu, 28 Mar 2024 10:00:00 +0200 Subject: hiscore name - game.game --- src/sliceitoff/__main__.py | 48 ++-------------------------- src/sliceitoff/assets/ball/00.png | Bin 1760 -> 0 bytes src/sliceitoff/assets/fonts.lst | 3 -- src/sliceitoff/assets/images.lst | 1 - src/sliceitoff/assets/player/00.png | Bin 20090 -> 0 bytes src/sliceitoff/game/__init__.py | 1 + src/sliceitoff/game/game.py | 61 ++++++++++++++++++++++++++++++++++++ src/sliceitoff/game/hiscore.py | 44 ++++++++++++++++++++++++++ src/sliceitoff/screens/__init__.py | 2 +- src/sliceitoff/screens/hiscore.py | 14 +++++++++ 10 files changed, 124 insertions(+), 50 deletions(-) delete mode 100644 src/sliceitoff/assets/ball/00.png delete mode 100644 src/sliceitoff/assets/images.lst delete mode 100644 src/sliceitoff/assets/player/00.png create mode 100644 src/sliceitoff/game/game.py create mode 100644 src/sliceitoff/game/hiscore.py create mode 100644 src/sliceitoff/screens/hiscore.py diff --git a/src/sliceitoff/__main__.py b/src/sliceitoff/__main__.py index 2ca02f7..971e58c 100644 --- a/src/sliceitoff/__main__.py +++ b/src/sliceitoff/__main__.py @@ -2,49 +2,7 @@ the minimum """ -from time import sleep -from pathlib import Path +from game import Game -import pygame - -from display import Display -from images import Images, Fonts -from game import Level, Show -from stats import Stats -from screens import welcome_screen - - -def sliceitoff(): - """ The game - It all starts here """ - pygame.init() - - pygame.mouse.set_visible(False) - - clock = pygame.time.Clock() - - display = Display() - current_path = Path(__file__).parent.resolve() - Images.load_images( current_path ) - Fonts.load_fonts( current_path ) - - - welcome = Show(welcome_screen()) - dt = 0 - while welcome.step(dt): - dt = clock.tick() - display.update( [welcome.sprites] ) - - - Stats.new_game() - - while Stats.lives: - level = Level(display = display) - dt = 0 - while level.step(dt): - dt = clock.tick() - if Stats.lives: - Stats.level_up() - - pygame.quit() - -sliceitoff() +game = Game() +game.run() diff --git a/src/sliceitoff/assets/ball/00.png b/src/sliceitoff/assets/ball/00.png deleted file mode 100644 index 844b814..0000000 Binary files a/src/sliceitoff/assets/ball/00.png and /dev/null differ diff --git a/src/sliceitoff/assets/fonts.lst b/src/sliceitoff/assets/fonts.lst index 0fb62b5..a782a86 100644 --- a/src/sliceitoff/assets/fonts.lst +++ b/src/sliceitoff/assets/fonts.lst @@ -1,7 +1,4 @@ lcd assets gnufonts UTIL GNUFONTS LCD.FNT -deco assets gnufonts UTIL GNUFONTS DECO.FNT 8x8 assets gnufonts UTIL GNUFONTS 8X8.FNT -8x14 assets gnufonts UTIL GNUFONTS 8X14.FNT computer assets gnufonts UTIL GNUFONTS COMPUTER.FNT standard assets gnufonts UTIL GNUFONTS STANDARD.FNT -hearst assets gnufonts UTIL GNUFONTS HEARST.FNT \ No newline at end of file diff --git a/src/sliceitoff/assets/images.lst b/src/sliceitoff/assets/images.lst deleted file mode 100644 index 3637a65..0000000 --- a/src/sliceitoff/assets/images.lst +++ /dev/null @@ -1 +0,0 @@ -player_00 assets player 00.png diff --git a/src/sliceitoff/assets/player/00.png b/src/sliceitoff/assets/player/00.png deleted file mode 100644 index 1508829..0000000 Binary files a/src/sliceitoff/assets/player/00.png and /dev/null differ 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 diff --git a/src/sliceitoff/screens/__init__.py b/src/sliceitoff/screens/__init__.py index ad49657..1d373f6 100644 --- a/src/sliceitoff/screens/__init__.py +++ b/src/sliceitoff/screens/__init__.py @@ -2,4 +2,4 @@ from .welcome import welcome_screen from .levelup import levelup_screen from .gameover import gameover_screen from .level import level_screen - +from .hiscore import hiscore_screen diff --git a/src/sliceitoff/screens/hiscore.py b/src/sliceitoff/screens/hiscore.py new file mode 100644 index 0000000..c6f2a21 --- /dev/null +++ b/src/sliceitoff/screens/hiscore.py @@ -0,0 +1,14 @@ +from text import TextPage + +def hiscore_screen(name): + return TextPage( + f" New High Score!\n" + f"\n" + f"\n" + f"Please give name:\n" + f"\n" + f"\n" + f"{name:^17s}", + font = '8x8', + size = (16_000, 16_000), + pos = (24_000, 32_000) ) -- cgit v1.2.3