00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef HEADER_SUPERTUX_OBJECT_PLAYER_HPP
00018 #define HEADER_SUPERTUX_OBJECT_PLAYER_HPP
00019
00020 #include "scripting/player.hpp"
00021 #include "sprite/sprite_ptr.hpp"
00022 #include "supertux/direction.hpp"
00023 #include "supertux/moving_object.hpp"
00024 #include "supertux/physic.hpp"
00025 #include "supertux/player_status.hpp"
00026 #include "supertux/script_interface.hpp"
00027 #include "supertux/timer.hpp"
00028
00029 class BadGuy;
00030 class Portable;
00031 class Climbable;
00032 class Controller;
00033 class CodeController;
00034 class Surface;
00035 class Timer;
00036
00037
00038 static const float TUX_SAFE_TIME = 1.8f;
00039 static const float TUX_INVINCIBLE_TIME = 14.0f;
00040 static const float TUX_INVINCIBLE_TIME_WARNING = 2.0f;
00041 static const float GROWING_TIME = 0.35f;
00042 static const int GROWING_FRAMES = 7;
00043
00044 class Camera;
00045 class PlayerStatus;
00046
00047 class Player : public MovingObject,
00048 public scripting::Player,
00049 public ScriptInterface
00050 {
00051 public:
00052 enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING };
00053
00054 void set_speedlimit(float newlimit);
00055 float get_speedlimit();
00056
00057 public:
00058 Player(PlayerStatus* player_status, const std::string& name);
00059 virtual ~Player();
00060
00061 virtual void expose(HSQUIRRELVM vm, SQInteger table_idx);
00062 virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
00063
00064 void set_controller(Controller* controller);
00065
00066
00067
00068 void set_winning();
00069 bool is_winning()
00070 {
00071 return winning;
00072 }
00073
00074 Controller* get_controller()
00075 {
00076 return controller;
00077 }
00078
00079 void use_scripting_controller(bool use_or_release);
00080 void do_scripting_controller(std::string control, bool pressed);
00081
00082 virtual void update(float elapsed_time);
00083 virtual void draw(DrawingContext& context);
00084 virtual void collision_solid(const CollisionHit& hit);
00085 virtual HitResponse collision(GameObject& other, const CollisionHit& hit);
00086 virtual void collision_tile(uint32_t tile_attributes);
00087
00088 void make_invincible();
00089 bool is_invincible() const
00090 {
00091 return invincible_timer.started();
00092 }
00093 bool is_dying() const
00094 {
00095 return dying;
00096 }
00097 Direction peeking_direction_x() const
00098 {
00099 return peekingX;
00100 }
00101
00102 Direction peeking_direction_y() const
00103 {
00104 return peekingY;
00105 }
00106
00107 void kill(bool completely);
00108 void check_bounds();
00109 void move(const Vector& vector);
00110
00111 virtual bool add_bonus(const std::string& bonus);
00112 virtual void add_coins(int count);
00113 virtual int get_coins();
00114
00121 bool add_bonus(BonusType type, bool animate = false);
00125 bool set_bonus(BonusType type, bool animate = false);
00126
00127 PlayerStatus* get_status()
00128 {
00129 return player_status;
00130 }
00131
00132 void kick();
00133
00138 void do_cheer();
00139
00144 void do_duck();
00145
00149 void do_standup();
00150
00154 void do_backflip();
00155
00160 void do_jump(float yspeed);
00161
00165 void add_velocity(const Vector& velocity);
00166
00170 void add_velocity(const Vector& velocity, const Vector& end_speed);
00171
00175 Vector get_velocity();
00176
00177 void bounce(BadGuy& badguy);
00178
00179 bool is_dead() const
00180 { return dead; }
00181 bool is_big();
00182
00183 void set_visible(bool visible);
00184 bool get_visible();
00185
00186 bool on_ground();
00187
00188 Portable* get_grabbed_object() const
00189 {
00190 return grabbed_object;
00191 }
00192 void stop_grabbing()
00193 {
00194 grabbed_object = NULL;
00195 }
00196
00201 void set_ghost_mode(bool enable);
00202
00207 void set_edit_mode(bool enable);
00208
00212 bool get_ghost_mode() { return ghost_mode; }
00213
00218 bool adjust_height(float new_height);
00219
00223 void trigger_sequence(std::string sequence_name);
00224
00228 void start_climbing(Climbable& climbable);
00229
00233 void stop_climbing(Climbable& climbable);
00234
00235 Physic& get_physic() { return physic; }
00236
00237 private:
00238 void handle_input();
00239 void handle_input_ghost();
00240 void handle_input_climbing();
00242 void init();
00243
00244 void handle_horizontal_input();
00245 void handle_vertical_input();
00246
00247 void activate();
00248 void deactivate();
00249 void walk(float speed);
00250
00251 void do_jump_apex();
00252 void early_jump_apex();
00253
00257 void apply_friction();
00258
00259 private:
00260 bool deactivated;
00261
00262 Controller* controller;
00263 std::auto_ptr<CodeController> scripting_controller;
00264 PlayerStatus* player_status;
00265 bool duck;
00266 bool dead;
00267
00268 private:
00269 bool dying;
00270 bool winning;
00271 bool backflipping;
00272 int backflip_direction;
00273 Direction peekingX;
00274 Direction peekingY;
00275 bool swimming;
00276 float speedlimit;
00277 Controller* scripting_controller_old;
00278 bool jump_early_apex;
00279 bool on_ice;
00280 bool ice_this_frame;
00281
00282 public:
00283 Direction dir;
00284 Direction old_dir;
00285
00286 float last_ground_y;
00287 FallMode fall_mode;
00288
00289 bool on_ground_flag;
00290 bool jumping;
00291 bool can_jump;
00292 Timer jump_button_timer;
00293 bool wants_buttjump;
00294 bool does_buttjump;
00295
00296 Timer invincible_timer;
00297 Timer skidding_timer;
00298 Timer safe_timer;
00299 Timer kick_timer;
00300 Timer shooting_timer;
00301 Timer dying_timer;
00302 bool growing;
00303 Timer backflip_timer;
00304
00305 Physic physic;
00306
00307 bool visible;
00308
00309 Portable* grabbed_object;
00310
00311 SpritePtr sprite;
00313 SurfacePtr airarrow;
00315 Vector floor_normal;
00316 void position_grabbed_object();
00317 void try_grab();
00318
00319 bool ghost_mode;
00320 bool edit_mode;
00322 Timer unduck_hurt_timer;
00324 Timer idle_timer;
00325 unsigned int idle_stage;
00326
00327 Climbable* climbing;
00329 private:
00330 Player(const Player&);
00331 Player& operator=(const Player&);
00332 };
00333
00334 #endif
00335
00336