working PlayerBitsWidget
authorStefano Rivera <stefano@rivera.za.net>
Sun, 11 May 2014 21:34:25 +0000 (23:34 +0200)
committerStefano Rivera <stefano@rivera.za.net>
Sun, 11 May 2014 21:34:25 +0000 (23:34 +0200)
naja/scenes/game.py
naja/widgets/player_bits.py

index 54368cbcd99a330324e34af5cb0937855275c456..f3db806a1403c4a6eee582066402cb614668b6bf 100644 (file)
@@ -20,7 +20,7 @@ class GameScene(Scene):
 
     def __init__(self, state):
         super(GameScene, self).__init__(state)
-        self.add(PlayerBitsWidget((0, 0)))
+        self.add(PlayerBitsWidget((0, 0), state))
         self.add(BoardWidget((0, 60), state))
         self.add(GameBitsWidget((0, 540)))
         self.add(InfoAreaWidget((480, 0)))
index 70d5d1183a480c25f05d4e6a6fe17799f142ba51..bdb7695637c9879cb7c4c2d410fab08f51f0d3b8 100644 (file)
@@ -2,7 +2,11 @@
 Widget that holds the player's bits.
 """
 
-from naja.constants import BIT_SIZE
+import pygame
+
+from naja.constants import BIT_SIZE, BITS
+from naja.resources import resources
+from naja.resources.mutators import R90, R180, R270
 from naja.widgets.base import Widget
 
 
@@ -10,12 +14,28 @@ class PlayerBitsWidget(Widget):
     """
     Widget which holds the player's bits.
     """
-    def __init__(self, pos, image=None):
+    def __init__(self, pos, state):
         super(PlayerBitsWidget, self).__init__(pos, BIT_SIZE)
+        self.state = state
 
     def prepare(self):
-        pass
+        self.surface = pygame.Surface(BIT_SIZE)
+        bits = (
+            (BITS.MSB, 'msb', ()),
+            (BITS.YELLOW, 'yellow', ()),
+            (BITS.MAGENTA, 'magenta', ()),
+            (BITS.CYAN, 'cyan', ()),
+            (BITS.WEST, 'arrow', (R90,)),
+            (BITS.EAST, 'arrow', (R270,)),
+            (BITS.SOUTH, 'arrow', (R180,)),
+            (BITS.NORTH, 'arrow', ()),
+        )
+        for pos, (bit, image, transforms) in enumerate(bits):
+            is_set = self.state.player.bits.check_bit(bit)
+            img = resources.get_image(
+                'bits', '%s_%s.png' % (image, 'on' if is_set else 'off'),
+                transforms=transforms)
+            self.surface.blit(img, (img.get_width() * pos, 0))
 
     def draw(self, surface):
-        pass
-        #surface.blit(self.surface, self.rect)
+        surface.blit(self.surface, self.pos)