Made trampolines less likely to interfere with level design:
[supertux.git] / src / object / scripted_object.cpp
index d525022..90875f2 100644 (file)
@@ -16,7 +16,6 @@
 //  You should have received a copy of the GNU General Public License
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
 #include <config.h>
 
 #include <stdexcept>
@@ -123,6 +122,23 @@ ScriptedObject::is_visible()
 }
 
 void
+ScriptedObject::set_solid(bool solid)
+{
+  this->solid = solid;
+  if(solid)
+    flags |= FLAG_SOLID;
+  else
+    flags ^= FLAG_SOLID;
+}
+
+bool
+ScriptedObject::is_solid()
+{
+  return solid;
+}
+
+
+void
 ScriptedObject::set_action(const std::string& animation)
 {
   sprite->set_action(animation);
@@ -162,30 +178,27 @@ ScriptedObject::draw(DrawingContext& context)
   sprite->draw(context, get_pos(), layer);
 }
 
-HitResponse
-ScriptedObject::collision(GameObject& other, const CollisionHit& hit)
+void
+ScriptedObject::collision_solid(const CollisionHit& hit)
 {
   if(!physic_enabled)
-    return FORCE_MOVE;
-
-  if(!(other.get_flags() & FLAG_SOLID))
-    return FORCE_MOVE;
-
-  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;
+
+  if(hit.bottom) {
+    if(physic.get_velocity_y() > 0)
+      physic.set_velocity_y(0);
+  } else if(hit.top) {
+    physic.set_velocity_y(.1);
   }
 
+  if(hit.left || hit.right) {
+    physic.set_velocity_x(0);
+  }
+}
+
+HitResponse
+ScriptedObject::collision(GameObject& , const CollisionHit& )
+{
   return FORCE_MOVE;
 }