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
13 class GameBitsWidget(Widget):
15 Widget which holds the game's bits.
17 def __init__(self, pos, state):
18 super(GameBitsWidget, self).__init__(pos, BIT_SIZE)
22 self.surface = pygame.Surface(BIT_SIZE)
24 health = self.state.gameboard.health
25 max_health = self.state.gameboard.max_health
26 wins = self.state.gameboard.wins
27 wins_required = self.state.gameboard.wins_required
30 bits.extend((i < health, 'health') for i in range(max_health))
31 bits.extend((i < wins, 'win') for i in range(wins_required))
33 for pos, (is_set, image) in enumerate(bits):
34 img = resources.get_image(
35 'bits', '%s_%s.png' % (image, 'on' if is_set else 'off'),
36 transforms=(EIGHT_BIT,))
37 self.surface.blit(img, (img.get_width() * pos, 0))
39 def draw(self, surface):
40 surface.blit(self.surface, self.pos)