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 |
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 | |
40 | /** Screen that runs a Level, where Players run and jump through Sectors. */ |
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 | |
53 | /** ends the current level */ |
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 | |
67 | /** |
68 | * returns the "working directory" usually this is the directory where the |
69 | * currently played level resides. This is used when locating additional |
70 | * resources for the current level/world |
71 | */ |
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 | |
81 | /** Enters or leaves level editor mode */ |
82 | void set_editmode(bool edit_mode = true); |
83 | |
84 | /** Forces all Players to enter ghost mode */ |
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; /**< total time in seconds that this session ran interactively */ |
131 | |
132 | bool m_edit_mode; /**< true if GameSession runs in level editor mode */ |
133 | bool m_levelintro_shown; /**< true if the LevelIntro screen was already shown */ |
134 | |
135 | int m_coins_at_start; /** How many coins does the player have at the start */ |
136 | BonusType m_bonus_at_start; /** What bonuses does the player have at the start */ |
137 | int m_max_fire_bullets_at_start; /** How many fire bullets does the player have */ |
138 | int m_max_ice_bullets_at_start; /** How many ice bullets does the player have */ |
139 | |
140 | bool m_active; /** Game active? **/ |
141 | |
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 */ |
152 | |