New grow and skid sounds from remaxim
[supertux.git] / src / game_session.hpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 #ifndef SUPERTUX_GAMELOOP_H
20 #define SUPERTUX_GAMELOOP_H
21
22 #include <string>
23 #include <SDL.h>
24 #include <squirrel.h>
25 #include "screen.hpp"
26 #include "math/vector.hpp"
27 #include "video/surface.hpp"
28 #include "object/endsequence.hpp"
29
30 class Level;
31 class Sector;
32 class Statistics;
33 class DrawingContext;
34 class CodeController;
35 class Menu;
36
37 /**
38  * Screen that runs a Level, where Players run and jump through Sectors.
39  */
40 class GameSession : public Screen
41 {
42 public:
43   GameSession(const std::string& levelfile, Statistics* statistics = NULL);
44   ~GameSession();
45
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);
49
50   void draw(DrawingContext& context);
51   void update(float frame_ratio);
52   void setup();
53
54   void set_current()
55   { current_ = this; }
56   static GameSession* current()
57   { return current_; }
58
59   /// ends the current level
60   void finish(bool win = true);
61   void respawn(const std::string& sectorname, const std::string& spawnpointname);
62   void set_reset_point(const std::string& sectorname, const Vector& pos);
63   std::string get_reset_point_sectorname()
64   { return reset_sector; }
65
66   Vector get_reset_point_pos()
67   { return reset_pos; }
68
69   Sector* get_current_sector()
70   { return currentsector; }
71
72   Level* get_current_level()
73   { return level.get(); }
74
75   void start_sequence(const std::string& sequencename);
76
77   /**
78    * returns the "working directory" usually this is the directory where the
79    * currently played level resides. This is used when locating additional
80    * resources for the current level/world
81    */
82   std::string get_working_directory();
83   void restart_level();
84
85   void toggle_pause();
86
87   /**
88    * Enters or leaves level editor mode
89    */
90   void set_editmode(bool edit_mode = true);
91
92   /**
93    * Forces all Players to enter ghost mode
94    */
95   void force_ghost_mode();
96
97 private:
98   void check_end_conditions();
99   void process_events();
100   void capture_demo_step();
101
102   void drawstatus(DrawingContext& context);
103   void draw_pause(DrawingContext& context);
104
105   HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
106   void on_escape_press();
107   void process_menu();
108
109   std::auto_ptr<Level> level;
110   std::auto_ptr<Surface> statistics_backdrop;
111
112   // scripts
113   typedef std::vector<HSQOBJECT> ScriptList;
114   ScriptList scripts;
115
116   Sector* currentsector;
117
118   int levelnb;
119   int pause_menu_frame;
120
121   EndSequence* end_sequence;
122
123   bool  game_pause;
124   float speed_before_pause;
125
126   std::string levelfile;
127
128   // reset point (the point where tux respawns if he dies)
129   std::string reset_sector;
130   Vector reset_pos;
131
132   // the sector and spawnpoint we should spawn after this frame
133   std::string newsector;
134   std::string newspawnpoint;
135
136   static GameSession* current_;
137
138   Statistics* best_level_statistics;
139
140   std::ostream* capture_demo_stream;
141   std::string capture_file;
142   std::istream* playback_demo_stream;
143   CodeController* demo_controller;
144
145   std::auto_ptr<Menu> game_menu;
146
147   float play_time; /**< total time in seconds that this session ran interactively */
148
149   bool edit_mode; /**< true if GameSession runs in level editor mode */
150   bool levelintro_shown; /**< true if the LevelIntro screen was already shown */
151 };
152
153 #endif /*SUPERTUX_GAMELOOP_H*/