Display 1s and 0s on the bits
authorStefano Rivera <stefano@rivera.za.net>
Tue, 13 May 2014 14:06:16 +0000 (16:06 +0200)
committerStefano Rivera <stefano@rivera.za.net>
Tue, 13 May 2014 14:06:16 +0000 (16:06 +0200)
naja/widgets/game_bits.py
naja/widgets/player_bits.py

index de6c6be04608abc7cd5992ef3fafa777e7de6be8..a78863c6804de118d4796d0e42976d606c7388a3 100644 (file)
@@ -8,6 +8,7 @@ from naja.constants import BIT_SIZE
 from naja.resources import resources
 from naja.resources.mutators import EIGHT_BIT
 from naja.widgets.base import Widget
+from naja.widgets.text import TextWidget
 
 
 class GameBitsWidget(Widget):
@@ -21,6 +22,14 @@ class GameBitsWidget(Widget):
     def prepare(self):
         self.surface = pygame.Surface(BIT_SIZE)
 
+        size = BIT_SIZE[1]
+
+        zero = TextWidget((0, 0), '0', fontsize=24, colour='white')
+        one = TextWidget((0, 0), '1', fontsize=24, colour='white')
+        zero.prepare()
+        zero.pos = (0, (size - zero.size[1]))
+        one.pos = zero.pos
+
         health = self.state.gameboard.health
         max_health = self.state.gameboard.max_health
         wins = self.state.gameboard.wins
@@ -35,6 +44,11 @@ class GameBitsWidget(Widget):
                 'bits', '%s_%s.png' % (image, 'on' if is_set else 'off'),
                 transforms=(EIGHT_BIT,))
             self.surface.blit(img, (img.get_width() * pos, 0))
+            if is_set:
+                one.render(self.surface)
+            else:
+                zero.render(self.surface)
+            one.pos = zero.pos = (zero.pos[0] + size, zero.pos[1])
 
     def draw(self, surface):
         surface.blit(self.surface, self.pos)
index fff8b0dffaccea301471a9831f32e3888b4d1047..df122c8342a665c1e5533cbf894adfbf97a1a340 100644 (file)
@@ -8,6 +8,7 @@ from naja.constants import BIT_SIZE, BITS
 from naja.resources import resources
 from naja.resources.mutators import R90, R180, R270, EIGHT_BIT
 from naja.widgets.base import Widget
+from naja.widgets.text import TextWidget
 
 
 class PlayerBitsWidget(Widget):
@@ -20,6 +21,15 @@ class PlayerBitsWidget(Widget):
 
     def prepare(self):
         self.surface = pygame.Surface(BIT_SIZE)
+
+        size = BIT_SIZE[1]
+
+        zero = TextWidget((0, 0), '0', fontsize=24, colour='white')
+        one = TextWidget((0, 0), '1', fontsize=24, colour='white')
+        zero.prepare()
+        zero.pos = (0, (size - zero.size[1]))
+        one.pos = zero.pos
+
         bits = (
             (BITS.MSB, 'msb', ()),
             (BITS.YELLOW, 'yellow', ()),
@@ -35,7 +45,12 @@ class PlayerBitsWidget(Widget):
             img = resources.get_image(
                 'bits', '%s_%s.png' % (image, 'on' if is_set else 'off'),
                 transforms=transforms + (EIGHT_BIT,))
-            self.surface.blit(img, (img.get_width() * pos, 0))
+            self.surface.blit(img, (size * pos, 0))
+            if is_set:
+                one.render(self.surface)
+            else:
+                zero.render(self.surface)
+            one.pos = zero.pos = (zero.pos[0] + size, zero.pos[1])
 
     def draw(self, surface):
         surface.blit(self.surface, self.pos)