FogOfWarViewer.js

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/*jslint node: true, vars: true */
/*global gEngine, Scene, GameObjectset, TextureObject, Camera, vec2,
  Renderable, FontRenderable, SpriteRenderable, LightRenderable,
  GameObject, Hero, Minion, Dye, Light */
/* find out more about jslint: http://www.jslint.com/help.html */

"use strict";  // Operate in Strict mode such that variables must be declared before used!

/**
 * Subclass of FogOfWar. Object tracks the movement of target object and radius for Field of View.
 * @name FogOfWarViewer
 * @constructor
 */
function FogOfWarViewer(){
    this.mTarget = null;
    this.mXPos = null;
    this.mYPos = null;
    this.mChanged = true;
    this.mRadius = null;
}

/**
 * Sets the target and radius for an object to have a Field of View.
 * @param {object} t - Already created object for the Fog Of War to track. 
 * @param {number} r - radius in World Coordinates
 */
FogOfWarViewer.prototype.setTarget = function(t, r) {
    this.mTarget = t;
    this.mXPos = t.getXform().getXPos();
    this.mYPos = t.getXform().getYPos();
    this.mRadius = r;
};

/**
 * Removes the target object from FogOfWarViewer object. 
 */
FogOfWarViewer.prototype.removeTarget = function () {
    this.mTarget = null;
    this.mXPos = null;
    this.mYPos = null;
    this.mRadius = null;
};

/**
 * Checks to see if the target object has changed positions. 
 * @returns {Boolean} - true if target object has changed X or Y location in World Coordinates.
 */
FogOfWarViewer.prototype.checkMove = function(){
    var targetX = this.mTarget.getXform();
    if(!this.mChanged){
        if(targetX.getXPos() === this.mXPos && targetX.getYPos() === this.mYPos){
            return false;
        }else{
            return true;
        }
    }else{
        this.mChanged = false;
        return true;
    }
};

/**
 * Changes the size of radius for a Field of View.
 * @param {number} r - New radius in World Coordinates.
 */
FogOfWarViewer.prototype.setRadius = function (r){
    this.mRadius = r;
    this.mChanged = true;
};

/**
 * Returns the value of radius for Field of View for this object. 
 * @returns {Number} - Radius in World Coordinates.
 */
FogOfWarViewer.prototype.getRadius = function (){
    return this.mRadius;
};

/**
 * Returns the X location in World Coordinates. 
 * @returns {Number} - X location in World Coordinates.
 */
FogOfWarViewer.prototype.getX = function(){ return this.mXPos; };

/**
 * Returns the Y location in World Coordinates. 
 * @returns {Number} - Y location in World Coordinates.
 */
FogOfWarViewer.prototype.getY = function(){ return this.mYPos; };

/**
 * Returns the target object. 
 * @returns {Object} - Target object for this FogOfWarViewer.
 */
FogOfWarViewer.prototype.getTarget = function () { return this.mTarget; };

/**
 * Updates the previous X and Y location.
 */
FogOfWarViewer.prototype.update = function (){
    if(this.mTarget !== null){
        this.mXPos = this.mTarget.getXform().getXPos();
        this.mYPos = this.mTarget.getXform().getYPos();
    }
};