- removed joystick setup menu, since it won't work anyway
[supertux.git] / src / gameloop.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 Bill Kendrick <bill@newbreedsoftware.com>
5 //                     Tobias Glaesser <tobi.web@gmx.de>
6 //                     Ingo Ruhnke <grumbel@gmx.de>
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; either version 2
11 //  of the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 // 
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
22 #ifndef SUPERTUX_GAMELOOP_H
23 #define SUPERTUX_GAMELOOP_H
24
25 #include "sound.h"
26 #include "type.h"
27 #include "level.h"
28 #include "world.h"
29
30 /* GameLoop modes */
31
32 #define ST_GL_PLAY 0
33 #define ST_GL_TEST 1
34 #define ST_GL_LOAD_GAME 2
35 #define ST_GL_LOAD_LEVEL_FILE  3
36 #define ST_GL_DEMO_GAME  4
37
38 extern int game_started;
39
40 class World;
41
42 /** The GameSession class controlls the controll flow of a World, ie.
43     present the menu on specifc keypresses, render and update it while
44     keeping the speed and framerate sane, etc. */
45 class GameSession
46 {
47  private:
48   Timer fps_timer;
49   Timer frame_timer;
50   Timer endsequence_timer;
51   World* world;
52   int st_gl_mode;
53   int levelnb;
54   float fps_fps;
55   unsigned int last_update_time;
56   unsigned int update_time;
57   int pause_menu_frame;
58   int debug_fps;
59
60   /** If true the end_sequence will be played, user input will be
61       ignored while doing that */
62   bool end_sequence;
63   float last_x_pos;
64
65   bool game_pause;
66
67   // FIXME: Hack for restarting the level
68   std::string subset;
69
70  public:
71   enum ExitStatus { NONE, LEVEL_FINISHED, GAME_OVER, LEVEL_ABORT };
72  private:
73   ExitStatus exit_status;
74  public:
75
76   Timer time_left;
77
78   GameSession(const std::string& subset, int levelnb, int mode);
79   ~GameSession();
80
81   /** Enter the busy loop */
82   ExitStatus run();
83
84   void draw();
85   void action(double frame_ratio);
86
87   Level* get_level() { return world->get_level(); }
88   World* get_world() { return world; }
89
90   static GameSession* current() { return current_; }
91  private:
92   static GameSession* current_;
93
94   void restart_level();
95
96   void check_end_conditions();
97   void start_timers();
98   void process_events();
99
100   void levelintro();
101   void drawstatus();
102   void drawendscreen();
103   void drawresultscreen(void);
104
105  private:
106   void on_escape_press();
107   void process_menu();
108 };
109
110 std::string slotinfo(int slot);
111
112 bool rectcollision(base_type* one, base_type* two);
113 void bumpbrick(float x, float y);
114
115 #endif /*SUPERTUX_GAMELOOP_H*/
116