From: Christoph Sommer Date: Mon, 24 Jul 2006 19:27:22 +0000 (+0000) Subject: Physics class can have its gravity altered X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=d5b880fb3fa978643816718159ca48b40b960f35;p=supertux.git Physics class can have its gravity altered SVN-Revision: 4082 --- diff --git a/src/physic.cpp b/src/physic.cpp index 358b41c73..d7993cd30 100644 --- a/src/physic.cpp +++ b/src/physic.cpp @@ -23,7 +23,7 @@ #include "physic.hpp" Physic::Physic() - : ax(0), ay(0), vx(0), vy(0), gravity_enabled_flag(true) + : ax(0), ay(0), vx(0), vy(0), gravity_enabled_flag(true), gravity(1000) { } @@ -141,10 +141,22 @@ Physic::gravity_enabled() const return gravity_enabled_flag; } +void +Physic::set_gravity(float gravity) +{ + this->gravity = gravity; +} + +float +Physic::get_gravity() const +{ + return gravity; +} + Vector Physic::get_movement(float elapsed_time) { - float grav = gravity_enabled_flag ? 1000 : 0; + float grav = gravity_enabled_flag ? gravity : 0; Vector result( vx * elapsed_time + ax * elapsed_time * elapsed_time, diff --git a/src/physic.hpp b/src/physic.hpp index f7ec06514..e05b65f3b 100644 --- a/src/physic.hpp +++ b/src/physic.hpp @@ -67,6 +67,12 @@ public: /// Enables or disables handling of gravity. void enable_gravity(bool gravity_enabled); bool gravity_enabled() const; + + /// Set gravity to apply to object when enabled + void set_gravity(float gravity); + + /// Get gravity to apply to object when enabled + float get_gravity() const; Vector get_movement(float elapsed_time); @@ -77,6 +83,8 @@ private: float vx, vy; /// should we respect gravity in out calculations? bool gravity_enabled_flag; + /// current gravity to apply to object, if enabled + float gravity; }; #endif