2 Widget that holds the player's bits.
7 from naja.constants import BIT_SIZE, BITS
8 from naja.resources import resources
9 from naja.resources.mutators import R90, R180, R270, EIGHT_BIT
10 from naja.widgets.base import Widget
13 class PlayerBitsWidget(Widget):
15 Widget which holds the player's bits.
17 def __init__(self, pos, state):
18 super(PlayerBitsWidget, self).__init__(pos, BIT_SIZE)
22 self.surface = pygame.Surface(BIT_SIZE)
24 (BITS.MSB, 'msb', ()),
25 (BITS.YELLOW, 'yellow', ()),
26 (BITS.MAGENTA, 'magenta', ()),
27 (BITS.CYAN, 'cyan', ()),
28 (BITS.WEST, 'arrow', (R90,)),
29 (BITS.EAST, 'arrow', (R270,)),
30 (BITS.SOUTH, 'arrow', (R180,)),
31 (BITS.NORTH, 'arrow', ()),
33 for pos, (bit, image, transforms) in enumerate(bits):
34 is_set = self.state.player.bits.check_bit(bit)
35 img = resources.get_image(
36 'bits', '%s_%s.png' % (image, 'on' if is_set else 'off'),
37 transforms=transforms + (EIGHT_BIT,))
38 self.surface.blit(img, (img.get_width() * pos, 0))
40 def draw(self, surface):
41 surface.blit(self.surface, self.pos)