- Cleanups
[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 TIME_WARNING 20000     /* When to alert player they're low on time! */
44
45 /* One-ups... */
46
47 #define DISTROS_LIFEUP 100
48
49 /* Scores: */
50
51 #define SCORE_BRICK 5
52 #define SCORE_DISTRO 25
53
54 /* Sizes: */
55
56 #define SMALL 0
57 #define BIG 1
58
59 #include <vector>
60
61 struct PlayerKeymap
62 {
63 public:
64   int jump;
65   int activate;
66   int duck;
67   int left;
68   int right;
69   int fire;
70   
71   PlayerKeymap();
72 };
73
74 extern PlayerKeymap keymap;
75
76 struct player_input_type
77 {
78   int right;
79   int left;
80   int up;
81   int old_up;
82   int down;
83   int fire;
84   int old_fire;
85   int activate;
86 };
87
88 void player_input_init(player_input_type* pplayer_input);
89
90 namespace SuperTux {
91 class Sprite;
92 }
93 class Camera;
94
95 extern Surface* tux_life;
96
97 extern Sprite* smalltux_gameover;
98 extern Sprite* smalltux_star;
99 extern Sprite* largetux_star;
100
101 #define GROWING_TIME 1000
102 #define GROWING_FRAMES 7
103 extern Surface* growingtux_left[GROWING_FRAMES];
104 extern Surface* growingtux_right[GROWING_FRAMES];
105
106 struct PlayerSprite
107 {
108   Sprite* stand_left;
109   Sprite* stand_right;
110   Sprite* walk_right;
111   Sprite* walk_left;
112   Sprite* jump_right;
113   Sprite* jump_left;
114   Sprite* kick_left;
115   Sprite* kick_right;
116   Sprite* skid_right;
117   Sprite* skid_left;
118   Sprite* grab_left;
119   Sprite* grab_right;
120   Sprite* duck_right;
121   Sprite* duck_left;
122   Sprite* stomp;
123 };
124
125 extern PlayerSprite smalltux;
126 extern PlayerSprite largetux;
127 extern PlayerSprite firetux;
128 extern PlayerSprite icetux;
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 can_jump;
153   bool butt_jump;
154   int frame_;
155   int frame_main;
156
157   base_type  previous_base;
158   Timer invincible_timer;
159   Timer skidding_timer;
160   Timer safe_timer;
161   Timer frame_timer;
162   Timer kick_timer;
163   Timer shooting_timer;   // used to show the arm when Tux is shooting
164   Timer dying_timer;
165   Timer growing_timer;
166   Timer stomp_timer;
167   Physic physic;
168   
169   Vector stomp_pos;
170
171 public:
172   Player();
173   virtual ~Player();
174   
175   int  key_event(SDLKey key, int state);
176   void level_begin();
177   void handle_input();
178   void grabdistros();
179
180   virtual void action(float elapsed_time);
181   virtual void draw(DrawingContext& context);
182   virtual void collision(const MovingObject& other_object,
183       int collision_type);
184
185   void collision(void* p_c_object, int c_object);
186   void kill(HurtMode mode);
187   void player_remove_powerups();
188   void check_bounds(Camera* camera);
189   bool on_ground();
190   bool under_solid();
191   bool tiles_on_air(int tiles);
192   void grow(bool animate);
193   void move(const Vector& vector);
194
195   /** let the player jump a bit or more if jump button is hold down
196       (used when you hit a badguy) */
197   void bounce(BadGuy* badguy);
198
199   bool is_dead() const
200   { return dead; }
201   
202 private:
203   void init();
204   
205   void handle_horizontal_input();
206   void handle_vertical_input();
207   void remove_powerups();
208 };
209
210 #endif /*SUPERTUX_PLAYER_H*/
211
212 /* Local Variables: */
213 /* mode:c++ */
214 /* End: */