From f502b21183d307fcab9b353aa18609d15c3547f1 Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Thu, 28 Mar 2024 13:54:00 +0200 Subject: hiscores: loading, saving, screen --- src/sliceitoff/game/initials.py | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/sliceitoff/game/initials.py (limited to 'src/sliceitoff/game/initials.py') diff --git a/src/sliceitoff/game/initials.py b/src/sliceitoff/game/initials.py new file mode 100644 index 0000000..5b25195 --- /dev/null +++ b/src/sliceitoff/game/initials.py @@ -0,0 +1,44 @@ +import pygame + +from screens import initials_screen + +class Initials(pygame.sprite.Group): + def __init__(self): + super().__init__() + self.add(initials_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(initials_screen(self.name)) + return True -- cgit v1.2.3