[ Patch #1793 ] Turn physic into POD
[supertux.git] / src / object / scripted_object.cpp
index e95e5b5..591053d 100644 (file)
@@ -29,7 +29,7 @@
 #include "math/vector.hpp"
 
 ScriptedObject::ScriptedObject(const lisp::Lisp& lisp)
-  : MovingSprite(lisp, LAYER_OBJECTS, COLGROUP_MOVING),
+  : MovingSprite(lisp, LAYER_OBJECTS, COLGROUP_MOVING_STATIC),
     solid(true), physic_enabled(true), visible(true), new_vel_set(false)
 {
   lisp.get("name", name);
@@ -47,6 +47,11 @@ ScriptedObject::ScriptedObject(const lisp::Lisp& lisp)
   lisp.get("physic-enabled", physic_enabled);
   lisp.get("visible", visible);
   lisp.get("z-pos", layer);
+  if( solid ){
+    set_group( COLGROUP_MOVING_STATIC );
+  } else {
+    set_group( COLGROUP_DISABLED );
+  }
 }
 
 void
@@ -74,7 +79,7 @@ ScriptedObject::set_pos(float x, float y)
 {
   printf("SetPos: %f %f\n", x, y);
   bbox.set_pos(Vector(x, y));
-  physic.reset();
+  physic = Physic();
 }
 
 float
@@ -99,13 +104,13 @@ ScriptedObject::set_velocity(float x, float y)
 float
 ScriptedObject::get_velocity_x()
 {
-  return physic.get_velocity_x();
+  return physic.vx;
 }
 
 float
 ScriptedObject::get_velocity_y()
 {
-  return physic.get_velocity_y();
+  return physic.vy;
 }
 
 void
@@ -124,6 +129,11 @@ void
 ScriptedObject::set_solid(bool solid)
 {
   this->solid = solid;
+  if( solid ){
+    set_group( COLGROUP_MOVING_STATIC );
+  } else {
+    set_group( COLGROUP_DISABLED );
+  }
 }
 
 bool
@@ -158,7 +168,8 @@ ScriptedObject::update(float elapsed_time)
     return;
 
   if(new_vel_set) {
-    physic.set_velocity(new_vel.x, new_vel.y);
+    physic.vx = new_vel.x;
+    physic.vy = new_vel.y;
     new_vel_set = false;
   }
   movement = physic.get_movement(elapsed_time);
@@ -180,14 +191,14 @@ ScriptedObject::collision_solid(const CollisionHit& hit)
     return;
 
   if(hit.bottom) {
-    if(physic.get_velocity_y() > 0)
-      physic.set_velocity_y(0);
+    if(physic.vy > 0)
+      physic.vy = 0;
   } else if(hit.top) {
-    physic.set_velocity_y(.1);
+    physic.vy = .1;
   }
 
   if(hit.left || hit.right) {
-    physic.set_velocity_x(0);
+    physic.vx = 0;
   }
 }