summaryrefslogtreecommitdiff
path: root/src/sliceitoff/game
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-28 23:34:19 +0200
committerViljami Ilola <+@hix.fi>2024-03-28 23:34:19 +0200
commit27c7e16e4bd808ce1176f18b7a78c02ff4fa88ee (patch)
treea585d5ef853a0f8ffd5000cbdc9b0c4257163e53 /src/sliceitoff/game
parentf894c2fd09ed17540c49cb4083573861ded76554 (diff)
fonts under text, more sprite.Groups
Diffstat (limited to 'src/sliceitoff/game')
-rw-r--r--src/sliceitoff/game/anykey.py2
-rw-r--r--src/sliceitoff/game/game.py6
-rw-r--r--src/sliceitoff/game/initials.py36
-rw-r--r--src/sliceitoff/game/level.py20
-rw-r--r--src/sliceitoff/game/show.py6
5 files changed, 45 insertions, 25 deletions
diff --git a/src/sliceitoff/game/anykey.py b/src/sliceitoff/game/anykey.py
index 6fd48a2..bd2a3c7 100644
--- a/src/sliceitoff/game/anykey.py
+++ b/src/sliceitoff/game/anykey.py
@@ -1,6 +1,8 @@
+""" 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
diff --git a/src/sliceitoff/game/game.py b/src/sliceitoff/game/game.py
index 982466b..146e34e 100644
--- a/src/sliceitoff/game/game.py
+++ b/src/sliceitoff/game/game.py
@@ -7,7 +7,7 @@ from pathlib import Path
import pygame
from display import Display
-from images import Images, Fonts
+from text import Fonts
from stats import Stats
from screens import welcome_screen, hiscores_screen
from hiscores import HiScores
@@ -56,8 +56,8 @@ class Game:
def initials(self):
initials = Initials()
dt = 0
- while initials.step():
- dt = self.clock.tick()
+ while initials.active:
+ initials.update(dt = self.clock.tick())
self.display.update([initials])
return initials.name
diff --git a/src/sliceitoff/game/initials.py b/src/sliceitoff/game/initials.py
index a317dd9..49db3d6 100644
--- a/src/sliceitoff/game/initials.py
+++ b/src/sliceitoff/game/initials.py
@@ -1,26 +1,47 @@
+""" game.initials - Use will be asked for initials """
import pygame
from screens import initials_screen
+from .anykey import anykey
+
class Initials(pygame.sprite.Group):
+ """ Sprite group that asks initials to self.name from user """
def __init__(self):
super().__init__()
self.add(initials_screen(""))
self.name = ""
+ self.explode = False
+ self.active = True
+ self.fadeout = 1_000
- def update(self, **kwargs):
- super().update(**kwargs)
+ def update(self, dt = 0, **kwargs):
+ if not self.active:
+ return
+
+ 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
- def step(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
- return False
+ self.explode = True
+ break
if event.type == pygame.KEYDOWN:
if event.key in (
pygame.K_ESCAPE,
pygame.K_KP_ENTER,
pygame.K_RETURN):
- return False
+ self.explode = True
+ break
if event.key in (
pygame.K_RSHIFT,
pygame.K_LSHIFT,
@@ -39,6 +60,5 @@ class Initials(pygame.sprite.Group):
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))
- return True
+ self.empty()
+ self.add(initials_screen(self.name))
diff --git a/src/sliceitoff/game/level.py b/src/sliceitoff/game/level.py
index f0bb871..ada29d2 100644
--- a/src/sliceitoff/game/level.py
+++ b/src/sliceitoff/game/level.py
@@ -16,16 +16,15 @@ class Level:
""" One level that can be played """
def __init__(self, display = None):
self.display = display
- self.ended = False
self.status = Status()
self.field = Field()
self.enemies = Enemies()
self.player = Player()
self.player_single = pygame.sprite.Group()
-
self.level_info = Show(level_screen())
- self.game_over = Show(gameover_screen(), active = False)
- self.levelup = Show(levelup_screen(), active = False)
+
+ self.ended = False
+ self.endscreen = pygame.sprite.Group()
self.gameplay = Gameplay(
player = self.player,
@@ -36,8 +35,6 @@ class Level:
self.status,
self.field,
self.enemies,
- self.game_over,
- self.levelup,
self.level_info]
def step(self, dt):
@@ -50,10 +47,8 @@ class Level:
self.level_info.update(dt = dt)
elif self.ended:
- if self.game_over.active:
- self.game_over.update(dt = dt)
- elif self.levelup.active:
- self.levelup.update(dt = dt)
+ if self.endscreen.active:
+ self.endscreen.update(dt = dt)
else:
return False
@@ -65,9 +60,10 @@ class Level:
self.player_single = pygame.sprite.Group()
self.ended = True
if Stats.lives:
- self.levelup.active = True
+ self.endscreen = Show(levelup_screen())
else:
- self.game_over.active = True
+ self.endscreen = Show(gameover_screen())
+ self.obj_classes.append(self.endscreen)
self.display.update(self.obj_classes+[self.player_single])
diff --git a/src/sliceitoff/game/show.py b/src/sliceitoff/game/show.py
index 018e555..b9b684b 100644
--- a/src/sliceitoff/game/show.py
+++ b/src/sliceitoff/game/show.py
@@ -1,4 +1,4 @@
-""" Reads user input and does actions when game play is on. """
+""" Sprite group that show sprites and skips if key is pressed """
import pygame
from .anykey import anykey
@@ -13,6 +13,7 @@ class Show(pygame.sprite.Group):
self.timeout = 15_000
def update(self, dt = 0, **kwargs):
+ """ First timeout then fadeout and then inactivity """
super().update(dt = dt, explode = self.explode, **kwargs)
if self.fadeout <= 0:
self.active = False
@@ -27,4 +28,5 @@ class Show(pygame.sprite.Group):
self.timeout -= dt
def sprites(self):
- return super().sprites() if self.active else None \ No newline at end of file
+ """ Return sprites only when active """
+ return super().sprites() if self.active else [] \ No newline at end of file