Scale up images
[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.resources.mutators import EIGHT_BIT
8 from naja.widgets.base import Widget
9
10 IMG_MAP = {
11         BITS.CYAN: 'board/robot_cyan.png',
12         BITS.YELLOW: 'board/robot_yellow.png',
13         BITS.MAGENTA: 'board/robot_magenta.png',
14         }
15
16
17 class RobotWidget(Widget):
18     """Widget which holds a tile on the game board."""
19     def __init__(self, state):
20         pos = (state.player.position[0] * TILE_SIZE[0] + 32,
21                state.player.position[1] * TILE_SIZE[1] + BIT_SIZE[1])
22         super(RobotWidget, self).__init__(pos, PLAYER_SIZE)
23         self.state = state
24
25     def prepare(self):
26         # Look up the required bits on the board location
27         self.pos = (self.state.player.position[0] * TILE_SIZE[0] + 32,
28                     self.state.player.position[1] * TILE_SIZE[1] + BIT_SIZE[1])
29         self.surface = resources.get_image('board/robot.png',
30                                            transforms=(EIGHT_BIT,))
31         for bit, img_name in IMG_MAP.iteritems():
32             if self.state.player.bits.check_bit(bit):
33                 bit_img = resources.get_image(img_name,
34                                               transforms=(EIGHT_BIT,))
35                 self.surface.blit(bit_img, (0, 0))
36
37     def draw(self, surface):
38         surface.blit(self.surface, self.rect)