X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=naja%2Fwidgets%2Fplayer_bits.py;h=6eeef0905ac0f0b0c76a048c0721aea253e7ab4e;hb=29c8196f7013ab28e4ad7628dd03c4b219ef465c;hp=0214bda757639235fd601605632ddd1821235e57;hpb=7ce9a5e2cbdc5a2dbdea5d000cad3e59628e9720;p=naja.git diff --git a/naja/widgets/player_bits.py b/naja/widgets/player_bits.py index 0214bda..6eeef09 100644 --- a/naja/widgets/player_bits.py +++ b/naja/widgets/player_bits.py @@ -2,20 +2,55 @@ Widget that holds the player's bits. """ -from .base import Widget -from naja.constants import BIT_SIZE +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 +from naja.widgets.text import TextWidget class PlayerBitsWidget(Widget): """ Widget which holds the player's bits. """ - def __init__(self, pos, image=None): + 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) + + size = BIT_SIZE[1] + + zero = TextWidget((0, 0), '0', fontsize=24, colour='white') + one = TextWidget((0, 0), '1', fontsize=24, colour='white') + zero.prepare() + zero.pos = (0, (size - zero.size[1])) + one.pos = zero.pos + + bits = ( + (BITS.MSB, 'msb', ()), + (BITS.RED, 'red', ()), + (BITS.GREEN, 'green', ()), + (BITS.BLUE, 'blue', ()), + (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, (size * pos, 0)) + if is_set: + one.render(self.surface) + else: + zero.render(self.surface) + one.pos = zero.pos = (zero.pos[0] + size, zero.pos[1]) def draw(self, surface): - pass - #surface.blit(self.surface, self.rect) + surface.blit(self.surface, self.pos)