- added standard copyright header to every file
[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 player_keymap_type
50 {
51   int jump;
52   int duck;
53   int left;
54   int right;
55   int fire;
56 };
57
58 struct player_input_type
59 {
60   int right;
61   int left;
62   int up;
63   int down;
64   int fire;
65   int old_fire;
66 };
67
68 void player_input_init(player_input_type* pplayer_input);
69
70 class Sprite;
71
72 extern Surface* tux_life;
73 extern std::vector<Surface*> tux_right;
74 extern std::vector<Surface*> tux_left;
75 extern Surface* smalltux_jump_left;
76 extern Surface* smalltux_jump_right;
77 extern Surface* smalltux_stand_left;
78 extern Surface* smalltux_stand_right;
79 extern Sprite* bigtux_right;
80 extern Sprite* bigtux_left;
81 extern Sprite* bigtux_right_jump;
82 extern Sprite* bigtux_left_jump;
83 extern Sprite* ducktux_right;
84 extern Sprite* ducktux_left;
85 extern Surface* skidtux_right;
86 extern Surface* skidtux_left;
87 extern Surface* firetux_right[3];
88 extern Surface* firetux_left[3];
89 extern Surface* bigfiretux_right[3];
90 extern Surface* bigfiretux_left[3];
91 extern Surface* bigfiretux_right_jump;
92 extern Surface* bigfiretux_left_jump;
93 extern Surface* duckfiretux_right;
94 extern Surface* duckfiretux_left;
95 extern Surface* skidfiretux_right;
96 extern Surface* skidfiretux_left;
97 extern Surface* cape_right[2];
98 extern Surface* cape_left[2];
99 extern Surface* bigcape_right[2];
100 extern Surface* bigcape_left[2];
101
102 class Player
103 {
104  public:
105   player_keymap_type keymap;
106
107   player_input_type  input;
108   bool got_coffee;
109   int size;
110   bool duck;
111   DyingType dying;
112   int dir;
113   bool jumping;
114   int frame_;
115   int frame_main;
116
117   base_type  base;
118   base_type  old_base;
119   base_type  previous_base;
120   Timer invincible_timer;
121   Timer skidding_timer;
122   Timer safe_timer;
123   Timer frame_timer;
124   Physic physic;
125
126  public:
127   void init();
128   int  key_event(SDLKey key, int state);
129   void level_begin();
130   void action(double frame_ratio);
131   void handle_input();
132   void grabdistros();
133   void draw();
134   void collision(void* p_c_object, int c_object);
135   void kill(int mode);
136   void is_dying();
137   bool is_dead();
138   void player_remove_powerups();
139   void keep_in_bounds();
140   bool on_ground();
141   bool under_solid();
142   
143  private:
144   void handle_horizontal_input();
145   void handle_vertical_input();
146   void remove_powerups();
147 };
148
149 #endif /*SUPERTUX_PLAYER_H*/