Allow Tux to throw rocks (and lanterns), so he won't hurt himself that easily
authorChristoph Sommer <mail@christoph-sommer.de>
Wed, 1 Nov 2006 04:42:29 +0000 (04:42 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Wed, 1 Nov 2006 04:42:29 +0000 (04:42 +0000)
SVN-Revision: 4432

src/object/rock.cpp
src/object/rock.hpp

index 472e396..e5f10b3 100644 (file)
@@ -64,6 +64,8 @@ Rock::update(float elapsed_time)
   if( grabbed )
     return;
 
+  if (on_ground) physic.set_velocity_x(0);
+
   movement = physic.get_movement(elapsed_time);
 }
 
@@ -104,17 +106,22 @@ void
 Rock::grab(MovingObject& , const Vector& pos, Direction)
 {
   movement = pos - get_pos();
+  last_movement = movement;
   set_group(COLGROUP_DISABLED);
   on_ground = true;
   grabbed = true;
 }
 
 void
-Rock::ungrab(MovingObject& , Direction )
+Rock::ungrab(MovingObject& , Direction dir)
 {
   set_group(COLGROUP_MOVING_STATIC);
   on_ground = false;
-  physic.set_velocity(0, 0);
+  if (last_movement.norm() > 1) {
+    physic.set_velocity((dir == RIGHT) ? 200 : -200, -200);
+  } else {
+    physic.set_velocity(0, 0);
+  }
   grabbed = false;
 }
 
index 5bbc514..fb1fb0c 100644 (file)
@@ -47,6 +47,7 @@ private:
   bool on_ground;
   bool grabbed;
   Physic physic;
+  Vector last_movement;
 };
 
 #endif