# HG changeset patch # User Simon Cross # Date 1301864717 -7200 # Node ID 60aa6c3eb96f4c0fad63a669fe1dff1b7df6b7e1 # Parent 64b135316b808f5d24ff1a38142a888fc71d24f1 Implement bounce factor. diff -r 64b135316b80 -r 60aa6c3eb96f skaapsteker/physics.py --- a/skaapsteker/physics.py Sun Apr 03 22:59:09 2011 +0200 +++ b/skaapsteker/physics.py Sun Apr 03 23:05:17 2011 +0200 @@ -15,6 +15,7 @@ gravitates = True # whether gravity applies to the sprite terminal_velocity = (100.0, 100.0) # maximum horizontal and vertial speeds + bounce_factor = (0.9, 0.9) # bounce factor def __init__(self, *args, **kwargs): super(Sprite, self).__init__(*args, **kwargs) @@ -60,8 +61,11 @@ frac_x = clip.width / abs(v_x) if abs(v_x) > EPSILON else 0.0 frac_y = clip.height / abs(v_y) if abs(v_y) > EPSILON else 0.0 frac = max(frac_x, frac_y) + b_x = -v_x * self.bounce_factor[0] * immobile.bounce_factor[0] + b_y = -v_y * self.bounce_factor[1] * immobile.bounce_factor[1] self.velocity = (-v_x, -v_y) self.deltap(frac) + self.velocity = (b_x, b_y) class World(object):