Merge branch 'master' of git://ctpug.org.za/naja
authorDavid Sharpe <decoydavid@gmail.com>
Sat, 17 May 2014 22:16:44 +0000 (00:16 +0200)
committerDavid Sharpe <decoydavid@gmail.com>
Sat, 17 May 2014 22:16:44 +0000 (00:16 +0200)
data/images/board/tile_selected_pulse.png [new file with mode: 0644]
data/location_decks/introduction.yaml
naja/utils.py
naja/widgets/board.py
naja/widgets/info_area.py
naja/widgets/tile.py
sources/images/square.xcf

diff --git a/data/images/board/tile_selected_pulse.png b/data/images/board/tile_selected_pulse.png
new file mode 100644 (file)
index 0000000..39bfadb
Binary files /dev/null and b/data/images/board/tile_selected_pulse.png differ
index 89a67fe67b303f690b7d99f890f22c613e5c1fb8..6f289233f82a4fae9f112d5d2b284e00e4d40c61 100644 (file)
@@ -30,13 +30,13 @@ _action_definitions:
     action_class: 'SetBits'
     required_bits: []
     data:
-      message: "Moving to a tile requires picking an action. Some tiles' actions set bits on your robot. Such as the {SOUTH} bit."
+      message: "Moving to a tile requires picking an action. This tile has 2 actions. Both this tile's actions set bits on your robot, the {SOUTH} bit."
 
   - &STEP2-ACTION-NULL
     action_class: 'SetBits'
     required_bits: []
     data:
-      message: "So does this one. See, we gave you a choice!"
+      message: "This is the second choice."
 
   - &STEP2-CARD
     card_name: 'step2'
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
index b2a93fa8e0baa6a5fffa5cc3ba9b1b62e9ccac7e..e6eafa5e8a429468f39fcfe51b70927b68ef0160 100644 (file)
@@ -3,12 +3,13 @@ Widget that holds the game tiles.
 """
 import pygame.locals as pgl
 
-from naja.constants import BOARD_SIZE, TILE_SIZE, KEYS, ACT
+from naja.constants import BOARD_SIZE, TILE_SIZE, KEYS, ACT, FPS
 from naja.events import finish_event
 from naja.sound import sound
 
 from naja.widgets.base import Widget
 from naja.widgets.tile import TileWidget
+from naja.utils import Flashlight
 
 
 class BoardWidget(Widget):
@@ -22,6 +23,7 @@ class BoardWidget(Widget):
         self.card_pos = state.player.position
         self._tiles = []
         self.legal = False
+        self.flash_light = Flashlight(FPS // 2)
         for y in range(0, 5):
             for x in range(0, 5):
                 tile_pos = (pos[0] + x * TILE_SIZE[0],
@@ -30,13 +32,15 @@ class BoardWidget(Widget):
 
     def prepare(self):
         for tile in self._tiles:
-            tile.set_highlight(self.card_pos)
+            tile.set_highlight(self.card_pos, self.flash_light.on)
             tile.prepare()
         self.size = BOARD_SIZE
         if self.state.gameboard.player_mode == ACT:
             self.card_pos = self.state.player.position
 
     def draw(self, surface):
+        if self.flash_light.tick():
+            self.prepare()
         for tile in self._tiles:
             tile.draw(surface)
 
index 1ff6bbbd92168e52ec12c4a489cf6f54638f95a7..fd470387e6b994a2d15eace94df7df8c22892274 100644 (file)
@@ -12,11 +12,11 @@ from naja.events import finish_event
 from naja.resources import resources
 from naja.resources.mutators import EIGHT_BIT, blender
 from naja.sound import sound
-from naja.utils import bit_glyphs
+from naja.utils import bit_glyphs, Flashlight
 
 from naja.widgets.base import Widget
 from naja.widgets.tile import BIT_MAP
-from naja.widgets.text import TextBoxWidget, TextWidget
+from naja.widgets.text import TextBoxWidget
 from naja import constants
 
 
@@ -44,8 +44,7 @@ class InfoAreaWidget(Widget):
         self.chosen = None
         self.card_position = state.player.position
         self.set_position(state.player.position)
-        self.flash_count = 0
-        self.flash_light = True
+        self.flash_light = Flashlight(constants.FPS // 2)
 
     def prepare(self):
         if self.state.gameboard.player_mode == ACT:
@@ -131,7 +130,7 @@ class InfoAreaWidget(Widget):
 
         border_colour = None
         if choice == self.chosen:
-            if self.flash_light:
+            if self.flash_light.on:
                 border_colour = (PALETTE.GREEN if action_viable else
                                  PALETTE.ORANGE)
             else:
@@ -188,10 +187,7 @@ class InfoAreaWidget(Widget):
             self.chosen = None
 
     def draw(self, surface):
-        self.flash_count += 1
-        if self.flash_count >= (constants.FPS // 2):
-            self.flash_light = not self.flash_light
-            self.flash_count = 0
+        if self.flash_light.tick():
             self.prepare()
         surface.blit(self.surface, self.pos)
 
index 06a0f78a3baaceca3047c8e40af29f38b07b46ef..9278e8419fefc60e719e9dfe201e04eac01fe1cc 100644 (file)
@@ -28,6 +28,7 @@ class TileWidget(Widget):
         self.current_card = None
         self.board_pos = board_pos
         self.highlighted = False
+        self.bright = False
         self.animation = TILE_SIZE[0]
 
     def prepare(self):
@@ -56,10 +57,12 @@ class TileWidget(Widget):
             overlays.append(resources.get_image(
                 tile_available_name, transforms=(EIGHT_BIT,)))
         if self.highlighted:
+            if self.bright:
+                select_name = 'board/tile_selected_pulse.png'
+            else:
+                select_name = 'board/tile_selected.png'
             overlays.append(resources.get_image(
-                'board/tile_selected.png',
-                transforms=(EIGHT_BIT,)))
-
+                select_name, transforms=(EIGHT_BIT,)))
         self.surface = pygame.surface.Surface(TILE_SIZE)
         self.surface.blit(bg, (0, 0))
         for overlay in overlays:
@@ -141,8 +144,9 @@ class TileWidget(Widget):
                 x_offset += img.get_width()
         return y_offset + LOCK_HEIGHT
 
-    def set_highlight(self, pos):
+    def set_highlight(self, pos, bright=False):
         self.highlighted = False
+        self.bright = bright
         if (self.state.gameboard.player_mode == EXAMINE and
                 self.board_pos == pos):
             self.highlighted = True
index 05a1503ff6156877ba339ec812b1f16289bad9b4..eca05bddc210f531e6570a1ff68c7d21d5b8b714 100644 (file)
Binary files a/sources/images/square.xcf and b/sources/images/square.xcf differ