1 //  $Id: player.h 2620 2005-06-18 12:12:10Z matzebraun $
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 1800
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 class BadGuy;
79 
80 extern Surface* tux_life;
81 
82 extern Sprite* smalltux_gameover;
83 extern Sprite* smalltux_star;
84 extern Sprite* largetux_star;
85 
86 struct PlayerSprite
87 {
88   Sprite* stand_left;
89   Sprite* stand_right;
90   Sprite* walk_right;
91   Sprite* walk_left;
92   Sprite* jump_right;
93   Sprite* jump_left;
94   Sprite* kick_left;
95   Sprite* kick_right;
96   Sprite* skid_right;
97   Sprite* skid_left;
98   Sprite* grab_left;
99   Sprite* grab_right;
100   Sprite* duck_right;
101   Sprite* duck_left;
102 };
103 
104 extern PlayerSprite smalltux;
105 extern PlayerSprite largetux;
106 extern PlayerSprite firetux;
107 
108 class Player : public GameObject
109 {
110 public:
111   enum HurtMode { KILL, SHRINK };
112 
113   player_input_type  input;
114   bool got_coffee;
115   int size;
116   bool duck;
117   bool holding_something;
118   DyingType dying;
119 
120   Direction dir;
121   Direction old_dir;
122 
123   bool jumping;
124   bool can_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   void jump_of_badguy(BadGuy* badguy);
155 
type()156   std::string type() { return "Player";};
157 
158 private:
159   void handle_horizontal_input();
160   void handle_vertical_input();
161   void remove_powerups();
162 };
163 
164 #endif /*SUPERTUX_PLAYER_H*/
165 
166 /* Local Variables: */
167 /* mode:c++ */
168 /* End: */
169