- removed auto-repeat of jump events, now one has to press again to jump and can...
[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 old_up;
69   int down;
70   int fire;
71   int old_fire;
72 };
73
74 void player_input_init(player_input_type* pplayer_input);
75
76 class Sprite;
77
78 extern Surface* tux_life;
79
80 extern Sprite* smalltux_gameover;
81 extern Sprite* smalltux_star;
82 extern Sprite* largetux_star;
83
84 struct PlayerSprite
85 {
86   Sprite* stand_left;
87   Sprite* stand_right;
88   Sprite* walk_right;
89   Sprite* walk_left;
90   Sprite* jump_right;
91   Sprite* jump_left;
92   Sprite* kick_left;
93   Sprite* kick_right;
94   Sprite* skid_right;
95   Sprite* skid_left;
96   Sprite* grab_left;
97   Sprite* grab_right;
98   Sprite* duck_right;
99   Sprite* duck_left;
100 };
101
102 extern PlayerSprite smalltux;
103 extern PlayerSprite largetux;
104 extern PlayerSprite firetux;
105
106 class Player
107 {
108 public:
109   enum HurtMode { KILL, SHRINK };
110
111   player_input_type  input;
112   bool got_coffee;
113   int size;
114   bool duck;
115   bool holding_something;
116   DyingType dying;
117
118   Direction dir;
119
120   bool jumping;
121   int frame_;
122   int frame_main;
123
124   base_type  base;
125   base_type  old_base;
126   base_type  previous_base;
127   Timer invincible_timer;
128   Timer skidding_timer;
129   Timer safe_timer;
130   Timer frame_timer;
131   Timer kick_timer;
132   Physic physic;
133
134 public:
135   void init();
136   int  key_event(SDLKey key, int state);
137   void level_begin();
138   void action(double frame_ratio);
139   void handle_input();
140   void grabdistros();
141   void draw();
142   void collision(void* p_c_object, int c_object);
143   void kill(HurtMode mode);
144   void is_dying();
145   bool is_dead();
146   void player_remove_powerups();
147   void keep_in_bounds();
148   bool on_ground();
149   bool under_solid();
150   void grow();
151   
152 private:
153   void handle_horizontal_input();
154   void handle_vertical_input();
155   void remove_powerups();
156 };
157
158 #endif /*SUPERTUX_PLAYER_H*/
159
160 /* Local Variables: */
161 /* mode:c++ */
162 /* End: */