From 7e8b3b067e71c7467fba587438c1bf7259f7ae6e Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Wed, 1 Nov 2006 04:42:29 +0000 Subject: [PATCH] Allow Tux to throw rocks (and lanterns), so he won't hurt himself that easily SVN-Revision: 4432 --- src/object/rock.cpp | 11 +++++++++-- src/object/rock.hpp | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) 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 -- 2.11.0