X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fphysic.cpp;h=d7993cd3066071c12841813079cfe026866f951b;hb=3655d32f63f75b2af054ec68d4176e55a561ba96;hp=84eb8923c81fc8f5f3db3f9a21f7cde8713959ff;hpb=714a30abd887def6331a193216387e66cbfbd1bb;p=supertux.git diff --git a/src/physic.cpp b/src/physic.cpp index 84eb8923c..d7993cd30 100644 --- a/src/physic.cpp +++ b/src/physic.cpp @@ -23,14 +23,140 @@ #include "physic.hpp" Physic::Physic() - : ax(0), ay(0), vx(0), vy(0), gravity_enabled(true), gravity(1000) + : ax(0), ay(0), vx(0), vy(0), gravity_enabled_flag(true), gravity(1000) { } +Physic::~Physic() +{ +} + +void +Physic::reset() +{ + ax = ay = vx = vy = 0; + gravity_enabled_flag = true; +} + +void +Physic::set_velocity_x(float nvx) +{ + vx = nvx; +} + +void +Physic::set_velocity_y(float nvy) +{ + vy = nvy; +} + +void +Physic::set_velocity(float nvx, float nvy) +{ + vx = nvx; + vy = nvy; +} + +void +Physic::set_velocity(const Vector& vector) +{ + vx = vector.x; + vy = vector.y; +} + +void Physic::inverse_velocity_x() +{ + vx = -vx; +} + +void Physic::inverse_velocity_y() +{ + vy = -vy; +} + +float +Physic::get_velocity_x() const +{ + return vx; +} + +float +Physic::get_velocity_y() const +{ + return vy; +} + +Vector +Physic::get_velocity() const +{ + return Vector(vx, vy); +} + +void +Physic::set_acceleration_x(float nax) +{ + ax = nax; +} + +void +Physic::set_acceleration_y(float nay) +{ + ay = nay; +} + +void +Physic::set_acceleration(float nax, float nay) +{ + ax = nax; + ay = nay; +} + +float +Physic::get_acceleration_x() const +{ + return ax; +} + +float +Physic::get_acceleration_y() const +{ + return ay; +} + +Vector +Physic::get_acceleration() const +{ + return Vector(ax, ay); +} + +void +Physic::enable_gravity(bool enable_gravity) +{ + gravity_enabled_flag = enable_gravity; +} + +bool +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 ? gravity : 0; + float grav = gravity_enabled_flag ? gravity : 0; Vector result( vx * elapsed_time + ax * elapsed_time * elapsed_time,