Finished up code for basic functionality of earthflower powerup.
[supertux.git] / src / object / player.hpp
index 0db526c..4d178aa 100644 (file)
@@ -18,6 +18,7 @@
 #define HEADER_SUPERTUX_OBJECT_PLAYER_HPP
 
 #include "scripting/player.hpp"
+#include "sprite/sprite_ptr.hpp"
 #include "supertux/direction.hpp"
 #include "supertux/moving_object.hpp"
 #include "supertux/physic.hpp"
@@ -30,7 +31,6 @@ class Portable;
 class Climbable;
 class Controller;
 class CodeController;
-class Sprite;
 class Surface;
 class Timer;
 
@@ -40,12 +40,13 @@ static const float TUX_INVINCIBLE_TIME = 14.0f;
 static const float TUX_INVINCIBLE_TIME_WARNING = 2.0f;
 static const float GROWING_TIME = 0.35f;
 static const int GROWING_FRAMES = 7;
+static const float TUX_BACKFLIP_TIME = 2.1f; // minimum air time that backflip results in a loss of control
 
 class Camera;
 class PlayerStatus;
 
-class Player : public MovingObject, 
-               public scripting::Player, 
+class Player : public MovingObject,
+               public scripting::Player,
                public ScriptInterface
 {
 public:
@@ -62,6 +63,15 @@ public:
   virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
 
   void set_controller(Controller* controller);
+  /*
+   * Level solved. Don't kill Tux any more.
+   */
+  void set_winning();
+  bool is_winning()
+  {
+    return winning;
+  }
+
   Controller* get_controller()
   {
     return controller;
@@ -96,7 +106,7 @@ public:
   }
 
   void kill(bool completely);
-  void check_bounds(Camera* camera);
+  void check_bounds();
   void move(const Vector& vector);
 
   virtual bool add_bonus(const std::string& bonus);
@@ -159,7 +169,7 @@ public:
    * Adds velocity to the player until given end speed is reached
    */
   void add_velocity(const Vector& velocity, const Vector& end_speed);
-  
+
   /**
    * Returns the current velocity of the player
    */
@@ -170,6 +180,8 @@ public:
   bool is_dead() const
   { return dead; }
   bool is_big();
+  bool is_stone()
+  { return stone; }
 
   void set_visible(bool visible);
   bool get_visible();
@@ -212,7 +224,7 @@ public:
    * Orders the current GameSession to start a sequence
    */
   void trigger_sequence(std::string sequence_name);
-  
+
   /**
    * Requests that the player start climbing the given Climbable
    */
@@ -238,6 +250,7 @@ private:
   void activate();
   void deactivate();
   void walk(float speed);
+  void set_dir(bool right);
 
   void do_jump_apex();
   void early_jump_apex();
@@ -251,23 +264,28 @@ private:
   bool deactivated;
 
   Controller* controller;
-  std::auto_ptr<CodeController> scripting_controller; /**< This controller is used when the Player is controlled via scripting */
+  std::unique_ptr<CodeController> scripting_controller; /**< This controller is used when the Player is controlled via scripting */
   PlayerStatus* player_status;
   bool duck;
   bool dead;
 
 private:
   bool dying;
+  bool winning;
   bool backflipping;
   int  backflip_direction;
   Direction peekingX;
   Direction peekingY;
+  float ability_time;
+  bool stone;
   bool swimming;
   float speedlimit;
   Controller* scripting_controller_old; /**< Saves the old controller while the scripting_controller is used */
   bool jump_early_apex;
   bool on_ice;
   bool ice_this_frame;
+  SpritePtr lightsprite;
+  SpritePtr powersprite;
 
 public:
   Direction dir;
@@ -288,6 +306,8 @@ public:
   Timer safe_timer;
   Timer kick_timer;
   Timer shooting_timer;   // used to show the arm when Tux is shooting
+  Timer ability_timer;  // maximum lengh of time that special abilities can last
+  Timer cooldown_timer; // minimum time period between successive uses of a special ability
   Timer dying_timer;
   bool growing;
   Timer backflip_timer;
@@ -298,11 +318,12 @@ public:
 
   Portable* grabbed_object;
 
-  std::auto_ptr<Sprite> sprite; /**< The main sprite representing Tux */
+  SpritePtr sprite; /**< The main sprite representing Tux */
 
-  std::auto_ptr<Surface> airarrow; /**< arrow indicating Tux' position when he's above the camera */
+  SurfacePtr airarrow; /**< arrow indicating Tux' position when he's above the camera */
 
   Vector floor_normal;
+  void position_grabbed_object();
   void try_grab();
 
   bool ghost_mode; /**< indicates if Tux should float around and through solid objects */