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
28 #include "statistics.hpp"
29 #include "math/vector.hpp"
30 #include "console.hpp"
33 enum GameSessionMode {
37 ST_GL_LOAD_LEVEL_FILE,
46 extern int game_started;
55 * The GameSession class controlls the controll flow of the Game (the part
56 * where you actually play a level)
58 class GameSession : public Screen, public ConsoleCommandReceiver
61 GameSession(const std::string& levelfile, GameSessionMode mode,
62 Statistics* statistics = NULL);
65 void record_demo(const std::string& filename);
66 void play_demo(const std::string& filename);
68 void draw(DrawingContext& context);
69 void update(float frame_ratio);
74 static GameSession* current()
77 /// ends the current level
78 void finish(bool win = true);
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);
85 Sector* get_current_sector()
86 { return currentsector; }
88 Level* get_current_level()
91 void start_sequence(const std::string& sequencename);
93 /** returns the "working directory" usually this is the directory where the
94 * currently played level resides. This is used when locating additional
95 * resources for the current level/world
97 std::string get_working_directory();
98 bool consoleCommand(std::string command); /**< callback from Console; return false if command was unknown, true otherwise */
101 void restart_level(bool fromBeginning = true);
103 void check_end_conditions();
104 void process_events();
105 void capture_demo_step();
108 void drawstatus(DrawingContext& context);
109 void draw_pause(DrawingContext& context);
111 void on_escape_press();
114 Timer endsequence_timer;
116 Sector* currentsector;
118 GameSessionMode mode;
121 int pause_menu_frame;
123 /** If true the end_sequence will be played, user input will be
124 ignored while doing that */
125 enum EndSequenceState {
127 ENDSEQUENCE_RUNNING, // tux is running right
128 ENDSEQUENCE_WAITING // waiting for the end of the music
130 EndSequenceState end_sequence;
132 CodeController* end_sequence_controller;
136 std::string levelfile;
138 // reset point (the point where tux respawns if he dies)
139 std::string reset_sector;
142 // the sector and spawnpoint we should spawn after this frame
143 std::string newsector;
144 std::string newspawnpoint;
146 static GameSession* current_;
148 Statistics* best_level_statistics;
150 std::ostream* capture_demo_stream;
151 std::string capture_file;
152 std::istream* playback_demo_stream;
153 CodeController* demo_controller;
157 #endif /*SUPERTUX_GAMELOOP_H*/