- beginnings of a wingling
[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 "texture.h"
28 #include "collision.h"
29 #include "sound.h"
30 #include "moving_object.h"
31 #include "drawable.h"
32 #include "physic.h"
33
34 /* Times: */
35
36 #define TUX_SAFE_TIME 1250
37 #define TUX_INVINCIBLE_TIME 10000
38 #define TUX_INVINCIBLE_TIME_WARNING 2000
39 #define TIME_WARNING 20000     /* When to alert player they're low on time! */
40
41 /* One-ups... */
42
43 #define DISTROS_LIFEUP 100
44
45 /* Scores: */
46
47 #define SCORE_BRICK 5
48 #define SCORE_DISTRO 25
49
50 #include <vector>
51
52 struct PlayerKeymap
53 {
54 public:
55   int jump;
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 };
76
77 void player_input_init(player_input_type* pplayer_input);
78
79 class Sprite;
80
81 extern Surface* tux_life;
82
83 extern Sprite* smalltux_gameover;
84 extern Sprite* smalltux_star;
85 extern Sprite* largetux_star;
86
87 struct PlayerSprite
88 {
89   Sprite* stand_left;
90   Sprite* stand_right;
91   Sprite* walk_right;
92   Sprite* walk_left;
93   Sprite* jump_right;
94   Sprite* jump_left;
95   Sprite* kick_left;
96   Sprite* kick_right;
97   Sprite* skid_right;
98   Sprite* skid_left;
99   Sprite* grab_left;
100   Sprite* grab_right;
101   Sprite* duck_right;
102   Sprite* duck_left;
103 };
104
105 extern PlayerSprite smalltux;
106 extern PlayerSprite largetux;
107 extern PlayerSprite firetux;
108 extern PlayerSprite icetux;
109
110 class Player : public MovingObject, public Drawable
111 {
112 public:
113   enum HurtMode { KILL, SHRINK };
114   enum Power { NONE_POWER, FIRE_POWER, ICE_POWER };
115   enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING };
116
117   player_input_type  input;
118   int got_power;
119   int size;
120   bool duck;
121   bool holding_something;
122   bool dead;
123   DyingType dying;
124
125   Direction dir;
126   Direction old_dir;
127
128   float last_ground_y;
129   FallMode fall_mode;
130
131   bool jumping;
132   bool can_jump;
133   bool butt_jump;
134   int frame_;
135   int frame_main;
136
137   base_type  previous_base;
138   Timer invincible_timer;
139   Timer skidding_timer;
140   Timer safe_timer;
141   Timer frame_timer;
142   Timer kick_timer;
143   Timer shooting_timer;   // used to show the arm when Tux is shooting
144   Timer dying_timer;
145   Physic physic;
146
147 public:
148   Player(DisplayManager& display_manager);
149   virtual ~Player();
150   
151   int  key_event(SDLKey key, int state);
152   void level_begin();
153   void handle_input();
154   void grabdistros();
155
156   virtual void action(float elapsed_time);
157   virtual void draw(Camera& viewport, int layer);
158   virtual void collision(const MovingObject& other_object,
159       int collision_type);
160
161   void collision(void* p_c_object, int c_object);
162   void kill(HurtMode mode);
163   void player_remove_powerups();
164   void check_bounds(Camera& viewport, bool back_scrolling, bool hor_autoscroll);
165   bool on_ground();
166   bool under_solid();
167   bool tiles_on_air(int tiles);
168   void grow();
169   void move(const Vector& vector);
170   bool is_dead() const
171   { return dead; }
172   
173 private:
174   void init();
175   
176   void handle_horizontal_input();
177   void handle_vertical_input();
178   void remove_powerups();
179 };
180
181 #endif /*SUPERTUX_PLAYER_H*/
182
183 /* Local Variables: */
184 /* mode:c++ */
185 /* End: */