2 Widget that holds the games's bits.
7 from naja.constants import BIT_SIZE
8 from naja.resources import resources
9 from naja.resources.mutators import EIGHT_BIT
10 from naja.widgets.base import Widget
11 from naja.widgets.text import TextWidget
14 class GameBitsWidget(Widget):
16 Widget which holds the game's bits.
18 def __init__(self, pos, state):
19 super(GameBitsWidget, self).__init__(pos, BIT_SIZE)
23 self.surface = pygame.Surface(BIT_SIZE)
27 zero = TextWidget((0, 0), '0', fontsize=24, colour='white')
28 one = TextWidget((0, 0), '1', fontsize=24, colour='white')
30 zero.pos = (0, (size - zero.size[1]))
33 health = self.state.gameboard.health
34 max_health = self.state.gameboard.max_health
35 wins = self.state.gameboard.wins
36 wins_required = self.state.gameboard.wins_required
39 bits.extend((i < health, 'health') for i in range(max_health))
40 bits.extend((i < wins, 'win') for i in range(wins_required))
42 for pos, (is_set, image) in enumerate(bits):
43 img = resources.get_image(
44 'bits', '%s_%s.png' % (image, 'on' if is_set else 'off'),
45 transforms=(EIGHT_BIT,))
46 self.surface.blit(img, (img.get_width() * pos, 0))
48 one.render(self.surface)
50 zero.render(self.surface)
51 one.pos = zero.pos = (zero.pos[0] + size, zero.pos[1])
53 def draw(self, surface):
54 surface.blit(self.surface, self.pos)