API Docs for:
Show:

File: gameplay\movement\grounded-movement\Components.js

/**
 A component class which allows an entity to move horizontally while on the ground or in the air.
 @class GroundedMovement
 @constructor
 @param groundMovementImpulseMagnitude {Number} The magnitude of an impulse that will be applied to move an entity while it's on the ground.
 @param airMovementImpulseMagnitude {Number} The magnitude of an impulse that will be applied to move an entity while it's in the air.
 @param groundSpeedLimit {Number} Maximum velocity on the x axis that the entity can achieve while on the ground.
 @param airSpeedLimit {Number} Maximum velocity on the x axis that the entity can achieve while in the air.
 @param onGroundTime {Number} This is the time, in seconds, that the entity remains on ground after it physically is no longer touching the ground. This, for example, gives a time window for an entity to jump after it left the ground by running off of a platform.
 @param idleFriction {Number} Each entity that has this component will have its friction set to 0 to ensure smooth movement. Entity's friction will be set to this value when its trying to stop while on the ground or while it's standing idly.
 */
function GroundedMovement(groundMovementImpulseMagnitude, airMovementImpulseMagnitude,  groundSpeedLimit, airSpeedLimit, onGroundTime, idleFriction){
    this._groundMovementImpulseMagnitude = groundMovementImpulseMagnitude || 0;
    this._airMovementImpulseMagnitude = airMovementImpulseMagnitude || 0;
    this._groundSpeedLimit = groundSpeedLimit || 0;
    this._airSpeedLimit = airSpeedLimit || 0;
    this._onGroundTime = onGroundTime || 0;
    this._idleFriction = idleFriction || 0;
    
    this._onGroundTimeRemaining = 0;
    this._groundRightTangent = new Vector2D();
    this._movedInDesiredDirection = false;
}

GroundedMovement.prototype = {
    constructor : GroundedMovement,
    _componentIdentifier : 0,
    
    /**
     @method getGroundMovementImpulseMagnitude
     @return {Number}
     */
    getGroundMovementImpulseMagnitude : function(){
        return this._groundMovementImpulseMagnitude;
    },
    
    /**
     @method setGroundMovementImpulseMagnitude
     @param groundMovementImpulseMagnitude {Number} The magnitude of an impulse that will be applied to move an entity while it's on the ground.
     */
    setGroundMovementImpulseMagnitude : function(groundMovementImpulseMagnitude){
        this._groundMovementImpulseMagnitude = groundMovementImpulseMagnitude;
    },
    
    /**
     @method getAirMovementImpulseMagnitude
     @return {Number}
     */
    getAirMovementImpulseMagnitude : function(){
        return this._airMovementImpulseMagnitude;
    },
    
    /**
     @method setAirMovementImpulseMagnitude
     @param airMovementImpulseMagnitude {Number} The magnitude of an impulse that will be applied to move an entity while it's in the air.
     */
    setAirMovementImpulseMagnitude : function(airMovementImpulseMagnitude){
        this._airMovementImpulseMagnitude = airMovementImpulseMagnitude;
    },
    
    /**
     @method getGroundSpeedLimit
     @return {Number}
     */
    getGroundSpeedLimit : function(){
        return this._groundSpeedLimit;
    },
    
    /**
     @method setGroundSpeedLimit
     @param groundSpeedLimit {Number} Maximum velocity on the x axis that the entity can achieve while on the ground.
     */
    setGroundSpeedLimit : function(groundSpeedLimit){
        this._groundSpeedLimit = groundSpeedLimit;
    },
    
    /**
     @method getAirSpeedLimit
     @return {Number}
     */
    getAirSpeedLimit : function(){
        return this._airSpeedLimit;
    },
    
    /**
     @method setAirSpeedLimit
     @param airSpeedLimit {Number} Maximum velocity on the x axis that the entity can achieve while in the air.
     */
    setAirSpeedLimit : function(airSpeedLimit){
        this._airSpeedLimit = airSpeedLimit;
    },
    
    /**
     @method getOnGroundTime
     @return {Number}
     */
    getOnGroundTime : function(){
        return this._onGroundTime;
    },
    
    /**
     @method setOnGroundTime
     @param onGroundTime {Number} This is the time, in seconds, that the entity remains on ground after it physically is no longer touching the ground. This, for example, gives a time window for an entity to jump after it left the ground by running off of a platform.
     */
    setOnGroundTime : function(onGroundTime){
        this._onGroundTime = onGroundTime;
    },
    
    /**
     @method isOnGround
     @return {Number}
     */
    isOnGround : function(){
        return this._onGroundTimeRemaining > 0;
    },
    
    /**
     @method getIdleFriction
     @return {Number}
     */
    getIdleFriction : function(){
        return this._idleFriction;
    },
    
    /**
     @method setIdleFriction
     @param idleFriction {Number} Each entity that has this component will have its friction set to 0 to ensure smooth movement. Entity's friction will be set to this value when its trying to stop while on the ground or while it's standing idly.
     */
    setIdleFriction : function(idleFriction){
        this._idleFriction = idleFriction;
    },
    
    /**
     Returns a normalized vector that goes along the ground surface this entity was last standing on, pointing to the right.
     @method getGroundRightTangent
     @param vector {Vector2D} Vector to which the tangent will be copied.
     */
    getGroundRightTangent : function(vector){
        vector.x = this._groundRightTangent.x;
        vector.y = this._groundRightTangent.y;
    }
};

/**
 A component class which describes which direction the entity is facing.
 @class FacingDirection
 @constructor
 @param facingDirection {String} Can be either 'left' or 'right'.
 */
function FacingDirection(facingDirection){
    this._facingDirection = facingDirection || 'right';
}

FacingDirection.prototype = {
    constructor : FacingDirection,
    _componentIdentifier : 0,
    
    /**
     @method getFacingDirection
     @return {String} Returns 'left' or 'right'
     */
    getFacingDirection : function(){
        return this._facingDirection;
    },
    
    /**
     @method setFacingDirection
     @param facingDirection {String} Can be either 'left' or 'right'.
     */
    setFacingDirection : function(facingDirection){
        this._facingDirection = facingDirection;
    }
};