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