4 // Copyright (C) 2004 Bill Kendrick <bill@newbreedsoftware.com>
5 // Tobias Glaesser <tobi.web@gmx.de>
6 // Ingo Ruhnke <grumbel@gmx.de>
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.
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.
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.
22 #ifndef SUPERTUX_GAMELOOP_H
23 #define SUPERTUX_GAMELOOP_H
26 #include "statistics.h"
28 using namespace SuperTux;
34 #define ST_GL_LOAD_GAME 2
35 #define ST_GL_LOAD_LEVEL_FILE 3
36 #define ST_GL_DEMO_GAME 4
43 extern int game_started;
53 /** The GameSession class controlls the controll flow of a World, ie.
54 present the menu on specifc keypresses, render and update it while
55 keeping the speed and framerate sane, etc. */
60 Timer2 endsequence_timer;
62 Sector* currentsector;
69 /** If true the end_sequence will be played, user input will be
70 ignored while doing that */
71 enum EndSequenceState {
73 ENDSEQUENCE_RUNNING, // tux is running right
74 ENDSEQUENCE_WAITING // waiting for the end of the music
76 EndSequenceState end_sequence;
81 std::string levelname;
84 // the sector and spawnpoint we shoudl spawn after this frame
85 std::string newsector;
86 std::string newspawnpoint;
89 enum ExitStatus { ES_NONE, ES_LEVEL_FINISHED, ES_GAME_OVER, ES_LEVEL_ABORT };
91 ExitStatus exit_status;
93 DrawingContext* context;
96 GameSession(const std::string& level, int mode, bool flip_level_ = false, Statistics* statistics = NULL);
99 /** Enter the busy loop */
103 void action(float frame_ratio);
107 static GameSession* current() { return current_; }
109 void respawn(const std::string& sectorname,
110 const std::string& spawnpointname);
111 Sector* get_current_sector()
112 { return currentsector; }
114 void start_sequence(const std::string& sequencename);
117 static GameSession* current_;
120 std::string last_keys;
123 Vector last_swap_point;
124 Statistics last_swap_stats;
126 Statistics* best_level_statistics;
128 void restart_level();
130 void check_end_conditions();
132 void process_events();
135 void drawstatus(DrawingContext& context);
136 void drawendscreen();
137 void drawresultscreen(void);
139 void on_escape_press();
143 std::string slotinfo(int slot);
145 void bumpbrick(float x, float y);
147 /** Return true if the gameloop() was entered, false otherwise */
148 bool process_load_game_menu();
150 #endif /*SUPERTUX_GAMELOOP_H*/