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
11 from naja.widgets.text import TextWidget
14 class PlayerBitsWidget(Widget):
16 Widget which holds the player's bits.
18 def __init__(self, pos, state):
19 super(PlayerBitsWidget, 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]))
34 (BITS.MSB, 'msb', ()),
35 (BITS.RED, 'red', ()),
36 (BITS.GREEN, 'green', ()),
37 (BITS.BLUE, 'blue', ()),
38 (BITS.WEST, 'arrow', (R90,)),
39 (BITS.EAST, 'arrow', (R270,)),
40 (BITS.SOUTH, 'arrow', (R180,)),
41 (BITS.NORTH, 'arrow', ()),
43 for pos, (bit, image, transforms) in enumerate(bits):
44 is_set = self.state.player.bits.check_bit(bit)
45 img = resources.get_image(
46 'bits', '%s_%s.png' % (image, 'on' if is_set else 'off'),
47 transforms=transforms + (EIGHT_BIT,))
48 self.surface.blit(img, (size * pos, 0))
50 one.render(self.surface)
52 zero.render(self.surface)
53 one.pos = zero.pos = (zero.pos[0] + size, zero.pos[1])
55 def draw(self, surface):
56 surface.blit(self.surface, self.pos)