src/Game.js
/**
 * The Game class manages the ingame state.
 *
 * @param {ResourceDepot} resources the resource depot instance.
 * @returns {Game}
 */
The Game class manages the ingame state.
@param {ResourceDepot} resources the resource depot instance.
@returns {Game}
The Game class manages the ingame state . @param { ResourceDepot } resources the resource depot instance . @returns { Game }
function Game(resources) {
	this.resources = resources;
	this.currentStage = null;
	this.mainStage = null;
	this.stages = {};
	this.camera = new Vec2(0, 0);
	this.cameraConstraint = new Rectf(0, 0, 0, 0);
	this.shaders = null;
	this.loadingStageProgress = 0;
	this.initialized = false;
	this.loadingStage = false;
	this.runningStage = false;
	this.externalPreloadCallback = null;
	this.focus = null;
	this.hud = new GUIHeadsUp();
	this.iteratingObjects = 0;
	this.currentFoe = null;
	this.currentFoeTimeout = 0;
	this.scoreObservers = [];
	this.deathRow = [];
	this.score = 0;
	this.tallyInfo = null;
	this.fadeParam = 0;
	this.fadeOut = false;
	this.respawn = false;
	this.isInCave = false;
	this.pendingMessages = [];
	this.dialogueSystem = new DialogueSystem();
	this.dialogueTriggerTimer = 0;
	this.stagesFinished = -1;
	var _this = this;
	this.provider = function (x1, x2, y1, y2) {
		var tileW = _this.currentStage.tileW;
		var tileH = _this.currentStage.tileH;
		var tileX1 = Math.floor(x1 / tileW);
		var tileX2 = Math.floor(x2 / tileW);
		var tileY1 = Math.floor(y1 / tileW);
		var tileY2 = Math.floor(y2 / tileW);
		var shapes = [];
		for (var x = tileX1; x <= tileX2; x++) {
			if (_this.currentStage.shapes[x]) {
				for (var y = tileY1; y <= tileY2; y++) {
					if (_this.currentStage.shapes[x][y]) {
						for (var s = 0; s < _this.currentStage.shapes[x][y].length; s++) {
							shapes.push(_this.currentStage.shapes[x][y][s]);
						}
					}
				}
			}
		}
		var c;
		if (x1 <= 0) {
			c = new ConvexShape();
			c.PushPoint(new Vec2(0, -100));
			c.PushPoint(new Vec2(-100, -100));
			c.PushPoint(new Vec2(-100, _this.currentStage.gamePlayLayerExtent.height + 100));
			c.PushPoint(new Vec2(0, _this.currentStage.gamePlayLayerExtent.height + 100));
			shapes.push(c);
		}
		if (x2 >= _this.currentStage.gamePlayLayerExtent.width) {
			c = new ConvexShape();
			c.PushPoint(new Vec2(_this.currentStage.gamePlayLayerExtent.width + 0, -100));
			c.PushPoint(new Vec2(_this.currentStage.gamePlayLayerExtent.width + 100, -100));
			c.PushPoint(new Vec2(_this.currentStage.gamePlayLayerExtent.width + 100, _this.currentStage.gamePlayLayerExtent.height + 100));
			c.PushPoint(new Vec2(_this.currentStage.gamePlayLayerExtent.width + 0, _this.currentStage.gamePlayLayerExtent.height + 100));
			shapes.push(c);
		}
		return shapes;
	};
}
function Game ( resources ) { this . resources = resources ; this . currentStage = null ; this . mainStage = null ; this . stages = { } ; this . camera = new Vec2 ( 0 , 0 ) ; this . cameraConstraint = new Rectf ( 0 , 0 , 0 , 0 ) ; this . shaders = null ; this . loadingStageProgress = 0 ; this . initialized = false ; this . loadingStage = false ; this . runningStage = false ; this . externalPreloadCallback = null ; this . focus = null ; this . hud = new GUIHeadsUp ( ) ; this . iteratingObjects = 0 ; this . currentFoe = null ; this . currentFoeTimeout = 0 ; this . scoreObservers = [ ] ; this . deathRow = [ ] ; this . score = 0 ; this . tallyInfo = null ; this . fadeParam = 0 ; this . fadeOut = false ; this . respawn = false ; this . isInCave = false ; this . pendingMessages = [ ] ; this . dialogueSystem = new DialogueSystem ( ) ; this . dialogueTriggerTimer = 0 ; this . stagesFinished = - 1 ; var _this = this ; this . provider = function ( x1 , x2 , y1 , y2 ) { var tileW = _this . currentStage . tileW ; var tileH = _this . currentStage . tileH ; var tileX1 = Math . floor ( x1 / tileW ) ; var tileX2 = Math . floor ( x2 / tileW ) ; var tileY1 = Math . floor ( y1 / tileW ) ; var tileY2 = Math . floor ( y2 / tileW ) ; var shapes = [ ] ; for ( var x = tileX1 ; x <= tileX2 ; x ++ ) { if ( _this . currentStage . shapes [ x ] ) { for ( var y = tileY1 ; y <= tileY2 ; y ++ ) { if ( _this . currentStage . shapes [ x ] [ y ] ) { for ( var s = 0 ; s < _this . currentStage . shapes [ x ] [ y ] . length ; s ++ ) { shapes . push ( _this . currentStage . shapes [ x ] [ y ] [ s ] ) ; } } } } } var c ; if ( x1 <= 0 ) { c = new ConvexShape ( ) ; c . PushPoint ( new Vec2 ( 0 , - 100 ) ) ; c . PushPoint ( new Vec2 ( - 100 , - 100 ) ) ; c . PushPoint ( new Vec2 ( - 100 , _this . currentStage . gamePlayLayerExtent . height + 100 ) ) ; c . PushPoint ( new Vec2 ( 0 , _this . currentStage . gamePlayLayerExtent . height + 100 ) ) ; shapes . push ( c ) ; } if ( x2 >= _this . currentStage . gamePlayLayerExtent . width ) { c = new ConvexShape ( ) ; c . PushPoint ( new Vec2 ( _this . currentStage . gamePlayLayerExtent . width + 0 , - 100 ) ) ; c . PushPoint ( new Vec2 ( _this . currentStage . gamePlayLayerExtent . width + 100 , - 100 ) ) ; c . PushPoint ( new Vec2 ( _this . currentStage . gamePlayLayerExtent . width + 100 , _this . currentStage . gamePlayLayerExtent . height + 100 ) ) ; c . PushPoint ( new Vec2 ( _this . currentStage . gamePlayLayerExtent . width + 0 , _this . currentStage . gamePlayLayerExtent . height + 100 ) ) ; shapes . push ( c ) ; } return shapes ; } ; }
The Game class manages the ingame state.
The Game class manages the ingame state .
/**
	 * Provides a set of shapes based on the given coordinates
	 *
	 * @param {number} x1
	 * @param {number} y1
	 * @param {number} x2
	 * @param {number} y2
	 */ // todo: temporary solution for keeping Kindle inside the stage to the left and right.