Background can now render three images: Top, Center and Bottom
[supertux.git] / src / object / scripted_object.cpp
index b9378fd..53ef317 100644 (file)
@@ -1,6 +1,7 @@
 #include <config.h>
 
 #include <stdexcept>
+#include <math.h>
 
 #include "scripted_object.hpp"
 #include "video/drawing_context.hpp"
@@ -140,7 +141,7 @@ ScriptedObject::draw(DrawingContext& context)
 }
 
 HitResponse
-ScriptedObject::collision(GameObject& other, const CollisionHit& )
+ScriptedObject::collision(GameObject& other, const CollisionHit& hit)
 {
   if(!physic_enabled)
     return FORCE_MOVE;
@@ -148,8 +149,22 @@ ScriptedObject::collision(GameObject& other, const CollisionHit& )
   if(!(other.get_flags() & FLAG_SOLID))
     return FORCE_MOVE;
 
-  physic.set_velocity(0, 0);
-  return CONTINUE;
+  if(other.get_flags() & FLAG_SOLID) {
+    if(hit.normal.y < 0) { // landed on floor
+      if(physic.get_velocity_y() < 0)
+        physic.set_velocity_y(0);
+    } else if(hit.normal.y > 0) { // bumped against roof
+      physic.set_velocity_y(.1);
+    }
+
+    if(fabsf(hit.normal.x) > .9) { // hit on side?
+      physic.set_velocity_x(0);
+    }
+        
+    return CONTINUE;
+  }
+
+  return FORCE_MOVE;
 }
 
 IMPLEMENT_FACTORY(ScriptedObject, "scriptedobject");