mainly changed #includes to work with the new SuperTux library
[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 "audio/sound.h"
31 #include "special/moving_object.h"
32 #include "math/physic.h"
33 #include "app/defines.h"
34
35 class BadGuy;
36
37 /* Times: */
38
39 #define TUX_SAFE_TIME 1250
40 #define TUX_INVINCIBLE_TIME 10000
41 #define TUX_INVINCIBLE_TIME_WARNING 2000
42 #define TIME_WARNING 20000     /* When to alert player they're low on time! */
43
44 /* One-ups... */
45
46 #define DISTROS_LIFEUP 100
47
48 /* Scores: */
49
50 #define SCORE_BRICK 5
51 #define SCORE_DISTRO 25
52
53 /* Sizes: */
54
55 #define SMALL 0
56 #define BIG 1
57
58 #include <vector>
59
60 struct PlayerKeymap
61 {
62 public:
63   int jump;
64   int activate;
65   int duck;
66   int left;
67   int right;
68   int fire;
69   
70   PlayerKeymap();
71 };
72
73 extern PlayerKeymap keymap;
74
75 struct player_input_type
76 {
77   int right;
78   int left;
79   int up;
80   int old_up;
81   int down;
82   int fire;
83   int old_fire;
84   int activate;
85 };
86
87 void player_input_init(player_input_type* pplayer_input);
88
89 class Sprite;
90 class Camera;
91
92 extern Surface* tux_life;
93
94 extern Sprite* smalltux_gameover;
95 extern Sprite* smalltux_star;
96 extern Sprite* largetux_star;
97
98 #define GROWING_TIME 1000
99 #define GROWING_FRAMES 7
100 extern Surface* growingtux_left[GROWING_FRAMES];
101 extern Surface* growingtux_right[GROWING_FRAMES];
102
103 struct PlayerSprite
104 {
105   Sprite* stand_left;
106   Sprite* stand_right;
107   Sprite* walk_right;
108   Sprite* walk_left;
109   Sprite* jump_right;
110   Sprite* jump_left;
111   Sprite* kick_left;
112   Sprite* kick_right;
113   Sprite* skid_right;
114   Sprite* skid_left;
115   Sprite* grab_left;
116   Sprite* grab_right;
117   Sprite* duck_right;
118   Sprite* duck_left;
119   Sprite* stomp;
120 };
121
122 extern PlayerSprite smalltux;
123 extern PlayerSprite largetux;
124 extern PlayerSprite firetux;
125 extern PlayerSprite icetux;
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   Timer stomp_timer;
164   Physic physic;
165   
166   Vector stomp_pos;
167
168 public:
169   Player();
170   virtual ~Player();
171   
172   int  key_event(SDLKey key, int state);
173   void level_begin();
174   void handle_input();
175   void grabdistros();
176
177   virtual void action(float elapsed_time);
178   virtual void draw(DrawingContext& context);
179   virtual void collision(const MovingObject& other_object,
180       int collision_type);
181
182   void collision(void* p_c_object, int c_object);
183   void kill(HurtMode mode);
184   void player_remove_powerups();
185   void check_bounds(Camera* camera);
186   bool on_ground();
187   bool under_solid();
188   bool tiles_on_air(int tiles);
189   void grow(bool animate);
190   void move(const Vector& vector);
191
192   /** let the player jump a bit or more if jump button is hold down
193       (used when you hit a badguy) */
194   void bounce(BadGuy* badguy);
195
196   bool is_dead() const
197   { return dead; }
198   
199 private:
200   void init();
201   
202   void handle_horizontal_input();
203   void handle_vertical_input();
204   void remove_powerups();
205 };
206
207 #endif /*SUPERTUX_PLAYER_H*/
208
209 /* Local Variables: */
210 /* mode:c++ */
211 /* End: */