Mercurial > skaapsteker
changeset 68:60aa6c3eb96f
Implement bounce factor.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sun, 03 Apr 2011 23:05:17 +0200 |
parents | 64b135316b80 |
children | e4089417766e |
files | skaapsteker/physics.py |
diffstat | 1 files changed, 4 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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):