the boat works now
[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 "screen.hpp"
25 #include "timer.hpp"
26 #include "statistics.hpp"
27 #include "math/vector.hpp"
28 #include "console.hpp"
29 #include "video/surface.hpp"
30
31 class Level;
32 class Sector;
33 class Statistics;
34 class DrawingContext;
35 class CodeController;
36 class Menu;
37
38 /**
39  * The GameSession class controlls the controll flow of the Game (the part
40  * where you actually play a level)
41  */
42 class GameSession : public Screen
43 {
44 public:
45   GameSession(const std::string& levelfile, Statistics* statistics = NULL);
46   ~GameSession();
47
48   void record_demo(const std::string& filename);
49   void play_demo(const std::string& filename);
50
51   void draw(DrawingContext& context);
52   void update(float frame_ratio);
53   void setup();
54
55   void set_current()
56   { current_ = this; }
57   static GameSession* current()
58   { return current_; }
59
60   /// ends the current level
61   void finish(bool win = true);
62   void respawn(const std::string& sectorname, const std::string& spawnpointname);
63   void set_reset_point(const std::string& sectorname, const Vector& pos);
64   void display_info_box(const std::string& text);
65   
66   Sector* get_current_sector()
67   { return currentsector; }
68
69   Level* get_current_level()
70   { return level.get(); }
71
72   void start_sequence(const std::string& sequencename);
73
74   /**
75    * returns the "working directory" usually this is the directory where the
76    * currently played level resides. This is used when locating additional
77    * resources for the current level/world
78    */
79   std::string get_working_directory();
80   void restart_level(bool fromBeginning = true);
81
82 private:
83   void check_end_conditions();
84   void process_events();
85   void capture_demo_step();
86
87   void levelintro();
88   void drawstatus(DrawingContext& context);
89   void draw_pause(DrawingContext& context);
90
91   void on_escape_press();
92   void process_menu();
93
94   Timer endsequence_timer;
95   std::auto_ptr<Level> level;
96   std::auto_ptr<Surface> statistics_backdrop;
97
98   Sector* currentsector;
99
100   int levelnb;
101   int pause_menu_frame;
102
103   /** If true the end_sequence will be played, user input will be
104       ignored while doing that */
105   enum EndSequenceState {
106     NO_ENDSEQUENCE,
107     ENDSEQUENCE_RUNNING, // tux is running right
108     ENDSEQUENCE_WAITING  // waiting for the end of the music
109   };
110   EndSequenceState end_sequence;
111   float last_x_pos;
112   CodeController* end_sequence_controller;
113
114   bool game_pause;
115
116   std::string levelfile;
117
118   // reset point (the point where tux respawns if he dies)
119   std::string reset_sector;
120   Vector reset_pos;
121
122   // the sector and spawnpoint we should spawn after this frame
123   std::string newsector;
124   std::string newspawnpoint;
125
126   static GameSession* current_;
127
128   Statistics* best_level_statistics;
129
130   std::ostream* capture_demo_stream;
131   std::string capture_file;
132   std::istream* playback_demo_stream;
133   CodeController* demo_controller;
134
135   std::auto_ptr<Menu> game_menu;
136 };
137
138 #endif /*SUPERTUX_GAMELOOP_H*/
139