3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.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.
19 #ifndef SUPERTUX_PLAYER_H
20 #define SUPERTUX_PLAYER_H
26 #include "direction.hpp"
27 #include "video/surface.hpp"
28 #include "moving_object.hpp"
29 #include "sprite/sprite.hpp"
31 #include "control/controller.hpp"
32 #include "scripting/player.hpp"
33 #include "player_status.hpp"
34 #include "display_effect.hpp"
35 #include "script_interface.hpp"
36 #include "console.hpp"
42 static const float TUX_SAFE_TIME = 1.8;
43 static const float TUX_INVINCIBLE_TIME = 10.0;
44 static const float TUX_INVINCIBLE_TIME_WARNING = 2.0;
45 static const float GROWING_TIME = 1.0;
46 static const int GROWING_FRAMES = 7;
51 extern Surface* growingtux_left[GROWING_FRAMES];
52 extern Surface* growingtux_right[GROWING_FRAMES];
58 : head(0), body(0), arms(0), feet(0)
67 void set_action(std::string action, int loops = -1);
68 void one_time_animation();
69 void draw(DrawingContext& context, const Vector& pos, int layer);
77 extern TuxBodyParts* small_tux;
78 extern TuxBodyParts* big_tux;
79 extern TuxBodyParts* fire_tux;
80 extern TuxBodyParts* ice_tux;
82 class Player : public MovingObject, public Scripting::Player, public ScriptInterface
85 enum HurtMode { KILL, SHRINK };
86 enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING };
88 Controller* controller;
89 PlayerStatus* player_status;
96 int backflip_direction;
110 Timer invincible_timer;
111 Timer skidding_timer;
114 Timer shooting_timer; // used to show the arm when Tux is shooting
118 Timer backflip_timer;
122 Player(PlayerStatus* player_status);
125 virtual void expose(HSQUIRRELVM vm, int table_idx);
126 virtual void unexpose(HSQUIRRELVM vm, int table_idx);
128 void set_controller(Controller* controller);
130 virtual void update(float elapsed_time);
131 virtual void draw(DrawingContext& context);
132 virtual HitResponse collision(GameObject& other, const CollisionHit& hit);
133 virtual void collision_tile(uint32_t tile_attributes);
135 void make_invincible();
136 bool is_invincible() const
138 return invincible_timer.started();
140 bool is_dying() const
145 void kill(HurtMode mode);
146 void check_bounds(Camera* camera);
147 void move(const Vector& vector);
148 void set_bonus(BonusType type, bool animate = false);
149 PlayerStatus* get_status()
151 return player_status;
153 // set kick animation
157 * Adds velocity to the player (be carefull when using this)
159 void add_velocity(const Vector& velocity);
161 void bounce(BadGuy& badguy);
167 void set_visible(bool visible);
178 void handle_horizontal_input();
179 void handle_vertical_input();
183 void walk(float speed);
189 Portable* grabbed_object;
191 Sprite* smalltux_gameover;
192 Sprite* smalltux_star;
197 #endif /*SUPERTUX_PLAYER_H*/