a first implementation of doors to switch between sectors
[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 extern Sprite* growingtux_left;
89 extern Sprite* growingtux_right;
90
91 struct PlayerSprite
92 {
93   Sprite* stand_left;
94   Sprite* stand_right;
95   Sprite* walk_right;
96   Sprite* walk_left;
97   Sprite* jump_right;
98   Sprite* jump_left;
99   Sprite* kick_left;
100   Sprite* kick_right;
101   Sprite* skid_right;
102   Sprite* skid_left;
103   Sprite* grab_left;
104   Sprite* grab_right;
105   Sprite* duck_right;
106   Sprite* duck_left;
107 };
108
109 extern PlayerSprite smalltux;
110 extern PlayerSprite largetux;
111 extern PlayerSprite firetux;
112 extern PlayerSprite icetux;
113
114 class Player : public MovingObject
115 {
116 public:
117   enum HurtMode { KILL, SHRINK };
118   enum Power { NONE_POWER, FIRE_POWER, ICE_POWER };
119   enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING };
120
121   player_input_type  input;
122   int got_power;
123   int size;
124   bool duck;
125   bool holding_something;
126   bool dead;
127   DyingType dying;
128
129   Direction dir;
130   Direction old_dir;
131
132   float last_ground_y;
133   FallMode fall_mode;
134
135   bool jumping;
136   bool can_jump;
137   bool butt_jump;
138   int frame_;
139   int frame_main;
140
141   base_type  previous_base;
142   Timer invincible_timer;
143   Timer skidding_timer;
144   Timer safe_timer;
145   Timer frame_timer;
146   Timer kick_timer;
147   Timer shooting_timer;   // used to show the arm when Tux is shooting
148   Timer dying_timer;
149   Timer growing_timer;
150   Physic physic;
151
152 public:
153   Player();
154   virtual ~Player();
155   
156   int  key_event(SDLKey key, int state);
157   void level_begin();
158   void handle_input();
159   void grabdistros();
160
161   virtual void action(float elapsed_time);
162   virtual void draw(DrawingContext& context);
163   virtual void collision(const MovingObject& other_object,
164       int collision_type);
165
166   void collision(void* p_c_object, int c_object);
167   void kill(HurtMode mode);
168   void player_remove_powerups();
169   void check_bounds(Camera* camera);
170   bool on_ground();
171   bool under_solid();
172   bool tiles_on_air(int tiles);
173   void grow(bool animate);
174   void move(const Vector& vector);
175   bool is_dead() const
176   { return dead; }
177   
178 private:
179   void init();
180   
181   void handle_horizontal_input();
182   void handle_vertical_input();
183   void remove_powerups();
184 };
185
186 #endif /*SUPERTUX_PLAYER_H*/
187
188 /* Local Variables: */
189 /* mode:c++ */
190 /* End: */