From: David Sharpe Date: Sat, 17 May 2014 11:00:36 +0000 (+0200) Subject: added animations X-Git-Tag: 0.1~98 X-Git-Url: https://git.ctpug.org.za/?p=naja.git;a=commitdiff_plain;h=79dcb11340635fa1f620909106c0d9a0788e3b89 added animations --- diff --git a/naja/widgets/tile.py b/naja/widgets/tile.py index db3ffb4..c932667 100644 --- a/naja/widgets/tile.py +++ b/naja/widgets/tile.py @@ -25,8 +25,10 @@ class TileWidget(Widget): def __init__(self, pos, state=None, board_pos=None): super(TileWidget, self).__init__(pos, TILE_SIZE) self.state = state + self.current_card = None self.board_pos = board_pos self.highlighted = False + self.animation = TILE_SIZE[0] def prepare(self): # Draw background @@ -55,6 +57,10 @@ class TileWidget(Widget): self.surface.blit(overlay, (0, 0)) # Look up the required bits on the board location card = self.state.board_locations[self.board_pos] + if card is not self.current_card: + self.animation = TILE_SIZE[0] + self.current_card = card + y_offset = TILE_SIZE[1] - LOCK_HEIGHT * len(card.actions) for action in card.actions: y_offset = self._prepare_action(action, y_offset) @@ -102,4 +108,12 @@ class TileWidget(Widget): self.highlighted = True def draw(self, surface): - surface.blit(self.surface, self.pos) + scaled_width = self.surface.get_width() - self.animation + scaled_height = self.surface.get_height() - self.animation + scaled_position = (self.pos[0] + (self.animation / 2), + self.pos[1] + (self.animation / 2)) + if self.animation > 0: + self.animation = max(0, self.animation - 4) + scaled_surface = pygame.transform.scale( + self.surface, (scaled_width, scaled_height)) + surface.blit(scaled_surface, scaled_position)