From c4bc36af488c23252855cf83dbd493e0e3b3590c Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Tue, 13 May 2014 16:06:16 +0200 Subject: [PATCH] Display 1s and 0s on the bits --- naja/widgets/game_bits.py | 14 ++++++++++++++ naja/widgets/player_bits.py | 17 ++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/naja/widgets/game_bits.py b/naja/widgets/game_bits.py index de6c6be..a78863c 100644 --- a/naja/widgets/game_bits.py +++ b/naja/widgets/game_bits.py @@ -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) diff --git a/naja/widgets/player_bits.py b/naja/widgets/player_bits.py index fff8b0d..df122c8 100644 --- a/naja/widgets/player_bits.py +++ b/naja/widgets/player_bits.py @@ -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) -- 2.34.1