# HG changeset patch # User Jeremy Thurgood # Date 1304782150 -7200 # Node ID 1abb53ae1a6ae225baf03579f5d224834c1dc3e2 # Parent 65882990b9cf81d1ed9eefcc07d12581e2234897 More mild refactoring. diff -r 65882990b9cf -r 1abb53ae1a6a skaapsteker/physics.py --- 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()