- converted text_type into a class
[supertux.git] / src / physic.h
index 3730285..37b6302 100644 (file)
 #ifndef SUPERTUX_PHYSIC_H
 #define SUPERTUX_PHYSIC_H
 
-#include "timer.h"
+/** This is a very simplistic physics engine handling accelerated and constant
+  * movement along with gravity.
+  */
+class Physic
+{
+public:
+    Physic();
+    ~Physic();
 
-enum {
-  PH_VTU /* Vertical throw up. */
-};
+    /** resets all velocities and accelerations to 0 */
+    void reset();
+
+    /** sets velocity to a fixed value */
+    void set_velocity(float vx, float vy);
+
+    float get_velocity_x();
+    float get_velocity_y();
+    
+    /** sets acceleration applied to the object. (Note that gravity is
+     * eventually added to the vertical acceleration)
+     */
+    void set_acceleration(float ax, float ay);
+
+    float get_acceleration_x();
+    float get_acceleration_y();
 
-/* Physic type: */
-
-typedef struct physic_type
-  {
-      int state;
-      unsigned int start_time;
-  }
-physic_type;
-
-void physic_init(physic_type* pphysic);
-int physic_get_state(physic_type* pphysic);
-void physic_set_state(physic_type* pphysic, int nstate);
-float physic_get_velocity(physic_type* pphysic, float start_velocity);
-float physic_get_max_distance(physic_type* pphysic, float start_velocity);
-unsigned int physic_get_max_time(physic_type* pphysic, float start_velocity);
-unsigned int physic_get_time_gone(physic_type* pphysic);
+    /** enables or disables handling of gravity */
+    void enable_gravity(bool gravity_enabled);
+
+    /** applies the physical simulation to given x and y coordinates */
+    void apply(float frame_ratio, float &x, float &y); 
+
+private:
+    /// horizontal and vertical acceleration
+    float ax, ay;
+    /// horizontal and vertical velocity
+    float vx, vy;
+    /// should we respect gravity in out calculations?
+    bool gravity_enabled;
+};
 
 #endif /*SUPERTUX_PHYSIC_H*/