level select timeout

This commit is contained in:
frank 2022-03-08 22:26:50 -05:00
parent 003141b7e4
commit da22509fe1
4 changed files with 43 additions and 7 deletions

38
NS.py
View File

@ -158,8 +158,8 @@ class NS(Game, Animation):
{ {
"time": "time":
{ {
"int": ["timer-max-time", "timer-start-time", "timer-addition", "sword-delay", "int": ["timer-max-time", "timer-start-time", "timer-addition", "sword-delay", "attract-gif-length",
"attract-gif-length", "attract-board-length", "attract-reset-countdown"], "attract-board-length", "attract-reset-countdown", "level-select-reset-countdown"],
"float": "timer-warning-start" "float": "timer-warning-start"
}, },
"input": "input":
@ -445,7 +445,7 @@ class NS(Game, Animation):
self.reset() self.reset()
class LevelSelect(GameChild): class LevelSelect(Animation):
""" """
Display the available levels. Initialize a platform for each level and display each platform beneath its level glowing Display the available levels. Initialize a platform for each level and display each platform beneath its level glowing
with a pair of pads to press to start that level. Wait for user input, then launch the level of the pair that gets with a pair of pads to press to start that level. Wait for user input, then launch the level of the pair that gets
@ -453,8 +453,9 @@ class LevelSelect(GameChild):
""" """
def __init__(self, parent): def __init__(self, parent):
GameChild.__init__(self, parent) Animation.__init__(self, parent)
self.subscribe(self.respond, KEYDOWN) self.subscribe(self.respond, KEYDOWN)
self.register(self.timeout)
y = 250 y = 250
indent = 10 indent = 10
dsr = self.get_display_surface().get_rect() dsr = self.get_display_surface().get_rect()
@ -499,6 +500,7 @@ class LevelSelect(GameChild):
self.active = True self.active = True
for platform in self.platforms: for platform in self.platforms:
platform.activate() platform.activate()
self.start_timeout_countdown()
def deactivate(self): def deactivate(self):
self.active = False self.active = False
@ -512,6 +514,7 @@ class LevelSelect(GameChild):
for level_index in range(3): for level_index in range(3):
self.platforms[level_index].view.unhide() self.platforms[level_index].view.unhide()
self.previews[level_index].unhide() self.previews[level_index].unhide()
self.halt()
def respond(self, event): def respond(self, event):
""" """
@ -539,8 +542,25 @@ class LevelSelect(GameChild):
""" """
self.launch(self.level_index_selected) self.launch(self.level_index_selected)
def start_timeout_countdown(self):
"""
Launch an animation on a delay that will reset the game after the delay. If the countdown is already active, reset the
countdown.
"""
print("start")
self.halt(self.timeout)
self.play(self.timeout, delay=self.get_configuration("time", "level-select-reset-countdown"), play_once=True)
def timeout(self):
"""
Reset to the title screen
"""
print("timeout")
self.get_game().wipe.start(self.get_game().reset, leave_wipe_running=True)
def update(self): def update(self):
if self.active: if self.active:
Animation.update(self)
self.get_game().logo.update() self.get_game().logo.update()
if self.level_index_selected is None: if self.level_index_selected is None:
for level_index, platform in enumerate(self.platforms): for level_index, platform in enumerate(self.platforms):
@ -569,6 +589,10 @@ class LevelSelect(GameChild):
rect.center = preview.location.center rect.center = preview.location.center
preview.update() preview.update()
self.get_display_surface().blit(frame, rect) self.get_display_surface().blit(frame, rect)
# If input in the player's platform detected reset the automatic game reset countdown
if self.get_game().platform.get_pressed():
print("reset")
self.start_timeout_countdown()
class Button(Sprite): class Button(Sprite):
@ -1193,6 +1217,7 @@ class Wipe(Animation):
Animation.__init__(self, parent) Animation.__init__(self, parent)
self.image = load(self.get_resource("Ink.png")).convert() self.image = load(self.get_resource("Ink.png")).convert()
self.sound = self.get_audio().sfx["wipe"] self.sound = self.get_audio().sfx["wipe"]
self.callback_kwargs = {}
def reset(self): def reset(self):
""" """
@ -1207,7 +1232,7 @@ class Wipe(Animation):
def activate(self): def activate(self):
self.active = True self.active = True
def start(self, callback): def start(self, callback, **kwargs):
""" """
Trigger the wipe animation to begin. The given callback function will be called when the screen is filled with the Trigger the wipe animation to begin. The given callback function will be called when the screen is filled with the
wipe graphic. wipe graphic.
@ -1218,6 +1243,7 @@ class Wipe(Animation):
self.up = True self.up = True
self.blind_height = self.get_display_surface().get_height() / self.BLIND_COUNT self.blind_height = self.get_display_surface().get_height() / self.BLIND_COUNT
self.callback = callback self.callback = callback
self.callback_kwargs = kwargs
self.play() self.play()
self.sound.play() self.sound.play()
@ -1230,7 +1256,7 @@ class Wipe(Animation):
self.blind_height -= self.SPEED self.blind_height -= self.SPEED
if self.blind_height <= 0: if self.blind_height <= 0:
self.up = False self.up = False
self.callback() self.callback(**self.callback_kwargs)
else: else:
self.blind_height += self.SPEED self.blind_height += self.SPEED
if self.blind_height >= self.get_display_surface().get_height() / self.BLIND_COUNT: if self.blind_height >= self.get_display_surface().get_height() / self.BLIND_COUNT:

1
config
View File

@ -61,6 +61,7 @@ sword-delay = 300
attract-gif-length = 10000 attract-gif-length = 10000
attract-board-length = 3600 attract-board-length = 3600
attract-reset-countdown = 30000 attract-reset-countdown = 30000
level-select-reset-countdown = 30000
[bgm] [bgm]
title = resource/bgm/title.ogg, .65 title = resource/bgm/title.ogg, .65

@ -1 +1 @@
Subproject commit f5de024ef3627a20191b0a36308ac8ad8a4e6e6c Subproject commit 7329aa76937b5fd225bb561459a2f5c70a57819d

View File

@ -0,0 +1,9 @@
52418 0
70979 0
78301 0
79581 0
98128 1
100960 1
113904 2
120571 2
122294 2