nolok dies properly now :)
[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, int loops = -1);
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   
160   float flapping_velocity;
161
162   // Ricardo's flapping
163   int flaps_nb;
164
165   // temporary to help player's choosing a flapping
166   enum { MAREK_FLAP, RICARDO_FLAP, RYAN_FLAP, NONE_FLAP };
167   int flapping_mode;
168
169   Timer2 invincible_timer;
170   Timer2 skidding_timer;
171   Timer2 safe_timer;
172   Timer2 kick_timer;
173   Timer2 shooting_timer;   // used to show the arm when Tux is shooting
174   Timer2 dying_timer;
175   Timer2 growing_timer;
176   Timer2 idle_timer;
177   Timer2 flapping_timer;
178   Physic physic;
179   
180 public:
181   Player();
182   virtual ~Player();
183   
184   int  key_event(SDLKey key, int state);
185   void level_begin();
186   void handle_input();
187   void grabdistros();
188
189   PlayerStatus& get_status();
190
191   virtual void action(float elapsed_time);
192   virtual void draw(DrawingContext& context);
193   virtual HitResponse collision(GameObject& other, const CollisionHit& hit);
194
195   void make_invincible();
196   bool is_invincible() const
197   {
198       return invincible_timer.started();
199   }
200   void kill(HurtMode mode);
201   void player_remove_powerups();
202   void check_bounds(Camera* camera);
203   bool on_ground();
204   bool under_solid();
205   void grow(bool animate = false);
206   void move(const Vector& vector);
207
208   void bounce(BadGuy& badguy);
209
210   bool is_dead() const
211   { return dead; }
212   
213 private:
214   void init();
215   
216   void handle_horizontal_input();
217   void handle_vertical_input();
218   void remove_powerups();
219 };
220
221 #endif /*SUPERTUX_PLAYER_H*/
222
223 /* Local Variables: */
224 /* mode:c++ */
225 /* End: */