From: Christoph Sommer Date: Wed, 1 Nov 2006 04:42:29 +0000 (+0000) Subject: Allow Tux to throw rocks (and lanterns), so he won't hurt himself that easily X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7e8b3b067e71c7467fba587438c1bf7259f7ae6e;p=supertux.git Allow Tux to throw rocks (and lanterns), so he won't hurt himself that easily SVN-Revision: 4432 --- diff --git a/src/object/rock.cpp b/src/object/rock.cpp index 472e3967a..e5f10b37d 100644 --- a/src/object/rock.cpp +++ b/src/object/rock.cpp @@ -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; } diff --git a/src/object/rock.hpp b/src/object/rock.hpp index 5bbc5143b..fb1fb0ca0 100644 --- a/src/object/rock.hpp +++ b/src/object/rock.hpp @@ -47,6 +47,7 @@ private: bool on_ground; bool grabbed; Physic physic; + Vector last_movement; }; #endif