- fixed problem with asyncron blinkig bonus block
[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     /** velocities invertion */
32     void inverse_velocity_x();
33     void inverse_velocity_y();
34
35     float get_velocity_x();
36     float get_velocity_y();
37     
38     /** sets acceleration applied to the object. (Note that gravity is
39      * eventually added to the vertical acceleration)
40      */
41     void set_acceleration(float ax, float ay);
42
43     float get_acceleration_x();
44     float get_acceleration_y();
45
46     /** enables or disables handling of gravity */
47     void enable_gravity(bool gravity_enabled);
48
49     /** applies the physical simulation to given x and y coordinates */
50     void apply(float frame_ratio, float &x, float &y); 
51
52 private:
53     /// horizontal and vertical acceleration
54     float ax, ay;
55     /// horizontal and vertical velocity
56     float vx, vy;
57     /// should we respect gravity in out calculations?
58     bool gravity_enabled;
59 };
60
61 #endif /*SUPERTUX_PHYSIC_H*/