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.
21 #ifndef SUPERTUX_GAMELOOP_H
22 #define SUPERTUX_GAMELOOP_H
26 #include "statistics.h"
28 using namespace SuperTux;
32 enum GameSessionMode {
36 ST_GL_LOAD_LEVEL_FILE,
45 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. */
59 enum ExitStatus { ES_NONE, ES_LEVEL_FINISHED, ES_GAME_OVER, ES_LEVEL_ABORT };
62 DrawingContext* context;
65 GameSession(const std::string& levelfile, GameSessionMode mode,
66 Statistics* statistics=0);
69 /** Enter the busy loop */
73 void action(float frame_ratio);
77 static GameSession* current() { return current_; }
79 void respawn(const std::string& sectorname,
80 const std::string& spawnpointname);
81 void set_reset_point(const std::string& sectorname,
83 void display_info_box(const std::string& text);
84 Sector* get_current_sector()
85 { return currentsector; }
87 void start_sequence(const std::string& sequencename);
88 /// called by JoystickKeyboardController after an ascii key has been pressed
94 void check_end_conditions();
96 void process_events();
99 void drawstatus(DrawingContext& context);
100 void drawendscreen();
101 void drawresultscreen();
104 void on_escape_press();
108 Timer2 endsequence_timer;
110 Sector* currentsector;
112 GameSessionMode mode;
115 int pause_menu_frame;
117 /** If true the end_sequence will be played, user input will be
118 ignored while doing that */
119 enum EndSequenceState {
121 ENDSEQUENCE_RUNNING, // tux is running right
122 ENDSEQUENCE_WAITING // waiting for the end of the music
124 EndSequenceState end_sequence;
126 CodeController* end_sequence_controller;
130 std::string levelfile;
132 // reset point (the point where tux respawns if he dies)
133 std::string reset_sector;
136 // the sector and spawnpoint we should spawn after this frame
137 std::string newsector;
138 std::string newspawnpoint;
140 static GameSession* current_;
143 std::string last_keys;
145 Statistics* best_level_statistics;
147 ExitStatus exit_status;
150 std::string slotinfo(int slot);
152 /** Return true if the gameloop() was entered, false otherwise */
153 bool process_load_game_menu();
155 #endif /*SUPERTUX_GAMELOOP_H*/