More location deck things.
[naja.git] / naja / widgets / game_bits.py
index 875558cd76b068ffcf448cc2a7bb2c6bdbb6da74..973c2b80f20abd80f524d002554b173995977088 100644 (file)
@@ -2,21 +2,38 @@
 Widget that holds the games's bits.
 """
 
-from naja.constants import BIT_SIZE
+import pygame
 
-from .base import Widget
+from naja.constants import BIT_SIZE
+from naja.resources import resources
+from naja.resources.mutators import EIGHT_BIT
+from naja.widgets.base import Widget
 
 
 class GameBitsWidget(Widget):
     """
     Widget which holds the game's bits.
     """
-    def __init__(self, pos, image=None):
+    def __init__(self, pos, state):
         super(GameBitsWidget, self).__init__(pos, BIT_SIZE)
+        self.state = state
 
     def prepare(self):
-        pass
+        self.surface = pygame.Surface(BIT_SIZE)
+        health = self.state.gameboard.health
+        wins = self.state.gameboard.wins
+
+        bits = []
+        bits.extend(
+            (i < health, 'health', (EIGHT_BIT,)) for i in range(4))
+        bits.extend(
+            (i < wins, 'win', (EIGHT_BIT,)) for i in range(4))
+
+        for pos, (is_set, image, transforms) in enumerate(bits):
+            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)