Added support for drawing effects again.
[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 duck;
56   int left;
57   int right;
58   int fire;
59   
60   PlayerKeymap();
61 };
62
63 extern PlayerKeymap keymap;
64
65 struct player_input_type
66 {
67   int right;
68   int left;
69   int up;
70   int old_up;
71   int down;
72   int fire;
73   int old_fire;
74 };
75
76 void player_input_init(player_input_type* pplayer_input);
77
78 class Sprite;
79 class Camera;
80
81 extern Surface* tux_life;
82
83 extern Sprite* smalltux_gameover;
84 extern Sprite* smalltux_star;
85 extern Sprite* largetux_star;
86 extern Sprite* growingtux_left;
87 extern Sprite* growingtux_right;
88
89 struct PlayerSprite
90 {
91   Sprite* stand_left;
92   Sprite* stand_right;
93   Sprite* walk_right;
94   Sprite* walk_left;
95   Sprite* jump_right;
96   Sprite* jump_left;
97   Sprite* kick_left;
98   Sprite* kick_right;
99   Sprite* skid_right;
100   Sprite* skid_left;
101   Sprite* grab_left;
102   Sprite* grab_right;
103   Sprite* duck_right;
104   Sprite* duck_left;
105 };
106
107 extern PlayerSprite smalltux;
108 extern PlayerSprite largetux;
109 extern PlayerSprite firetux;
110 extern PlayerSprite icetux;
111
112 class Player : public MovingObject
113 {
114 public:
115   enum HurtMode { KILL, SHRINK };
116   enum Power { NONE_POWER, FIRE_POWER, ICE_POWER };
117   enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING };
118
119   player_input_type  input;
120   int got_power;
121   int size;
122   bool duck;
123   bool holding_something;
124   bool dead;
125   DyingType dying;
126
127   Direction dir;
128   Direction old_dir;
129
130   float last_ground_y;
131   FallMode fall_mode;
132
133   bool jumping;
134   bool can_jump;
135   bool butt_jump;
136   int frame_;
137   int frame_main;
138
139   base_type  previous_base;
140   Timer invincible_timer;
141   Timer skidding_timer;
142   Timer safe_timer;
143   Timer frame_timer;
144   Timer kick_timer;
145   Timer shooting_timer;   // used to show the arm when Tux is shooting
146   Timer dying_timer;
147   Timer growing_timer;
148   Physic physic;
149
150 public:
151   Player();
152   virtual ~Player();
153   
154   int  key_event(SDLKey key, int state);
155   void level_begin();
156   void handle_input();
157   void grabdistros();
158
159   virtual void action(float elapsed_time);
160   virtual void draw(DrawingContext& context);
161   virtual void collision(const MovingObject& other_object,
162       int collision_type);
163
164   void collision(void* p_c_object, int c_object);
165   void kill(HurtMode mode);
166   void player_remove_powerups();
167   void check_bounds(Camera* camera);
168   bool on_ground();
169   bool under_solid();
170   bool tiles_on_air(int tiles);
171   void grow(bool animate);
172   void move(const Vector& vector);
173   bool is_dead() const
174   { return dead; }
175   
176 private:
177   void init();
178   
179   void handle_horizontal_input();
180   void handle_vertical_input();
181   void remove_powerups();
182 };
183
184 #endif /*SUPERTUX_PLAYER_H*/
185
186 /* Local Variables: */
187 /* mode:c++ */
188 /* End: */