From: Stefano Rivera Date: Sat, 17 May 2014 23:42:47 +0000 (+0200) Subject: Ensure that the flash starts ON after ever mode change X-Git-Tag: 0.1~6 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=9ff6979c6cafe70ff36ceb9010048b7da4174bbc;p=naja.git Ensure that the flash starts ON after ever mode change --- diff --git a/naja/utils.py b/naja/utils.py index 7ad4f58..925442a 100644 --- a/naja/utils.py +++ b/naja/utils.py @@ -42,8 +42,7 @@ def warp_to_game_state(game_state): class Flashlight(object): def __init__(self, rate): self.rate = rate - self.ticks = 0 - self.on = False + self.reset() def tick(self): self.ticks += 1 @@ -52,3 +51,7 @@ class Flashlight(object): self.ticks = 0 return True return False + + def reset(self): + self.ticks = 0 + self.on = True diff --git a/naja/widgets/board.py b/naja/widgets/board.py index e6eafa5..f7f8384 100644 --- a/naja/widgets/board.py +++ b/naja/widgets/board.py @@ -4,7 +4,7 @@ Widget that holds the game tiles. import pygame.locals as pgl from naja.constants import BOARD_SIZE, TILE_SIZE, KEYS, ACT, FPS -from naja.events import finish_event +from naja.events import InvalidateTheWorld, finish_event from naja.sound import sound from naja.widgets.base import Widget @@ -71,6 +71,8 @@ class BoardWidget(Widget): tile.animation = 0 def handle_event(self, ev): + if InvalidateTheWorld.matches(ev): + self.flash_light.reset() if self.state.gameboard.player_mode == ACT: return super(BoardWidget, self).handle_event(ev) if ev.type == pgl.KEYDOWN: diff --git a/naja/widgets/info_area.py b/naja/widgets/info_area.py index b4c6e2b..4a545c0 100644 --- a/naja/widgets/info_area.py +++ b/naja/widgets/info_area.py @@ -8,7 +8,7 @@ from naja.constants import ( INFO_SIZE, ACT, KEYS, EXAMINE, PALETTE, ACTION_TEXT_OFFSET, INFO_LEFT_PADDING, INFO_RIGHT_PADDING, BIT_SIZE, BITS) -from naja.events import finish_event +from naja.events import InvalidateTheWorld, finish_event from naja.resources import resources from naja.resources.mutators import EIGHT_BIT, blender from naja.sound import sound @@ -221,6 +221,8 @@ class InfoAreaWidget(Widget): self.set_position(player.position) def handle_event(self, ev): + if InvalidateTheWorld.matches(ev): + self.flash_light.reset() if self.state.gameboard.player_mode == EXAMINE: return super(InfoAreaWidget, self).handle_event(ev) if ev.type == pgl.KEYDOWN: