Finally, made keys configurable via the menu!! ;)
[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 750
35 #define TUX_INVINCIBLE_TIME 10000
36 #define TIME_WARNING 20000     /* When to alert player they're low on time! */
37
38 /* One-ups... */
39
40 #define DISTROS_LIFEUP 100
41
42 /* Scores: */
43
44 #define SCORE_BRICK 5
45 #define SCORE_DISTRO 25
46
47 #include <vector>
48
49 struct PlayerKeymap
50 {
51 public:
52   int jump;
53   int duck;
54   int left;
55   int right;
56   int fire;
57   
58   PlayerKeymap();
59 };
60
61 extern PlayerKeymap keymap;
62
63 struct player_input_type
64 {
65   int right;
66   int left;
67   int up;
68   int down;
69   int fire;
70   int old_fire;
71 };
72
73 void player_input_init(player_input_type* pplayer_input);
74
75 class Sprite;
76
77 extern Surface* tux_life;
78 extern std::vector<Surface*> tux_right;
79 extern std::vector<Surface*> tux_left;
80 extern Surface* smalltux_jump_left;
81 extern Surface* smalltux_jump_right;
82 extern Surface* smalltux_stand_left;
83 extern Surface* smalltux_stand_right;
84 extern Sprite* bigtux_right;
85 extern Sprite* bigtux_left;
86 extern Sprite* bigtux_right_jump;
87 extern Sprite* bigtux_left_jump;
88 extern Sprite* ducktux_right;
89 extern Sprite* ducktux_left;
90 extern Surface* skidtux_right;
91 extern Surface* skidtux_left;
92 extern Surface* firetux_right[3];
93 extern Surface* firetux_left[3];
94 extern Surface* bigfiretux_right[3];
95 extern Surface* bigfiretux_left[3];
96 extern Surface* bigfiretux_right_jump;
97 extern Surface* bigfiretux_left_jump;
98 extern Surface* duckfiretux_right;
99 extern Surface* duckfiretux_left;
100 extern Surface* skidfiretux_right;
101 extern Surface* skidfiretux_left;
102 extern Surface* cape_right[2];
103 extern Surface* cape_left[2];
104 extern Surface* bigcape_right[2];
105 extern Surface* bigcape_left[2];
106
107 class Player
108 {
109 public:
110   player_input_type  input;
111   bool got_coffee;
112   int size;
113   bool duck;
114   DyingType dying;
115
116   Direction dir;
117
118   bool jumping;
119   int frame_;
120   int frame_main;
121
122   base_type  base;
123   base_type  old_base;
124   base_type  previous_base;
125   Timer invincible_timer;
126   Timer skidding_timer;
127   Timer safe_timer;
128   Timer frame_timer;
129   Physic physic;
130
131 public:
132   void init();
133   int  key_event(SDLKey key, int state);
134   void level_begin();
135   void action(double frame_ratio);
136   void handle_input();
137   void grabdistros();
138   void draw();
139   void collision(void* p_c_object, int c_object);
140   void kill(int mode);
141   void is_dying();
142   bool is_dead();
143   void player_remove_powerups();
144   void keep_in_bounds();
145   bool on_ground();
146   bool under_solid();
147   
148 private:
149   void handle_horizontal_input();
150   void handle_vertical_input();
151   void remove_powerups();
152 };
153
154 #endif /*SUPERTUX_PLAYER_H*/
155
156 /* Local Variables: */
157 /* mode:c++ */
158 /* End: */