95b1a56b82ff6ddecdf782cd8c691e9588024d8d
[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
116   player_input_type  input;
117   int got_power;
118   int size;
119   bool duck;
120   bool holding_something;
121   DyingType dying;
122
123   Direction dir;
124   Direction old_dir;
125
126   bool jumping;
127   bool can_jump;
128   bool butt_jump;
129   int frame_;
130   int frame_main;
131
132   base_type  previous_base;
133   Timer invincible_timer;
134   Timer skidding_timer;
135   Timer safe_timer;
136   Timer frame_timer;
137   Timer kick_timer;
138   Timer shooting_timer;   // used to show the arm when Tux is shooting
139   Physic physic;
140
141 public:
142   Player(DisplayManager& display_manager);
143   virtual ~Player();
144   
145   int  key_event(SDLKey key, int state);
146   void level_begin();
147   void handle_input();
148   void grabdistros();
149
150   virtual void action(float elapsed_time);
151   virtual void draw(ViewPort& viewport, int layer);
152   virtual void collision(const MovingObject& other_object,
153       int collision_type);
154   virtual std::string type() const
155   { return "Player"; }
156
157   void collision(void* p_c_object, int c_object);
158   void kill(HurtMode mode);
159   void is_dying();
160   bool is_dead();
161   void player_remove_powerups();
162   void check_bounds(ViewPort& viewport, bool back_scrolling, bool hor_autoscroll);
163   bool on_ground();
164   bool under_solid();
165   bool tiles_on_air(int tiles);
166   void grow();
167   
168 private:
169   void init();
170   
171   void handle_horizontal_input();
172   void handle_vertical_input();
173   void remove_powerups();
174 };
175
176 #endif /*SUPERTUX_PLAYER_H*/
177
178 /* Local Variables: */
179 /* mode:c++ */
180 /* End: */