From 7ce9a5e2cbdc5a2dbdea5d000cad3e59628e9720 Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 11 May 2014 19:02:46 +0200 Subject: [PATCH] Add tiles to the board. Skip draw for other game scene widgets for now --- naja/constants.py | 4 ++++ naja/widgets/board.py | 21 +++++++++++++++++---- naja/widgets/game_bits.py | 7 +++++-- naja/widgets/info_area.py | 7 +++++-- naja/widgets/player_bits.py | 6 ++++-- naja/widgets/tile.py | 5 +++-- 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/naja/constants.py b/naja/constants.py index d8087d6..d7e023a 100644 --- a/naja/constants.py +++ b/naja/constants.py @@ -36,4 +36,8 @@ BITS = AttrDict({ DIRECTION_BITS = AttrDict((k, v) for k, v in BITS.items() if v < 4) CONDITION_BITS = AttrDict((k, v) for k, v in BITS.items() if v >= 4) +# Game size constants TILE_SIZE = (96, 96) +BOARD_SIZE = (5 * TILE_SIZE[0], 5 * TILE_SIZE[1]) +BIT_SIZE = (5 * TILE_SIZE[0], (SCREEN[1] - 5 * TILE_SIZE[1]) // 2) +INFO_SIZE = (SCREEN[0] - 5 * TILE_SIZE[0], SCREEN[1]) diff --git a/naja/widgets/board.py b/naja/widgets/board.py index c791a57..1f59f01 100644 --- a/naja/widgets/board.py +++ b/naja/widgets/board.py @@ -2,18 +2,31 @@ Widget that holds the game tiles. """ +from naja.constants import BOARD_SIZE, TILE_SIZE + from .base import Widget +from .tile import TileWidget class BoardWidget(Widget): """ Widget which holds all the tiles that make up the gameboard. """ - def __init__(self, pos, image=None): - super(BoardWidget, self).__init__(pos, (96, 96)) + def __init__(self, pos, tiles=None): + super(BoardWidget, self).__init__(pos, BOARD_SIZE) + # FIXME: Placeholder logic + self._tiles = [] + for y in range(0, 5): + for x in range(0, 5): + tile_pos = (pos[0] + x * TILE_SIZE[0], + pos[1] + y * TILE_SIZE[1]) + self._tiles.append(TileWidget(tile_pos, None)) def prepare(self): - pass + for tile in self._tiles: + tile.prepare() + self.size = BOARD_SIZE def draw(self, surface): - surface.blit(self.surface, self.rect) + for tile in self._tiles: + tile.draw(surface) diff --git a/naja/widgets/game_bits.py b/naja/widgets/game_bits.py index 54fa683..875558c 100644 --- a/naja/widgets/game_bits.py +++ b/naja/widgets/game_bits.py @@ -2,6 +2,8 @@ Widget that holds the games's bits. """ +from naja.constants import BIT_SIZE + from .base import Widget @@ -10,10 +12,11 @@ class GameBitsWidget(Widget): Widget which holds the game's bits. """ def __init__(self, pos, image=None): - super(GameBitsWidget, self).__init__(pos, (96, 96)) + super(GameBitsWidget, self).__init__(pos, BIT_SIZE) def prepare(self): pass def draw(self, surface): - surface.blit(self.surface, self.rect) + pass + #surface.blit(self.surface, self.rect) diff --git a/naja/widgets/info_area.py b/naja/widgets/info_area.py index 2f93311..2a9b50f 100644 --- a/naja/widgets/info_area.py +++ b/naja/widgets/info_area.py @@ -2,6 +2,8 @@ Widget for the game board information area. """ +from naja.constants import INFO_SIZE + from .base import Widget @@ -10,10 +12,11 @@ class InfoAreaWidget(Widget): Widget for the game board information area. """ def __init__(self, pos, image=None): - super(InfoAreaWidget, self).__init__(pos, (96, 96)) + super(InfoAreaWidget, self).__init__(pos, INFO_SIZE) def prepare(self): pass def draw(self, surface): - surface.blit(self.surface, self.rect) + pass + #surface.blit(self.surface, self.rect) diff --git a/naja/widgets/player_bits.py b/naja/widgets/player_bits.py index e82f173..0214bda 100644 --- a/naja/widgets/player_bits.py +++ b/naja/widgets/player_bits.py @@ -3,6 +3,7 @@ Widget that holds the player's bits. """ from .base import Widget +from naja.constants import BIT_SIZE class PlayerBitsWidget(Widget): @@ -10,10 +11,11 @@ class PlayerBitsWidget(Widget): Widget which holds the player's bits. """ def __init__(self, pos, image=None): - super(PlayerBitsWidget, self).__init__(pos, (96, 96)) + super(PlayerBitsWidget, self).__init__(pos, BIT_SIZE) def prepare(self): pass def draw(self, surface): - surface.blit(self.surface, self.rect) + pass + #surface.blit(self.surface, self.rect) diff --git a/naja/widgets/tile.py b/naja/widgets/tile.py index db20cda..1950996 100644 --- a/naja/widgets/tile.py +++ b/naja/widgets/tile.py @@ -1,7 +1,8 @@ from naja.constants import TILE_SIZE -from naja.widgets.base import Widget from naja.resources import resources +from .base import Widget + # These will probably need to go away when we have images import pygame import pygame.locals as pgl @@ -15,7 +16,7 @@ class TileWidget(Widget): def prepare(self): # Placeholder logic - just draw the outline of a square - self.surface = pygame.surface.Surface(self.size) + self.surface = pygame.surface.Surface(TILE_SIZE) pygame.draw.lines(self.surface, pgl.color.THECOLORS['yellow'], True, [(1, 1), (1, 95), (95, 95), (95, 1)], 2) self.surface.convert_alpha(pygame.display.get_surface()) -- 2.34.1