API Docs for:
Show:

File: gameplay\movement\jumping\Components.js

/**
 A component class that adds the ability to jump.
 @class Jumping
 @constructor
 @param jumpImpulseMagnitude {Number}
 */
function Jumping(jumpImpulseMagnitude){
    this._jumpImpulseMagnitude = jumpImpulseMagnitude || 0;
    
    //These flags and the supporting logic make sure that the player can't
    //just hold the jump button to keep jumping continously.
    this._pressedJump = false;
    this._canJump = true;
}

Jumping.prototype = {
    constructor : Jumping,
    _componentIdentifier : 0,
    
    /**
     @method getJumpImpulseMagnitude
     @return {Number}
     */
    getJumpImpulseMagnitude : function(){
        return this._jumpImpulseMagnitude;
    },
    
    /**
     @method setJumpImpulseMagnitude
     @param magnitude {Number}
     */
    setJumpImpulseMagnitude : function(magnitude){
        this._jumpImpulseMagnitude = magnitude;
    }
};

/**
 A component class that adds the ability to jump multiple times while in the air.
 @class DoubleJumping
 @constructor
 @param doubleJumpImpulseMagnitude {Number}
 @param numberOfCharges {Number} The number of times that the entity can jump while in the air.
 */
function DoubleJumping(doubleJumpImpulseMagnitude, numberOfCharges){
    this._doubleJumpImpulseMagnitude = doubleJumpImpulseMagnitude || 0;
    this._numberOfCharges = numberOfCharges || 0;
    this._numberOfChargesRemaining = 0;
}

DoubleJumping.prototype = {
    constructor : DoubleJumping,
    _componentIdentifier : 0,
    
    /**
     @method getDoubleJumpImpulseMagnitude
     @return {Number}
     */
    getDoubleJumpImpulseMagnitude : function(){
        return this._doubleJumpImpulseMagnitude;
    },
    
    /**
     @method setDoubleJumpImpulseMagnitude
     @param magnitude {Number}
     */
    setDoubleJumpImpulseMagnitude : function(magnitude){
        this._doubleJumpImpulseMagnitude = magnitude;
    },
    
    /**
     @method getNumberOfCharges
     @return {Number}
     */
    getNumberOfCharges : function(){
        return this._numberOfCharges;
    },
    
    /**
     @method setNumberOfCharges
     @param numberOfCharges {Number} The number of times that the entity can jump while in the air.
     */
    setNumberOfCharges : function(numberOfCharges){
        this._numberOfCharges = numberOfCharges;
    },
    
    /**
     @method canDoubleJump
     @return {Boolean}
     */
    canDoubleJump : function(){
        return this._numberOfChargesRemaining > 0;
    }
};

/**
 A component class that adds the ability to jump off of walls while in the air.
 @class WallJumping
 @constructor
 @param wallJumpRightImpulseX {Number} The x component of the wall jump impulse. This impulse is for jumping off of walls detected on the left side, the opposite variant is calculated automatically.
 @param wallJumpRightImpulseY {Number} The y component of the wall jump impulse. This impulse is for jumping off of walls detected on the left side, the opposite variant is calculated automatically.
 @param wallDetectorRightRay {Ray} A ray that will be used to detect walls. The beginning position of the ray should be defined relatively to the position of the entity. The ray is for detecting walls on the right side, the left variant is calculated automatically.
 */
function WallJumping(wallJumpRightImpulseX, wallJumpRightImpulseY, wallDetectorRightRay){
    this._wallJumpRightImpulse = new Vector2D(wallJumpRightImpulseX, wallJumpRightImpulseY);
    this._wallDetectorRightRay = wallDetectorRightRay || null;
}

WallJumping.prototype = {
    constructor : WallJumping,
    _componentIdentifier : 0,
    
    /**
     @method getWallJumpRightImpulse
     @param vector {Vector2D} Vector to which the impulse will be copied.
     */
    getWallJumpRightImpulse : function(vector){
        vector.x = this._wallJumpRightImpulse.x;
        vector.y = this._wallJumpRightImpulse.y;
    },
    
    /**
     @method setWallJumpRightImpulse
     @param x {Number} The x component of the wall jump impulse. This impulse is for jumping off of walls detected on the left side, the opposite variant is calculated automatically.
     @param y {Number} The y component of the wall jump impulse. This impulse is for jumping off of walls detected on the left side, the opposite variant is calculated automatically.
     */
    setWallJumpRightImpulse : function(x, y){
        this._wallJumpRightImpulse.x = x;
        this._wallJumpRightImpulse.y = y;
    },
    
    /**
     @method getWallDetectorRightRay
     @return {Ray|Null} A direct reference to the ray object. If a ray was not set, returns null.
     */
    getWallDetectorRightRay : function(){
        return this._wallDetectorRightRay;
    },
    
    /**
     @method setWallDetectorRightRay
     @param wallDetectorRightRay {Ray} A ray that will be used to detect walls. The beginning position of the ray should be defined relatively to the position of the entity. The ray is for detecting walls on the right side, the left variant is calculated automatically.
     */
    setWallDetectorRightRay : function(wallDetectorRightRay){
        this._wallDetectorRightRay = wallDetectorRightRay;
    }
};