mirror of
https://github.com/wassname/phaser.git
synced 2026-09-11 12:31:29 +08:00
Tidying up and trying to fix more stupid TypeScript errors.
This commit is contained in:
@@ -1,353 +0,0 @@
|
||||
/// <reference path="../gameobjects/Sprite.ts" />
|
||||
/// <reference path="../Game.ts" />
|
||||
/**
|
||||
* Phaser - Camera
|
||||
*
|
||||
* A Camera is your view into the game world. It has a position, size, scale and rotation and renders only those objects
|
||||
* within its field of view. The game automatically creates a single Stage sized camera on boot, but it can be changed and
|
||||
* additional cameras created via the CameraManager.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Camera = (function () {
|
||||
/**
|
||||
* Instantiates a new camera at the specified location, with the specified size and zoom level.
|
||||
*
|
||||
* @param X X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
|
||||
* @param Y Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
|
||||
* @param Width The width of the camera display in pixels.
|
||||
* @param Height The height of the camera display in pixels.
|
||||
* @param Zoom The initial zoom level of the camera. A zoom level of 2 will make all pixels display at 2x resolution.
|
||||
*/
|
||||
function Camera(game, id, x, y, width, height) {
|
||||
this._clip = false;
|
||||
this._rotation = 0;
|
||||
this._target = null;
|
||||
this._sx = 0;
|
||||
this._sy = 0;
|
||||
this.scale = new Phaser.MicroPoint(1, 1);
|
||||
this.scroll = new Phaser.MicroPoint(0, 0);
|
||||
this.bounds = null;
|
||||
this.deadzone = null;
|
||||
// Camera Border
|
||||
this.disableClipping = false;
|
||||
this.showBorder = false;
|
||||
this.borderColor = 'rgb(255,255,255)';
|
||||
// Camera Background Color
|
||||
this.opaque = true;
|
||||
this._bgColor = 'rgb(0,0,0)';
|
||||
this._bgTextureRepeat = 'repeat';
|
||||
// Camera Shadow
|
||||
this.showShadow = false;
|
||||
this.shadowColor = 'rgb(0,0,0)';
|
||||
this.shadowBlur = 10;
|
||||
this.shadowOffset = new Phaser.MicroPoint(4, 4);
|
||||
this.visible = true;
|
||||
this.alpha = 1;
|
||||
// The x/y position of the current input event in world coordinates
|
||||
this.inputX = 0;
|
||||
this.inputY = 0;
|
||||
this._game = game;
|
||||
this.ID = id;
|
||||
this._stageX = x;
|
||||
this._stageY = y;
|
||||
this.fx = new Phaser.FXManager(this._game, this);
|
||||
// The view into the world canvas we wish to render
|
||||
this.worldView = new Phaser.Rectangle(0, 0, width, height);
|
||||
this.checkClip();
|
||||
}
|
||||
Camera.STYLE_LOCKON = 0;
|
||||
Camera.STYLE_PLATFORMER = 1;
|
||||
Camera.STYLE_TOPDOWN = 2;
|
||||
Camera.STYLE_TOPDOWN_TIGHT = 3;
|
||||
Camera.prototype.follow = function (target, style) {
|
||||
if (typeof style === "undefined") { style = Camera.STYLE_LOCKON; }
|
||||
this._target = target;
|
||||
var helper;
|
||||
switch(style) {
|
||||
case Camera.STYLE_PLATFORMER:
|
||||
var w = this.width / 8;
|
||||
var h = this.height / 3;
|
||||
this.deadzone = new Phaser.Rectangle((this.width - w) / 2, (this.height - h) / 2 - h * 0.25, w, h);
|
||||
break;
|
||||
case Camera.STYLE_TOPDOWN:
|
||||
helper = Math.max(this.width, this.height) / 4;
|
||||
this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
|
||||
break;
|
||||
case Camera.STYLE_TOPDOWN_TIGHT:
|
||||
helper = Math.max(this.width, this.height) / 8;
|
||||
this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
|
||||
break;
|
||||
case Camera.STYLE_LOCKON:
|
||||
default:
|
||||
this.deadzone = null;
|
||||
break;
|
||||
}
|
||||
};
|
||||
Camera.prototype.focusOnXY = function (x, y) {
|
||||
x += (x > 0) ? 0.0000001 : -0.0000001;
|
||||
y += (y > 0) ? 0.0000001 : -0.0000001;
|
||||
this.scroll.x = Math.round(x - this.worldView.halfWidth);
|
||||
this.scroll.y = Math.round(y - this.worldView.halfHeight);
|
||||
};
|
||||
Camera.prototype.focusOn = function (point) {
|
||||
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
|
||||
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
|
||||
this.scroll.x = Math.round(point.x - this.worldView.halfWidth);
|
||||
this.scroll.y = Math.round(point.y - this.worldView.halfHeight);
|
||||
};
|
||||
Camera.prototype.setBounds = /**
|
||||
* Specify the boundaries of the world or where the camera is allowed to move.
|
||||
*
|
||||
* @param x The smallest X value of your world (usually 0).
|
||||
* @param y The smallest Y value of your world (usually 0).
|
||||
* @param width The largest X value of your world (usually the world width).
|
||||
* @param height The largest Y value of your world (usually the world height).
|
||||
*/
|
||||
function (x, y, width, height) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof width === "undefined") { width = 0; }
|
||||
if (typeof height === "undefined") { height = 0; }
|
||||
if(this.bounds == null) {
|
||||
this.bounds = new Phaser.Rectangle();
|
||||
}
|
||||
this.bounds.setTo(x, y, width, height);
|
||||
this.scroll.setTo(0, 0);
|
||||
this.update();
|
||||
};
|
||||
Camera.prototype.update = function () {
|
||||
this.fx.preUpdate();
|
||||
if(this._target !== null) {
|
||||
if(this.deadzone == null) {
|
||||
this.focusOnXY(this._target.x + this._target.origin.x, this._target.y + this._target.origin.y);
|
||||
} else {
|
||||
var edge;
|
||||
var targetX = this._target.x + ((this._target.x > 0) ? 0.0000001 : -0.0000001);
|
||||
var targetY = this._target.y + ((this._target.y > 0) ? 0.0000001 : -0.0000001);
|
||||
edge = targetX - this.deadzone.x;
|
||||
if(this.scroll.x > edge) {
|
||||
this.scroll.x = edge;
|
||||
}
|
||||
edge = targetX + this._target.width - this.deadzone.x - this.deadzone.width;
|
||||
if(this.scroll.x < edge) {
|
||||
this.scroll.x = edge;
|
||||
}
|
||||
edge = targetY - this.deadzone.y;
|
||||
if(this.scroll.y > edge) {
|
||||
this.scroll.y = edge;
|
||||
}
|
||||
edge = targetY + this._target.height - this.deadzone.y - this.deadzone.height;
|
||||
if(this.scroll.y < edge) {
|
||||
this.scroll.y = edge;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Make sure we didn't go outside the cameras bounds
|
||||
if(this.bounds !== null) {
|
||||
if(this.scroll.x < this.bounds.left) {
|
||||
this.scroll.x = this.bounds.left;
|
||||
}
|
||||
if(this.scroll.x > this.bounds.right - this.width) {
|
||||
this.scroll.x = (this.bounds.right - this.width) + 1;
|
||||
}
|
||||
if(this.scroll.y < this.bounds.top) {
|
||||
this.scroll.y = this.bounds.top;
|
||||
}
|
||||
if(this.scroll.y > this.bounds.bottom - this.height) {
|
||||
this.scroll.y = (this.bounds.bottom - this.height) + 1;
|
||||
}
|
||||
}
|
||||
this.worldView.x = this.scroll.x;
|
||||
this.worldView.y = this.scroll.y;
|
||||
// Input values
|
||||
this.inputX = this.worldView.x + this._game.input.x;
|
||||
this.inputY = this.worldView.y + this._game.input.y;
|
||||
this.fx.postUpdate();
|
||||
};
|
||||
Camera.prototype.render = function () {
|
||||
if(this.visible === false || this.alpha < 0.1) {
|
||||
return;
|
||||
}
|
||||
//if (this._rotation !== 0 || this._clip || this.scale.x !== 1 || this.scale.y !== 1)
|
||||
//{
|
||||
//this._game.stage.context.save();
|
||||
//}
|
||||
// It may be safer/quicker to just save the context every frame regardless (needs testing on mobile)
|
||||
this._game.stage.context.save();
|
||||
this.fx.preRender(this, this._stageX, this._stageY, this.worldView.width, this.worldView.height);
|
||||
if(this.alpha !== 1) {
|
||||
this._game.stage.context.globalAlpha = this.alpha;
|
||||
}
|
||||
this._sx = this._stageX;
|
||||
this._sy = this._stageY;
|
||||
// Shadow
|
||||
if(this.showShadow) {
|
||||
this._game.stage.context.shadowColor = this.shadowColor;
|
||||
this._game.stage.context.shadowBlur = this.shadowBlur;
|
||||
this._game.stage.context.shadowOffsetX = this.shadowOffset.x;
|
||||
this._game.stage.context.shadowOffsetY = this.shadowOffset.y;
|
||||
}
|
||||
// Scale on
|
||||
if(this.scale.x !== 1 || this.scale.y !== 1) {
|
||||
this._game.stage.context.scale(this.scale.x, this.scale.y);
|
||||
this._sx = this._sx / this.scale.x;
|
||||
this._sy = this._sy / this.scale.y;
|
||||
}
|
||||
// Rotation - translate to the mid-point of the camera
|
||||
if(this._rotation !== 0) {
|
||||
this._game.stage.context.translate(this._sx + this.worldView.halfWidth, this._sy + this.worldView.halfHeight);
|
||||
this._game.stage.context.rotate(this._rotation * (Math.PI / 180));
|
||||
// now shift back to where that should actually render
|
||||
this._game.stage.context.translate(-(this._sx + this.worldView.halfWidth), -(this._sy + this.worldView.halfHeight));
|
||||
}
|
||||
// Background
|
||||
if(this.opaque == true) {
|
||||
if(this._bgTexture) {
|
||||
this._game.stage.context.fillStyle = this._bgTexture;
|
||||
this._game.stage.context.fillRect(this._sx, this._sy, this.worldView.width, this.worldView.height);
|
||||
} else {
|
||||
this._game.stage.context.fillStyle = this._bgColor;
|
||||
this._game.stage.context.fillRect(this._sx, this._sy, this.worldView.width, this.worldView.height);
|
||||
}
|
||||
}
|
||||
// Shadow off
|
||||
if(this.showShadow) {
|
||||
this._game.stage.context.shadowBlur = 0;
|
||||
this._game.stage.context.shadowOffsetX = 0;
|
||||
this._game.stage.context.shadowOffsetY = 0;
|
||||
}
|
||||
this.fx.render(this, this._stageX, this._stageY, this.worldView.width, this.worldView.height);
|
||||
// Clip the camera so we don't get sprites appearing outside the edges
|
||||
if(this._clip && this.disableClipping == false) {
|
||||
this._game.stage.context.beginPath();
|
||||
this._game.stage.context.rect(this._sx, this._sy, this.worldView.width, this.worldView.height);
|
||||
this._game.stage.context.closePath();
|
||||
this._game.stage.context.clip();
|
||||
}
|
||||
this._game.world.group.render(this, this._sx, this._sy);
|
||||
if(this.showBorder) {
|
||||
this._game.stage.context.strokeStyle = this.borderColor;
|
||||
this._game.stage.context.lineWidth = 1;
|
||||
this._game.stage.context.rect(this._sx, this._sy, this.worldView.width, this.worldView.height);
|
||||
this._game.stage.context.stroke();
|
||||
}
|
||||
// Scale off
|
||||
if(this.scale.x !== 1 || this.scale.y !== 1) {
|
||||
this._game.stage.context.scale(1, 1);
|
||||
}
|
||||
this.fx.postRender(this, this._sx, this._sy, this.worldView.width, this.worldView.height);
|
||||
if(this._rotation !== 0 || (this._clip && this.disableClipping == false)) {
|
||||
this._game.stage.context.translate(0, 0);
|
||||
}
|
||||
this._game.stage.context.restore();
|
||||
if(this.alpha !== 1) {
|
||||
this._game.stage.context.globalAlpha = 1;
|
||||
}
|
||||
};
|
||||
Object.defineProperty(Camera.prototype, "backgroundColor", {
|
||||
get: function () {
|
||||
return this._bgColor;
|
||||
},
|
||||
set: function (color) {
|
||||
this._bgColor = color;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Camera.prototype.setTexture = function (key, repeat) {
|
||||
if (typeof repeat === "undefined") { repeat = 'repeat'; }
|
||||
this._bgTexture = this._game.stage.context.createPattern(this._game.cache.getImage(key), repeat);
|
||||
this._bgTextureRepeat = repeat;
|
||||
};
|
||||
Camera.prototype.setPosition = function (x, y) {
|
||||
this._stageX = x;
|
||||
this._stageY = y;
|
||||
this.checkClip();
|
||||
};
|
||||
Camera.prototype.setSize = function (width, height) {
|
||||
this.worldView.width = width;
|
||||
this.worldView.height = height;
|
||||
this.checkClip();
|
||||
};
|
||||
Camera.prototype.renderDebugInfo = function (x, y, color) {
|
||||
if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
|
||||
this._game.stage.context.fillStyle = color;
|
||||
this._game.stage.context.fillText('Camera ID: ' + this.ID + ' (' + this.worldView.width + ' x ' + this.worldView.height + ')', x, y);
|
||||
this._game.stage.context.fillText('X: ' + this._stageX + ' Y: ' + this._stageY + ' Rotation: ' + this._rotation, x, y + 14);
|
||||
this._game.stage.context.fillText('World X: ' + this.scroll.x.toFixed(1) + ' World Y: ' + this.scroll.y.toFixed(1), x, y + 28);
|
||||
if(this.bounds) {
|
||||
this._game.stage.context.fillText('Bounds: ' + this.bounds.width + ' x ' + this.bounds.height, x, y + 56);
|
||||
}
|
||||
};
|
||||
Object.defineProperty(Camera.prototype, "x", {
|
||||
get: function () {
|
||||
return this._stageX;
|
||||
},
|
||||
set: function (value) {
|
||||
this._stageX = value;
|
||||
this.checkClip();
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Camera.prototype, "y", {
|
||||
get: function () {
|
||||
return this._stageY;
|
||||
},
|
||||
set: function (value) {
|
||||
this._stageY = value;
|
||||
this.checkClip();
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Camera.prototype, "width", {
|
||||
get: function () {
|
||||
return this.worldView.width;
|
||||
},
|
||||
set: function (value) {
|
||||
if(value > this._game.stage.width) {
|
||||
value = this._game.stage.width;
|
||||
}
|
||||
this.worldView.width = value;
|
||||
this.checkClip();
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Camera.prototype, "height", {
|
||||
get: function () {
|
||||
return this.worldView.height;
|
||||
},
|
||||
set: function (value) {
|
||||
if(value > this._game.stage.height) {
|
||||
value = this._game.stage.height;
|
||||
}
|
||||
this.worldView.height = value;
|
||||
this.checkClip();
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Camera.prototype, "rotation", {
|
||||
get: function () {
|
||||
return this._rotation;
|
||||
},
|
||||
set: function (value) {
|
||||
this._rotation = this._game.math.wrap(value, 360, 0);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Camera.prototype.checkClip = function () {
|
||||
if(this._stageX !== 0 || this._stageY !== 0 || this.worldView.width < this._game.stage.width || this.worldView.height < this._game.stage.height) {
|
||||
this._clip = true;
|
||||
} else {
|
||||
this._clip = false;
|
||||
}
|
||||
};
|
||||
return Camera;
|
||||
})();
|
||||
Phaser.Camera = Camera;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,365 +0,0 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/**
|
||||
* Phaser - CollisionMask
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var CollisionMask = (function () {
|
||||
/**
|
||||
* CollisionMask constructor. Creates a new <code>CollisionMask</code> for the given GameObject.
|
||||
*
|
||||
* @param game {Phaser.Game} Current game instance.
|
||||
* @param parent {Phaser.GameObject} The GameObject this CollisionMask belongs to.
|
||||
* @param x {number} The initial x position of the CollisionMask.
|
||||
* @param y {number} The initial y position of the CollisionMask.
|
||||
* @param width {number} The width of the CollisionMask.
|
||||
* @param height {number} The height of the CollisionMask.
|
||||
*/
|
||||
function CollisionMask(game, parent, x, y, width, height) {
|
||||
/**
|
||||
* Geom type of this sprite. (available: QUAD, POINT, CIRCLE, LINE, RECTANGLE, POLYGON)
|
||||
* @type {number}
|
||||
*/
|
||||
this.type = 0;
|
||||
this._game = game;
|
||||
this._parent = parent;
|
||||
// By default the CollisionMask is a quad
|
||||
this.type = CollisionMask.QUAD;
|
||||
this.quad = new Phaser.Quad(this._parent.x, this._parent.y, this._parent.width, this._parent.height);
|
||||
this.offset = new Phaser.MicroPoint(0, 0);
|
||||
this.last = new Phaser.MicroPoint(0, 0);
|
||||
this._ref = this.quad;
|
||||
return this;
|
||||
}
|
||||
CollisionMask.QUAD = 0;
|
||||
CollisionMask.POINT = 1;
|
||||
CollisionMask.CIRCLE = 2;
|
||||
CollisionMask.LINE = 3;
|
||||
CollisionMask.RECTANGLE = 4;
|
||||
CollisionMask.POLYGON = 5;
|
||||
CollisionMask.prototype.createCircle = /**
|
||||
* Create a circle shape with specific diameter.
|
||||
* @param diameter {number} Diameter of the circle.
|
||||
* @return {CollisionMask} This
|
||||
*/
|
||||
function (diameter) {
|
||||
this.type = CollisionMask.CIRCLE;
|
||||
this.circle = new Phaser.Circle(this.last.x, this.last.y, diameter);
|
||||
this._ref = this.circle;
|
||||
return this;
|
||||
};
|
||||
CollisionMask.prototype.preUpdate = /**
|
||||
* Pre-update is called right before update() on each object in the game loop.
|
||||
*/
|
||||
function () {
|
||||
this.last.x = this.x;
|
||||
this.last.y = this.y;
|
||||
};
|
||||
CollisionMask.prototype.update = function () {
|
||||
this._ref.x = this._parent.x + this.offset.x;
|
||||
this._ref.y = this._parent.y + this.offset.y;
|
||||
};
|
||||
CollisionMask.prototype.render = /**
|
||||
* Renders the bounding box around this Sprite and the contact points. Useful for visually debugging.
|
||||
* @param camera {Camera} Camera the bound will be rendered to.
|
||||
* @param cameraOffsetX {number} X offset of bound to the camera.
|
||||
* @param cameraOffsetY {number} Y offset of bound to the camera.
|
||||
*/
|
||||
function (camera, cameraOffsetX, cameraOffsetY) {
|
||||
var _dx = cameraOffsetX + (this.x - camera.worldView.x);
|
||||
var _dy = cameraOffsetY + (this.y - camera.worldView.y);
|
||||
this._parent.context.fillStyle = this._parent.renderDebugColor;
|
||||
if(this.type == CollisionMask.QUAD) {
|
||||
this._parent.context.fillRect(_dx, _dy, this.width, this.height);
|
||||
} else if(this.type == CollisionMask.CIRCLE) {
|
||||
this._parent.context.beginPath();
|
||||
this._parent.context.arc(_dx, _dy, this.circle.radius, 0, Math.PI * 2);
|
||||
this._parent.context.fill();
|
||||
this._parent.context.closePath();
|
||||
}
|
||||
};
|
||||
CollisionMask.prototype.destroy = /**
|
||||
* Destroy all objects and references belonging to this CollisionMask
|
||||
*/
|
||||
function () {
|
||||
this._game = null;
|
||||
this._parent = null;
|
||||
this._ref = null;
|
||||
this.quad = null;
|
||||
this.point = null;
|
||||
this.circle = null;
|
||||
this.rect = null;
|
||||
this.line = null;
|
||||
this.offset = null;
|
||||
};
|
||||
CollisionMask.prototype.intersectsRaw = function (left, right, top, bottom) {
|
||||
//if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height))
|
||||
return true;
|
||||
};
|
||||
CollisionMask.prototype.intersectsVector = function (vector) {
|
||||
if(this.type == CollisionMask.QUAD) {
|
||||
return this.quad.contains(vector.x, vector.y);
|
||||
}
|
||||
};
|
||||
CollisionMask.prototype.intersects = /**
|
||||
* Gives a basic boolean response to a geometric collision.
|
||||
* If you need the details of the collision use the Collision functions instead and inspect the IntersectResult object.
|
||||
* @param source {GeomSprite} Sprite you want to check.
|
||||
* @return {boolean} Whether they overlaps or not.
|
||||
*/
|
||||
function (source) {
|
||||
// Quad vs. Quad
|
||||
if(this.type == CollisionMask.QUAD && source.type == CollisionMask.QUAD) {
|
||||
return this.quad.intersects(source.quad);
|
||||
}
|
||||
// Circle vs. Circle
|
||||
if(this.type == CollisionMask.CIRCLE && source.type == CollisionMask.CIRCLE) {
|
||||
return Phaser.Collision.circleToCircle(this.circle, source.circle).result;
|
||||
}
|
||||
// Circle vs. Rect
|
||||
if(this.type == CollisionMask.CIRCLE && source.type == CollisionMask.RECTANGLE) {
|
||||
return Phaser.Collision.circleToRectangle(this.circle, source.rect).result;
|
||||
}
|
||||
// Circle vs. Point
|
||||
if(this.type == CollisionMask.CIRCLE && source.type == CollisionMask.POINT) {
|
||||
return Phaser.Collision.circleContainsPoint(this.circle, source.point).result;
|
||||
}
|
||||
// Circle vs. Line
|
||||
if(this.type == CollisionMask.CIRCLE && source.type == CollisionMask.LINE) {
|
||||
return Phaser.Collision.lineToCircle(source.line, this.circle).result;
|
||||
}
|
||||
// Rect vs. Rect
|
||||
if(this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.RECTANGLE) {
|
||||
return Phaser.Collision.rectangleToRectangle(this.rect, source.rect).result;
|
||||
}
|
||||
// Rect vs. Circle
|
||||
if(this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.CIRCLE) {
|
||||
return Phaser.Collision.circleToRectangle(source.circle, this.rect).result;
|
||||
}
|
||||
// Rect vs. Point
|
||||
if(this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.POINT) {
|
||||
return Phaser.Collision.pointToRectangle(source.point, this.rect).result;
|
||||
}
|
||||
// Rect vs. Line
|
||||
if(this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.LINE) {
|
||||
return Phaser.Collision.lineToRectangle(source.line, this.rect).result;
|
||||
}
|
||||
// Point vs. Point
|
||||
if(this.type == CollisionMask.POINT && source.type == CollisionMask.POINT) {
|
||||
return this.point.equals(source.point);
|
||||
}
|
||||
// Point vs. Circle
|
||||
if(this.type == CollisionMask.POINT && source.type == CollisionMask.CIRCLE) {
|
||||
return Phaser.Collision.circleContainsPoint(source.circle, this.point).result;
|
||||
}
|
||||
// Point vs. Rect
|
||||
if(this.type == CollisionMask.POINT && source.type == CollisionMask.RECTANGLE) {
|
||||
return Phaser.Collision.pointToRectangle(this.point, source.rect).result;
|
||||
}
|
||||
// Point vs. Line
|
||||
if(this.type == CollisionMask.POINT && source.type == CollisionMask.LINE) {
|
||||
return source.line.isPointOnLine(this.point.x, this.point.y);
|
||||
}
|
||||
// Line vs. Line
|
||||
if(this.type == CollisionMask.LINE && source.type == CollisionMask.LINE) {
|
||||
return Phaser.Collision.lineSegmentToLineSegment(this.line, source.line).result;
|
||||
}
|
||||
// Line vs. Circle
|
||||
if(this.type == CollisionMask.LINE && source.type == CollisionMask.CIRCLE) {
|
||||
return Phaser.Collision.lineToCircle(this.line, source.circle).result;
|
||||
}
|
||||
// Line vs. Rect
|
||||
if(this.type == CollisionMask.LINE && source.type == CollisionMask.RECTANGLE) {
|
||||
return Phaser.Collision.lineSegmentToRectangle(this.line, source.rect).result;
|
||||
}
|
||||
// Line vs. Point
|
||||
if(this.type == CollisionMask.LINE && source.type == CollisionMask.POINT) {
|
||||
return this.line.isPointOnLine(source.point.x, source.point.y);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
CollisionMask.prototype.checkHullIntersection = function (mask) {
|
||||
if((this.hullX + this.hullWidth > mask.hullX) && (this.hullX < mask.hullX + mask.width) && (this.hullY + this.hullHeight > mask.hullY) && (this.hullY < mask.hullY + mask.hullHeight)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Object.defineProperty(CollisionMask.prototype, "hullWidth", {
|
||||
get: function () {
|
||||
if(this.deltaX > 0) {
|
||||
return this.width + this.deltaX;
|
||||
} else {
|
||||
return this.width - this.deltaX;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "hullHeight", {
|
||||
get: function () {
|
||||
if(this.deltaY > 0) {
|
||||
return this.height + this.deltaY;
|
||||
} else {
|
||||
return this.height - this.deltaY;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "hullX", {
|
||||
get: function () {
|
||||
if(this.x < this.last.x) {
|
||||
return this.x;
|
||||
} else {
|
||||
return this.last.x;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "hullY", {
|
||||
get: function () {
|
||||
if(this.y < this.last.y) {
|
||||
return this.y;
|
||||
} else {
|
||||
return this.last.y;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "deltaXAbs", {
|
||||
get: function () {
|
||||
return (this.deltaX > 0 ? this.deltaX : -this.deltaX);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "deltaYAbs", {
|
||||
get: function () {
|
||||
return (this.deltaY > 0 ? this.deltaY : -this.deltaY);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "deltaX", {
|
||||
get: function () {
|
||||
return this.x - this.last.x;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "deltaY", {
|
||||
get: function () {
|
||||
return this.y - this.last.y;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "x", {
|
||||
get: function () {
|
||||
return this._ref.x;
|
||||
//return this.quad.x;
|
||||
},
|
||||
set: function (value) {
|
||||
this._ref.x = value;
|
||||
//this.quad.x = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "y", {
|
||||
get: function () {
|
||||
return this._ref.y;
|
||||
//return this.quad.y;
|
||||
},
|
||||
set: function (value) {
|
||||
this._ref.y = value;
|
||||
//this.quad.y = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "width", {
|
||||
get: function () {
|
||||
//return this.quad.width;
|
||||
return this._ref.width;
|
||||
},
|
||||
set: //public get rotation(): number {
|
||||
// return this._angle;
|
||||
//}
|
||||
//public set rotation(value: number) {
|
||||
// this._angle = this._game.math.wrap(value, 360, 0);
|
||||
//}
|
||||
//public get angle(): number {
|
||||
// return this._angle;
|
||||
//}
|
||||
//public set angle(value: number) {
|
||||
// this._angle = this._game.math.wrap(value, 360, 0);
|
||||
//}
|
||||
function (value) {
|
||||
//this.quad.width = value;
|
||||
this._ref.width = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "height", {
|
||||
get: function () {
|
||||
//return this.quad.height;
|
||||
return this._ref.height;
|
||||
},
|
||||
set: function (value) {
|
||||
//this.quad.height = value;
|
||||
this._ref.height = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "left", {
|
||||
get: function () {
|
||||
return this.x;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "right", {
|
||||
get: function () {
|
||||
return this.x + this.width;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "top", {
|
||||
get: function () {
|
||||
return this.y;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "bottom", {
|
||||
get: function () {
|
||||
return this.y + this.height;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "halfWidth", {
|
||||
get: function () {
|
||||
return this.width / 2;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CollisionMask.prototype, "halfHeight", {
|
||||
get: function () {
|
||||
return this.height / 2;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return CollisionMask;
|
||||
})();
|
||||
Phaser.CollisionMask = CollisionMask;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,428 +0,0 @@
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Device
|
||||
*
|
||||
* Detects device support capabilities. Using some elements from System.js by MrDoob and Modernizr
|
||||
* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/audio.js
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Device = (function () {
|
||||
/**
|
||||
* Device constructor
|
||||
*/
|
||||
function Device() {
|
||||
/**
|
||||
* An optional 'fix' for the horrendous Android stock browser bug
|
||||
* https://code.google.com/p/android/issues/detail?id=39247
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.patchAndroidClearRectBug = false;
|
||||
// Operating System
|
||||
/**
|
||||
* Is running desktop?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.desktop = false;
|
||||
/**
|
||||
* Is running on iOS?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.iOS = false;
|
||||
/**
|
||||
* Is running on android?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.android = false;
|
||||
/**
|
||||
* Is running on chromeOS?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.chromeOS = false;
|
||||
/**
|
||||
* Is running on linux?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.linux = false;
|
||||
/**
|
||||
* Is running on maxOS?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.macOS = false;
|
||||
/**
|
||||
* Is running on windows?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.windows = false;
|
||||
// Features
|
||||
/**
|
||||
* Is canvas available?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.canvas = false;
|
||||
/**
|
||||
* Is file available?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.file = false;
|
||||
/**
|
||||
* Is fileSystem available?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.fileSystem = false;
|
||||
/**
|
||||
* Is localStorage available?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.localStorage = false;
|
||||
/**
|
||||
* Is webGL available?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.webGL = false;
|
||||
/**
|
||||
* Is worker available?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.worker = false;
|
||||
/**
|
||||
* Is touch available?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.touch = false;
|
||||
/**
|
||||
* Is mspointer available?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.mspointer = false;
|
||||
/**
|
||||
* Is css3D available?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.css3D = false;
|
||||
// Browser
|
||||
/**
|
||||
* Is running in arora?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.arora = false;
|
||||
/**
|
||||
* Is running in chrome?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.chrome = false;
|
||||
/**
|
||||
* Is running in epiphany?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.epiphany = false;
|
||||
/**
|
||||
* Is running in firefox?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.firefox = false;
|
||||
/**
|
||||
* Is running in ie?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.ie = false;
|
||||
/**
|
||||
* Version of ie?
|
||||
* @type Number
|
||||
*/
|
||||
this.ieVersion = 0;
|
||||
/**
|
||||
* Is running in mobileSafari?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.mobileSafari = false;
|
||||
/**
|
||||
* Is running in midori?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.midori = false;
|
||||
/**
|
||||
* Is running in opera?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.opera = false;
|
||||
/**
|
||||
* Is running in safari?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.safari = false;
|
||||
this.webApp = false;
|
||||
// Audio
|
||||
/**
|
||||
* Are Audio tags available?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.audioData = false;
|
||||
/**
|
||||
* Is the WebAudio API available?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.webAudio = false;
|
||||
/**
|
||||
* Can this device play ogg files?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.ogg = false;
|
||||
/**
|
||||
* Can this device play opus files?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.opus = false;
|
||||
/**
|
||||
* Can this device play mp3 files?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.mp3 = false;
|
||||
/**
|
||||
* Can this device play wav files?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.wav = false;
|
||||
/**
|
||||
* Can this device play m4a files?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.m4a = false;
|
||||
/**
|
||||
* Can this device play webm files?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.webm = false;
|
||||
// Device
|
||||
/**
|
||||
* Is running on iPhone?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.iPhone = false;
|
||||
/**
|
||||
* Is running on iPhone4?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.iPhone4 = false;
|
||||
/**
|
||||
* Is running on iPad?
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.iPad = false;
|
||||
/**
|
||||
* PixelRatio of the host device?
|
||||
* @type Number
|
||||
*/
|
||||
this.pixelRatio = 0;
|
||||
this._checkAudio();
|
||||
this._checkBrowser();
|
||||
this._checkCSS3D();
|
||||
this._checkDevice();
|
||||
this._checkFeatures();
|
||||
this._checkOS();
|
||||
}
|
||||
/**
|
||||
* Check which OS is game running on.
|
||||
* @private
|
||||
*/
|
||||
Device.prototype._checkOS = function () {
|
||||
var ua = navigator.userAgent;
|
||||
|
||||
if (/Android/.test(ua)) {
|
||||
this.android = true;
|
||||
} else if (/CrOS/.test(ua)) {
|
||||
this.chromeOS = true;
|
||||
} else if (/iP[ao]d|iPhone/i.test(ua)) {
|
||||
this.iOS = true;
|
||||
} else if (/Linux/.test(ua)) {
|
||||
this.linux = true;
|
||||
} else if (/Mac OS/.test(ua)) {
|
||||
this.macOS = true;
|
||||
} else if (/Windows/.test(ua)) {
|
||||
this.windows = true;
|
||||
}
|
||||
|
||||
if (this.windows || this.macOS || this.linux) {
|
||||
this.desktop = true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check HTML5 features of the host environment.
|
||||
* @private
|
||||
*/
|
||||
Device.prototype._checkFeatures = function () {
|
||||
this.canvas = !!window['CanvasRenderingContext2D'];
|
||||
|
||||
try {
|
||||
this.localStorage = !!localStorage.getItem;
|
||||
} catch (error) {
|
||||
this.localStorage = false;
|
||||
}
|
||||
|
||||
this.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob'];
|
||||
this.fileSystem = !!window['requestFileSystem'];
|
||||
this.webGL = !!window['WebGLRenderingContext'];
|
||||
this.worker = !!window['Worker'];
|
||||
|
||||
if ('ontouchstart' in document.documentElement || window.navigator.msPointerEnabled) {
|
||||
this.touch = true;
|
||||
}
|
||||
|
||||
if (window.navigator.msPointerEnabled) {
|
||||
this.mspointer = true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check what browser is game running in.
|
||||
* @private
|
||||
*/
|
||||
Device.prototype._checkBrowser = function () {
|
||||
var ua = navigator.userAgent;
|
||||
|
||||
if (/Arora/.test(ua)) {
|
||||
this.arora = true;
|
||||
} else if (/Chrome/.test(ua)) {
|
||||
this.chrome = true;
|
||||
} else if (/Epiphany/.test(ua)) {
|
||||
this.epiphany = true;
|
||||
} else if (/Firefox/.test(ua)) {
|
||||
this.firefox = true;
|
||||
} else if (/Mobile Safari/.test(ua)) {
|
||||
this.mobileSafari = true;
|
||||
} else if (/MSIE (\d+\.\d+);/.test(ua)) {
|
||||
this.ie = true;
|
||||
this.ieVersion = parseInt(RegExp.$1);
|
||||
} else if (/Midori/.test(ua)) {
|
||||
this.midori = true;
|
||||
} else if (/Opera/.test(ua)) {
|
||||
this.opera = true;
|
||||
} else if (/Safari/.test(ua)) {
|
||||
this.safari = true;
|
||||
}
|
||||
|
||||
if (navigator['standalone']) {
|
||||
this.webApp = true;
|
||||
}
|
||||
};
|
||||
|
||||
Device.prototype.canPlayAudio = function (type) {
|
||||
if (type == 'mp3' && this.mp3) {
|
||||
return true;
|
||||
} else if (type == 'ogg' && (this.ogg || this.opus)) {
|
||||
return true;
|
||||
} else if (type == 'm4a' && this.m4a) {
|
||||
return true;
|
||||
} else if (type == 'wav' && this.wav) {
|
||||
return true;
|
||||
} else if (type == 'webm' && this.webm) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check audio support.
|
||||
* @private
|
||||
*/
|
||||
Device.prototype._checkAudio = function () {
|
||||
this.audioData = !!(window['Audio']);
|
||||
this.webAudio = !!(window['webkitAudioContext'] || window['AudioContext']);
|
||||
|
||||
var audioElement = document.createElement('audio');
|
||||
var result = false;
|
||||
|
||||
try {
|
||||
if (result = !!audioElement.canPlayType) {
|
||||
if (audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, '')) {
|
||||
this.ogg = true;
|
||||
}
|
||||
|
||||
if (audioElement.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, '')) {
|
||||
this.opus = true;
|
||||
}
|
||||
|
||||
if (audioElement.canPlayType('audio/mpeg;').replace(/^no$/, '')) {
|
||||
this.mp3 = true;
|
||||
}
|
||||
|
||||
if (audioElement.canPlayType('audio/wav; codecs="1"').replace(/^no$/, '')) {
|
||||
this.wav = true;
|
||||
}
|
||||
|
||||
if (audioElement.canPlayType('audio/x-m4a;') || audioElement.canPlayType('audio/aac;').replace(/^no$/, '')) {
|
||||
this.m4a = true;
|
||||
}
|
||||
|
||||
if (audioElement.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, '')) {
|
||||
this.webm = true;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check PixelRatio of devices.
|
||||
* @private
|
||||
*/
|
||||
Device.prototype._checkDevice = function () {
|
||||
this.pixelRatio = window['devicePixelRatio'] || 1;
|
||||
this.iPhone = navigator.userAgent.toLowerCase().indexOf('iphone') != -1;
|
||||
this.iPhone4 = (this.pixelRatio == 2 && this.iPhone);
|
||||
this.iPad = navigator.userAgent.toLowerCase().indexOf('ipad') != -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether the host environment support 3D CSS.
|
||||
* @private
|
||||
*/
|
||||
Device.prototype._checkCSS3D = function () {
|
||||
var el = document.createElement('p');
|
||||
var has3d;
|
||||
var transforms = {
|
||||
'webkitTransform': '-webkit-transform',
|
||||
'OTransform': '-o-transform',
|
||||
'msTransform': '-ms-transform',
|
||||
'MozTransform': '-moz-transform',
|
||||
'transform': 'transform'
|
||||
};
|
||||
|
||||
// Add it to the body to get the computed style.
|
||||
document.body.insertBefore(el, null);
|
||||
|
||||
for (var t in transforms) {
|
||||
if (el.style[t] !== undefined) {
|
||||
el.style[t] = "translate3d(1px,1px,1px)";
|
||||
has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
|
||||
}
|
||||
}
|
||||
|
||||
document.body.removeChild(el);
|
||||
|
||||
this.css3D = (has3d !== undefined && has3d.length > 0 && has3d !== "none");
|
||||
};
|
||||
|
||||
Device.prototype.isConsoleOpen = function () {
|
||||
if (window.console && window.console['firebug']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (window.console) {
|
||||
console.profile();
|
||||
console.profileEnd();
|
||||
|
||||
if (console.clear)
|
||||
console.clear();
|
||||
|
||||
return console['profiles'].length > 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
return Device;
|
||||
})();
|
||||
Phaser.Device = Device;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,30 +0,0 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/**
|
||||
* Phaser - LinkedList
|
||||
*
|
||||
* A miniature linked list class. Useful for optimizing time-critical or highly repetitive tasks!
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var LinkedList = (function () {
|
||||
/**
|
||||
* Creates a new link, and sets <code>object</code> and <code>next</code> to <code>null</code>.
|
||||
*/
|
||||
function LinkedList() {
|
||||
this.object = null;
|
||||
this.next = null;
|
||||
}
|
||||
LinkedList.prototype.destroy = /**
|
||||
* Clean up memory.
|
||||
*/
|
||||
function () {
|
||||
this.object = null;
|
||||
if(this.next != null) {
|
||||
this.next.destroy();
|
||||
}
|
||||
this.next = null;
|
||||
};
|
||||
return LinkedList;
|
||||
})();
|
||||
Phaser.LinkedList = LinkedList;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,355 +0,0 @@
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="LinkedList.ts" />
|
||||
/**
|
||||
* Phaser - QuadTree
|
||||
*
|
||||
* A fairly generic quad tree structure for rapid overlap checks. QuadTree is also configured for single or dual list operation.
|
||||
* You can add items either to its A list or its B list. When you do an overlap check, you can compare the A list to itself,
|
||||
* or the A list against the B list. Handy for different things!
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var QuadTree = (function (_super) {
|
||||
__extends(QuadTree, _super);
|
||||
/**
|
||||
* Instantiate a new Quad Tree node.
|
||||
*
|
||||
* @param {Number} x The X-coordinate of the point in space.
|
||||
* @param {Number} y The Y-coordinate of the point in space.
|
||||
* @param {Number} width Desired width of this node.
|
||||
* @param {Number} height Desired height of this node.
|
||||
* @param {Number} parent The parent branch or node. Pass null to create a root.
|
||||
*/
|
||||
function QuadTree(x, y, width, height, parent) {
|
||||
if (typeof parent === "undefined") { parent = null; }
|
||||
_super.call(this, x, y, width, height);
|
||||
this._headA = this._tailA = new LinkedList();
|
||||
this._headB = this._tailB = new LinkedList();
|
||||
//Copy the parent's children (if there are any)
|
||||
if(parent != null) {
|
||||
var iterator;
|
||||
var ot;
|
||||
if(parent._headA.object != null) {
|
||||
iterator = parent._headA;
|
||||
while(iterator != null) {
|
||||
if(this._tailA.object != null) {
|
||||
ot = this._tailA;
|
||||
this._tailA = new LinkedList();
|
||||
ot.next = this._tailA;
|
||||
}
|
||||
this._tailA.object = iterator.object;
|
||||
iterator = iterator.next;
|
||||
}
|
||||
}
|
||||
if(parent._headB.object != null) {
|
||||
iterator = parent._headB;
|
||||
while(iterator != null) {
|
||||
if(this._tailB.object != null) {
|
||||
ot = this._tailB;
|
||||
this._tailB = new LinkedList();
|
||||
ot.next = this._tailB;
|
||||
}
|
||||
this._tailB.object = iterator.object;
|
||||
iterator = iterator.next;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
QuadTree._min = (this.width + this.height) / (2 * QuadTree.divisions);
|
||||
}
|
||||
this._canSubdivide = (this.width > QuadTree._min) || (this.height > QuadTree._min);
|
||||
//Set up comparison/sort helpers
|
||||
this._northWestTree = null;
|
||||
this._northEastTree = null;
|
||||
this._southEastTree = null;
|
||||
this._southWestTree = null;
|
||||
this._leftEdge = this.x;
|
||||
this._rightEdge = this.x + this.width;
|
||||
this._halfWidth = this.width / 2;
|
||||
this._midpointX = this._leftEdge + this._halfWidth;
|
||||
this._topEdge = this.y;
|
||||
this._bottomEdge = this.y + this.height;
|
||||
this._halfHeight = this.height / 2;
|
||||
this._midpointY = this._topEdge + this._halfHeight;
|
||||
}
|
||||
QuadTree.A_LIST = 0;
|
||||
QuadTree.B_LIST = 1;
|
||||
QuadTree.prototype.destroy = /**
|
||||
* Clean up memory.
|
||||
*/
|
||||
function () {
|
||||
this._tailA.destroy();
|
||||
this._tailB.destroy();
|
||||
this._headA.destroy();
|
||||
this._headB.destroy();
|
||||
this._tailA = null;
|
||||
this._tailB = null;
|
||||
this._headA = null;
|
||||
this._headB = null;
|
||||
if(this._northWestTree != null) {
|
||||
this._northWestTree.destroy();
|
||||
}
|
||||
if(this._northEastTree != null) {
|
||||
this._northEastTree.destroy();
|
||||
}
|
||||
if(this._southEastTree != null) {
|
||||
this._southEastTree.destroy();
|
||||
}
|
||||
if(this._southWestTree != null) {
|
||||
this._southWestTree.destroy();
|
||||
}
|
||||
this._northWestTree = null;
|
||||
this._northEastTree = null;
|
||||
this._southEastTree = null;
|
||||
this._southWestTree = null;
|
||||
Phaser.QuadTree._object = null;
|
||||
Phaser.QuadTree._processingCallback = null;
|
||||
Phaser.QuadTree._notifyCallback = null;
|
||||
};
|
||||
QuadTree.prototype.load = /**
|
||||
* Load objects and/or groups into the quad tree, and register notify and processing callbacks.
|
||||
*
|
||||
* @param {Basic} objectOrGroup1 Any object that is or extends GameObject or Group.
|
||||
* @param {Basic} objectOrGroup2 Any object that is or extends GameObject or Group. If null, the first parameter will be checked against itself.
|
||||
* @param {Function} notifyCallback A function with the form <code>myFunction(Object1:GameObject,Object2:GameObject)</code> that is called whenever two objects are found to overlap in world space, and either no processCallback is specified, or the processCallback returns true.
|
||||
* @param {Function} processCallback A function with the form <code>myFunction(Object1:GameObject,Object2:GameObject):bool</code> that is called whenever two objects are found to overlap in world space. The notifyCallback is only called if this function returns true. See GameObject.separate().
|
||||
* @param context The context in which the callbacks will be called
|
||||
*/
|
||||
function (objectOrGroup1, objectOrGroup2, notifyCallback, processCallback, context) {
|
||||
if (typeof objectOrGroup2 === "undefined") { objectOrGroup2 = null; }
|
||||
if (typeof notifyCallback === "undefined") { notifyCallback = null; }
|
||||
if (typeof processCallback === "undefined") { processCallback = null; }
|
||||
if (typeof context === "undefined") { context = null; }
|
||||
this.add(objectOrGroup1, Phaser.QuadTree.A_LIST);
|
||||
if(objectOrGroup2 != null) {
|
||||
this.add(objectOrGroup2, Phaser.QuadTree.B_LIST);
|
||||
Phaser.QuadTree._useBothLists = true;
|
||||
} else {
|
||||
Phaser.QuadTree._useBothLists = false;
|
||||
}
|
||||
Phaser.QuadTree._notifyCallback = notifyCallback;
|
||||
Phaser.QuadTree._processingCallback = processCallback;
|
||||
Phaser.QuadTree._callbackContext = context;
|
||||
};
|
||||
QuadTree.prototype.add = /**
|
||||
* Call this function to add an object to the root of the tree.
|
||||
* This function will recursively add all group members, but
|
||||
* not the groups themselves.
|
||||
*
|
||||
* @param {Basic} objectOrGroup GameObjects are just added, Groups are recursed and their applicable members added accordingly.
|
||||
* @param {Number} list A <code>uint</code> flag indicating the list to which you want to add the objects. Options are <code>QuadTree.A_LIST</code> and <code>QuadTree.B_LIST</code>.
|
||||
*/
|
||||
function (objectOrGroup, list) {
|
||||
Phaser.QuadTree._list = list;
|
||||
if(objectOrGroup.isGroup == true) {
|
||||
var i = 0;
|
||||
var basic;
|
||||
var members = objectOrGroup['members'];
|
||||
var l = objectOrGroup['length'];
|
||||
while(i < l) {
|
||||
basic = members[i++];
|
||||
if((basic != null) && basic.exists) {
|
||||
if(basic.isGroup) {
|
||||
this.add(basic, list);
|
||||
} else {
|
||||
Phaser.QuadTree._object = basic;
|
||||
if(Phaser.QuadTree._object.exists && Phaser.QuadTree._object.allowCollisions) {
|
||||
this.addObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Phaser.QuadTree._object = objectOrGroup;
|
||||
if(Phaser.QuadTree._object.exists && Phaser.QuadTree._object.allowCollisions) {
|
||||
this.addObject();
|
||||
}
|
||||
}
|
||||
};
|
||||
QuadTree.prototype.addObject = /**
|
||||
* Internal function for recursively navigating and creating the tree
|
||||
* while adding objects to the appropriate nodes.
|
||||
*/
|
||||
function () {
|
||||
//If this quad (not its children) lies entirely inside this object, add it here
|
||||
if(!this._canSubdivide || ((this._leftEdge >= Phaser.QuadTree._object.collisionMask.x) && (this._rightEdge <= Phaser.QuadTree._object.collisionMask.right) && (this._topEdge >= Phaser.QuadTree._object.collisionMask.y) && (this._bottomEdge <= Phaser.QuadTree._object.collisionMask.bottom))) {
|
||||
this.addToList();
|
||||
return;
|
||||
}
|
||||
//See if the selected object fits completely inside any of the quadrants
|
||||
if((Phaser.QuadTree._object.collisionMask.x > this._leftEdge) && (Phaser.QuadTree._object.collisionMask.right < this._midpointX)) {
|
||||
if((Phaser.QuadTree._object.collisionMask.y > this._topEdge) && (Phaser.QuadTree._object.collisionMask.bottom < this._midpointY)) {
|
||||
if(this._northWestTree == null) {
|
||||
this._northWestTree = new Phaser.QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._northWestTree.addObject();
|
||||
return;
|
||||
}
|
||||
if((Phaser.QuadTree._object.collisionMask.y > this._midpointY) && (Phaser.QuadTree._object.collisionMask.bottom < this._bottomEdge)) {
|
||||
if(this._southWestTree == null) {
|
||||
this._southWestTree = new Phaser.QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._southWestTree.addObject();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if((Phaser.QuadTree._object.collisionMask.x > this._midpointX) && (Phaser.QuadTree._object.collisionMask.right < this._rightEdge)) {
|
||||
if((Phaser.QuadTree._object.collisionMask.y > this._topEdge) && (Phaser.QuadTree._object.collisionMask.bottom < this._midpointY)) {
|
||||
if(this._northEastTree == null) {
|
||||
this._northEastTree = new Phaser.QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._northEastTree.addObject();
|
||||
return;
|
||||
}
|
||||
if((Phaser.QuadTree._object.collisionMask.y > this._midpointY) && (Phaser.QuadTree._object.collisionMask.bottom < this._bottomEdge)) {
|
||||
if(this._southEastTree == null) {
|
||||
this._southEastTree = new Phaser.QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._southEastTree.addObject();
|
||||
return;
|
||||
}
|
||||
}
|
||||
//If it wasn't completely contained we have to check out the partial overlaps
|
||||
if((Phaser.QuadTree._object.collisionMask.right > this._leftEdge) && (Phaser.QuadTree._object.collisionMask.x < this._midpointX) && (Phaser.QuadTree._object.collisionMask.bottom > this._topEdge) && (Phaser.QuadTree._object.collisionMask.y < this._midpointY)) {
|
||||
if(this._northWestTree == null) {
|
||||
this._northWestTree = new Phaser.QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._northWestTree.addObject();
|
||||
}
|
||||
if((Phaser.QuadTree._object.collisionMask.right > this._midpointX) && (Phaser.QuadTree._object.collisionMask.x < this._rightEdge) && (Phaser.QuadTree._object.collisionMask.bottom > this._topEdge) && (Phaser.QuadTree._object.collisionMask.y < this._midpointY)) {
|
||||
if(this._northEastTree == null) {
|
||||
this._northEastTree = new Phaser.QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._northEastTree.addObject();
|
||||
}
|
||||
if((Phaser.QuadTree._object.collisionMask.right > this._midpointX) && (Phaser.QuadTree._object.collisionMask.x < this._rightEdge) && (Phaser.QuadTree._object.collisionMask.bottom > this._midpointY) && (Phaser.QuadTree._object.collisionMask.y < this._bottomEdge)) {
|
||||
if(this._southEastTree == null) {
|
||||
this._southEastTree = new Phaser.QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._southEastTree.addObject();
|
||||
}
|
||||
if((Phaser.QuadTree._object.collisionMask.right > this._leftEdge) && (Phaser.QuadTree._object.collisionMask.x < this._midpointX) && (Phaser.QuadTree._object.collisionMask.bottom > this._midpointY) && (Phaser.QuadTree._object.collisionMask.y < this._bottomEdge)) {
|
||||
if(this._southWestTree == null) {
|
||||
this._southWestTree = new Phaser.QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
|
||||
}
|
||||
this._southWestTree.addObject();
|
||||
}
|
||||
};
|
||||
QuadTree.prototype.addToList = /**
|
||||
* Internal function for recursively adding objects to leaf lists.
|
||||
*/
|
||||
function () {
|
||||
var ot;
|
||||
if(Phaser.QuadTree._list == Phaser.QuadTree.A_LIST) {
|
||||
if(this._tailA.object != null) {
|
||||
ot = this._tailA;
|
||||
this._tailA = new Phaser.LinkedList();
|
||||
ot.next = this._tailA;
|
||||
}
|
||||
this._tailA.object = Phaser.QuadTree._object;
|
||||
} else {
|
||||
if(this._tailB.object != null) {
|
||||
ot = this._tailB;
|
||||
this._tailB = new Phaser.LinkedList();
|
||||
ot.next = this._tailB;
|
||||
}
|
||||
this._tailB.object = Phaser.QuadTree._object;
|
||||
}
|
||||
if(!this._canSubdivide) {
|
||||
return;
|
||||
}
|
||||
if(this._northWestTree != null) {
|
||||
this._northWestTree.addToList();
|
||||
}
|
||||
if(this._northEastTree != null) {
|
||||
this._northEastTree.addToList();
|
||||
}
|
||||
if(this._southEastTree != null) {
|
||||
this._southEastTree.addToList();
|
||||
}
|
||||
if(this._southWestTree != null) {
|
||||
this._southWestTree.addToList();
|
||||
}
|
||||
};
|
||||
QuadTree.prototype.execute = /**
|
||||
* <code>QuadTree</code>'s other main function. Call this after adding objects
|
||||
* using <code>QuadTree.load()</code> to compare the objects that you loaded.
|
||||
*
|
||||
* @return {Boolean} Whether or not any overlaps were found.
|
||||
*/
|
||||
function () {
|
||||
var overlapProcessed = false;
|
||||
var iterator;
|
||||
if(this._headA.object != null) {
|
||||
iterator = this._headA;
|
||||
while(iterator != null) {
|
||||
Phaser.QuadTree._object = iterator.object;
|
||||
if(Phaser.QuadTree._useBothLists) {
|
||||
Phaser.QuadTree._iterator = this._headB;
|
||||
} else {
|
||||
Phaser.QuadTree._iterator = iterator.next;
|
||||
}
|
||||
if(Phaser.QuadTree._object.exists && (Phaser.QuadTree._object.allowCollisions > 0) && (Phaser.QuadTree._iterator != null) && (Phaser.QuadTree._iterator.object != null) && Phaser.QuadTree._iterator.object.exists && this.overlapNode()) {
|
||||
overlapProcessed = true;
|
||||
}
|
||||
iterator = iterator.next;
|
||||
}
|
||||
}
|
||||
//Advance through the tree by calling overlap on each child
|
||||
if((this._northWestTree != null) && this._northWestTree.execute()) {
|
||||
overlapProcessed = true;
|
||||
}
|
||||
if((this._northEastTree != null) && this._northEastTree.execute()) {
|
||||
overlapProcessed = true;
|
||||
}
|
||||
if((this._southEastTree != null) && this._southEastTree.execute()) {
|
||||
overlapProcessed = true;
|
||||
}
|
||||
if((this._southWestTree != null) && this._southWestTree.execute()) {
|
||||
overlapProcessed = true;
|
||||
}
|
||||
return overlapProcessed;
|
||||
};
|
||||
QuadTree.prototype.overlapNode = /**
|
||||
* A private for comparing an object against the contents of a node.
|
||||
*
|
||||
* @return {Boolean} Whether or not any overlaps were found.
|
||||
*/
|
||||
function () {
|
||||
//Walk the list and check for overlaps
|
||||
var overlapProcessed = false;
|
||||
var checkObject;
|
||||
while(Phaser.QuadTree._iterator != null) {
|
||||
if(!Phaser.QuadTree._object.exists || (Phaser.QuadTree._object.allowCollisions <= 0)) {
|
||||
break;
|
||||
}
|
||||
checkObject = Phaser.QuadTree._iterator.object;
|
||||
if((Phaser.QuadTree._object === checkObject) || !checkObject.exists || (checkObject.allowCollisions <= 0)) {
|
||||
Phaser.QuadTree._iterator = Phaser.QuadTree._iterator.next;
|
||||
continue;
|
||||
}
|
||||
if(Phaser.QuadTree._object.collisionMask.checkHullIntersection(checkObject.collisionMask)) {
|
||||
//Execute callback functions if they exist
|
||||
if((Phaser.QuadTree._processingCallback == null) || Phaser.QuadTree._processingCallback(Phaser.QuadTree._object, checkObject)) {
|
||||
overlapProcessed = true;
|
||||
}
|
||||
if(overlapProcessed && (Phaser.QuadTree._notifyCallback != null)) {
|
||||
if(Phaser.QuadTree._callbackContext !== null) {
|
||||
Phaser.QuadTree._notifyCallback.call(Phaser.QuadTree._callbackContext, Phaser.QuadTree._object, checkObject);
|
||||
} else {
|
||||
Phaser.QuadTree._notifyCallback(Phaser.QuadTree._object, checkObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Phaser.QuadTree._iterator = Phaser.QuadTree._iterator.next;
|
||||
}
|
||||
return overlapProcessed;
|
||||
};
|
||||
return QuadTree;
|
||||
})(Phaser.Rectangle);
|
||||
Phaser.QuadTree = QuadTree;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,227 +0,0 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/**
|
||||
* Phaser - RandomDataGenerator
|
||||
*
|
||||
* An extremely useful repeatable random data generator. Access it via Game.rnd
|
||||
* Based on Nonsense by Josh Faul https://github.com/jocafa/Nonsense
|
||||
* Random number generator from http://baagoe.org/en/wiki/Better_random_numbers_for_javascript
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var RandomDataGenerator = (function () {
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Array} seeds
|
||||
* @return {Phaser.RandomDataGenerator}
|
||||
*/
|
||||
function RandomDataGenerator(seeds) {
|
||||
if (typeof seeds === "undefined") { seeds = []; }
|
||||
/**
|
||||
* @property c
|
||||
* @type Number
|
||||
* @private
|
||||
*/
|
||||
this.c = 1;
|
||||
this.sow(seeds);
|
||||
}
|
||||
RandomDataGenerator.prototype.uint32 = /**
|
||||
* @method uint32
|
||||
* @private
|
||||
*/
|
||||
function () {
|
||||
return this.rnd.apply(this) * 0x100000000;// 2^32
|
||||
|
||||
};
|
||||
RandomDataGenerator.prototype.fract32 = /**
|
||||
* @method fract32
|
||||
* @private
|
||||
*/
|
||||
function () {
|
||||
return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16;// 2^-53
|
||||
|
||||
};
|
||||
RandomDataGenerator.prototype.rnd = // private random helper
|
||||
/**
|
||||
* @method rnd
|
||||
* @private
|
||||
*/
|
||||
function () {
|
||||
var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10;// 2^-32
|
||||
|
||||
this.c = t | 0;
|
||||
this.s0 = this.s1;
|
||||
this.s1 = this.s2;
|
||||
this.s2 = t - this.c;
|
||||
return this.s2;
|
||||
};
|
||||
RandomDataGenerator.prototype.hash = /**
|
||||
* @method hash
|
||||
* @param {Any} data
|
||||
* @private
|
||||
*/
|
||||
function (data) {
|
||||
var h, i, n;
|
||||
n = 0xefc8249d;
|
||||
data = data.toString();
|
||||
for(i = 0; i < data.length; i++) {
|
||||
n += data.charCodeAt(i);
|
||||
h = 0.02519603282416938 * n;
|
||||
n = h >>> 0;
|
||||
h -= n;
|
||||
h *= n;
|
||||
n = h >>> 0;
|
||||
h -= n;
|
||||
n += h * 0x100000000// 2^32
|
||||
;
|
||||
}
|
||||
return (n >>> 0) * 2.3283064365386963e-10;// 2^-32
|
||||
|
||||
};
|
||||
RandomDataGenerator.prototype.sow = /**
|
||||
* Reset the seed of the random data generator
|
||||
* @method sow
|
||||
* @param {Array} seeds
|
||||
*/
|
||||
function (seeds) {
|
||||
if (typeof seeds === "undefined") { seeds = []; }
|
||||
this.s0 = this.hash(' ');
|
||||
this.s1 = this.hash(this.s0);
|
||||
this.s2 = this.hash(this.s1);
|
||||
var seed;
|
||||
for(var i = 0; seed = seeds[i++]; ) {
|
||||
this.s0 -= this.hash(seed);
|
||||
this.s0 += ~~(this.s0 < 0);
|
||||
this.s1 -= this.hash(seed);
|
||||
this.s1 += ~~(this.s1 < 0);
|
||||
this.s2 -= this.hash(seed);
|
||||
this.s2 += ~~(this.s2 < 0);
|
||||
}
|
||||
};
|
||||
Object.defineProperty(RandomDataGenerator.prototype, "integer", {
|
||||
get: /**
|
||||
* Returns a random integer between 0 and 2^32
|
||||
* @method integer
|
||||
* @return {Number}
|
||||
*/
|
||||
function () {
|
||||
return this.uint32();
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(RandomDataGenerator.prototype, "frac", {
|
||||
get: /**
|
||||
* Returns a random real number between 0 and 1
|
||||
* @method frac
|
||||
* @return {Number}
|
||||
*/
|
||||
function () {
|
||||
return this.fract32();
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(RandomDataGenerator.prototype, "real", {
|
||||
get: /**
|
||||
* Returns a random real number between 0 and 2^32
|
||||
* @method real
|
||||
* @return {Number}
|
||||
*/
|
||||
function () {
|
||||
return this.uint32() + this.fract32();
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
RandomDataGenerator.prototype.integerInRange = /**
|
||||
* Returns a random integer between min and max
|
||||
* @method integerInRange
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @return {Number}
|
||||
*/
|
||||
function (min, max) {
|
||||
return Math.floor(this.realInRange(min, max));
|
||||
};
|
||||
RandomDataGenerator.prototype.realInRange = /**
|
||||
* Returns a random real number between min and max
|
||||
* @method realInRange
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @return {Number}
|
||||
*/
|
||||
function (min, max) {
|
||||
min = min || 0;
|
||||
max = max || 0;
|
||||
return this.frac * (max - min) + min;
|
||||
};
|
||||
Object.defineProperty(RandomDataGenerator.prototype, "normal", {
|
||||
get: /**
|
||||
* Returns a random real number between -1 and 1
|
||||
* @method normal
|
||||
* @return {Number}
|
||||
*/
|
||||
function () {
|
||||
return 1 - 2 * this.frac;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(RandomDataGenerator.prototype, "uuid", {
|
||||
get: /**
|
||||
* Returns a valid v4 UUID hex string (from https://gist.github.com/1308368)
|
||||
* @method uuid
|
||||
* @return {String}
|
||||
*/
|
||||
function () {
|
||||
var a, b;
|
||||
for(b = a = ''; a++ < 36; b += ~a % 5 | a * 3 & 4 ? (a ^ 15 ? 8 ^ this.frac * (a ^ 20 ? 16 : 4) : 4).toString(16) : '-') {
|
||||
;
|
||||
}
|
||||
return b;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
RandomDataGenerator.prototype.pick = /**
|
||||
* Returns a random member of `array`
|
||||
* @method pick
|
||||
* @param {Any} array
|
||||
*/
|
||||
function (array) {
|
||||
return array[this.integerInRange(0, array.length)];
|
||||
};
|
||||
RandomDataGenerator.prototype.weightedPick = /**
|
||||
* Returns a random member of `array`, favoring the earlier entries
|
||||
* @method weightedPick
|
||||
* @param {Any} array
|
||||
*/
|
||||
function (array) {
|
||||
return array[~~(Math.pow(this.frac, 2) * array.length)];
|
||||
};
|
||||
RandomDataGenerator.prototype.timestamp = /**
|
||||
* Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified
|
||||
* @method timestamp
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
*/
|
||||
function (min, max) {
|
||||
if (typeof min === "undefined") { min = 946684800000; }
|
||||
if (typeof max === "undefined") { max = 1577862000000; }
|
||||
return this.realInRange(min, max);
|
||||
};
|
||||
Object.defineProperty(RandomDataGenerator.prototype, "angle", {
|
||||
get: /**
|
||||
* Returns a random angle between -180 and 180
|
||||
* @method angle
|
||||
*/
|
||||
function () {
|
||||
return this.integerInRange(-180, 180);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return RandomDataGenerator;
|
||||
})();
|
||||
Phaser.RandomDataGenerator = RandomDataGenerator;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,142 +0,0 @@
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - RequestAnimationFrame
|
||||
*
|
||||
* Abstracts away the use of RAF or setTimeOut for the core game update loop. The callback can be re-mapped on the fly.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var RequestAnimationFrame = (function () {
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Any} callback
|
||||
* @return {RequestAnimationFrame} This object.
|
||||
*/
|
||||
function RequestAnimationFrame(game, callback) {
|
||||
/**
|
||||
*
|
||||
* @property _isSetTimeOut
|
||||
* @type Boolean
|
||||
* @private
|
||||
**/
|
||||
this._isSetTimeOut = false;
|
||||
/**
|
||||
*
|
||||
* @property isRunning
|
||||
* @type Boolean
|
||||
**/
|
||||
this.isRunning = false;
|
||||
this.game = game;
|
||||
this.callback = callback;
|
||||
|
||||
var vendors = ['ms', 'moz', 'webkit', 'o'];
|
||||
|
||||
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; x++) {
|
||||
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
|
||||
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'];
|
||||
}
|
||||
|
||||
this.start();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @method usingSetTimeOut
|
||||
* @return Boolean
|
||||
**/
|
||||
RequestAnimationFrame.prototype.isUsingSetTimeOut = function () {
|
||||
return this._isSetTimeOut;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @method usingRAF
|
||||
* @return Boolean
|
||||
**/
|
||||
RequestAnimationFrame.prototype.isUsingRAF = function () {
|
||||
return this._isSetTimeOut === true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts the requestAnimatioFrame running or setTimeout if unavailable in browser
|
||||
* @method start
|
||||
* @param {Any} [callback]
|
||||
**/
|
||||
RequestAnimationFrame.prototype.start = function (callback) {
|
||||
if (typeof callback === "undefined") { callback = null; }
|
||||
var _this = this;
|
||||
if (callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
if (!window.requestAnimationFrame) {
|
||||
this._isSetTimeOut = true;
|
||||
this._onLoop = function () {
|
||||
return _this.SetTimeoutUpdate();
|
||||
};
|
||||
this._timeOutID = window.setTimeout(this._onLoop, 0);
|
||||
} else {
|
||||
this._isSetTimeOut = false;
|
||||
this._onLoop = function () {
|
||||
return _this.RAFUpdate(0);
|
||||
};
|
||||
window.requestAnimationFrame(this._onLoop);
|
||||
}
|
||||
|
||||
this.isRunning = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Stops the requestAnimationFrame from running
|
||||
* @method stop
|
||||
**/
|
||||
RequestAnimationFrame.prototype.stop = function () {
|
||||
if (this._isSetTimeOut) {
|
||||
clearTimeout(this._timeOutID);
|
||||
} else {
|
||||
window.cancelAnimationFrame;
|
||||
}
|
||||
|
||||
this.isRunning = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* The update method for the requestAnimationFrame
|
||||
* @method RAFUpdate
|
||||
**/
|
||||
RequestAnimationFrame.prototype.RAFUpdate = function (time) {
|
||||
var _this = this;
|
||||
this.game.time.update(time);
|
||||
|
||||
if (this.callback) {
|
||||
this.callback.call(this.game);
|
||||
}
|
||||
|
||||
this._onLoop = function (time) {
|
||||
return _this.RAFUpdate(time);
|
||||
};
|
||||
|
||||
window.requestAnimationFrame(this._onLoop);
|
||||
};
|
||||
|
||||
/**
|
||||
* The update method for the setTimeout
|
||||
* @method SetTimeoutUpdate
|
||||
**/
|
||||
RequestAnimationFrame.prototype.SetTimeoutUpdate = function () {
|
||||
var _this = this;
|
||||
this.game.time.update(Date.now());
|
||||
|
||||
this._onLoop = function () {
|
||||
return _this.SetTimeoutUpdate();
|
||||
};
|
||||
|
||||
this._timeOutID = window.setTimeout(this._onLoop, 16);
|
||||
|
||||
if (this.callback) {
|
||||
this.callback.call(this.game);
|
||||
}
|
||||
};
|
||||
return RequestAnimationFrame;
|
||||
})();
|
||||
Phaser.RequestAnimationFrame = RequestAnimationFrame;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,80 +0,0 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../SoundManager.ts" />
|
||||
/**
|
||||
* Phaser - Sound
|
||||
*
|
||||
* A Sound file, used by the Game.SoundManager for playback.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Sound = (function () {
|
||||
function Sound(context, gainNode, data, volume, loop) {
|
||||
if (typeof volume === "undefined") { volume = 1; }
|
||||
if (typeof loop === "undefined") { loop = false; }
|
||||
this.loop = false;
|
||||
this.isPlaying = false;
|
||||
this.isDecoding = false;
|
||||
this._context = context;
|
||||
this._gainNode = gainNode;
|
||||
this._buffer = data;
|
||||
this._volume = volume;
|
||||
this.loop = loop;
|
||||
// Local volume control
|
||||
if(this._context !== null) {
|
||||
this._localGainNode = this._context.createGainNode();
|
||||
this._localGainNode.connect(this._gainNode);
|
||||
this._localGainNode.gain.value = this._volume;
|
||||
}
|
||||
if(this._buffer === null) {
|
||||
this.isDecoding = true;
|
||||
} else {
|
||||
this.play();
|
||||
}
|
||||
}
|
||||
Sound.prototype.setDecodedBuffer = function (data) {
|
||||
this._buffer = data;
|
||||
this.isDecoding = false;
|
||||
//this.play();
|
||||
};
|
||||
Sound.prototype.play = function () {
|
||||
if(this._buffer === null || this.isDecoding === true) {
|
||||
return;
|
||||
}
|
||||
this._sound = this._context.createBufferSource();
|
||||
this._sound.buffer = this._buffer;
|
||||
this._sound.connect(this._localGainNode);
|
||||
if(this.loop) {
|
||||
this._sound.loop = true;
|
||||
}
|
||||
this._sound.noteOn(0)// the zero is vitally important, crashes iOS6 without it
|
||||
;
|
||||
this.duration = this._sound.buffer.duration;
|
||||
this.isPlaying = true;
|
||||
};
|
||||
Sound.prototype.stop = function () {
|
||||
if(this.isPlaying === true) {
|
||||
this.isPlaying = false;
|
||||
this._sound.noteOff(0);
|
||||
}
|
||||
};
|
||||
Sound.prototype.mute = function () {
|
||||
this._localGainNode.gain.value = 0;
|
||||
};
|
||||
Sound.prototype.unmute = function () {
|
||||
this._localGainNode.gain.value = this._volume;
|
||||
};
|
||||
Object.defineProperty(Sound.prototype, "volume", {
|
||||
get: function () {
|
||||
return this._volume;
|
||||
},
|
||||
set: function (value) {
|
||||
this._volume = value;
|
||||
this._localGainNode.gain.value = this._volume;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return Sound;
|
||||
})();
|
||||
Phaser.Sound = Sound;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,382 +0,0 @@
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - StageScaleMode
|
||||
*
|
||||
* This class controls the scaling of your game. On mobile devices it will also remove the URL bar and allow
|
||||
* you to maintain proportion and aspect ratio.
|
||||
* The resizing method is based on a technique taken from Viewporter v2.0 by Zynga Inc. http://github.com/zynga/viewporter
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var StageScaleMode = (function () {
|
||||
/**
|
||||
* StageScaleMode constructor
|
||||
*/
|
||||
function StageScaleMode(game, width, height) {
|
||||
var _this = this;
|
||||
/**
|
||||
* Stage height when start the game.
|
||||
* @type {number}
|
||||
*/
|
||||
this._startHeight = 0;
|
||||
/**
|
||||
* If the game should be forced to use Landscape mode, this is set to true by Game.Stage
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.forceLandscape = false;
|
||||
/**
|
||||
* If the game should be forced to use Portrait mode, this is set to true by Game.Stage
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.forcePortrait = false;
|
||||
/**
|
||||
* If the game should be forced to use a specific orientation and the device currently isn't in that orientation this is set to true.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.incorrectOrientation = false;
|
||||
/**
|
||||
* If you wish to align your game in the middle of the page then you can set this value to true.
|
||||
* It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing.
|
||||
* It doesn't care about any other DOM element that may be on the page, it literally just sets the margin.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.pageAlignHorizontally = false;
|
||||
/**
|
||||
* If you wish to align your game in the middle of the page then you can set this value to true.
|
||||
* It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing.
|
||||
* It doesn't care about any other DOM element that may be on the page, it literally just sets the margin.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.pageAlignVeritcally = false;
|
||||
/**
|
||||
* Minimum width the canvas should be scaled to (in pixels)
|
||||
* @type {number}
|
||||
*/
|
||||
this.minWidth = null;
|
||||
/**
|
||||
* Maximum width the canvas should be scaled to (in pixels).
|
||||
* If null it will scale to whatever width the browser can handle.
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxWidth = null;
|
||||
/**
|
||||
* Minimum height the canvas should be scaled to (in pixels)
|
||||
* @type {number}
|
||||
*/
|
||||
this.minHeight = null;
|
||||
/**
|
||||
* Maximum height the canvas should be scaled to (in pixels).
|
||||
* If null it will scale to whatever height the browser can handle.
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxHeight = null;
|
||||
/**
|
||||
* Width of the stage after calculation.
|
||||
* @type {number}
|
||||
*/
|
||||
this.width = 0;
|
||||
/**
|
||||
* Height of the stage after calculation.
|
||||
* @type {number}
|
||||
*/
|
||||
this.height = 0;
|
||||
/**
|
||||
* The maximum number of times it will try to resize the canvas to fill the browser (default is 10)
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxIterations = 10;
|
||||
this.game = game;
|
||||
|
||||
this.enterLandscape = new Phaser.Signal();
|
||||
this.enterPortrait = new Phaser.Signal();
|
||||
|
||||
if (window['orientation']) {
|
||||
this.orientation = window['orientation'];
|
||||
} else {
|
||||
if (window.outerWidth > window.outerHeight) {
|
||||
this.orientation = 90;
|
||||
} else {
|
||||
this.orientation = 0;
|
||||
}
|
||||
}
|
||||
|
||||
this.scaleFactor = new Phaser.Vec2(1, 1);
|
||||
this.aspectRatio = 0;
|
||||
this.minWidth = width;
|
||||
this.minHeight = height;
|
||||
this.maxWidth = width;
|
||||
this.maxHeight = height;
|
||||
|
||||
window.addEventListener('orientationchange', function (event) {
|
||||
return _this.checkOrientation(event);
|
||||
}, false);
|
||||
window.addEventListener('resize', function (event) {
|
||||
return _this.checkResize(event);
|
||||
}, false);
|
||||
}
|
||||
Object.defineProperty(StageScaleMode.prototype, "isFullScreen", {
|
||||
get: // Full Screen API calls
|
||||
function () {
|
||||
if (document['fullscreenElement'] === null || document['mozFullScreenElement'] === null || document['webkitFullscreenElement'] === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
StageScaleMode.prototype.startFullScreen = function () {
|
||||
if (this.isFullScreen) {
|
||||
return;
|
||||
}
|
||||
|
||||
var element = this.game.stage.canvas;
|
||||
|
||||
if (element['requestFullScreen']) {
|
||||
element['requestFullScreen']();
|
||||
} else if (element['mozRequestFullScreen']) {
|
||||
element['mozRequestFullScreen']();
|
||||
} else if (element['webkitRequestFullScreen']) {
|
||||
element['webkitRequestFullScreen']();
|
||||
}
|
||||
};
|
||||
|
||||
StageScaleMode.prototype.stopFullScreen = function () {
|
||||
if (document['cancelFullScreen']) {
|
||||
document['cancelFullScreen']();
|
||||
} else if (document['mozCancelFullScreen']) {
|
||||
document['mozCancelFullScreen']();
|
||||
} else if (document['webkitCancelFullScreen']) {
|
||||
document['webkitCancelFullScreen']();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The core update loop, called by Phaser.Stage
|
||||
*/
|
||||
StageScaleMode.prototype.update = function () {
|
||||
if (this.game.stage.scaleMode !== Phaser.StageScaleMode.NO_SCALE && (window.innerWidth !== this.width || window.innerHeight !== this.height)) {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
if (this.forceLandscape || this.forcePortrait) {
|
||||
this.checkOrientationState();
|
||||
}
|
||||
};
|
||||
|
||||
StageScaleMode.prototype.checkOrientationState = function () {
|
||||
if (this.incorrectOrientation) {
|
||||
if ((this.forceLandscape && window.innerWidth > window.innerHeight) || (this.forcePortrait && window.innerHeight > window.innerWidth)) {
|
||||
// Back to normal
|
||||
this.game.paused = false;
|
||||
this.incorrectOrientation = false;
|
||||
this.refresh();
|
||||
}
|
||||
} else {
|
||||
if ((this.forceLandscape && window.innerWidth < window.innerHeight) || (this.forcePortrait && window.innerHeight < window.innerWidth)) {
|
||||
// Show orientation screen
|
||||
this.game.paused = true;
|
||||
this.incorrectOrientation = true;
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Object.defineProperty(StageScaleMode.prototype, "isPortrait", {
|
||||
get: function () {
|
||||
return this.orientation == 0 || this.orientation == 180;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(StageScaleMode.prototype, "isLandscape", {
|
||||
get: function () {
|
||||
return this.orientation === 90 || this.orientation === -90;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
* Handle window.orientationchange events
|
||||
*/
|
||||
StageScaleMode.prototype.checkOrientation = function (event) {
|
||||
this.orientation = window['orientation'];
|
||||
|
||||
if (this.isLandscape) {
|
||||
this.enterLandscape.dispatch(this.orientation, true, false);
|
||||
} else {
|
||||
this.enterPortrait.dispatch(this.orientation, false, true);
|
||||
}
|
||||
|
||||
if (this.game.stage.scaleMode !== StageScaleMode.NO_SCALE) {
|
||||
this.refresh();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle window.resize events
|
||||
*/
|
||||
StageScaleMode.prototype.checkResize = function (event) {
|
||||
if (window.outerWidth > window.outerHeight) {
|
||||
this.orientation = 90;
|
||||
} else {
|
||||
this.orientation = 0;
|
||||
}
|
||||
|
||||
if (this.isLandscape) {
|
||||
this.enterLandscape.dispatch(this.orientation, true, false);
|
||||
} else {
|
||||
this.enterPortrait.dispatch(this.orientation, false, true);
|
||||
}
|
||||
|
||||
if (this.game.stage.scaleMode !== StageScaleMode.NO_SCALE) {
|
||||
this.refresh();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Re-calculate scale mode and update screen size.
|
||||
*/
|
||||
StageScaleMode.prototype.refresh = function () {
|
||||
var _this = this;
|
||||
if (this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false) {
|
||||
document.documentElement['style'].minHeight = '2000px';
|
||||
|
||||
this._startHeight = window.innerHeight;
|
||||
|
||||
if (this.game.device.android && this.game.device.chrome == false) {
|
||||
window.scrollTo(0, 1);
|
||||
} else {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (this._check == null && this.maxIterations > 0) {
|
||||
this._iterations = this.maxIterations;
|
||||
this._check = window.setInterval(function () {
|
||||
return _this.setScreenSize();
|
||||
}, 10);
|
||||
this.setScreenSize();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set screen size automatically based on the scaleMode.
|
||||
*/
|
||||
StageScaleMode.prototype.setScreenSize = function (force) {
|
||||
if (typeof force === "undefined") { force = false; }
|
||||
if (this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false) {
|
||||
if (this.game.device.android && this.game.device.chrome == false) {
|
||||
window.scrollTo(0, 1);
|
||||
} else {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
this._iterations--;
|
||||
|
||||
if (force || window.innerHeight > this._startHeight || this._iterations < 0) {
|
||||
// Set minimum height of content to new window height
|
||||
document.documentElement['style'].minHeight = window.innerHeight + 'px';
|
||||
|
||||
if (this.incorrectOrientation == true) {
|
||||
this.setMaximum();
|
||||
} else if (this.game.stage.scaleMode == StageScaleMode.EXACT_FIT) {
|
||||
this.setExactFit();
|
||||
} else if (this.game.stage.scaleMode == StageScaleMode.SHOW_ALL) {
|
||||
this.setShowAll();
|
||||
}
|
||||
|
||||
this.setSize();
|
||||
|
||||
clearInterval(this._check);
|
||||
|
||||
this._check = null;
|
||||
}
|
||||
};
|
||||
|
||||
StageScaleMode.prototype.setSize = function () {
|
||||
if (this.incorrectOrientation == false) {
|
||||
if (this.maxWidth && this.width > this.maxWidth) {
|
||||
this.width = this.maxWidth;
|
||||
}
|
||||
|
||||
if (this.maxHeight && this.height > this.maxHeight) {
|
||||
this.height = this.maxHeight;
|
||||
}
|
||||
|
||||
if (this.minWidth && this.width < this.minWidth) {
|
||||
this.width = this.minWidth;
|
||||
}
|
||||
|
||||
if (this.minHeight && this.height < this.minHeight) {
|
||||
this.height = this.minHeight;
|
||||
}
|
||||
}
|
||||
|
||||
this.game.stage.canvas.style.width = this.width + 'px';
|
||||
this.game.stage.canvas.style.height = this.height + 'px';
|
||||
|
||||
this.game.input.scale.setTo(this.game.stage.width / this.width, this.game.stage.height / this.height);
|
||||
|
||||
if (this.pageAlignHorizontally) {
|
||||
if (this.width < window.innerWidth && this.incorrectOrientation == false) {
|
||||
this.game.stage.canvas.style.marginLeft = Math.round((window.innerWidth - this.width) / 2) + 'px';
|
||||
} else {
|
||||
this.game.stage.canvas.style.marginLeft = '0px';
|
||||
}
|
||||
}
|
||||
|
||||
if (this.pageAlignVeritcally) {
|
||||
if (this.height < window.innerHeight && this.incorrectOrientation == false) {
|
||||
this.game.stage.canvas.style.marginTop = Math.round((window.innerHeight - this.height) / 2) + 'px';
|
||||
} else {
|
||||
this.game.stage.canvas.style.marginTop = '0px';
|
||||
}
|
||||
}
|
||||
|
||||
this.game.stage.getOffset(this.game.stage.canvas);
|
||||
|
||||
this.aspectRatio = this.width / this.height;
|
||||
this.scaleFactor.x = this.game.stage.width / this.width;
|
||||
this.scaleFactor.y = this.game.stage.height / this.height;
|
||||
};
|
||||
|
||||
StageScaleMode.prototype.setMaximum = function () {
|
||||
this.width = window.innerWidth;
|
||||
this.height = window.innerHeight;
|
||||
};
|
||||
|
||||
StageScaleMode.prototype.setShowAll = function () {
|
||||
var multiplier = Math.min((window.innerHeight / this.game.stage.height), (window.innerWidth / this.game.stage.width));
|
||||
|
||||
this.width = Math.round(this.game.stage.width * multiplier);
|
||||
this.height = Math.round(this.game.stage.height * multiplier);
|
||||
};
|
||||
|
||||
StageScaleMode.prototype.setExactFit = function () {
|
||||
if (this.maxWidth && window.innerWidth > this.maxWidth) {
|
||||
this.width = this.maxWidth;
|
||||
} else {
|
||||
this.width = window.innerWidth;
|
||||
}
|
||||
|
||||
if (this.maxHeight && window.innerHeight > this.maxHeight) {
|
||||
this.height = this.maxHeight;
|
||||
} else {
|
||||
this.height = window.innerHeight;
|
||||
}
|
||||
};
|
||||
StageScaleMode.EXACT_FIT = 0;
|
||||
|
||||
StageScaleMode.NO_SCALE = 1;
|
||||
|
||||
StageScaleMode.SHOW_ALL = 2;
|
||||
return StageScaleMode;
|
||||
})();
|
||||
Phaser.StageScaleMode = StageScaleMode;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,123 +0,0 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/**
|
||||
* Phaser - Tile
|
||||
*
|
||||
* A Tile is a single representation of a tile within a Tilemap
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Tile = (function () {
|
||||
/**
|
||||
* Tile constructor
|
||||
* Create a new <code>Tile</code>.
|
||||
*
|
||||
* @param tilemap {Tilemap} the tilemap this tile belongs to.
|
||||
* @param index {number} The index of this tile type in the core map data.
|
||||
* @param width {number} Width of the tile.
|
||||
* @param height number} Height of the tile.
|
||||
*/
|
||||
function Tile(game, tilemap, index, width, height) {
|
||||
/**
|
||||
* The virtual mass of the tile.
|
||||
* @type {number}
|
||||
*/
|
||||
this.mass = 1.0;
|
||||
/**
|
||||
* Indicating collide with any object on the left.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.collideLeft = false;
|
||||
/**
|
||||
* Indicating collide with any object on the right.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.collideRight = false;
|
||||
/**
|
||||
* Indicating collide with any object on the top.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.collideUp = false;
|
||||
/**
|
||||
* Indicating collide with any object on the bottom.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.collideDown = false;
|
||||
/**
|
||||
* Enable separation at x-axis.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.separateX = true;
|
||||
/**
|
||||
* Enable separation at y-axis.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.separateY = true;
|
||||
this._game = game;
|
||||
this.tilemap = tilemap;
|
||||
this.index = index;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.allowCollisions = Collision.NONE;
|
||||
}
|
||||
Tile.prototype.destroy = /**
|
||||
* Clean up memory.
|
||||
*/
|
||||
function () {
|
||||
this.tilemap = null;
|
||||
};
|
||||
Tile.prototype.setCollision = /**
|
||||
* Set collision configs.
|
||||
* @param collision {number} Bit field of flags. (see Tile.allowCollision)
|
||||
* @param resetCollisions {boolean} Reset collision flags before set.
|
||||
* @param separateX {boolean} Enable seprate at x-axis.
|
||||
* @param separateY {boolean} Enable seprate at y-axis.
|
||||
*/
|
||||
function (collision, resetCollisions, separateX, separateY) {
|
||||
if(resetCollisions) {
|
||||
this.resetCollision();
|
||||
}
|
||||
this.separateX = separateX;
|
||||
this.separateY = separateY;
|
||||
this.allowCollisions = collision;
|
||||
if(collision & Phaser.Collision.ANY) {
|
||||
this.collideLeft = true;
|
||||
this.collideRight = true;
|
||||
this.collideUp = true;
|
||||
this.collideDown = true;
|
||||
return;
|
||||
}
|
||||
if(collision & Phaser.Collision.LEFT || collision & Phaser.Collision.WALL) {
|
||||
this.collideLeft = true;
|
||||
}
|
||||
if(collision & Phaser.Collision.RIGHT || collision & Phaser.Collision.WALL) {
|
||||
this.collideRight = true;
|
||||
}
|
||||
if(collision & Phaser.Collision.UP || collision & Phaser.Collision.CEILING) {
|
||||
this.collideUp = true;
|
||||
}
|
||||
if(collision & Phaser.Collision.DOWN || collision & Phaser.Collision.CEILING) {
|
||||
this.collideDown = true;
|
||||
}
|
||||
};
|
||||
Tile.prototype.resetCollision = /**
|
||||
* Reset collision status flags.
|
||||
*/
|
||||
function () {
|
||||
this.allowCollisions = Phaser.Collision.NONE;
|
||||
this.collideLeft = false;
|
||||
this.collideRight = false;
|
||||
this.collideUp = false;
|
||||
this.collideDown = false;
|
||||
};
|
||||
Tile.prototype.toString = /**
|
||||
* Returns a string representation of this object.
|
||||
* @method toString
|
||||
* @return {string} a string representation of the object.
|
||||
**/
|
||||
function () {
|
||||
return "[{Tiled (index=" + this.index + " collisions=" + this.allowCollisions + " width=" + this.width + " height=" + this.height + ")}]";
|
||||
};
|
||||
return Tile;
|
||||
})();
|
||||
Phaser.Tile = Tile;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,455 +0,0 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/**
|
||||
* Phaser - TilemapLayer
|
||||
*
|
||||
* A Tilemap Layer. Tiled format maps can have multiple overlapping layers.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var TilemapLayer = (function () {
|
||||
/**
|
||||
* TilemapLayer constructor
|
||||
* Create a new <code>TilemapLayer</code>.
|
||||
*
|
||||
* @param game {Phaser.Game} Current game instance.
|
||||
* @param parent {Tilemap} The tilemap that contains this layer.
|
||||
* @param key {string} Asset key for this map.
|
||||
* @param mapFormat {number} Format of this map data, available: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
|
||||
* @param name {string} Name of this layer, so you can get this layer by its name.
|
||||
* @param tileWidth {number} Width of tiles in this map.
|
||||
* @param tileHeight {number} Height of tiles in this map.
|
||||
*/
|
||||
function TilemapLayer(game, parent, key, mapFormat, name, tileWidth, tileHeight) {
|
||||
this._startX = 0;
|
||||
this._startY = 0;
|
||||
this._maxX = 0;
|
||||
this._maxY = 0;
|
||||
this._tx = 0;
|
||||
this._ty = 0;
|
||||
this._dx = 0;
|
||||
this._dy = 0;
|
||||
this._oldCameraX = 0;
|
||||
this._oldCameraY = 0;
|
||||
/**
|
||||
* Opacity of this layer.
|
||||
* @type {number}
|
||||
*/
|
||||
this.alpha = 1;
|
||||
/**
|
||||
* Controls whether update() and draw() are automatically called.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.exists = true;
|
||||
/**
|
||||
* Controls whether draw() are automatically called.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.visible = true;
|
||||
/**
|
||||
* How many tiles in each row.
|
||||
* Read-only variable, do NOT recommend changing after the map is loaded!
|
||||
* @type {number}
|
||||
*/
|
||||
this.widthInTiles = 0;
|
||||
/**
|
||||
* How many tiles in each column.
|
||||
* Read-only variable, do NOT recommend changing after the map is loaded!
|
||||
* @type {number}
|
||||
*/
|
||||
this.heightInTiles = 0;
|
||||
/**
|
||||
* Read-only variable, do NOT recommend changing after the map is loaded!
|
||||
* @type {number}
|
||||
*/
|
||||
this.widthInPixels = 0;
|
||||
/**
|
||||
* Read-only variable, do NOT recommend changing after the map is loaded!
|
||||
* @type {number}
|
||||
*/
|
||||
this.heightInPixels = 0;
|
||||
/**
|
||||
* Distance between REAL tiles to the tileset texture bound.
|
||||
* @type {number}
|
||||
*/
|
||||
this.tileMargin = 0;
|
||||
/**
|
||||
* Distance between every 2 neighbor tile in the tileset texture.
|
||||
* @type {number}
|
||||
*/
|
||||
this.tileSpacing = 0;
|
||||
this._game = game;
|
||||
this._parent = parent;
|
||||
this.name = name;
|
||||
this.mapFormat = mapFormat;
|
||||
this.tileWidth = tileWidth;
|
||||
this.tileHeight = tileHeight;
|
||||
this.boundsInTiles = new Rectangle();
|
||||
//this.scrollFactor = new MicroPoint(1, 1);
|
||||
this.canvas = game.stage.canvas;
|
||||
this.context = game.stage.context;
|
||||
this.mapData = [];
|
||||
this._tempTileBlock = [];
|
||||
this._texture = this._game.cache.getImage(key);
|
||||
}
|
||||
TilemapLayer.prototype.putTile = /**
|
||||
* Set a specific tile with its x and y in tiles.
|
||||
* @param x {number} X position of this tile.
|
||||
* @param y {number} Y position of this tile.
|
||||
* @param index {number} The index of this tile type in the core map data.
|
||||
*/
|
||||
function (x, y, index) {
|
||||
x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
|
||||
y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
|
||||
if(y >= 0 && y < this.mapData.length) {
|
||||
if(x >= 0 && x < this.mapData[y].length) {
|
||||
this.mapData[y][x] = index;
|
||||
}
|
||||
}
|
||||
};
|
||||
TilemapLayer.prototype.swapTile = /**
|
||||
* Swap tiles with 2 kinds of indexes.
|
||||
* @param tileA {number} First tile index.
|
||||
* @param tileB {number} Second tile index.
|
||||
* @param [x] {number} specify a rectangle of tiles to operate. The x position in tiles of rectangle's left-top corner.
|
||||
* @param [y] {number} specify a rectangle of tiles to operate. The y position in tiles of rectangle's left-top corner.
|
||||
* @param [width] {number} specify a rectangle of tiles to operate. The width in tiles.
|
||||
* @param [height] {number} specify a rectangle of tiles to operate. The height in tiles.
|
||||
*/
|
||||
function (tileA, tileB, x, y, width, height) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof width === "undefined") { width = this.widthInTiles; }
|
||||
if (typeof height === "undefined") { height = this.heightInTiles; }
|
||||
this.getTempBlock(x, y, width, height);
|
||||
for(var r = 0; r < this._tempTileBlock.length; r++) {
|
||||
// First sweep marking tileA as needing a new index
|
||||
if(this._tempTileBlock[r].tile.index == tileA) {
|
||||
this._tempTileBlock[r].newIndex = true;
|
||||
}
|
||||
// In the same pass we can swap tileB to tileA
|
||||
if(this._tempTileBlock[r].tile.index == tileB) {
|
||||
this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileA;
|
||||
}
|
||||
}
|
||||
for(var r = 0; r < this._tempTileBlock.length; r++) {
|
||||
// And now swap our newIndex tiles for tileB
|
||||
if(this._tempTileBlock[r].newIndex == true) {
|
||||
this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileB;
|
||||
}
|
||||
}
|
||||
};
|
||||
TilemapLayer.prototype.fillTile = /**
|
||||
* Fill a tile block with a specific tile index.
|
||||
* @param index {number} Index of tiles you want to fill with.
|
||||
* @param [x] {number} x position (in tiles) of block's left-top corner.
|
||||
* @param [y] {number} y position (in tiles) of block's left-top corner.
|
||||
* @param [width] {number} width of block.
|
||||
* @param [height] {number} height of block.
|
||||
*/
|
||||
function (index, x, y, width, height) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof width === "undefined") { width = this.widthInTiles; }
|
||||
if (typeof height === "undefined") { height = this.heightInTiles; }
|
||||
this.getTempBlock(x, y, width, height);
|
||||
for(var r = 0; r < this._tempTileBlock.length; r++) {
|
||||
this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = index;
|
||||
}
|
||||
};
|
||||
TilemapLayer.prototype.randomiseTiles = /**
|
||||
* Set random tiles to a specific tile block.
|
||||
* @param tiles {number[]} Tiles with indexes in this array will be randomly set to the given block.
|
||||
* @param [x] {number} x position (in tiles) of block's left-top corner.
|
||||
* @param [y] {number} y position (in tiles) of block's left-top corner.
|
||||
* @param [width] {number} width of block.
|
||||
* @param [height] {number} height of block.
|
||||
*/
|
||||
function (tiles, x, y, width, height) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof width === "undefined") { width = this.widthInTiles; }
|
||||
if (typeof height === "undefined") { height = this.heightInTiles; }
|
||||
this.getTempBlock(x, y, width, height);
|
||||
for(var r = 0; r < this._tempTileBlock.length; r++) {
|
||||
this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = this._game.math.getRandom(tiles);
|
||||
}
|
||||
};
|
||||
TilemapLayer.prototype.replaceTile = /**
|
||||
* Replace one kind of tiles to another kind.
|
||||
* @param tileA {number} Index of tiles you want to replace.
|
||||
* @param tileB {number} Index of tiles you want to set.
|
||||
* @param [x] {number} x position (in tiles) of block's left-top corner.
|
||||
* @param [y] {number} y position (in tiles) of block's left-top corner.
|
||||
* @param [width] {number} width of block.
|
||||
* @param [height] {number} height of block.
|
||||
*/
|
||||
function (tileA, tileB, x, y, width, height) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof width === "undefined") { width = this.widthInTiles; }
|
||||
if (typeof height === "undefined") { height = this.heightInTiles; }
|
||||
this.getTempBlock(x, y, width, height);
|
||||
for(var r = 0; r < this._tempTileBlock.length; r++) {
|
||||
if(this._tempTileBlock[r].tile.index == tileA) {
|
||||
this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileB;
|
||||
}
|
||||
}
|
||||
};
|
||||
TilemapLayer.prototype.getTileBlock = /**
|
||||
* Get a tile block with specific position and size.(both are in tiles)
|
||||
* @param x {number} X position of block's left-top corner.
|
||||
* @param y {number} Y position of block's left-top corner.
|
||||
* @param width {number} Width of block.
|
||||
* @param height {number} Height of block.
|
||||
*/
|
||||
function (x, y, width, height) {
|
||||
var output = [];
|
||||
this.getTempBlock(x, y, width, height);
|
||||
for(var r = 0; r < this._tempTileBlock.length; r++) {
|
||||
output.push({
|
||||
x: this._tempTileBlock[r].x,
|
||||
y: this._tempTileBlock[r].y,
|
||||
tile: this._tempTileBlock[r].tile
|
||||
});
|
||||
}
|
||||
return output;
|
||||
};
|
||||
TilemapLayer.prototype.getTileFromWorldXY = /**
|
||||
* Get a tile with specific position (in world coordinate). (thus you give a position of a point which is within the tile)
|
||||
* @param x {number} X position of the point in target tile.
|
||||
* @param x {number} Y position of the point in target tile.
|
||||
*/
|
||||
function (x, y) {
|
||||
x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
|
||||
y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
|
||||
return this.getTileIndex(x, y);
|
||||
};
|
||||
TilemapLayer.prototype.getTileOverlaps = /**
|
||||
* Get tiles overlaps the given object.
|
||||
* @param object {GameObject} Tiles you want to get that overlaps this.
|
||||
* @return {array} Array with tiles informations. (Each contains x, y and the tile.)
|
||||
*/
|
||||
function (object) {
|
||||
// If the object is outside of the world coordinates then abort the check (tilemap has to exist within world bounds)
|
||||
if(object.collisionMask.x < 0 || object.collisionMask.x > this.widthInPixels || object.collisionMask.y < 0 || object.collisionMask.bottom > this.heightInPixels) {
|
||||
return;
|
||||
}
|
||||
// What tiles do we need to check against?
|
||||
this._tempTileX = this._game.math.snapToFloor(object.collisionMask.x, this.tileWidth) / this.tileWidth;
|
||||
this._tempTileY = this._game.math.snapToFloor(object.collisionMask.y, this.tileHeight) / this.tileHeight;
|
||||
this._tempTileW = (this._game.math.snapToCeil(object.collisionMask.width, this.tileWidth) + this.tileWidth) / this.tileWidth;
|
||||
this._tempTileH = (this._game.math.snapToCeil(object.collisionMask.height, this.tileHeight) + this.tileHeight) / this.tileHeight;
|
||||
// Loop through the tiles we've got and check overlaps accordingly (the results are stored in this._tempTileBlock)
|
||||
this._tempBlockResults = [];
|
||||
this.getTempBlock(this._tempTileX, this._tempTileY, this._tempTileW, this._tempTileH, true);
|
||||
Phaser.Collision.TILE_OVERLAP = false;
|
||||
for(var r = 0; r < this._tempTileBlock.length; r++) {
|
||||
if(Phaser.Collision.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true) {
|
||||
this._tempBlockResults.push({
|
||||
x: this._tempTileBlock[r].x,
|
||||
y: this._tempTileBlock[r].y,
|
||||
tile: this._tempTileBlock[r].tile
|
||||
});
|
||||
}
|
||||
}
|
||||
return this._tempBlockResults;
|
||||
};
|
||||
TilemapLayer.prototype.getTempBlock = /**
|
||||
* Get a tile block with its position and size. (This method does not return, it'll set result to _tempTileBlock)
|
||||
* @param x {number} X position of block's left-top corner.
|
||||
* @param y {number} Y position of block's left-top corner.
|
||||
* @param width {number} Width of block.
|
||||
* @param height {number} Height of block.
|
||||
* @param collisionOnly {boolean} Whethor or not ONLY return tiles which will collide (its allowCollisions value is not Collision.NONE).
|
||||
*/
|
||||
function (x, y, width, height, collisionOnly) {
|
||||
if (typeof collisionOnly === "undefined") { collisionOnly = false; }
|
||||
if(x < 0) {
|
||||
x = 0;
|
||||
}
|
||||
if(y < 0) {
|
||||
y = 0;
|
||||
}
|
||||
if(width > this.widthInTiles) {
|
||||
width = this.widthInTiles;
|
||||
}
|
||||
if(height > this.heightInTiles) {
|
||||
height = this.heightInTiles;
|
||||
}
|
||||
this._tempTileBlock = [];
|
||||
for(var ty = y; ty < y + height; ty++) {
|
||||
for(var tx = x; tx < x + width; tx++) {
|
||||
if(collisionOnly) {
|
||||
// We only want to consider the tile for checking if you can actually collide with it
|
||||
if(this.mapData[ty] && this.mapData[ty][tx] && this._parent.tiles[this.mapData[ty][tx]].allowCollisions != Phaser.Collision.NONE) {
|
||||
this._tempTileBlock.push({
|
||||
x: tx,
|
||||
y: ty,
|
||||
tile: this._parent.tiles[this.mapData[ty][tx]]
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if(this.mapData[ty] && this.mapData[ty][tx]) {
|
||||
this._tempTileBlock.push({
|
||||
x: tx,
|
||||
y: ty,
|
||||
tile: this._parent.tiles[this.mapData[ty][tx]]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
TilemapLayer.prototype.getTileIndex = /**
|
||||
* Get the tile index of specific position (in tiles).
|
||||
* @param x {number} X position of the tile.
|
||||
* @param y {number} Y position of the tile.
|
||||
* @return {number} Index of the tile at that position. Return null if there isn't a tile there.
|
||||
*/
|
||||
function (x, y) {
|
||||
if(y >= 0 && y < this.mapData.length) {
|
||||
if(x >= 0 && x < this.mapData[y].length) {
|
||||
return this.mapData[y][x];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
TilemapLayer.prototype.addColumn = /**
|
||||
* Add a column of tiles into the layer.
|
||||
* @param column {string[]/number[]} An array of tile indexes to be added.
|
||||
*/
|
||||
function (column) {
|
||||
var data = [];
|
||||
for(var c = 0; c < column.length; c++) {
|
||||
data[c] = parseInt(column[c]);
|
||||
}
|
||||
if(this.widthInTiles == 0) {
|
||||
this.widthInTiles = data.length;
|
||||
this.widthInPixels = this.widthInTiles * this.tileWidth;
|
||||
}
|
||||
this.mapData.push(data);
|
||||
this.heightInTiles++;
|
||||
this.heightInPixels += this.tileHeight;
|
||||
};
|
||||
TilemapLayer.prototype.updateBounds = /**
|
||||
* Update boundsInTiles with widthInTiles and heightInTiles.
|
||||
*/
|
||||
function () {
|
||||
this.boundsInTiles.setTo(0, 0, this.widthInTiles, this.heightInTiles);
|
||||
};
|
||||
TilemapLayer.prototype.parseTileOffsets = /**
|
||||
* Parse tile offsets from map data.
|
||||
* @return {number} length of _tileOffsets array.
|
||||
*/
|
||||
function () {
|
||||
this._tileOffsets = [];
|
||||
var i = 0;
|
||||
if(this.mapFormat == Phaser.Tilemap.FORMAT_TILED_JSON) {
|
||||
// For some reason Tiled counts from 1 not 0
|
||||
this._tileOffsets[0] = null;
|
||||
i = 1;
|
||||
}
|
||||
for(var ty = this.tileMargin; ty < this._texture.height; ty += (this.tileHeight + this.tileSpacing)) {
|
||||
for(var tx = this.tileMargin; tx < this._texture.width; tx += (this.tileWidth + this.tileSpacing)) {
|
||||
this._tileOffsets[i] = {
|
||||
x: tx,
|
||||
y: ty
|
||||
};
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return this._tileOffsets.length;
|
||||
};
|
||||
TilemapLayer.prototype.renderDebugInfo = function (x, y, color) {
|
||||
if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillText('TilemapLayer: ' + this.name, x, y);
|
||||
this.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14);
|
||||
this.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28);
|
||||
this.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42);
|
||||
};
|
||||
TilemapLayer.prototype.render = /**
|
||||
* Render this layer to a specific camera with offset to camera.
|
||||
* @param camera {Camera} The camera the layer is going to be rendered.
|
||||
* @param dx {number} X offset to the camera.
|
||||
* @param dy {number} Y offset to the camera.
|
||||
* @return {boolean} Return false if layer is invisible or has a too low opacity(will stop rendering), return true if succeed.
|
||||
*/
|
||||
function (camera, dx, dy) {
|
||||
if(this.visible === false || this.alpha < 0.1) {
|
||||
return false;
|
||||
}
|
||||
// Work out how many tiles we can fit into our camera and round it up for the edges
|
||||
this._maxX = this._game.math.ceil(camera.width / this.tileWidth) + 1;
|
||||
this._maxY = this._game.math.ceil(camera.height / this.tileHeight) + 1;
|
||||
// And now work out where in the tilemap the camera actually is
|
||||
this._startX = this._game.math.floor(camera.worldView.x / this.tileWidth);
|
||||
this._startY = this._game.math.floor(camera.worldView.y / this.tileHeight);
|
||||
// Tilemap bounds check
|
||||
if(this._startX < 0) {
|
||||
this._startX = 0;
|
||||
}
|
||||
if(this._startY < 0) {
|
||||
this._startY = 0;
|
||||
}
|
||||
if(this._maxX > this.widthInTiles) {
|
||||
this._maxX = this.widthInTiles;
|
||||
}
|
||||
if(this._maxY > this.heightInTiles) {
|
||||
this._maxY = this.heightInTiles;
|
||||
}
|
||||
if(this._startX + this._maxX > this.widthInTiles) {
|
||||
this._startX = this.widthInTiles - this._maxX;
|
||||
}
|
||||
if(this._startY + this._maxY > this.heightInTiles) {
|
||||
this._startY = this.heightInTiles - this._maxY;
|
||||
}
|
||||
// Finally get the offset to avoid the blocky movement
|
||||
this._dx = dx;
|
||||
this._dy = dy;
|
||||
this._dx += -(camera.worldView.x - (this._startX * this.tileWidth));
|
||||
this._dy += -(camera.worldView.y - (this._startY * this.tileHeight));
|
||||
this._tx = this._dx;
|
||||
this._ty = this._dy;
|
||||
// Apply camera difference
|
||||
/*
|
||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
||||
{
|
||||
this._dx -= (camera.worldView.x * this.scrollFactor.x);
|
||||
this._dy -= (camera.worldView.y * this.scrollFactor.y);
|
||||
}
|
||||
*/
|
||||
// Alpha
|
||||
if(this.alpha !== 1) {
|
||||
var globalAlpha = this.context.globalAlpha;
|
||||
this.context.globalAlpha = this.alpha;
|
||||
}
|
||||
for(var row = this._startY; row < this._startY + this._maxY; row++) {
|
||||
this._columnData = this.mapData[row];
|
||||
for(var tile = this._startX; tile < this._startX + this._maxX; tile++) {
|
||||
if(this._tileOffsets[this._columnData[tile]]) {
|
||||
this.context.drawImage(this._texture, // Source Image
|
||||
this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image)
|
||||
this._tileOffsets[this._columnData[tile]].y, // Source Y
|
||||
this.tileWidth, // Source Width
|
||||
this.tileHeight, // Source Height
|
||||
this._tx, // Destination X (where on the canvas it'll be drawn)
|
||||
this._ty, // Destination Y
|
||||
this.tileWidth, // Destination Width (always same as Source Width unless scaled)
|
||||
this.tileHeight);
|
||||
// Destination Height (always same as Source Height unless scaled)
|
||||
}
|
||||
this._tx += this.tileWidth;
|
||||
}
|
||||
this._tx = this._dx;
|
||||
this._ty += this.tileHeight;
|
||||
}
|
||||
if(globalAlpha > -1) {
|
||||
this.context.globalAlpha = globalAlpha;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
return TilemapLayer;
|
||||
})();
|
||||
Phaser.TilemapLayer = TilemapLayer;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,173 +0,0 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="easing/Back.ts" />
|
||||
/// <reference path="easing/Bounce.ts" />
|
||||
/// <reference path="easing/Circular.ts" />
|
||||
/// <reference path="easing/Cubic.ts" />
|
||||
/// <reference path="easing/Elastic.ts" />
|
||||
/// <reference path="easing/Exponential.ts" />
|
||||
/// <reference path="easing/Linear.ts" />
|
||||
/// <reference path="easing/Quadratic.ts" />
|
||||
/// <reference path="easing/Quartic.ts" />
|
||||
/// <reference path="easing/Quintic.ts" />
|
||||
/// <reference path="easing/Sinusoidal.ts" />
|
||||
/**
|
||||
* Phaser - Tween
|
||||
*
|
||||
* Based heavily on tween.js by sole (https://github.com/sole/tween.js) converted to TypeScript and integrated into Phaser
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Tween = (function () {
|
||||
function Tween(object, game) {
|
||||
this._object = null;
|
||||
this._pausedTime = 0;
|
||||
this._valuesStart = {
|
||||
};
|
||||
this._valuesEnd = {
|
||||
};
|
||||
this._duration = 1000;
|
||||
this._delayTime = 0;
|
||||
this._startTime = null;
|
||||
this._chainedTweens = [];
|
||||
this._object = object;
|
||||
this._game = game;
|
||||
this._manager = this._game.tweens;
|
||||
this._interpolationFunction = this._game.math.linearInterpolation;
|
||||
this._easingFunction = Phaser.Easing.Linear.None;
|
||||
this._chainedTweens = [];
|
||||
this.onStart = new Phaser.Signal();
|
||||
this.onUpdate = new Phaser.Signal();
|
||||
this.onComplete = new Phaser.Signal();
|
||||
}
|
||||
Tween.prototype.to = function (properties, duration, ease, autoStart) {
|
||||
if (typeof duration === "undefined") { duration = 1000; }
|
||||
if (typeof ease === "undefined") { ease = null; }
|
||||
if (typeof autoStart === "undefined") { autoStart = false; }
|
||||
this._duration = duration;
|
||||
// If properties isn't an object this will fail, sanity check it here somehow?
|
||||
this._valuesEnd = properties;
|
||||
if(ease !== null) {
|
||||
this._easingFunction = ease;
|
||||
}
|
||||
if(autoStart === true) {
|
||||
return this.start();
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
Tween.prototype.start = function () {
|
||||
if(this._game === null || this._object === null) {
|
||||
return;
|
||||
}
|
||||
this._manager.add(this);
|
||||
this.onStart.dispatch(this._object);
|
||||
this._startTime = this._game.time.now + this._delayTime;
|
||||
for(var property in this._valuesEnd) {
|
||||
// This prevents the interpolation of null values or of non-existing properties
|
||||
if(this._object[property] === null || !(property in this._object)) {
|
||||
throw Error('Phaser.Tween interpolation of null value of non-existing property');
|
||||
continue;
|
||||
}
|
||||
// check if an Array was provided as property value
|
||||
if(this._valuesEnd[property] instanceof Array) {
|
||||
if(this._valuesEnd[property].length === 0) {
|
||||
continue;
|
||||
}
|
||||
// create a local copy of the Array with the start value at the front
|
||||
this._valuesEnd[property] = [
|
||||
this._object[property]
|
||||
].concat(this._valuesEnd[property]);
|
||||
}
|
||||
this._valuesStart[property] = this._object[property];
|
||||
}
|
||||
return this;
|
||||
};
|
||||
Tween.prototype.stop = function () {
|
||||
if(this._manager !== null) {
|
||||
this._manager.remove(this);
|
||||
}
|
||||
this.onComplete.dispose();
|
||||
return this;
|
||||
};
|
||||
Object.defineProperty(Tween.prototype, "parent", {
|
||||
set: function (value) {
|
||||
this._game = value;
|
||||
this._manager = this._game.tweens;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Tween.prototype, "delay", {
|
||||
get: function () {
|
||||
return this._delayTime;
|
||||
},
|
||||
set: function (amount) {
|
||||
this._delayTime = amount;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Tween.prototype, "easing", {
|
||||
get: function () {
|
||||
return this._easingFunction;
|
||||
},
|
||||
set: function (easing) {
|
||||
this._easingFunction = easing;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Tween.prototype, "interpolation", {
|
||||
get: function () {
|
||||
return this._interpolationFunction;
|
||||
},
|
||||
set: function (interpolation) {
|
||||
this._interpolationFunction = interpolation;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Tween.prototype.chain = function (tween) {
|
||||
this._chainedTweens.push(tween);
|
||||
return this;
|
||||
};
|
||||
Tween.prototype.update = function (time) {
|
||||
if(this._game.paused == true) {
|
||||
if(this._pausedTime == 0) {
|
||||
this._pausedTime = time;
|
||||
}
|
||||
} else {
|
||||
// Ok we aren't paused, but was there some time gained?
|
||||
if(this._pausedTime > 0) {
|
||||
this._startTime += (time - this._pausedTime);
|
||||
this._pausedTime = 0;
|
||||
}
|
||||
}
|
||||
if(time < this._startTime) {
|
||||
return true;
|
||||
}
|
||||
var elapsed = (time - this._startTime) / this._duration;
|
||||
elapsed = elapsed > 1 ? 1 : elapsed;
|
||||
var value = this._easingFunction(elapsed);
|
||||
for(var property in this._valuesStart) {
|
||||
// Add checks for object, array, numeric up front
|
||||
if(this._valuesEnd[property] instanceof Array) {
|
||||
this._object[property] = this._interpolationFunction(this._valuesEnd[property], value);
|
||||
} else {
|
||||
this._object[property] = this._valuesStart[property] + (this._valuesEnd[property] - this._valuesStart[property]) * value;
|
||||
}
|
||||
}
|
||||
this.onUpdate.dispatch(this._object, value);
|
||||
if(elapsed == 1) {
|
||||
this.onComplete.dispatch(this._object);
|
||||
for(var i = 0; i < this._chainedTweens.length; i++) {
|
||||
this._chainedTweens[i].start();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
return Tween;
|
||||
})();
|
||||
Phaser.Tween = Tween;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,107 +0,0 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Animation
|
||||
*
|
||||
* An Animation is a single animation. It is created by the AnimationManager and belongs to Sprite objects.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Animation = (function () {
|
||||
function Animation(game, parent, frameData, name, frames, delay, looped) {
|
||||
this._game = game;
|
||||
this._parent = parent;
|
||||
this._frames = frames;
|
||||
this._frameData = frameData;
|
||||
this.name = name;
|
||||
this.delay = 1000 / delay;
|
||||
this.looped = looped;
|
||||
this.isFinished = false;
|
||||
this.isPlaying = false;
|
||||
this._frameIndex = 0;
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
}
|
||||
Object.defineProperty(Animation.prototype, "frameTotal", {
|
||||
get: function () {
|
||||
return this._frames.length;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Animation.prototype, "frame", {
|
||||
get: function () {
|
||||
return this._frameIndex;
|
||||
},
|
||||
set: function (value) {
|
||||
this.currentFrame = this._frameData.getFrame(value);
|
||||
if(this.currentFrame !== null) {
|
||||
this._parent.bounds.width = this.currentFrame.width;
|
||||
this._parent.bounds.height = this.currentFrame.height;
|
||||
this._frameIndex = value;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Animation.prototype.play = function (frameRate, loop) {
|
||||
if (typeof frameRate === "undefined") { frameRate = null; }
|
||||
if(frameRate !== null) {
|
||||
this.delay = 1000 / frameRate;
|
||||
}
|
||||
if(loop !== undefined) {
|
||||
this.looped = loop;
|
||||
}
|
||||
this.isPlaying = true;
|
||||
this.isFinished = false;
|
||||
this._timeLastFrame = this._game.time.now;
|
||||
this._timeNextFrame = this._game.time.now + this.delay;
|
||||
this._frameIndex = 0;
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
};
|
||||
Animation.prototype.restart = function () {
|
||||
this.isPlaying = true;
|
||||
this.isFinished = false;
|
||||
this._timeLastFrame = this._game.time.now;
|
||||
this._timeNextFrame = this._game.time.now + this.delay;
|
||||
this._frameIndex = 0;
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
};
|
||||
Animation.prototype.stop = function () {
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
};
|
||||
Animation.prototype.update = function () {
|
||||
if(this.isPlaying == true && this._game.time.now >= this._timeNextFrame) {
|
||||
this._frameIndex++;
|
||||
if(this._frameIndex == this._frames.length) {
|
||||
if(this.looped) {
|
||||
this._frameIndex = 0;
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
} else {
|
||||
this.onComplete();
|
||||
}
|
||||
} else {
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
}
|
||||
this._timeLastFrame = this._game.time.now;
|
||||
this._timeNextFrame = this._game.time.now + this.delay;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Animation.prototype.destroy = function () {
|
||||
this._game = null;
|
||||
this._parent = null;
|
||||
this._frames = null;
|
||||
this._frameData = null;
|
||||
this.currentFrame = null;
|
||||
this.isPlaying = false;
|
||||
};
|
||||
Animation.prototype.onComplete = function () {
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
// callback
|
||||
};
|
||||
return Animation;
|
||||
})();
|
||||
Phaser.Animation = Animation;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,58 +0,0 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - AnimationLoader
|
||||
*
|
||||
* Responsible for parsing sprite sheet and JSON data into the internal FrameData format that Phaser uses for animations.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var AnimationLoader = (function () {
|
||||
function AnimationLoader() { }
|
||||
AnimationLoader.parseSpriteSheet = function parseSpriteSheet(game, key, frameWidth, frameHeight, frameMax) {
|
||||
// How big is our image?
|
||||
var img = game.cache.getImage(key);
|
||||
if(img == null) {
|
||||
return null;
|
||||
}
|
||||
var width = img.width;
|
||||
var height = img.height;
|
||||
var row = Math.round(width / frameWidth);
|
||||
var column = Math.round(height / frameHeight);
|
||||
var total = row * column;
|
||||
if(frameMax !== -1) {
|
||||
total = frameMax;
|
||||
}
|
||||
// Zero or smaller than frame sizes?
|
||||
if(width == 0 || height == 0 || width < frameWidth || height < frameHeight || total === 0) {
|
||||
return null;
|
||||
}
|
||||
// Let's create some frames then
|
||||
var data = new Phaser.FrameData();
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
for(var i = 0; i < total; i++) {
|
||||
data.addFrame(new Phaser.Frame(x, y, frameWidth, frameHeight, ''));
|
||||
x += frameWidth;
|
||||
if(x === width) {
|
||||
x = 0;
|
||||
y += frameHeight;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
};
|
||||
AnimationLoader.parseJSONData = function parseJSONData(game, json) {
|
||||
// Let's create some frames then
|
||||
var data = new Phaser.FrameData();
|
||||
// By this stage frames is a fully parsed array
|
||||
var frames = json;
|
||||
var newFrame;
|
||||
for(var i = 0; i < frames.length; i++) {
|
||||
newFrame = data.addFrame(new Phaser.Frame(frames[i].frame.x, frames[i].frame.y, frames[i].frame.w, frames[i].frame.h, frames[i].filename));
|
||||
newFrame.setTrim(frames[i].trimmed, frames[i].sourceSize.w, frames[i].sourceSize.h, frames[i].spriteSourceSize.x, frames[i].spriteSourceSize.y, frames[i].spriteSourceSize.w, frames[i].spriteSourceSize.h);
|
||||
}
|
||||
return data;
|
||||
};
|
||||
return AnimationLoader;
|
||||
})();
|
||||
Phaser.AnimationLoader = AnimationLoader;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,40 +0,0 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Frame
|
||||
*
|
||||
* A Frame is a single frame of an animation and is part of a FrameData collection.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Frame = (function () {
|
||||
function Frame(x, y, width, height, name) {
|
||||
// Useful for Texture Atlas files (is set to the filename value)
|
||||
this.name = '';
|
||||
// Rotated? (not yet implemented)
|
||||
this.rotated = false;
|
||||
// Either cw or ccw, rotation is always 90 degrees
|
||||
this.rotationDirection = 'cw';
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.name = name;
|
||||
this.rotated = false;
|
||||
this.trimmed = false;
|
||||
}
|
||||
Frame.prototype.setRotation = function (rotated, rotationDirection) {
|
||||
// Not yet supported
|
||||
};
|
||||
Frame.prototype.setTrim = function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) {
|
||||
this.trimmed = trimmed;
|
||||
this.sourceSizeW = actualWidth;
|
||||
this.sourceSizeH = actualHeight;
|
||||
this.spriteSourceSizeX = destX;
|
||||
this.spriteSourceSizeY = destY;
|
||||
this.spriteSourceSizeW = destWidth;
|
||||
this.spriteSourceSizeH = destHeight;
|
||||
};
|
||||
return Frame;
|
||||
})();
|
||||
Phaser.Frame = Frame;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,84 +0,0 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - FrameData
|
||||
*
|
||||
* FrameData is a container for Frame objects, the internal representation of animation data in Phaser.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var FrameData = (function () {
|
||||
function FrameData() {
|
||||
this._frames = [];
|
||||
this._frameNames = [];
|
||||
}
|
||||
Object.defineProperty(FrameData.prototype, "total", {
|
||||
get: function () {
|
||||
return this._frames.length;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
FrameData.prototype.addFrame = function (frame) {
|
||||
frame.index = this._frames.length;
|
||||
this._frames.push(frame);
|
||||
if(frame.name !== '') {
|
||||
this._frameNames[frame.name] = frame.index;
|
||||
}
|
||||
return frame;
|
||||
};
|
||||
FrameData.prototype.getFrame = function (index) {
|
||||
if(this._frames[index]) {
|
||||
return this._frames[index];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
FrameData.prototype.getFrameByName = function (name) {
|
||||
if(this._frameNames[name] >= 0) {
|
||||
return this._frames[this._frameNames[name]];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
FrameData.prototype.checkFrameName = function (name) {
|
||||
if(this._frameNames[name] >= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
FrameData.prototype.getFrameRange = function (start, end, output) {
|
||||
if (typeof output === "undefined") { output = []; }
|
||||
for(var i = start; i <= end; i++) {
|
||||
output.push(this._frames[i]);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
FrameData.prototype.getFrameIndexes = function (output) {
|
||||
if (typeof output === "undefined") { output = []; }
|
||||
output.length = 0;
|
||||
for(var i = 0; i < this._frames.length; i++) {
|
||||
output.push(i);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
FrameData.prototype.getFrameIndexesByName = function (input) {
|
||||
var output = [];
|
||||
for(var i = 0; i < input.length; i++) {
|
||||
if(this.getFrameByName(input[i])) {
|
||||
output.push(this.getFrameByName(input[i]).index);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
};
|
||||
FrameData.prototype.getAllFrames = function () {
|
||||
return this._frames;
|
||||
};
|
||||
FrameData.prototype.getFrames = function (range) {
|
||||
var output = [];
|
||||
for(var i = 0; i < range.length; i++) {
|
||||
output.push(this._frames[i]);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
return FrameData;
|
||||
})();
|
||||
Phaser.FrameData = FrameData;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,32 +0,0 @@
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Easing - Back
|
||||
*
|
||||
* For use with Phaser.Tween
|
||||
*/
|
||||
(function (Easing) {
|
||||
var Back = (function () {
|
||||
function Back() { }
|
||||
Back.In = function In(k) {
|
||||
var s = 1.70158;
|
||||
return k * k * ((s + 1) * k - s);
|
||||
};
|
||||
Back.Out = function Out(k) {
|
||||
var s = 1.70158;
|
||||
return --k * k * ((s + 1) * k + s) + 1;
|
||||
};
|
||||
Back.InOut = function InOut(k) {
|
||||
var s = 1.70158 * 1.525;
|
||||
if((k *= 2) < 1) {
|
||||
return 0.5 * (k * k * ((s + 1) * k - s));
|
||||
}
|
||||
return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
|
||||
};
|
||||
return Back;
|
||||
})();
|
||||
Easing.Back = Back;
|
||||
})(Phaser.Easing || (Phaser.Easing = {}));
|
||||
var Easing = Phaser.Easing;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,37 +0,0 @@
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Easing - Bounce
|
||||
*
|
||||
* For use with Phaser.Tween
|
||||
*/
|
||||
(function (Easing) {
|
||||
var Bounce = (function () {
|
||||
function Bounce() { }
|
||||
Bounce.In = function In(k) {
|
||||
return 1 - Phaser.Easing.Bounce.Out(1 - k);
|
||||
};
|
||||
Bounce.Out = function Out(k) {
|
||||
if(k < (1 / 2.75)) {
|
||||
return 7.5625 * k * k;
|
||||
} else if(k < (2 / 2.75)) {
|
||||
return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
|
||||
} else if(k < (2.5 / 2.75)) {
|
||||
return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
|
||||
} else {
|
||||
return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
|
||||
}
|
||||
};
|
||||
Bounce.InOut = function InOut(k) {
|
||||
if(k < 0.5) {
|
||||
return Phaser.Easing.Bounce.In(k * 2) * 0.5;
|
||||
}
|
||||
return Phaser.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5;
|
||||
};
|
||||
return Bounce;
|
||||
})();
|
||||
Easing.Bounce = Bounce;
|
||||
})(Phaser.Easing || (Phaser.Easing = {}));
|
||||
var Easing = Phaser.Easing;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,29 +0,0 @@
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Easing - Circular
|
||||
*
|
||||
* For use with Phaser.Tween
|
||||
*/
|
||||
(function (Easing) {
|
||||
var Circular = (function () {
|
||||
function Circular() { }
|
||||
Circular.In = function In(k) {
|
||||
return 1 - Math.sqrt(1 - k * k);
|
||||
};
|
||||
Circular.Out = function Out(k) {
|
||||
return Math.sqrt(1 - (--k * k));
|
||||
};
|
||||
Circular.InOut = function InOut(k) {
|
||||
if((k *= 2) < 1) {
|
||||
return -0.5 * (Math.sqrt(1 - k * k) - 1);
|
||||
}
|
||||
return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
|
||||
};
|
||||
return Circular;
|
||||
})();
|
||||
Easing.Circular = Circular;
|
||||
})(Phaser.Easing || (Phaser.Easing = {}));
|
||||
var Easing = Phaser.Easing;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,29 +0,0 @@
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Easing - Cubic
|
||||
*
|
||||
* For use with Phaser.Tween
|
||||
*/
|
||||
(function (Easing) {
|
||||
var Cubic = (function () {
|
||||
function Cubic() { }
|
||||
Cubic.In = function In(k) {
|
||||
return k * k * k;
|
||||
};
|
||||
Cubic.Out = function Out(k) {
|
||||
return --k * k * k + 1;
|
||||
};
|
||||
Cubic.InOut = function InOut(k) {
|
||||
if((k *= 2) < 1) {
|
||||
return 0.5 * k * k * k;
|
||||
}
|
||||
return 0.5 * ((k -= 2) * k * k + 2);
|
||||
};
|
||||
return Cubic;
|
||||
})();
|
||||
Easing.Cubic = Cubic;
|
||||
})(Phaser.Easing || (Phaser.Easing = {}));
|
||||
var Easing = Phaser.Easing;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,68 +0,0 @@
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Easing - Elastic
|
||||
*
|
||||
* For use with Phaser.Tween
|
||||
*/
|
||||
(function (Easing) {
|
||||
var Elastic = (function () {
|
||||
function Elastic() { }
|
||||
Elastic.In = function In(k) {
|
||||
var s, a = 0.1, p = 0.4;
|
||||
if(k === 0) {
|
||||
return 0;
|
||||
}
|
||||
if(k === 1) {
|
||||
return 1;
|
||||
}
|
||||
if(!a || a < 1) {
|
||||
a = 1;
|
||||
s = p / 4;
|
||||
} else {
|
||||
s = p * Math.asin(1 / a) / (2 * Math.PI);
|
||||
}
|
||||
return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
|
||||
};
|
||||
Elastic.Out = function Out(k) {
|
||||
var s, a = 0.1, p = 0.4;
|
||||
if(k === 0) {
|
||||
return 0;
|
||||
}
|
||||
if(k === 1) {
|
||||
return 1;
|
||||
}
|
||||
if(!a || a < 1) {
|
||||
a = 1;
|
||||
s = p / 4;
|
||||
} else {
|
||||
s = p * Math.asin(1 / a) / (2 * Math.PI);
|
||||
}
|
||||
return (a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
|
||||
};
|
||||
Elastic.InOut = function InOut(k) {
|
||||
var s, a = 0.1, p = 0.4;
|
||||
if(k === 0) {
|
||||
return 0;
|
||||
}
|
||||
if(k === 1) {
|
||||
return 1;
|
||||
}
|
||||
if(!a || a < 1) {
|
||||
a = 1;
|
||||
s = p / 4;
|
||||
} else {
|
||||
s = p * Math.asin(1 / a) / (2 * Math.PI);
|
||||
}
|
||||
if((k *= 2) < 1) {
|
||||
return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
|
||||
}
|
||||
return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
|
||||
};
|
||||
return Elastic;
|
||||
})();
|
||||
Easing.Elastic = Elastic;
|
||||
})(Phaser.Easing || (Phaser.Easing = {}));
|
||||
var Easing = Phaser.Easing;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,35 +0,0 @@
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Easing - Exponential
|
||||
*
|
||||
* For use with Phaser.Tween
|
||||
*/
|
||||
(function (Easing) {
|
||||
var Exponential = (function () {
|
||||
function Exponential() { }
|
||||
Exponential.In = function In(k) {
|
||||
return k === 0 ? 0 : Math.pow(1024, k - 1);
|
||||
};
|
||||
Exponential.Out = function Out(k) {
|
||||
return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
|
||||
};
|
||||
Exponential.InOut = function InOut(k) {
|
||||
if(k === 0) {
|
||||
return 0;
|
||||
}
|
||||
if(k === 1) {
|
||||
return 1;
|
||||
}
|
||||
if((k *= 2) < 1) {
|
||||
return 0.5 * Math.pow(1024, k - 1);
|
||||
}
|
||||
return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
|
||||
};
|
||||
return Exponential;
|
||||
})();
|
||||
Easing.Exponential = Exponential;
|
||||
})(Phaser.Easing || (Phaser.Easing = {}));
|
||||
var Easing = Phaser.Easing;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,20 +0,0 @@
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Easing - Linear
|
||||
*
|
||||
* For use with Phaser.Tween
|
||||
*/
|
||||
(function (Easing) {
|
||||
var Linear = (function () {
|
||||
function Linear() { }
|
||||
Linear.None = function None(k) {
|
||||
return k;
|
||||
};
|
||||
return Linear;
|
||||
})();
|
||||
Easing.Linear = Linear;
|
||||
})(Phaser.Easing || (Phaser.Easing = {}));
|
||||
var Easing = Phaser.Easing;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,29 +0,0 @@
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Easing - Quadratic
|
||||
*
|
||||
* For use with Phaser.Tween
|
||||
*/
|
||||
(function (Easing) {
|
||||
var Quadratic = (function () {
|
||||
function Quadratic() { }
|
||||
Quadratic.In = function In(k) {
|
||||
return k * k;
|
||||
};
|
||||
Quadratic.Out = function Out(k) {
|
||||
return k * (2 - k);
|
||||
};
|
||||
Quadratic.InOut = function InOut(k) {
|
||||
if((k *= 2) < 1) {
|
||||
return 0.5 * k * k;
|
||||
}
|
||||
return -0.5 * (--k * (k - 2) - 1);
|
||||
};
|
||||
return Quadratic;
|
||||
})();
|
||||
Easing.Quadratic = Quadratic;
|
||||
})(Phaser.Easing || (Phaser.Easing = {}));
|
||||
var Easing = Phaser.Easing;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,29 +0,0 @@
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Easing - Quartic
|
||||
*
|
||||
* For use with Phaser.Tween
|
||||
*/
|
||||
(function (Easing) {
|
||||
var Quartic = (function () {
|
||||
function Quartic() { }
|
||||
Quartic.In = function In(k) {
|
||||
return k * k * k * k;
|
||||
};
|
||||
Quartic.Out = function Out(k) {
|
||||
return 1 - (--k * k * k * k);
|
||||
};
|
||||
Quartic.InOut = function InOut(k) {
|
||||
if((k *= 2) < 1) {
|
||||
return 0.5 * k * k * k * k;
|
||||
}
|
||||
return -0.5 * ((k -= 2) * k * k * k - 2);
|
||||
};
|
||||
return Quartic;
|
||||
})();
|
||||
Easing.Quartic = Quartic;
|
||||
})(Phaser.Easing || (Phaser.Easing = {}));
|
||||
var Easing = Phaser.Easing;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,29 +0,0 @@
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Easing - Quintic
|
||||
*
|
||||
* For use with Phaser.Tween
|
||||
*/
|
||||
(function (Easing) {
|
||||
var Quintic = (function () {
|
||||
function Quintic() { }
|
||||
Quintic.In = function In(k) {
|
||||
return k * k * k * k * k;
|
||||
};
|
||||
Quintic.Out = function Out(k) {
|
||||
return --k * k * k * k * k + 1;
|
||||
};
|
||||
Quintic.InOut = function InOut(k) {
|
||||
if((k *= 2) < 1) {
|
||||
return 0.5 * k * k * k * k * k;
|
||||
}
|
||||
return 0.5 * ((k -= 2) * k * k * k * k + 2);
|
||||
};
|
||||
return Quintic;
|
||||
})();
|
||||
Easing.Quintic = Quintic;
|
||||
})(Phaser.Easing || (Phaser.Easing = {}));
|
||||
var Easing = Phaser.Easing;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,26 +0,0 @@
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Easing - Sinusoidal
|
||||
*
|
||||
* For use with Phaser.Tween
|
||||
*/
|
||||
(function (Easing) {
|
||||
var Sinusoidal = (function () {
|
||||
function Sinusoidal() { }
|
||||
Sinusoidal.In = function In(k) {
|
||||
return 1 - Math.cos(k * Math.PI / 2);
|
||||
};
|
||||
Sinusoidal.Out = function Out(k) {
|
||||
return Math.sin(k * Math.PI / 2);
|
||||
};
|
||||
Sinusoidal.InOut = function InOut(k) {
|
||||
return 0.5 * (1 - Math.cos(Math.PI * k));
|
||||
};
|
||||
return Sinusoidal;
|
||||
})();
|
||||
Easing.Sinusoidal = Sinusoidal;
|
||||
})(Phaser.Easing || (Phaser.Easing = {}));
|
||||
var Easing = Phaser.Easing;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,231 +0,0 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Finger
|
||||
*
|
||||
* A Finger object is used by the Touch manager and represents a single finger on the touch screen.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Finger = (function () {
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Phaser.Game} game.
|
||||
* @return {Phaser.Finger} This object.
|
||||
*/
|
||||
function Finger(game) {
|
||||
/**
|
||||
*
|
||||
* @property point
|
||||
* @type Point
|
||||
**/
|
||||
this.point = null;
|
||||
/**
|
||||
*
|
||||
* @property circle
|
||||
* @type Circle
|
||||
**/
|
||||
this.circle = null;
|
||||
/**
|
||||
*
|
||||
* @property withinGame
|
||||
* @type Boolean
|
||||
*/
|
||||
this.withinGame = false;
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
||||
* @property clientX
|
||||
* @type Number
|
||||
*/
|
||||
this.clientX = -1;
|
||||
//
|
||||
/**
|
||||
* The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
||||
* @property clientY
|
||||
* @type Number
|
||||
*/
|
||||
this.clientY = -1;
|
||||
//
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset
|
||||
* @property pageX
|
||||
* @type Number
|
||||
*/
|
||||
this.pageX = -1;
|
||||
/**
|
||||
* The vertical coordinate of point relative to the viewport in pixels, including any scroll offset
|
||||
* @property pageY
|
||||
* @type Number
|
||||
*/
|
||||
this.pageY = -1;
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the screen in pixels
|
||||
* @property screenX
|
||||
* @type Number
|
||||
*/
|
||||
this.screenX = -1;
|
||||
/**
|
||||
* The vertical coordinate of point relative to the screen in pixels
|
||||
* @property screenY
|
||||
* @type Number
|
||||
*/
|
||||
this.screenY = -1;
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the game element
|
||||
* @property x
|
||||
* @type Number
|
||||
*/
|
||||
this.x = -1;
|
||||
/**
|
||||
* The vertical coordinate of point relative to the game element
|
||||
* @property y
|
||||
* @type Number
|
||||
*/
|
||||
this.y = -1;
|
||||
/**
|
||||
*
|
||||
* @property isDown
|
||||
* @type Boolean
|
||||
**/
|
||||
this.isDown = false;
|
||||
/**
|
||||
*
|
||||
* @property isUp
|
||||
* @type Boolean
|
||||
**/
|
||||
this.isUp = false;
|
||||
/**
|
||||
*
|
||||
* @property timeDown
|
||||
* @type Number
|
||||
**/
|
||||
this.timeDown = 0;
|
||||
/**
|
||||
*
|
||||
* @property duration
|
||||
* @type Number
|
||||
**/
|
||||
this.duration = 0;
|
||||
/**
|
||||
*
|
||||
* @property timeUp
|
||||
* @type Number
|
||||
**/
|
||||
this.timeUp = 0;
|
||||
/**
|
||||
*
|
||||
* @property justPressedRate
|
||||
* @type Number
|
||||
**/
|
||||
this.justPressedRate = 200;
|
||||
/**
|
||||
*
|
||||
* @property justReleasedRate
|
||||
* @type Number
|
||||
**/
|
||||
this.justReleasedRate = 200;
|
||||
this._game = game;
|
||||
this.active = false;
|
||||
}
|
||||
Finger.prototype.start = /**
|
||||
*
|
||||
* @method start
|
||||
* @param {Any} event
|
||||
*/
|
||||
function (event) {
|
||||
this.identifier = event.identifier;
|
||||
this.target = event.target;
|
||||
// populate geom objects
|
||||
if(this.point === null) {
|
||||
this.point = new Phaser.Point();
|
||||
}
|
||||
if(this.circle === null) {
|
||||
this.circle = new Phaser.Circle(0, 0, 44);
|
||||
}
|
||||
this.move(event);
|
||||
this.active = true;
|
||||
this.withinGame = true;
|
||||
this.isDown = true;
|
||||
this.isUp = false;
|
||||
this.timeDown = this._game.time.now;
|
||||
};
|
||||
Finger.prototype.move = /**
|
||||
*
|
||||
* @method move
|
||||
* @param {Any} event
|
||||
*/
|
||||
function (event) {
|
||||
this.clientX = event.clientX;
|
||||
this.clientY = event.clientY;
|
||||
this.pageX = event.pageX;
|
||||
this.pageY = event.pageY;
|
||||
this.screenX = event.screenX;
|
||||
this.screenY = event.screenY;
|
||||
this.x = this.pageX - this._game.stage.offset.x;
|
||||
this.y = this.pageY - this._game.stage.offset.y;
|
||||
this.point.setTo(this.x, this.y);
|
||||
this.circle.setTo(this.x, this.y, 44);
|
||||
// Droppings history (used for gestures and motion tracking)
|
||||
this.duration = this._game.time.now - this.timeDown;
|
||||
};
|
||||
Finger.prototype.leave = /**
|
||||
*
|
||||
* @method leave
|
||||
* @param {Any} event
|
||||
*/
|
||||
function (event) {
|
||||
this.withinGame = false;
|
||||
this.move(event);
|
||||
};
|
||||
Finger.prototype.stop = /**
|
||||
*
|
||||
* @method stop
|
||||
* @param {Any} event
|
||||
*/
|
||||
function (event) {
|
||||
this.active = false;
|
||||
this.withinGame = false;
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
this.timeUp = this._game.time.now;
|
||||
this.duration = this.timeUp - this.timeDown;
|
||||
};
|
||||
Finger.prototype.justPressed = /**
|
||||
*
|
||||
* @method justPressed
|
||||
* @param {Number} [duration].
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function (duration) {
|
||||
if (typeof duration === "undefined") { duration = this.justPressedRate; }
|
||||
if(this.isDown === true && (this.timeDown + duration) > this._game.time.now) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Finger.prototype.justReleased = /**
|
||||
*
|
||||
* @method justReleased
|
||||
* @param {Number} [duration].
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function (duration) {
|
||||
if (typeof duration === "undefined") { duration = this.justReleasedRate; }
|
||||
if(this.isUp === true && (this.timeUp + duration) > this._game.time.now) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Finger.prototype.toString = /**
|
||||
* Returns a string representation of this object.
|
||||
* @method toString
|
||||
* @return {string} a string representation of the instance.
|
||||
**/
|
||||
function () {
|
||||
return "[{Finger (identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]";
|
||||
};
|
||||
return Finger;
|
||||
})();
|
||||
Phaser.Finger = Finger;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,58 +0,0 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../Signal.ts" />
|
||||
/**
|
||||
* Phaser - Input
|
||||
*
|
||||
* A game specific Input manager that looks after the mouse, keyboard and touch objects. This is updated by the core game loop.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Input = (function () {
|
||||
function Input(game) {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.scaleX = 1;
|
||||
this.scaleY = 1;
|
||||
this.worldX = 0;
|
||||
this.worldY = 0;
|
||||
this._game = game;
|
||||
this.mouse = new Phaser.Mouse(this._game);
|
||||
this.keyboard = new Phaser.Keyboard(this._game);
|
||||
this.touch = new Phaser.Touch(this._game);
|
||||
this.onDown = new Phaser.Signal();
|
||||
this.onUp = new Phaser.Signal();
|
||||
}
|
||||
Input.prototype.update = function () {
|
||||
this.x = Math.round(this.x);
|
||||
this.y = Math.round(this.y);
|
||||
this.worldX = this._game.camera.worldView.x + this.x;
|
||||
this.worldY = this._game.camera.worldView.y + this.y;
|
||||
this.mouse.update();
|
||||
this.touch.update();
|
||||
};
|
||||
Input.prototype.reset = function () {
|
||||
this.mouse.reset();
|
||||
this.keyboard.reset();
|
||||
this.touch.reset();
|
||||
};
|
||||
Input.prototype.getWorldX = function (camera) {
|
||||
if (typeof camera === "undefined") { camera = this._game.camera; }
|
||||
return camera.worldView.x + this.x;
|
||||
};
|
||||
Input.prototype.getWorldY = function (camera) {
|
||||
if (typeof camera === "undefined") { camera = this._game.camera; }
|
||||
return camera.worldView.y + this.y;
|
||||
};
|
||||
Input.prototype.renderDebugInfo = function (x, y, color) {
|
||||
if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
|
||||
this._game.stage.context.font = '14px Courier';
|
||||
this._game.stage.context.fillStyle = color;
|
||||
this._game.stage.context.fillText('Input', x, y);
|
||||
this._game.stage.context.fillText('Screen X: ' + this.x + ' Screen Y: ' + this.y, x, y + 14);
|
||||
this._game.stage.context.fillText('World X: ' + this.worldX + ' World Y: ' + this.worldY, x, y + 28);
|
||||
this._game.stage.context.fillText('Scale X: ' + this.scaleX.toFixed(1) + ' Scale Y: ' + this.scaleY.toFixed(1), x, y + 42);
|
||||
};
|
||||
return Input;
|
||||
})();
|
||||
Phaser.Input = Input;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,204 +0,0 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Keyboard
|
||||
*
|
||||
* The Keyboard class handles keyboard interactions with the game and the resulting events.
|
||||
* The avoid stealing all browser input we don't use event.preventDefault. If you would like to trap a specific key however
|
||||
* then use the addKeyCapture() method.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Keyboard = (function () {
|
||||
function Keyboard(game) {
|
||||
this._keys = {
|
||||
};
|
||||
this._capture = {
|
||||
};
|
||||
this._game = game;
|
||||
this.start();
|
||||
}
|
||||
Keyboard.prototype.start = function () {
|
||||
var _this = this;
|
||||
document.body.addEventListener('keydown', function (event) {
|
||||
return _this.onKeyDown(event);
|
||||
}, false);
|
||||
document.body.addEventListener('keyup', function (event) {
|
||||
return _this.onKeyUp(event);
|
||||
}, false);
|
||||
};
|
||||
Keyboard.prototype.addKeyCapture = function (keycode) {
|
||||
if(typeof keycode === 'object') {
|
||||
for(var i = 0; i < keycode.length; i++) {
|
||||
this._capture[keycode[i]] = true;
|
||||
}
|
||||
} else {
|
||||
this._capture[keycode] = true;
|
||||
}
|
||||
};
|
||||
Keyboard.prototype.removeKeyCapture = function (keycode) {
|
||||
delete this._capture[keycode];
|
||||
};
|
||||
Keyboard.prototype.clearCaptures = function () {
|
||||
this._capture = {
|
||||
};
|
||||
};
|
||||
Keyboard.prototype.onKeyDown = function (event) {
|
||||
if(this._capture[event.keyCode]) {
|
||||
event.preventDefault();
|
||||
}
|
||||
if(!this._keys[event.keyCode]) {
|
||||
this._keys[event.keyCode] = {
|
||||
isDown: true,
|
||||
timeDown: this._game.time.now,
|
||||
timeUp: 0
|
||||
};
|
||||
} else {
|
||||
this._keys[event.keyCode].isDown = true;
|
||||
this._keys[event.keyCode].timeDown = this._game.time.now;
|
||||
}
|
||||
};
|
||||
Keyboard.prototype.onKeyUp = function (event) {
|
||||
if(this._capture[event.keyCode]) {
|
||||
event.preventDefault();
|
||||
}
|
||||
if(!this._keys[event.keyCode]) {
|
||||
this._keys[event.keyCode] = {
|
||||
isDown: false,
|
||||
timeDown: 0,
|
||||
timeUp: this._game.time.now
|
||||
};
|
||||
} else {
|
||||
this._keys[event.keyCode].isDown = false;
|
||||
this._keys[event.keyCode].timeUp = this._game.time.now;
|
||||
}
|
||||
};
|
||||
Keyboard.prototype.reset = function () {
|
||||
for(var key in this._keys) {
|
||||
this._keys[key].isDown = false;
|
||||
}
|
||||
};
|
||||
Keyboard.prototype.justPressed = function (keycode, duration) {
|
||||
if (typeof duration === "undefined") { duration = 250; }
|
||||
if(this._keys[keycode] && this._keys[keycode].isDown === true && (this._game.time.now - this._keys[keycode].timeDown < duration)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Keyboard.prototype.justReleased = function (keycode, duration) {
|
||||
if (typeof duration === "undefined") { duration = 250; }
|
||||
if(this._keys[keycode] && this._keys[keycode].isDown === false && (this._game.time.now - this._keys[keycode].timeUp < duration)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Keyboard.prototype.isDown = function (keycode) {
|
||||
if(this._keys[keycode]) {
|
||||
return this._keys[keycode].isDown;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Keyboard.A = "A".charCodeAt(0);
|
||||
Keyboard.B = "B".charCodeAt(0);
|
||||
Keyboard.C = "C".charCodeAt(0);
|
||||
Keyboard.D = "D".charCodeAt(0);
|
||||
Keyboard.E = "E".charCodeAt(0);
|
||||
Keyboard.F = "F".charCodeAt(0);
|
||||
Keyboard.G = "G".charCodeAt(0);
|
||||
Keyboard.H = "H".charCodeAt(0);
|
||||
Keyboard.I = "I".charCodeAt(0);
|
||||
Keyboard.J = "J".charCodeAt(0);
|
||||
Keyboard.K = "K".charCodeAt(0);
|
||||
Keyboard.L = "L".charCodeAt(0);
|
||||
Keyboard.M = "M".charCodeAt(0);
|
||||
Keyboard.N = "N".charCodeAt(0);
|
||||
Keyboard.O = "O".charCodeAt(0);
|
||||
Keyboard.P = "P".charCodeAt(0);
|
||||
Keyboard.Q = "Q".charCodeAt(0);
|
||||
Keyboard.R = "R".charCodeAt(0);
|
||||
Keyboard.S = "S".charCodeAt(0);
|
||||
Keyboard.T = "T".charCodeAt(0);
|
||||
Keyboard.U = "U".charCodeAt(0);
|
||||
Keyboard.V = "V".charCodeAt(0);
|
||||
Keyboard.W = "W".charCodeAt(0);
|
||||
Keyboard.X = "X".charCodeAt(0);
|
||||
Keyboard.Y = "Y".charCodeAt(0);
|
||||
Keyboard.Z = "Z".charCodeAt(0);
|
||||
Keyboard.ZERO = "0".charCodeAt(0);
|
||||
Keyboard.ONE = "1".charCodeAt(0);
|
||||
Keyboard.TWO = "2".charCodeAt(0);
|
||||
Keyboard.THREE = "3".charCodeAt(0);
|
||||
Keyboard.FOUR = "4".charCodeAt(0);
|
||||
Keyboard.FIVE = "5".charCodeAt(0);
|
||||
Keyboard.SIX = "6".charCodeAt(0);
|
||||
Keyboard.SEVEN = "7".charCodeAt(0);
|
||||
Keyboard.EIGHT = "8".charCodeAt(0);
|
||||
Keyboard.NINE = "9".charCodeAt(0);
|
||||
Keyboard.NUMPAD_0 = 96;
|
||||
Keyboard.NUMPAD_1 = 97;
|
||||
Keyboard.NUMPAD_2 = 98;
|
||||
Keyboard.NUMPAD_3 = 99;
|
||||
Keyboard.NUMPAD_4 = 100;
|
||||
Keyboard.NUMPAD_5 = 101;
|
||||
Keyboard.NUMPAD_6 = 102;
|
||||
Keyboard.NUMPAD_7 = 103;
|
||||
Keyboard.NUMPAD_8 = 104;
|
||||
Keyboard.NUMPAD_9 = 105;
|
||||
Keyboard.NUMPAD_MULTIPLY = 106;
|
||||
Keyboard.NUMPAD_ADD = 107;
|
||||
Keyboard.NUMPAD_ENTER = 108;
|
||||
Keyboard.NUMPAD_SUBTRACT = 109;
|
||||
Keyboard.NUMPAD_DECIMAL = 110;
|
||||
Keyboard.NUMPAD_DIVIDE = 111;
|
||||
Keyboard.F1 = 112;
|
||||
Keyboard.F2 = 113;
|
||||
Keyboard.F3 = 114;
|
||||
Keyboard.F4 = 115;
|
||||
Keyboard.F5 = 116;
|
||||
Keyboard.F6 = 117;
|
||||
Keyboard.F7 = 118;
|
||||
Keyboard.F8 = 119;
|
||||
Keyboard.F9 = 120;
|
||||
Keyboard.F10 = 121;
|
||||
Keyboard.F11 = 122;
|
||||
Keyboard.F12 = 123;
|
||||
Keyboard.F13 = 124;
|
||||
Keyboard.F14 = 125;
|
||||
Keyboard.F15 = 126;
|
||||
Keyboard.COLON = 186;
|
||||
Keyboard.EQUALS = 187;
|
||||
Keyboard.UNDERSCORE = 189;
|
||||
Keyboard.QUESTION_MARK = 191;
|
||||
Keyboard.TILDE = 192;
|
||||
Keyboard.OPEN_BRACKET = 219;
|
||||
Keyboard.BACKWARD_SLASH = 220;
|
||||
Keyboard.CLOSED_BRACKET = 221;
|
||||
Keyboard.QUOTES = 222;
|
||||
Keyboard.BACKSPACE = 8;
|
||||
Keyboard.TAB = 9;
|
||||
Keyboard.CLEAR = 12;
|
||||
Keyboard.ENTER = 13;
|
||||
Keyboard.SHIFT = 16;
|
||||
Keyboard.CONTROL = 17;
|
||||
Keyboard.ALT = 18;
|
||||
Keyboard.CAPS_LOCK = 20;
|
||||
Keyboard.ESC = 27;
|
||||
Keyboard.SPACEBAR = 32;
|
||||
Keyboard.PAGE_UP = 33;
|
||||
Keyboard.PAGE_DOWN = 34;
|
||||
Keyboard.END = 35;
|
||||
Keyboard.HOME = 36;
|
||||
Keyboard.LEFT = 37;
|
||||
Keyboard.UP = 38;
|
||||
Keyboard.RIGHT = 39;
|
||||
Keyboard.DOWN = 40;
|
||||
Keyboard.INSERT = 45;
|
||||
Keyboard.DELETE = 46;
|
||||
Keyboard.HELP = 47;
|
||||
Keyboard.NUM_LOCK = 144;
|
||||
return Keyboard;
|
||||
})();
|
||||
Phaser.Keyboard = Keyboard;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,80 +0,0 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/**
|
||||
* Phaser - Mouse
|
||||
*
|
||||
* The Mouse class handles mouse interactions with the game and the resulting events.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Mouse = (function () {
|
||||
function Mouse(game) {
|
||||
this._x = 0;
|
||||
this._y = 0;
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
this.timeDown = 0;
|
||||
this.duration = 0;
|
||||
this.timeUp = 0;
|
||||
this._game = game;
|
||||
this.start();
|
||||
}
|
||||
Mouse.LEFT_BUTTON = 0;
|
||||
Mouse.MIDDLE_BUTTON = 1;
|
||||
Mouse.RIGHT_BUTTON = 2;
|
||||
Mouse.prototype.start = function () {
|
||||
var _this = this;
|
||||
this._game.stage.canvas.addEventListener('mousedown', function (event) {
|
||||
return _this.onMouseDown(event);
|
||||
}, true);
|
||||
this._game.stage.canvas.addEventListener('mousemove', function (event) {
|
||||
return _this.onMouseMove(event);
|
||||
}, true);
|
||||
this._game.stage.canvas.addEventListener('mouseup', function (event) {
|
||||
return _this.onMouseUp(event);
|
||||
}, true);
|
||||
};
|
||||
Mouse.prototype.reset = function () {
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
};
|
||||
Mouse.prototype.onMouseDown = function (event) {
|
||||
this.button = event.button;
|
||||
this._x = event.clientX - this._game.stage.x;
|
||||
this._y = event.clientY - this._game.stage.y;
|
||||
this._game.input.x = this._x * this._game.input.scaleX;
|
||||
this._game.input.y = this._y * this._game.input.scaleY;
|
||||
this.isDown = true;
|
||||
this.isUp = false;
|
||||
this.timeDown = this._game.time.now;
|
||||
this._game.input.onDown.dispatch(this._game.input.x, this._game.input.y, this.timeDown);
|
||||
};
|
||||
Mouse.prototype.update = function () {
|
||||
//this._game.input.x = this._x * this._game.input.scaleX;
|
||||
//this._game.input.y = this._y * this._game.input.scaleY;
|
||||
if(this.isDown) {
|
||||
this.duration = this._game.time.now - this.timeDown;
|
||||
}
|
||||
};
|
||||
Mouse.prototype.onMouseMove = function (event) {
|
||||
this.button = event.button;
|
||||
this._x = event.clientX - this._game.stage.x;
|
||||
this._y = event.clientY - this._game.stage.y;
|
||||
this._game.input.x = this._x * this._game.input.scaleX;
|
||||
this._game.input.y = this._y * this._game.input.scaleY;
|
||||
};
|
||||
Mouse.prototype.onMouseUp = function (event) {
|
||||
this.button = event.button;
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
this.timeUp = this._game.time.now;
|
||||
this.duration = this.timeUp - this.timeDown;
|
||||
this._x = event.clientX - this._game.stage.x;
|
||||
this._y = event.clientY - this._game.stage.y;
|
||||
this._game.input.x = this._x * this._game.input.scaleX;
|
||||
this._game.input.y = this._y * this._game.input.scaleY;
|
||||
this._game.input.onUp.dispatch(this._game.input.x, this._game.input.y, this.timeDown);
|
||||
};
|
||||
return Mouse;
|
||||
})();
|
||||
Phaser.Mouse = Mouse;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,303 +0,0 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="Finger.ts" />
|
||||
/**
|
||||
* Phaser - Touch
|
||||
*
|
||||
* The Touch class handles touch interactions with the game and the resulting Finger objects.
|
||||
* http://www.w3.org/TR/touch-events/
|
||||
* https://developer.mozilla.org/en-US/docs/DOM/TouchList
|
||||
* http://www.html5rocks.com/en/mobile/touchandmouse/
|
||||
* Note: Android 2.x only supports 1 touch event at once, no multi-touch
|
||||
*
|
||||
* @todo Try and resolve update lag in Chrome/Android
|
||||
* Gestures (pinch, zoom, swipe)
|
||||
* GameObject Touch
|
||||
* Touch point within GameObject
|
||||
* Input Zones (mouse and touch) - lock entities within them + axis aligned drags
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Touch = (function () {
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Game} game.
|
||||
* @return {Touch} This object.
|
||||
*/
|
||||
function Touch(game) {
|
||||
/**
|
||||
*
|
||||
* @property x
|
||||
* @type Number
|
||||
**/
|
||||
this.x = 0;
|
||||
/**
|
||||
*
|
||||
* @property y
|
||||
* @type Number
|
||||
**/
|
||||
this.y = 0;
|
||||
/**
|
||||
*
|
||||
* @property isDown
|
||||
* @type Boolean
|
||||
**/
|
||||
this.isDown = false;
|
||||
/**
|
||||
*
|
||||
* @property isUp
|
||||
* @type Boolean
|
||||
**/
|
||||
this.isUp = true;
|
||||
this._game = game;
|
||||
this.finger1 = new Phaser.Finger(this._game);
|
||||
this.finger2 = new Phaser.Finger(this._game);
|
||||
this.finger3 = new Phaser.Finger(this._game);
|
||||
this.finger4 = new Phaser.Finger(this._game);
|
||||
this.finger5 = new Phaser.Finger(this._game);
|
||||
this.finger6 = new Phaser.Finger(this._game);
|
||||
this.finger7 = new Phaser.Finger(this._game);
|
||||
this.finger8 = new Phaser.Finger(this._game);
|
||||
this.finger9 = new Phaser.Finger(this._game);
|
||||
this.finger10 = new Phaser.Finger(this._game);
|
||||
this._fingers = [
|
||||
this.finger1,
|
||||
this.finger2,
|
||||
this.finger3,
|
||||
this.finger4,
|
||||
this.finger5,
|
||||
this.finger6,
|
||||
this.finger7,
|
||||
this.finger8,
|
||||
this.finger9,
|
||||
this.finger10
|
||||
];
|
||||
this.touchDown = new Phaser.Signal();
|
||||
this.touchUp = new Phaser.Signal();
|
||||
this.start();
|
||||
}
|
||||
Touch.prototype.start = /**
|
||||
*
|
||||
* @method start
|
||||
*/
|
||||
function () {
|
||||
var _this = this;
|
||||
this._game.stage.canvas.addEventListener('touchstart', function (event) {
|
||||
return _this.onTouchStart(event);
|
||||
}, false);
|
||||
this._game.stage.canvas.addEventListener('touchmove', function (event) {
|
||||
return _this.onTouchMove(event);
|
||||
}, false);
|
||||
this._game.stage.canvas.addEventListener('touchend', function (event) {
|
||||
return _this.onTouchEnd(event);
|
||||
}, false);
|
||||
this._game.stage.canvas.addEventListener('touchenter', function (event) {
|
||||
return _this.onTouchEnter(event);
|
||||
}, false);
|
||||
this._game.stage.canvas.addEventListener('touchleave', function (event) {
|
||||
return _this.onTouchLeave(event);
|
||||
}, false);
|
||||
this._game.stage.canvas.addEventListener('touchcancel', function (event) {
|
||||
return _this.onTouchCancel(event);
|
||||
}, false);
|
||||
document.addEventListener('touchmove', function (event) {
|
||||
return _this.consumeTouchMove(event);
|
||||
}, false);
|
||||
};
|
||||
Touch.prototype.consumeTouchMove = /**
|
||||
* Prevent iOS bounce-back (doesn't work?)
|
||||
* @method consumeTouchMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
event.preventDefault();
|
||||
};
|
||||
Touch.prototype.onTouchStart = /**
|
||||
*
|
||||
* @method onTouchStart
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
event.preventDefault();
|
||||
// A list of all the touch points that BECAME active with the current event
|
||||
// https://developer.mozilla.org/en-US/docs/DOM/TouchList
|
||||
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
|
||||
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for(var i = 0; i < event.changedTouches.length; i++) {
|
||||
for(var f = 0; f < this._fingers.length; f++) {
|
||||
if(this._fingers[f].active === false) {
|
||||
this._fingers[f].start(event.changedTouches[i]);
|
||||
this.x = this._fingers[f].x;
|
||||
this.y = this._fingers[f].y;
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
this.touchDown.dispatch(this._fingers[f].x, this._fingers[f].y, this._fingers[f].timeDown, this._fingers[f].timeUp, this._fingers[f].duration);
|
||||
this._game.input.onDown.dispatch(this._game.input.x, this._game.input.y, this._fingers[f].timeDown);
|
||||
this.isDown = true;
|
||||
this.isUp = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Touch.prototype.onTouchCancel = /**
|
||||
* Doesn't appear to be supported by most browsers yet
|
||||
* @method onTouchCancel
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
event.preventDefault();
|
||||
// Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome)
|
||||
// http://www.w3.org/TR/touch-events/#dfn-touchcancel
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for(var i = 0; i < event.changedTouches.length; i++) {
|
||||
for(var f = 0; f < this._fingers.length; f++) {
|
||||
if(this._fingers[f].identifier === event.changedTouches[i].identifier) {
|
||||
this._fingers[f].stop(event.changedTouches[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Touch.prototype.onTouchEnter = /**
|
||||
* Doesn't appear to be supported by most browsers yet
|
||||
* @method onTouchEnter
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
event.preventDefault();
|
||||
// For touch enter and leave its a list of the touch points that have entered or left the target
|
||||
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
|
||||
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for(var i = 0; i < event.changedTouches.length; i++) {
|
||||
for(var f = 0; f < this._fingers.length; f++) {
|
||||
if(this._fingers[f].active === false) {
|
||||
this._fingers[f].start(event.changedTouches[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Touch.prototype.onTouchLeave = /**
|
||||
* Doesn't appear to be supported by most browsers yet
|
||||
* @method onTouchLeave
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
event.preventDefault();
|
||||
// For touch enter and leave its a list of the touch points that have entered or left the target
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for(var i = 0; i < event.changedTouches.length; i++) {
|
||||
for(var f = 0; f < this._fingers.length; f++) {
|
||||
if(this._fingers[f].identifier === event.changedTouches[i].identifier) {
|
||||
this._fingers[f].leave(event.changedTouches[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Touch.prototype.onTouchMove = /**
|
||||
*
|
||||
* @method onTouchMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
event.preventDefault();
|
||||
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
|
||||
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for(var i = 0; i < event.changedTouches.length; i++) {
|
||||
for(var f = 0; f < this._fingers.length; f++) {
|
||||
if(this._fingers[f].identifier === event.changedTouches[i].identifier) {
|
||||
this._fingers[f].move(event.changedTouches[i]);
|
||||
this.x = this._fingers[f].x;
|
||||
this.y = this._fingers[f].y;
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Touch.prototype.onTouchEnd = /**
|
||||
*
|
||||
* @method onTouchEnd
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
event.preventDefault();
|
||||
// For touch end its a list of the touch points that have been removed from the surface
|
||||
// https://developer.mozilla.org/en-US/docs/DOM/TouchList
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for(var i = 0; i < event.changedTouches.length; i++) {
|
||||
for(var f = 0; f < this._fingers.length; f++) {
|
||||
if(this._fingers[f].identifier === event.changedTouches[i].identifier) {
|
||||
this._fingers[f].stop(event.changedTouches[i]);
|
||||
this.x = this._fingers[f].x;
|
||||
this.y = this._fingers[f].y;
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
this.touchUp.dispatch(this._fingers[f].x, this._fingers[f].y, this._fingers[f].timeDown, this._fingers[f].timeUp, this._fingers[f].duration);
|
||||
this._game.input.onUp.dispatch(this._game.input.x, this._game.input.y, this._fingers[f].timeUp);
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Touch.prototype.calculateDistance = /**
|
||||
*
|
||||
* @method calculateDistance
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
**/
|
||||
function (finger1, finger2) {
|
||||
};
|
||||
Touch.prototype.calculateAngle = /**
|
||||
*
|
||||
* @method calculateAngle
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
**/
|
||||
function (finger1, finger2) {
|
||||
};
|
||||
Touch.prototype.checkOverlap = /**
|
||||
*
|
||||
* @method checkOverlap
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
**/
|
||||
function (finger1, finger2) {
|
||||
};
|
||||
Touch.prototype.update = /**
|
||||
*
|
||||
* @method update
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
Touch.prototype.stop = /**
|
||||
*
|
||||
* @method stop
|
||||
*/
|
||||
function () {
|
||||
//this._domElement.addEventListener('touchstart', (event) => this.onTouchStart(event), false);
|
||||
//this._domElement.addEventListener('touchmove', (event) => this.onTouchMove(event), false);
|
||||
//this._domElement.addEventListener('touchend', (event) => this.onTouchEnd(event), false);
|
||||
//this._domElement.addEventListener('touchenter', (event) => this.onTouchEnter(event), false);
|
||||
//this._domElement.addEventListener('touchleave', (event) => this.onTouchLeave(event), false);
|
||||
//this._domElement.addEventListener('touchcancel', (event) => this.onTouchCancel(event), false);
|
||||
};
|
||||
Touch.prototype.reset = /**
|
||||
*
|
||||
* @method reset
|
||||
**/
|
||||
function () {
|
||||
this.isDown = false;
|
||||
this.isUp = false;
|
||||
};
|
||||
return Touch;
|
||||
})();
|
||||
Phaser.Touch = Touch;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,102 +0,0 @@
|
||||
/// <reference path="../../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - BootScreen
|
||||
*
|
||||
* The BootScreen is displayed when Phaser is started without any default functions or State
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var BootScreen = (function () {
|
||||
/**
|
||||
* BootScreen constructor
|
||||
* Create a new <code>BootScreen</code> with specific width and height.
|
||||
*
|
||||
* @param width {number} Screen canvas width.
|
||||
* @param height {number} Screen canvas height.
|
||||
*/
|
||||
function BootScreen(game) {
|
||||
/**
|
||||
* Engine logo image data.
|
||||
*/
|
||||
this._logoData = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGgAAAAZCAYAAADdYmvFAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAstJREFUeNrsWlFuwjAMbavdZGcAcRm4AXzvCPuGG8BlEJxhZ+l4TJ48z3actGGthqUI1MaO/V6cmIT2/fW10eTt46NvKshtvDZlG31yfOL9a/ldU6x4IZ0GQs0gS217enMkJYr5ixXkYrFoVqtV1kDn8/n+KfXw/Hq9Nin7h8MhScB2u3Xtav2ivsNWrh7XLcWMYqA4eUZ1kj0MAifHJEeKFojWzyIH+rL/0Cwif2AX9nN1oQOgrTg8XcTFx+ScdEOJ4WBxXQ1EjRyrn0cOzzQLzFyQSQcgw/5Qkkr0JVEQpNIdhL4vm4DL5fLulNTHcy6Uxl4/6iMLiePx2KzX6/v30+n0aynUlrnSeNq2/VN9bgM4dFPdNPmsJnIg/PuQbJmLdFN3UNu0SzbyJ0GOWJVWZE/QMkY+owrqXxGEdZA37BVyX6lJTipT6J1lf7fbqc+xh8nYeIvikatP+PGW0nEJ4jOydHYOIcfKnmgWoZDQSIIeio4Sf1IthYWskCO4vqQ6lFYjl8tl9L1H67PZbMz3VO3t93uVXHofmUjReLyMwHi5eCb3ICwJj5ZU9nCg+SzUgPYyif+2epTk4pkkyDp+eXTlZu2BkUybEkklePZfK9lPuTnc07vbmt1bYulHBeNQgx18SsH4ni/cV2rSLtqNDNUH2JQ2SsXS57Y9PHlfumkwCdICt5rnkNdPjpMiIEWgRlAJSdF4SvCQMWj+VyfI0h8D/EgWSYKiJKXi8VrOhJUxaFiFCOKKUJAtR78k9eX4USLHXqLGXOIiWUT4Vj9JiP4W0io3VDz8AJXblNWQrOimLjIGy/9uLICH6mrVmFbxEFHauzmc0fGJJmPg/v+6D0oB7N2bj0FsNHtSWTQniWTR931QlHXvasDTHXLjqY0/1/8hSDxACD+lAGH8dKQbQk5N3TFtzDmLWutvV0+pL5FVoHvCNG35FGAAayS4KUoKC9QAAAAASUVORK5CYII=";
|
||||
/**
|
||||
* Background gradient effect color 1.
|
||||
*/
|
||||
this._color1 = { r: 20, g: 20, b: 20 };
|
||||
/**
|
||||
* Background gradient effect color 2.
|
||||
*/
|
||||
this._color2 = { r: 200, g: 200, b: 200 };
|
||||
/**
|
||||
* Fade effect tween.
|
||||
* @type {Phaser.Tween}
|
||||
*/
|
||||
this._fade = null;
|
||||
this.game = game;
|
||||
|
||||
this._logo = new Image();
|
||||
this._logo.src = this._logoData;
|
||||
}
|
||||
/**
|
||||
* Update color and fade.
|
||||
*/
|
||||
BootScreen.prototype.update = function () {
|
||||
if (this._fade == null) {
|
||||
this.colorCycle();
|
||||
}
|
||||
|
||||
this._color1.r = Math.round(this._color1.r);
|
||||
this._color1.g = Math.round(this._color1.g);
|
||||
this._color1.b = Math.round(this._color1.b);
|
||||
this._color2.r = Math.round(this._color2.r);
|
||||
this._color2.g = Math.round(this._color2.g);
|
||||
this._color2.b = Math.round(this._color2.b);
|
||||
};
|
||||
|
||||
/**
|
||||
* Render BootScreen.
|
||||
*/
|
||||
BootScreen.prototype.render = function () {
|
||||
var grd = this.game.stage.context.createLinearGradient(0, 0, 0, this.game.stage.height);
|
||||
grd.addColorStop(0, 'rgb(' + this._color1.r + ', ' + this._color1.g + ', ' + this._color1.b + ')');
|
||||
grd.addColorStop(0.5, 'rgb(' + this._color2.r + ', ' + this._color2.g + ', ' + this._color2.b + ')');
|
||||
grd.addColorStop(1, 'rgb(' + this._color1.r + ', ' + this._color1.g + ', ' + this._color1.b + ')');
|
||||
this.game.stage.context.fillStyle = grd;
|
||||
this.game.stage.context.fillRect(0, 0, this.game.stage.width, this.game.stage.height);
|
||||
|
||||
this.game.stage.context.shadowOffsetX = 0;
|
||||
this.game.stage.context.shadowOffsetY = 0;
|
||||
|
||||
if (this._logo) {
|
||||
this.game.stage.context.drawImage(this._logo, 32, 32);
|
||||
}
|
||||
|
||||
this.game.stage.context.shadowColor = 'rgb(0,0,0)';
|
||||
this.game.stage.context.shadowOffsetX = 1;
|
||||
this.game.stage.context.shadowOffsetY = 1;
|
||||
this.game.stage.context.shadowBlur = 0;
|
||||
this.game.stage.context.fillStyle = 'rgb(255,255,255)';
|
||||
this.game.stage.context.font = 'bold 18px Arial';
|
||||
this.game.stage.context.textBaseline = 'top';
|
||||
this.game.stage.context.fillText(Phaser.VERSION, 32, 64 + 32);
|
||||
this.game.stage.context.fillText('Game Size: ' + this.game.stage.width + ' x ' + this.game.stage.height, 32, 64 + 64);
|
||||
this.game.stage.context.fillText('www.photonstorm.com', 32, 64 + 96);
|
||||
this.game.stage.context.font = '16px Arial';
|
||||
this.game.stage.context.fillText('You are seeing this screen because you didn\'t specify any default', 32, 64 + 160);
|
||||
this.game.stage.context.fillText('functions in the Game constructor or use Game.switchState()', 32, 64 + 184);
|
||||
};
|
||||
|
||||
/**
|
||||
* Start color fading cycle.
|
||||
*/
|
||||
BootScreen.prototype.colorCycle = function () {
|
||||
this._fade = this.game.add.tween(this._color2);
|
||||
|
||||
this._fade.to({ r: Math.random() * 250, g: Math.random() * 250, b: Math.random() * 250 }, 3000, Phaser.Easing.Linear.None);
|
||||
this._fade.onComplete.add(this.colorCycle, this);
|
||||
this._fade.start();
|
||||
};
|
||||
return BootScreen;
|
||||
})();
|
||||
Phaser.BootScreen = BootScreen;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,48 +0,0 @@
|
||||
/// <reference path="../../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - OrientationScreen
|
||||
*
|
||||
* The Orientation Screen is displayed whenever the device is turned to an unsupported orientation.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var OrientationScreen = (function () {
|
||||
/**
|
||||
* OrientationScreen constructor
|
||||
* Create a new <code>OrientationScreen</code> with specific width and height.
|
||||
*
|
||||
* @param width {number} Screen canvas width.
|
||||
* @param height {number} Screen canvas height.
|
||||
*/
|
||||
function OrientationScreen(game) {
|
||||
this._showOnLandscape = false;
|
||||
this._showOnPortrait = false;
|
||||
this.game = game;
|
||||
}
|
||||
OrientationScreen.prototype.enable = function (onLandscape, onPortrait, imageKey) {
|
||||
this._showOnLandscape = onLandscape;
|
||||
this._showOnPortrait = onPortrait;
|
||||
this.landscapeImage = this.game.cache.getImage(imageKey);
|
||||
this.portraitImage = this.game.cache.getImage(imageKey);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update
|
||||
*/
|
||||
OrientationScreen.prototype.update = function () {
|
||||
};
|
||||
|
||||
/**
|
||||
* Render
|
||||
*/
|
||||
OrientationScreen.prototype.render = function () {
|
||||
if (this._showOnLandscape) {
|
||||
this.game.stage.context.drawImage(this.landscapeImage, 0, 0, this.landscapeImage.width, this.landscapeImage.height, 0, 0, this.game.stage.width, this.game.stage.height);
|
||||
} else if (this._showOnPortrait) {
|
||||
this.game.stage.context.drawImage(this.portraitImage, 0, 0, this.portraitImage.width, this.portraitImage.height, 0, 0, this.game.stage.width, this.game.stage.height);
|
||||
}
|
||||
};
|
||||
return OrientationScreen;
|
||||
})();
|
||||
Phaser.OrientationScreen = OrientationScreen;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,101 +0,0 @@
|
||||
/// <reference path="../../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - PauseScreen
|
||||
*
|
||||
* The PauseScreen is displayed whenever the game loses focus or the player switches to another browser tab.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var PauseScreen = (function () {
|
||||
/**
|
||||
* PauseScreen constructor
|
||||
* Create a new <code>PauseScreen</code> with specific width and height.
|
||||
*
|
||||
* @param width {number} Screen canvas width.
|
||||
* @param height {number} Screen canvas height.
|
||||
*/
|
||||
function PauseScreen(game, width, height) {
|
||||
this.game = game;
|
||||
this._canvas = document.createElement('canvas');
|
||||
this._canvas.width = width;
|
||||
this._canvas.height = height;
|
||||
this._context = this._canvas.getContext('2d');
|
||||
}
|
||||
/**
|
||||
* Called when the game enters pause mode.
|
||||
*/
|
||||
PauseScreen.prototype.onPaused = function () {
|
||||
// Take a grab of the current canvas to our temporary one
|
||||
this._context.clearRect(0, 0, this._canvas.width, this._canvas.height);
|
||||
this._context.drawImage(this.game.stage.canvas, 0, 0);
|
||||
this._color = { r: 255, g: 255, b: 255 };
|
||||
this.fadeOut();
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when the game resume from pause mode.
|
||||
*/
|
||||
PauseScreen.prototype.onResume = function () {
|
||||
this._fade.stop();
|
||||
this.game.tweens.remove(this._fade);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update background color.
|
||||
*/
|
||||
PauseScreen.prototype.update = function () {
|
||||
this._color.r = Math.round(this._color.r);
|
||||
this._color.g = Math.round(this._color.g);
|
||||
this._color.b = Math.round(this._color.b);
|
||||
};
|
||||
|
||||
/**
|
||||
* Render PauseScreen.
|
||||
*/
|
||||
PauseScreen.prototype.render = function () {
|
||||
this.game.stage.context.drawImage(this._canvas, 0, 0);
|
||||
|
||||
this.game.stage.context.fillStyle = 'rgba(0, 0, 0, 0.4)';
|
||||
this.game.stage.context.fillRect(0, 0, this.game.stage.width, this.game.stage.height);
|
||||
|
||||
// Draw a 'play' arrow
|
||||
var arrowWidth = Math.round(this.game.stage.width / 2);
|
||||
var arrowHeight = Math.round(this.game.stage.height / 2);
|
||||
|
||||
var sx = this.game.stage.centerX - arrowWidth / 2;
|
||||
var sy = this.game.stage.centerY - arrowHeight / 2;
|
||||
|
||||
this.game.stage.context.beginPath();
|
||||
this.game.stage.context.moveTo(sx, sy);
|
||||
this.game.stage.context.lineTo(sx, sy + arrowHeight);
|
||||
this.game.stage.context.lineTo(sx + arrowWidth, this.game.stage.centerY);
|
||||
this.game.stage.context.fillStyle = 'rgba(' + this._color.r + ', ' + this._color.g + ', ' + this._color.b + ', 0.8)';
|
||||
this.game.stage.context.fill();
|
||||
this.game.stage.context.closePath();
|
||||
};
|
||||
|
||||
/**
|
||||
* Start fadeOut effect.
|
||||
*/
|
||||
PauseScreen.prototype.fadeOut = function () {
|
||||
this._fade = this.game.add.tween(this._color);
|
||||
|
||||
this._fade.to({ r: 50, g: 50, b: 50 }, 1000, Phaser.Easing.Linear.None);
|
||||
this._fade.onComplete.add(this.fadeIn, this);
|
||||
this._fade.start();
|
||||
};
|
||||
|
||||
/**
|
||||
* Start fadeIn effect.
|
||||
*/
|
||||
PauseScreen.prototype.fadeIn = function () {
|
||||
this._fade = this.game.add.tween(this._color);
|
||||
|
||||
this._fade.to({ r: 255, g: 255, b: 255 }, 1000, Phaser.Easing.Linear.None);
|
||||
this._fade.onComplete.add(this.fadeOut, this);
|
||||
this._fade.start();
|
||||
};
|
||||
return PauseScreen;
|
||||
})();
|
||||
Phaser.PauseScreen = PauseScreen;
|
||||
})(Phaser || (Phaser = {}));
|
||||
Reference in New Issue
Block a user