Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implement sprite acceleration

  • Loading branch information...
commit 5a5dbed82883bf3df830f6c275a1eb1337f74f51 1 parent 0563cba
@andrewsmedina authored
Showing with 29 additions and 0 deletions.
  1. +9 −0 physics/sprite.py
  2. +20 −0 tests/test_sprite.py
View
9 physics/sprite.py
@@ -9,3 +9,12 @@ def __init__(self, x, y, x_velocity=0, y_velocity=0):
def step(self):
self.x += self.x_velocity
self.y += self.y_velocity
+
+ def accelerate(self, x_acceleration=0, y_acceleration=0):
+ self.step()
+
+ self.x_velocity *= 0.99
+ self.y_velocity *= 0.99
+
+ self.x_velocity += x_acceleration
+ self.y_velocity += y_acceleration
View
20 tests/test_sprite.py
@@ -21,3 +21,23 @@ def test_step_should_increment_x_sprite_position(self):
def test_step_should_increment_y_sprite_position(self):
self.sprite.step()
self.assertEqual(16, self.sprite.y)
+
+ def test_acceletare_should_change_x_velocity(self):
+ self.sprite.accelerate(x_acceleration=0.25)
+ self.assertEqual(1.24, self.sprite.x_velocity)
+
+ def test_acceletare_should_change_y_velocity(self):
+ self.sprite.accelerate(y_acceleration=0.25)
+ self.assertEqual(1.24, self.sprite.y_velocity)
+
+ def test_accelerate_should_increment_x_sprite_position_using_velocity(self):
+ self.sprite.accelerate(x_acceleration=0.25)
+ self.sprite.accelerate(x_acceleration=0.25)
+
+ self.assertEqual(12.24, self.sprite.x)
+
+ def test_accelerate_should_increment_y_sprite_position_using_velocity(self):
+ self.sprite.accelerate(y_acceleration=0.25)
+ self.sprite.accelerate(y_acceleration=0.25)
+
+ self.assertEqual(17.24, self.sprite.y)
Please sign in to comment.
Something went wrong with that request. Please try again.