- new star tux, still rather pure, but useable
[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*  smalltux_skid_left;
85 extern Sprite*  smalltux_skid_right;
86 extern Sprite*  smalltux_gameover;
87 extern Sprite*  largetux_stand_left;
88 extern Sprite*  largetux_stand_right;
89
90 extern Sprite*  smalltux_kick_left;
91 extern Sprite*  smalltux_kick_right;
92 extern Sprite*  smalltux_grab_left;
93 extern Sprite*  smalltux_grab_right;
94 extern Sprite*  smalltux_star;
95 extern Sprite*  largetux_star;
96
97 extern Sprite*  largetux_kick_left;
98 extern Sprite*  largetux_kick_right;
99 extern Sprite*  largetux_grab_left;
100 extern Sprite*  largetux_grab_right;
101
102 extern Sprite* bigtux_right;
103 extern Sprite* bigtux_left;
104 extern Sprite* bigtux_right_jump;
105 extern Sprite* bigtux_left_jump;
106 extern Sprite* ducktux_right;
107 extern Sprite* ducktux_left;
108 extern Surface* skidtux_right;
109 extern Surface* skidtux_left;
110 extern Surface* firetux_right[3];
111 extern Surface* firetux_left[3];
112 extern Surface* bigfiretux_right[3];
113 extern Surface* bigfiretux_left[3];
114 extern Surface* bigfiretux_right_jump;
115 extern Surface* bigfiretux_left_jump;
116 extern Surface* duckfiretux_right;
117 extern Surface* duckfiretux_left;
118 extern Surface* skidfiretux_right;
119 extern Surface* skidfiretux_left;
120 extern Surface* cape_right[2];
121 extern Surface* cape_left[2];
122 extern Surface* bigcape_right[2];
123 extern Surface* bigcape_left[2];
124
125 class Player
126 {
127 public:
128   enum HurtMode { KILL, SHRINK };
129
130   player_input_type  input;
131   bool got_coffee;
132   int size;
133   bool duck;
134   bool holding_something;
135   DyingType dying;
136
137   Direction dir;
138
139   bool jumping;
140   int frame_;
141   int frame_main;
142
143   base_type  base;
144   base_type  old_base;
145   base_type  previous_base;
146   Timer invincible_timer;
147   Timer skidding_timer;
148   Timer safe_timer;
149   Timer frame_timer;
150   Physic physic;
151
152 public:
153   void init();
154   int  key_event(SDLKey key, int state);
155   void level_begin();
156   void action(double frame_ratio);
157   void handle_input();
158   void grabdistros();
159   void draw();
160   void collision(void* p_c_object, int c_object);
161   void kill(HurtMode mode);
162   void is_dying();
163   bool is_dead();
164   void player_remove_powerups();
165   void keep_in_bounds();
166   bool on_ground();
167   bool under_solid();
168   
169 private:
170   void handle_horizontal_input();
171   void handle_vertical_input();
172   void remove_powerups();
173 };
174
175 #endif /*SUPERTUX_PLAYER_H*/
176
177 /* Local Variables: */
178 /* mode:c++ */
179 /* End: */