dispense with movement mode
[naja.git] / naja / widgets / robot.py
1 """Widget to draw the player on the screen"""
2
3 import pygame.locals as pgl
4
5 from naja.constants import (PLAYER_SIZE, BIT_SIZE, TILE_SIZE, BITS)
6 from naja.events import finish_event
7 from naja.resources import resources
8 from naja.resources.mutators import EIGHT_BIT
9 from naja.widgets.base import Widget
10
11 IMG_MAP = {
12         BITS.CYAN: 'board/robot_cyan.png',
13         BITS.YELLOW: 'board/robot_yellow.png',
14         BITS.MAGENTA: 'board/robot_magenta.png',
15         }
16
17
18 class RobotWidget(Widget):
19     """Widget which holds a tile on the game board."""
20     def __init__(self, state):
21         pos = (state.player.position[0] * TILE_SIZE[0],
22                state.player.position[1] * TILE_SIZE[1] + BIT_SIZE[1])
23         super(RobotWidget, self).__init__(pos, PLAYER_SIZE)
24         self.state = state
25
26     def prepare(self):
27         # Look up the required bits on the board location
28         self.pos = (self.state.player.position[0] * TILE_SIZE[0],
29                     self.state.player.position[1] * TILE_SIZE[1] + BIT_SIZE[1])
30         self.surface = resources.get_image('board/robot.png',
31                                            transforms=(EIGHT_BIT,)).copy()
32         for bit, img_name in IMG_MAP.iteritems():
33             if self.state.player.bits.check_bit(bit):
34                 bit_img = resources.get_image(img_name,
35                                               transforms=(EIGHT_BIT,))
36                 self.surface.blit(bit_img, (0, 0))
37
38     def draw(self, surface):
39         surface.blit(self.surface, self.rect)