Ensure that the flash starts ON after ever mode change
authorStefano Rivera <stefano@rivera.za.net>
Sat, 17 May 2014 23:42:47 +0000 (01:42 +0200)
committerStefano Rivera <stefano@rivera.za.net>
Sat, 17 May 2014 23:42:47 +0000 (01:42 +0200)
naja/utils.py
naja/widgets/board.py
naja/widgets/info_area.py

index 7ad4f582c2188a9c6fdcc914fa535eddd70fdc3f..925442a7a12eef328f723b40f026070a37214f7d 100644 (file)
@@ -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
index e6eafa5e8a429468f39fcfe51b70927b68ef0160..f7f8384198f8ae64023ae392bc5a091098152762 100644 (file)
@@ -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:
index b4c6e2b2a66208b522d638928eddc300f9118399..4a545c04de7067adef6bafffb64e6f7b9268db95 100644 (file)
@@ -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: