[ Patch #1793 ] Turn physic into POD
[supertux.git] / src / badguy / bouncing_snowball.cpp
index 76df35a..b28b03e 100644 (file)
 
 #include "bouncing_snowball.hpp"
 
-static const float JUMPSPEED = 450;
+static const float JUMPSPEED = -450;
 static const float WALKSPEED = 80;
 
 BouncingSnowball::BouncingSnowball(const lisp::Lisp& reader)
        : BadGuy(reader, "images/creatures/bouncing_snowball/bouncing_snowball.sprite")
 {
-  set_direction = false;
 }
 
 BouncingSnowball::BouncingSnowball(const Vector& pos, Direction d)
-       : BadGuy(pos, "images/creatures/bouncing_snowball/bouncing_snowball.sprite")
+  : BadGuy(pos, d, "images/creatures/bouncing_snowball/bouncing_snowball.sprite")
 {
-   set_direction = true;
-   initial_direction = d;
 }
 
 void
@@ -51,48 +48,43 @@ BouncingSnowball::write(lisp::Writer& writer)
 void
 BouncingSnowball::activate()
 {
-  if (set_direction) {dir = initial_direction;}
-  physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
+  physic.vx = (dir == LEFT ? -WALKSPEED : WALKSPEED);
   sprite->set_action(dir == LEFT ? "left" : "right");
 }
 
 bool
-BouncingSnowball::collision_squished(Player& player)
+BouncingSnowball::collision_squished(GameObject& object)
 {
   sprite->set_action("squished");
-  kill_squished(player);
+  kill_squished(object);
   return true;
 }
 
-HitResponse
-BouncingSnowball::collision_solid(GameObject& , const CollisionHit& hit)
+void
+BouncingSnowball::collision_solid(const CollisionHit& hit)
 {
-  if(hit.normal.y < -.5) { // hit floor
-    physic.set_velocity_y(JUMPSPEED);
-  } else if(hit.normal.y > .5) { // bumped on roof
-    physic.set_velocity_y(0);
-  } else { // left or right collision
+  if(hit.bottom) {
+    if(get_state() == STATE_ACTIVE) {
+      physic.vy = JUMPSPEED;
+    } else {
+      physic.vy = 0;
+    }
+  } else if(hit.top) {
+    physic.vy = 0;
+  }
+
+  if(hit.left || hit.right) { // left or right collision
     dir = dir == LEFT ? RIGHT : LEFT;
     sprite->set_action(dir == LEFT ? "left" : "right");
-    physic.set_velocity_x(-physic.get_velocity_x());
+    physic.vx = -physic.vx;
   }
-
-  return CONTINUE;
 }
 
 HitResponse
 BouncingSnowball::collision_badguy(BadGuy& , const CollisionHit& hit)
 {
-  if(fabsf(hit.normal.x) > .8) { // left/right?
-    dir = dir == LEFT ? RIGHT : LEFT;
-    sprite->set_action(dir == LEFT ? "left" : "right");    
-    physic.set_velocity_x(-physic.get_velocity_x());
-  } else if(hit.normal.y < -.8) { // grounf
-    physic.set_velocity_y(JUMPSPEED);
-  }
-
+  collision_solid(hit);
   return CONTINUE;
 }
 
 IMPLEMENT_FACTORY(BouncingSnowball, "bouncingsnowball")
-