Widget that holds the player's bits.
"""
-from .base import Widget
+import pygame
+
+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
class PlayerBitsWidget(Widget):
"""
Widget which holds the player's bits.
"""
- def __init__(self, pos, image=None):
- super(PlayerBitsWidget, self).__init__(pos, (96, 96))
+ def __init__(self, pos, state):
+ super(PlayerBitsWidget, self).__init__(pos, BIT_SIZE)
+ self.state = state
def prepare(self):
- pass
+ self.surface = pygame.Surface(BIT_SIZE)
+ bits = (
+ (BITS.MSB, 'msb', ()),
+ (BITS.YELLOW, 'yellow', ()),
+ (BITS.MAGENTA, 'magenta', ()),
+ (BITS.CYAN, 'cyan', ()),
+ (BITS.WEST, 'arrow', (R90,)),
+ (BITS.EAST, 'arrow', (R270,)),
+ (BITS.SOUTH, 'arrow', (R180,)),
+ (BITS.NORTH, 'arrow', ()),
+ )
+ for pos, (bit, image, transforms) in enumerate(bits):
+ is_set = self.state.player.bits.check_bit(bit)
+ 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))
def draw(self, surface):
- surface.blit(self.surface, self.rect)
+ surface.blit(self.surface, self.pos)