4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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.
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.
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.
20 #ifndef SUPERTUX_PLAYER_H
21 #define SUPERTUX_PLAYER_H
27 #include "direction.hpp"
28 #include "video/surface.hpp"
29 #include "moving_object.hpp"
30 #include "sprite/sprite.hpp"
32 #include "control/controller.hpp"
33 #include "control/codecontroller.hpp"
34 #include "scripting/player.hpp"
35 #include "player_status.hpp"
36 #include "display_effect.hpp"
37 #include "script_interface.hpp"
38 #include "console.hpp"
46 static const float TUX_SAFE_TIME = 1.8f;
47 static const float TUX_INVINCIBLE_TIME = 10.0f;
48 static const float TUX_INVINCIBLE_TIME_WARNING = 2.0f;
49 static const float GROWING_TIME = 0.35f;
50 static const int GROWING_FRAMES = 7;
55 extern Surface* growingtux_left[GROWING_FRAMES];
56 extern Surface* growingtux_right[GROWING_FRAMES];
62 : head(0), body(0), arms(0), feet(0)
71 void set_action(std::string action, int loops = -1);
72 void one_time_animation();
73 void draw(DrawingContext& context, const Vector& pos, int layer, Portable* grabbed_object);
81 extern TuxBodyParts* small_tux;
82 extern TuxBodyParts* big_tux;
83 extern TuxBodyParts* fire_tux;
84 extern TuxBodyParts* ice_tux;
86 class Player : public MovingObject, public UsesPhysic, public Scripting::Player, public ScriptInterface
89 enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING };
91 Controller* controller;
92 CodeController* scripting_controller; /**< This controller is used when the Player is controlled via scripting */
93 PlayerStatus* player_status;
96 //Tux can only go this fast. If set to 0 no special limit is used, only the default limits.
97 void set_speedlimit(float newlimit);
98 float get_speedlimit();
103 int backflip_direction;
107 Controller* scripting_controller_old; /**< Saves the old controller while the scripting_controller is used */
121 Timer invincible_timer;
122 Timer skidding_timer;
125 Timer shooting_timer; // used to show the arm when Tux is shooting
129 Timer backflip_timer;
132 Player(PlayerStatus* player_status, const std::string& name);
135 virtual void expose(HSQUIRRELVM vm, SQInteger table_idx);
136 virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
138 void set_controller(Controller* controller);
139 Controller* get_controller()
144 void use_scripting_controller(bool use_or_release);
145 void do_scripting_controller(std::string control, bool pressed);
147 virtual void update(float elapsed_time);
148 virtual void draw(DrawingContext& context);
149 virtual void collision_solid(const CollisionHit& hit);
150 virtual HitResponse collision(GameObject& other, const CollisionHit& hit);
151 virtual void collision_tile(uint32_t tile_attributes);
153 void make_invincible();
154 bool is_invincible() const
156 return invincible_timer.started();
158 bool is_dying() const
162 Direction peeking_direction() const
167 void kill(bool completely);
168 void check_bounds(Camera* camera);
169 void move(const Vector& vector);
171 virtual bool add_bonus(const std::string& bonus);
172 virtual void add_coins(int count);
173 virtual int get_coins();
176 * picks up a bonus, taking care not to pick up lesser bonus items than we already have
178 * @returns true if the bonus has been set (or was already good enough)
179 * false if the bonus could not be set (for example no space for big tux)
181 bool add_bonus(BonusType type, bool animate = false);
183 * like add_bonus, but can also downgrade the bonus items carried
185 bool set_bonus(BonusType type, bool animate = false);
187 PlayerStatus* get_status()
189 return player_status;
191 // set kick animation
195 * play cheer animation.
196 * This might need some space and behave in an unpredictable way. Best to use this at level end.
201 * duck down if possible.
202 * this won't last long as long as input is enabled.
207 * stand back up if possible.
212 * do a backflip if possible.
217 * jump in the air if possible
218 * sensible values for yspeed are negative - unless we want to jump into the ground of course
220 void do_jump(float yspeed);
223 * Adds velocity to the player (be carefull when using this)
225 void add_velocity(const Vector& velocity);
228 * Adds velocity to the player until given end speed is reached
230 void add_velocity(const Vector& velocity, const Vector& end_speed);
232 void bounce(BadGuy& badguy);
238 void set_visible(bool visible);
243 Portable* get_grabbed_object() const
245 return grabbed_object;
249 * Switches ghost mode on/off.
250 * Lets Tux float around and through solid objects.
252 void set_ghost_mode(bool enable);
255 * Switches edit mode on/off.
256 * In edit mode, Tux will enter ghost_mode instead of dying.
258 void set_edit_mode(bool enable);
261 * Returns whether ghost mode is currently enabled
263 bool get_ghost_mode() { return ghost_mode; }
266 * Changes height of bounding box.
267 * Returns true if successful, false otherwise
269 bool adjust_height(float new_height);
272 * Orders the current GameSession to start a sequence
274 void trigger_sequence(std::string sequence_name);
277 * Requests that the player start climbing the given Climbable
279 void start_climbing(Climbable& climbable);
282 * Requests that the player stop climbing the given Climbable
284 void stop_climbing(Climbable& climbable);
288 void handle_input_ghost(); /**< input handling while in ghost mode */
289 void handle_input_climbing(); /**< input handling while climbing */
294 void handle_horizontal_input();
295 void handle_vertical_input();
299 void walk(float speed);
302 * slows Tux down a little, based on where he's standing
304 void apply_friction();
308 Portable* grabbed_object;
310 Sprite* smalltux_gameover;
311 Sprite* smalltux_star;
314 std::auto_ptr<Surface> airarrow; /**< arrow indicating Tux' position when he's above the camera */
319 bool ghost_mode; /**< indicates if Tux should float around and through solid objects */
320 bool edit_mode; /**< indicates if Tux should switch to ghost mode rather than dying */
322 Timer unduck_hurt_timer; /**< if Tux wants to stand up again after ducking and cannot, this timer is started */
324 Climbable* climbing; /**< Climbable object we are currently climbing, null if none */
327 #endif /*SUPERTUX_PLAYER_H*/