X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fobject%2Fplayer.h;h=4d7ce216e8de5e7d2f2ca4baa7f621f36c8e0953;hb=c0093d25093395cb62fc2526ab42be65a9f015b8;hp=91e14b5117f273ea58f0f5eaa9d33dc47addb67d;hpb=9599042661b468aae7bd34dca05441c0ebc93ad7;p=supertux.git diff --git a/src/object/player.h b/src/object/player.h index 91e14b511..4d7ce216e 100644 --- a/src/object/player.h +++ b/src/object/player.h @@ -20,14 +20,16 @@ #define SUPERTUX_PLAYER_H #include -#include +#include "SDL.h" #include "timer.h" #include "direction.h" #include "video/surface.h" -#include "special/moving_object.h" -#include "special/sprite.h" +#include "moving_object.h" +#include "sprite/sprite.h" #include "math/physic.h" +#include "control/controller.h" +#include "player_status.h" using namespace SuperTux; @@ -35,61 +37,17 @@ class BadGuy; class Portable; /* Times: */ - -#define TUX_SAFE_TIME 1.250 -#define TUX_INVINCIBLE_TIME 10.0 -#define TUX_INVINCIBLE_TIME_WARNING 2.0 -#define TUX_FLAPPING_TIME 1 /* How long Tux can flap his wings to gain additional jump height */ -#define TIME_WARNING 20 /* When to alert player they're low on time! */ - -/* Sizes: */ -#define SMALL 0 -#define BIG 1 - -struct PlayerKeymap -{ -public: - int jump; - int up; - int down; - int left; - int right; - int power; - - PlayerKeymap(); -}; - -extern PlayerKeymap keymap; - -/** Contains a field of booleans that indicate wheter a button is pressed or - * released. The old_ fields contain the state of the button at the previous - * frame. - */ -struct PlayerInputType -{ -public: - PlayerInputType(); - void reset(); - - bool left; - bool right; - bool up; - bool old_up; - bool down; - bool fire; - bool old_fire; - bool activate; - bool jump; - bool old_jump; -}; +static const float TUX_SAFE_TIME = 1.250; +static const float TUX_INVINCIBLE_TIME = 10.0; +static const float TUX_INVINCIBLE_TIME_WARNING = 2.0; +static const float TUX_FLAPPING_TIME = 1; /* How long Tux can flap his wings to gain additional jump height */ +static const float TIME_WARNING = 20; /* When to alert player they're low on time! */ +static const float GROWING_TIME = 1.0; +static const int GROWING_FRAMES = 7; class Camera; class PlayerStatus; -extern Surface* tux_life; - -#define GROWING_TIME 1.0 -#define GROWING_FRAMES 7 extern Surface* growingtux_left[GROWING_FRAMES]; extern Surface* growingtux_right[GROWING_FRAMES]; @@ -126,12 +84,10 @@ class Player : public MovingObject { public: enum HurtMode { KILL, SHRINK }; - enum Power { NONE_POWER, FIRE_POWER, ICE_POWER }; enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING }; - PlayerInputType input; - int got_power; - int size; + Controller* controller; + PlayerStatus* player_status; bool duck; bool dead; @@ -160,7 +116,7 @@ public: int flaps_nb; // temporary to help player's choosing a flapping - enum { MAREK_FLAP, RICARDO_FLAP, RYAN_FLAP, NONE_FLAP }; + enum { MAREK_FLAP, RICARDO_FLAP, RYAN_FLAP, NO_FLAP }; int flapping_mode; Timer2 invincible_timer; @@ -175,14 +131,10 @@ public: Physic physic; public: - Player(); + Player(PlayerStatus* player_status); virtual ~Player(); - - bool key_event(SDLKey key, bool state); - void level_begin(); - void handle_input(); - PlayerStatus& get_status(); + void set_controller(Controller* controller); virtual void action(float elapsed_time); virtual void draw(DrawingContext& context); @@ -199,24 +151,28 @@ public: } void kill(HurtMode mode); - void player_remove_powerups(); void check_bounds(Camera* camera); - void grow(bool animate = false); void move(const Vector& vector); + void set_bonus(BonusType type, bool animate = false); + PlayerStatus* get_status() + { + return player_status; + } void bounce(BadGuy& badguy); bool is_dead() const { return dead; } + bool is_big(); private: + void handle_input(); bool on_ground(); void init(); void handle_horizontal_input(); void handle_vertical_input(); - void remove_powerups(); Portable* grabbed_object;