- added jumping from badguys (hold jump pressed while jumping on one)
[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 "type.h"
27 #include "timer.h"
28 #include "screen/texture.h"
29 #include "collision.h"
30 #include "sound.h"
31 #include "moving_object.h"
32 #include "physic.h"
33
34 /* Times: */
35
36 #define TUX_SAFE_TIME 1250
37 #define TUX_INVINCIBLE_TIME 10000
38 #define TUX_INVINCIBLE_TIME_WARNING 2000
39 #define TIME_WARNING 20000     /* When to alert player they're low on time! */
40
41 /* One-ups... */
42
43 #define DISTROS_LIFEUP 100
44
45 /* Scores: */
46
47 #define SCORE_BRICK 5
48 #define SCORE_DISTRO 25
49
50 #include <vector>
51
52 struct PlayerKeymap
53 {
54 public:
55   int jump;
56   int activate;
57   int duck;
58   int left;
59   int right;
60   int fire;
61   
62   PlayerKeymap();
63 };
64
65 extern PlayerKeymap keymap;
66
67 struct player_input_type
68 {
69   int right;
70   int left;
71   int up;
72   int old_up;
73   int down;
74   int fire;
75   int old_fire;
76   int activate;
77 };
78
79 void player_input_init(player_input_type* pplayer_input);
80
81 class Sprite;
82 class Camera;
83
84 extern Surface* tux_life;
85
86 extern Sprite* smalltux_gameover;
87 extern Sprite* smalltux_star;
88 extern Sprite* largetux_star;
89
90 #define GROWING_TIME 1000
91 #define GROWING_FRAMES 7
92 extern Surface* growingtux_left[GROWING_FRAMES];
93 extern Surface* growingtux_right[GROWING_FRAMES];
94
95 struct PlayerSprite
96 {
97   Sprite* stand_left;
98   Sprite* stand_right;
99   Sprite* walk_right;
100   Sprite* walk_left;
101   Sprite* jump_right;
102   Sprite* jump_left;
103   Sprite* kick_left;
104   Sprite* kick_right;
105   Sprite* skid_right;
106   Sprite* skid_left;
107   Sprite* grab_left;
108   Sprite* grab_right;
109   Sprite* duck_right;
110   Sprite* duck_left;
111   Sprite* stomp;
112 };
113
114 extern PlayerSprite smalltux;
115 extern PlayerSprite largetux;
116 extern PlayerSprite firetux;
117 extern PlayerSprite icetux;
118
119 class Player : public MovingObject
120 {
121 public:
122   enum HurtMode { KILL, SHRINK };
123   enum Power { NONE_POWER, FIRE_POWER, ICE_POWER };
124   enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING };
125
126   player_input_type  input;
127   int got_power;
128   int size;
129   bool duck;
130   bool holding_something;
131   bool dead;
132   DyingType dying;
133
134   Direction dir;
135   Direction old_dir;
136
137   float last_ground_y;
138   FallMode fall_mode;
139
140   bool jumping;
141   bool can_jump;
142   bool butt_jump;
143   int frame_;
144   int frame_main;
145
146   base_type  previous_base;
147   Timer invincible_timer;
148   Timer skidding_timer;
149   Timer safe_timer;
150   Timer frame_timer;
151   Timer kick_timer;
152   Timer shooting_timer;   // used to show the arm when Tux is shooting
153   Timer dying_timer;
154   Timer growing_timer;
155   Timer stomp_timer;
156   Physic physic;
157   
158   Vector stomp_pos;
159
160 public:
161   Player();
162   virtual ~Player();
163   
164   int  key_event(SDLKey key, int state);
165   void level_begin();
166   void handle_input();
167   void grabdistros();
168
169   virtual void action(float elapsed_time);
170   virtual void draw(DrawingContext& context);
171   virtual void collision(const MovingObject& other_object,
172       int collision_type);
173
174   void collision(void* p_c_object, int c_object);
175   void kill(HurtMode mode);
176   void player_remove_powerups();
177   void check_bounds(Camera* camera);
178   bool on_ground();
179   bool under_solid();
180   bool tiles_on_air(int tiles);
181   void grow(bool animate);
182   void move(const Vector& vector);
183
184   /** let the player jump a bit or more if jump button is hold down
185       (used when you hit a badguy) */
186   void bounce();
187
188   bool is_dead() const
189   { return dead; }
190   
191 private:
192   void init();
193   
194   void handle_horizontal_input();
195   void handle_vertical_input();
196   void remove_powerups();
197 };
198
199 #endif /*SUPERTUX_PLAYER_H*/
200
201 /* Local Variables: */
202 /* mode:c++ */
203 /* End: */