Use EIGHT_BIT for game bits.
[naja.git] / naja / widgets / game_bits.py
1 """
2 Widget that holds the games's bits.
3 """
4
5 import pygame
6
7 from naja.constants import BIT_SIZE
8 from naja.resources import resources
9 from naja.resources.mutators import EIGHT_BIT
10 from naja.widgets.base import Widget
11
12
13 class GameBitsWidget(Widget):
14     """
15     Widget which holds the game's bits.
16     """
17     def __init__(self, pos, state):
18         super(GameBitsWidget, self).__init__(pos, BIT_SIZE)
19         self.state = state
20
21     def prepare(self):
22         self.surface = pygame.Surface(BIT_SIZE)
23         health = self.state.gameboard.health
24         wins = self.state.gameboard.wins
25
26         bits = []
27         bits.extend(
28             (i < health, 'health', (EIGHT_BIT,)) for i in range(4))
29         bits.extend(
30             (i < wins, 'win', (EIGHT_BIT,)) for i in range(4))
31
32         for pos, (is_set, image, transforms) in enumerate(bits):
33             img = resources.get_image(
34                 'bits', '%s_%s.png' % (image, 'on' if is_set else 'off'),
35                 transforms=transforms)
36             self.surface.blit(img, (img.get_width() * pos, 0))
37
38     def draw(self, surface):
39         surface.blit(self.surface, self.pos)