diff --git a/Phaser/Phaser.csproj b/Phaser/Phaser.csproj
index 62a3ed22..7019ecb9 100644
--- a/Phaser/Phaser.csproj
+++ b/Phaser/Phaser.csproj
@@ -61,6 +61,7 @@
AnimationManager.ts
+
@@ -107,6 +108,14 @@
+
+
+
+ AABB.ts
+
+
+ PhysicsManager.ts
+
HeadlessRenderer.ts
diff --git a/Phaser/World.ts b/Phaser/World.ts
index 31d6f568..5eef880b 100644
--- a/Phaser/World.ts
+++ b/Phaser/World.ts
@@ -2,6 +2,7 @@
///
///
///
+///
/**
* Phaser - World
@@ -34,6 +35,8 @@ module Phaser {
this.bounds = new Rectangle(0, 0, width, height);
+ this.physics = new Physics.PhysicsManager(this._game, width, height);
+
this.worldDivisions = 6;
}
@@ -61,6 +64,12 @@ module Phaser {
*/
public bounds: Rectangle;
+ /**
+ * Reference to the physics manager.
+ * @type {Physics.PhysicsManager}
+ */
+ public physics: Physics.PhysicsManager;
+
/**
* @type {number}
*/
@@ -71,6 +80,7 @@ module Phaser {
*/
public update() {
+ this.physics.update();
this.group.update();
this.cameras.update();
@@ -81,8 +91,8 @@ module Phaser {
*/
public destroy() {
+ //this.physics.destroy();
this.group.destroy();
-
this.cameras.destroy();
}
@@ -94,7 +104,7 @@ module Phaser {
* @param height {number} New height of the world.
* @param [updateCameraBounds] {boolean} Update camera bounds automatically or not. Default to true.
*/
- public setSize(width: number, height: number, updateCameraBounds: bool = true) {
+ public setSize(width: number, height: number, updateCameraBounds: bool = true, updatePhysicsBounds: bool = true) {
this.bounds.width = width;
this.bounds.height = height;
@@ -104,6 +114,11 @@ module Phaser {
this._game.camera.setBounds(0, 0, width, height);
}
+ if (updatePhysicsBounds == true)
+ {
+ //this.physics.bounds.copyFrom(this.bounds);
+ }
+
// dispatch world resize event
}
diff --git a/Phaser/components/sprite/Physics.ts b/Phaser/components/sprite/Physics.ts
index 8fc6aff4..7073305d 100644
--- a/Phaser/components/sprite/Physics.ts
+++ b/Phaser/components/sprite/Physics.ts
@@ -1,5 +1,6 @@
///
///
+///
/**
* Phaser - Components - Physics
@@ -11,6 +12,28 @@ module Phaser.Components {
export class Physics {
+ constructor(parent: Sprite) {
+
+ this._game = parent.game;
+ this._sprite = parent;
+
+ //this.AABB = new Phaser.Physics.AABB(this._game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height);
+ this.AABB = this._game.world.physics.add(new Phaser.Physics.AABB(this._game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height));
+
+ }
+
+ /**
+ *
+ */
+ private _game: Game;
+
+ /**
+ *
+ */
+ private _sprite: Sprite;
+
+ public AABB: Phaser.Physics.AABB;
+
/**
* Whether this object will be moved by impacts with other objects or not.
* @type {boolean}
@@ -126,9 +149,9 @@ module Phaser.Components {
*
* @return {boolean} Whether the object is touching an object in (any of) the specified direction(s) this frame.
*/
- public isTouching(direction: number): bool {
- return (this.touching & direction) > Collision.NONE;
- }
+ //public isTouching(direction: number): bool {
+ // return (this.touching & direction) > Collision.NONE;
+ //}
/**
* Handy function for checking if this object just landed on a particular surface.
@@ -137,9 +160,9 @@ module Phaser.Components {
*
* @returns {boolean} Whether the object just landed on any specicied surfaces.
*/
- public justTouched(direction: number): bool {
- return ((this.touching & direction) > Collision.NONE) && ((this.wasTouching & direction) <= Collision.NONE);
- }
+ //public justTouched(direction: number): bool {
+ // return ((this.touching & direction) > Collision.NONE) && ((this.wasTouching & direction) <= Collision.NONE);
+ //}
/**
@@ -147,6 +170,12 @@ module Phaser.Components {
*/
public update() {
+ if (this.moves)
+ {
+ this._sprite.x = this.AABB.position.x - this.AABB.halfWidth;
+ this._sprite.y = this.AABB.position.y - this.AABB.halfHeight;
+ }
+
/*
var delta: number;
var velocityDelta: number;
@@ -176,20 +205,20 @@ module Phaser.Components {
* the object will collide from, use collision constants (like LEFT, FLOOR, etc)
* to set the value of allowCollisions directly.
*/
- public get solid(): bool {
- return (this.allowCollisions & Collision.ANY) > Collision.NONE;
- }
+ //public get solid(): bool {
+ // return (this.allowCollisions & Collision.ANY) > Collision.NONE;
+ //}
public set solid(value: bool) {
- if (value)
- {
- this.allowCollisions = Collision.ANY;
- }
- else
- {
- this.allowCollisions = Collision.NONE;
- }
+ //if (value)
+ //{
+ // this.allowCollisions = Collision.ANY;
+ //}
+ //else
+ //{
+ // this.allowCollisions = Collision.NONE;
+ //}
}
diff --git a/Phaser/gameobjects/GameObjectFactory.ts b/Phaser/gameobjects/GameObjectFactory.ts
index 85197333..75024640 100644
--- a/Phaser/gameobjects/GameObjectFactory.ts
+++ b/Phaser/gameobjects/GameObjectFactory.ts
@@ -1,5 +1,6 @@
///
///
+///
/**
* Phaser - GameObjectFactory
@@ -89,6 +90,19 @@ module Phaser {
return this._world.group.add(new Group(this._game, maxSize));
}
+ /**
+ * Create a new Sprite with specific position and sprite sheet key.
+ *
+ * @param x {number} X position of the new sprite.
+ * @param y {number} Y position of the new sprite.
+ * @param key {string} Optional, key for the sprite sheet you want it to use.
+ * @returns {Sprite} The newly created sprite object.
+ * WILL NEED TO TRACK A SPRITE
+ */
+ public physicsAABB(x: number, y: number, width: number, height: number): Physics.AABB {
+ return this._world.physics.add(new Physics.AABB(this._game, null, x, y, width, height));
+ }
+
/**
* Create a new Particle.
*
diff --git a/Phaser/gameobjects/Sprite.ts b/Phaser/gameobjects/Sprite.ts
index baabfbce..ad0b0cff 100644
--- a/Phaser/gameobjects/Sprite.ts
+++ b/Phaser/gameobjects/Sprite.ts
@@ -3,6 +3,7 @@
///
///
///
+///
/**
* Phaser - Sprite
@@ -47,6 +48,8 @@ module Phaser {
this.width = this.frameBounds.width;
this.height = this.frameBounds.height;
+ this.physics = new Phaser.Components.Physics(this);
+
// Transform related (if we add any more then move to a component)
this.origin = new Phaser.Vec2(0, 0);
this.scale = new Phaser.Vec2(1, 1);
@@ -99,6 +102,11 @@ module Phaser {
public width: number;
public height: number;
+ /**
+ * Sprite physics.
+ */
+ public physics: Phaser.Components.Physics;
+
/**
* The texture used to render the Sprite.
*/
@@ -213,10 +221,8 @@ module Phaser {
*/
public preUpdate() {
- //this.last.x = this.frameBounds.x;
- //this.last.y = this.frameBounds.y;
-
- //this.collisionMask.preUpdate();
+ this.frameBounds.x = this.x;
+ this.frameBounds.y = this.y;
if (this.modified == false && (!this.scale.equals(1) || !this.skew.equals(0) || this.rotation != 0 || this.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY))
{
@@ -237,13 +243,9 @@ module Phaser {
public postUpdate() {
this.animations.update();
+ this.physics.update();
/*
- if (this.moves)
- {
- this.updateMotion();
- }
-
if (this.worldBounds != null)
{
if (this.outOfBoundsAction == GameObject.OUT_OF_BOUNDS_KILL)
diff --git a/Phaser/physics/AABB.ts b/Phaser/physics/AABB.ts
new file mode 100644
index 00000000..2bc83e66
--- /dev/null
+++ b/Phaser/physics/AABB.ts
@@ -0,0 +1,155 @@
+///
+///
+
+/**
+* Phaser - Physics - AABB
+*/
+
+module Phaser.Physics {
+
+ export class AABB {
+
+ constructor(game: Game, sprite: Sprite, x: number, y: number, width: number, height: number) {
+
+ this.game = game;
+ this.world = game.world.physics;
+ this.sprite = sprite;
+
+ this.width = width;
+ this.height = height;
+ this.halfWidth = Math.round(width / 2);
+ this.halfHeight = Math.round(height / 2);
+
+ this.position = new Vec2(x + this.halfWidth, y + this.halfHeight);
+ this.oldPosition = new Vec2(x + this.halfWidth, y + this.halfHeight);
+
+ }
+
+ /**
+ * Local private reference to Game.
+ */
+ public game: Game;
+ public world: PhysicsManager;
+ public sprite: Sprite;
+
+ public position: Vec2;
+ public oldPosition: Vec2;
+ public width: number;
+ public height: number;
+ public halfWidth: number;
+ public halfHeight: number;
+
+ public update() {
+
+ if (this.sprite.physics.moves)
+ {
+ this.integrate();
+ this.collideWorld();
+ }
+
+ }
+
+ private integrate() {
+
+ var ox: number = this.oldPosition.x;
+ var oy: number = this.oldPosition.y;
+
+ this.oldPosition.x = this.position.x;
+ this.oldPosition.y = this.position.y;
+
+ //this.position.x += (this.world.drag.x * this.position.x + this.halfWidth) - (this.world.drag.x * ox) + this.world.gravity.x;
+ //this.position.y += (this.world.drag.y * this.position.y + this.halfHeight) - (this.world.drag.y * oy) + this.world.gravity.y;
+ this.position.x += (this.world.drag.x * this.position.x) - (this.world.drag.x * ox) + this.world.gravity.x;
+ this.position.y += (this.world.drag.y * this.position.y) - (this.world.drag.y * oy) + this.world.gravity.y;
+
+ }
+
+ private collideWorld() {
+
+ // Collide on the x-axis
+ var dx: number = this.world.bounds.x - (this.position.x - this.halfWidth);
+
+ if (0 < dx)
+ {
+ this.processWorld(dx, 0, 1, 0, null);
+ }
+ else
+ {
+ dx = (this.position.x + this.halfWidth) - this.world.bounds.right;
+
+ if (0 < dx)
+ {
+ this.processWorld(-dx, 0, -1, 0, null);
+ }
+ }
+
+ // Collide on the y-axis
+ var dy: number = this.world.bounds.y - (this.position.y - this.halfHeight);
+
+ if (0 < dy)
+ {
+ this.processWorld(0, dy, 0, 1, null);
+ }
+ else
+ {
+ dy = (this.position.y + this.halfHeight) - this.world.bounds.bottom;
+
+ if (0 < dy)
+ {
+ this.processWorld(0, -dy, 0, -1, null);
+ }
+ }
+
+ }
+
+ private processWorld(px, py, dx, dy, tile) {
+
+ // Velocity
+ var vx: number = this.position.x - this.oldPosition.x;
+ var vy: number = this.position.y - this.oldPosition.y;
+
+ var dp: number = (vx * dx + vy * dy);
+ var nx: number = dp * dx;
+ var ny: number = dp * dy;
+ var tx: number = vx - nx;
+ var ty: number = vy - ny;
+
+ var b, bx, by, f, fx, fy;
+
+ if (dp < 0)
+ {
+ fx = tx * this.world.friction.x;
+ fy = ty * this.world.friction.y;
+ bx = (nx * (1 + this.world.bounce.x));
+ by = (ny * (1 + this.world.bounce.y));
+ }
+ else
+ {
+ bx = by = fx = fy = 0;
+ }
+
+ this.position.x += px;
+ this.position.y += py;
+
+ this.oldPosition.x += px + bx + fx;
+ this.oldPosition.y += py + by + fy;
+
+ }
+
+ public render(context:CanvasRenderingContext2D) {
+
+ context.beginPath();
+ context.strokeStyle = 'rgb(0,255,0)';
+ context.strokeRect(this.position.x - this.halfWidth, this.position.y - this.halfHeight, this.width, this.height);
+ context.stroke();
+ context.closePath();
+
+ // center point
+ context.fillStyle = 'rgb(0,255,0)';
+ context.fillRect(this.position.x, this.position.y, 2, 2);
+
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/Phaser/physics/PhysicsManager.ts b/Phaser/physics/PhysicsManager.ts
new file mode 100644
index 00000000..7dba6e7e
--- /dev/null
+++ b/Phaser/physics/PhysicsManager.ts
@@ -0,0 +1,83 @@
+///
+
+/**
+* Phaser - PhysicsManager
+*
+* Your game only has one PhysicsManager instance and it's responsible for looking after, creating and colliding
+* all of the physics objects in the world.
+*/
+
+module Phaser.Physics {
+
+ export class PhysicsManager {
+
+ constructor(game: Game, width: number, height: number) {
+
+ this._game = game;
+
+ this.gravity = new Vec2(0, 0.2);
+ this.drag = new Vec2(1, 1);
+ this.bounce = new Vec2(0.3, 0.7);
+ this.friction = new Vec2(0.05, 0.05);
+
+ this.bounds = new Rectangle(0, 0, width, height);
+
+ this._objects = [];
+
+ }
+
+ /**
+ * Local private reference to Game.
+ */
+ private _game: Game;
+
+ private _objects;
+
+ public bounds: Rectangle;
+
+ public gravity: Vec2;
+ public drag: Vec2;
+ public bounce: Vec2;
+ public friction: Vec2;
+
+ private minFriction: number = 0;
+ private maxFriction: number = 1;
+
+ private minBounce: number = 0;
+ private maxBounce: number = 1;
+
+ private minGravity: number = 0;
+ private maxGravity: number = 1;
+
+ private _i: number = 0;
+ private _length: number = 0;
+
+ public add(o) {
+ this._objects.push(o);
+ this._length++;
+ return o;
+ }
+
+ public update() {
+
+ // iterate through the objects here, updating and colliding
+ for (this._i = 0; this._i < this._length; this._i++)
+ {
+ this._objects[this._i].update();
+ }
+
+ }
+
+ public render() {
+
+ // iterate through the objects here, updating and colliding
+ for (this._i = 0; this._i < this._length; this._i++)
+ {
+ this._objects[this._i].render(this._game.stage.context);
+ }
+
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/Phaser/renderers/CanvasRenderer.ts b/Phaser/renderers/CanvasRenderer.ts
index 86285707..4bcc10cd 100644
--- a/Phaser/renderers/CanvasRenderer.ts
+++ b/Phaser/renderers/CanvasRenderer.ts
@@ -53,6 +53,9 @@ module Phaser {
this._camera.postRender();
}
+ // Physics Debug layer
+ this._game.world.physics.render();
+
}
/**
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index eb1d5834..01604c17 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -65,6 +65,10 @@
scrollfactor 2.ts
+
+
+ aabb 1.ts
+
tween loop 1.ts
diff --git a/Tests/cameras/scrollfactor 2.js b/Tests/cameras/scrollfactor 2.js
index d6af5870..7e3e137b 100644
--- a/Tests/cameras/scrollfactor 2.js
+++ b/Tests/cameras/scrollfactor 2.js
@@ -11,8 +11,7 @@
var temp = game.add.sprite(600 + (10 * i), 200 + (10 * i), 'disk');
temp.scrollFactor.setTo(i / 2, i / 2);
}
- //game.camera.focusOnXY(800, 200);
- }
+ }
function update() {
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
game.camera.scroll.x -= 4;
diff --git a/Tests/phaser.js b/Tests/phaser.js
index 4e614f9e..a9fd22a9 100644
--- a/Tests/phaser.js
+++ b/Tests/phaser.js
@@ -1811,200 +1811,353 @@ var Phaser;
})(Phaser || (Phaser = {}));
///
/**
-* Phaser - Vec2
+* Phaser - Point
*
-* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
+* The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
*/
var Phaser;
(function (Phaser) {
- var Vec2 = (function () {
+ var Point = (function () {
/**
- * Creates a new Vec2 object.
- * @class Vec2
+ * Creates a new Point. If you pass no parameters a Point is created set to (0,0).
+ * @class Point
* @constructor
- * @param {Number} x The x position of the vector
- * @param {Number} y The y position of the vector
- * @return {Vec2} This object
+ * @param {Number} x The horizontal position of this Point (default 0)
+ * @param {Number} y The vertical position of this Point (default 0)
**/
- function Vec2(x, y) {
+ function Point(x, y) {
if (typeof x === "undefined") { x = 0; }
if (typeof y === "undefined") { y = 0; }
this.x = x;
this.y = y;
}
- Vec2.prototype.copyFrom = /**
- * Copies the x and y properties from any given object to this Vec2.
+ Point.prototype.copyFrom = /**
+ * Copies the x and y properties from any given object to this Point.
* @method copyFrom
* @param {any} source - The object to copy from.
- * @return {Vec2} This Vec2 object.
+ * @return {Point} This Point object.
**/
function (source) {
return this.setTo(source.x, source.y);
};
- Vec2.prototype.setTo = /**
- * Sets the x and y properties of the Vector.
- * @param {Number} x The x position of the vector
- * @param {Number} y The y position of the vector
- * @return {Vec2} This object
+ Point.prototype.invert = /**
+ * Inverts the x and y values of this Point
+ * @method invert
+ * @return {Point} This Point object.
+ **/
+ function () {
+ return this.setTo(this.y, this.x);
+ };
+ Point.prototype.setTo = /**
+ * Sets the x and y values of this MicroPoint object to the given coordinates.
+ * @method setTo
+ * @param {Number} x - The horizontal position of this point.
+ * @param {Number} y - The vertical position of this point.
+ * @return {MicroPoint} This MicroPoint object. Useful for chaining method calls.
**/
function (x, y) {
this.x = x;
this.y = y;
return this;
};
- Vec2.prototype.add = /**
- * Add another vector to this one.
- *
- * @param {Vec2} other The other Vector.
- * @return {Vec2} This for chaining.
- */
- function (a) {
- this.x += a.x;
- this.y += a.y;
- return this;
- };
- Vec2.prototype.subtract = /**
- * Subtract another vector from this one.
- *
- * @param {Vec2} other The other Vector.
- * @return {Vec2} This for chaining.
- */
- function (v) {
- this.x -= v.x;
- this.y -= v.y;
- return this;
- };
- Vec2.prototype.multiply = /**
- * Multiply another vector with this one.
- *
- * @param {Vec2} other The other Vector.
- * @return {Vec2} This for chaining.
- */
- function (v) {
- this.x *= v.x;
- this.y *= v.y;
- return this;
- };
- Vec2.prototype.divide = /**
- * Divide this vector by another one.
- *
- * @param {Vec2} other The other Vector.
- * @return {Vec2} This for chaining.
- */
- function (v) {
- this.x /= v.x;
- this.y /= v.y;
- return this;
- };
- Vec2.prototype.length = /**
- * Get the length of this vector.
- *
- * @return {number} The length of this vector.
- */
- function () {
- return Math.sqrt((this.x * this.x) + (this.y * this.y));
- };
- Vec2.prototype.lengthSq = /**
- * Get the length squared of this vector.
- *
- * @return {number} The length^2 of this vector.
- */
- function () {
- return (this.x * this.x) + (this.y * this.y);
- };
- Vec2.prototype.dot = /**
- * The dot product of two 2D vectors.
- *
- * @param {Vec2} a Reference to a source Vec2 object.
- * @return {Number}
- */
- function (a) {
- return ((this.x * a.x) + (this.y * a.y));
- };
- Vec2.prototype.cross = /**
- * The cross product of two 2D vectors.
- *
- * @param {Vec2} a Reference to a source Vec2 object.
- * @return {Number}
- */
- function (a) {
- return ((this.x * a.y) - (this.y * a.x));
- };
- Vec2.prototype.projectionLength = /**
- * The projection magnitude of two 2D vectors.
- *
- * @param {Vec2} a Reference to a source Vec2 object.
- * @return {Number}
- */
- function (a) {
- var den = a.dot(a);
- if(den == 0) {
- return 0;
- } else {
- return Math.abs(this.dot(a) / den);
- }
- };
- Vec2.prototype.angle = /**
- * The angle between two 2D vectors.
- *
- * @param {Vec2} a Reference to a source Vec2 object.
- * @return {Number}
- */
- function (a) {
- return Math.atan2(a.x * this.y - a.y * this.x, a.x * this.x + a.y * this.y);
- };
- Vec2.prototype.scale = /**
- * Scale this vector.
- *
- * @param {number} x The scaling factor in the x direction.
- * @param {?number=} y The scaling factor in the y direction. If this is not specified, the x scaling factor will be used.
- * @return {Vec2} This for chaining.
- */
- function (x, y) {
- this.x *= x;
- this.y *= y || x;
- return this;
- };
- Vec2.prototype.divideByScalar = /**
- * Divide this vector by the given scalar.
- *
- * @param {number} scalar
- * @return {Vec2} This for chaining.
- */
- function (scalar) {
- this.x /= scalar;
- this.y /= scalar;
- return this;
- };
- Vec2.prototype.reverse = /**
- * Reverse this vector.
- *
- * @return {Vec2} This for chaining.
- */
- function () {
- this.x = -this.x;
- this.y = -this.y;
- return this;
- };
- Vec2.prototype.equals = /**
- * Check if both the x and y of this vector equal the given value.
- *
- * @return {Boolean}
- */
- function (value) {
- return (this.x == value && this.y == value);
- };
- Vec2.prototype.toString = /**
+ Point.prototype.toString = /**
* Returns a string representation of this object.
* @method toString
- * @return {string} a string representation of the object.
+ * @return {string} a string representation of the instance.
**/
function () {
- return "[{Vec2 (x=" + this.x + " y=" + this.y + ")}]";
+ return '[{Point (x=' + this.x + ' y=' + this.y + ')}]';
};
- return Vec2;
+ return Point;
})();
- Phaser.Vec2 = Vec2;
+ Phaser.Point = Point;
+})(Phaser || (Phaser = {}));
+///
+/**
+* Rectangle
+*
+* @desc A Rectangle object is an area defined by its position, as indicated by its top-left corner (x,y) and width and height.
+*
+* @version 1.6 - 24th May 2013
+* @author Richard Davey
+*/
+var Phaser;
+(function (Phaser) {
+ var Rectangle = (function () {
+ /**
+ * Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a rectangle with x, y, width, and height properties set to 0 is created.
+ * @class Rectangle
+ * @constructor
+ * @param {Number} x The x coordinate of the top-left corner of the rectangle.
+ * @param {Number} y The y coordinate of the top-left corner of the rectangle.
+ * @param {Number} width The width of the rectangle in pixels.
+ * @param {Number} height The height of the rectangle in pixels.
+ * @return {Rectangle} This rectangle object
+ **/
+ function Rectangle(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; }
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+ Object.defineProperty(Rectangle.prototype, "halfWidth", {
+ get: /**
+ * Half of the width of the rectangle
+ * @property halfWidth
+ * @type Number
+ **/
+ function () {
+ return Math.round(this.width / 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "halfHeight", {
+ get: /**
+ * Half of the height of the rectangle
+ * @property halfHeight
+ * @type Number
+ **/
+ function () {
+ return Math.round(this.height / 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "bottom", {
+ get: /**
+ * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
+ * @method bottom
+ * @return {Number}
+ **/
+ function () {
+ return this.y + this.height;
+ },
+ set: /**
+ * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
+ * @method bottom
+ * @param {Number} value
+ **/
+ function (value) {
+ if(value <= this.y) {
+ this.height = 0;
+ } else {
+ this.height = (this.y - value);
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "bottomRight", {
+ set: /**
+ * Sets the bottom-right corner of the Rectangle, determined by the values of the given Point object.
+ * @method bottomRight
+ * @param {Point} value
+ **/
+ function (value) {
+ this.right = value.x;
+ this.bottom = value.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "left", {
+ get: /**
+ * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
+ * @method left
+ * @ return {number}
+ **/
+ function () {
+ return this.x;
+ },
+ set: /**
+ * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties.
+ * However it does affect the width, whereas changing the x value does not affect the width property.
+ * @method left
+ * @param {Number} value
+ **/
+ function (value) {
+ if(value >= this.right) {
+ this.width = 0;
+ } else {
+ this.width = this.right - value;
+ }
+ this.x = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "right", {
+ get: /**
+ * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
+ * However it does affect the width property.
+ * @method right
+ * @return {Number}
+ **/
+ function () {
+ return this.x + this.width;
+ },
+ set: /**
+ * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
+ * However it does affect the width property.
+ * @method right
+ * @param {Number} value
+ **/
+ function (value) {
+ if(value <= this.x) {
+ this.width = 0;
+ } else {
+ this.width = this.x + value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "volume", {
+ get: /**
+ * The volume of the Rectangle derived from width * height
+ * @method volume
+ * @return {Number}
+ **/
+ function () {
+ return this.width * this.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "perimeter", {
+ get: /**
+ * The perimeter size of the Rectangle. This is the sum of all 4 sides.
+ * @method perimeter
+ * @return {Number}
+ **/
+ function () {
+ return (this.width * 2) + (this.height * 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "top", {
+ get: /**
+ * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
+ * However it does affect the height property, whereas changing the y value does not affect the height property.
+ * @method top
+ * @return {Number}
+ **/
+ function () {
+ return this.y;
+ },
+ set: /**
+ * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
+ * However it does affect the height property, whereas changing the y value does not affect the height property.
+ * @method top
+ * @param {Number} value
+ **/
+ function (value) {
+ if(value >= this.bottom) {
+ this.height = 0;
+ this.y = value;
+ } else {
+ this.height = (this.bottom - value);
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "topLeft", {
+ set: /**
+ * The location of the Rectangles top-left corner, determined by the x and y coordinates of the Point.
+ * @method topLeft
+ * @param {Point} value
+ **/
+ function (value) {
+ this.x = value.x;
+ this.y = value.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "empty", {
+ get: /**
+ * Determines whether or not this Rectangle object is empty.
+ * @method isEmpty
+ * @return {Boolean} A value of true if the Rectangle object's width or height is less than or equal to 0; otherwise false.
+ **/
+ function () {
+ return (!this.width || !this.height);
+ },
+ set: /**
+ * Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0.
+ * @method setEmpty
+ * @return {Rectangle} This rectangle object
+ **/
+ function (value) {
+ return this.setTo(0, 0, 0, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Rectangle.prototype.offset = /**
+ * Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
+ * @method offset
+ * @param {Number} dx Moves the x value of the Rectangle object by this amount.
+ * @param {Number} dy Moves the y value of the Rectangle object by this amount.
+ * @return {Rectangle} This Rectangle object.
+ **/
+ function (dx, dy) {
+ this.x += dx;
+ this.y += dy;
+ return this;
+ };
+ Rectangle.prototype.offsetPoint = /**
+ * Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
+ * @method offsetPoint
+ * @param {Point} point A Point object to use to offset this Rectangle object.
+ * @return {Rectangle} This Rectangle object.
+ **/
+ function (point) {
+ return this.offset(point.x, point.y);
+ };
+ Rectangle.prototype.setTo = /**
+ * Sets the members of Rectangle to the specified values.
+ * @method setTo
+ * @param {Number} x The x coordinate of the top-left corner of the rectangle.
+ * @param {Number} y The y coordinate of the top-left corner of the rectangle.
+ * @param {Number} width The width of the rectangle in pixels.
+ * @param {Number} height The height of the rectangle in pixels.
+ * @return {Rectangle} This rectangle object
+ **/
+ function (x, y, width, height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ return this;
+ };
+ Rectangle.prototype.copyFrom = /**
+ * Copies the x, y, width and height properties from any given object to this Rectangle.
+ * @method copyFrom
+ * @param {any} source - The object to copy from.
+ * @return {Rectangle} This Rectangle object.
+ **/
+ function (source) {
+ return this.setTo(source.x, source.y, source.width, source.height);
+ };
+ Rectangle.prototype.toString = /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the instance.
+ **/
+ function () {
+ return "[{Rectangle (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + " empty=" + this.empty + ")}]";
+ };
+ return Rectangle;
+ })();
+ Phaser.Rectangle = Rectangle;
})(Phaser || (Phaser = {}));
///
/**
@@ -3828,6 +3981,7 @@ var Phaser;
///
///
///
+///
/**
* Phaser - Sprite
*
@@ -3896,8 +4050,8 @@ var Phaser;
this.texture = new Phaser.Components.Texture(this, key);
this.width = this.frameBounds.width;
this.height = this.frameBounds.height;
+ this.physics = new Phaser.Components.Physics(this);
// Transform related (if we add any more then move to a component)
- //this.origin = new Phaser.Vec2(this.width / 2, this.height / 2);
this.origin = new Phaser.Vec2(0, 0);
this.scale = new Phaser.Vec2(1, 1);
this.skew = new Phaser.Vec2(0, 0);
@@ -3955,9 +4109,8 @@ var Phaser;
* Pre-update is called right before update() on each object in the game loop.
*/
function () {
- //this.last.x = this.frameBounds.x;
- //this.last.y = this.frameBounds.y;
- //this.collisionMask.preUpdate();
+ this.frameBounds.x = this.x;
+ this.frameBounds.y = this.y;
if(this.modified == false && (!this.scale.equals(1) || !this.skew.equals(0) || this.rotation != 0 || this.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
this.modified = true;
}
@@ -3972,12 +4125,8 @@ var Phaser;
*/
function () {
this.animations.update();
+ this.physics.update();
/*
- if (this.moves)
- {
- this.updateMotion();
- }
-
if (this.worldBounds != null)
{
if (this.outOfBoundsAction == GameObject.OUT_OF_BOUNDS_KILL)
@@ -5382,8 +5531,157 @@ var Phaser;
})();
Phaser.Tween = Tween;
})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - PhysicsManager
+ *
+ * Your game only has one PhysicsManager instance and it's responsible for looking after, creating and colliding
+ * all of the physics objects in the world.
+ */
+ (function (Physics) {
+ var PhysicsManager = (function () {
+ function PhysicsManager(game, width, height) {
+ this.minFriction = 0;
+ this.maxFriction = 1;
+ this.minBounce = 0;
+ this.maxBounce = 1;
+ this.minGravity = 0;
+ this.maxGravity = 1;
+ this._i = 0;
+ this._length = 0;
+ this._game = game;
+ this.gravity = new Phaser.Vec2(0, 0.2);
+ this.drag = new Phaser.Vec2(1, 1);
+ this.bounce = new Phaser.Vec2(0.3, 0.9);
+ this.friction = new Phaser.Vec2(0.05, 0.05);
+ this.bounds = new Phaser.Rectangle(0, 0, width, height);
+ this._objects = [];
+ }
+ PhysicsManager.prototype.add = function (o) {
+ this._objects.push(o);
+ this._length++;
+ return o;
+ };
+ PhysicsManager.prototype.update = function () {
+ // iterate through the objects here, updating and colliding
+ for(this._i = 0; this._i < this._length; this._i++) {
+ this._objects[this._i].update();
+ }
+ };
+ PhysicsManager.prototype.render = function () {
+ // iterate through the objects here, updating and colliding
+ for(this._i = 0; this._i < this._length; this._i++) {
+ this._objects[this._i].render(this._game.stage.context);
+ }
+ };
+ return PhysicsManager;
+ })();
+ Physics.PhysicsManager = PhysicsManager;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ ///
+ ///
+ /**
+ * Phaser - Physics - AABB
+ */
+ (function (Physics) {
+ var AABB = (function () {
+ function AABB(game, sprite, x, y, width, height) {
+ this.game = game;
+ this.world = game.world.physics;
+ this.sprite = sprite;
+ this.width = width;
+ this.height = height;
+ this.halfWidth = Math.round(width / 2);
+ this.halfHeight = Math.round(height / 2);
+ this.position = new Phaser.Vec2(x + this.halfWidth, y + this.halfHeight);
+ this.oldPosition = new Phaser.Vec2(x + this.halfWidth, y + this.halfHeight);
+ }
+ AABB.prototype.update = function () {
+ if(this.sprite.physics.moves) {
+ this.integrate();
+ this.collideWorld();
+ }
+ };
+ AABB.prototype.integrate = function () {
+ var ox = this.oldPosition.x;
+ var oy = this.oldPosition.y;
+ this.oldPosition.x = this.position.x;
+ this.oldPosition.y = this.position.y;
+ //this.position.x += (this.world.drag.x * this.position.x + this.halfWidth) - (this.world.drag.x * ox) + this.world.gravity.x;
+ //this.position.y += (this.world.drag.y * this.position.y + this.halfHeight) - (this.world.drag.y * oy) + this.world.gravity.y;
+ this.position.x += (this.world.drag.x * this.position.x) - (this.world.drag.x * ox) + this.world.gravity.x;
+ this.position.y += (this.world.drag.y * this.position.y) - (this.world.drag.y * oy) + this.world.gravity.y;
+ };
+ AABB.prototype.collideWorld = function () {
+ // Collide on the x-axis
+ var dx = this.world.bounds.x - (this.position.x - this.halfWidth);
+ if(0 < dx) {
+ this.processWorld(dx, 0, 1, 0, null);
+ } else {
+ dx = (this.position.x + this.halfWidth) - this.world.bounds.right;
+ if(0 < dx) {
+ this.processWorld(-dx, 0, -1, 0, null);
+ }
+ }
+ // Collide on the y-axis
+ var dy = this.world.bounds.y - (this.position.y - this.halfHeight);
+ if(0 < dy) {
+ this.processWorld(0, dy, 0, 1, null);
+ } else {
+ dy = (this.position.y + this.halfHeight) - this.world.bounds.bottom;
+ if(0 < dy) {
+ this.processWorld(0, -dy, 0, -1, null);
+ }
+ }
+ };
+ AABB.prototype.processWorld = function (px, py, dx, dy, tile) {
+ // Velocity
+ var vx = this.position.x - this.oldPosition.x;
+ var vy = this.position.y - this.oldPosition.y;
+ var dp = (vx * dx + vy * dy);
+ var nx = dp * dx;
+ var ny = dp * dy;
+ var tx = vx - nx;
+ var ty = vy - ny;
+ var b, bx, by, f, fx, fy;
+ if(dp < 0) {
+ fx = tx * this.world.friction.x;
+ fy = ty * this.world.friction.y;
+ bx = (nx * (1 + this.world.bounce.x));
+ by = (ny * (1 + this.world.bounce.y));
+ } else {
+ bx = by = fx = fy = 0;
+ }
+ this.position.x += px;
+ this.position.y += py;
+ this.oldPosition.x += px + bx + fx;
+ this.oldPosition.y += py + by + fy;
+ };
+ AABB.prototype.render = function (context) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(0,255,0)';
+ context.strokeRect(this.position.x - this.halfWidth, this.position.y - this.halfHeight, this.width, this.height);
+ context.stroke();
+ context.closePath();
+ // center point
+ context.fillStyle = 'rgb(0,255,0)';
+ context.fillRect(this.position.x, this.position.y, 2, 2);
+ };
+ return AABB;
+ })();
+ Physics.AABB = AABB;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
///
///
+///
/**
* Phaser - GameObjectFactory
*
@@ -5454,6 +5752,18 @@ var Phaser;
if (typeof maxSize === "undefined") { maxSize = 0; }
return this._world.group.add(new Phaser.Group(this._game, maxSize));
};
+ GameObjectFactory.prototype.physicsAABB = /**
+ * Create a new Sprite with specific position and sprite sheet key.
+ *
+ * @param x {number} X position of the new sprite.
+ * @param y {number} Y position of the new sprite.
+ * @param key {string} Optional, key for the sprite sheet you want it to use.
+ * @returns {Sprite} The newly created sprite object.
+ * WILL NEED TO TRACK A SPRITE
+ */
+ function (x, y, width, height) {
+ return this._world.physics.add(new Phaser.Physics.AABB(this._game, null, x, y, width, height));
+ };
GameObjectFactory.prototype.tween = /**
* Create a new Particle.
*
@@ -7654,6 +7964,7 @@ var Phaser;
///
///
///
+///
/**
* Phaser - World
*
@@ -7678,12 +7989,14 @@ var Phaser;
this.cameras = new Phaser.CameraManager(this._game, 0, 0, width, height);
this.group = new Phaser.Group(this._game, 0);
this.bounds = new Phaser.Rectangle(0, 0, width, height);
+ this.physics = new Phaser.Physics.PhysicsManager(this._game, width, height);
this.worldDivisions = 6;
}
World.prototype.update = /**
* This is called automatically every frame, and is where main logic happens.
*/
function () {
+ this.physics.update();
this.group.update();
this.cameras.update();
};
@@ -7691,6 +8004,7 @@ var Phaser;
* Clean up memory.
*/
function () {
+ //this.physics.destroy();
this.group.destroy();
this.cameras.destroy();
};
@@ -7701,13 +8015,17 @@ var Phaser;
* @param height {number} New height of the world.
* @param [updateCameraBounds] {boolean} Update camera bounds automatically or not. Default to true.
*/
- function (width, height, updateCameraBounds) {
+ function (width, height, updateCameraBounds, updatePhysicsBounds) {
if (typeof updateCameraBounds === "undefined") { updateCameraBounds = true; }
+ if (typeof updatePhysicsBounds === "undefined") { updatePhysicsBounds = true; }
this.bounds.width = width;
this.bounds.height = height;
if(updateCameraBounds == true) {
this._game.camera.setBounds(0, 0, width, height);
}
+ if(updatePhysicsBounds == true) {
+ //this.physics.bounds.copyFrom(this.bounds);
+ }
// dispatch world resize event
};
Object.defineProperty(World.prototype, "width", {
@@ -10461,6 +10779,8 @@ var Phaser;
this._game.world.group.render(this, this._camera);
this._camera.postRender();
}
+ // Physics Debug layer
+ this._game.world.physics.render();
};
CanvasRenderer.prototype.renderSprite = /**
* Render this sprite to specific camera. Called by game loop after update().
@@ -10507,14 +10827,6 @@ var Phaser;
this._dy += sprite.animations.currentFrame.spriteSourceSizeY;
}
}
- // Apply camera difference - looks like this is already applied?
- /*
- if (sprite.scrollFactor.x !== 1 || sprite.scrollFactor.y !== 1)
- {
- //this._dx -= (camera.worldView.x * this.scrollFactor.x);
- //this._dy -= (camera.worldView.y * this.scrollFactor.y);
- }
- */
// Rotation and Flipped
if(sprite.modified) {
if(sprite.texture.renderRotation == true && (sprite.rotation !== 0 || sprite.rotationOffset !== 0)) {
@@ -11027,353 +11339,304 @@ var Phaser;
})(Phaser || (Phaser = {}));
///
/**
-* Phaser - Point
+* Phaser - Vec2
*
-* The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
+* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
*/
var Phaser;
(function (Phaser) {
- var Point = (function () {
+ var Vec2 = (function () {
/**
- * Creates a new Point. If you pass no parameters a Point is created set to (0,0).
- * @class Point
+ * Creates a new Vec2 object.
+ * @class Vec2
* @constructor
- * @param {Number} x The horizontal position of this Point (default 0)
- * @param {Number} y The vertical position of this Point (default 0)
+ * @param {Number} x The x position of the vector
+ * @param {Number} y The y position of the vector
+ * @return {Vec2} This object
**/
- function Point(x, y) {
+ function Vec2(x, y) {
if (typeof x === "undefined") { x = 0; }
if (typeof y === "undefined") { y = 0; }
this.x = x;
this.y = y;
}
- Point.prototype.copyFrom = /**
- * Copies the x and y properties from any given object to this Point.
+ Vec2.prototype.copyFrom = /**
+ * Copies the x and y properties from any given object to this Vec2.
* @method copyFrom
* @param {any} source - The object to copy from.
- * @return {Point} This Point object.
+ * @return {Vec2} This Vec2 object.
**/
function (source) {
return this.setTo(source.x, source.y);
};
- Point.prototype.invert = /**
- * Inverts the x and y values of this Point
- * @method invert
- * @return {Point} This Point object.
- **/
- function () {
- return this.setTo(this.y, this.x);
- };
- Point.prototype.setTo = /**
- * Sets the x and y values of this MicroPoint object to the given coordinates.
- * @method setTo
- * @param {Number} x - The horizontal position of this point.
- * @param {Number} y - The vertical position of this point.
- * @return {MicroPoint} This MicroPoint object. Useful for chaining method calls.
+ Vec2.prototype.setTo = /**
+ * Sets the x and y properties of the Vector.
+ * @param {Number} x The x position of the vector
+ * @param {Number} y The y position of the vector
+ * @return {Vec2} This object
**/
function (x, y) {
this.x = x;
this.y = y;
return this;
};
- Point.prototype.toString = /**
+ Vec2.prototype.add = /**
+ * Add another vector to this one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ function (a) {
+ this.x += a.x;
+ this.y += a.y;
+ return this;
+ };
+ Vec2.prototype.subtract = /**
+ * Subtract another vector from this one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ function (v) {
+ this.x -= v.x;
+ this.y -= v.y;
+ return this;
+ };
+ Vec2.prototype.multiply = /**
+ * Multiply another vector with this one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ function (v) {
+ this.x *= v.x;
+ this.y *= v.y;
+ return this;
+ };
+ Vec2.prototype.divide = /**
+ * Divide this vector by another one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ function (v) {
+ this.x /= v.x;
+ this.y /= v.y;
+ return this;
+ };
+ Vec2.prototype.length = /**
+ * Get the length of this vector.
+ *
+ * @return {number} The length of this vector.
+ */
+ function () {
+ return Math.sqrt((this.x * this.x) + (this.y * this.y));
+ };
+ Vec2.prototype.lengthSq = /**
+ * Get the length squared of this vector.
+ *
+ * @return {number} The length^2 of this vector.
+ */
+ function () {
+ return (this.x * this.x) + (this.y * this.y);
+ };
+ Vec2.prototype.dot = /**
+ * The dot product of two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function (a) {
+ return ((this.x * a.x) + (this.y * a.y));
+ };
+ Vec2.prototype.cross = /**
+ * The cross product of two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function (a) {
+ return ((this.x * a.y) - (this.y * a.x));
+ };
+ Vec2.prototype.projectionLength = /**
+ * The projection magnitude of two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function (a) {
+ var den = a.dot(a);
+ if(den == 0) {
+ return 0;
+ } else {
+ return Math.abs(this.dot(a) / den);
+ }
+ };
+ Vec2.prototype.angle = /**
+ * The angle between two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function (a) {
+ return Math.atan2(a.x * this.y - a.y * this.x, a.x * this.x + a.y * this.y);
+ };
+ Vec2.prototype.scale = /**
+ * Scale this vector.
+ *
+ * @param {number} x The scaling factor in the x direction.
+ * @param {?number=} y The scaling factor in the y direction. If this is not specified, the x scaling factor will be used.
+ * @return {Vec2} This for chaining.
+ */
+ function (x, y) {
+ this.x *= x;
+ this.y *= y || x;
+ return this;
+ };
+ Vec2.prototype.divideByScalar = /**
+ * Divide this vector by the given scalar.
+ *
+ * @param {number} scalar
+ * @return {Vec2} This for chaining.
+ */
+ function (scalar) {
+ this.x /= scalar;
+ this.y /= scalar;
+ return this;
+ };
+ Vec2.prototype.reverse = /**
+ * Reverse this vector.
+ *
+ * @return {Vec2} This for chaining.
+ */
+ function () {
+ this.x = -this.x;
+ this.y = -this.y;
+ return this;
+ };
+ Vec2.prototype.equals = /**
+ * Check if both the x and y of this vector equal the given value.
+ *
+ * @return {Boolean}
+ */
+ function (value) {
+ return (this.x == value && this.y == value);
+ };
+ Vec2.prototype.toString = /**
* Returns a string representation of this object.
* @method toString
- * @return {string} a string representation of the instance.
+ * @return {string} a string representation of the object.
**/
function () {
- return '[{Point (x=' + this.x + ' y=' + this.y + ')}]';
+ return "[{Vec2 (x=" + this.x + " y=" + this.y + ")}]";
};
- return Point;
+ return Vec2;
})();
- Phaser.Point = Point;
+ Phaser.Vec2 = Vec2;
})(Phaser || (Phaser = {}));
-///
-/**
-* Rectangle
-*
-* @desc A Rectangle object is an area defined by its position, as indicated by its top-left corner (x,y) and width and height.
-*
-* @version 1.6 - 24th May 2013
-* @author Richard Davey
-*/
var Phaser;
(function (Phaser) {
- var Rectangle = (function () {
- /**
- * Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a rectangle with x, y, width, and height properties set to 0 is created.
- * @class Rectangle
- * @constructor
- * @param {Number} x The x coordinate of the top-left corner of the rectangle.
- * @param {Number} y The y coordinate of the top-left corner of the rectangle.
- * @param {Number} width The width of the rectangle in pixels.
- * @param {Number} height The height of the rectangle in pixels.
- * @return {Rectangle} This rectangle object
- **/
- function Rectangle(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; }
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- }
- Object.defineProperty(Rectangle.prototype, "halfWidth", {
- get: /**
- * Half of the width of the rectangle
- * @property halfWidth
- * @type Number
- **/
+ ///
+ ///
+ ///
+ /**
+ * Phaser - Components - Physics
+ *
+ *
+ */
+ (function (Components) {
+ var Physics = (function () {
+ function Physics(parent) {
+ /**
+ * Set this to false if you want to skip the automatic motion/movement stuff
+ * (see updateMotion()).
+ * @type {boolean}
+ */
+ this.moves = true;
+ this._game = parent.game;
+ this._sprite = parent;
+ //this.AABB = new Phaser.Physics.AABB(this._game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height);
+ this.AABB = this._game.world.physics.add(new Phaser.Physics.AABB(this._game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height));
+ }
+ Physics.prototype.update = /**
+ * Handy for checking if this object is touching a particular surface.
+ * For slightly better performance you can just & the value directly into touching.
+ * However, this method is good for readability and accessibility.
+ *
+ * @param Direction {number} Any of the collision flags (e.g. LEFT, FLOOR, etc).
+ *
+ * @return {boolean} Whether the object is touching an object in (any of) the specified direction(s) this frame.
+ */
+ //public isTouching(direction: number): bool {
+ // return (this.touching & direction) > Collision.NONE;
+ //}
+ /**
+ * Handy function for checking if this object just landed on a particular surface.
+ *
+ * @param Direction {number} Any of the collision flags (e.g. LEFT, FLOOR, etc).
+ *
+ * @returns {boolean} Whether the object just landed on any specicied surfaces.
+ */
+ //public justTouched(direction: number): bool {
+ // return ((this.touching & direction) > Collision.NONE) && ((this.wasTouching & direction) <= Collision.NONE);
+ //}
+ /**
+ * Internal function for updating the position and speed of this object.
+ */
function () {
- return Math.round(this.width / 2);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "halfHeight", {
- get: /**
- * Half of the height of the rectangle
- * @property halfHeight
- * @type Number
- **/
- function () {
- return Math.round(this.height / 2);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "bottom", {
- get: /**
- * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
- * @method bottom
- * @return {Number}
- **/
- function () {
- return this.y + this.height;
- },
- set: /**
- * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
- * @method bottom
- * @param {Number} value
- **/
- function (value) {
- if(value <= this.y) {
- this.height = 0;
- } else {
- this.height = (this.y - value);
+ if(this.moves) {
+ this._sprite.x = this.AABB.position.x - this.AABB.halfWidth;
+ this._sprite.y = this.AABB.position.y - this.AABB.halfHeight;
}
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "bottomRight", {
- set: /**
- * Sets the bottom-right corner of the Rectangle, determined by the values of the given Point object.
- * @method bottomRight
- * @param {Point} value
- **/
- function (value) {
- this.right = value.x;
- this.bottom = value.y;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "left", {
- get: /**
- * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
- * @method left
- * @ return {number}
- **/
- function () {
- return this.x;
- },
- set: /**
- * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties.
- * However it does affect the width, whereas changing the x value does not affect the width property.
- * @method left
- * @param {Number} value
- **/
- function (value) {
- if(value >= this.right) {
- this.width = 0;
- } else {
- this.width = this.right - value;
- }
- this.x = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "right", {
- get: /**
- * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
- * However it does affect the width property.
- * @method right
- * @return {Number}
- **/
- function () {
- return this.x + this.width;
- },
- set: /**
- * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
- * However it does affect the width property.
- * @method right
- * @param {Number} value
- **/
- function (value) {
- if(value <= this.x) {
- this.width = 0;
- } else {
- this.width = this.x + value;
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "volume", {
- get: /**
- * The volume of the Rectangle derived from width * height
- * @method volume
- * @return {Number}
- **/
- function () {
- return this.width * this.height;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "perimeter", {
- get: /**
- * The perimeter size of the Rectangle. This is the sum of all 4 sides.
- * @method perimeter
- * @return {Number}
- **/
- function () {
- return (this.width * 2) + (this.height * 2);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "top", {
- get: /**
- * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
- * However it does affect the height property, whereas changing the y value does not affect the height property.
- * @method top
- * @return {Number}
- **/
- function () {
- return this.y;
- },
- set: /**
- * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
- * However it does affect the height property, whereas changing the y value does not affect the height property.
- * @method top
- * @param {Number} value
- **/
- function (value) {
- if(value >= this.bottom) {
- this.height = 0;
- this.y = value;
- } else {
- this.height = (this.bottom - value);
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "topLeft", {
- set: /**
- * The location of the Rectangles top-left corner, determined by the x and y coordinates of the Point.
- * @method topLeft
- * @param {Point} value
- **/
- function (value) {
- this.x = value.x;
- this.y = value.y;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "empty", {
- get: /**
- * Determines whether or not this Rectangle object is empty.
- * @method isEmpty
- * @return {Boolean} A value of true if the Rectangle object's width or height is less than or equal to 0; otherwise false.
- **/
- function () {
- return (!this.width || !this.height);
- },
- set: /**
- * Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0.
- * @method setEmpty
- * @return {Rectangle} This rectangle object
- **/
- function (value) {
- return this.setTo(0, 0, 0, 0);
- },
- enumerable: true,
- configurable: true
- });
- Rectangle.prototype.offset = /**
- * Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
- * @method offset
- * @param {Number} dx Moves the x value of the Rectangle object by this amount.
- * @param {Number} dy Moves the y value of the Rectangle object by this amount.
- * @return {Rectangle} This Rectangle object.
- **/
- function (dx, dy) {
- this.x += dx;
- this.y += dy;
- return this;
- };
- Rectangle.prototype.offsetPoint = /**
- * Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
- * @method offsetPoint
- * @param {Point} point A Point object to use to offset this Rectangle object.
- * @return {Rectangle} This Rectangle object.
- **/
- function (point) {
- return this.offset(point.x, point.y);
- };
- Rectangle.prototype.setTo = /**
- * Sets the members of Rectangle to the specified values.
- * @method setTo
- * @param {Number} x The x coordinate of the top-left corner of the rectangle.
- * @param {Number} y The y coordinate of the top-left corner of the rectangle.
- * @param {Number} width The width of the rectangle in pixels.
- * @param {Number} height The height of the rectangle in pixels.
- * @return {Rectangle} This rectangle object
- **/
- function (x, y, width, height) {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- return this;
- };
- Rectangle.prototype.copyFrom = /**
- * Copies the x, y, width and height properties from any given object to this Rectangle.
- * @method copyFrom
- * @param {any} source - The object to copy from.
- * @return {Rectangle} This Rectangle object.
- **/
- function (source) {
- return this.setTo(source.x, source.y, source.width, source.height);
- };
- Rectangle.prototype.toString = /**
- * Returns a string representation of this object.
- * @method toString
- * @return {string} a string representation of the instance.
- **/
- function () {
- return "[{Rectangle (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + " empty=" + this.empty + ")}]";
- };
- return Rectangle;
- })();
- Phaser.Rectangle = Rectangle;
+ /*
+ var delta: number;
+ var velocityDelta: number;
+
+ velocityDelta = (this._game.motion.computeVelocity(this.angularVelocity, this.angularAcceleration, this.angularDrag, this.maxAngular) - this.angularVelocity) / 2;
+ this.angularVelocity += velocityDelta;
+ this._angle += this.angularVelocity * this._game.time.elapsed;
+ this.angularVelocity += velocityDelta;
+
+ velocityDelta = (this._game.motion.computeVelocity(this.velocity.x, this.acceleration.x, this.drag.x, this.maxVelocity.x) - this.velocity.x) / 2;
+ this.velocity.x += velocityDelta;
+ delta = this.velocity.x * this._game.time.elapsed;
+ this.velocity.x += velocityDelta;
+ this.frameBounds.x += delta;
+
+ velocityDelta = (this._game.motion.computeVelocity(this.velocity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y) - this.velocity.y) / 2;
+ this.velocity.y += velocityDelta;
+ delta = this.velocity.y * this._game.time.elapsed;
+ this.velocity.y += velocityDelta;
+ this.frameBounds.y += delta;
+ */
+ };
+ Object.defineProperty(Physics.prototype, "solid", {
+ set: /**
+ * Whether the object collides or not. For more control over what directions
+ * the object will collide from, use collision constants (like LEFT, FLOOR, etc)
+ * to set the value of allowCollisions directly.
+ */
+ //public get solid(): bool {
+ // return (this.allowCollisions & Collision.ANY) > Collision.NONE;
+ //}
+ function (value) {
+ //if (value)
+ //{
+ // this.allowCollisions = Collision.ANY;
+ //}
+ //else
+ //{
+ // this.allowCollisions = Collision.NONE;
+ //}
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Physics;
+ })();
+ Components.Physics = Physics;
+ })(Phaser.Components || (Phaser.Components = {}));
+ var Components = Phaser.Components;
})(Phaser || (Phaser = {}));
///
///
diff --git a/Tests/physics/aabb 1.js b/Tests/physics/aabb 1.js
new file mode 100644
index 00000000..2e5de471
--- /dev/null
+++ b/Tests/physics/aabb 1.js
@@ -0,0 +1,17 @@
+///
+(function () {
+ var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
+ function init() {
+ // Using Phasers asset loader we load up a PNG from the assets folder
+ game.loader.addImageFile('bunny', 'assets/sprites/atari800xl.png');
+ game.loader.load();
+ }
+ var atari;
+ function create() {
+ atari = game.add.sprite(200, 200, 'bunny');
+ //game.add.physicsAABB(200, 200, 233, 99);
+ }
+ function update() {
+ //atari.y += 0.2;
+ }
+})();
diff --git a/Tests/physics/aabb 1.ts b/Tests/physics/aabb 1.ts
new file mode 100644
index 00000000..7e899372
--- /dev/null
+++ b/Tests/physics/aabb 1.ts
@@ -0,0 +1,26 @@
+///
+
+(function () {
+
+ var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
+
+ function init() {
+
+ // Using Phasers asset loader we load up a PNG from the assets folder
+ game.loader.addImageFile('atari', 'assets/sprites/atari800xl.png');
+ game.loader.load();
+
+ }
+
+ var atari: Phaser.Sprite;
+
+ function create() {
+
+ atari = game.add.sprite(200, 200, 'atari');
+
+ }
+
+ function update() {
+ }
+
+})();
diff --git a/build/phaser.d.ts b/build/phaser.d.ts
index 274391d1..72539344 100644
--- a/build/phaser.d.ts
+++ b/build/phaser.d.ts
@@ -949,146 +949,228 @@ module Phaser {
}
}
/**
-* Phaser - Vec2
+* Phaser - Point
*
-* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
+* The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
*/
module Phaser {
- class Vec2 {
+ class Point {
/**
- * Creates a new Vec2 object.
- * @class Vec2
+ * Creates a new Point. If you pass no parameters a Point is created set to (0,0).
+ * @class Point
* @constructor
- * @param {Number} x The x position of the vector
- * @param {Number} y The y position of the vector
- * @return {Vec2} This object
+ * @param {Number} x The horizontal position of this Point (default 0)
+ * @param {Number} y The vertical position of this Point (default 0)
**/
constructor(x?: number, y?: number);
+ public x: number;
+ public y: number;
/**
- * The x coordinate of the vector
+ * Copies the x and y properties from any given object to this Point.
+ * @method copyFrom
+ * @param {any} source - The object to copy from.
+ * @return {Point} This Point object.
+ **/
+ public copyFrom(source: any): Point;
+ /**
+ * Inverts the x and y values of this Point
+ * @method invert
+ * @return {Point} This Point object.
+ **/
+ public invert(): Point;
+ /**
+ * Sets the x and y values of this MicroPoint object to the given coordinates.
+ * @method setTo
+ * @param {Number} x - The horizontal position of this point.
+ * @param {Number} y - The vertical position of this point.
+ * @return {MicroPoint} This MicroPoint object. Useful for chaining method calls.
+ **/
+ public setTo(x: number, y: number): Point;
+ /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the instance.
+ **/
+ public toString(): string;
+ }
+}
+/**
+* Rectangle
+*
+* @desc A Rectangle object is an area defined by its position, as indicated by its top-left corner (x,y) and width and height.
+*
+* @version 1.6 - 24th May 2013
+* @author Richard Davey
+*/
+module Phaser {
+ class Rectangle {
+ /**
+ * Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a rectangle with x, y, width, and height properties set to 0 is created.
+ * @class Rectangle
+ * @constructor
+ * @param {Number} x The x coordinate of the top-left corner of the rectangle.
+ * @param {Number} y The y coordinate of the top-left corner of the rectangle.
+ * @param {Number} width The width of the rectangle in pixels.
+ * @param {Number} height The height of the rectangle in pixels.
+ * @return {Rectangle} This rectangle object
+ **/
+ constructor(x?: number, y?: number, width?: number, height?: number);
+ /**
+ * The x coordinate of the top-left corner of the rectangle
* @property x
* @type Number
**/
public x: number;
/**
- * The y coordinate of the vector
+ * The y coordinate of the top-left corner of the rectangle
* @property y
* @type Number
**/
public y: number;
/**
- * Copies the x and y properties from any given object to this Vec2.
+ * The width of the rectangle in pixels
+ * @property width
+ * @type Number
+ **/
+ public width: number;
+ /**
+ * The height of the rectangle in pixels
+ * @property height
+ * @type Number
+ **/
+ public height: number;
+ /**
+ * Half of the width of the rectangle
+ * @property halfWidth
+ * @type Number
+ **/
+ public halfWidth : number;
+ /**
+ * Half of the height of the rectangle
+ * @property halfHeight
+ * @type Number
+ **/
+ public halfHeight : number;
+ /**
+ * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
+ * @method bottom
+ * @return {Number}
+ **/
+ /**
+ * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
+ * @method bottom
+ * @param {Number} value
+ **/
+ public bottom : number;
+ /**
+ * Sets the bottom-right corner of the Rectangle, determined by the values of the given Point object.
+ * @method bottomRight
+ * @param {Point} value
+ **/
+ public bottomRight : Point;
+ /**
+ * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
+ * @method left
+ * @ return {number}
+ **/
+ /**
+ * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties.
+ * However it does affect the width, whereas changing the x value does not affect the width property.
+ * @method left
+ * @param {Number} value
+ **/
+ public left : number;
+ /**
+ * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
+ * However it does affect the width property.
+ * @method right
+ * @return {Number}
+ **/
+ /**
+ * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
+ * However it does affect the width property.
+ * @method right
+ * @param {Number} value
+ **/
+ public right : number;
+ /**
+ * The volume of the Rectangle derived from width * height
+ * @method volume
+ * @return {Number}
+ **/
+ public volume : number;
+ /**
+ * The perimeter size of the Rectangle. This is the sum of all 4 sides.
+ * @method perimeter
+ * @return {Number}
+ **/
+ public perimeter : number;
+ /**
+ * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
+ * However it does affect the height property, whereas changing the y value does not affect the height property.
+ * @method top
+ * @return {Number}
+ **/
+ /**
+ * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
+ * However it does affect the height property, whereas changing the y value does not affect the height property.
+ * @method top
+ * @param {Number} value
+ **/
+ public top : number;
+ /**
+ * The location of the Rectangles top-left corner, determined by the x and y coordinates of the Point.
+ * @method topLeft
+ * @param {Point} value
+ **/
+ public topLeft : Point;
+ /**
+ * Determines whether or not this Rectangle object is empty.
+ * @method isEmpty
+ * @return {Boolean} A value of true if the Rectangle object's width or height is less than or equal to 0; otherwise false.
+ **/
+ /**
+ * Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0.
+ * @method setEmpty
+ * @return {Rectangle} This rectangle object
+ **/
+ public empty : bool;
+ /**
+ * Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
+ * @method offset
+ * @param {Number} dx Moves the x value of the Rectangle object by this amount.
+ * @param {Number} dy Moves the y value of the Rectangle object by this amount.
+ * @return {Rectangle} This Rectangle object.
+ **/
+ public offset(dx: number, dy: number): Rectangle;
+ /**
+ * Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
+ * @method offsetPoint
+ * @param {Point} point A Point object to use to offset this Rectangle object.
+ * @return {Rectangle} This Rectangle object.
+ **/
+ public offsetPoint(point: Point): Rectangle;
+ /**
+ * Sets the members of Rectangle to the specified values.
+ * @method setTo
+ * @param {Number} x The x coordinate of the top-left corner of the rectangle.
+ * @param {Number} y The y coordinate of the top-left corner of the rectangle.
+ * @param {Number} width The width of the rectangle in pixels.
+ * @param {Number} height The height of the rectangle in pixels.
+ * @return {Rectangle} This rectangle object
+ **/
+ public setTo(x: number, y: number, width: number, height: number): Rectangle;
+ /**
+ * Copies the x, y, width and height properties from any given object to this Rectangle.
* @method copyFrom
* @param {any} source - The object to copy from.
- * @return {Vec2} This Vec2 object.
+ * @return {Rectangle} This Rectangle object.
**/
- public copyFrom(source: any): Vec2;
- /**
- * Sets the x and y properties of the Vector.
- * @param {Number} x The x position of the vector
- * @param {Number} y The y position of the vector
- * @return {Vec2} This object
- **/
- public setTo(x: number, y: number): Vec2;
- /**
- * Add another vector to this one.
- *
- * @param {Vec2} other The other Vector.
- * @return {Vec2} This for chaining.
- */
- public add(a: Vec2): Vec2;
- /**
- * Subtract another vector from this one.
- *
- * @param {Vec2} other The other Vector.
- * @return {Vec2} This for chaining.
- */
- public subtract(v: Vec2): Vec2;
- /**
- * Multiply another vector with this one.
- *
- * @param {Vec2} other The other Vector.
- * @return {Vec2} This for chaining.
- */
- public multiply(v: Vec2): Vec2;
- /**
- * Divide this vector by another one.
- *
- * @param {Vec2} other The other Vector.
- * @return {Vec2} This for chaining.
- */
- public divide(v: Vec2): Vec2;
- /**
- * Get the length of this vector.
- *
- * @return {number} The length of this vector.
- */
- public length(): number;
- /**
- * Get the length squared of this vector.
- *
- * @return {number} The length^2 of this vector.
- */
- public lengthSq(): number;
- /**
- * The dot product of two 2D vectors.
- *
- * @param {Vec2} a Reference to a source Vec2 object.
- * @return {Number}
- */
- public dot(a: Vec2): number;
- /**
- * The cross product of two 2D vectors.
- *
- * @param {Vec2} a Reference to a source Vec2 object.
- * @return {Number}
- */
- public cross(a: Vec2): number;
- /**
- * The projection magnitude of two 2D vectors.
- *
- * @param {Vec2} a Reference to a source Vec2 object.
- * @return {Number}
- */
- public projectionLength(a: Vec2): number;
- /**
- * The angle between two 2D vectors.
- *
- * @param {Vec2} a Reference to a source Vec2 object.
- * @return {Number}
- */
- public angle(a: Vec2): number;
- /**
- * Scale this vector.
- *
- * @param {number} x The scaling factor in the x direction.
- * @param {?number=} y The scaling factor in the y direction. If this is not specified, the x scaling factor will be used.
- * @return {Vec2} This for chaining.
- */
- public scale(x: number, y?: number): Vec2;
- /**
- * Divide this vector by the given scalar.
- *
- * @param {number} scalar
- * @return {Vec2} This for chaining.
- */
- public divideByScalar(scalar: number): Vec2;
- /**
- * Reverse this vector.
- *
- * @return {Vec2} This for chaining.
- */
- public reverse(): Vec2;
- /**
- * Check if both the x and y of this vector equal the given value.
- *
- * @return {Boolean}
- */
- public equals(value): bool;
+ public copyFrom(source: any): Rectangle;
/**
* Returns a string representation of this object.
* @method toString
- * @return {string} a string representation of the object.
+ * @return {string} a string representation of the instance.
**/
public toString(): string;
}
@@ -2221,6 +2303,10 @@ module Phaser {
public width: number;
public height: number;
/**
+ * Sprite physics.
+ */
+ public physics: Components.Physics;
+ /**
* The texture used to render the Sprite.
*/
public texture: Components.Texture;
@@ -2933,6 +3019,63 @@ module Phaser {
}
}
/**
+* Phaser - PhysicsManager
+*
+* Your game only has one PhysicsManager instance and it's responsible for looking after, creating and colliding
+* all of the physics objects in the world.
+*/
+module Phaser.Physics {
+ class PhysicsManager {
+ constructor(game: Game, width: number, height: number);
+ /**
+ * Local private reference to Game.
+ */
+ private _game;
+ private _objects;
+ public bounds: Rectangle;
+ public gravity: Vec2;
+ public drag: Vec2;
+ public bounce: Vec2;
+ public friction: Vec2;
+ private minFriction;
+ private maxFriction;
+ private minBounce;
+ private maxBounce;
+ private minGravity;
+ private maxGravity;
+ private _i;
+ private _length;
+ public add(o);
+ public update(): void;
+ public render(): void;
+ }
+}
+/**
+* Phaser - Physics - AABB
+*/
+module Phaser.Physics {
+ class AABB {
+ constructor(game: Game, sprite: Sprite, x: number, y: number, width: number, height: number);
+ /**
+ * Local private reference to Game.
+ */
+ public game: Game;
+ public world: PhysicsManager;
+ public sprite: Sprite;
+ public position: Vec2;
+ public oldPosition: Vec2;
+ public width: number;
+ public height: number;
+ public halfWidth: number;
+ public halfHeight: number;
+ public update(): void;
+ private integrate();
+ private collideWorld();
+ private processWorld(px, py, dx, dy, tile);
+ public render(context: CanvasRenderingContext2D): void;
+ }
+}
+/**
* Phaser - GameObjectFactory
*
* A quick way to create new world objects and add existing objects to the current world.
@@ -2987,6 +3130,16 @@ module Phaser {
*/
public group(maxSize?: number): Group;
/**
+ * Create a new Sprite with specific position and sprite sheet key.
+ *
+ * @param x {number} X position of the new sprite.
+ * @param y {number} Y position of the new sprite.
+ * @param key {string} Optional, key for the sprite sheet you want it to use.
+ * @returns {Sprite} The newly created sprite object.
+ * WILL NEED TO TRACK A SPRITE
+ */
+ public physicsAABB(x: number, y: number, width: number, height: number): Physics.AABB;
+ /**
* Create a tween object for a specific object.
*
* @param obj Object you wish the tween will affect.
@@ -4291,6 +4444,11 @@ module Phaser {
*/
public bounds: Rectangle;
/**
+ * Reference to the physics manager.
+ * @type {Physics.PhysicsManager}
+ */
+ public physics: Physics.PhysicsManager;
+ /**
* @type {number}
*/
public worldDivisions: number;
@@ -4309,7 +4467,7 @@ module Phaser {
* @param height {number} New height of the world.
* @param [updateCameraBounds] {boolean} Update camera bounds automatically or not. Default to true.
*/
- public setSize(width: number, height: number, updateCameraBounds?: bool): void;
+ public setSize(width: number, height: number, updateCameraBounds?: bool, updatePhysicsBounds?: bool): void;
public width : number;
public height : number;
public centerX : number;
@@ -6102,233 +6260,265 @@ module Phaser {
}
}
/**
-* Phaser - Point
+* Phaser - Vec2
*
-* The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
+* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
*/
module Phaser {
- class Point {
+ class Vec2 {
/**
- * Creates a new Point. If you pass no parameters a Point is created set to (0,0).
- * @class Point
+ * Creates a new Vec2 object.
+ * @class Vec2
* @constructor
- * @param {Number} x The horizontal position of this Point (default 0)
- * @param {Number} y The vertical position of this Point (default 0)
+ * @param {Number} x The x position of the vector
+ * @param {Number} y The y position of the vector
+ * @return {Vec2} This object
**/
constructor(x?: number, y?: number);
- public x: number;
- public y: number;
/**
- * Copies the x and y properties from any given object to this Point.
- * @method copyFrom
- * @param {any} source - The object to copy from.
- * @return {Point} This Point object.
- **/
- public copyFrom(source: any): Point;
- /**
- * Inverts the x and y values of this Point
- * @method invert
- * @return {Point} This Point object.
- **/
- public invert(): Point;
- /**
- * Sets the x and y values of this MicroPoint object to the given coordinates.
- * @method setTo
- * @param {Number} x - The horizontal position of this point.
- * @param {Number} y - The vertical position of this point.
- * @return {MicroPoint} This MicroPoint object. Useful for chaining method calls.
- **/
- public setTo(x: number, y: number): Point;
- /**
- * Returns a string representation of this object.
- * @method toString
- * @return {string} a string representation of the instance.
- **/
- public toString(): string;
- }
-}
-/**
-* Rectangle
-*
-* @desc A Rectangle object is an area defined by its position, as indicated by its top-left corner (x,y) and width and height.
-*
-* @version 1.6 - 24th May 2013
-* @author Richard Davey
-*/
-module Phaser {
- class Rectangle {
- /**
- * Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a rectangle with x, y, width, and height properties set to 0 is created.
- * @class Rectangle
- * @constructor
- * @param {Number} x The x coordinate of the top-left corner of the rectangle.
- * @param {Number} y The y coordinate of the top-left corner of the rectangle.
- * @param {Number} width The width of the rectangle in pixels.
- * @param {Number} height The height of the rectangle in pixels.
- * @return {Rectangle} This rectangle object
- **/
- constructor(x?: number, y?: number, width?: number, height?: number);
- /**
- * The x coordinate of the top-left corner of the rectangle
+ * The x coordinate of the vector
* @property x
* @type Number
**/
public x: number;
/**
- * The y coordinate of the top-left corner of the rectangle
+ * The y coordinate of the vector
* @property y
* @type Number
**/
public y: number;
/**
- * The width of the rectangle in pixels
- * @property width
- * @type Number
- **/
- public width: number;
- /**
- * The height of the rectangle in pixels
- * @property height
- * @type Number
- **/
- public height: number;
- /**
- * Half of the width of the rectangle
- * @property halfWidth
- * @type Number
- **/
- public halfWidth : number;
- /**
- * Half of the height of the rectangle
- * @property halfHeight
- * @type Number
- **/
- public halfHeight : number;
- /**
- * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
- * @method bottom
- * @return {Number}
- **/
- /**
- * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
- * @method bottom
- * @param {Number} value
- **/
- public bottom : number;
- /**
- * Sets the bottom-right corner of the Rectangle, determined by the values of the given Point object.
- * @method bottomRight
- * @param {Point} value
- **/
- public bottomRight : Point;
- /**
- * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
- * @method left
- * @ return {number}
- **/
- /**
- * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties.
- * However it does affect the width, whereas changing the x value does not affect the width property.
- * @method left
- * @param {Number} value
- **/
- public left : number;
- /**
- * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
- * However it does affect the width property.
- * @method right
- * @return {Number}
- **/
- /**
- * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
- * However it does affect the width property.
- * @method right
- * @param {Number} value
- **/
- public right : number;
- /**
- * The volume of the Rectangle derived from width * height
- * @method volume
- * @return {Number}
- **/
- public volume : number;
- /**
- * The perimeter size of the Rectangle. This is the sum of all 4 sides.
- * @method perimeter
- * @return {Number}
- **/
- public perimeter : number;
- /**
- * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
- * However it does affect the height property, whereas changing the y value does not affect the height property.
- * @method top
- * @return {Number}
- **/
- /**
- * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
- * However it does affect the height property, whereas changing the y value does not affect the height property.
- * @method top
- * @param {Number} value
- **/
- public top : number;
- /**
- * The location of the Rectangles top-left corner, determined by the x and y coordinates of the Point.
- * @method topLeft
- * @param {Point} value
- **/
- public topLeft : Point;
- /**
- * Determines whether or not this Rectangle object is empty.
- * @method isEmpty
- * @return {Boolean} A value of true if the Rectangle object's width or height is less than or equal to 0; otherwise false.
- **/
- /**
- * Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0.
- * @method setEmpty
- * @return {Rectangle} This rectangle object
- **/
- public empty : bool;
- /**
- * Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
- * @method offset
- * @param {Number} dx Moves the x value of the Rectangle object by this amount.
- * @param {Number} dy Moves the y value of the Rectangle object by this amount.
- * @return {Rectangle} This Rectangle object.
- **/
- public offset(dx: number, dy: number): Rectangle;
- /**
- * Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
- * @method offsetPoint
- * @param {Point} point A Point object to use to offset this Rectangle object.
- * @return {Rectangle} This Rectangle object.
- **/
- public offsetPoint(point: Point): Rectangle;
- /**
- * Sets the members of Rectangle to the specified values.
- * @method setTo
- * @param {Number} x The x coordinate of the top-left corner of the rectangle.
- * @param {Number} y The y coordinate of the top-left corner of the rectangle.
- * @param {Number} width The width of the rectangle in pixels.
- * @param {Number} height The height of the rectangle in pixels.
- * @return {Rectangle} This rectangle object
- **/
- public setTo(x: number, y: number, width: number, height: number): Rectangle;
- /**
- * Copies the x, y, width and height properties from any given object to this Rectangle.
+ * Copies the x and y properties from any given object to this Vec2.
* @method copyFrom
* @param {any} source - The object to copy from.
- * @return {Rectangle} This Rectangle object.
+ * @return {Vec2} This Vec2 object.
**/
- public copyFrom(source: any): Rectangle;
+ public copyFrom(source: any): Vec2;
+ /**
+ * Sets the x and y properties of the Vector.
+ * @param {Number} x The x position of the vector
+ * @param {Number} y The y position of the vector
+ * @return {Vec2} This object
+ **/
+ public setTo(x: number, y: number): Vec2;
+ /**
+ * Add another vector to this one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ public add(a: Vec2): Vec2;
+ /**
+ * Subtract another vector from this one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ public subtract(v: Vec2): Vec2;
+ /**
+ * Multiply another vector with this one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ public multiply(v: Vec2): Vec2;
+ /**
+ * Divide this vector by another one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ public divide(v: Vec2): Vec2;
+ /**
+ * Get the length of this vector.
+ *
+ * @return {number} The length of this vector.
+ */
+ public length(): number;
+ /**
+ * Get the length squared of this vector.
+ *
+ * @return {number} The length^2 of this vector.
+ */
+ public lengthSq(): number;
+ /**
+ * The dot product of two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ public dot(a: Vec2): number;
+ /**
+ * The cross product of two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ public cross(a: Vec2): number;
+ /**
+ * The projection magnitude of two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ public projectionLength(a: Vec2): number;
+ /**
+ * The angle between two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ public angle(a: Vec2): number;
+ /**
+ * Scale this vector.
+ *
+ * @param {number} x The scaling factor in the x direction.
+ * @param {?number=} y The scaling factor in the y direction. If this is not specified, the x scaling factor will be used.
+ * @return {Vec2} This for chaining.
+ */
+ public scale(x: number, y?: number): Vec2;
+ /**
+ * Divide this vector by the given scalar.
+ *
+ * @param {number} scalar
+ * @return {Vec2} This for chaining.
+ */
+ public divideByScalar(scalar: number): Vec2;
+ /**
+ * Reverse this vector.
+ *
+ * @return {Vec2} This for chaining.
+ */
+ public reverse(): Vec2;
+ /**
+ * Check if both the x and y of this vector equal the given value.
+ *
+ * @return {Boolean}
+ */
+ public equals(value): bool;
/**
* Returns a string representation of this object.
* @method toString
- * @return {string} a string representation of the instance.
+ * @return {string} a string representation of the object.
**/
public toString(): string;
}
}
/**
+* Phaser - Components - Physics
+*
+*
+*/
+module Phaser.Components {
+ class Physics {
+ constructor(parent: Sprite);
+ /**
+ *
+ */
+ private _game;
+ /**
+ *
+ */
+ private _sprite;
+ public AABB: Physics.AABB;
+ /**
+ * Whether this object will be moved by impacts with other objects or not.
+ * @type {boolean}
+ */
+ public immovable: bool;
+ /**
+ * Basic speed of this object.
+ *
+ * Velocity is given in pixels per second. Therefore a velocity of
+ * 100 will move at a rate of 100 pixels every 1000 ms (1sec). It's not balls-on
+ * accurate due to the way timers work, but it's pretty close. Expect tolerance
+ * of +- 10 px. Also that speed assumes no drag.
+ *
+ * @type {Vec2}
+ */
+ public velocity: Vec2;
+ /**
+ * The virtual mass of the object.
+ * @type {number}
+ */
+ public mass: number;
+ /**
+ * The bounciness of the object.
+ * @type {number}
+ */
+ public elasticity: number;
+ /**
+ * How fast the speed of this object is changing.
+ * @type {number}
+ */
+ public acceleration: Vec2;
+ /**
+ * This isn't drag exactly, more like deceleration that is only applied
+ * when acceleration is not affecting the sprite.
+ * @type {Vec2}
+ */
+ public drag: Vec2;
+ /**
+ * It will cap the speed automatically if you use the acceleration
+ * to change its velocity.
+ * @type {Vec2}
+ */
+ public maxVelocity: Vec2;
+ /**
+ * How fast this object is rotating.
+ * @type {number}
+ */
+ public angularVelocity: number;
+ /**
+ * How fast angularVelocity of this object is changing.
+ * @type {number}
+ */
+ public angularAcceleration: number;
+ /**
+ * Deacceleration of angularVelocity will be applied when it's rotating.
+ * @type {number}
+ */
+ public angularDrag: number;
+ /**
+ * It will cap the rotate speed automatically if you use the angularAcceleration
+ * to change its angularVelocity.
+ * @type {number}
+ */
+ public maxAngular: number;
+ /**
+ * Set this to false if you want to skip the automatic motion/movement stuff
+ * (see updateMotion()).
+ * @type {boolean}
+ */
+ public moves: bool;
+ /**
+ * Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts.
+ * @type {number}
+ */
+ public touching: number;
+ /**
+ * Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts from the previous game loop step.
+ * @type {number}
+ */
+ public wasTouching: number;
+ /**
+ * Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating collision directions.
+ * @type {number}
+ */
+ public allowCollisions: number;
+ /**
+ * Important variable for collision processing.
+ * @type {Vec2}
+ */
+ public last: Vec2;
+ /**
+ * Internal function for updating the position and speed of this object.
+ */
+ public update(): void;
+ public solid : bool;
+ }
+}
+/**
* Phaser - CircleUtils
*
* A collection of methods useful for manipulating and comparing Circle objects.
diff --git a/build/phaser.js b/build/phaser.js
index 4e614f9e..a9fd22a9 100644
--- a/build/phaser.js
+++ b/build/phaser.js
@@ -1811,200 +1811,353 @@ var Phaser;
})(Phaser || (Phaser = {}));
///
/**
-* Phaser - Vec2
+* Phaser - Point
*
-* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
+* The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
*/
var Phaser;
(function (Phaser) {
- var Vec2 = (function () {
+ var Point = (function () {
/**
- * Creates a new Vec2 object.
- * @class Vec2
+ * Creates a new Point. If you pass no parameters a Point is created set to (0,0).
+ * @class Point
* @constructor
- * @param {Number} x The x position of the vector
- * @param {Number} y The y position of the vector
- * @return {Vec2} This object
+ * @param {Number} x The horizontal position of this Point (default 0)
+ * @param {Number} y The vertical position of this Point (default 0)
**/
- function Vec2(x, y) {
+ function Point(x, y) {
if (typeof x === "undefined") { x = 0; }
if (typeof y === "undefined") { y = 0; }
this.x = x;
this.y = y;
}
- Vec2.prototype.copyFrom = /**
- * Copies the x and y properties from any given object to this Vec2.
+ Point.prototype.copyFrom = /**
+ * Copies the x and y properties from any given object to this Point.
* @method copyFrom
* @param {any} source - The object to copy from.
- * @return {Vec2} This Vec2 object.
+ * @return {Point} This Point object.
**/
function (source) {
return this.setTo(source.x, source.y);
};
- Vec2.prototype.setTo = /**
- * Sets the x and y properties of the Vector.
- * @param {Number} x The x position of the vector
- * @param {Number} y The y position of the vector
- * @return {Vec2} This object
+ Point.prototype.invert = /**
+ * Inverts the x and y values of this Point
+ * @method invert
+ * @return {Point} This Point object.
+ **/
+ function () {
+ return this.setTo(this.y, this.x);
+ };
+ Point.prototype.setTo = /**
+ * Sets the x and y values of this MicroPoint object to the given coordinates.
+ * @method setTo
+ * @param {Number} x - The horizontal position of this point.
+ * @param {Number} y - The vertical position of this point.
+ * @return {MicroPoint} This MicroPoint object. Useful for chaining method calls.
**/
function (x, y) {
this.x = x;
this.y = y;
return this;
};
- Vec2.prototype.add = /**
- * Add another vector to this one.
- *
- * @param {Vec2} other The other Vector.
- * @return {Vec2} This for chaining.
- */
- function (a) {
- this.x += a.x;
- this.y += a.y;
- return this;
- };
- Vec2.prototype.subtract = /**
- * Subtract another vector from this one.
- *
- * @param {Vec2} other The other Vector.
- * @return {Vec2} This for chaining.
- */
- function (v) {
- this.x -= v.x;
- this.y -= v.y;
- return this;
- };
- Vec2.prototype.multiply = /**
- * Multiply another vector with this one.
- *
- * @param {Vec2} other The other Vector.
- * @return {Vec2} This for chaining.
- */
- function (v) {
- this.x *= v.x;
- this.y *= v.y;
- return this;
- };
- Vec2.prototype.divide = /**
- * Divide this vector by another one.
- *
- * @param {Vec2} other The other Vector.
- * @return {Vec2} This for chaining.
- */
- function (v) {
- this.x /= v.x;
- this.y /= v.y;
- return this;
- };
- Vec2.prototype.length = /**
- * Get the length of this vector.
- *
- * @return {number} The length of this vector.
- */
- function () {
- return Math.sqrt((this.x * this.x) + (this.y * this.y));
- };
- Vec2.prototype.lengthSq = /**
- * Get the length squared of this vector.
- *
- * @return {number} The length^2 of this vector.
- */
- function () {
- return (this.x * this.x) + (this.y * this.y);
- };
- Vec2.prototype.dot = /**
- * The dot product of two 2D vectors.
- *
- * @param {Vec2} a Reference to a source Vec2 object.
- * @return {Number}
- */
- function (a) {
- return ((this.x * a.x) + (this.y * a.y));
- };
- Vec2.prototype.cross = /**
- * The cross product of two 2D vectors.
- *
- * @param {Vec2} a Reference to a source Vec2 object.
- * @return {Number}
- */
- function (a) {
- return ((this.x * a.y) - (this.y * a.x));
- };
- Vec2.prototype.projectionLength = /**
- * The projection magnitude of two 2D vectors.
- *
- * @param {Vec2} a Reference to a source Vec2 object.
- * @return {Number}
- */
- function (a) {
- var den = a.dot(a);
- if(den == 0) {
- return 0;
- } else {
- return Math.abs(this.dot(a) / den);
- }
- };
- Vec2.prototype.angle = /**
- * The angle between two 2D vectors.
- *
- * @param {Vec2} a Reference to a source Vec2 object.
- * @return {Number}
- */
- function (a) {
- return Math.atan2(a.x * this.y - a.y * this.x, a.x * this.x + a.y * this.y);
- };
- Vec2.prototype.scale = /**
- * Scale this vector.
- *
- * @param {number} x The scaling factor in the x direction.
- * @param {?number=} y The scaling factor in the y direction. If this is not specified, the x scaling factor will be used.
- * @return {Vec2} This for chaining.
- */
- function (x, y) {
- this.x *= x;
- this.y *= y || x;
- return this;
- };
- Vec2.prototype.divideByScalar = /**
- * Divide this vector by the given scalar.
- *
- * @param {number} scalar
- * @return {Vec2} This for chaining.
- */
- function (scalar) {
- this.x /= scalar;
- this.y /= scalar;
- return this;
- };
- Vec2.prototype.reverse = /**
- * Reverse this vector.
- *
- * @return {Vec2} This for chaining.
- */
- function () {
- this.x = -this.x;
- this.y = -this.y;
- return this;
- };
- Vec2.prototype.equals = /**
- * Check if both the x and y of this vector equal the given value.
- *
- * @return {Boolean}
- */
- function (value) {
- return (this.x == value && this.y == value);
- };
- Vec2.prototype.toString = /**
+ Point.prototype.toString = /**
* Returns a string representation of this object.
* @method toString
- * @return {string} a string representation of the object.
+ * @return {string} a string representation of the instance.
**/
function () {
- return "[{Vec2 (x=" + this.x + " y=" + this.y + ")}]";
+ return '[{Point (x=' + this.x + ' y=' + this.y + ')}]';
};
- return Vec2;
+ return Point;
})();
- Phaser.Vec2 = Vec2;
+ Phaser.Point = Point;
+})(Phaser || (Phaser = {}));
+///
+/**
+* Rectangle
+*
+* @desc A Rectangle object is an area defined by its position, as indicated by its top-left corner (x,y) and width and height.
+*
+* @version 1.6 - 24th May 2013
+* @author Richard Davey
+*/
+var Phaser;
+(function (Phaser) {
+ var Rectangle = (function () {
+ /**
+ * Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a rectangle with x, y, width, and height properties set to 0 is created.
+ * @class Rectangle
+ * @constructor
+ * @param {Number} x The x coordinate of the top-left corner of the rectangle.
+ * @param {Number} y The y coordinate of the top-left corner of the rectangle.
+ * @param {Number} width The width of the rectangle in pixels.
+ * @param {Number} height The height of the rectangle in pixels.
+ * @return {Rectangle} This rectangle object
+ **/
+ function Rectangle(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; }
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+ Object.defineProperty(Rectangle.prototype, "halfWidth", {
+ get: /**
+ * Half of the width of the rectangle
+ * @property halfWidth
+ * @type Number
+ **/
+ function () {
+ return Math.round(this.width / 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "halfHeight", {
+ get: /**
+ * Half of the height of the rectangle
+ * @property halfHeight
+ * @type Number
+ **/
+ function () {
+ return Math.round(this.height / 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "bottom", {
+ get: /**
+ * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
+ * @method bottom
+ * @return {Number}
+ **/
+ function () {
+ return this.y + this.height;
+ },
+ set: /**
+ * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
+ * @method bottom
+ * @param {Number} value
+ **/
+ function (value) {
+ if(value <= this.y) {
+ this.height = 0;
+ } else {
+ this.height = (this.y - value);
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "bottomRight", {
+ set: /**
+ * Sets the bottom-right corner of the Rectangle, determined by the values of the given Point object.
+ * @method bottomRight
+ * @param {Point} value
+ **/
+ function (value) {
+ this.right = value.x;
+ this.bottom = value.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "left", {
+ get: /**
+ * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
+ * @method left
+ * @ return {number}
+ **/
+ function () {
+ return this.x;
+ },
+ set: /**
+ * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties.
+ * However it does affect the width, whereas changing the x value does not affect the width property.
+ * @method left
+ * @param {Number} value
+ **/
+ function (value) {
+ if(value >= this.right) {
+ this.width = 0;
+ } else {
+ this.width = this.right - value;
+ }
+ this.x = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "right", {
+ get: /**
+ * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
+ * However it does affect the width property.
+ * @method right
+ * @return {Number}
+ **/
+ function () {
+ return this.x + this.width;
+ },
+ set: /**
+ * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
+ * However it does affect the width property.
+ * @method right
+ * @param {Number} value
+ **/
+ function (value) {
+ if(value <= this.x) {
+ this.width = 0;
+ } else {
+ this.width = this.x + value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "volume", {
+ get: /**
+ * The volume of the Rectangle derived from width * height
+ * @method volume
+ * @return {Number}
+ **/
+ function () {
+ return this.width * this.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "perimeter", {
+ get: /**
+ * The perimeter size of the Rectangle. This is the sum of all 4 sides.
+ * @method perimeter
+ * @return {Number}
+ **/
+ function () {
+ return (this.width * 2) + (this.height * 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "top", {
+ get: /**
+ * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
+ * However it does affect the height property, whereas changing the y value does not affect the height property.
+ * @method top
+ * @return {Number}
+ **/
+ function () {
+ return this.y;
+ },
+ set: /**
+ * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
+ * However it does affect the height property, whereas changing the y value does not affect the height property.
+ * @method top
+ * @param {Number} value
+ **/
+ function (value) {
+ if(value >= this.bottom) {
+ this.height = 0;
+ this.y = value;
+ } else {
+ this.height = (this.bottom - value);
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "topLeft", {
+ set: /**
+ * The location of the Rectangles top-left corner, determined by the x and y coordinates of the Point.
+ * @method topLeft
+ * @param {Point} value
+ **/
+ function (value) {
+ this.x = value.x;
+ this.y = value.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "empty", {
+ get: /**
+ * Determines whether or not this Rectangle object is empty.
+ * @method isEmpty
+ * @return {Boolean} A value of true if the Rectangle object's width or height is less than or equal to 0; otherwise false.
+ **/
+ function () {
+ return (!this.width || !this.height);
+ },
+ set: /**
+ * Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0.
+ * @method setEmpty
+ * @return {Rectangle} This rectangle object
+ **/
+ function (value) {
+ return this.setTo(0, 0, 0, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Rectangle.prototype.offset = /**
+ * Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
+ * @method offset
+ * @param {Number} dx Moves the x value of the Rectangle object by this amount.
+ * @param {Number} dy Moves the y value of the Rectangle object by this amount.
+ * @return {Rectangle} This Rectangle object.
+ **/
+ function (dx, dy) {
+ this.x += dx;
+ this.y += dy;
+ return this;
+ };
+ Rectangle.prototype.offsetPoint = /**
+ * Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
+ * @method offsetPoint
+ * @param {Point} point A Point object to use to offset this Rectangle object.
+ * @return {Rectangle} This Rectangle object.
+ **/
+ function (point) {
+ return this.offset(point.x, point.y);
+ };
+ Rectangle.prototype.setTo = /**
+ * Sets the members of Rectangle to the specified values.
+ * @method setTo
+ * @param {Number} x The x coordinate of the top-left corner of the rectangle.
+ * @param {Number} y The y coordinate of the top-left corner of the rectangle.
+ * @param {Number} width The width of the rectangle in pixels.
+ * @param {Number} height The height of the rectangle in pixels.
+ * @return {Rectangle} This rectangle object
+ **/
+ function (x, y, width, height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ return this;
+ };
+ Rectangle.prototype.copyFrom = /**
+ * Copies the x, y, width and height properties from any given object to this Rectangle.
+ * @method copyFrom
+ * @param {any} source - The object to copy from.
+ * @return {Rectangle} This Rectangle object.
+ **/
+ function (source) {
+ return this.setTo(source.x, source.y, source.width, source.height);
+ };
+ Rectangle.prototype.toString = /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the instance.
+ **/
+ function () {
+ return "[{Rectangle (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + " empty=" + this.empty + ")}]";
+ };
+ return Rectangle;
+ })();
+ Phaser.Rectangle = Rectangle;
})(Phaser || (Phaser = {}));
///
/**
@@ -3828,6 +3981,7 @@ var Phaser;
///
///
///
+///
/**
* Phaser - Sprite
*
@@ -3896,8 +4050,8 @@ var Phaser;
this.texture = new Phaser.Components.Texture(this, key);
this.width = this.frameBounds.width;
this.height = this.frameBounds.height;
+ this.physics = new Phaser.Components.Physics(this);
// Transform related (if we add any more then move to a component)
- //this.origin = new Phaser.Vec2(this.width / 2, this.height / 2);
this.origin = new Phaser.Vec2(0, 0);
this.scale = new Phaser.Vec2(1, 1);
this.skew = new Phaser.Vec2(0, 0);
@@ -3955,9 +4109,8 @@ var Phaser;
* Pre-update is called right before update() on each object in the game loop.
*/
function () {
- //this.last.x = this.frameBounds.x;
- //this.last.y = this.frameBounds.y;
- //this.collisionMask.preUpdate();
+ this.frameBounds.x = this.x;
+ this.frameBounds.y = this.y;
if(this.modified == false && (!this.scale.equals(1) || !this.skew.equals(0) || this.rotation != 0 || this.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
this.modified = true;
}
@@ -3972,12 +4125,8 @@ var Phaser;
*/
function () {
this.animations.update();
+ this.physics.update();
/*
- if (this.moves)
- {
- this.updateMotion();
- }
-
if (this.worldBounds != null)
{
if (this.outOfBoundsAction == GameObject.OUT_OF_BOUNDS_KILL)
@@ -5382,8 +5531,157 @@ var Phaser;
})();
Phaser.Tween = Tween;
})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - PhysicsManager
+ *
+ * Your game only has one PhysicsManager instance and it's responsible for looking after, creating and colliding
+ * all of the physics objects in the world.
+ */
+ (function (Physics) {
+ var PhysicsManager = (function () {
+ function PhysicsManager(game, width, height) {
+ this.minFriction = 0;
+ this.maxFriction = 1;
+ this.minBounce = 0;
+ this.maxBounce = 1;
+ this.minGravity = 0;
+ this.maxGravity = 1;
+ this._i = 0;
+ this._length = 0;
+ this._game = game;
+ this.gravity = new Phaser.Vec2(0, 0.2);
+ this.drag = new Phaser.Vec2(1, 1);
+ this.bounce = new Phaser.Vec2(0.3, 0.9);
+ this.friction = new Phaser.Vec2(0.05, 0.05);
+ this.bounds = new Phaser.Rectangle(0, 0, width, height);
+ this._objects = [];
+ }
+ PhysicsManager.prototype.add = function (o) {
+ this._objects.push(o);
+ this._length++;
+ return o;
+ };
+ PhysicsManager.prototype.update = function () {
+ // iterate through the objects here, updating and colliding
+ for(this._i = 0; this._i < this._length; this._i++) {
+ this._objects[this._i].update();
+ }
+ };
+ PhysicsManager.prototype.render = function () {
+ // iterate through the objects here, updating and colliding
+ for(this._i = 0; this._i < this._length; this._i++) {
+ this._objects[this._i].render(this._game.stage.context);
+ }
+ };
+ return PhysicsManager;
+ })();
+ Physics.PhysicsManager = PhysicsManager;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ ///
+ ///
+ /**
+ * Phaser - Physics - AABB
+ */
+ (function (Physics) {
+ var AABB = (function () {
+ function AABB(game, sprite, x, y, width, height) {
+ this.game = game;
+ this.world = game.world.physics;
+ this.sprite = sprite;
+ this.width = width;
+ this.height = height;
+ this.halfWidth = Math.round(width / 2);
+ this.halfHeight = Math.round(height / 2);
+ this.position = new Phaser.Vec2(x + this.halfWidth, y + this.halfHeight);
+ this.oldPosition = new Phaser.Vec2(x + this.halfWidth, y + this.halfHeight);
+ }
+ AABB.prototype.update = function () {
+ if(this.sprite.physics.moves) {
+ this.integrate();
+ this.collideWorld();
+ }
+ };
+ AABB.prototype.integrate = function () {
+ var ox = this.oldPosition.x;
+ var oy = this.oldPosition.y;
+ this.oldPosition.x = this.position.x;
+ this.oldPosition.y = this.position.y;
+ //this.position.x += (this.world.drag.x * this.position.x + this.halfWidth) - (this.world.drag.x * ox) + this.world.gravity.x;
+ //this.position.y += (this.world.drag.y * this.position.y + this.halfHeight) - (this.world.drag.y * oy) + this.world.gravity.y;
+ this.position.x += (this.world.drag.x * this.position.x) - (this.world.drag.x * ox) + this.world.gravity.x;
+ this.position.y += (this.world.drag.y * this.position.y) - (this.world.drag.y * oy) + this.world.gravity.y;
+ };
+ AABB.prototype.collideWorld = function () {
+ // Collide on the x-axis
+ var dx = this.world.bounds.x - (this.position.x - this.halfWidth);
+ if(0 < dx) {
+ this.processWorld(dx, 0, 1, 0, null);
+ } else {
+ dx = (this.position.x + this.halfWidth) - this.world.bounds.right;
+ if(0 < dx) {
+ this.processWorld(-dx, 0, -1, 0, null);
+ }
+ }
+ // Collide on the y-axis
+ var dy = this.world.bounds.y - (this.position.y - this.halfHeight);
+ if(0 < dy) {
+ this.processWorld(0, dy, 0, 1, null);
+ } else {
+ dy = (this.position.y + this.halfHeight) - this.world.bounds.bottom;
+ if(0 < dy) {
+ this.processWorld(0, -dy, 0, -1, null);
+ }
+ }
+ };
+ AABB.prototype.processWorld = function (px, py, dx, dy, tile) {
+ // Velocity
+ var vx = this.position.x - this.oldPosition.x;
+ var vy = this.position.y - this.oldPosition.y;
+ var dp = (vx * dx + vy * dy);
+ var nx = dp * dx;
+ var ny = dp * dy;
+ var tx = vx - nx;
+ var ty = vy - ny;
+ var b, bx, by, f, fx, fy;
+ if(dp < 0) {
+ fx = tx * this.world.friction.x;
+ fy = ty * this.world.friction.y;
+ bx = (nx * (1 + this.world.bounce.x));
+ by = (ny * (1 + this.world.bounce.y));
+ } else {
+ bx = by = fx = fy = 0;
+ }
+ this.position.x += px;
+ this.position.y += py;
+ this.oldPosition.x += px + bx + fx;
+ this.oldPosition.y += py + by + fy;
+ };
+ AABB.prototype.render = function (context) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(0,255,0)';
+ context.strokeRect(this.position.x - this.halfWidth, this.position.y - this.halfHeight, this.width, this.height);
+ context.stroke();
+ context.closePath();
+ // center point
+ context.fillStyle = 'rgb(0,255,0)';
+ context.fillRect(this.position.x, this.position.y, 2, 2);
+ };
+ return AABB;
+ })();
+ Physics.AABB = AABB;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
///
///
+///
/**
* Phaser - GameObjectFactory
*
@@ -5454,6 +5752,18 @@ var Phaser;
if (typeof maxSize === "undefined") { maxSize = 0; }
return this._world.group.add(new Phaser.Group(this._game, maxSize));
};
+ GameObjectFactory.prototype.physicsAABB = /**
+ * Create a new Sprite with specific position and sprite sheet key.
+ *
+ * @param x {number} X position of the new sprite.
+ * @param y {number} Y position of the new sprite.
+ * @param key {string} Optional, key for the sprite sheet you want it to use.
+ * @returns {Sprite} The newly created sprite object.
+ * WILL NEED TO TRACK A SPRITE
+ */
+ function (x, y, width, height) {
+ return this._world.physics.add(new Phaser.Physics.AABB(this._game, null, x, y, width, height));
+ };
GameObjectFactory.prototype.tween = /**
* Create a new Particle.
*
@@ -7654,6 +7964,7 @@ var Phaser;
///
///
///
+///
/**
* Phaser - World
*
@@ -7678,12 +7989,14 @@ var Phaser;
this.cameras = new Phaser.CameraManager(this._game, 0, 0, width, height);
this.group = new Phaser.Group(this._game, 0);
this.bounds = new Phaser.Rectangle(0, 0, width, height);
+ this.physics = new Phaser.Physics.PhysicsManager(this._game, width, height);
this.worldDivisions = 6;
}
World.prototype.update = /**
* This is called automatically every frame, and is where main logic happens.
*/
function () {
+ this.physics.update();
this.group.update();
this.cameras.update();
};
@@ -7691,6 +8004,7 @@ var Phaser;
* Clean up memory.
*/
function () {
+ //this.physics.destroy();
this.group.destroy();
this.cameras.destroy();
};
@@ -7701,13 +8015,17 @@ var Phaser;
* @param height {number} New height of the world.
* @param [updateCameraBounds] {boolean} Update camera bounds automatically or not. Default to true.
*/
- function (width, height, updateCameraBounds) {
+ function (width, height, updateCameraBounds, updatePhysicsBounds) {
if (typeof updateCameraBounds === "undefined") { updateCameraBounds = true; }
+ if (typeof updatePhysicsBounds === "undefined") { updatePhysicsBounds = true; }
this.bounds.width = width;
this.bounds.height = height;
if(updateCameraBounds == true) {
this._game.camera.setBounds(0, 0, width, height);
}
+ if(updatePhysicsBounds == true) {
+ //this.physics.bounds.copyFrom(this.bounds);
+ }
// dispatch world resize event
};
Object.defineProperty(World.prototype, "width", {
@@ -10461,6 +10779,8 @@ var Phaser;
this._game.world.group.render(this, this._camera);
this._camera.postRender();
}
+ // Physics Debug layer
+ this._game.world.physics.render();
};
CanvasRenderer.prototype.renderSprite = /**
* Render this sprite to specific camera. Called by game loop after update().
@@ -10507,14 +10827,6 @@ var Phaser;
this._dy += sprite.animations.currentFrame.spriteSourceSizeY;
}
}
- // Apply camera difference - looks like this is already applied?
- /*
- if (sprite.scrollFactor.x !== 1 || sprite.scrollFactor.y !== 1)
- {
- //this._dx -= (camera.worldView.x * this.scrollFactor.x);
- //this._dy -= (camera.worldView.y * this.scrollFactor.y);
- }
- */
// Rotation and Flipped
if(sprite.modified) {
if(sprite.texture.renderRotation == true && (sprite.rotation !== 0 || sprite.rotationOffset !== 0)) {
@@ -11027,353 +11339,304 @@ var Phaser;
})(Phaser || (Phaser = {}));
///
/**
-* Phaser - Point
+* Phaser - Vec2
*
-* The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
+* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
*/
var Phaser;
(function (Phaser) {
- var Point = (function () {
+ var Vec2 = (function () {
/**
- * Creates a new Point. If you pass no parameters a Point is created set to (0,0).
- * @class Point
+ * Creates a new Vec2 object.
+ * @class Vec2
* @constructor
- * @param {Number} x The horizontal position of this Point (default 0)
- * @param {Number} y The vertical position of this Point (default 0)
+ * @param {Number} x The x position of the vector
+ * @param {Number} y The y position of the vector
+ * @return {Vec2} This object
**/
- function Point(x, y) {
+ function Vec2(x, y) {
if (typeof x === "undefined") { x = 0; }
if (typeof y === "undefined") { y = 0; }
this.x = x;
this.y = y;
}
- Point.prototype.copyFrom = /**
- * Copies the x and y properties from any given object to this Point.
+ Vec2.prototype.copyFrom = /**
+ * Copies the x and y properties from any given object to this Vec2.
* @method copyFrom
* @param {any} source - The object to copy from.
- * @return {Point} This Point object.
+ * @return {Vec2} This Vec2 object.
**/
function (source) {
return this.setTo(source.x, source.y);
};
- Point.prototype.invert = /**
- * Inverts the x and y values of this Point
- * @method invert
- * @return {Point} This Point object.
- **/
- function () {
- return this.setTo(this.y, this.x);
- };
- Point.prototype.setTo = /**
- * Sets the x and y values of this MicroPoint object to the given coordinates.
- * @method setTo
- * @param {Number} x - The horizontal position of this point.
- * @param {Number} y - The vertical position of this point.
- * @return {MicroPoint} This MicroPoint object. Useful for chaining method calls.
+ Vec2.prototype.setTo = /**
+ * Sets the x and y properties of the Vector.
+ * @param {Number} x The x position of the vector
+ * @param {Number} y The y position of the vector
+ * @return {Vec2} This object
**/
function (x, y) {
this.x = x;
this.y = y;
return this;
};
- Point.prototype.toString = /**
+ Vec2.prototype.add = /**
+ * Add another vector to this one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ function (a) {
+ this.x += a.x;
+ this.y += a.y;
+ return this;
+ };
+ Vec2.prototype.subtract = /**
+ * Subtract another vector from this one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ function (v) {
+ this.x -= v.x;
+ this.y -= v.y;
+ return this;
+ };
+ Vec2.prototype.multiply = /**
+ * Multiply another vector with this one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ function (v) {
+ this.x *= v.x;
+ this.y *= v.y;
+ return this;
+ };
+ Vec2.prototype.divide = /**
+ * Divide this vector by another one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ function (v) {
+ this.x /= v.x;
+ this.y /= v.y;
+ return this;
+ };
+ Vec2.prototype.length = /**
+ * Get the length of this vector.
+ *
+ * @return {number} The length of this vector.
+ */
+ function () {
+ return Math.sqrt((this.x * this.x) + (this.y * this.y));
+ };
+ Vec2.prototype.lengthSq = /**
+ * Get the length squared of this vector.
+ *
+ * @return {number} The length^2 of this vector.
+ */
+ function () {
+ return (this.x * this.x) + (this.y * this.y);
+ };
+ Vec2.prototype.dot = /**
+ * The dot product of two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function (a) {
+ return ((this.x * a.x) + (this.y * a.y));
+ };
+ Vec2.prototype.cross = /**
+ * The cross product of two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function (a) {
+ return ((this.x * a.y) - (this.y * a.x));
+ };
+ Vec2.prototype.projectionLength = /**
+ * The projection magnitude of two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function (a) {
+ var den = a.dot(a);
+ if(den == 0) {
+ return 0;
+ } else {
+ return Math.abs(this.dot(a) / den);
+ }
+ };
+ Vec2.prototype.angle = /**
+ * The angle between two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function (a) {
+ return Math.atan2(a.x * this.y - a.y * this.x, a.x * this.x + a.y * this.y);
+ };
+ Vec2.prototype.scale = /**
+ * Scale this vector.
+ *
+ * @param {number} x The scaling factor in the x direction.
+ * @param {?number=} y The scaling factor in the y direction. If this is not specified, the x scaling factor will be used.
+ * @return {Vec2} This for chaining.
+ */
+ function (x, y) {
+ this.x *= x;
+ this.y *= y || x;
+ return this;
+ };
+ Vec2.prototype.divideByScalar = /**
+ * Divide this vector by the given scalar.
+ *
+ * @param {number} scalar
+ * @return {Vec2} This for chaining.
+ */
+ function (scalar) {
+ this.x /= scalar;
+ this.y /= scalar;
+ return this;
+ };
+ Vec2.prototype.reverse = /**
+ * Reverse this vector.
+ *
+ * @return {Vec2} This for chaining.
+ */
+ function () {
+ this.x = -this.x;
+ this.y = -this.y;
+ return this;
+ };
+ Vec2.prototype.equals = /**
+ * Check if both the x and y of this vector equal the given value.
+ *
+ * @return {Boolean}
+ */
+ function (value) {
+ return (this.x == value && this.y == value);
+ };
+ Vec2.prototype.toString = /**
* Returns a string representation of this object.
* @method toString
- * @return {string} a string representation of the instance.
+ * @return {string} a string representation of the object.
**/
function () {
- return '[{Point (x=' + this.x + ' y=' + this.y + ')}]';
+ return "[{Vec2 (x=" + this.x + " y=" + this.y + ")}]";
};
- return Point;
+ return Vec2;
})();
- Phaser.Point = Point;
+ Phaser.Vec2 = Vec2;
})(Phaser || (Phaser = {}));
-///
-/**
-* Rectangle
-*
-* @desc A Rectangle object is an area defined by its position, as indicated by its top-left corner (x,y) and width and height.
-*
-* @version 1.6 - 24th May 2013
-* @author Richard Davey
-*/
var Phaser;
(function (Phaser) {
- var Rectangle = (function () {
- /**
- * Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a rectangle with x, y, width, and height properties set to 0 is created.
- * @class Rectangle
- * @constructor
- * @param {Number} x The x coordinate of the top-left corner of the rectangle.
- * @param {Number} y The y coordinate of the top-left corner of the rectangle.
- * @param {Number} width The width of the rectangle in pixels.
- * @param {Number} height The height of the rectangle in pixels.
- * @return {Rectangle} This rectangle object
- **/
- function Rectangle(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; }
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- }
- Object.defineProperty(Rectangle.prototype, "halfWidth", {
- get: /**
- * Half of the width of the rectangle
- * @property halfWidth
- * @type Number
- **/
+ ///
+ ///
+ ///
+ /**
+ * Phaser - Components - Physics
+ *
+ *
+ */
+ (function (Components) {
+ var Physics = (function () {
+ function Physics(parent) {
+ /**
+ * Set this to false if you want to skip the automatic motion/movement stuff
+ * (see updateMotion()).
+ * @type {boolean}
+ */
+ this.moves = true;
+ this._game = parent.game;
+ this._sprite = parent;
+ //this.AABB = new Phaser.Physics.AABB(this._game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height);
+ this.AABB = this._game.world.physics.add(new Phaser.Physics.AABB(this._game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height));
+ }
+ Physics.prototype.update = /**
+ * Handy for checking if this object is touching a particular surface.
+ * For slightly better performance you can just & the value directly into touching.
+ * However, this method is good for readability and accessibility.
+ *
+ * @param Direction {number} Any of the collision flags (e.g. LEFT, FLOOR, etc).
+ *
+ * @return {boolean} Whether the object is touching an object in (any of) the specified direction(s) this frame.
+ */
+ //public isTouching(direction: number): bool {
+ // return (this.touching & direction) > Collision.NONE;
+ //}
+ /**
+ * Handy function for checking if this object just landed on a particular surface.
+ *
+ * @param Direction {number} Any of the collision flags (e.g. LEFT, FLOOR, etc).
+ *
+ * @returns {boolean} Whether the object just landed on any specicied surfaces.
+ */
+ //public justTouched(direction: number): bool {
+ // return ((this.touching & direction) > Collision.NONE) && ((this.wasTouching & direction) <= Collision.NONE);
+ //}
+ /**
+ * Internal function for updating the position and speed of this object.
+ */
function () {
- return Math.round(this.width / 2);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "halfHeight", {
- get: /**
- * Half of the height of the rectangle
- * @property halfHeight
- * @type Number
- **/
- function () {
- return Math.round(this.height / 2);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "bottom", {
- get: /**
- * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
- * @method bottom
- * @return {Number}
- **/
- function () {
- return this.y + this.height;
- },
- set: /**
- * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
- * @method bottom
- * @param {Number} value
- **/
- function (value) {
- if(value <= this.y) {
- this.height = 0;
- } else {
- this.height = (this.y - value);
+ if(this.moves) {
+ this._sprite.x = this.AABB.position.x - this.AABB.halfWidth;
+ this._sprite.y = this.AABB.position.y - this.AABB.halfHeight;
}
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "bottomRight", {
- set: /**
- * Sets the bottom-right corner of the Rectangle, determined by the values of the given Point object.
- * @method bottomRight
- * @param {Point} value
- **/
- function (value) {
- this.right = value.x;
- this.bottom = value.y;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "left", {
- get: /**
- * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
- * @method left
- * @ return {number}
- **/
- function () {
- return this.x;
- },
- set: /**
- * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties.
- * However it does affect the width, whereas changing the x value does not affect the width property.
- * @method left
- * @param {Number} value
- **/
- function (value) {
- if(value >= this.right) {
- this.width = 0;
- } else {
- this.width = this.right - value;
- }
- this.x = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "right", {
- get: /**
- * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
- * However it does affect the width property.
- * @method right
- * @return {Number}
- **/
- function () {
- return this.x + this.width;
- },
- set: /**
- * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
- * However it does affect the width property.
- * @method right
- * @param {Number} value
- **/
- function (value) {
- if(value <= this.x) {
- this.width = 0;
- } else {
- this.width = this.x + value;
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "volume", {
- get: /**
- * The volume of the Rectangle derived from width * height
- * @method volume
- * @return {Number}
- **/
- function () {
- return this.width * this.height;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "perimeter", {
- get: /**
- * The perimeter size of the Rectangle. This is the sum of all 4 sides.
- * @method perimeter
- * @return {Number}
- **/
- function () {
- return (this.width * 2) + (this.height * 2);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "top", {
- get: /**
- * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
- * However it does affect the height property, whereas changing the y value does not affect the height property.
- * @method top
- * @return {Number}
- **/
- function () {
- return this.y;
- },
- set: /**
- * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
- * However it does affect the height property, whereas changing the y value does not affect the height property.
- * @method top
- * @param {Number} value
- **/
- function (value) {
- if(value >= this.bottom) {
- this.height = 0;
- this.y = value;
- } else {
- this.height = (this.bottom - value);
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "topLeft", {
- set: /**
- * The location of the Rectangles top-left corner, determined by the x and y coordinates of the Point.
- * @method topLeft
- * @param {Point} value
- **/
- function (value) {
- this.x = value.x;
- this.y = value.y;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "empty", {
- get: /**
- * Determines whether or not this Rectangle object is empty.
- * @method isEmpty
- * @return {Boolean} A value of true if the Rectangle object's width or height is less than or equal to 0; otherwise false.
- **/
- function () {
- return (!this.width || !this.height);
- },
- set: /**
- * Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0.
- * @method setEmpty
- * @return {Rectangle} This rectangle object
- **/
- function (value) {
- return this.setTo(0, 0, 0, 0);
- },
- enumerable: true,
- configurable: true
- });
- Rectangle.prototype.offset = /**
- * Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
- * @method offset
- * @param {Number} dx Moves the x value of the Rectangle object by this amount.
- * @param {Number} dy Moves the y value of the Rectangle object by this amount.
- * @return {Rectangle} This Rectangle object.
- **/
- function (dx, dy) {
- this.x += dx;
- this.y += dy;
- return this;
- };
- Rectangle.prototype.offsetPoint = /**
- * Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
- * @method offsetPoint
- * @param {Point} point A Point object to use to offset this Rectangle object.
- * @return {Rectangle} This Rectangle object.
- **/
- function (point) {
- return this.offset(point.x, point.y);
- };
- Rectangle.prototype.setTo = /**
- * Sets the members of Rectangle to the specified values.
- * @method setTo
- * @param {Number} x The x coordinate of the top-left corner of the rectangle.
- * @param {Number} y The y coordinate of the top-left corner of the rectangle.
- * @param {Number} width The width of the rectangle in pixels.
- * @param {Number} height The height of the rectangle in pixels.
- * @return {Rectangle} This rectangle object
- **/
- function (x, y, width, height) {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- return this;
- };
- Rectangle.prototype.copyFrom = /**
- * Copies the x, y, width and height properties from any given object to this Rectangle.
- * @method copyFrom
- * @param {any} source - The object to copy from.
- * @return {Rectangle} This Rectangle object.
- **/
- function (source) {
- return this.setTo(source.x, source.y, source.width, source.height);
- };
- Rectangle.prototype.toString = /**
- * Returns a string representation of this object.
- * @method toString
- * @return {string} a string representation of the instance.
- **/
- function () {
- return "[{Rectangle (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + " empty=" + this.empty + ")}]";
- };
- return Rectangle;
- })();
- Phaser.Rectangle = Rectangle;
+ /*
+ var delta: number;
+ var velocityDelta: number;
+
+ velocityDelta = (this._game.motion.computeVelocity(this.angularVelocity, this.angularAcceleration, this.angularDrag, this.maxAngular) - this.angularVelocity) / 2;
+ this.angularVelocity += velocityDelta;
+ this._angle += this.angularVelocity * this._game.time.elapsed;
+ this.angularVelocity += velocityDelta;
+
+ velocityDelta = (this._game.motion.computeVelocity(this.velocity.x, this.acceleration.x, this.drag.x, this.maxVelocity.x) - this.velocity.x) / 2;
+ this.velocity.x += velocityDelta;
+ delta = this.velocity.x * this._game.time.elapsed;
+ this.velocity.x += velocityDelta;
+ this.frameBounds.x += delta;
+
+ velocityDelta = (this._game.motion.computeVelocity(this.velocity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y) - this.velocity.y) / 2;
+ this.velocity.y += velocityDelta;
+ delta = this.velocity.y * this._game.time.elapsed;
+ this.velocity.y += velocityDelta;
+ this.frameBounds.y += delta;
+ */
+ };
+ Object.defineProperty(Physics.prototype, "solid", {
+ set: /**
+ * Whether the object collides or not. For more control over what directions
+ * the object will collide from, use collision constants (like LEFT, FLOOR, etc)
+ * to set the value of allowCollisions directly.
+ */
+ //public get solid(): bool {
+ // return (this.allowCollisions & Collision.ANY) > Collision.NONE;
+ //}
+ function (value) {
+ //if (value)
+ //{
+ // this.allowCollisions = Collision.ANY;
+ //}
+ //else
+ //{
+ // this.allowCollisions = Collision.NONE;
+ //}
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Physics;
+ })();
+ Components.Physics = Physics;
+ })(Phaser.Components || (Phaser.Components = {}));
+ var Components = Phaser.Components;
})(Phaser || (Phaser = {}));
///
///