Changeset 128:36267deaccd8


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

Add friction. Remove old dirty sprite attributes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/physics.py

    r122 r128  
    1313from .constants import EPSILON
    1414
    15 class Sprite(pygame.sprite.DirtySprite):
     15class Sprite(pygame.sprite.Sprite):
    1616
    1717    # physics attributes
     
    2121    bounce_factor = (0.95, 0.95) # bounce factor
    2222    mass = 1.0 # used for shared collisions and applying forces
     23    friction_coeff = (0.99, 0.99) # friction factor
    2324
    2425    # collision attributes
     
    4142        self.image = pygame.Surface((10, 10))
    4243        self.image.fill((0, 0, 200))
    43         self.visible = 1
    44         self.dirty = 1
    45         self.blendmode = 0
    4644
    4745    def init_pos(self):
     
    8583    def collided(self, other):
    8684        pass
     85
     86    def apply_friction(self):
     87        v_x, v_y = self.velocity
     88        self.velocity = self.friction_coeff[0] * v_x, self.friction_coeff[1] * v_y
    8789
    8890    def bounce(self, other, normal):
     
    169171        sprite.deltap(max(-1.1 * frac, -dt))
    170172        sprite.bounce(others[idx], normal)
     173
    171174        for other in others:
    172175            sprite.collided(other)
     
    185188        for sprite in self._gravitators:
    186189            sprite.deltav(dv)
     190
     191        # friction
     192        for sprite in self._mobiles:
     193            sprite.apply_friction()
    187194
    188195        # position update and collision check (do last)
Note: See TracChangeset for help on using the changeset viewer.