Added inverse functions for speed. Might be usefull for someone that wants to make...
[supertux.git] / src / gameloop.h
1 /*
2   gameloop.h
3   
4   Super Tux - Game Loop!
5   
6   by Bill Kendrick & Tobias Glaesser <tobi.web@gmx.de>
7   bill@newbreedsoftware.com
8   http://www.newbreedsoftware.com/supertux/
9   
10   April 11, 2000 - March 15, 2004
11 */
12
13 #ifndef SUPERTUX_GAMELOOP_H
14 #define SUPERTUX_GAMELOOP_H
15
16 #include "sound.h"
17 #include "type.h"
18 #include "level.h"
19 #include "world.h"
20
21 /* GameLoop modes */
22
23 #define ST_GL_PLAY 0
24 #define ST_GL_TEST 1
25 #define ST_GL_LOAD_GAME 2
26 #define ST_GL_LOAD_LEVEL_FILE  3
27 #define ST_GL_DEMO_GAME  4
28
29 extern int game_started;
30
31 class World;
32
33 /** The GameSession class controlls the controll flow of a World, ie.
34     present the menu on specifc keypresses, render and update it while
35     keeping the speed and framerate sane, etc. */
36 class GameSession
37 {
38  private:
39   Timer fps_timer;
40   Timer frame_timer;
41   World* world;
42   int st_gl_mode;
43   int levelnb;
44   float fps_fps;
45   unsigned int last_update_time;
46   unsigned int update_time;
47   int pause_menu_frame;
48   int debug_fps;
49   bool game_pause;
50
51   // FIXME: Hack for restarting the level
52   std::string subset;
53
54   enum ExitStatus { NONE, LEVEL_FINISHED, GAME_OVER, LEVEL_ABORT };
55   ExitStatus exit_status;
56  public:
57   Timer time_left;
58
59   GameSession(const std::string& subset, int levelnb, int mode);
60   ~GameSession();
61
62   /** Enter the busy loop */
63   ExitStatus run();
64
65   void draw();
66   void action(double frame_ratio);
67
68   Level* get_level() { return world->get_level(); }
69   World* get_world() { return world; }
70
71   static GameSession* current() { return current_; }
72  private:
73   static GameSession* current_;
74
75   void restart_level();
76
77   void check_end_conditions();
78   void start_timers();
79   void process_events();
80
81   void levelintro();
82   void drawstatus();
83   void drawendscreen();
84   void drawresultscreen(void);
85 };
86
87 std::string slotinfo(int slot);
88
89 bool rectcollision(base_type* one, base_type* two);
90 void bumpbrick(float x, float y);
91
92 #endif /*SUPERTUX_GAMELOOP_H*/
93