2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef HEADER_SUPERTUX_SUPERTUX_GAME_SESSION_HPP
18 #define HEADER_SUPERTUX_SUPERTUX_GAME_SESSION_HPP
24 #include "object/endsequence.hpp"
25 #include "supertux/screen.hpp"
26 #include "util/currenton.hpp"
27 #include "video/surface.hpp"
37 * Screen that runs a Level, where Players run and jump through Sectors.
39 class GameSession : public Screen,
40 public Currenton<GameSession>
43 GameSession(const std::string& levelfile, Statistics* statistics = NULL);
46 void record_demo(const std::string& filename);
47 int get_demo_random_seed(const std::string& filename);
48 void play_demo(const std::string& filename);
50 void draw(DrawingContext& context);
51 void update(float frame_ratio);
54 /// ends the current level
55 void finish(bool win = true);
56 void respawn(const std::string& sectorname, const std::string& spawnpointname);
57 void set_reset_point(const std::string& sectorname, const Vector& pos);
58 std::string get_reset_point_sectorname()
59 { return reset_sector; }
61 Vector get_reset_point_pos()
64 Sector* get_current_sector()
65 { return currentsector; }
67 Level* get_current_level()
68 { return level.get(); }
70 void start_sequence(const std::string& sequencename);
73 * returns the "working directory" usually this is the directory where the
74 * currently played level resides. This is used when locating additional
75 * resources for the current level/world
77 std::string get_working_directory();
83 * Enters or leaves level editor mode
85 void set_editmode(bool edit_mode = true);
88 * Forces all Players to enter ghost mode
90 void force_ghost_mode();
93 void check_end_conditions();
94 void process_events();
95 void capture_demo_step();
97 void drawstatus(DrawingContext& context);
98 void draw_pause(DrawingContext& context);
100 HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
101 void on_escape_press();
104 std::auto_ptr<Level> level;
105 std::auto_ptr<Surface> statistics_backdrop;
108 typedef std::vector<HSQOBJECT> ScriptList;
111 Sector* currentsector;
114 int pause_menu_frame;
116 EndSequence* end_sequence;
119 float speed_before_pause;
121 std::string levelfile;
123 // reset point (the point where tux respawns if he dies)
124 std::string reset_sector;
127 // the sector and spawnpoint we should spawn after this frame
128 std::string newsector;
129 std::string newspawnpoint;
131 Statistics* best_level_statistics;
133 std::ostream* capture_demo_stream;
134 std::string capture_file;
135 std::istream* playback_demo_stream;
136 CodeController* demo_controller;
138 std::auto_ptr<Menu> game_menu;
140 float play_time; /**< total time in seconds that this session ran interactively */
142 bool edit_mode; /**< true if GameSession runs in level editor mode */
143 bool levelintro_shown; /**< true if the LevelIntro screen was already shown */
146 GameSession(const GameSession&);
147 GameSession& operator=(const GameSession&);
150 #endif /*SUPERTUX_GAMELOOP_H*/