Start on GameBits widget.
authorSimon Cross <hodgestar@gmail.com>
Sun, 11 May 2014 21:47:01 +0000 (23:47 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sun, 11 May 2014 21:47:48 +0000 (23:47 +0200)
naja/widgets/game_bits.py

index 21756586bf80276ea1ea28f072c81b252c22e81c..78f1ab91f488ef7ff275e7041ded574bc933f808 100644 (file)
@@ -5,6 +5,7 @@ Widget that holds the games's bits.
 import pygame
 
 from naja.constants import BIT_SIZE, BITS
+from naja.resources import resources
 from naja.widgets.base import Widget
 
 
@@ -18,6 +19,22 @@ class GameBitsWidget(Widget):
 
     def prepare(self):
         self.surface = pygame.Surface(BIT_SIZE)
+        bits = (
+            (BITS.MSB, 'msb', ()),
+            (BITS.YELLOW, 'yellow', ()),
+            (BITS.MAGENTA, 'magenta', ()),
+            (BITS.CYAN, 'cyan', ()),
+            (BITS.WEST, 'arrow', ()),
+            (BITS.EAST, 'arrow', ()),
+            (BITS.SOUTH, 'arrow', ()),
+            (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):
         surface.blit(self.surface, self.pos)