- added butt-jump
[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 "physic.h"
31
32 /* Times: */
33
34 #define TUX_SAFE_TIME 1250
35 #define TUX_INVINCIBLE_TIME 10000
36 #define TUX_INVINCIBLE_TIME_WARNING 2000
37 #define TIME_WARNING 20000     /* When to alert player they're low on time! */
38
39 /* One-ups... */
40
41 #define DISTROS_LIFEUP 100
42
43 /* Scores: */
44
45 #define SCORE_BRICK 5
46 #define SCORE_DISTRO 25
47
48 #include <vector>
49
50 struct PlayerKeymap
51 {
52 public:
53   int jump;
54   int duck;
55   int left;
56   int right;
57   int fire;
58   
59   PlayerKeymap();
60 };
61
62 extern PlayerKeymap keymap;
63
64 struct player_input_type
65 {
66   int right;
67   int left;
68   int up;
69   int old_up;
70   int down;
71   int fire;
72   int old_fire;
73 };
74
75 void player_input_init(player_input_type* pplayer_input);
76
77 class Sprite;
78
79 extern Surface* tux_life;
80
81 extern Sprite* smalltux_gameover;
82 extern Sprite* smalltux_star;
83 extern Sprite* largetux_star;
84
85 struct PlayerSprite
86 {
87   Sprite* stand_left;
88   Sprite* stand_right;
89   Sprite* walk_right;
90   Sprite* walk_left;
91   Sprite* jump_right;
92   Sprite* jump_left;
93   Sprite* kick_left;
94   Sprite* kick_right;
95   Sprite* skid_right;
96   Sprite* skid_left;
97   Sprite* grab_left;
98   Sprite* grab_right;
99   Sprite* duck_right;
100   Sprite* duck_left;
101 };
102
103 extern PlayerSprite smalltux;
104 extern PlayerSprite largetux;
105 extern PlayerSprite firetux;
106
107 class Player : public GameObject
108 {
109 public:
110   enum HurtMode { KILL, SHRINK };
111
112   player_input_type  input;
113   bool got_coffee;
114   int size;
115   bool duck;
116   bool holding_something;
117   DyingType dying;
118
119   Direction dir;
120   Direction old_dir;
121
122   bool jumping;
123   bool can_jump;
124   bool butt_jump;
125   int frame_;
126   int frame_main;
127
128   base_type  previous_base;
129   Timer invincible_timer;
130   Timer skidding_timer;
131   Timer safe_timer;
132   Timer frame_timer;
133   Timer kick_timer;
134   Physic physic;
135
136 public:
137   void init();
138   int  key_event(SDLKey key, int state);
139   void level_begin();
140   void action(double frame_ratio);
141   void handle_input();
142   void grabdistros();
143   void draw();
144   void collision(void* p_c_object, int c_object);
145   void kill(HurtMode mode);
146   void is_dying();
147   bool is_dead();
148   void player_remove_powerups();
149   void check_bounds(bool back_scrolling, bool hor_autoscroll);
150   bool on_ground();
151   bool under_solid();
152   void grow();
153   
154   std::string type() { return "Player";};
155   
156 private:
157   void handle_horizontal_input();
158   void handle_vertical_input();
159   void remove_powerups();
160 };
161
162 #endif /*SUPERTUX_PLAYER_H*/
163
164 /* Local Variables: */
165 /* mode:c++ */
166 /* End: */