13396eab1a9c71dbf7f556b184c3634ffcd7db8f
[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* bigtux_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 class TuxBodyParts
107 {
108 public:
109   TuxBodyParts() { };
110   ~TuxBodyParts() { };
111
112   void set_action(std::string action);
113   void draw(DrawingContext& context, const Vector& pos, int layer,
114                 Uint32 drawing_effect = NONE_EFFECT);
115
116   Sprite* head;
117   Sprite* body;
118   Sprite* arms;
119   Sprite* feet;
120 };
121
122 extern TuxBodyParts* small_tux;
123 extern TuxBodyParts* big_tux;
124 extern TuxBodyParts* fire_tux;
125 extern TuxBodyParts* ice_tux;
126
127 class Player : public MovingObject
128 {
129 public:
130   enum HurtMode { KILL, SHRINK };
131   enum Power { NONE_POWER, FIRE_POWER, ICE_POWER };
132   enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING };
133
134   player_input_type  input;
135   int got_power;
136   int size;
137   bool duck;
138   bool holding_something;
139   bool dead;
140   DyingType dying;
141
142   Direction dir;
143   Direction old_dir;
144
145   float last_ground_y;
146   FallMode fall_mode;
147
148   bool jumping;
149   bool can_jump;
150   bool butt_jump;
151   int frame_;
152   int frame_main;
153
154   base_type  previous_base;
155   Timer invincible_timer;
156   Timer skidding_timer;
157   Timer safe_timer;
158   Timer frame_timer;
159   Timer kick_timer;
160   Timer shooting_timer;   // used to show the arm when Tux is shooting
161   Timer dying_timer;
162   Timer growing_timer;
163   Physic physic;
164   
165 public:
166   Player();
167   virtual ~Player();
168   
169   int  key_event(SDLKey key, int state);
170   void level_begin();
171   void handle_input();
172   void grabdistros();
173
174   virtual void action(float elapsed_time);
175   virtual void draw(DrawingContext& context);
176   virtual void collision(const MovingObject& other_object,
177       int collision_type);
178
179   void collision(void* p_c_object, int c_object);
180   void kill(HurtMode mode);
181   void player_remove_powerups();
182   void check_bounds(Camera* camera);
183   bool on_ground();
184   bool under_solid();
185   bool tiles_on_air(int tiles);
186   void grow(bool animate);
187   void move(const Vector& vector);
188
189   /** let the player jump a bit or more if jump button is hold down
190       (used when you hit a badguy) */
191   void bounce(BadGuy* badguy);
192
193   bool is_dead() const
194   { return dead; }
195   
196 private:
197   void init();
198   
199   void handle_horizontal_input();
200   void handle_vertical_input();
201   void remove_powerups();
202 };
203
204 #endif /*SUPERTUX_PLAYER_H*/
205
206 /* Local Variables: */
207 /* mode:c++ */
208 /* End: */