implemented a new object factory mechanism which is now really independent of the...
[supertux.git] / src / badguy / snowball.cpp
index 4442d02..5f65eaa 100644 (file)
@@ -28,8 +28,8 @@ SnowBall::write(lisp::Writer& writer)
 {
   writer.start_list("snowball");
 
-  writer.write_float("x", get_pos().x);
-  writer.write_float("y", get_pos().y);
+  writer.write_float("x", start_position.x);
+  writer.write_float("y", start_position.y);
 
   writer.end_list("snowball");
 }
@@ -64,3 +64,16 @@ SnowBall::collision_solid(GameObject& , const CollisionHit& hit)
   return CONTINUE;
 }
 
+HitResponse
+SnowBall::collision_badguy(BadGuy& , const CollisionHit& hit)
+{
+  if(fabsf(hit.normal.x) > .8) { // left or right hit
+    dir = dir == LEFT ? RIGHT : LEFT;
+    sprite->set_action(dir == LEFT ? "left" : "right");
+    physic.set_velocity_x(-physic.get_velocity_x());       
+  }
+
+  return CONTINUE;
+}
+
+IMPLEMENT_FACTORY(SnowBall, "snowball")