Changeset 202:3074784c93f4


Ignore:
Timestamp:
Sep 4, 2009, 8:23:30 PM (11 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@203
Message:

Animation support

Location:
gamelib
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • gamelib/engine.py

    r183 r202  
    111111        # disable timer
    112112        pygame.time.set_timer(MOVE_FOX_ID, 0)
     113        pygame.time.set_timer(ANIM_ID, 50)
    113114        self.game.gameboard.advance_day()
    114115        self.game.gameboard.clear_foxes()
     
    122123            self.game.gameboard.reset_cursor()
    123124            return GameOver(self.game)
     125        elif e.type is ANIM_ID:
     126            self.game.gameboard.run_animations()
    124127        elif e.type is KEYDOWN and e.key == K_n:
    125128            return pygame.event.post(START_NIGHT)
     
    152155        self.cycle_count = 0
    153156        pygame.time.set_timer(MOVE_FOX_ID, 200)
     157        pygame.time.set_timer(ANIM_ID, 50)
    154158        self.game.gameboard.spawn_foxes()
    155159        sound.background_music("nighttime.ogg")
     
    167171            self.game.gameboard.reset_cursor()
    168172            return GameOver(self.game)
     173        elif e.type is ANIM_ID:
     174            self.game.gameboard.run_animations()
    169175        elif e.type is MOVE_FOX_ID:
    170176            self.cycle_count += 1
     
    195201        self.game.create_game_over()
    196202        pygame.time.set_timer(MOVE_FOX_ID, 0)
     203        pygame.time.set_timer(ANIM_ID, 0)
    197204
    198205    def event(self, e):
     
    225232GO_HELP_SCREEN = pygame.event.Event(USEREVENT, name="GO_HELP_SCREEN")
    226233MOVE_FOX_ID = USEREVENT + 1
     234ANIM_ID = USEREVENT + 6
    227235MOVE_FOXES = pygame.event.Event(MOVE_FOX_ID, name="MOVE_FOXES")
    228236QUIT = pygame.event.Event(QUIT)
  • gamelib/equipment.py

    r200 r202  
    44import sound
    55import imagecache
     6import animations
    67
    78class Equipment(object):
     
    5152        if hasattr(self, 'HIT_SOUND'):
    5253            sound.play_sound(self.HIT_SOUND)
     54        if hasattr(self, 'ANIMATION'):
     55            gameboard.animations.append(self.ANIMATION(wielder))
    5356        roll = random.randint(1, 100)
    5457        base_hit = self._get_parameter('BASE_HIT', wielder)
     
    7477
    7578    CHICKEN_IMAGE_FILE = 'sprites/equip_rifle.png'
     79
     80    ANIMATION = animations.MuzzleFlash
    7681
    7782class Knife(Weapon):
  • gamelib/gameboard.py

    r201 r202  
    150150    def paint(self, surface):
    151151        self.vid.paint(surface)
     152        # Blit animation frames on top of the drawing
     153        x, y = self.vid.view.x, self.vid.view.y
     154        for anim in self.gameboard.animations:
     155            anim.fix_pos(self.vid)
     156            anim.irect.x = anim.rect.x - anim.shape.x
     157            anim.irect.y = anim.rect.y - anim.shape.y
     158            surface.blit(anim.image, (anim.irect.x - x, anim.irect.y - y))
     159            # We don't store anim._irect, since we only update anims if the
     160            # image changes, which kills irect
    152161
    153162    def update(self, surface):
    154         return self.vid.update(surface)
     163        us = []
     164        x, y = self.vid.view.x, self.vid.view.y
     165        for anim in self.gameboard.animations[:]:
     166            """Handle completed animations"""
     167            if anim.removed:
     168                us.append(pygame.Rect(anim.irect.x - x, anim.irect.y - y,
     169                    anim.irect.width, anim.irect.height))
     170                self.gameboard.animations.remove(anim)
     171                # Flag the underlying tiles/sprites to be redrawn
     172                self.vid.alayer[anim.pos.y][anim.pos.x]=1
     173        us.extend(self.vid.update(surface))
     174        for anim in self.gameboard.animations:
     175            if anim.updated:
     176                anim.fix_pos(self.vid)
     177                # setimage has happened
     178                anim.irect.x = anim.rect.x - anim.shape.x
     179                anim.irect.y = anim.rect.y - anim.shape.y
     180                surface.blit(anim.image, (anim.irect.x - x, anim.irect.y - y))
     181                anim.updated = 0
     182                us.append(pygame.Rect(anim.irect.x - x, anim.irect.y - y,
     183                    anim.irect.width, anim.irect.height))
     184        return us
    155185
    156186    def move_view(self, x, y):
     
    187217        self.foxes = set()
    188218        self.buildings = []
     219        self.animations = []
    189220        self.cash = 0
    190221        self.eggs = 0
     
    593624                self.tv.sprites.remove(fox)
    594625        self.foxes = set() # Remove all the foxes
     626
     627    def run_animations(self):
     628        for anim in self.animations:
     629            anim.animate()
    595630
    596631    def move_foxes(self):
Note: See TracChangeset for help on using the changeset viewer.