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 "scripting/player.hpp"
34 #include "player_status.hpp"
35 #include "display_effect.hpp"
36 #include "script_interface.hpp"
37 #include "console.hpp"
44 static const float TUX_SAFE_TIME = 1.8;
45 static const float TUX_INVINCIBLE_TIME = 10.0;
46 static const float TUX_INVINCIBLE_TIME_WARNING = 2.0;
47 static const float GROWING_TIME = 0.35;
48 static const int GROWING_FRAMES = 7;
53 extern Surface* growingtux_left[GROWING_FRAMES];
54 extern Surface* growingtux_right[GROWING_FRAMES];
60 : head(0), body(0), arms(0), feet(0)
69 void set_action(std::string action, int loops = -1);
70 void one_time_animation();
71 void draw(DrawingContext& context, const Vector& pos, int layer);
79 extern TuxBodyParts* small_tux;
80 extern TuxBodyParts* big_tux;
81 extern TuxBodyParts* fire_tux;
82 extern TuxBodyParts* ice_tux;
84 class Player : public MovingObject, public Scripting::Player, public ScriptInterface
87 enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING };
89 Controller* controller;
90 PlayerStatus* player_status;
97 int backflip_direction;
113 Timer invincible_timer;
114 Timer skidding_timer;
117 Timer shooting_timer; // used to show the arm when Tux is shooting
121 Timer backflip_timer;
125 Player(PlayerStatus* player_status, const std::string& name);
128 virtual void expose(HSQUIRRELVM vm, SQInteger table_idx);
129 virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
131 void set_controller(Controller* controller);
132 Controller* get_controller()
137 virtual void update(float elapsed_time);
138 virtual void draw(DrawingContext& context);
139 virtual void collision_solid(const CollisionHit& hit);
140 virtual HitResponse collision(GameObject& other, const CollisionHit& hit);
141 virtual void collision_tile(uint32_t tile_attributes);
143 void make_invincible();
144 bool is_invincible() const
146 return invincible_timer.started();
148 bool is_dying() const
152 Direction peeking_direction() const
157 void kill(bool completely);
158 void check_bounds(Camera* camera);
159 void move(const Vector& vector);
161 virtual bool add_bonus(const std::string& bonus);
162 virtual void add_coins(int count);
165 * picks up a bonus, taking care not to pick up lesser bonus items than we already have
167 * @returns true if the bonus has been set (or was already good enough)
168 * false if the bonus could not be set (for example no space for big tux)
170 bool add_bonus(BonusType type, bool animate = false);
172 * like add_bonus, but can also downgrade the bonus items carried
174 bool set_bonus(BonusType type, bool animate = false);
176 PlayerStatus* get_status()
178 return player_status;
180 // set kick animation
184 * play cheer animation.
185 * This might need some space and behave in an unpredictable way. Best to use this at level end.
190 * duck down if possible.
191 * this won't last long as long as input is enabled.
196 * stand back up if possible.
201 * do a backflip if possible.
206 * jump in the air if possible
207 * sensible values for yspeed are negative - unless we want to jump into the ground of course
209 void do_jump(float yspeed);
212 * Adds velocity to the player (be carefull when using this)
214 void add_velocity(const Vector& velocity);
217 * Adds velocity to the player until given end speed is reached
219 void add_velocity(const Vector& velocity, const Vector& end_speed);
221 void bounce(BadGuy& badguy);
227 void set_visible(bool visible);
232 Portable* get_grabbed_object() const
234 return grabbed_object;
238 * Switches ghost mode on/off.
239 * Lets Tux float around and through solid objects.
241 void set_ghost_mode(bool enable);
244 * Returns whether ghost mode is currently enabled
246 bool get_ghost_mode() { return ghost_mode; }
249 * Changes height of bounding box.
250 * Returns true if successful, false otherwise
252 bool adjust_height(float new_height);
256 void handle_input_ghost(); /**< input handling while in ghost mode */
261 void handle_horizontal_input();
262 void handle_vertical_input();
266 void walk(float speed);
269 * slows Tux down a little, based on where he's standing
271 void apply_friction();
275 Portable* grabbed_object;
277 Sprite* smalltux_gameover;
278 Sprite* smalltux_star;
284 bool ghost_mode; /**< indicates if Tux should float around and through solid objects */
286 Timer unduck_hurt_timer; /**< if Tux wants to stand up again after ducking and cannot, this timer is started */
289 #endif /*SUPERTUX_PLAYER_H*/