- converted text_type into a class
[supertux.git] / src / physic.h
1 //
2 // C++ Interface: physic
3 //
4 // Description: 
5 //
6 //
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #ifndef SUPERTUX_PHYSIC_H
14 #define SUPERTUX_PHYSIC_H
15
16 /** This is a very simplistic physics engine handling accelerated and constant
17   * movement along with gravity.
18   */
19 class Physic
20 {
21 public:
22     Physic();
23     ~Physic();
24
25     /** resets all velocities and accelerations to 0 */
26     void reset();
27
28     /** sets velocity to a fixed value */
29     void set_velocity(float vx, float vy);
30
31     float get_velocity_x();
32     float get_velocity_y();
33     
34     /** sets acceleration applied to the object. (Note that gravity is
35      * eventually added to the vertical acceleration)
36      */
37     void set_acceleration(float ax, float ay);
38
39     float get_acceleration_x();
40     float get_acceleration_y();
41
42     /** enables or disables handling of gravity */
43     void enable_gravity(bool gravity_enabled);
44
45     /** applies the physical simulation to given x and y coordinates */
46     void apply(float frame_ratio, float &x, float &y); 
47
48 private:
49     /// horizontal and vertical acceleration
50     float ax, ay;
51     /// horizontal and vertical velocity
52     float vx, vy;
53     /// should we respect gravity in out calculations?
54     bool gravity_enabled;
55 };
56
57 #endif /*SUPERTUX_PHYSIC_H*/