fixed robot's msb flag
[naja.git] / naja / widgets / robot.py
1 """Widget to draw the player on the screen"""
2
3 from naja.constants import (PLAYER_SIZE, BIT_SIZE, TILE_SIZE, BITS)
4 from naja.resources import resources
5 from naja.resources.mutators import EIGHT_BIT
6 from naja.widgets.base import Widget
7
8 IMG_MAP = {
9     BITS.MSB: 'board/robot_msb.png',
10     BITS.RED: 'board/robot_red.png',
11     BITS.GREEN: 'board/robot_green.png',
12     BITS.BLUE: 'board/robot_blue.png',
13 }
14
15
16 class RobotWidget(Widget):
17     """Widget which holds a tile on the game board."""
18     def __init__(self, state):
19         pos = (state.player.position[0] * TILE_SIZE[0],
20                state.player.position[1] * TILE_SIZE[1] + BIT_SIZE[1])
21         super(RobotWidget, self).__init__(pos, PLAYER_SIZE)
22         self.state = state
23
24     def prepare(self):
25         # Look up the required bits on the board location
26         self.pos = (self.state.player.position[0] * TILE_SIZE[0],
27                     self.state.player.position[1] * TILE_SIZE[1] + BIT_SIZE[1])
28         self.surface = resources.get_image('board/robot.png',
29                                            transforms=(EIGHT_BIT,)).copy()
30         for bit, img_name in IMG_MAP.iteritems():
31             if self.state.player.bits.check_bit(bit):
32                 bit_img = resources.get_image(img_name,
33                                               transforms=(EIGHT_BIT,))
34                 self.surface.blit(bit_img, (0, 0))
35
36     def draw(self, surface):
37         surface.blit(self.surface, self.rect)