The SuperTux library features a SuperTux namespace 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
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 "audio/sound.h"
31 #include "special/moving_object.h"
32 #include "math/physic.h"
33 #include "app/defines.h"
34
35 using namespace SuperTux;
36
37 class BadGuy;
38
39 /* Times: */
40
41 #define TUX_SAFE_TIME 1250
42 #define TUX_INVINCIBLE_TIME 10000
43 #define TUX_INVINCIBLE_TIME_WARNING 2000
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 25
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 activate;
67   int duck;
68   int left;
69   int right;
70   int fire;
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 old_up;
83   int down;
84   int fire;
85   int old_fire;
86   int activate;
87 };
88
89 void player_input_init(player_input_type* pplayer_input);
90
91 namespace SuperTux {
92 class Sprite;
93 }
94 class Camera;
95
96 extern Surface* tux_life;
97
98 extern Sprite* smalltux_gameover;
99 extern Sprite* smalltux_star;
100 extern Sprite* largetux_star;
101
102 #define GROWING_TIME 1000
103 #define GROWING_FRAMES 7
104 extern Surface* growingtux_left[GROWING_FRAMES];
105 extern Surface* growingtux_right[GROWING_FRAMES];
106
107 struct PlayerSprite
108 {
109   Sprite* stand_left;
110   Sprite* stand_right;
111   Sprite* walk_right;
112   Sprite* walk_left;
113   Sprite* jump_right;
114   Sprite* jump_left;
115   Sprite* kick_left;
116   Sprite* kick_right;
117   Sprite* skid_right;
118   Sprite* skid_left;
119   Sprite* grab_left;
120   Sprite* grab_right;
121   Sprite* duck_right;
122   Sprite* duck_left;
123   Sprite* stomp;
124 };
125
126 extern PlayerSprite smalltux;
127 extern PlayerSprite largetux;
128 extern PlayerSprite firetux;
129 extern PlayerSprite icetux;
130
131 class Player : public MovingObject
132 {
133 public:
134   enum HurtMode { KILL, SHRINK };
135   enum Power { NONE_POWER, FIRE_POWER, ICE_POWER };
136   enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING };
137
138   player_input_type  input;
139   int got_power;
140   int size;
141   bool duck;
142   bool holding_something;
143   bool dead;
144   DyingType dying;
145
146   Direction dir;
147   Direction old_dir;
148
149   float last_ground_y;
150   FallMode fall_mode;
151
152   bool jumping;
153   bool can_jump;
154   bool butt_jump;
155   int frame_;
156   int frame_main;
157
158   base_type  previous_base;
159   Timer invincible_timer;
160   Timer skidding_timer;
161   Timer safe_timer;
162   Timer frame_timer;
163   Timer kick_timer;
164   Timer shooting_timer;   // used to show the arm when Tux is shooting
165   Timer dying_timer;
166   Timer growing_timer;
167   Timer stomp_timer;
168   Physic physic;
169   
170   Vector stomp_pos;
171
172 public:
173   Player();
174   virtual ~Player();
175   
176   int  key_event(SDLKey key, int state);
177   void level_begin();
178   void handle_input();
179   void grabdistros();
180
181   virtual void action(float elapsed_time);
182   virtual void draw(DrawingContext& context);
183   virtual void collision(const MovingObject& other_object,
184       int collision_type);
185
186   void collision(void* p_c_object, int c_object);
187   void kill(HurtMode mode);
188   void player_remove_powerups();
189   void check_bounds(Camera* camera);
190   bool on_ground();
191   bool under_solid();
192   bool tiles_on_air(int tiles);
193   void grow(bool animate);
194   void move(const Vector& vector);
195
196   /** let the player jump a bit or more if jump button is hold down
197       (used when you hit a badguy) */
198   void bounce(BadGuy* badguy);
199
200   bool is_dead() const
201   { return dead; }
202   
203 private:
204   void init();
205   
206   void handle_horizontal_input();
207   void handle_vertical_input();
208   void remove_powerups();
209 };
210
211 #endif /*SUPERTUX_PLAYER_H*/
212
213 /* Local Variables: */
214 /* mode:c++ */
215 /* End: */