Should fix arm crash.
[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 };*/
123
124 extern Sprite* small_tux;
125 extern Sprite* big_tux;
126 extern Sprite* fire_tux;
127 extern Sprite* ice_tux;
128
129 extern Sprite* tux_arm;
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   Physic physic;
168   
169 public:
170   Player();
171   virtual ~Player();
172   
173   int  key_event(SDLKey key, int state);
174   void level_begin();
175   void handle_input();
176   void grabdistros();
177
178   virtual void action(float elapsed_time);
179   virtual void draw(DrawingContext& context);
180   virtual void collision(const MovingObject& other_object,
181       int collision_type);
182
183   void collision(void* p_c_object, int c_object);
184   void kill(HurtMode mode);
185   void player_remove_powerups();
186   void check_bounds(Camera* camera);
187   bool on_ground();
188   bool under_solid();
189   bool tiles_on_air(int tiles);
190   void grow(bool animate);
191   void move(const Vector& vector);
192
193   /** let the player jump a bit or more if jump button is hold down
194       (used when you hit a badguy) */
195   void bounce(BadGuy* badguy);
196
197   bool is_dead() const
198   { return dead; }
199   
200 private:
201   void init();
202   
203   void handle_horizontal_input();
204   void handle_vertical_input();
205   void remove_powerups();
206 };
207
208 #endif /*SUPERTUX_PLAYER_H*/
209
210 /* Local Variables: */
211 /* mode:c++ */
212 /* End: */