summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-04-26 23:21:22 +0300
committerViljami Ilola <+@hix.fi>2024-04-26 23:21:22 +0300
commit54cf5ab6dde77dff1afe177b33a054925569a0cf (patch)
tree4d37391b38104546ef2321ecb6d48ad2b6624cb2
parent220211bf89e5c873c2ee694b14ab70578188a36c (diff)
settings submenu
-rw-r--r--src/sliceitoff/game/game.py10
-rw-r--r--src/sliceitoff/game/settings.py79
-rw-r--r--src/sliceitoff/screens/__init__.py1
-rw-r--r--src/sliceitoff/screens/settings.py24
4 files changed, 114 insertions, 0 deletions
diff --git a/src/sliceitoff/game/game.py b/src/sliceitoff/game/game.py
index c6a5fe0..2ef377f 100644
--- a/src/sliceitoff/game/game.py
+++ b/src/sliceitoff/game/game.py
@@ -20,6 +20,7 @@ from .mainmenu import Mainmenu, MenuItems
from .level import Level
from .show import Show
from .initials import Initials
+from .settings import Settings
class Game:
""" This is the whole game. """
@@ -81,6 +82,13 @@ class Game:
self.display.update([menu])
return menu.selection
+ def settings(self):
+ """ settings menu where one can adjust volume for example """
+ menu = Settings()
+ while menu.active:
+ menu.update(dt = self.clock.tick())
+ self.display.update([menu])
+
def run(self):
""" This is the main loop of the game """
while True:
@@ -91,6 +99,8 @@ class Game:
self.show_highscores()
case MenuItems.INSTRUCT:
self.instructions()
+ case MenuItems.SETTINGS:
+ self.settings()
case MenuItems.NEWGAME:
self.newgame()
if self.hiscores.high_enough(self.stats.score):
diff --git a/src/sliceitoff/game/settings.py b/src/sliceitoff/game/settings.py
new file mode 100644
index 0000000..6a709a4
--- /dev/null
+++ b/src/sliceitoff/game/settings.py
@@ -0,0 +1,79 @@
+""" game.mainmenu - Let's user choose """
+from enum import IntEnum
+import pygame
+
+from sliceitoff.screens import settings_screen
+from sliceitoff.display import Scaling
+from sliceitoff.sfx import sfx
+
+from .explodeout import ExplodeOutGroup
+
+MOUSE_TRESHOLD = 100
+
+class MenuItems(IntEnum):
+ """ Items in the menu. Should match mainmenu_screen """
+ SFX = 0
+ MUSIC = 1
+ BACK = 2
+
+class Settings(ExplodeOutGroup):
+ """ sprite group with imputs to make selection """
+ def __init__(self):
+ super().__init__()
+ self.add(settings_screen(0))
+ self.selection = 0
+ self.mousey = 0
+
+ def do_selection(self):
+ """ Actions for manu entries """
+ match self.selection:
+ case MenuItems.BACK:
+ 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 = MenuItems.BACK
+ self.do_fadeout()
+ 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(settings_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 %= len(MenuItems)
+ 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 = MenuItems.BACK
+ self.do_fadeout()
+ return True
+ case pygame.K_UP:
+ self.selection -= 1
+ self.selection %= len(MenuItems)
+ case pygame.K_DOWN:
+ self.selection += 1
+ self.selection %= len(MenuItems)
+ return False
diff --git a/src/sliceitoff/screens/__init__.py b/src/sliceitoff/screens/__init__.py
index 6b5165e..ac83714 100644
--- a/src/sliceitoff/screens/__init__.py
+++ b/src/sliceitoff/screens/__init__.py
@@ -6,5 +6,6 @@ from .level import level_screen
from .initials import initials_screen
from .hiscores import hiscores_screen
from .mainmenu import mainmenu_screen
+from .settings import settings_screen
from .instructions1 import instructions1_screen
from .instructions2 import instructions2_screen
diff --git a/src/sliceitoff/screens/settings.py b/src/sliceitoff/screens/settings.py
new file mode 100644
index 0000000..cb0549a
--- /dev/null
+++ b/src/sliceitoff/screens/settings.py
@@ -0,0 +1,24 @@
+""" screens.mainmenu - Screen for mainmenu"""
+from random import randrange
+from sliceitoff.text import TextPage
+
+def settings_screen(selection):
+ """ Screen where current selection is flashing """
+ active = randrange(0xe9,0xf0)
+ inactive = 0xe7
+ text = (
+ f" Settings:\n"
+ f"\n\n"
+ f"\xe7SFX Volume:\n"
+ f"{chr(active if selection == 0 else inactive)}"
+ f" [ ]\n\n"
+ f"\xe7Music Volume:\n"
+ f"{chr(active if selection == 1 else inactive)}"
+ f" [ ]\n\n"
+ f"{chr(active if selection == 2 else inactive)}"
+ f"Back.")
+ return TextPage(
+ text,
+ font = '8x8',
+ size = (16_000, 16_000),
+ pos = (32_000, 16_000) )