Fixed Score = -1 on worldmap display when no level has been played in a fresh slot.
[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 TUX_FLAPPING_TIME 1000 /* How long Tux can flap his wings to gain additional jump height */
44 #define TIME_WARNING 20000     /* When to alert player they're low on time! */
45
46 /* One-ups... */
47
48 #define DISTROS_LIFEUP 100
49
50 /* Scores: */
51
52 #define SCORE_BRICK 5
53 #define SCORE_DISTRO 20
54
55 /* Sizes: */
56
57 #define SMALL 0
58 #define BIG 1
59
60 #include <vector>
61
62 struct PlayerKeymap
63 {
64 public:
65   int jump;
66   int activate;
67   int duck;
68   int left;
69   int right;
70   int fire;
71   
72   PlayerKeymap();
73 };
74
75 extern PlayerKeymap keymap;
76
77 struct player_input_type
78 {
79   int right;
80   int left;
81   int up;
82   int old_up;
83   int down;
84   int fire;
85   int old_fire;
86   int activate;
87 };
88
89 void player_input_init(player_input_type* pplayer_input);
90
91 namespace SuperTux {
92 class Sprite;
93 }
94 class Camera;
95
96 extern Surface* tux_life;
97
98 extern Sprite* smalltux_gameover;
99 extern Sprite* smalltux_star;
100 extern Sprite* bigtux_star;
101
102 #define GROWING_TIME 1000
103 #define GROWING_FRAMES 7
104 extern Surface* growingtux_left[GROWING_FRAMES];
105 extern Surface* growingtux_right[GROWING_FRAMES];
106
107 class TuxBodyParts
108 {
109 public:
110   TuxBodyParts() { };
111   ~TuxBodyParts() { };
112
113   void set_action(std::string action);
114   void one_time_animation();
115   void draw(DrawingContext& context, const Vector& pos, int layer,
116                 Uint32 drawing_effect = NONE_EFFECT);
117
118   Sprite* head;
119   Sprite* body;
120   Sprite* arms;
121   Sprite* feet;
122 };
123
124 extern TuxBodyParts* small_tux;
125 extern TuxBodyParts* big_tux;
126 extern TuxBodyParts* fire_tux;
127 extern TuxBodyParts* ice_tux;
128
129 class Player : public MovingObject
130 {
131 public:
132   enum HurtMode { KILL, SHRINK };
133   enum Power { NONE_POWER, FIRE_POWER, ICE_POWER };
134   enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING };
135
136   player_input_type  input;
137   int got_power;
138   int size;
139   bool duck;
140   bool holding_something;
141   bool dead;
142   DyingType dying;
143
144   Direction dir;
145   Direction old_dir;
146
147   float last_ground_y;
148   FallMode fall_mode;
149
150   bool jumping;
151   bool flapping;
152   bool can_jump;
153   bool can_flap;
154   bool enable_hover;
155   bool butt_jump;
156   int frame_;
157   int frame_main;
158
159   base_type  previous_base;
160   Timer invincible_timer;
161   Timer skidding_timer;
162   Timer safe_timer;
163   Timer frame_timer;
164   Timer kick_timer;
165   Timer shooting_timer;   // used to show the arm when Tux is shooting
166   Timer dying_timer;
167   Timer growing_timer;
168   Timer idle_timer;
169   Timer flapping_timer;
170   Physic physic;
171   
172 public:
173   Player();
174   virtual ~Player();
175   
176   int  key_event(SDLKey key, int state);
177   void level_begin();
178   void handle_input();
179   void grabdistros();
180
181   virtual void action(float elapsed_time);
182   virtual void draw(DrawingContext& context);
183   virtual void collision(const MovingObject& other_object,
184       int collision_type);
185
186   void collision(void* p_c_object, int c_object);
187   void kill(HurtMode mode);
188   void player_remove_powerups();
189   void check_bounds(Camera* camera);
190   bool on_ground();
191   bool under_solid();
192   bool tiles_on_air(int tiles);
193   void grow(bool animate);
194   void move(const Vector& vector);
195
196   /** let the player jump a bit or more if jump button is hold down
197       (used when you hit a badguy) */
198   void bounce(BadGuy* badguy);
199
200   bool is_dead() const
201   { return dead; }
202   
203 private:
204   void init();
205   
206   void handle_horizontal_input();
207   void handle_vertical_input();
208   void remove_powerups();
209 };
210
211 #endif /*SUPERTUX_PLAYER_H*/
212
213 /* Local Variables: */
214 /* mode:c++ */
215 /* End: */