Factor out flash light into utils.
[naja.git] / naja / utils.py
index d5d17cc6067276a8649369c625893872388760fe..7ad4f582c2188a9c6fdcc914fa535eddd70fdc3f 100644 (file)
@@ -37,3 +37,18 @@ def warp_to_game_state(game_state):
     from naja.scenes.game import GameScene
     LoadGameEvent.post(game_state)
     SceneChangeEvent.post(GameScene)
+
+
+class Flashlight(object):
+    def __init__(self, rate):
+        self.rate = rate
+        self.ticks = 0
+        self.on = False
+
+    def tick(self):
+        self.ticks += 1
+        if self.ticks >= self.rate:
+            self.on = not self.on
+            self.ticks = 0
+            return True
+        return False