remove unused/outdated stgt files
[supertux.git] / src / player.h
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.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_PLAYER_H
20 #define SUPERTUX_PLAYER_H
21
22 #include "SDL.h"
23
24 #include "timer.h"
25 #include "video/surface.h"
26 #include "collision.h"
27 #include "special/moving_object.h"
28 #include "special/sprite.h"
29 #include "math/physic.h"
30 #include "defines.h"
31
32 using namespace SuperTux;
33
34 class BadGuy;
35
36 /* Times: */
37
38 #define TUX_SAFE_TIME 1.250
39 #define TUX_INVINCIBLE_TIME 10.0
40 #define TUX_INVINCIBLE_TIME_WARNING 2.0
41 #define TUX_FLAPPING_TIME 1 /* How long Tux can flap his wings to gain additional jump height */
42 #define TIME_WARNING 20     /* When to alert player they're low on time! */
43
44 /* Scores: */
45
46 #define SCORE_BRICK 5
47 #define SCORE_DISTRO 20
48
49 /* Sizes: */
50
51 #define SMALL 0
52 #define BIG 1
53
54 #include <vector>
55
56 struct PlayerKeymap
57 {
58 public:
59   int jump;
60   int up;
61   int down;
62   int left;
63   int right;
64   int power;
65   
66   PlayerKeymap();
67 };
68
69 extern PlayerKeymap keymap;
70
71 struct player_input_type
72 {
73   int right;
74   int left;
75   int up;
76   int old_up;
77   int down;
78   int fire;
79   int old_fire;
80   int activate;
81   int jump;
82   int old_jump;
83 };
84
85 void player_input_init(player_input_type* pplayer_input);
86
87 class Camera;
88 class PlayerStatus;
89
90 extern Surface* tux_life;
91
92 extern Sprite* smalltux_gameover;
93 extern Sprite* smalltux_star;
94 extern Sprite* bigtux_star;
95
96 #define GROWING_TIME 1.0
97 #define GROWING_FRAMES 7
98 extern Surface* growingtux_left[GROWING_FRAMES];
99 extern Surface* growingtux_right[GROWING_FRAMES];
100
101 class TuxBodyParts
102 {
103 public:
104   TuxBodyParts()
105     : head(0), body(0), arms(0), feet(0)
106   { }
107   ~TuxBodyParts() {
108     delete head;
109     delete body;
110     delete arms;
111     delete feet;
112   }
113
114   void set_action(std::string action);
115   void one_time_animation();
116   void draw(DrawingContext& context, const Vector& pos, int layer,
117                 Uint32 drawing_effect = NONE_EFFECT);
118
119   Sprite* head;
120   Sprite* body;
121   Sprite* arms;
122   Sprite* feet;
123 };
124
125 extern TuxBodyParts* small_tux;
126 extern TuxBodyParts* big_tux;
127 extern TuxBodyParts* fire_tux;
128 extern TuxBodyParts* ice_tux;
129
130 class Player : public MovingObject
131 {
132 public:
133   enum HurtMode { KILL, SHRINK };
134   enum Power { NONE_POWER, FIRE_POWER, ICE_POWER };
135   enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING };
136
137   player_input_type  input;
138   int got_power;
139   int size;
140   bool duck;
141   bool holding_something;
142   bool dead;
143   DyingType dying;
144
145   Direction dir;
146   Direction old_dir;
147
148   float last_ground_y;
149   FallMode fall_mode;
150
151   bool on_ground_flag;
152   bool jumping;
153   bool flapping;
154   bool can_jump;
155   bool can_flap;
156   bool falling_from_flap;
157   bool enable_hover;
158   bool butt_jump;
159   int frame_;
160   int frame_main;
161   
162   float flapping_velocity;
163
164   // Ricardo's flapping
165   int flaps_nb;
166
167   // temporary to help player's choosing a flapping
168   enum { MAREK_FLAP, RICARDO_FLAP, RYAN_FLAP, NONE_FLAP };
169   int flapping_mode;
170
171   Timer2 invincible_timer;
172   Timer2 skidding_timer;
173   Timer2 safe_timer;
174   Timer2 frame_timer;
175   Timer2 kick_timer;
176   Timer2 shooting_timer;   // used to show the arm when Tux is shooting
177   Timer2 dying_timer;
178   Timer2 growing_timer;
179   Timer2 idle_timer;
180   Timer2 flapping_timer;
181   Physic physic;
182   
183 public:
184   Player();
185   virtual ~Player();
186   
187   int  key_event(SDLKey key, int state);
188   void level_begin();
189   void handle_input();
190   void grabdistros();
191
192   PlayerStatus& get_status();
193
194   virtual void action(float elapsed_time);
195   virtual void draw(DrawingContext& context);
196   virtual HitResponse collision(GameObject& other, const CollisionHit& hit);
197
198   void make_invincible();
199   bool is_invincible() const
200   {
201       return invincible_timer.started();
202   }
203   void kill(HurtMode mode);
204   void player_remove_powerups();
205   void check_bounds(Camera* camera);
206   bool on_ground();
207   bool under_solid();
208   void grow(bool animate = false);
209   void move(const Vector& vector);
210
211   void bounce(BadGuy& badguy);
212
213   bool is_dead() const
214   { return dead; }
215   
216 private:
217   void init();
218   
219   void handle_horizontal_input();
220   void handle_vertical_input();
221   void remove_powerups();
222 };
223
224 #endif /*SUPERTUX_PLAYER_H*/
225
226 /* Local Variables: */
227 /* mode:c++ */
228 /* End: */