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