- moved tux gfx into a struct
[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
79 extern Sprite* smalltux_gameover;
80 extern Sprite* smalltux_star;
81 extern Sprite* largetux_star;
82
83 struct PlayerSprite
84 {
85   Sprite* stand_left;
86   Sprite* stand_right;
87   Sprite* walk_right;
88   Sprite* walk_left;
89   Sprite* jump_right;
90   Sprite* jump_left;
91   Sprite* kick_left;
92   Sprite* kick_right;
93   Sprite* skid_right;
94   Sprite* skid_left;
95   Sprite* grab_left;
96   Sprite* grab_right;
97   Sprite* duck_right;
98   Sprite* duck_left;
99 };
100
101 extern PlayerSprite smalltux;
102 extern PlayerSprite largetux;
103
104 extern Surface* firetux_right[3];
105 extern Surface* firetux_left[3];
106 extern Surface* bigfiretux_right[3];
107 extern Surface* bigfiretux_left[3];
108 extern Surface* bigfiretux_right_jump;
109 extern Surface* bigfiretux_left_jump;
110 extern Surface* duckfiretux_right;
111 extern Surface* duckfiretux_left;
112 extern Surface* skidfiretux_right;
113 extern Surface* skidfiretux_left;
114
115 class Player
116 {
117 public:
118   enum HurtMode { KILL, SHRINK };
119
120   player_input_type  input;
121   bool got_coffee;
122   int size;
123   bool duck;
124   bool holding_something;
125   DyingType dying;
126
127   Direction dir;
128
129   bool jumping;
130   int frame_;
131   int frame_main;
132
133   base_type  base;
134   base_type  old_base;
135   base_type  previous_base;
136   Timer invincible_timer;
137   Timer skidding_timer;
138   Timer safe_timer;
139   Timer frame_timer;
140   Physic physic;
141
142 public:
143   void init();
144   int  key_event(SDLKey key, int state);
145   void level_begin();
146   void action(double frame_ratio);
147   void handle_input();
148   void grabdistros();
149   void draw();
150   void collision(void* p_c_object, int c_object);
151   void kill(HurtMode mode);
152   void is_dying();
153   bool is_dead();
154   void player_remove_powerups();
155   void keep_in_bounds();
156   bool on_ground();
157   bool under_solid();
158   
159 private:
160   void handle_horizontal_input();
161   void handle_vertical_input();
162   void remove_powerups();
163 };
164
165 #endif /*SUPERTUX_PLAYER_H*/
166
167 /* Local Variables: */
168 /* mode:c++ */
169 /* End: */