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 "supertux/player_status.hpp"
27 #include "util/currenton.hpp"
28 #include "video/surface.hpp"
40 * Screen that runs a Level, where Players run and jump through Sectors.
42 class GameSession : public Screen,
43 public Currenton<GameSession>
46 GameSession(const std::string& levelfile, Savegame& savegame, Statistics* statistics = NULL);
49 void record_demo(const std::string& filename);
50 int get_demo_random_seed(const std::string& filename);
51 void play_demo(const std::string& filename);
53 void draw(DrawingContext& context);
54 void update(float frame_ratio);
55 void setup() override;
56 void leave() override;
58 /// ends the current level
59 void finish(bool win = true);
60 void respawn(const std::string& sectorname, const std::string& spawnpointname);
61 void set_reset_point(const std::string& sectorname, const Vector& pos);
62 std::string get_reset_point_sectorname()
63 { return reset_sector; }
65 Vector get_reset_point_pos()
68 Sector* get_current_sector()
69 { return currentsector; }
71 Level* get_current_level()
72 { return level.get(); }
74 void start_sequence(const std::string& sequencename);
77 * returns the "working directory" usually this is the directory where the
78 * currently played level resides. This is used when locating additional
79 * resources for the current level/world
81 std::string get_working_directory();
82 int restart_level(bool after_death = false);
86 bool is_active() const;
89 * Enters or leaves level editor mode
91 void set_editmode(bool edit_mode = true);
94 * Forces all Players to enter ghost mode
96 void force_ghost_mode();
98 Savegame& get_savegame() { return m_savegame; }
101 void check_end_conditions();
102 void process_events();
103 void capture_demo_step();
105 void drawstatus(DrawingContext& context);
106 void draw_pause(DrawingContext& context);
108 HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
109 void on_escape_press();
111 std::unique_ptr<Level> level;
112 SurfacePtr statistics_backdrop;
115 typedef std::vector<HSQOBJECT> ScriptList;
118 Sector* currentsector;
121 int pause_menu_frame;
123 std::shared_ptr<EndSequence> end_sequence;
126 float speed_before_pause;
128 std::string levelfile;
130 // reset point (the point where tux respawns if he dies)
131 std::string reset_sector;
134 // the sector and spawnpoint we should spawn after this frame
135 std::string newsector;
136 std::string newspawnpoint;
138 Statistics* best_level_statistics;
139 Savegame& m_savegame;
141 std::ostream* capture_demo_stream;
142 std::string capture_file;
143 std::istream* playback_demo_stream;
144 CodeController* demo_controller;
146 float play_time; /**< total time in seconds that this session ran interactively */
148 bool edit_mode; /**< true if GameSession runs in level editor mode */
149 bool levelintro_shown; /**< true if the LevelIntro screen was already shown */
151 int coins_at_start; /** How many coins does the player have at the start */
152 BonusType bonus_at_start; /** What bonuses does the player have at the start */
153 int max_fire_bullets_at_start; /** How many fire bullets does the player have */
154 int max_ice_bullets_at_start; /** How many ice bullets does the player have */
156 bool active; /** Game active? **/
159 GameSession(const GameSession&);
160 GameSession& operator=(const GameSession&);
163 #endif /*SUPERTUX_GAMELOOP_H*/