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