Draw robot on the world
[naja.git] / naja / widgets / robot.py
1 """Widget to draw the player on the screen"""
2 import pygame
3 import pygame.locals as pgl
4
5 from naja.constants import PLAYER_SIZE, BIT_SIZE, TILE_SIZE, BITS
6 from naja.resources import resources
7 from naja.widgets.base import Widget
8
9 IMG_MAP = {
10         BITS.CYAN: 'board/robot_cyan.png',
11         BITS.YELLOW: 'board/robot_yellow.png',
12         BITS.MAGENTA: 'board/robot_magenta.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] + 32,
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] + 32,
27                     self.state.player.position[1] * TILE_SIZE[1] + BIT_SIZE[1])
28         self.surface = resources.get_image('board/robot.png')
29         for bit, img_name in IMG_MAP.iteritems():
30             if self.state.player.bits.check_bit(bit):
31                 bit_img = resources.get_image(img_name)
32                 self.surface.blit(bit_img, (0, 0))
33
34     def draw(self, surface):
35         surface.blit(self.surface, self.rect)