Mercurial > skaapsteker
changeset 626:1abb53ae1a6a
More mild refactoring.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 07 May 2011 17:29:10 +0200 |
parents | 65882990b9cf |
children | 35919d12b792 |
files | skaapsteker/physics.py |
diffstat | 1 files changed, 19 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/skaapsteker/physics.py Sat May 07 15:39:38 2011 +0200 +++ b/skaapsteker/physics.py Sat May 07 17:29:10 2011 +0200 @@ -252,17 +252,7 @@ self._last_time = now return dt - def update(self): - if self._last_time is None: - self._last_time = time.time() - return - - dt = self.get_dt() - - self.apply_gravity(dt) - self.apply_friction() - self.handle_escaped_sprites() - + def update_sprite_positions(self, dt): # position update and collision check (do last) for sprite in self._mobiles: sprite.apply_velocity(dt) @@ -279,23 +269,26 @@ (sprite.collide_rect.width, 1)) collides = contact_rect.colliderect floors = [] - if sprite.on_solid: - # Check if we are still in contact with the ground - still_on_solid = False - for other in self._collision_groups[sprite.collision_layer]: - if (other.floor or other.block) and collides(other.floor_rect): - still_on_solid = True - floors.append(other) - sprite.on_solid = still_on_solid - else: - # Are we currently in contact with the ground - for other in self._collision_groups[sprite.collision_layer]: - if (other.floor or other.block) and collides(other.floor_rect): - sprite.on_solid = True - floors.append(other) + + # Are we currently in contact with the ground? + sprite.on_solid = False + for other in self._collision_groups[sprite.collision_layer]: + if (other.floor or other.block) and collides(other.floor_rect): + sprite.on_solid = True + floors.append(other) sprite.check_floors(floors) - # call update methods + def update(self): + if self._last_time is None: + self._last_time = time.time() + return + + dt = self.get_dt() + + self.apply_gravity(dt) + self.apply_friction() + self.handle_escaped_sprites() + self.update_sprite_positions(dt) self._updaters.update() self.handle_actions()