Changeset 116:69a97094417a


Ignore:
Timestamp:
Apr 4, 2011, 7:54:42 PM (9 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Message:

Hook up per-tick sprite animations.

Location:
skaapsteker
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/physics.py

    r112 r116  
    2727    collision_layer = None # never collides with anything
    2828    collides_with = set() # nothing collides with this
     29
     30    # set to True to have .update() called once per tick
     31    wants_updates = False
    2932
    3033    def __init__(self, *args, **kwargs):
     
    8285        self.velocity = v_x, v_y
    8386
     87    def update(self):
     88        pass # only called in wants_update = True
     89
    8490
    8591class World(object):
     
    9197        self._mobiles = pygame.sprite.Group()
    9298        self._gravitators = pygame.sprite.Group()
     99        self._updaters = pygame.sprite.Group()
    93100        self._collision_groups = { None: pygame.sprite.Group() }
    94101        self._last_time = None
     
    107114        if sprite.gravitates:
    108115            self._gravitators.add(sprite)
     116        if sprite.wants_updates:
     117            self._updaters.add(sprite)
    109118        self._add_collision_group(sprite.collision_layer)
    110119        for layer in sprite.collides_with:
     
    164173                self._backout_collisions(sprite, collisions, dt)
    165174
     175        # call update methods
     176        self._updaters.update()
     177
    166178    def draw(self, surface):
    167179        self._all.draw(surface)
  • skaapsteker/sprites/player.py

    r115 r116  
    1414    collision_layer = PC_LAYER
    1515    collides_with = set([MONSTER_LAYER])
     16    wants_updates = True
    1617
    1718    def __init__(self):
     
    3536        # TODO: handle animations
    3637        self.image = self._image_dict[key][0]
     38
     39    def update(self):
     40        pass # animate tail here
    3741
    3842    def set_facing(self, new_facing):
Note: See TracChangeset for help on using the changeset viewer.