src/PhysicsObject.hh
changeset 264 215de3d4de60
parent 257 549783d71e51
child 265 d97bf6790c22
equal deleted inserted replaced
263:8c999cf4c182 264:215de3d4de60
    13 #include "Config.hh"
    13 #include "Config.hh"
    14 
    14 
    15 // Type definitions
    15 // Type definitions
    16 typedef Vector Force;
    16 typedef Vector Force;
    17 
    17 
       
    18 enum FacingDirection {
       
    19     FACING_LEFT,
       
    20     FACING_RIGHT
       
    21 };
    18 
    22 
    19 /**
    23 /**
    20  * PhysicObject class. A basic PhysicsObject class.
    24  * PhysicObject class. A basic PhysicsObject class.
    21  */
    25  */
    22 class PhysicsObject {
    26 class PhysicsObject {
    27     bool inAir; // Is the object "on the ground"
    31     bool inAir; // Is the object "on the ground"
    28     float collision_elasticity;
    32     float collision_elasticity;
    29 
    33 
    30     // Attributes for players
    34     // Attributes for players
    31     float aim; // Aim direction (half circle)
    35     float aim; // Aim direction (half circle)
    32     bool facingRight; // Player facing
    36     FacingDirection facing; // Player facing
    33 
    37 
    34     bool alive;
    38     bool alive;
    35     bool shouldDelete;
    39     bool shouldDelete;
    36 
    40 
    37     PhysicsObject *pivot;
    41     PhysicsObject *pivot;
    58     /**
    62     /**
    59      * Set player facing.
    63      * Set player facing.
    60      *
    64      *
    61      * @param facingRight True if player is facing right.
    65      * @param facingRight True if player is facing right.
    62      */
    66      */
    63     void setFacing(bool facingRight);
    67     void setFacing (FacingDirection facing);
    64 
    68 
    65     /**
    69     /**
    66      * Makes the player jump in the air.
    70      * Makes the player jump in the air.
    67      * @param direction -1: jump left, 0: jump up, 1: jump right
    71      * @param direction -1: jump left, 0: jump up, 1: jump right
    68      */
    72      */
    82      * @param velocity New velocity
    86      * @param velocity New velocity
    83      * @param inAir New inAir value
    87      * @param inAir New inAir value
    84      * @param facingRight New facingRight value
    88      * @param facingRight New facingRight value
    85      * @param aim New aim
    89      * @param aim New aim
    86      */
    90      */
    87     virtual void updatePhysics(Vector position, Vector velocity, bool inAir, bool facingRight, float aim);
    91     virtual void updatePhysics(Vector position, Vector velocity, bool inAir, FacingDirection facing, float aim);
    88 
    92 
    89     /**
    93     /**
    90      * Put object to the objects list so that its movement will be calculated.
    94      * Put object to the objects list so that its movement will be calculated.
    91      */
    95      */
    92     void enable (void);
    96     void enable (void);
   195     /**
   199     /**
   196      * Return object facing.
   200      * Return object facing.
   197      *
   201      *
   198      * @return Object facing (true if facing right)
   202      * @return Object facing (true if facing right)
   199      */
   203      */
   200     bool getFacing() const;
   204     FacingDirection getFacing() const;
   201 
   205 
   202     /**
   206     /**
   203      * Return object aim angle.
   207      * Return object aim angle.
   204      *
   208      *
   205      * @return Object aim angle
   209      * @return Object aim angle
   238 
   242 
   239     /**
   243     /**
   240      * Update object in physics simulation.
   244      * Update object in physics simulation.
   241      */
   245      */
   242     virtual void tick (TimeMS tick_length);
   246     virtual void tick (TimeMS tick_length);
   243 
       
   244     /**
       
   245      * Draw object
       
   246      *
       
   247      * @param gc CL_GraphicContext
       
   248      */
       
   249     virtual void draw(CL_GraphicContext *gc);
       
   250 };
   247 };
   251 
   248 
   252 struct Derivative {
   249 struct Derivative {
   253     Vector dx; // Velocity
   250     Vector dx; // Velocity
   254     Vector dv; // Acceleration
   251     Vector dv; // Acceleration