changing directions while flapping now works
[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
20 #ifndef SUPERTUX_PLAYER_H
21 #define SUPERTUX_PLAYER_H
22
23 #include "SDL.h"
24
25 #include "bitmask.h"
26 #include "special/timer.h"
27 #include "special/base.h"
28 #include "video/surface.h"
29 #include "collision.h"
30 #include "special/moving_object.h"
31 #include "math/physic.h"
32 #include "defines.h"
33
34 using namespace SuperTux;
35
36 class BadGuy;
37
38 /* Times: */
39
40 #define TUX_SAFE_TIME 1250
41 #define TUX_INVINCIBLE_TIME 10000
42 #define TUX_INVINCIBLE_TIME_WARNING 2000
43 #define TUX_FLAPPING_TIME 1000 /* How long Tux can flap his wings to gain additional jump height */
44 #define TIME_WARNING 20000     /* When to alert player they're low on time! */
45
46 /* One-ups... */
47
48 #define DISTROS_LIFEUP 100
49
50 /* Scores: */
51
52 #define SCORE_BRICK 5
53 #define SCORE_DISTRO 20
54
55 /* Sizes: */
56
57 #define SMALL 0
58 #define BIG 1
59
60 #include <vector>
61
62 struct PlayerKeymap
63 {
64 public:
65   int jump;
66   int up;
67   int down;
68   int left;
69   int right;
70   int power;
71   
72   PlayerKeymap();
73 };
74
75 extern PlayerKeymap keymap;
76
77 struct player_input_type
78 {
79   int right;
80   int left;
81   int up;
82   int down;
83   int fire;
84   int old_fire;
85   int activate;
86   int jump;
87   int old_jump;
88 };
89
90 void player_input_init(player_input_type* pplayer_input);
91
92 namespace SuperTux {
93 class Sprite;
94 }
95 class Camera;
96
97 extern Surface* tux_life;
98
99 extern Sprite* smalltux_gameover;
100 extern Sprite* smalltux_star;
101 extern Sprite* bigtux_star;
102
103 #define GROWING_TIME 1000
104 #define GROWING_FRAMES 7
105 extern Surface* growingtux_left[GROWING_FRAMES];
106 extern Surface* growingtux_right[GROWING_FRAMES];
107
108 class TuxBodyParts
109 {
110 public:
111   TuxBodyParts() { };
112   ~TuxBodyParts() { };
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 jumping;
152   bool flapping;
153   bool can_jump;
154   bool can_flap;
155   bool falling_from_flap;
156   bool enable_hover;
157   bool butt_jump;
158   int frame_;
159   int frame_main;
160
161   base_type  previous_base;
162   Timer invincible_timer;
163   Timer skidding_timer;
164   Timer safe_timer;
165   Timer frame_timer;
166   Timer kick_timer;
167   Timer shooting_timer;   // used to show the arm when Tux is shooting
168   Timer dying_timer;
169   Timer growing_timer;
170   Timer idle_timer;
171   Timer flapping_timer;
172   Physic physic;
173   
174 public:
175   Player();
176   virtual ~Player();
177   
178   int  key_event(SDLKey key, int state);
179   void level_begin();
180   void handle_input();
181   void grabdistros();
182
183   virtual void action(float elapsed_time);
184   virtual void draw(DrawingContext& context);
185   virtual void collision(const MovingObject& other_object,
186       int collision_type);
187
188   void collision(void* p_c_object, int c_object);
189   void kill(HurtMode mode);
190   void player_remove_powerups();
191   void check_bounds(Camera* camera);
192   bool on_ground();
193   bool under_solid();
194   bool tiles_on_air(int tiles);
195   void grow(bool animate);
196   void move(const Vector& vector);
197
198   /** let the player jump a bit or more if jump button is hold down
199       (used when you hit a badguy) */
200   void bounce(BadGuy* badguy);
201
202   bool is_dead() const
203   { return dead; }
204   
205 private:
206   void init();
207   
208   void handle_horizontal_input();
209   void handle_vertical_input();
210   void remove_powerups();
211 };
212
213 #endif /*SUPERTUX_PLAYER_H*/
214
215 /* Local Variables: */
216 /* mode:c++ */
217 /* End: */