Added a new SoundManager based on OpenAL. I also simplified the API along the
[supertux.git] / src / object / player.h
index 0a179a4..985648b 100644 (file)
 #include "SDL.h"
 
 #include "timer.h"
+#include "direction.h"
 #include "video/surface.h"
-#include "special/moving_object.h"
-#include "special/sprite.h"
-#include "math/physic.h"
-#include "defines.h"
-
-using namespace SuperTux;
+#include "moving_object.h"
+#include "sprite/sprite.h"
+#include "physic.h"
+#include "control/controller.h"
+#include "player_status.h"
 
 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;
-
-struct player_input_type
-{
-  int right;
-  int left;
-  int up;
-  int old_up;
-  int down;
-  int fire;
-  int old_fire;
-  int activate;
-  int jump;
-  int old_jump;
-};
-
-void player_input_init(player_input_type* pplayer_input);
+static const float TUX_SAFE_TIME = 1.8;
+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 TUX_FLAPPING_STRENGTH = 100; /* How much Y velocity Tux gains when flapping */
+static const float TUX_FLAPPING_LEAST_X = 30; /* How much X velocity Tux gains when flapping from vertical jump */
+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];
 
@@ -103,8 +65,7 @@ public:
 
   void set_action(std::string action, int loops = -1);
   void one_time_animation();
-  void draw(DrawingContext& context, const Vector& pos, int layer,
-                Uint32 drawing_effect = NONE_EFFECT);
+  void draw(DrawingContext& context, const Vector& pos, int layer);
 
   Sprite* head;
   Sprite* body;
@@ -121,15 +82,16 @@ 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 };
 
-  player_input_type  input;
-  int got_power;
-  int size;
+  Controller* controller;
+  PlayerStatus* player_status;
   bool duck;
   bool dead;
-  DyingType dying;
+
+private:
+  bool dying;
+public:
 
   Direction dir;
   Direction old_dir;
@@ -152,59 +114,64 @@ public:
   int flaps_nb;
 
   // temporary to help player's choosing a flapping
-  enum { MAREK_FLAP, RICARDO_FLAP, RYAN_FLAP, NONE_FLAP };
+  // TODO: remove this after agreeing on flapstyle!
+  enum { MAREK_FLAP, RICARDO_FLAP, RYAN_FLAP, NO_FLAP };
   int flapping_mode;
 
-  Timer2 invincible_timer;
-  Timer2 skidding_timer;
-  Timer2 safe_timer;
-  Timer2 kick_timer;
-  Timer2 shooting_timer;   // used to show the arm when Tux is shooting
-  Timer2 dying_timer;
-  Timer2 growing_timer;
-  Timer2 idle_timer;
-  Timer2 flapping_timer;
+  Timer invincible_timer;
+  Timer skidding_timer;
+  Timer safe_timer;
+  Timer kick_timer;
+  Timer shooting_timer;   // used to show the arm when Tux is shooting
+  Timer dying_timer;
+  Timer growing_timer;
+  Timer idle_timer;
+  Timer flapping_timer;
   Physic physic;
   
 public:
-  Player();
+  Player(PlayerStatus* player_status);
   virtual ~Player();
-  
-  int  key_event(SDLKey key, int state);
-  void level_begin();
-  void handle_input();
 
-  PlayerStatus& get_status();
+  void set_controller(Controller* controller);  
 
-  virtual void action(float elapsed_time);
+  virtual void update(float elapsed_time);
   virtual void draw(DrawingContext& context);
   virtual HitResponse collision(GameObject& other, const CollisionHit& hit);
 
   void make_invincible();
   bool is_invincible() const
   {
-      return invincible_timer.started();
+    return invincible_timer.started();
+  }
+  bool is_dying() const
+  {
+    return dying;
   }
   
   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;