diff options
Diffstat (limited to 'src/sliceitoff/game')
-rw-r--r-- | src/sliceitoff/game/__init__.py | 1 | ||||
-rw-r--r-- | src/sliceitoff/game/anykey.py | 9 | ||||
-rw-r--r-- | src/sliceitoff/game/explodeout.py | 38 | ||||
-rw-r--r-- | src/sliceitoff/game/game.py | 10 | ||||
-rw-r--r-- | src/sliceitoff/game/initials.py | 50 | ||||
-rw-r--r-- | src/sliceitoff/game/level.py | 2 | ||||
-rw-r--r-- | src/sliceitoff/game/mainmenu.py | 18 | ||||
-rw-r--r-- | src/sliceitoff/game/menu.py | 70 | ||||
-rw-r--r-- | src/sliceitoff/game/settings.py | 28 | ||||
-rw-r--r-- | src/sliceitoff/game/show.py | 24 |
10 files changed, 7 insertions, 243 deletions
diff --git a/src/sliceitoff/game/__init__.py b/src/sliceitoff/game/__init__.py index 221acd3..7785623 100644 --- a/src/sliceitoff/game/__init__.py +++ b/src/sliceitoff/game/__init__.py @@ -1,3 +1,2 @@ """ game - All the game logic and user inputs """ from .game import Game -from .explodeout import ExplodeOutGroup diff --git a/src/sliceitoff/game/anykey.py b/src/sliceitoff/game/anykey.py deleted file mode 100644 index bd2a3c7..0000000 --- a/src/sliceitoff/game/anykey.py +++ /dev/null @@ -1,9 +0,0 @@ -""" game.anykey - Event waiting. Used for skipping screens. """ -import pygame - -def anykey(): - """ Anything but mouse movement gives True """ - for event in pygame.event.get(): - if event.type in (pygame.MOUSEBUTTONDOWN, pygame.KEYDOWN, pygame.QUIT): - return True - return False diff --git a/src/sliceitoff/game/explodeout.py b/src/sliceitoff/game/explodeout.py deleted file mode 100644 index 0349b09..0000000 --- a/src/sliceitoff/game/explodeout.py +++ /dev/null @@ -1,38 +0,0 @@ -""" game.explodeout - For showing explogind effect and waiting for a key """ -import pygame - -from sliceitoff.sfx import sfx -from .anykey import anykey - -class ExplodeOutGroup(pygame.sprite.Group): - """ Sprite group that just counts down feadeout/explosion or a key """ - def __init__(self, active = True): - super().__init__() - self.explode = False - self.active = active - self.fadeout = 1_000 - - def update(self, dt = 0, **kwargs): - """ Just does the explosion and marks group inactive """ - if not self.active: - return False - - super().update(dt = dt, explode = self.explode, **kwargs) - - if self.explode: - if self.fadeout <= 0: - self.active = False - else: - if anykey(): - self.fadeout = 0 - self.active = False - self.fadeout -= dt - return True - return True - - def do_fadeout(self): - """ Just kicks off exploding phase """ - if self.explode: - return - sfx.play("glass") - self.explode = True diff --git a/src/sliceitoff/game/game.py b/src/sliceitoff/game/game.py index e25a6a6..72b5749 100644 --- a/src/sliceitoff/game/game.py +++ b/src/sliceitoff/game/game.py @@ -16,12 +16,14 @@ from sliceitoff.screens import ( from sliceitoff.hiscores import hi_scores from sliceitoff.text import fonts from sliceitoff.sfx import sfx +from sliceitoff.menu import ( + Show, + MainMenu, + MainMenuItems, + Initials, + SettingsMenu) -from .mainmenu import MainMenu, MainMenuItems from .level import Level -from .show import Show -from .initials import Initials -from .settings import SettingsMenu class Game: """ This is the whole game. """ diff --git a/src/sliceitoff/game/initials.py b/src/sliceitoff/game/initials.py deleted file mode 100644 index 385562c..0000000 --- a/src/sliceitoff/game/initials.py +++ /dev/null @@ -1,50 +0,0 @@ -""" game.initials - Use will be asked for initials """ -import pygame - -from sliceitoff.screens import initials_screen - -from .explodeout import ExplodeOutGroup - -class Initials(ExplodeOutGroup): - """ Sprite group that asks initials to self.name from user """ - def __init__(self): - super().__init__() - self.add(initials_screen("")) - self.name = "" - - def update(self, dt = 0, **kwargs): - """ Does it all. Reads keyboard and updates screen """ - if not super().update(dt = dt, **kwargs): - return - - for event in pygame.event.get(): - if event.type == pygame.QUIT: - self.do_fadeout() - break - if event.type == pygame.KEYDOWN: - if event.key in ( - pygame.K_ESCAPE, - pygame.K_KP_ENTER, - pygame.K_RETURN): - self.do_fadeout() - break - 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[:3] - self.empty() - self.add(initials_screen(self.name)) diff --git a/src/sliceitoff/game/level.py b/src/sliceitoff/game/level.py index 08e4495..421a1eb 100644 --- a/src/sliceitoff/game/level.py +++ b/src/sliceitoff/game/level.py @@ -7,8 +7,8 @@ from sliceitoff.field import Field from sliceitoff.enemies import Enemies from sliceitoff.screens import levelup_screen, gameover_screen, level_screen from sliceitoff.sfx import sfx +from sliceitoff.menu import Show from .gameplay import Gameplay -from .show import Show class Level(pygame.sprite.Group): """ One level that can be played """ diff --git a/src/sliceitoff/game/mainmenu.py b/src/sliceitoff/game/mainmenu.py deleted file mode 100644 index fbd91c9..0000000 --- a/src/sliceitoff/game/mainmenu.py +++ /dev/null @@ -1,18 +0,0 @@ -""" game.mainmenu - Let's user choose """ -from enum import IntEnum - -from sliceitoff.screens import mainmenu_screen -from .menu import Menu - -class MainMenuItems(IntEnum): - """ Items in the menu. Should match mainmenu_screen """ - NEWGAME = 0 - HISCORES = 1 - INSTRUCT = 2 - SETTINGS = 3 - QUIT = 4 - -class MainMenu(Menu): - """ Main menu """ - def __init__(self): - super().__init__(mainmenu_screen, len(MainMenuItems)) diff --git a/src/sliceitoff/game/menu.py b/src/sliceitoff/game/menu.py deleted file mode 100644 index 446e37f..0000000 --- a/src/sliceitoff/game/menu.py +++ /dev/null @@ -1,70 +0,0 @@ -""" game.menu - Skeleton for menus """ -import pygame - -from sliceitoff.display import Scaling - -from .explodeout import ExplodeOutGroup - -MOUSE_TRESHOLD = 100 - -class Menu(ExplodeOutGroup): - """ sprite group with imputs to make selection """ - def __init__(self, screen, items): - super().__init__() - self.items = items - self.selection = 0 - self.mousey = 0 - self.screen = screen - self.add(self.screen(self.selection)) - - def do_selection(self): - """ Default selection handler. Every action just ends menu. """ - self.do_fadeout() - - def update(self, dt = 0, **kwargs): - """ Does it all. Reads keyboard and updates screen """ - if not super().update(dt = dt, **kwargs) or self.explode: - return - - for event in pygame.event.get(): - if event.type == pygame.QUIT: - self.selection = self.items - 1 - self.do_selection() - break - if event.type == pygame.MOUSEBUTTONDOWN and event.button <= 3: - self.do_selection() - break - if event.type == pygame.KEYDOWN: - if self.process_key(event.key): - break - elif event.type == pygame.MOUSEMOTION: - self.process_mouse_motion() - self.empty() - self.add(self.screen(self.selection)) - - def process_mouse_motion(self): - """ Mouse movement up or down moves menu selection """ - self.mousey += pygame.mouse.get_rel()[1] - pygame.mouse.set_pos(Scaling.center) - if abs(self.mousey) > MOUSE_TRESHOLD: - self.selection += 1 if self.mousey > 0 else -1 - self.selection %= self.items - self.mousey = 0 - - def process_key(self, key): - """ Processes known key presses """ - match key: - case pygame.K_KP_ENTER | pygame.K_RETURN | pygame.K_RIGHT: - self.do_selection() - return True - case pygame.K_ESCAPE | pygame.K_q | pygame.K_LEFT: - self.selection = self.items - 1 - self.do_selection() - return True - case pygame.K_UP: - self.selection -= 1 - self.selection %= self.items - case pygame.K_DOWN: - self.selection += 1 - self.selection %= self.items - return False diff --git a/src/sliceitoff/game/settings.py b/src/sliceitoff/game/settings.py deleted file mode 100644 index 0b3bed8..0000000 --- a/src/sliceitoff/game/settings.py +++ /dev/null @@ -1,28 +0,0 @@ -""" game.settings - Settings dialog """ -from enum import IntEnum - -from sliceitoff.sfx import sfx -from sliceitoff.screens import settings_screen -from .menu import Menu - - -class SettingsItems(IntEnum): - """ Items in the menu. Should match settings_screen """ - SFX = 0 - MUSIC = 1 - BACK = 2 - -class SettingsMenu(Menu): - """ Settings menu """ - def __init__(self): - super().__init__(settings_screen, len(SettingsItems)) - - def do_selection(self): - """ Custom actions for menu entries """ - match self.selection: - case SettingsItems.BACK: - self.do_fadeout() - case SettingsItems.SFX: - sfx.sfx_up() - case SettingsItems.MUSIC: - sfx.music_up() diff --git a/src/sliceitoff/game/show.py b/src/sliceitoff/game/show.py deleted file mode 100644 index 32a87cf..0000000 --- a/src/sliceitoff/game/show.py +++ /dev/null @@ -1,24 +0,0 @@ -""" game.show - Sprite group that show sprites and skips if key is pressed """ -from .anykey import anykey -from .explodeout import ExplodeOutGroup - -class Show(ExplodeOutGroup): - """ To show some sprites and quit on any key """ - def __init__(self, sprites = None, active = True): - super().__init__(active = active) - self.add(sprites) - self.timeout = 15_000 - - def update(self, dt = 0, **kwargs): - """ First timeout then fadeout and then inactivity """ - if not super().update(dt = dt, **kwargs): - return - if anykey(): - self.do_fadeout() - if self.timeout <= 0: - self.do_fadeout() - self.timeout -= dt - - def sprites(self): - """ Return sprites only when active """ - return super().sprites() if self.active else [] |