supertux
game_session.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
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.
8 //
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.
13 //
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/>.
16 
17 #ifndef HEADER_SUPERTUX_SUPERTUX_GAME_SESSION_HPP
18 #define HEADER_SUPERTUX_SUPERTUX_GAME_SESSION_HPP
19 
20 #include <memory>
21 #include <vector>
22 #include <squirrel.h>
23 
24 #include "math/vector.hpp"
25 #include "supertux/game_session_recorder.hpp"
26 #include "supertux/player_status.hpp"
27 #include "supertux/screen.hpp"
28 #include "supertux/sequence.hpp"
29 #include "util/currenton.hpp"
30 #include "video/surface_ptr.hpp"
31 
32 class CodeController;
33 class DrawingContext;
34 class EndSequence;
35 class Level;
36 class Sector;
37 class Statistics;
38 class Savegame;
39 
41 class GameSession final : public Screen,
42  public GameSessionRecorder,
43  public Currenton<GameSession>
44 {
45 public:
46  GameSession(const std::string& levelfile, Savegame& savegame, Statistics* statistics = nullptr);
47 
48  virtual void draw(Compositor& compositor) override;
49  virtual void update(float dt_sec, const Controller& controller) override;
50  virtual void setup() override;
51  virtual void leave() override;
52 
54  void finish(bool win = true);
55  void respawn(const std::string& sectorname, const std::string& spawnpointname,
56  const bool invincibility = false, const int invincibilityperiod = 0);
57  void reset_level();
58  void set_reset_point(const std::string& sectorname, const Vector& pos);
59  std::string get_reset_point_sectorname() const { return m_reset_sector; }
60 
61  Vector get_reset_point_pos() const { return m_reset_pos; }
62  Sector& get_current_sector() const { return *m_currentsector; }
63  Level& get_current_level() const { return *m_level; }
64 
65  void start_sequence(Sequence seq, const SequenceData* data = nullptr);
66 
72  std::string get_working_directory() const;
73  int restart_level(bool after_death = false);
74  bool reset_button;
75  bool reset_checkpoint_button;
76 
77  void toggle_pause();
78  void abort_level();
79  bool is_active() const;
80 
82  void set_editmode(bool edit_mode = true);
83 
85  void force_ghost_mode();
86 
87  Savegame& get_savegame() const { return m_savegame; }
88 
89 private:
90  void check_end_conditions();
91 
92  void drawstatus(DrawingContext& context);
93  void draw_pause(DrawingContext& context);
94 
95  void on_escape_press();
96 
97 private:
98  std::unique_ptr<Level> m_level;
99  std::unique_ptr<Level> m_old_level;
100  SurfacePtr m_statistics_backdrop;
101 
102  // scripts
103  typedef std::vector<HSQOBJECT> ScriptList;
104  ScriptList m_scripts;
105 
106  Sector* m_currentsector;
107 
108  EndSequence* m_end_sequence;
109 
110  bool m_game_pause;
111  float m_speed_before_pause;
112 
113  std::string m_levelfile;
114 
115  // reset point (the point where tux respawns if he dies)
116  std::string m_reset_sector;
117  Vector m_reset_pos;
118 
119  // the sector and spawnpoint we should spawn after this frame
120  std::string m_newsector;
121  std::string m_newspawnpoint;
122 
123  // Whether the player had invincibility before spawning in a new sector
124  bool m_pastinvincibility;
125  int m_newinvincibilityperiod;
126 
127  Statistics* m_best_level_statistics;
128  Savegame& m_savegame;
129 
130  float m_play_time;
132  bool m_edit_mode;
133  bool m_levelintro_shown;
135  int m_coins_at_start;
136  BonusType m_bonus_at_start;
137  int m_max_fire_bullets_at_start;
138  int m_max_ice_bullets_at_start;
140  bool m_active;
142  bool m_end_seq_started;
143 
144 private:
145  GameSession(const GameSession&) = delete;
146  GameSession& operator=(const GameSession&) = delete;
147 };
148 
149 #endif
150 
151 /* EOF */
Definition: controller.hpp:56
void finish(bool win=true)
ends the current level
Definition: game_session.cpp:418
Abstract base class for code the MainLoop runs exclusively and full-screen.
Definition: screen.hpp:29
Simple two dimensional vector.
Definition: vector.hpp:24
virtual void update(float dt_sec, const Controller &controller) override
gets called for once (per logical) frame.
Definition: game_session.cpp:296
void set_editmode(bool edit_mode=true)
Enters or leaves level editor mode.
Definition: game_session.cpp:210
Definition: sequence.hpp:33
This class is a layer between level and worldmap to keep track of stuff like scores, and minor, but funny things, like number of jumps and stuff.
Definition: statistics.hpp:32
std::string get_working_directory() const
returns the "working directory" usually this is the directory where the currently played level reside...
Definition: game_session.cpp:464
Represents one of (potentially) multiple, separate parts of a Level.
Definition: sector.hpp:49
Definition: game_session_recorder.hpp:25
Definition: endsequence.hpp:23
virtual void draw(Compositor &compositor) override
gets called once per frame.
Definition: game_session.cpp:249
virtual void setup() override
gets called before this screen gets activated (which is at least once before the first draw or update...
Definition: game_session.cpp:270
A &#39;Currenton&#39; allows access to the currently active instance of a class via the static current() func...
Definition: currenton.hpp:30
Represents a collection of Sectors running in a single GameSession.
Definition: level.hpp:29
virtual void leave() override
gets called when the current screen is temporarily suspended
Definition: game_session.cpp:291
Definition: compositor.hpp:29
Definition: savegame.hpp:66
This is a dummy controller that doesn&#39;t react to any user input but should be controlled by code...
Definition: codecontroller.hpp:24
void force_ghost_mode()
Forces all Players to enter ghost mode.
Definition: game_session.cpp:230
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
Screen that runs a Level, where Players run and jump through Sectors.
Definition: game_session.hpp:41