renamed all .h to .hpp
[supertux.git] / src / object / player.hpp
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 #ifndef SUPERTUX_PLAYER_H
20 #define SUPERTUX_PLAYER_H
21
22 #include <vector>
23 #include <SDL.h>
24
25 #include "timer.hpp"
26 #include "direction.hpp"
27 #include "video/surface.hpp"
28 #include "moving_object.hpp"
29 #include "sprite/sprite.hpp"
30 #include "physic.hpp"
31 #include "control/controller.hpp"
32 #include "player_status.hpp"
33
34 class BadGuy;
35 class Portable;
36
37 /* Times: */
38 static const float TUX_SAFE_TIME = 1.8;
39 static const float TUX_INVINCIBLE_TIME = 10.0;
40 static const float TUX_INVINCIBLE_TIME_WARNING = 2.0;
41 static const float TUX_FLAPPING_TIME = 1; /* How long Tux can flap his wings to gain additional jump height */
42 static const float TUX_FLAPPING_STRENGTH = 100; /* How much Y velocity Tux gains when flapping */
43 static const float TUX_FLAPPING_LEAST_X = 30; /* How much X velocity Tux gains when flapping from vertical jump */
44 static const float GROWING_TIME = 1.0;
45 static const int GROWING_FRAMES = 7;
46
47 class Camera;
48 class PlayerStatus;
49
50 extern Surface* growingtux_left[GROWING_FRAMES];
51 extern Surface* growingtux_right[GROWING_FRAMES];
52
53 class TuxBodyParts
54 {
55 public:
56   TuxBodyParts()
57     : head(0), body(0), arms(0), feet(0)
58   { }
59   ~TuxBodyParts() {
60     delete head;
61     delete body;
62     delete arms;
63     delete feet;
64   }
65
66   void set_action(std::string action, int loops = -1);
67   void one_time_animation();
68   void draw(DrawingContext& context, const Vector& pos, int layer);
69
70   Sprite* head;
71   Sprite* body;
72   Sprite* arms;
73   Sprite* feet;
74 };
75
76 extern TuxBodyParts* small_tux;
77 extern TuxBodyParts* big_tux;
78 extern TuxBodyParts* fire_tux;
79 extern TuxBodyParts* ice_tux;
80
81 class Player : public MovingObject
82 {
83 public:
84   enum HurtMode { KILL, SHRINK };
85   enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING };
86
87   Controller* controller;
88   PlayerStatus* player_status;
89   bool duck;
90   bool dead;
91
92 private:
93   bool dying;
94 public:
95
96   Direction dir;
97   Direction old_dir;
98
99   float last_ground_y;
100   FallMode fall_mode;
101
102   bool on_ground_flag;
103   bool jumping;
104   bool flapping;
105   bool can_jump;
106   bool can_flap;
107   bool falling_from_flap;
108   bool enable_hover;
109   bool butt_jump;
110   
111   float flapping_velocity;
112
113   // Ricardo's flapping
114   int flaps_nb;
115
116   // temporary to help player's choosing a flapping
117   // TODO: remove this after agreeing on flapstyle!
118   enum { MAREK_FLAP, RICARDO_FLAP, RYAN_FLAP, NO_FLAP };
119   int flapping_mode;
120
121   Timer invincible_timer;
122   Timer skidding_timer;
123   Timer safe_timer;
124   Timer kick_timer;
125   Timer shooting_timer;   // used to show the arm when Tux is shooting
126   Timer dying_timer;
127   Timer growing_timer;
128   Timer idle_timer;
129   Timer flapping_timer;
130   Physic physic;
131   
132 public:
133   Player(PlayerStatus* player_status);
134   virtual ~Player();
135
136   void set_controller(Controller* controller);  
137
138   virtual void update(float elapsed_time);
139   virtual void draw(DrawingContext& context);
140   virtual HitResponse collision(GameObject& other, const CollisionHit& hit);
141
142   void make_invincible();
143   bool is_invincible() const
144   {
145     return invincible_timer.started();
146   }
147   bool is_dying() const
148   {
149     return dying;
150   }
151   
152   void kill(HurtMode mode);
153   void check_bounds(Camera* camera);
154   void move(const Vector& vector);
155   void set_bonus(BonusType type, bool animate = false);
156   PlayerStatus* get_status()
157   {
158     return player_status;
159   }
160
161   void bounce(BadGuy& badguy);
162
163   bool is_dead() const
164   { return dead; }
165   bool is_big();
166   
167 private:
168   void handle_input();
169   bool on_ground();
170   
171   void init();
172   
173   void handle_horizontal_input();
174   void handle_vertical_input();
175
176   Portable* grabbed_object;
177
178   Sprite* smalltux_gameover;
179   Sprite* smalltux_star;
180   Sprite* bigtux_star;
181 };
182
183 #endif /*SUPERTUX_PLAYER_H*/