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