Changed Yeti behaviour. You must stun him (jump on him) when is under a falling stala...
[supertux.git] / src / gameloop.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 Bill Kendrick <bill@newbreedsoftware.com>
5 //                     Tobias Glaesser <tobi.web@gmx.de>
6 //                     Ingo Ruhnke <grumbel@gmx.de>
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; either version 2
11 //  of the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 // 
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
22 #ifndef SUPERTUX_GAMELOOP_H
23 #define SUPERTUX_GAMELOOP_H
24
25 #include <SDL.h>
26 #include "timer.h"
27 #include "statistics.h"
28
29 using namespace SuperTux;
30
31 /* GameLoop modes */
32
33 #define ST_GL_PLAY 0
34 #define ST_GL_TEST 1
35 #define ST_GL_LOAD_GAME 2
36 #define ST_GL_LOAD_LEVEL_FILE  3
37 #define ST_GL_DEMO_GAME  4
38
39 enum GameMenuIDs {
40   MNID_CONTINUE,
41   MNID_ABORTLEVEL
42   };
43
44 extern int game_started;
45
46 class Level;
47 class Sector;
48 class Statistics;
49
50 namespace SuperTux {
51 class DrawingContext;
52 }
53
54 /** The GameSession class controlls the controll flow of a World, ie.
55     present the menu on specifc keypresses, render and update it while
56     keeping the speed and framerate sane, etc. */
57 class GameSession
58 {
59 public:
60   enum ExitStatus { ES_NONE, ES_LEVEL_FINISHED, ES_GAME_OVER, ES_LEVEL_ABORT };
61
62 public:
63   DrawingContext* context;
64   Timer2 time_left;
65
66   GameSession(const std::string& levelfile, int mode, Statistics* statistics=0);
67   ~GameSession();
68
69   /** Enter the busy loop */
70   ExitStatus run();
71
72   void draw();
73   void action(float frame_ratio);
74
75   void set_current()
76   { current_ = this; }
77   static GameSession* current() { return current_; }
78
79   void respawn(const std::string& sectorname,
80       const std::string& spawnpointname);
81   void set_reset_point(const std::string& sectorname,
82       const Vector& pos);
83   void display_info_box(const std::string& text);
84   Sector* get_current_sector()
85   { return currentsector; }
86
87   void start_sequence(const std::string& sequencename);
88   
89 private:
90   void restart_level();
91
92   void check_end_conditions();
93   void start_timers();
94   void process_events();
95   void handle_cheats();
96
97   void levelintro();
98   void drawstatus(DrawingContext& context);
99   void drawendscreen();
100   void drawresultscreen();
101   void draw_pause();
102
103   void on_escape_press();
104   void process_menu();
105
106   Uint32 fps_ticks;
107   Timer2 endsequence_timer;
108   Level* level;
109   Sector* currentsector;
110
111   int st_gl_mode;
112   int levelnb;
113   float fps_fps;
114   int pause_menu_frame;
115
116   /** If true the end_sequence will be played, user input will be
117       ignored while doing that */
118   enum EndSequenceState {
119     NO_ENDSEQUENCE,
120     ENDSEQUENCE_RUNNING, // tux is running right
121     ENDSEQUENCE_WAITING  // waiting for the end of the music
122   };
123   EndSequenceState end_sequence;
124   float last_x_pos;
125
126   bool game_pause;
127
128   std::string levelfile;
129
130   // reset point (the point where tux respawns if he dies)
131   std::string reset_sector;
132   Vector reset_pos;
133
134   // the sector and spawnpoint we should spawn after this frame
135   std::string newsector;
136   std::string newspawnpoint;
137
138   static GameSession* current_;
139
140   // for cheating
141   std::string last_keys;
142
143   Statistics* best_level_statistics;
144
145   ExitStatus exit_status;
146 };
147
148 std::string slotinfo(int slot);
149
150 /** Return true if the gameloop() was entered, false otherwise */
151 bool process_load_game_menu();
152
153 #endif /*SUPERTUX_GAMELOOP_H*/
154