Mercurial > skaapsteker
changeset 116:69a97094417a
Hook up per-tick sprite animations.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Mon, 04 Apr 2011 21:54:42 +0200 |
parents | b73724bb93f8 |
children | b361d9e17c26 |
files | skaapsteker/physics.py skaapsteker/sprites/player.py |
diffstat | 2 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/skaapsteker/physics.py Mon Apr 04 21:45:59 2011 +0200 +++ b/skaapsteker/physics.py Mon Apr 04 21:54:42 2011 +0200 @@ -27,6 +27,9 @@ collision_layer = None # never collides with anything collides_with = set() # nothing collides with this + # set to True to have .update() called once per tick + wants_updates = False + def __init__(self, *args, **kwargs): super(Sprite, self).__init__(*args, **kwargs) self.velocity = (0.0, 0.0) @@ -81,6 +84,9 @@ v_y = (1.0 - normal[1] * b_y) * v_y self.velocity = v_x, v_y + def update(self): + pass # only called in wants_update = True + class World(object): @@ -90,6 +96,7 @@ self._all = pygame.sprite.LayeredUpdates() self._mobiles = pygame.sprite.Group() self._gravitators = pygame.sprite.Group() + self._updaters = pygame.sprite.Group() self._collision_groups = { None: pygame.sprite.Group() } self._last_time = None @@ -106,6 +113,8 @@ self._mobiles.add(sprite) if sprite.gravitates: self._gravitators.add(sprite) + if sprite.wants_updates: + self._updaters.add(sprite) self._add_collision_group(sprite.collision_layer) for layer in sprite.collides_with: self._add_collision_group(layer) @@ -163,6 +172,9 @@ if collisions: self._backout_collisions(sprite, collisions, dt) + # call update methods + self._updaters.update() + def draw(self, surface): self._all.draw(surface) if options['debug_rects']:
--- a/skaapsteker/sprites/player.py Mon Apr 04 21:45:59 2011 +0200 +++ b/skaapsteker/sprites/player.py Mon Apr 04 21:54:42 2011 +0200 @@ -13,6 +13,7 @@ collision_layer = PC_LAYER collides_with = set([MONSTER_LAYER]) + wants_updates = True def __init__(self): Sprite.__init__(self) @@ -35,6 +36,9 @@ # TODO: handle animations self.image = self._image_dict[key][0] + def update(self): + pass # animate tail here + def set_facing(self, new_facing): self.facing = new_facing