mirror of
https://github.com/wassname/phaser.git
synced 2026-06-30 16:40:20 +08:00
Added the GameObjectManager
This commit is contained in:
@@ -211,7 +211,15 @@ module Phaser {
|
||||
}
|
||||
|
||||
public get frameTotal(): number {
|
||||
return this._frameData.total;
|
||||
|
||||
if (this._frameData)
|
||||
{
|
||||
return this._frameData.total;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public get frame(): number {
|
||||
@@ -248,6 +256,19 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all related references
|
||||
*/
|
||||
public destroy() {
|
||||
|
||||
this._anims = {};
|
||||
this._frameData = null;
|
||||
this._frameIndex = 0;
|
||||
this.currentAnim = null;
|
||||
this.currentFrame = null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,9 +6,6 @@
|
||||
*
|
||||
* Your game only has one CameraManager instance and it's responsible for looking after, creating and destroying
|
||||
* all of the cameras in the world.
|
||||
*
|
||||
* TODO: If the Camera is larger than the Stage size then the rotation offset isn't correct
|
||||
* TODO: Texture Repeat doesn't scroll, because it's part of the camera not the world, need to think about this more
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
+657
-239
@@ -5,6 +5,8 @@
|
||||
/// <reference path="geom/Circle.ts" />
|
||||
/// <reference path="geom/Line.ts" />
|
||||
/// <reference path="geom/IntersectResult.ts" />
|
||||
/// <reference path="geom/Response.ts" />
|
||||
/// <reference path="geom/Vector2.ts" />
|
||||
/// <reference path="system/QuadTree.ts" />
|
||||
|
||||
/**
|
||||
@@ -25,6 +27,20 @@ module Phaser {
|
||||
|
||||
this._game = game;
|
||||
|
||||
Collision.T_VECTORS = [];
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
Collision.T_VECTORS.push(new Vector2);
|
||||
}
|
||||
|
||||
Collision.T_ARRAYS = [];
|
||||
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
Collision.T_ARRAYS.push([]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -553,20 +569,6 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
public static circleToQuad(circle: Circle, quad: Quad): bool {
|
||||
|
||||
// Check if the center of the circle is within the Quad
|
||||
if (quad.contains(circle.x, circle.y))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Failing that let's check each line of the quad against the circle
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks if the Circle object intersects with the Rectangle and returns the result in an IntersectResult object.
|
||||
* @param circle The Circle object to check
|
||||
@@ -647,8 +649,6 @@ module Phaser {
|
||||
*/
|
||||
public static separate(object1, object2): bool {
|
||||
|
||||
console.log('sep o');
|
||||
|
||||
object1.collisionMask.update();
|
||||
object2.collisionMask.update();
|
||||
|
||||
@@ -667,6 +667,8 @@ module Phaser {
|
||||
*/
|
||||
public static separateTile(object:GameObject, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool, collideUp: bool, collideDown: bool, separateX: bool, separateY: bool): bool {
|
||||
|
||||
object.collisionMask.update();
|
||||
|
||||
var separatedX: bool = Collision.separateTileX(object, x, y, width, height, mass, collideLeft, collideRight, separateX);
|
||||
var separatedY: bool = Collision.separateTileY(object, x, y, width, height, mass, collideUp, collideDown, separateY);
|
||||
|
||||
@@ -691,11 +693,13 @@ module Phaser {
|
||||
// First, get the object delta
|
||||
var overlap: number = 0;
|
||||
var objDelta: number = object.x - object.last.x;
|
||||
//var objDelta: number = object.collisionMask.deltaX;
|
||||
|
||||
if (objDelta != 0)
|
||||
{
|
||||
// Check if the X hulls actually overlap
|
||||
var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta;
|
||||
//var objDeltaAbs: number = object.collisionMask.deltaXAbs;
|
||||
var objBounds: Quad = new Quad(object.x - ((objDelta > 0) ? objDelta : 0), object.last.y, object.width + ((objDelta > 0) ? objDelta : -objDelta), object.height);
|
||||
|
||||
if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height))
|
||||
@@ -739,6 +743,7 @@ module Phaser {
|
||||
{
|
||||
if (separate == true)
|
||||
{
|
||||
//console.log('
|
||||
object.x = object.x - overlap;
|
||||
object.velocity.x = -(object.velocity.x * object.elasticity);
|
||||
}
|
||||
@@ -831,6 +836,170 @@ module Phaser {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Separates the two objects on their x axis
|
||||
* @param object The GameObject to separate
|
||||
* @param tile The Tile to separate
|
||||
* @returns {boolean} Whether the objects in fact touched and were separated along the X axis.
|
||||
*/
|
||||
public static NEWseparateTileX(object:GameObject, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool, separate: bool): bool {
|
||||
|
||||
// Can't separate two immovable objects (tiles are always immovable)
|
||||
if (object.immovable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// First, get the object delta
|
||||
var overlap: number = 0;
|
||||
|
||||
if (object.collisionMask.deltaX != 0)
|
||||
{
|
||||
// Check if the X hulls actually overlap
|
||||
//var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta;
|
||||
//var objBounds: Quad = new Quad(object.x - ((objDelta > 0) ? objDelta : 0), object.last.y, object.width + ((objDelta > 0) ? objDelta : -objDelta), object.height);
|
||||
|
||||
//if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height))
|
||||
if (object.collisionMask.intersectsRaw(x, x + width, y, y + height))
|
||||
{
|
||||
var maxOverlap: number = object.collisionMask.deltaXAbs + Collision.OVERLAP_BIAS;
|
||||
|
||||
// If they did overlap (and can), figure out by how much and flip the corresponding flags
|
||||
if (object.collisionMask.deltaX > 0)
|
||||
{
|
||||
//overlap = object.x + object.width - x;
|
||||
overlap = object.collisionMask.right - x;
|
||||
|
||||
if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.RIGHT) || collideLeft == false)
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
object.touching |= Collision.RIGHT;
|
||||
}
|
||||
}
|
||||
else if (object.collisionMask.deltaX < 0)
|
||||
{
|
||||
//overlap = object.x - width - x;
|
||||
overlap = object.collisionMask.x - width - x;
|
||||
|
||||
if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.LEFT) || collideRight == false)
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
object.touching |= Collision.LEFT;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (overlap != 0)
|
||||
{
|
||||
if (separate == true)
|
||||
{
|
||||
object.x = object.x - overlap;
|
||||
object.velocity.x = -(object.velocity.x * object.elasticity);
|
||||
}
|
||||
|
||||
Collision.TILE_OVERLAP = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Separates the two objects on their y axis
|
||||
* @param object The first GameObject to separate
|
||||
* @param tile The second GameObject to separate
|
||||
* @returns {boolean} Whether the objects in fact touched and were separated along the Y axis.
|
||||
*/
|
||||
public static NEWseparateTileY(object: GameObject, x: number, y: number, width: number, height: number, mass: number, collideUp: bool, collideDown: bool, separate: bool): bool {
|
||||
|
||||
// Can't separate two immovable objects (tiles are always immovable)
|
||||
if (object.immovable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// First, get the two object deltas
|
||||
var overlap: number = 0;
|
||||
//var objDelta: number = object.y - object.last.y;
|
||||
|
||||
if (object.collisionMask.deltaY != 0)
|
||||
{
|
||||
// Check if the Y hulls actually overlap
|
||||
//var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta;
|
||||
//var objBounds: Quad = new Quad(object.x, object.y - ((objDelta > 0) ? objDelta : 0), object.width, object.height + objDeltaAbs);
|
||||
|
||||
//if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height))
|
||||
if (object.collisionMask.intersectsRaw(x, x + width, y, y + height))
|
||||
{
|
||||
//var maxOverlap: number = objDeltaAbs + Collision.OVERLAP_BIAS;
|
||||
var maxOverlap: number = object.collisionMask.deltaYAbs + Collision.OVERLAP_BIAS;
|
||||
|
||||
// If they did overlap (and can), figure out by how much and flip the corresponding flags
|
||||
if (object.collisionMask.deltaY > 0)
|
||||
{
|
||||
//overlap = object.y + object.height - y;
|
||||
overlap = object.collisionMask.bottom - y;
|
||||
|
||||
if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.DOWN) || collideUp == false)
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
object.touching |= Collision.DOWN;
|
||||
}
|
||||
}
|
||||
else if (object.collisionMask.deltaY < 0)
|
||||
{
|
||||
//overlap = object.y - height - y;
|
||||
overlap = object.collisionMask.y - height - y;
|
||||
|
||||
if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.UP) || collideDown == false)
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
object.touching |= Collision.UP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO - with super low velocities you get lots of stuttering, set some kind of base minimum here
|
||||
|
||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (overlap != 0)
|
||||
{
|
||||
if (separate == true)
|
||||
{
|
||||
object.y = object.y - overlap;
|
||||
object.velocity.y = -(object.velocity.y * object.elasticity);
|
||||
}
|
||||
|
||||
Collision.TILE_OVERLAP = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Separates the two objects on their x axis
|
||||
* @param object1 The first GameObject to separate
|
||||
@@ -1032,229 +1201,6 @@ module Phaser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Separates the two objects on their x axis
|
||||
* @param object1 The first GameObject to separate
|
||||
* @param object2 The second GameObject to separate
|
||||
* @returns {boolean} Whether the objects in fact touched and were separated along the X axis.
|
||||
*/
|
||||
public static OLDseparateX(object1, object2): bool {
|
||||
|
||||
// Can't separate two immovable objects
|
||||
if (object1.immovable && object2.immovable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// First, get the two object deltas
|
||||
var overlap: number = 0;
|
||||
var obj1Delta: number = object1.x - object1.last.x;
|
||||
var obj2Delta: number = object2.x - object2.last.x;
|
||||
|
||||
if (obj1Delta != obj2Delta)
|
||||
{
|
||||
// Check if the X hulls actually overlap
|
||||
var obj1DeltaAbs: number = (obj1Delta > 0) ? obj1Delta : -obj1Delta;
|
||||
var obj2DeltaAbs: number = (obj2Delta > 0) ? obj2Delta : -obj2Delta;
|
||||
var obj1Bounds: Quad = new Quad(object1.x - ((obj1Delta > 0) ? obj1Delta : 0), object1.last.y, object1.width + ((obj1Delta > 0) ? obj1Delta : -obj1Delta), object1.height);
|
||||
var obj2Bounds: Quad = new Quad(object2.x - ((obj2Delta > 0) ? obj2Delta : 0), object2.last.y, object2.width + ((obj2Delta > 0) ? obj2Delta : -obj2Delta), object2.height);
|
||||
|
||||
if ((obj1Bounds.x + obj1Bounds.width > obj2Bounds.x) && (obj1Bounds.x < obj2Bounds.x + obj2Bounds.width) && (obj1Bounds.y + obj1Bounds.height > obj2Bounds.y) && (obj1Bounds.y < obj2Bounds.y + obj2Bounds.height))
|
||||
{
|
||||
var maxOverlap: number = obj1DeltaAbs + obj2DeltaAbs + Collision.OVERLAP_BIAS;
|
||||
|
||||
// If they did overlap (and can), figure out by how much and flip the corresponding flags
|
||||
if (obj1Delta > obj2Delta)
|
||||
{
|
||||
overlap = object1.x + object1.width - object2.x;
|
||||
|
||||
if ((overlap > maxOverlap) || !(object1.allowCollisions & Collision.RIGHT) || !(object2.allowCollisions & Collision.LEFT))
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
object1.touching |= Collision.RIGHT;
|
||||
object2.touching |= Collision.LEFT;
|
||||
}
|
||||
}
|
||||
else if (obj1Delta < obj2Delta)
|
||||
{
|
||||
overlap = object1.x - object2.width - object2.x;
|
||||
|
||||
if ((-overlap > maxOverlap) || !(object1.allowCollisions & Collision.LEFT) || !(object2.allowCollisions & Collision.RIGHT))
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
object1.touching |= Collision.LEFT;
|
||||
object2.touching |= Collision.RIGHT;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (overlap != 0)
|
||||
{
|
||||
var obj1Velocity: number = object1.velocity.x;
|
||||
var obj2Velocity: number = object2.velocity.x;
|
||||
|
||||
if (!object1.immovable && !object2.immovable)
|
||||
{
|
||||
overlap *= 0.5;
|
||||
object1.x = object1.x - overlap;
|
||||
object2.x += overlap;
|
||||
|
||||
var obj1NewVelocity: number = Math.sqrt((obj2Velocity * obj2Velocity * object2.mass) / object1.mass) * ((obj2Velocity > 0) ? 1 : -1);
|
||||
var obj2NewVelocity: number = Math.sqrt((obj1Velocity * obj1Velocity * object1.mass) / object2.mass) * ((obj1Velocity > 0) ? 1 : -1);
|
||||
var average: number = (obj1NewVelocity + obj2NewVelocity) * 0.5;
|
||||
obj1NewVelocity -= average;
|
||||
obj2NewVelocity -= average;
|
||||
object1.velocity.x = average + obj1NewVelocity * object1.elasticity;
|
||||
object2.velocity.x = average + obj2NewVelocity * object2.elasticity;
|
||||
}
|
||||
else if (!object1.immovable)
|
||||
{
|
||||
object1.x = object1.x - overlap;
|
||||
object1.velocity.x = obj2Velocity - obj1Velocity * object1.elasticity;
|
||||
}
|
||||
else if (!object2.immovable)
|
||||
{
|
||||
object2.x += overlap;
|
||||
object2.velocity.x = obj1Velocity - obj2Velocity * object2.elasticity;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Separates the two objects on their y axis
|
||||
* @param object1 The first GameObject to separate
|
||||
* @param object2 The second GameObject to separate
|
||||
* @returns {boolean} Whether the objects in fact touched and were separated along the Y axis.
|
||||
*/
|
||||
public static OLDseparateY(object1, object2): bool {
|
||||
|
||||
// Can't separate two immovable objects
|
||||
if (object1.immovable && object2.immovable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// First, get the two object deltas
|
||||
var overlap: number = 0;
|
||||
var obj1Delta: number = object1.y - object1.last.y;
|
||||
var obj2Delta: number = object2.y - object2.last.y;
|
||||
|
||||
if (obj1Delta != obj2Delta)
|
||||
{
|
||||
// Check if the Y hulls actually overlap
|
||||
var obj1DeltaAbs: number = (obj1Delta > 0) ? obj1Delta : -obj1Delta;
|
||||
var obj2DeltaAbs: number = (obj2Delta > 0) ? obj2Delta : -obj2Delta;
|
||||
var obj1Bounds: Quad = new Quad(object1.x, object1.y - ((obj1Delta > 0) ? obj1Delta : 0), object1.width, object1.height + obj1DeltaAbs);
|
||||
var obj2Bounds: Quad = new Quad(object2.x, object2.y - ((obj2Delta > 0) ? obj2Delta : 0), object2.width, object2.height + obj2DeltaAbs);
|
||||
|
||||
console.log(obj1Bounds.toString(), obj2Bounds.toString());
|
||||
|
||||
if ((obj1Bounds.x + obj1Bounds.width > obj2Bounds.x) && (obj1Bounds.x < obj2Bounds.x + obj2Bounds.width) && (obj1Bounds.y + obj1Bounds.height > obj2Bounds.y) && (obj1Bounds.y < obj2Bounds.y + obj2Bounds.height))
|
||||
{
|
||||
var maxOverlap: number = obj1DeltaAbs + obj2DeltaAbs + Collision.OVERLAP_BIAS;
|
||||
console.log('max33', maxOverlap, obj1Delta, obj2Delta, obj1DeltaAbs, obj2DeltaAbs);
|
||||
|
||||
// If they did overlap (and can), figure out by how much and flip the corresponding flags
|
||||
if (obj1Delta > obj2Delta)
|
||||
{
|
||||
overlap = object1.y + object1.height - object2.y;
|
||||
|
||||
if ((overlap > maxOverlap) || !(object1.allowCollisions & Collision.DOWN) || !(object2.allowCollisions & Collision.UP))
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
object1.touching |= Collision.DOWN;
|
||||
object2.touching |= Collision.UP;
|
||||
}
|
||||
}
|
||||
else if (obj1Delta < obj2Delta)
|
||||
{
|
||||
overlap = object1.y - object2.height - object2.y;
|
||||
|
||||
if ((-overlap > maxOverlap) || !(object1.allowCollisions & Collision.UP) || !(object2.allowCollisions & Collision.DOWN))
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
object1.touching |= Collision.UP;
|
||||
object2.touching |= Collision.DOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (overlap != 0)
|
||||
{
|
||||
console.log('y overlap', overlap);
|
||||
|
||||
var obj1Velocity: number = object1.velocity.y;
|
||||
var obj2Velocity: number = object2.velocity.y;
|
||||
|
||||
if (!object1.immovable && !object2.immovable)
|
||||
{
|
||||
overlap *= 0.5;
|
||||
object1.y = object1.y - overlap;
|
||||
object2.y += overlap;
|
||||
|
||||
var obj1NewVelocity: number = Math.sqrt((obj2Velocity * obj2Velocity * object2.mass) / object1.mass) * ((obj2Velocity > 0) ? 1 : -1);
|
||||
var obj2NewVelocity: number = Math.sqrt((obj1Velocity * obj1Velocity * object1.mass) / object2.mass) * ((obj1Velocity > 0) ? 1 : -1);
|
||||
var average: number = (obj1NewVelocity + obj2NewVelocity) * 0.5;
|
||||
obj1NewVelocity -= average;
|
||||
obj2NewVelocity -= average;
|
||||
object1.velocity.y = average + obj1NewVelocity * object1.elasticity;
|
||||
object2.velocity.y = average + obj2NewVelocity * object2.elasticity;
|
||||
}
|
||||
else if (!object1.immovable)
|
||||
{
|
||||
object1.y = object1.y - overlap;
|
||||
object1.velocity.y = obj2Velocity - obj1Velocity * object1.elasticity;
|
||||
// This is special case code that handles things like horizontal moving platforms you can ride
|
||||
if (object2.active && object2.moves && (obj1Delta > obj2Delta))
|
||||
{
|
||||
object1.x += object2.x - object2.last.x;
|
||||
}
|
||||
console.log('y2', object1.y, object1.velocity.y);
|
||||
}
|
||||
else if (!object2.immovable)
|
||||
{
|
||||
object2.y += overlap;
|
||||
object2.velocity.y = obj1Velocity - obj2Velocity * object2.elasticity;
|
||||
// This is special case code that handles things like horizontal moving platforms you can ride
|
||||
if (object1.active && object1.moves && (obj1Delta < obj2Delta))
|
||||
{
|
||||
object2.x += object1.x - object1.last.x;
|
||||
}
|
||||
console.log('y3', object2.y, object2.velocity.y);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the distance between the two given coordinates.
|
||||
* @param x1 The X value of the first coordinate
|
||||
@@ -1279,6 +1225,478 @@ module Phaser {
|
||||
return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// SAT
|
||||
|
||||
/**
|
||||
* Flattens the specified array of points onto a unit vector axis,
|
||||
* resulting in a one dimensional range of the minimum and
|
||||
* maximum value on that axis.
|
||||
*
|
||||
* @param {Array.<Vector>} points The points to flatten.
|
||||
* @param {Vector} normal The unit vector axis to flatten on.
|
||||
* @param {Array.<number>} result An array. After calling this function,
|
||||
* result[0] will be the minimum value,
|
||||
* result[1] will be the maximum value.
|
||||
*/
|
||||
public static flattenPointsOn(points, normal, result) {
|
||||
|
||||
var min = Number.MAX_VALUE;
|
||||
var max = -Number.MAX_VALUE;
|
||||
var len = points.length;
|
||||
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
// Get the magnitude of the projection of the point onto the normal
|
||||
var dot = points[i].dot(normal);
|
||||
if (dot < min) { min = dot; }
|
||||
if (dot > max) { max = dot; }
|
||||
}
|
||||
|
||||
result[0] = min; result[1] = max;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Pool of Vectors used in calculations.
|
||||
*
|
||||
* @type {Array.<Vector>}
|
||||
*/
|
||||
public static T_VECTORS: Vector2[];
|
||||
|
||||
/**
|
||||
* Pool of Arrays used in calculations.
|
||||
*
|
||||
* @type {Array.<Array.<*>>}
|
||||
*/
|
||||
public static T_ARRAYS;
|
||||
|
||||
/**
|
||||
* Check whether two convex clockwise polygons are separated by the specified
|
||||
* axis (must be a unit vector).
|
||||
*
|
||||
* @param {Vector} aPos The position of the first polygon.
|
||||
* @param {Vector} bPos The position of the second polygon.
|
||||
* @param {Array.<Vector>} aPoints The points in the first polygon.
|
||||
* @param {Array.<Vector>} bPoints The points in the second polygon.
|
||||
* @param {Vector} axis The axis (unit sized) to test against. The points of both polygons
|
||||
* will be projected onto this axis.
|
||||
* @param {Response=} response A Response object (optional) which will be populated
|
||||
* if the axis is not a separating axis.
|
||||
* @return {boolean} true if it is a separating axis, false otherwise. If false,
|
||||
* and a response is passed in, information about how much overlap and
|
||||
* the direction of the overlap will be populated.
|
||||
*/
|
||||
public static isSeparatingAxis(aPos, bPos, aPoints, bPoints, axis, response?:Response = null): bool {
|
||||
|
||||
var rangeA = Collision.T_ARRAYS.pop();
|
||||
var rangeB = Collision.T_ARRAYS.pop();
|
||||
|
||||
// Get the magnitude of the offset between the two polygons
|
||||
var offsetV = Collision.T_VECTORS.pop().copyFrom(bPos).sub(aPos);
|
||||
var projectedOffset = offsetV.dot(axis);
|
||||
|
||||
// Project the polygons onto the axis.
|
||||
Collision.flattenPointsOn(aPoints, axis, rangeA);
|
||||
Collision.flattenPointsOn(bPoints, axis, rangeB);
|
||||
|
||||
// Move B's range to its position relative to A.
|
||||
rangeB[0] += projectedOffset;
|
||||
rangeB[1] += projectedOffset;
|
||||
|
||||
// Check if there is a gap. If there is, this is a separating axis and we can stop
|
||||
if (rangeA[0] > rangeB[1] || rangeB[0] > rangeA[1])
|
||||
{
|
||||
Collision.T_VECTORS.push(offsetV);
|
||||
Collision.T_ARRAYS.push(rangeA);
|
||||
Collision.T_ARRAYS.push(rangeB);
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we're calculating a response, calculate the overlap.
|
||||
if (response)
|
||||
{
|
||||
var overlap = 0;
|
||||
|
||||
// A starts further left than B
|
||||
if (rangeA[0] < rangeB[0])
|
||||
{
|
||||
response.aInB = false;
|
||||
|
||||
// A ends before B does. We have to pull A out of B
|
||||
if (rangeA[1] < rangeB[1])
|
||||
{
|
||||
overlap = rangeA[1] - rangeB[0];
|
||||
response.bInA = false;
|
||||
// B is fully inside A. Pick the shortest way out.
|
||||
}
|
||||
else
|
||||
{
|
||||
var option1 = rangeA[1] - rangeB[0];
|
||||
var option2 = rangeB[1] - rangeA[0];
|
||||
overlap = option1 < option2 ? option1 : -option2;
|
||||
}
|
||||
// B starts further left than A
|
||||
}
|
||||
else
|
||||
{
|
||||
response.bInA = false;
|
||||
|
||||
// B ends before A ends. We have to push A out of B
|
||||
if (rangeA[1] > rangeB[1])
|
||||
{
|
||||
overlap = rangeA[0] - rangeB[1];
|
||||
response.aInB = false;
|
||||
// A is fully inside B. Pick the shortest way out.
|
||||
}
|
||||
else
|
||||
{
|
||||
var option1 = rangeA[1] - rangeB[0];
|
||||
var option2 = rangeB[1] - rangeA[0];
|
||||
overlap = option1 < option2 ? option1 : -option2;
|
||||
}
|
||||
}
|
||||
|
||||
// If this is the smallest amount of overlap we've seen so far, set it as the minimum overlap.
|
||||
var absOverlap = Math.abs(overlap);
|
||||
|
||||
if (absOverlap < response.overlap)
|
||||
{
|
||||
response.overlap = absOverlap;
|
||||
response.overlapN.copyFrom(axis);
|
||||
|
||||
if (overlap < 0)
|
||||
{
|
||||
response.overlapN.reverse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collision.T_VECTORS.push(offsetV);
|
||||
Collision.T_ARRAYS.push(rangeA);
|
||||
Collision.T_ARRAYS.push(rangeB);
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public static LEFT_VORNOI_REGION:number = -1;
|
||||
public static MIDDLE_VORNOI_REGION:number = 0;
|
||||
public static RIGHT_VORNOI_REGION:number = 1;
|
||||
|
||||
/**
|
||||
* Calculates which Vornoi region a point is on a line segment.
|
||||
* It is assumed that both the line and the point are relative to (0, 0)
|
||||
*
|
||||
* | (0) |
|
||||
* (-1) [0]--------------[1] (1)
|
||||
* | (0) |
|
||||
*
|
||||
* @param {Vector} line The line segment.
|
||||
* @param {Vector} point The point.
|
||||
* @return {number} LEFT_VORNOI_REGION (-1) if it is the left region,
|
||||
* MIDDLE_VORNOI_REGION (0) if it is the middle region,
|
||||
* RIGHT_VORNOI_REGION (1) if it is the right region.
|
||||
*/
|
||||
public static vornoiRegion(line: Vector2, point: Vector2): number {
|
||||
|
||||
var len2 = line.length2();
|
||||
var dp = point.dot(line);
|
||||
|
||||
if (dp < 0) { return Collision.LEFT_VORNOI_REGION; }
|
||||
else if (dp > len2) { return Collision.RIGHT_VORNOI_REGION; }
|
||||
else { return Collision.MIDDLE_VORNOI_REGION; }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if two circles intersect.
|
||||
*
|
||||
* @param {Circle} a The first circle.
|
||||
* @param {Circle} b The second circle.
|
||||
* @param {Response=} response Response object (optional) that will be populated if
|
||||
* the circles intersect.
|
||||
* @return {boolean} true if the circles intersect, false if they don't.
|
||||
*/
|
||||
public static testCircleCircle(a: Circle, b: Circle, response?: Response = null): bool {
|
||||
|
||||
var differenceV = Collision.T_VECTORS.pop().copyFrom(b.pos).sub(a.pos);
|
||||
var totalRadius = a.radius + b.radius;
|
||||
var totalRadiusSq = totalRadius * totalRadius;
|
||||
var distanceSq = differenceV.length2();
|
||||
|
||||
if (distanceSq > totalRadiusSq)
|
||||
{
|
||||
// They do not intersect
|
||||
Collision.T_VECTORS.push(differenceV);
|
||||
return false;
|
||||
}
|
||||
|
||||
// They intersect. If we're calculating a response, calculate the overlap.
|
||||
if (response)
|
||||
{
|
||||
var dist = Math.sqrt(distanceSq);
|
||||
response.a = a;
|
||||
response.b = b;
|
||||
response.overlap = totalRadius - dist;
|
||||
response.overlapN.copyFrom(differenceV.normalize());
|
||||
response.overlapV.copyFrom(differenceV).scale(response.overlap);
|
||||
response.aInB = a.radius <= b.radius && dist <= b.radius - a.radius;
|
||||
response.bInA = b.radius <= a.radius && dist <= a.radius - b.radius;
|
||||
}
|
||||
|
||||
Collision.T_VECTORS.push(differenceV);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a polygon and a circle intersect.
|
||||
*
|
||||
* @param {Polygon} polygon The polygon.
|
||||
* @param {Circle} circle The circle.
|
||||
* @param {Response=} response Response object (optional) that will be populated if
|
||||
* they interset.
|
||||
* @return {boolean} true if they intersect, false if they don't.
|
||||
*/
|
||||
public static testPolygonCircle(polygon: Polygon, circle: Circle, response?: Response = null): bool {
|
||||
|
||||
var circlePos = Collision.T_VECTORS.pop().copyFrom(circle.pos).sub(polygon.pos);
|
||||
var radius = circle.radius;
|
||||
var radius2 = radius * radius;
|
||||
var points = polygon.points;
|
||||
var len = points.length;
|
||||
var edge = T_VECTORS.pop();
|
||||
var point = T_VECTORS.pop();
|
||||
|
||||
// For each edge in the polygon
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
var next = i === len - 1 ? 0 : i + 1;
|
||||
var prev = i === 0 ? len - 1 : i - 1;
|
||||
var overlap = 0;
|
||||
var overlapN = null;
|
||||
|
||||
// Get the edge
|
||||
edge.copyFrom(polygon.edges[i]);
|
||||
// Calculate the center of the cirble relative to the starting point of the edge
|
||||
point.copyFrom(circlePos).sub(points[i]);
|
||||
|
||||
// If the distance between the center of the circle and the point
|
||||
// is bigger than the radius, the polygon is definitely not fully in
|
||||
// the circle.
|
||||
if (response && point.length2() > radius2)
|
||||
{
|
||||
response.aInB = false;
|
||||
}
|
||||
|
||||
// Calculate which Vornoi region the center of the circle is in.
|
||||
var region = vornoiRegion(edge, point);
|
||||
|
||||
if (region === Collision.LEFT_VORNOI_REGION)
|
||||
{
|
||||
// Need to make sure we're in the RIGHT_VORNOI_REGION of the previous edge.
|
||||
edge.copyFrom(polygon.edges[prev]);
|
||||
|
||||
// Calculate the center of the circle relative the starting point of the previous edge
|
||||
var point2 = Collision.T_VECTORS.pop().copyFrom(circlePos).sub(points[prev]);
|
||||
region = vornoiRegion(edge, point2);
|
||||
|
||||
if (region === Collision.RIGHT_VORNOI_REGION)
|
||||
{
|
||||
// It's in the region we want. Check if the circle intersects the point.
|
||||
var dist = point.length2();
|
||||
|
||||
if (dist > radius)
|
||||
{
|
||||
// No intersection
|
||||
Collision.T_VECTORS.push(circlePos);
|
||||
Collision.T_VECTORS.push(edge);
|
||||
Collision.T_VECTORS.push(point);
|
||||
Collision.T_VECTORS.push(point2);
|
||||
return false;
|
||||
}
|
||||
else if (response)
|
||||
{
|
||||
// It intersects, calculate the overlap
|
||||
response.bInA = false;
|
||||
overlapN = point.normalize();
|
||||
overlap = radius - dist;
|
||||
}
|
||||
}
|
||||
|
||||
Collision.T_VECTORS.push(point2);
|
||||
|
||||
}
|
||||
else if (region === Collision.RIGHT_VORNOI_REGION)
|
||||
{
|
||||
// Need to make sure we're in the left region on the next edge
|
||||
edge.copyFrom(polygon.edges[next]);
|
||||
|
||||
// Calculate the center of the circle relative to the starting point of the next edge
|
||||
point.copyFrom(circlePos).sub(points[next]);
|
||||
region = vornoiRegion(edge, point);
|
||||
|
||||
if (region === Collision.LEFT_VORNOI_REGION)
|
||||
{
|
||||
// It's in the region we want. Check if the circle intersects the point.
|
||||
var dist = point.length2();
|
||||
|
||||
if (dist > radius)
|
||||
{
|
||||
// No intersection
|
||||
Collision.T_VECTORS.push(circlePos);
|
||||
Collision.T_VECTORS.push(edge);
|
||||
Collision.T_VECTORS.push(point);
|
||||
return false;
|
||||
}
|
||||
else if (response)
|
||||
{
|
||||
// It intersects, calculate the overlap
|
||||
response.bInA = false;
|
||||
overlapN = point.normalize();
|
||||
overlap = radius - dist;
|
||||
}
|
||||
}
|
||||
// MIDDLE_VORNOI_REGION
|
||||
}
|
||||
else
|
||||
{
|
||||
// Need to check if the circle is intersecting the edge,
|
||||
// Change the edge into its "edge normal".
|
||||
var normal = edge.perp().normalize();
|
||||
|
||||
// Find the perpendicular distance between the center of the
|
||||
// circle and the edge.
|
||||
var dist = point.dot(normal);
|
||||
var distAbs = Math.abs(dist);
|
||||
|
||||
// If the circle is on the outside of the edge, there is no intersection
|
||||
if (dist > 0 && distAbs > radius)
|
||||
{
|
||||
Collision.T_VECTORS.push(circlePos);
|
||||
Collision.T_VECTORS.push(normal);
|
||||
Collision.T_VECTORS.push(point);
|
||||
return false;
|
||||
}
|
||||
else if (response)
|
||||
{
|
||||
// It intersects, calculate the overlap.
|
||||
overlapN = normal;
|
||||
overlap = radius - dist;
|
||||
// If the center of the circle is on the outside of the edge, or part of the
|
||||
// circle is on the outside, the circle is not fully inside the polygon.
|
||||
if (dist >= 0 || overlap < 2 * radius)
|
||||
{
|
||||
response.bInA = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If this is the smallest overlap we've seen, keep it.
|
||||
// (overlapN may be null if the circle was in the wrong Vornoi region)
|
||||
if (overlapN && response && Math.abs(overlap) < Math.abs(response.overlap))
|
||||
{
|
||||
response.overlap = overlap;
|
||||
response.overlapN.copyFrom(overlapN);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the final overlap vector - based on the smallest overlap.
|
||||
if (response)
|
||||
{
|
||||
response.a = polygon;
|
||||
response.b = circle;
|
||||
response.overlapV.copyFrom(response.overlapN).scale(response.overlap);
|
||||
}
|
||||
|
||||
Collision.T_VECTORS.push(circlePos);
|
||||
Collision.T_VECTORS.push(edge);
|
||||
Collision.T_VECTORS.push(point);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a circle and a polygon intersect.
|
||||
*
|
||||
* NOTE: This runs slightly slower than polygonCircle as it just
|
||||
* runs polygonCircle and reverses everything at the end.
|
||||
*
|
||||
* @param {Circle} circle The circle.
|
||||
* @param {Polygon} polygon The polygon.
|
||||
* @param {Response=} response Response object (optional) that will be populated if
|
||||
* they interset.
|
||||
* @return {boolean} true if they intersect, false if they don't.
|
||||
*/
|
||||
public static testCirclePolygon(circle: Circle, polygon: Polygon, response?: Response = null): bool {
|
||||
|
||||
var result = Collision.testPolygonCircle(polygon, circle, response);
|
||||
|
||||
if (result && response)
|
||||
{
|
||||
// Swap A and B in the response.
|
||||
var a = response.a;
|
||||
var aInB = response.aInB;
|
||||
response.overlapN.reverse();
|
||||
response.overlapV.reverse();
|
||||
response.a = response.b;
|
||||
response.b = a;
|
||||
response.aInB = response.bInA;
|
||||
response.bInA = aInB;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether two convex, clockwise polygons intersect.
|
||||
*
|
||||
* @param {Polygon} a The first polygon.
|
||||
* @param {Polygon} b The second polygon.
|
||||
* @param {Response=} response Response object (optional) that will be populated if
|
||||
* they interset.
|
||||
* @return {boolean} true if they intersect, false if they don't.
|
||||
*/
|
||||
public static testPolygonPolygon(a: Polygon, b: Polygon, response?: Response = null): bool {
|
||||
|
||||
var aPoints = a.points;
|
||||
var aLen = aPoints.length;
|
||||
var bPoints = b.points;
|
||||
var bLen = bPoints.length;
|
||||
|
||||
// If any of the edge normals of A is a separating axis, no intersection.
|
||||
for (var i = 0; i < aLen; i++)
|
||||
{
|
||||
if (Collision.isSeparatingAxis(a.pos, b.pos, aPoints, bPoints, a.normals[i], response))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// If any of the edge normals of B is a separating axis, no intersection.
|
||||
for (var i = 0; i < bLen; i++)
|
||||
{
|
||||
if (Collision.isSeparatingAxis(a.pos, b.pos, aPoints, bPoints, b.normals[i], response))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Since none of the edge normals of A or B are a separating axis, there is an intersection
|
||||
// and we've already calculated the smallest overlap (in isSeparatingAxis). Calculate the
|
||||
// final overlap vector.
|
||||
if (response)
|
||||
{
|
||||
response.a = a;
|
||||
response.b = b;
|
||||
response.overlapV.copyFrom(response.overlapN).scale(response.overlap);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+9
-120
@@ -6,6 +6,7 @@
|
||||
/// <reference path="DynamicTexture.ts" />
|
||||
/// <reference path="FXManager.ts" />
|
||||
/// <reference path="GameMath.ts" />
|
||||
/// <reference path="GameObjectFactory.ts" />
|
||||
/// <reference path="Group.ts" />
|
||||
/// <reference path="Loader.ts" />
|
||||
/// <reference path="Motion.ts" />
|
||||
@@ -172,6 +173,12 @@ module Phaser {
|
||||
*/
|
||||
public onDestroyCallback = null;
|
||||
|
||||
/**
|
||||
* Reference to the GameObject Factory.
|
||||
* @type {GameObjectFactory}
|
||||
*/
|
||||
public add: GameObjectFactory;
|
||||
|
||||
/**
|
||||
* Reference to the assets cache.
|
||||
* @type {Cache}
|
||||
@@ -251,7 +258,7 @@ module Phaser {
|
||||
public rnd: RandomDataGenerator;
|
||||
|
||||
/**
|
||||
* Device detector.
|
||||
* Contains device information and capabilities.
|
||||
* @type {Device}
|
||||
*/
|
||||
public device: Device;
|
||||
@@ -292,6 +299,7 @@ module Phaser {
|
||||
this.math = new GameMath(this);
|
||||
this.stage = new Stage(this, parent, width, height);
|
||||
this.world = new World(this, width, height);
|
||||
this.add = new GameObjectFactory(this);
|
||||
this.sound = new SoundManager(this);
|
||||
this.cache = new Cache(this);
|
||||
this.collision = new Collision(this);
|
||||
@@ -619,125 +627,6 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
// Handy Proxy methods
|
||||
|
||||
/**
|
||||
* Create a new camera with specific position and size.
|
||||
*
|
||||
* @param x {number} X position of the new camera.
|
||||
* @param y {number} Y position of the new camera.
|
||||
* @param width {number} Width of the new camera.
|
||||
* @param height {number} Height of the new camera.
|
||||
* @returns {Camera} The newly created camera object.
|
||||
*/
|
||||
public createCamera(x: number, y: number, width: number, height: number): Camera {
|
||||
return this.world.createCamera(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new GeomSprite with specific position.
|
||||
*
|
||||
* @param x {number} X position of the new geom sprite.
|
||||
* @param y {number} Y position of the new geom sprite.
|
||||
* @returns {GeomSprite} The newly created geom sprite object.
|
||||
*/
|
||||
public createGeomSprite(x: number, y: number): GeomSprite {
|
||||
return this.world.createGeomSprite(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public createSprite(x: number, y: number, key?: string = ''): Sprite {
|
||||
return this.world.createSprite(x, y, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DynamicTexture with specific size.
|
||||
*
|
||||
* @param width {number} Width of the texture.
|
||||
* @param height {number} Height of the texture.
|
||||
* @returns {DynamicTexture} The newly created dynamic texture object.
|
||||
*/
|
||||
public createDynamicTexture(width: number, height: number): DynamicTexture {
|
||||
return this.world.createDynamicTexture(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new object container.
|
||||
*
|
||||
* @param maxSize {number} Optional, capacity of this group.
|
||||
* @returns {Group} The newly created group.
|
||||
*/
|
||||
public createGroup(maxSize?: number = 0): Group {
|
||||
return this.world.createGroup(maxSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Particle.
|
||||
*
|
||||
* @return {Particle} The newly created particle object.
|
||||
*/
|
||||
public createParticle(): Particle {
|
||||
return this.world.createParticle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Emitter.
|
||||
*
|
||||
* @param x {number} Optional, x position of the emitter.
|
||||
* @param y {number} Optional, y position of the emitter.
|
||||
* @param size {number} Optional, size of this emitter.
|
||||
* @return {Emitter} The newly created emitter object.
|
||||
*/
|
||||
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
||||
return this.world.createEmitter(x, y, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ScrollZone object with image key, position and size.
|
||||
*
|
||||
* @param key {string} Key to a image you wish this object to use.
|
||||
* @param x {number} X position of this object.
|
||||
* @param y {number} Y position of this object.
|
||||
* @param width number} Width of this object.
|
||||
* @param height {number} Height of this object.
|
||||
* @returns {ScrollZone} The newly created scroll zone object.
|
||||
*/
|
||||
public createScrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
|
||||
return this.world.createScrollZone(key, x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Tilemap.
|
||||
*
|
||||
* @param key {string} Key for tileset image.
|
||||
* @param mapData {string} Data of this tilemap.
|
||||
* @param format {number} Format of map data. (Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON)
|
||||
* @param [resizeWorld] {boolean} resize the world to make same as tilemap?
|
||||
* @param [tileWidth] {number} width of each tile.
|
||||
* @param [tileHeight] {number} height of each tile.
|
||||
* @return {Tilemap} The newly created tilemap object.
|
||||
*/
|
||||
public createTilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
||||
return this.world.createTilemap(key, mapData, format, resizeWorld, tileWidth, tileHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a tween object for a specific object.
|
||||
*
|
||||
* @param obj Object you wish the tween will affect.
|
||||
* @return {Phaser.Tween} The newly created tween object.
|
||||
*/
|
||||
public createTween(obj): Tween {
|
||||
return this.tweens.create(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
|
||||
* Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.
|
||||
|
||||
+18
-11
@@ -1039,25 +1039,32 @@ module Phaser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a point around the x/y coordinates given to the desired angle
|
||||
* Rotates the point around the x/y coordinates given to the desired angle and distance
|
||||
* @param point {Object} Any object with exposed x and y properties
|
||||
* @param x {number} The x coordinate of the anchor point
|
||||
* @param y {number} The y coordinate of the anchor point
|
||||
* @param angle {number} The angle of the rotation in radians
|
||||
* @param point {Point} The point object to perform the rotation on
|
||||
* @param {Number} angle The angle in radians (unless asDegrees is true) to return the point from.
|
||||
* @param {Boolean} asDegrees Is the given angle in radians (false) or degrees (true)?
|
||||
* @param {Number} distance An optional distance constraint between the point and the anchor
|
||||
* @return The modified point object
|
||||
*/
|
||||
public rotatePoint(x: number, y: number, angle: number, point) {
|
||||
public rotatePoint(point, x1: number, y1: number, angle: number, asDegrees: bool = false, distance?:number = null) {
|
||||
|
||||
var s: number = Math.sin(angle);
|
||||
var c: number = Math.cos(angle);
|
||||
if (asDegrees)
|
||||
{
|
||||
angle = angle * GameMath.DEG_TO_RAD;
|
||||
}
|
||||
|
||||
point.x -= x;
|
||||
point.y -= y;
|
||||
// Get distance from origin to the point
|
||||
if (distance === null)
|
||||
{
|
||||
distance = Math.sqrt(((x1 - point.x) * (x1 - point.x)) + ((y1 - point.y) * (y1 - point.y)));
|
||||
}
|
||||
|
||||
var newX: number = point.x * c - point.y * s;
|
||||
var newY: number = point.x * s - point.y * c;
|
||||
point.x = x1 + distance * Math.cos(angle);
|
||||
point.y = y1 + distance * Math.sin(angle);
|
||||
|
||||
return point.setTo(newX + x, newY + y);
|
||||
return point;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
/// <reference path="Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - GameObjectFactory
|
||||
*
|
||||
* A quick way to create new world objects and add existing objects to the current world.
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class GameObjectFactory {
|
||||
|
||||
/**
|
||||
* GameObjectFactory constructor
|
||||
* @param game {Game} A reference to the current Game.
|
||||
*/
|
||||
constructor(game: Phaser.Game) {
|
||||
|
||||
this._game = game;
|
||||
this._world = this._game.world;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Local private reference to Game
|
||||
*/
|
||||
private _game: Phaser.Game;
|
||||
|
||||
/**
|
||||
* Local private reference to World
|
||||
*/
|
||||
private _world: Phaser.World;
|
||||
|
||||
/**
|
||||
* Create a new camera with specific position and size.
|
||||
*
|
||||
* @param x {number} X position of the new camera.
|
||||
* @param y {number} Y position of the new camera.
|
||||
* @param width {number} Width of the new camera.
|
||||
* @param height {number} Height of the new camera.
|
||||
* @returns {Camera} The newly created camera object.
|
||||
*/
|
||||
public camera(x: number, y: number, width: number, height: number): Camera {
|
||||
return this._world.createCamera(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new GeomSprite with specific position.
|
||||
*
|
||||
* @param x {number} X position of the new geom sprite.
|
||||
* @param y {number} Y position of the new geom sprite.
|
||||
* @returns {GeomSprite} The newly created geom sprite object.
|
||||
*/
|
||||
public geomSprite(x: number, y: number): GeomSprite {
|
||||
return this._world.createGeomSprite(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public sprite(x: number, y: number, key?: string = ''): Sprite {
|
||||
return this._world.createSprite(x, y, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DynamicTexture with specific size.
|
||||
*
|
||||
* @param width {number} Width of the texture.
|
||||
* @param height {number} Height of the texture.
|
||||
* @returns {DynamicTexture} The newly created dynamic texture object.
|
||||
*/
|
||||
public dynamicTexture(width: number, height: number): DynamicTexture {
|
||||
return this._world.createDynamicTexture(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new object container.
|
||||
*
|
||||
* @param maxSize {number} Optional, capacity of this group.
|
||||
* @returns {Group} The newly created group.
|
||||
*/
|
||||
public group(maxSize?: number = 0): Group {
|
||||
return this._world.createGroup(maxSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Particle.
|
||||
*
|
||||
* @return {Particle} The newly created particle object.
|
||||
*/
|
||||
public particle(): Particle {
|
||||
return this._world.createParticle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Emitter.
|
||||
*
|
||||
* @param x {number} Optional, x position of the emitter.
|
||||
* @param y {number} Optional, y position of the emitter.
|
||||
* @param size {number} Optional, size of this emitter.
|
||||
* @return {Emitter} The newly created emitter object.
|
||||
*/
|
||||
public emitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
||||
return this._world.createEmitter(x, y, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ScrollZone object with image key, position and size.
|
||||
*
|
||||
* @param key {string} Key to a image you wish this object to use.
|
||||
* @param x {number} X position of this object.
|
||||
* @param y {number} Y position of this object.
|
||||
* @param width number} Width of this object.
|
||||
* @param height {number} Height of this object.
|
||||
* @returns {ScrollZone} The newly created scroll zone object.
|
||||
*/
|
||||
public scrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
|
||||
return this._world.createScrollZone(key, x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Tilemap.
|
||||
*
|
||||
* @param key {string} Key for tileset image.
|
||||
* @param mapData {string} Data of this tilemap.
|
||||
* @param format {number} Format of map data. (Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON)
|
||||
* @param [resizeWorld] {boolean} resize the world to make same as tilemap?
|
||||
* @param [tileWidth] {number} width of each tile.
|
||||
* @param [tileHeight] {number} height of each tile.
|
||||
* @return {Tilemap} The newly created tilemap object.
|
||||
*/
|
||||
public tilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
||||
return this._world.createTilemap(key, mapData, format, resizeWorld, tileWidth, tileHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a tween object for a specific object.
|
||||
*
|
||||
* @param obj Object you wish the tween will affect.
|
||||
* @return {Phaser.Tween} The newly created tween object.
|
||||
*/
|
||||
public tween(obj): Tween {
|
||||
return this._game.tweens.create(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an existing Sprite to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param sprite The Sprite to add to the Game World
|
||||
* @return {Phaser.Sprite} The Sprite object
|
||||
*/
|
||||
public existingSprite(sprite: Sprite): Sprite {
|
||||
return this._world.group.add(sprite);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an existing GeomSprite to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param sprite The GeomSprite to add to the Game World
|
||||
* @return {Phaser.GeomSprite} The GeomSprite object
|
||||
*/
|
||||
public existingGeomSprite(sprite: GeomSprite): GeomSprite {
|
||||
return this._world.group.add(sprite);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an existing Emitter to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param emitter The Emitter to add to the Game World
|
||||
* @return {Phaser.Emitter} The Emitter object
|
||||
*/
|
||||
public existingEmitter(emitter: Emitter): Emitter {
|
||||
return this._world.group.add(emitter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an existing ScrollZone to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param scrollZone The ScrollZone to add to the Game World
|
||||
* @return {Phaser.ScrollZone} The ScrollZone object
|
||||
*/
|
||||
public existingScrollZone(scrollZone: ScrollZone): ScrollZone {
|
||||
return this._world.group.add(scrollZone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an existing Tilemap to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param tilemap The Tilemap to add to the Game World
|
||||
* @return {Phaser.Tilemap} The Tilemap object
|
||||
*/
|
||||
public existingTilemap(tilemap: Tilemap): Tilemap {
|
||||
return this._world.group.add(tilemap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an existing Tween to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param tween The Tween to add to the Game World
|
||||
* @return {Phaser.Tween} The Tween object
|
||||
*/
|
||||
public existingTween(tween: Tween): Tween {
|
||||
return this._game.tweens.add(tween);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -76,6 +76,12 @@ module Phaser {
|
||||
*/
|
||||
public progress: number;
|
||||
|
||||
/**
|
||||
* The crossOrigin value applied to loaded images
|
||||
* @type {string}
|
||||
*/
|
||||
public crossOrigin: string = '';
|
||||
|
||||
/**
|
||||
* Reset loader, this will remove all loaded assets.
|
||||
*/
|
||||
@@ -280,6 +286,7 @@ module Phaser {
|
||||
file.data.name = file.key;
|
||||
file.data.onload = () => this.fileComplete(file.key);
|
||||
file.data.onerror = () => this.fileError(file.key);
|
||||
file.data.crossOrigin = this.crossOrigin;
|
||||
file.data.src = file.url;
|
||||
break;
|
||||
|
||||
|
||||
@@ -79,6 +79,10 @@
|
||||
<Content Include="GameMath.js">
|
||||
<DependentUpon>GameMath.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="GameObjectFactory.ts" />
|
||||
<Content Include="GameObjectFactory.js">
|
||||
<DependentUpon>GameObjectFactory.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="gameobjects\Emitter.js">
|
||||
<DependentUpon>Emitter.ts</DependentUpon>
|
||||
</Content>
|
||||
@@ -107,6 +111,14 @@
|
||||
</Content>
|
||||
<TypeScriptCompile Include="verlet\AngleConstraint.ts" />
|
||||
<TypeScriptCompile Include="VerletManager.ts" />
|
||||
<TypeScriptCompile Include="geom\Polygon.ts" />
|
||||
<Content Include="geom\Polygon.js">
|
||||
<DependentUpon>Polygon.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="geom\Response.ts" />
|
||||
<Content Include="geom\Response.js">
|
||||
<DependentUpon>Response.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="VerletManager.js">
|
||||
<DependentUpon>VerletManager.ts</DependentUpon>
|
||||
</Content>
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Phaser
|
||||
*
|
||||
* v0.9.5 - April 28th 2013
|
||||
* v0.9.6 - May 21st 2013
|
||||
*
|
||||
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
||||
*
|
||||
@@ -16,6 +16,6 @@
|
||||
|
||||
module Phaser {
|
||||
|
||||
export var VERSION: string = 'Phaser version 0.9.5';
|
||||
export var VERSION: string = 'Phaser version 0.9.6';
|
||||
|
||||
}
|
||||
|
||||
+18
-6
@@ -195,23 +195,35 @@ module Phaser {
|
||||
{
|
||||
if (this._game.paused == false)
|
||||
{
|
||||
this._pauseScreen.onPaused();
|
||||
this.saveCanvasValues();
|
||||
this._game.paused = true;
|
||||
this.pauseGame();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this._game.paused == true)
|
||||
{
|
||||
this._pauseScreen.onResume();
|
||||
this._game.paused = false;
|
||||
this.restoreCanvasValues();
|
||||
this.resumeGame();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public pauseGame() {
|
||||
|
||||
this._pauseScreen.onPaused();
|
||||
this.saveCanvasValues();
|
||||
this._game.paused = true;
|
||||
|
||||
}
|
||||
|
||||
public resumeGame() {
|
||||
|
||||
this._pauseScreen.onResume();
|
||||
this.restoreCanvasValues();
|
||||
this._game.paused = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DOM offset values of the given element
|
||||
*/
|
||||
|
||||
+7
-119
@@ -18,6 +18,7 @@ module Phaser {
|
||||
|
||||
this.game = game;
|
||||
|
||||
this.add = game.add;
|
||||
this.camera = game.camera;
|
||||
this.cache = game.cache;
|
||||
this.collision = game.collision;
|
||||
@@ -56,6 +57,12 @@ module Phaser {
|
||||
*/
|
||||
public collision: Collision;
|
||||
|
||||
/**
|
||||
* Reference to the GameObject Factory.
|
||||
* @type {GameObjectFactory}
|
||||
*/
|
||||
public add: GameObjectFactory;
|
||||
|
||||
/**
|
||||
* Reference to the input manager
|
||||
* @type {Input}
|
||||
@@ -144,125 +151,6 @@ module Phaser {
|
||||
*/
|
||||
public destroy() { }
|
||||
|
||||
// Handy Proxy methods
|
||||
|
||||
/**
|
||||
* Create a new camera with specific position and size.
|
||||
*
|
||||
* @param x {number} X position of the new camera.
|
||||
* @param y {number} Y position of the new camera.
|
||||
* @param width {number} Width of the new camera.
|
||||
* @param height {number} Height of the new camera.
|
||||
* @returns {Camera} The newly created camera object.
|
||||
*/
|
||||
public createCamera(x: number, y: number, width: number, height: number): Camera {
|
||||
return this.game.world.createCamera(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new GeomSprite with specific position.
|
||||
*
|
||||
* @param x {number} X position of the new geom sprite.
|
||||
* @param y {number} Y position of the new geom sprite.
|
||||
* @returns {GeomSprite} The newly created geom sprite object.
|
||||
*/
|
||||
public createGeomSprite(x: number, y: number): GeomSprite {
|
||||
return this.world.createGeomSprite(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public createSprite(x: number, y: number, key?: string = ''): Sprite {
|
||||
return this.game.world.createSprite(x, y, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DynamicTexture with specific size.
|
||||
*
|
||||
* @param width {number} Width of the texture.
|
||||
* @param height {number} Height of the texture.
|
||||
* @returns {DynamicTexture} The newly created dynamic texture object.
|
||||
*/
|
||||
public createDynamicTexture(width: number, height: number): DynamicTexture {
|
||||
return this.game.world.createDynamicTexture(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new object container.
|
||||
*
|
||||
* @param maxSize {number} [optional] capacity of this group.
|
||||
* @returns {Group} The newly created group.
|
||||
*/
|
||||
public createGroup(maxSize?: number = 0): Group {
|
||||
return this.game.world.createGroup(maxSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Particle.
|
||||
*
|
||||
* @return {Particle} The newly created particle object.
|
||||
*/
|
||||
public createParticle(): Particle {
|
||||
return this.game.world.createParticle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Emitter.
|
||||
*
|
||||
* @param x {number} [optional] x position of the emitter.
|
||||
* @param y {number} [optional] y position of the emitter.
|
||||
* @param size {number} [optional] size of this emitter.
|
||||
* @return {Emitter} The newly created emitter object.
|
||||
*/
|
||||
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
||||
return this.game.world.createEmitter(x, y, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ScrollZone object with image key, position and size.
|
||||
*
|
||||
* @param key {string} Key to a image you wish this object to use.
|
||||
* @param x {number} X position of this object.
|
||||
* @param y {number} Y position of this object.
|
||||
* @param width {number} Width of this object.
|
||||
* @param height {number} Height of this object.
|
||||
* @returns {ScrollZone} The newly created scroll zone object.
|
||||
*/
|
||||
public createScrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
|
||||
return this.game.world.createScrollZone(key, x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Tilemap.
|
||||
*
|
||||
* @param key {string} Key for tileset image.
|
||||
* @param mapData {string} Data of this tilemap.
|
||||
* @param format {number} Format of map data. (Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON)
|
||||
* @param resizeWorld {boolean} [optional] resize the world to make same as tilemap?
|
||||
* @param tileWidth {number} [optional] width of each tile.
|
||||
* @param tileHeight number} [optional] height of each tile.
|
||||
* @return {Tilemap} The newly created tilemap object.
|
||||
*/
|
||||
public createTilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
||||
return this.game.world.createTilemap(key, mapData, format, resizeWorld, tileWidth, tileHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a tween object for a specific object.
|
||||
*
|
||||
* @param obj Object you wish the tween will affect.
|
||||
* @return {Phaser.Tween} The newly created tween object.
|
||||
*/
|
||||
public createTween(obj): Tween {
|
||||
return this.game.tweens.create(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method to see if one object collids another.
|
||||
* @return {boolean} Whether the given objects or groups collids.
|
||||
|
||||
@@ -30,6 +30,7 @@ module Phaser {
|
||||
* Local private reference to Game
|
||||
*/
|
||||
private _game: Phaser.Game;
|
||||
|
||||
/**
|
||||
* Local private array which is the container of all tween objects.
|
||||
*/
|
||||
|
||||
+62
-52
@@ -42,12 +42,13 @@ module Phaser.Verlet {
|
||||
}
|
||||
|
||||
private _game: Game;
|
||||
private _v = new Phaser.Vector2;
|
||||
|
||||
public composites = [];
|
||||
|
||||
public width: number;
|
||||
public height: number;
|
||||
public step: number = 32;
|
||||
public step: number = 16;
|
||||
public gravity: Vector2;
|
||||
public friction: number;
|
||||
public groundFriction: number;
|
||||
@@ -55,15 +56,14 @@ module Phaser.Verlet {
|
||||
public draggedEntity = null;
|
||||
public highlightColor = '#4f545c';
|
||||
|
||||
|
||||
/**
|
||||
* This class is actually a wrapper of canvas.
|
||||
* A reference to the canvas this renders to
|
||||
* @type {HTMLCanvasElement}
|
||||
*/
|
||||
public canvas: HTMLCanvasElement;
|
||||
|
||||
/**
|
||||
* Canvas context of this object.
|
||||
* A reference to the context this renders to
|
||||
* @type {CanvasRenderingContext2D}
|
||||
*/
|
||||
public context: CanvasRenderingContext2D;
|
||||
@@ -71,10 +71,10 @@ module Phaser.Verlet {
|
||||
/**
|
||||
* Computes time of intersection of a particle with a wall
|
||||
*
|
||||
* @param {Vec2} line wall's root position
|
||||
* @param {Vec2} p particle's position
|
||||
* @param {Vec2} dir walls's direction
|
||||
* @param {Vec2} v particle's velocity
|
||||
* @param {Vec2} line walls root position
|
||||
* @param {Vec2} p particle position
|
||||
* @param {Vec2} dir walls direction
|
||||
* @param {Vec2} v particles velocity
|
||||
*/
|
||||
public intersectionTime(wall, p, dir, v) {
|
||||
|
||||
@@ -100,81 +100,56 @@ module Phaser.Verlet {
|
||||
return new Phaser.Vector2(p.x + v.x * t, p.y + v.y * t);
|
||||
}
|
||||
|
||||
private v = new Phaser.Vector2();
|
||||
|
||||
public bounds(particle: Phaser.Verlet.Particle) {
|
||||
|
||||
this.v.mutableSet(particle.pos);
|
||||
this.v.mutableSub(particle.lastPos);
|
||||
this._v.mutableSet(particle.pos);
|
||||
this._v.mutableSub(particle.lastPos);
|
||||
|
||||
if (particle.pos.y > this.height - 1)
|
||||
{
|
||||
particle.pos.mutableSet(
|
||||
this.intersectionPoint(new Phaser.Vector2(0, this.height - 1), particle.lastPos, new Phaser.Vector2(1, 0), this.v));
|
||||
particle.pos.mutableSet(this.intersectionPoint(new Phaser.Vector2(0, this.height - 1), particle.lastPos, new Phaser.Vector2(1, 0), this._v));
|
||||
}
|
||||
|
||||
if (particle.pos.x < 0)
|
||||
{
|
||||
particle.pos.mutableSet(
|
||||
this.intersectionPoint(new Phaser.Vector2(0, 0), particle.pos, new Phaser.Vector2(0, 1), this.v));
|
||||
particle.pos.mutableSet(this.intersectionPoint(new Phaser.Vector2(0, 0), particle.pos, new Phaser.Vector2(0, 1), this._v));
|
||||
}
|
||||
|
||||
if (particle.pos.x > this.width - 1)
|
||||
{
|
||||
particle.pos.mutableSet(
|
||||
this.intersectionPoint(new Phaser.Vector2(this.width - 1, 0), particle.pos, new Phaser.Vector2(0, 1), this.v));
|
||||
particle.pos.mutableSet(this.intersectionPoint(new Phaser.Vector2(this.width - 1, 0), particle.pos, new Phaser.Vector2(0, 1), this._v));
|
||||
}
|
||||
}
|
||||
|
||||
public OLDbounds(particle: Phaser.Verlet.Particle) {
|
||||
|
||||
if (particle.pos.y > this.height - 1)
|
||||
particle.pos.y = this.height - 1;
|
||||
|
||||
if (particle.pos.x < 0)
|
||||
{
|
||||
var vx = particle.pos.x - particle.lastPos.x;
|
||||
var vy = particle.pos.y - particle.lastPos.y;
|
||||
|
||||
if (vx == 0)
|
||||
{
|
||||
particle.pos.x = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
var t = -particle.lastPos.x / vx;
|
||||
particle.pos.x = particle.lastPos.x + t * vx;
|
||||
particle.pos.y = particle.lastPos.y + t * vy;
|
||||
}
|
||||
}
|
||||
|
||||
if (particle.pos.x > this.width - 1)
|
||||
particle.pos.x = this.width - 1;
|
||||
|
||||
}
|
||||
|
||||
public createPoint(pos: Vector2) {
|
||||
|
||||
var composite = new Phaser.Verlet.Composite(this._game);
|
||||
|
||||
composite.particles.push(new Phaser.Verlet.Particle(pos));
|
||||
|
||||
this.composites.push(composite);
|
||||
|
||||
return composite;
|
||||
|
||||
}
|
||||
|
||||
public createLineSegments(vertices, stiffness) {
|
||||
|
||||
var i;
|
||||
var composite = new Phaser.Verlet.Composite(this._game);
|
||||
var i;
|
||||
|
||||
for (i in vertices)
|
||||
{
|
||||
composite.particles.push(new Phaser.Verlet.Particle(vertices[i]));
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
composite.constraints.push(new Phaser.Verlet.DistanceConstraint(composite.particles[i], composite.particles[i - 1], stiffness));
|
||||
}
|
||||
}
|
||||
|
||||
this.composites.push(composite);
|
||||
|
||||
return composite;
|
||||
|
||||
}
|
||||
@@ -186,30 +161,40 @@ module Phaser.Verlet {
|
||||
var xStride = width / segments;
|
||||
var yStride = height / segments;
|
||||
|
||||
var x, y;
|
||||
var x;
|
||||
var y;
|
||||
|
||||
for (y = 0; y < segments; ++y)
|
||||
{
|
||||
for (x = 0; x < segments; ++x)
|
||||
{
|
||||
var px = origin.x + x * xStride - width / 2 + xStride / 2;
|
||||
var py = origin.y + y * yStride - height / 2 + yStride / 2;
|
||||
|
||||
composite.particles.push(new Phaser.Verlet.Particle(new Vector2(px, py)));
|
||||
|
||||
if (x > 0)
|
||||
{
|
||||
composite.constraints.push(new Phaser.Verlet.DistanceConstraint(composite.particles[y * segments + x], composite.particles[y * segments + x - 1], stiffness));
|
||||
}
|
||||
|
||||
if (y > 0)
|
||||
{
|
||||
composite.constraints.push(new Phaser.Verlet.DistanceConstraint(composite.particles[y * segments + x], composite.particles[(y - 1) * segments + x], stiffness));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (x = 0; x < segments; ++x)
|
||||
{
|
||||
if (x % pinMod == 0)
|
||||
{
|
||||
composite.pin(x);
|
||||
}
|
||||
}
|
||||
|
||||
this.composites.push(composite);
|
||||
|
||||
return composite;
|
||||
|
||||
}
|
||||
@@ -284,7 +269,9 @@ module Phaser.Verlet {
|
||||
|
||||
// handle dragging of entities
|
||||
if (this.draggedEntity)
|
||||
this.draggedEntity.pos.mutableSet(new Vector2(this._game.input.x, this._game.input.y));
|
||||
{
|
||||
this.draggedEntity.pos.mutableSet(this._game.input.position);
|
||||
}
|
||||
|
||||
// relax
|
||||
var stepCoef = 1 / this.step;
|
||||
@@ -292,17 +279,25 @@ module Phaser.Verlet {
|
||||
for (c in this.composites)
|
||||
{
|
||||
var constraints = this.composites[c].constraints;
|
||||
|
||||
for (i = 0; i < this.step; ++i)
|
||||
{
|
||||
for (j in constraints)
|
||||
{
|
||||
constraints[j].relax(stepCoef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// bounds checking
|
||||
for (c in this.composites)
|
||||
{
|
||||
var particles = this.composites[c].particles;
|
||||
|
||||
for (i in particles)
|
||||
{
|
||||
this.bounds(particles[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -335,7 +330,7 @@ module Phaser.Verlet {
|
||||
|
||||
for (i in particles)
|
||||
{
|
||||
var d2 = particles[i].pos.dist2(new Vector2(this._game.input.x, this._game.input.y));
|
||||
var d2 = particles[i].pos.distance2(this._game.input.position);
|
||||
|
||||
if (d2 <= this.selectionRadius * this.selectionRadius && (entity == null || d2 < d2Nearest))
|
||||
{
|
||||
@@ -348,13 +343,19 @@ module Phaser.Verlet {
|
||||
|
||||
// search for pinned constraints for this entity
|
||||
for (i in constraintsNearest)
|
||||
{
|
||||
if (constraintsNearest[i] instanceof PinConstraint && constraintsNearest[i].a == entity)
|
||||
{
|
||||
entity = constraintsNearest[i];
|
||||
}
|
||||
}
|
||||
|
||||
return entity;
|
||||
|
||||
}
|
||||
|
||||
public hideNearestEntityCircle: bool = false;
|
||||
|
||||
public render() {
|
||||
|
||||
var i, c;
|
||||
@@ -365,34 +366,43 @@ module Phaser.Verlet {
|
||||
if (this.composites[c].drawConstraints)
|
||||
{
|
||||
this.composites[c].drawConstraints(this.context, this.composites[c]);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
var constraints = this.composites[c].constraints;
|
||||
|
||||
for (i in constraints)
|
||||
{
|
||||
constraints[i].render(this.context);
|
||||
}
|
||||
}
|
||||
|
||||
// draw particles
|
||||
if (this.composites[c].drawParticles)
|
||||
{
|
||||
this.composites[c].drawParticles(this.context, this.composites[c]);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
var particles = this.composites[c].particles;
|
||||
|
||||
for (i in particles)
|
||||
{
|
||||
particles[i].render(this.context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// highlight nearest / dragged entity
|
||||
var nearest = this.draggedEntity || this.nearestEntity();
|
||||
|
||||
if (nearest)
|
||||
if (nearest && this.hideNearestEntityCircle == false)
|
||||
{
|
||||
this.context.beginPath();
|
||||
this.context.arc(nearest.pos.x, nearest.pos.y, 8, 0, 2 * Math.PI);
|
||||
this.context.strokeStyle = this.highlightColor;
|
||||
this.context.stroke();
|
||||
this.context.closePath();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-2
@@ -101,13 +101,14 @@ module Phaser {
|
||||
|
||||
/**
|
||||
* Update size of this world with specific width and height.
|
||||
* You can choose update camera bounds automatically or not.
|
||||
* You can choose update camera bounds and verlet manager automatically or not.
|
||||
*
|
||||
* @param width {number} New width of the world.
|
||||
* @param height {number} New height of the world.
|
||||
* @param [updateCameraBounds] {boolean} update camera bounds automatically or not. Default to true.
|
||||
* @param [updateVerletBounds] {boolean} update verlet 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, updateVerletBounds: bool = true) {
|
||||
|
||||
this.bounds.width = width;
|
||||
this.bounds.height = height;
|
||||
@@ -117,6 +118,12 @@ module Phaser {
|
||||
this._game.camera.setBounds(0, 0, width, height);
|
||||
}
|
||||
|
||||
if (updateVerletBounds == true)
|
||||
{
|
||||
this._game.verlet.width = width;
|
||||
this._game.verlet.height = height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public get width(): number {
|
||||
|
||||
@@ -835,6 +835,12 @@ module Phaser {
|
||||
* Clean up memory.
|
||||
*/
|
||||
public destroy() {
|
||||
}
|
||||
|
||||
public setPosition(x: number, y: number) {
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../geom/Polygon.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - GeomSprite
|
||||
@@ -71,6 +72,12 @@ module Phaser {
|
||||
*/
|
||||
public static RECTANGLE: number = 4;
|
||||
|
||||
/**
|
||||
* Polygon.
|
||||
* @type {number}
|
||||
*/
|
||||
public static POLYGON: number = 5;
|
||||
|
||||
/**
|
||||
* Circle shape container. A Circle instance.
|
||||
* @type {Circle}
|
||||
@@ -95,6 +102,12 @@ module Phaser {
|
||||
*/
|
||||
public rect: Rectangle;
|
||||
|
||||
/**
|
||||
* Polygon shape container. A Polygon instance.
|
||||
* @type {Polygon}
|
||||
*/
|
||||
public polygon: Polygon;
|
||||
|
||||
/**
|
||||
* Render outline of this sprite or not. (default is true)
|
||||
* @type {boolean}
|
||||
@@ -243,6 +256,22 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a polygon object
|
||||
* @param width {Number} Width of the rectangle
|
||||
* @param height {Number} Height of the rectangle
|
||||
* @return {GeomSprite} GeomSprite instance.
|
||||
*/
|
||||
createPolygon(points?: Vector2[] = []): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.polygon = new Polygon(new Vector2(this.x, this.y), points);
|
||||
this.type = GeomSprite.POLYGON;
|
||||
//this.frameBounds.copyFrom(this.rect);
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all geom shapes of this sprite.
|
||||
*/
|
||||
|
||||
@@ -109,9 +109,15 @@ module Phaser {
|
||||
/**
|
||||
* Load graphic for this sprite. (graphic can be SpriteSheet or Texture)
|
||||
* @param key {string} Key of the graphic you want to load for this sprite.
|
||||
* @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean
|
||||
* @return {Sprite} Sprite instance itself.
|
||||
*/
|
||||
public loadGraphic(key: string): Sprite {
|
||||
public loadGraphic(key: string, clearAnimations: bool = true): Sprite {
|
||||
|
||||
if (clearAnimations && this.animations.frameData !== null)
|
||||
{
|
||||
this.animations.destroy();
|
||||
}
|
||||
|
||||
if (this._game.cache.getImage(key) !== null)
|
||||
{
|
||||
@@ -127,8 +133,8 @@ module Phaser {
|
||||
{
|
||||
this._texture = this._game.cache.getImage(key);
|
||||
this.animations.loadFrameData(this._game.cache.getFrameData(key));
|
||||
//this.collisionMask.width = this._texture.width;
|
||||
//this.collisionMask.height = this._texture.height;
|
||||
this.collisionMask.width = this.animations.currentFrame.width;
|
||||
this.collisionMask.height = this.animations.currentFrame.height;
|
||||
}
|
||||
|
||||
this._dynamicTexture = false;
|
||||
@@ -181,19 +187,27 @@ module Phaser {
|
||||
*/
|
||||
public inCamera(camera: Rectangle): bool {
|
||||
|
||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
||||
// Object fixed in place regardless of the camera scrolling? Then it's always visible
|
||||
if (this.scrollFactor.x == 0 && this.scrollFactor.y == 0)
|
||||
{
|
||||
this._dx = this.frameBounds.x - (camera.x * this.scrollFactor.x);
|
||||
this._dy = this.frameBounds.y - (camera.y * this.scrollFactor.x);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, if it's scrolling perfectly in sync with the camera (1 to 1) then it's a simple bounds check on world coordinates
|
||||
if (this.scrollFactor.x == 1 && this.scrollFactor.y == 1)
|
||||
{
|
||||
return camera.intersects(this.frameBounds, this.frameBounds.length);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Else apply the offsets
|
||||
this._dx = (this.frameBounds.x - camera.x) * this.scrollFactor.x;
|
||||
this._dy = (this.frameBounds.y - camera.y) * this.scrollFactor.y;
|
||||
this._dw = this.frameBounds.width * this.scale.x;
|
||||
this._dh = this.frameBounds.height * this.scale.y;
|
||||
|
||||
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
|
||||
}
|
||||
else
|
||||
{
|
||||
return camera.intersects(this.frameBounds, this.frameBounds.length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -250,8 +264,9 @@ module Phaser {
|
||||
this._sy = 0;
|
||||
this._sw = this.frameBounds.width;
|
||||
this._sh = this.frameBounds.height;
|
||||
this._dx = cameraOffsetX + (this.frameBounds.topLeft.x - camera.worldView.x);
|
||||
this._dy = cameraOffsetY + (this.frameBounds.topLeft.y - camera.worldView.y);
|
||||
|
||||
this._dx = (cameraOffsetX * this.scrollFactor.x) + this.frameBounds.topLeft.x - (camera.worldView.x * this.scrollFactor.x);
|
||||
this._dy = (cameraOffsetY * this.scrollFactor.y) + this.frameBounds.topLeft.y - (camera.worldView.y * this.scrollFactor.y);
|
||||
this._dw = this.frameBounds.width * this.scale.x;
|
||||
this._dh = this.frameBounds.height * this.scale.y;
|
||||
|
||||
@@ -305,10 +320,10 @@ module Phaser {
|
||||
}
|
||||
|
||||
// Apply camera difference
|
||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
||||
if (this.scrollFactor.x !== 1 || this.scrollFactor.y !== 1)
|
||||
{
|
||||
this._dx -= (camera.worldView.x * this.scrollFactor.x);
|
||||
this._dy -= (camera.worldView.y * this.scrollFactor.y);
|
||||
//this._dx -= (camera.worldView.x * this.scrollFactor.x);
|
||||
//this._dy -= (camera.worldView.y * this.scrollFactor.y);
|
||||
}
|
||||
|
||||
// Rotation - needs to work from origin point really, but for now from center
|
||||
|
||||
+11
-2
@@ -21,12 +21,14 @@ module Phaser {
|
||||
**/
|
||||
constructor(x: number = 0, y: number = 0, diameter: number = 0) {
|
||||
|
||||
this._pos = new Vector2;
|
||||
this.setTo(x, y, diameter);
|
||||
|
||||
}
|
||||
|
||||
private _diameter: number = 0;
|
||||
private _radius: number = 0;
|
||||
private _pos: Vector2;
|
||||
|
||||
/**
|
||||
* The x coordinate of the center of the circle
|
||||
@@ -42,15 +44,22 @@ module Phaser {
|
||||
**/
|
||||
public y: number = 0;
|
||||
|
||||
/**
|
||||
* The position of this Circle object represented by a Vector2
|
||||
* @property pos
|
||||
* @type Vector2
|
||||
**/
|
||||
public get pos(): Vector2 {
|
||||
return this._pos.setTo(this.x, this.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* The diameter of the circle. The largest distance between any two points on the circle. The same as the radius * 2.
|
||||
* @method diameter
|
||||
* @return {Number}
|
||||
**/
|
||||
get diameter(): number {
|
||||
|
||||
return this._diameter;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Polygon
|
||||
*
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Polygon {
|
||||
|
||||
/**
|
||||
* A *convex* clockwise polygon
|
||||
* @class Polygon
|
||||
* @constructor
|
||||
* @param {Vector2} pos A vector representing the origin of the polygon (all other points are relative to this one)
|
||||
* @param {Array.<Vector2>} points An Array of vectors representing the points in the polygon, in clockwise order.
|
||||
**/
|
||||
constructor(pos?: Vector2 = new Vector2, points?: Vector2[] = [], parent?:any = null) {
|
||||
|
||||
this.pos = pos;
|
||||
this.points = points;
|
||||
this.parent = parent;
|
||||
this.recalc();
|
||||
|
||||
}
|
||||
|
||||
public parent: any;
|
||||
public pos: Vector2;
|
||||
public points: Vector2[];
|
||||
public edges: Vector2[];
|
||||
public normals: Vector2[];
|
||||
|
||||
/**
|
||||
* Recalculate the edges and normals of the polygon. This
|
||||
* MUST be called if the points array is modified at all and
|
||||
* the edges or normals are to be accessed.
|
||||
*/
|
||||
public recalc() {
|
||||
|
||||
var points = this.points;
|
||||
var len = points.length;
|
||||
|
||||
this.edges = [];
|
||||
this.normals = [];
|
||||
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
var p1 = points[i];
|
||||
var p2 = i < len - 1 ? points[i + 1] : points[0];
|
||||
var e = new Vector2().copyFrom(p2).sub(p1);
|
||||
var n = new Vector2().copyFrom(e).perp().normalize();
|
||||
this.edges.push(e);
|
||||
this.normals.push(n);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="Polygon.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Quad
|
||||
@@ -90,6 +91,22 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the object specified intersects (overlaps) with the given values.
|
||||
* @method intersectsProps
|
||||
* @param {Number} left
|
||||
* @param {Number} right
|
||||
* @param {Number} top
|
||||
* @param {Number} bottomt
|
||||
* @param {Number} tolerance A tolerance value to allow for an intersection test with padding, default to 0
|
||||
* @return {Boolean} A value of true if the specified object intersects with this Quad; otherwise false.
|
||||
**/
|
||||
public intersectsRaw(left: number, right: number, top: number, bottom: number, tolerance?: number = 0): bool {
|
||||
|
||||
return !(left > this.right + tolerance || right < this.left - tolerance || top > this.bottom + tolerance || bottom < this.top - tolerance);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the specified coordinates are contained within the region defined by this Quad object.
|
||||
* @method contains
|
||||
@@ -133,6 +150,20 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a Polygon that is the same as this Quad.
|
||||
* @method toPolygon
|
||||
* @return {Polygon} A new Polygon that represents this quad.
|
||||
**/
|
||||
public toPolygon(): Polygon {
|
||||
|
||||
return new Polygon(new Vector2(this.x, this.y), [
|
||||
new Vector2(), new Vector2(this.width, 0),
|
||||
new Vector2(this.width, this.height), new Vector2(0, this.height)
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
* @method toString
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="Polygon.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Response
|
||||
*
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Response {
|
||||
|
||||
/**
|
||||
* An object representing the result of an intersection. Contain information about:
|
||||
* - The two objects participating in the intersection
|
||||
* - The vector representing the minimum change necessary to extract the first object
|
||||
* from the second one.
|
||||
* - Whether the first object is entirely inside the second, or vice versa.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
this.a = null;
|
||||
this.b = null;
|
||||
this.overlapN = new Vector2;
|
||||
this.overlapV = new Vector2;
|
||||
|
||||
this.clear();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The first object in the collision
|
||||
*/
|
||||
public a;
|
||||
|
||||
/**
|
||||
* The second object in the collision
|
||||
*/
|
||||
public b;
|
||||
|
||||
/**
|
||||
* The shortest colliding axis (unit-vector)
|
||||
*/
|
||||
public overlapN: Vector2;
|
||||
|
||||
/**
|
||||
* The overlap vector (i.e. overlapN.scale(overlap, overlap)).
|
||||
* If this vector is subtracted from the position of `a`, `a` and `b` will no longer be colliding.
|
||||
*/
|
||||
public overlapV: Vector2;
|
||||
|
||||
/**
|
||||
* Whether the first object is completely inside the second.
|
||||
*/
|
||||
public aInB: bool;
|
||||
|
||||
/**
|
||||
* Whether the second object is completely inside the first.
|
||||
*/
|
||||
public bInA: bool;
|
||||
|
||||
/**
|
||||
* Magnitude of the overlap on the shortest colliding axis
|
||||
*/
|
||||
public overlap: number;
|
||||
|
||||
/**
|
||||
* Set some values of the response back to their defaults. Call this between tests if
|
||||
* you are going to reuse a single Response object for multiple intersection tests (recommented)
|
||||
*
|
||||
* @return {Response} This for chaining
|
||||
*/
|
||||
public clear() {
|
||||
|
||||
this.aInB = true;
|
||||
this.bInA = true;
|
||||
this.overlap = Number.MAX_VALUE;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+297
-17
@@ -3,7 +3,8 @@
|
||||
/**
|
||||
* Phaser - Vector2
|
||||
*
|
||||
* A simple 2-dimensional vector class. Based on the one included with verlet-js by Sub Protocol released under MIT
|
||||
* A two dimensional vector.
|
||||
* Contains methods and ideas from verlet-js by Sub Protocol, SAT.js by Jim Riecken and N by Metanet Software.
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
@@ -14,8 +15,8 @@ module Phaser {
|
||||
* Creates a new Vector2 object.
|
||||
* @class Vector2
|
||||
* @constructor
|
||||
* @param {Number} x The x coordinate of vector2
|
||||
* @param {Number} y The y coordinate of vector2
|
||||
* @param {Number} x The x position of the vector
|
||||
* @param {Number} y The y position of the vector
|
||||
* @return {Vector2} This object
|
||||
**/
|
||||
constructor(x: number = 0, y: number = 0) {
|
||||
@@ -34,62 +35,163 @@ module Phaser {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add this vector to the given one and return the result.
|
||||
*
|
||||
* @param {Vector2} v The other Vector.
|
||||
* @param {Vector2} The output Vector.
|
||||
* @return {Vector2} The new Vector
|
||||
*/
|
||||
public add(v: Vector2, output?:Vector2 = new Vector2): Vector2 {
|
||||
return output.setTo(this.x + v.x, this.y + v.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract this vector to the given one and return the result.
|
||||
*
|
||||
* @param {Vector2} v The other Vector.
|
||||
* @param {Vector2} The output Vector.
|
||||
* @return {Vector2} The new Vector
|
||||
*/
|
||||
public sub(v: Vector2, output?:Vector2 = new Vector2): Vector2 {
|
||||
return output.setTo(this.x - v.x, this.y - v.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply this vector with the given one and return the result.
|
||||
*
|
||||
* @param {Vector2} v The other Vector.
|
||||
* @param {Vector2} The output Vector.
|
||||
* @return {Vector2} The new Vector
|
||||
*/
|
||||
public mul(v: Vector2, output?:Vector2 = new Vector2): Vector2 {
|
||||
return output.setTo(this.x * v.x, this.y * v.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide this vector by the given one and return the result.
|
||||
*
|
||||
* @param {Vector2} v The other Vector.
|
||||
* @param {Vector2} The output Vector.
|
||||
* @return {Vector2} The new Vector
|
||||
*/
|
||||
public div(v: Vector2, output?:Vector2 = new Vector2): Vector2 {
|
||||
return output.setTo(this.x / v.x, this.y / v.y);
|
||||
}
|
||||
|
||||
public scale(coef: number, output?:Vector2 = new Vector2): Vector2 {
|
||||
return output.setTo(this.x * coef, this.y * coef);
|
||||
/**
|
||||
* Scale this vector by the given values and return the result.
|
||||
*
|
||||
* @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 {Vector} The new Vector
|
||||
*/
|
||||
public scale(x: number, y?:number = null, output?:Vector2 = new Vector2): Vector2 {
|
||||
|
||||
if (y === null)
|
||||
{
|
||||
y = x;
|
||||
}
|
||||
|
||||
return output.setTo(this.x * x, this.y * y);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate this vector by 90 degrees
|
||||
*
|
||||
* @return {Vector} This for chaining.
|
||||
*/
|
||||
public perp(output?: Vector2 = this): Vector2 {
|
||||
var x = this.x;
|
||||
return output.setTo(this.y, -x);
|
||||
}
|
||||
|
||||
// Same as copyFrom, used by VerletManager
|
||||
public mutableSet(v: Vector2): Vector2 {
|
||||
this.x = v.x;
|
||||
this.y = v.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add another vector to this one.
|
||||
*
|
||||
* @param {Vector} other The other Vector.
|
||||
* @return {Vector} This for chaining.
|
||||
*/
|
||||
public mutableAdd(v: Vector2): Vector2 {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract another vector from this one.
|
||||
*
|
||||
* @param {Vector} other The other Vector.
|
||||
* @return {Vector} This for chaining.
|
||||
*/
|
||||
public mutableSub(v: Vector2): Vector2 {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply another vector with this one.
|
||||
*
|
||||
* @param {Vector} other The other Vector.
|
||||
* @return {Vector} This for chaining.
|
||||
*/
|
||||
public mutableMul(v: Vector2): Vector2 {
|
||||
this.x *= v.x;
|
||||
this.y *= v.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide this vector by another one.
|
||||
*
|
||||
* @param {Vector} other The other Vector.
|
||||
* @return {Vector} This for chaining.
|
||||
*/
|
||||
public mutableDiv(v: Vector2): Vector2 {
|
||||
this.x /= v.x;
|
||||
this.y /= v.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public mutableScale(coef: number): Vector2 {
|
||||
this.x *= coef;
|
||||
this.y *= coef;
|
||||
/**
|
||||
* 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 {Vector} This for chaining.
|
||||
*/
|
||||
public mutableScale(x: number, y?:number): Vector2 {
|
||||
this.x *= x;
|
||||
this.y *= y || x;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse this vector.
|
||||
*
|
||||
* @return {Vector} This for chaining.
|
||||
*/
|
||||
public reverse(): Vector2 {
|
||||
this.x = -this.x;
|
||||
this.y = -this.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public edge(v: Vector2, output?: Vector2 = new Vector2): Vector2 {
|
||||
return this.sub(v, output);
|
||||
}
|
||||
|
||||
public equals(v: Vector2): bool {
|
||||
return this.x == v.x && this.y == v.y;
|
||||
}
|
||||
@@ -98,31 +200,190 @@ module Phaser {
|
||||
return Math.abs(this.x - v.x) <= epsilon && Math.abs(this.y - v.y) <= epsilon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the length of this vector.
|
||||
*
|
||||
* @return {number} The length of this vector.
|
||||
*/
|
||||
public length(): number {
|
||||
return Math.sqrt(this.x * this.x + this.y * this.y);
|
||||
return Math.sqrt((this.x * this.x) + (this.y * this.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the length^2 of this vector.
|
||||
*
|
||||
* @return {number} The length^2 of this vector.
|
||||
*/
|
||||
public length2(): number {
|
||||
return this.x * this.x + this.y * this.y;
|
||||
return (this.x * this.x) + (this.y * this.y);
|
||||
}
|
||||
|
||||
public dist(v: Vector2): number {
|
||||
return Math.sqrt(this.dist2(v));
|
||||
/**
|
||||
* Get the distance between this vector and the given vector.
|
||||
*
|
||||
* @return {Vector2} v The vector to check
|
||||
*/
|
||||
public distance(v: Vector2): number {
|
||||
return Math.sqrt(this.distance2(v));
|
||||
}
|
||||
|
||||
public dist2(v: Vector2): number {
|
||||
/**
|
||||
* Get the distance^2 between this vector and the given vector.
|
||||
*
|
||||
* @return {Vector2} v The vector to check
|
||||
*/
|
||||
public distance2(v: Vector2): number {
|
||||
return ((v.x - this.x) * (v.x - this.x)) + ((v.y - this.y) * (v.y - this.y));
|
||||
}
|
||||
|
||||
public normal(output?: Vector2 = new Vector2) {
|
||||
var m = Math.sqrt(this.x * this.x + this.y * this.y);
|
||||
return output.setTo(this.x / m, this.y / m);
|
||||
/**
|
||||
* Project this vector on to another vector.
|
||||
*
|
||||
* @param {Vector} other The vector to project onto.
|
||||
* @return {Vector} This for chaining.
|
||||
*/
|
||||
public project(other: Vector2): Vector2 {
|
||||
|
||||
var amt = this.dot(other) / other.length2();
|
||||
|
||||
if (amt != 0)
|
||||
{
|
||||
this.x = amt * other.x;
|
||||
this.y = amt * other.y;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Project this vector onto a vector of unit length.
|
||||
*
|
||||
* @param {Vector} other The unit vector to project onto.
|
||||
* @return {Vector} This for chaining.
|
||||
*/
|
||||
public projectN(other: Vector2): Vector2 {
|
||||
|
||||
var amt = this.dot(other);
|
||||
|
||||
if (amt != 0)
|
||||
{
|
||||
this.x = amt * other.x;
|
||||
this.y = amt * other.y;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reflect this vector on an arbitrary axis.
|
||||
*
|
||||
* @param {Vector} axis The vector representing the axis.
|
||||
* @return {Vector} This for chaining.
|
||||
*/
|
||||
public reflect(axis): Vector2 {
|
||||
|
||||
var x = this.x;
|
||||
var y = this.y;
|
||||
this.project(axis).scale(2);
|
||||
this.x -= x;
|
||||
this.y -= y;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reflect this vector on an arbitrary axis (represented by a unit vector)
|
||||
*
|
||||
* @param {Vector} axis The unit vector representing the axis.
|
||||
* @return {Vector} This for chaining.
|
||||
*/
|
||||
public reflectN(axis): Vector2 {
|
||||
|
||||
var x = this.x;
|
||||
var y = this.y;
|
||||
this.projectN(axis).scale(2);
|
||||
this.x -= x;
|
||||
this.y -= y;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public getProjectionMagnitude(v: Vector2): number {
|
||||
|
||||
var den = v.dot(v);
|
||||
|
||||
if (den == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Math.abs(this.dot(v) / den);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public direction(output?: Vector2 = new Vector2): Vector2 {
|
||||
|
||||
output.copyFrom(this);
|
||||
return this.normalize(output);
|
||||
|
||||
}
|
||||
|
||||
public normalRightHand(output?: Vector2 = this): Vector2 {
|
||||
return output.setTo(this.y * -1, this.x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize (make unit length) this vector.
|
||||
*
|
||||
* @return {Vector} This for chaining.
|
||||
*/
|
||||
public normalize(output?: Vector2 = this): Vector2 {
|
||||
|
||||
var m = this.length();
|
||||
|
||||
if (m != 0)
|
||||
{
|
||||
output.setTo(this.x / m, this.y / m);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
public getMagnitude(): number {
|
||||
return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dot product of this vector against another.
|
||||
*
|
||||
* @param {Vector} other The vector to dot this one against.
|
||||
* @return {number} The dot product.
|
||||
*/
|
||||
public dot(v: Vector2): number {
|
||||
return this.x * v.x + this.y * v.y;
|
||||
return ((this.x * v.x) + (this.y * v.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cross product of this vector against another.
|
||||
*
|
||||
* @param {Vector} other The vector to cross this one against.
|
||||
* @return {number} The cross product.
|
||||
*/
|
||||
public cross(v: Vector2): number {
|
||||
return ((this.x * v.y) - (this.y * v.x));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the angle between this vector and the given vector.
|
||||
*
|
||||
* @return {Vector2} v The vector to check
|
||||
*/
|
||||
public angle(v: Vector2): number {
|
||||
return Math.atan2(this.x * v.y - this.y * v.x, this.x * v.x + this.y * v.y);
|
||||
}
|
||||
@@ -131,12 +392,31 @@ module Phaser {
|
||||
return vLeft.sub(this).angle(vRight.sub(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate this vector around the origin to the given angle (theta) and return the result in a new Vector
|
||||
*
|
||||
* @return {Vector2} v The vector to check
|
||||
*/
|
||||
public rotate(origin, theta, output?: Vector2 = new Vector2): Vector2 {
|
||||
var x = this.x - origin.x;
|
||||
var y = this.y - origin.y;
|
||||
return output.setTo(x * Math.cos(theta) - y * Math.sin(theta) + origin.x, x * Math.sin(theta) + y * Math.cos(theta) + origin.y);
|
||||
}
|
||||
|
||||
public clone(output?: Vector2 = new Vector2): Vector2 {
|
||||
return output.setTo(this.x, this.y);
|
||||
}
|
||||
|
||||
public copyFrom(v: Vector2): Vector2 {
|
||||
this.x = v.x;
|
||||
this.y = v.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public copyTo(v: Vector2): Vector2 {
|
||||
return v.setTo(this.x, this.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
* @method toString
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Phaser
|
||||
*
|
||||
* v0.9.5 - April 28th 2013
|
||||
* v0.9.6 - May 21st 2013
|
||||
*
|
||||
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
||||
*
|
||||
@@ -15,5 +15,5 @@
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
Phaser.VERSION = 'Phaser version 0.9.5';
|
||||
Phaser.VERSION = 'Phaser version 0.9.6';
|
||||
})(Phaser || (Phaser = {}));
|
||||
|
||||
@@ -318,7 +318,7 @@ module Phaser {
|
||||
{
|
||||
if (this.deadzone == null)
|
||||
{
|
||||
this.focusOnXY(this._target.x + this._target.origin.x, this._target.y + this._target.origin.y);
|
||||
this.focusOnXY(this._target.x, this._target.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -155,8 +155,6 @@ module Phaser {
|
||||
|
||||
public update() {
|
||||
|
||||
//this.quad.x = this._parent.x + this.offset.x;
|
||||
//this.quad.y = this._parent.y + this.offset.y;
|
||||
this._ref.x = this._parent.x + this.offset.x;
|
||||
this._ref.y = this._parent.y + this.offset.y;
|
||||
|
||||
@@ -173,8 +171,7 @@ module Phaser {
|
||||
var _dx = cameraOffsetX + (this.x - camera.worldView.x);
|
||||
var _dy = cameraOffsetY + (this.y - camera.worldView.y);
|
||||
|
||||
//this._parent.context.fillStyle = this._parent.renderDebugColor;
|
||||
this._parent.context.fillStyle = 'rgba(255,0,0,0.4)';
|
||||
this._parent.context.fillStyle = this._parent.renderDebugColor;
|
||||
|
||||
if (this.type == CollisionMask.QUAD)
|
||||
{
|
||||
@@ -207,6 +204,23 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
public intersectsRaw(left: number, right: number, top: number, bottom: number): bool {
|
||||
|
||||
//if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height))
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public intersectsVector(vector: Phaser.Vector2): bool {
|
||||
|
||||
if (this.type == CollisionMask.QUAD)
|
||||
{
|
||||
return this.quad.contains(vector.x, vector.y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives a basic boolean response to a geometric collision.
|
||||
* If you need the details of the collision use the Collision functions instead and inspect the IntersectResult object.
|
||||
@@ -224,7 +238,6 @@ module Phaser {
|
||||
// Circle vs. Circle
|
||||
if (this.type == CollisionMask.CIRCLE && source.type == CollisionMask.CIRCLE)
|
||||
{
|
||||
console.log('c vs c');
|
||||
return Collision.circleToCircle(this.circle, source.circle).result;
|
||||
}
|
||||
|
||||
|
||||
+122
-78
@@ -25,11 +25,6 @@ module Phaser {
|
||||
this.pointer3 = new Pointer(this._game, 3);
|
||||
this.pointer4 = new Pointer(this._game, 4);
|
||||
this.pointer5 = new Pointer(this._game, 5);
|
||||
this.pointer6 = new Pointer(this._game, 6);
|
||||
this.pointer7 = new Pointer(this._game, 7);
|
||||
this.pointer8 = new Pointer(this._game, 8);
|
||||
this.pointer9 = new Pointer(this._game, 9);
|
||||
this.pointer10 = new Pointer(this._game, 10);
|
||||
|
||||
this.mouse = new Mouse(this._game);
|
||||
this.keyboard = new Keyboard(this._game);
|
||||
@@ -42,7 +37,7 @@ module Phaser {
|
||||
this.onTap = new Phaser.Signal();
|
||||
this.onHold = new Phaser.Signal();
|
||||
|
||||
this.point = new Point();
|
||||
this.position = new Vector2;
|
||||
this.circle = new Circle(0, 0, 44);
|
||||
|
||||
this.currentPointers = 0;
|
||||
@@ -115,11 +110,11 @@ module Phaser {
|
||||
public gestures: Gestures;
|
||||
|
||||
/**
|
||||
* A Point object representing the x/y screen coordinates of the Pointer.
|
||||
* @property point
|
||||
* @type {Point}
|
||||
* A vector object representing the current position of the Pointer.
|
||||
* @property vector
|
||||
* @type {Vector2}
|
||||
**/
|
||||
public point: Point = null;
|
||||
public position: Vector2 = null;
|
||||
|
||||
/**
|
||||
* A Circle object centered on the x/y screen coordinates of the Input.
|
||||
@@ -299,35 +294,35 @@ module Phaser {
|
||||
* @property pointer6
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer6: Pointer;
|
||||
public pointer6: Pointer = null;
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer7
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer7: Pointer;
|
||||
public pointer7: Pointer = null;
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer8
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer8: Pointer;
|
||||
public pointer8: Pointer = null;
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer9
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer9: Pointer;
|
||||
public pointer9: Pointer = null;
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer10
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer10: Pointer;
|
||||
public pointer10: Pointer = null;
|
||||
|
||||
/**
|
||||
* The screen X coordinate
|
||||
@@ -363,6 +358,58 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new Pointer object to the Input Manager. By default Input creates 5 pointer objects for you. If you need more
|
||||
* use this to create a new one, up to a maximum of 10.
|
||||
* @method addPointer
|
||||
* @return {Pointer} A reference to the new Pointer object
|
||||
**/
|
||||
public addPointer(): Pointer {
|
||||
|
||||
var next: number = 0;
|
||||
|
||||
if (this.pointer10 === null)
|
||||
{
|
||||
next = 10;
|
||||
}
|
||||
|
||||
if (this.pointer9 === null)
|
||||
{
|
||||
next = 9;
|
||||
}
|
||||
|
||||
if (this.pointer8 === null)
|
||||
{
|
||||
next = 8;
|
||||
}
|
||||
|
||||
if (this.pointer7 === null)
|
||||
{
|
||||
next = 7;
|
||||
}
|
||||
|
||||
if (this.pointer6 === null)
|
||||
{
|
||||
next = 6;
|
||||
}
|
||||
|
||||
if (next == 0)
|
||||
{
|
||||
throw new Error("You can only have 10 Pointer objects");
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this['pointer' + next] = new Pointer(this._game, next);
|
||||
return this['pointer' + next];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Input Manager running
|
||||
* @method start
|
||||
**/
|
||||
public start() {
|
||||
|
||||
this.mouse.start();
|
||||
@@ -373,6 +420,10 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the Input Manager. Called by the core Game loop.
|
||||
* @method update
|
||||
**/
|
||||
public update() {
|
||||
|
||||
this.mousePointer.update();
|
||||
@@ -381,11 +432,12 @@ module Phaser {
|
||||
this.pointer3.update();
|
||||
this.pointer4.update();
|
||||
this.pointer5.update();
|
||||
this.pointer6.update();
|
||||
this.pointer7.update();
|
||||
this.pointer8.update();
|
||||
this.pointer9.update();
|
||||
this.pointer10.update();
|
||||
|
||||
if (this.pointer6) { this.pointer6.update(); }
|
||||
if (this.pointer7) { this.pointer7.update(); }
|
||||
if (this.pointer8) { this.pointer8.update(); }
|
||||
if (this.pointer9) { this.pointer9.update(); }
|
||||
if (this.pointer10) { this.pointer10.update(); }
|
||||
|
||||
}
|
||||
|
||||
@@ -403,11 +455,12 @@ module Phaser {
|
||||
this.pointer3.reset();
|
||||
this.pointer4.reset();
|
||||
this.pointer5.reset();
|
||||
this.pointer6.reset();
|
||||
this.pointer7.reset();
|
||||
this.pointer8.reset();
|
||||
this.pointer9.reset();
|
||||
this.pointer10.reset();
|
||||
|
||||
if (this.pointer6) { this.pointer6.reset(); }
|
||||
if (this.pointer7) { this.pointer7.reset(); }
|
||||
if (this.pointer8) { this.pointer8.reset(); }
|
||||
if (this.pointer9) { this.pointer9.reset(); }
|
||||
if (this.pointer10) { this.pointer10.reset(); }
|
||||
|
||||
this.currentPointers = 0;
|
||||
|
||||
@@ -417,7 +470,6 @@ module Phaser {
|
||||
this.onUp = new Phaser.Signal();
|
||||
this.onTap = new Phaser.Signal();
|
||||
this.onHold = new Phaser.Signal();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -462,23 +514,23 @@ module Phaser {
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
else if (this.pointer6.active == true)
|
||||
else if (this.pointer6 && this.pointer6.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
else if (this.pointer7.active == true)
|
||||
else if (this.pointer7 && this.pointer7.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
else if (this.pointer8.active == true)
|
||||
else if (this.pointer8 && this.pointer8.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
else if (this.pointer9.active == true)
|
||||
else if (this.pointer9 && this.pointer9.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
else if (this.pointer10.active == true)
|
||||
else if (this.pointer10 && this.pointer10.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
@@ -521,23 +573,23 @@ module Phaser {
|
||||
{
|
||||
return this.pointer5.start(event);
|
||||
}
|
||||
else if (this.pointer6.active == false)
|
||||
else if (this.pointer6 && this.pointer6.active == false)
|
||||
{
|
||||
return this.pointer6.start(event);
|
||||
}
|
||||
else if (this.pointer7.active == false)
|
||||
else if (this.pointer7 && this.pointer7.active == false)
|
||||
{
|
||||
return this.pointer7.start(event);
|
||||
}
|
||||
else if (this.pointer8.active == false)
|
||||
else if (this.pointer8 && this.pointer8.active == false)
|
||||
{
|
||||
return this.pointer8.start(event);
|
||||
}
|
||||
else if (this.pointer9.active == false)
|
||||
else if (this.pointer9 && this.pointer9.active == false)
|
||||
{
|
||||
return this.pointer9.start(event);
|
||||
}
|
||||
else if (this.pointer10.active == false)
|
||||
else if (this.pointer10 && this.pointer10.active == false)
|
||||
{
|
||||
return this.pointer10.start(event);
|
||||
}
|
||||
@@ -575,23 +627,23 @@ module Phaser {
|
||||
{
|
||||
return this.pointer5.move(event);
|
||||
}
|
||||
else if (this.pointer6.active == true && this.pointer6.identifier == event.identifier)
|
||||
else if (this.pointer6 && this.pointer6.active == true && this.pointer6.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer6.move(event);
|
||||
}
|
||||
else if (this.pointer7.active == true && this.pointer7.identifier == event.identifier)
|
||||
else if (this.pointer7 && this.pointer7.active == true && this.pointer7.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer7.move(event);
|
||||
}
|
||||
else if (this.pointer8.active == true && this.pointer8.identifier == event.identifier)
|
||||
else if (this.pointer8 && this.pointer8.active == true && this.pointer8.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer8.move(event);
|
||||
}
|
||||
else if (this.pointer9.active == true && this.pointer9.identifier == event.identifier)
|
||||
else if (this.pointer9 && this.pointer9.active == true && this.pointer9.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer9.move(event);
|
||||
}
|
||||
else if (this.pointer10.active == true && this.pointer10.identifier == event.identifier)
|
||||
else if (this.pointer10 && this.pointer10.active == true && this.pointer10.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer10.move(event);
|
||||
}
|
||||
@@ -629,23 +681,23 @@ module Phaser {
|
||||
{
|
||||
return this.pointer5.stop(event);
|
||||
}
|
||||
else if (this.pointer6.active == true && this.pointer6.identifier == event.identifier)
|
||||
else if (this.pointer6 && this.pointer6.active == true && this.pointer6.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer6.stop(event);
|
||||
}
|
||||
else if (this.pointer7.active == true && this.pointer7.identifier == event.identifier)
|
||||
else if (this.pointer7 && this.pointer7.active == true && this.pointer7.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer7.stop(event);
|
||||
}
|
||||
else if (this.pointer8.active == true && this.pointer8.identifier == event.identifier)
|
||||
else if (this.pointer8 && this.pointer8.active == true && this.pointer8.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer8.stop(event);
|
||||
}
|
||||
else if (this.pointer9.active == true && this.pointer9.identifier == event.identifier)
|
||||
else if (this.pointer9 && this.pointer9.active == true && this.pointer9.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer9.stop(event);
|
||||
}
|
||||
else if (this.pointer10.active == true && this.pointer10.identifier == event.identifier)
|
||||
else if (this.pointer10 && this.pointer10.active == true && this.pointer10.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer10.stop(event);
|
||||
}
|
||||
@@ -683,23 +735,23 @@ module Phaser {
|
||||
{
|
||||
return this.pointer5;
|
||||
}
|
||||
else if (this.pointer6.active == state)
|
||||
else if (this.pointer6 && this.pointer6.active == state)
|
||||
{
|
||||
return this.pointer6;
|
||||
}
|
||||
else if (this.pointer7.active == state)
|
||||
else if (this.pointer7 && this.pointer7.active == state)
|
||||
{
|
||||
return this.pointer7;
|
||||
}
|
||||
else if (this.pointer8.active == state)
|
||||
else if (this.pointer8 && this.pointer8.active == state)
|
||||
{
|
||||
return this.pointer8;
|
||||
}
|
||||
else if (this.pointer9.active == state)
|
||||
else if (this.pointer9 && this.pointer9.active == state)
|
||||
{
|
||||
return this.pointer9;
|
||||
}
|
||||
else if (this.pointer10.active == state)
|
||||
else if (this.pointer10 && this.pointer10.active == state)
|
||||
{
|
||||
return this.pointer10;
|
||||
}
|
||||
@@ -737,23 +789,23 @@ module Phaser {
|
||||
{
|
||||
return this.pointer5;
|
||||
}
|
||||
else if (this.pointer6.identifier == identifier)
|
||||
else if (this.pointer6 && this.pointer6.identifier == identifier)
|
||||
{
|
||||
return this.pointer6;
|
||||
}
|
||||
else if (this.pointer7.identifier == identifier)
|
||||
else if (this.pointer7 && this.pointer7.identifier == identifier)
|
||||
{
|
||||
return this.pointer7;
|
||||
}
|
||||
else if (this.pointer8.identifier == identifier)
|
||||
else if (this.pointer8 && this.pointer8.identifier == identifier)
|
||||
{
|
||||
return this.pointer8;
|
||||
}
|
||||
else if (this.pointer9.identifier == identifier)
|
||||
else if (this.pointer9 && this.pointer9.identifier == identifier)
|
||||
{
|
||||
return this.pointer9;
|
||||
}
|
||||
else if (this.pointer10.identifier == identifier)
|
||||
else if (this.pointer10 && this.pointer10.identifier == identifier)
|
||||
{
|
||||
return this.pointer10;
|
||||
}
|
||||
@@ -797,32 +849,24 @@ module Phaser {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method calculateDistance
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
* Get the distance between two Pointer objects
|
||||
* @method getDistance
|
||||
* @param {Pointer} pointer1
|
||||
* @param {Pointer} pointer2
|
||||
**/
|
||||
//public calculateDistance(finger1: Finger, finger2: Finger) {
|
||||
//}
|
||||
public getDistance(pointer1: Pointer, pointer2: Pointer): number {
|
||||
return pointer1.position.distance(pointer2.position);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method calculateAngle
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
* Get the angle between two Pointer objects
|
||||
* @method getAngle
|
||||
* @param {Pointer} pointer1
|
||||
* @param {Pointer} pointer2
|
||||
**/
|
||||
//public calculateAngle(finger1: Finger, finger2: Finger) {
|
||||
//}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method checkOverlap
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
**/
|
||||
//public checkOverlap(finger1: Finger, finger2: Finger) {
|
||||
//}
|
||||
|
||||
public getAngle(pointer1: Pointer, pointer2: Pointer): number {
|
||||
return pointer1.position.angle(pointer2.position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../geom/Vector2.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Pointer
|
||||
@@ -21,8 +22,8 @@ module Phaser {
|
||||
|
||||
this.id = id;
|
||||
this.active = false;
|
||||
this.pointA = new Point();
|
||||
this.pointB = new Point();
|
||||
this.position = new Vector2;
|
||||
this.positionDown = new Vector2;
|
||||
this.circle = new Circle(0, 0, 44);
|
||||
|
||||
if (id == 0)
|
||||
@@ -88,18 +89,18 @@ module Phaser {
|
||||
public active: bool;
|
||||
|
||||
/**
|
||||
* A Point object representing the x/y screen coordinates of the Pointer.
|
||||
* @property pointA
|
||||
* @type {Point}
|
||||
* A Vector object containing the initial position when the Pointer was engaged with the screen.
|
||||
* @property positionDown
|
||||
* @type {Vector2}
|
||||
**/
|
||||
public pointA: Point = null;
|
||||
public positionDown: Vector2 = null;
|
||||
|
||||
/**
|
||||
* A Point object representing the x/y screen coordinates of the Pointer.
|
||||
* @property pointB
|
||||
* @type {Point}
|
||||
* A Vector object containing the current position of the Pointer on the screen.
|
||||
* @property position
|
||||
* @type {Vector2}
|
||||
**/
|
||||
public pointB: Point = null;
|
||||
public position: Vector2 = null;
|
||||
|
||||
/**
|
||||
* A Circle object centered on the x/y screen coordinates of the Pointer.
|
||||
@@ -286,11 +287,18 @@ module Phaser {
|
||||
this.button = event.button;
|
||||
}
|
||||
|
||||
// Fix to stop rogue browser plugins from blocking the visibility state event
|
||||
if (this._game.paused == true)
|
||||
{
|
||||
this._game.stage.resumeGame();
|
||||
return this;
|
||||
}
|
||||
|
||||
this._history.length = 0;
|
||||
|
||||
this.move(event);
|
||||
|
||||
this.pointA.setTo(this.x, this.y);
|
||||
this.positionDown.setTo(this.x, this.y);
|
||||
|
||||
this.active = true;
|
||||
this.withinGame = true;
|
||||
@@ -335,7 +343,7 @@ module Phaser {
|
||||
if (this._game.input.recordPointerHistory && this._game.time.now >= this._nextDrop)
|
||||
{
|
||||
this._nextDrop = this._game.time.now + this._game.input.recordRate;
|
||||
this._history.push({ x: this.pointB.x, y: this.pointB.y });
|
||||
this._history.push({ x: this.position.x, y: this.position.y });
|
||||
|
||||
if (this._history.length > this._game.input.recordLimit)
|
||||
{
|
||||
@@ -369,7 +377,7 @@ module Phaser {
|
||||
this.x = this.pageX - this._game.stage.offset.x;
|
||||
this.y = this.pageY - this._game.stage.offset.y;
|
||||
|
||||
this.pointB.setTo(this.x, this.y);
|
||||
this.position.setTo(this.x, this.y);
|
||||
this.circle.x = this.x;
|
||||
this.circle.y = this.y;
|
||||
|
||||
@@ -377,7 +385,7 @@ module Phaser {
|
||||
{
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
this._game.input.point.setTo(this._game.input.x, this._game.input.y);
|
||||
this._game.input.position.setTo(this._game.input.x, this._game.input.y);
|
||||
this._game.input.circle.x = this._game.input.x;
|
||||
this._game.input.circle.y = this._game.input.y;
|
||||
}
|
||||
@@ -529,8 +537,8 @@ module Phaser {
|
||||
|
||||
// Render the points
|
||||
this._game.stage.context.beginPath();
|
||||
this._game.stage.context.moveTo(this.pointA.x, this.pointA.y);
|
||||
this._game.stage.context.lineTo(this.pointB.x, this.pointB.y);
|
||||
this._game.stage.context.moveTo(this.positionDown.x, this.positionDown.y);
|
||||
this._game.stage.context.lineTo(this.position.x, this.position.y);
|
||||
this._game.stage.context.lineWidth = 2;
|
||||
this._game.stage.context.stroke();
|
||||
this._game.stage.context.closePath();
|
||||
|
||||
@@ -112,7 +112,7 @@ module Phaser {
|
||||
*/
|
||||
private colorCycle() {
|
||||
|
||||
this._fade = this._game.createTween(this._color2);
|
||||
this._fade = this._game.add.tween(this._color2);
|
||||
|
||||
this._fade.to({ r: Math.random() * 250, g: Math.random() * 250, b: Math.random() * 250 }, 3000, Phaser.Easing.Linear.None);
|
||||
this._fade.onComplete.add(this.colorCycle, this);
|
||||
|
||||
@@ -31,11 +31,13 @@ module Phaser {
|
||||
* Local private reference to game.
|
||||
*/
|
||||
private _game: Game;
|
||||
|
||||
/**
|
||||
* Canvas element used by engine.
|
||||
* @type {HTMLCanvasElement}
|
||||
*/
|
||||
private _canvas: HTMLCanvasElement;
|
||||
|
||||
/**
|
||||
* Render context of stage's canvas.
|
||||
* @type {CanvasRenderingContext2D}
|
||||
@@ -46,6 +48,7 @@ module Phaser {
|
||||
* Background color.
|
||||
*/
|
||||
private _color;
|
||||
|
||||
/**
|
||||
* Fade effect tween.
|
||||
* @type {Phaser.Tween}
|
||||
@@ -114,7 +117,7 @@ module Phaser {
|
||||
*/
|
||||
private fadeOut() {
|
||||
|
||||
this._fade = this._game.createTween(this._color);
|
||||
this._fade = this._game.add.tween(this._color);
|
||||
|
||||
this._fade.to({ r: 50, g: 50, b: 50 }, 1000, Phaser.Easing.Linear.None);
|
||||
this._fade.onComplete.add(this.fadeIn, this);
|
||||
@@ -127,7 +130,7 @@ module Phaser {
|
||||
*/
|
||||
private fadeIn() {
|
||||
|
||||
this._fade = this._game.createTween(this._color);
|
||||
this._fade = this._game.add.tween(this._color);
|
||||
|
||||
this._fade.to({ r: 255, g: 255, b: 255 }, 1000, Phaser.Easing.Linear.None);
|
||||
this._fade.onComplete.add(this.fadeOut, this);
|
||||
|
||||
+126
-1
@@ -25,19 +25,47 @@ module Phaser.Verlet {
|
||||
|
||||
this._game = game;
|
||||
|
||||
this.sprites = [];
|
||||
this.particles = [];
|
||||
this.constraints = [];
|
||||
|
||||
this.frameBounds = new Phaser.Quad();
|
||||
|
||||
}
|
||||
|
||||
private _game: Game;
|
||||
|
||||
/**
|
||||
* Texture of the particles to be rendered.
|
||||
*/
|
||||
private _texture = null;
|
||||
|
||||
/**
|
||||
* Rendering bounds for the texture
|
||||
* @type {Quad}
|
||||
*/
|
||||
private frameBounds: Quad;
|
||||
|
||||
// local rendering related temp vars to help avoid gc spikes
|
||||
private _sx: number = 0;
|
||||
private _sy: number = 0;
|
||||
private _sw: number = 0;
|
||||
private _sh: number = 0;
|
||||
private _dx: number = 0;
|
||||
private _dy: number = 0;
|
||||
private _dw: number = 0;
|
||||
private _dh: number = 0;
|
||||
private _hw: number = 0;
|
||||
private _hh: number = 0;
|
||||
|
||||
public sprites: Phaser.Sprite[];
|
||||
public particles: Phaser.Verlet.Particle[];
|
||||
public constraints;
|
||||
|
||||
public drawParticles = null;
|
||||
public drawConstraints = null;
|
||||
|
||||
// Map sprites to particles
|
||||
// Create Constraints
|
||||
|
||||
public createDistanceConstraint(a: Phaser.Verlet.Particle, b: Phaser.Verlet.Particle, stiffness: number, distance?: number = null): Phaser.Verlet.DistanceConstraint {
|
||||
|
||||
@@ -60,6 +88,103 @@ module Phaser.Verlet {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a graphic for this Composite. The graphic cannot be a SpriteSheet yet.
|
||||
* @param key {string} Key of the graphic you want to load for this sprite.
|
||||
* @return {Composite} This object
|
||||
*/
|
||||
public loadGraphic(key: string): Composite {
|
||||
|
||||
if (this._game.cache.getImage(key) !== null)
|
||||
{
|
||||
if (this._game.cache.isSpriteSheet(key) == false)
|
||||
{
|
||||
this._texture = this._game.cache.getImage(key);
|
||||
this.frameBounds.width = this._texture.width;
|
||||
this.frameBounds.height = this._texture.height;
|
||||
this._hw = Math.floor(this.frameBounds.width / 2);
|
||||
this._hh = Math.floor(this.frameBounds.width / 2);
|
||||
this.drawParticles = this.render;
|
||||
this.drawConstraints = this.renderConstraints;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public hideConstraints: bool = true;
|
||||
public constraintLineColor: string = 'rgba(200,200,200,1)';
|
||||
|
||||
private renderConstraints(context) {
|
||||
|
||||
if (this.hideConstraints == true || this.constraints.length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var i;
|
||||
|
||||
context.beginPath();
|
||||
|
||||
for (i in this.constraints)
|
||||
{
|
||||
if (this.constraints[i].b)
|
||||
{
|
||||
context.moveTo(this.constraints[i].a.pos.x, this.constraints[i].a.pos.y);
|
||||
context.lineTo(this.constraints[i].b.pos.x, this.constraints[i].b.pos.y);
|
||||
}
|
||||
}
|
||||
|
||||
context.strokeStyle = this.constraintLineColor;
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
|
||||
}
|
||||
|
||||
private render(context) {
|
||||
|
||||
this._sx = 0;
|
||||
this._sy = 0;
|
||||
this._sw = this.frameBounds.width;
|
||||
this._sh = this.frameBounds.height;
|
||||
this._dw = this.frameBounds.width;
|
||||
this._dh = this.frameBounds.height;
|
||||
|
||||
this._sx = Math.round(this._sx);
|
||||
this._sy = Math.round(this._sy);
|
||||
this._sw = Math.round(this._sw);
|
||||
this._sh = Math.round(this._sh);
|
||||
this._dw = Math.round(this._dw);
|
||||
this._dh = Math.round(this._dh);
|
||||
|
||||
var i;
|
||||
|
||||
for (i in this.particles)
|
||||
{
|
||||
//this._dx = cameraOffsetX + (this.frameBounds.topLeft.x - camera.worldView.x);
|
||||
//this._dy = cameraOffsetY + (this.frameBounds.topLeft.y - camera.worldView.y);
|
||||
this._dx = this.particles[i].pos.x - this._hw;
|
||||
this._dy = this.particles[i].pos.y - this._hh;
|
||||
this._dx = Math.round(this._dx);
|
||||
this._dy = Math.round(this._dy);
|
||||
|
||||
context.drawImage(
|
||||
this._texture, // Source Image
|
||||
this._sx, // Source X (location within the source image)
|
||||
this._sy, // Source Y
|
||||
this._sw, // Source Width
|
||||
this._sh, // Source Height
|
||||
this._dx, // Destination X (where on the canvas it'll be drawn)
|
||||
this._dy, // Destination Y
|
||||
this._dw, // Destination Width (always same as Source Width unless scaled)
|
||||
this._dh // Destination Height (always same as Source Height unless scaled)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public pin(index, pos?=null) {
|
||||
|
||||
if (pos == null)
|
||||
|
||||
@@ -62,6 +62,7 @@ module Phaser.Verlet {
|
||||
ctx.lineTo(this.b.pos.x, this.b.pos.y);
|
||||
ctx.strokeStyle = "#d8dde2";
|
||||
ctx.stroke();
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,8 +53,12 @@ V0.9.6
|
||||
* Added Input.startPointer, Input.updatePointer and Input.stopPointer.
|
||||
* Phaser Input now confirmed working on Windows Phone 8 (Nokia Lumia 920).
|
||||
* Added Input.maxPointers to allow you to limit the number of fingers your game will listen for on multi-touch systems.
|
||||
* Added Input.addPointer. By default Input will create 5 pointers (+1 for the mouse). Use addPointer() to add up to a maximum of 10.
|
||||
* Added Input.position - a Vector2 object containing the most recent position of the most recently active Pointer.
|
||||
* Added Input.getDistance. Find the distance between the two given Pointer objects.
|
||||
* Added Input.getAngle. Find the angle between the two given Pointer objects.
|
||||
* Pointer.totalTouches value keeps a running total of the number of times the Pointer has been pressed.
|
||||
* Added Pointer.pointA and pointB - pointA is placed on touch, pointB is moved on update, useful for tracking distance/direction/gestures.
|
||||
* Added Pointer.position and positionDown. positionDown is placed on touch and position is update on move, useful for tracking distance/direction/gestures.
|
||||
* Added Game.state - now contains a reference to the current state object (if any was given).
|
||||
* Moved the Input start events from the constructors to a single Input.start method.
|
||||
* Added Input.disabled boolean to globally turn off all input event processing.
|
||||
@@ -71,7 +75,7 @@ V0.9.6
|
||||
* Added Basic.ignoreGlobalUpdate - stops the object being updated as part of the main game loop, you'll need to call update on it yourself
|
||||
* Added Basic.ignoreGlobalRender - stops the object being rendered as part of the main game loop, you'll need to call render on it yourself
|
||||
* Added forceUpdate and forceRender parameters to Group.update and Group.render respectively. Combined with ignoreGlobal you can create custom rendering set-ups
|
||||
* Fixed Loader.progress calculation so it now accurate passes a value between 0 and 100% to your loader callback
|
||||
* Fixed Loader.progress calculation so it now accurately passes a value between 0 and 100 to your loader callback
|
||||
* Added a 'hard reset' parameter to Input.reset. A hard reset clears Input signals (such as on a state swap), a soft (such as on game pause) doesn't
|
||||
* Added Device.isConsoleOpen() to check if the browser console is open. Tested on Firefox with Firebug and Chrome with DevTools
|
||||
* Added delay parameter to Tween.to()
|
||||
@@ -91,19 +95,29 @@ V0.9.6
|
||||
* Added Group.alpha to apply a globalAlpha before the groups children are rendered. Useful to save on alpha calls.
|
||||
* Added Group.globalCompositeOperation to apply a composite operation before all of the groups children are rendered.
|
||||
* Added Camera black list support to Group along with Group.showToCamera, Group.hideFromCamera and Group.clearCameraList
|
||||
|
||||
|
||||
* Added GameMath.rotatePoint to allow for point rotation at any angle around a given anchor and distance
|
||||
* Updated World.setSize() to optionally update the VerletManager dimensions as well
|
||||
* Added GameObject.setPosition(x, y)
|
||||
* Added Quad.intersectsRaw(left, right, top, bottom, tolerance)
|
||||
* Updated Sprite.inCamera to correctly apply the scrollFactor to the camera bounds check
|
||||
* Added Loader.crossOrigin property which is applied to loaded Images
|
||||
* Added AnimationManager.destroy() to clear out all local references and objects
|
||||
* Added the clearAnimations parameter to Sprite.loadGraphic(). Allows you to change animation textures but retain the frame data.
|
||||
* Added the GameObjectFactory to Game. You now make Sprites like this: game.add.sprite(). Much better separation of game object creation methods now. But you'll have to update ALL code, sorry!
|
||||
* Added GameObjectFactory methods to add existing objects to the game world, such as existingSprite(), existingTween(), etc.
|
||||
* Added the GameObjectFactory to Phaser.State
|
||||
|
||||
* TODO: Check that tween pausing works with the new performance.now
|
||||
* TODO: Game.Time should monitor pause duration
|
||||
* TODO: Investigate bug re: tilemap collision and animation frames
|
||||
* TODO: Update tests that use arrow keys and include touch/mouse support
|
||||
* TODO: GameObject.clipRect
|
||||
* TODO: Use CollisionMask in Input instead of Circle?
|
||||
* TODO: Polygon geom primitive
|
||||
* TODO: Move GameObject transforms to a single matrix
|
||||
|
||||
|
||||
* TODO: this.target.view.style.cursor = "pointer"; ("default")
|
||||
* TODO: Fix bug in scrollFactor inCamera check where the scrollFactor > 0 and < 1
|
||||
* TODO: If the Camera is larger than the Stage size then the rotation offset isn't correct
|
||||
* TODO: Texture Repeat doesn't scroll, because it's part of the camera not the world, need to think about this more
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
@@ -118,6 +118,10 @@
|
||||
<TypeScriptCompile Include="input\multitouch.ts" />
|
||||
<TypeScriptCompile Include="groups\display order.ts" />
|
||||
<TypeScriptCompile Include="collision\mask test 1.ts" />
|
||||
<TypeScriptCompile Include="collision\mask animation 1.ts" />
|
||||
<Content Include="collision\mask animation 1.js">
|
||||
<DependentUpon>mask animation 1.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="collision\mask test 1.js">
|
||||
<DependentUpon>mask test 1.ts</DependentUpon>
|
||||
</Content>
|
||||
@@ -131,6 +135,10 @@
|
||||
</Content>
|
||||
<TypeScriptCompile Include="geometry\rotate point 2.ts" />
|
||||
<TypeScriptCompile Include="geometry\rotate point 1.ts" />
|
||||
<TypeScriptCompile Include="geometry\rope bridge.ts" />
|
||||
<Content Include="geometry\rope bridge.js">
|
||||
<DependentUpon>rope bridge.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="geometry\rotate point 1.js">
|
||||
<DependentUpon>rotate point 1.ts</DependentUpon>
|
||||
</Content>
|
||||
@@ -190,6 +198,14 @@
|
||||
<Content Include="particles\mousetrail.js">
|
||||
<DependentUpon>mousetrail.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\temp1.ts" />
|
||||
<Content Include="physics\temp1.js">
|
||||
<DependentUpon>temp1.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\temp2.ts" />
|
||||
<Content Include="physics\temp2.js">
|
||||
<DependentUpon>temp2.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="scrollzones\ballscroller.js">
|
||||
<DependentUpon>ballscroller.ts</DependentUpon>
|
||||
</Content>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('card', 'assets/sprites/mana_card.png');
|
||||
myGame.loader.addTextureAtlas('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var card;
|
||||
var bot;
|
||||
function create() {
|
||||
card = myGame.createSprite(200, 220, 'card');
|
||||
bot = myGame.createSprite(myGame.stage.width - 100, 300, 'bot');
|
||||
// The collision mask is much thinner than the animated sprite
|
||||
bot.collisionMask.offset.x = 16;
|
||||
bot.collisionMask.width = 32;
|
||||
bot.renderDebug = true;
|
||||
bot.animations.add('run');
|
||||
bot.animations.play('run', 10, true);
|
||||
bot.velocity.x = -150;
|
||||
}
|
||||
function update() {
|
||||
if(bot.x < -bot.width) {
|
||||
bot.x = myGame.stage.width;
|
||||
bot.velocity.x = -150;
|
||||
card.x = 200;
|
||||
card.velocity.x = 0;
|
||||
}
|
||||
myGame.collide(card, bot);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,50 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('card', 'assets/sprites/mana_card.png');
|
||||
myGame.loader.addTextureAtlas('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var card: Phaser.Sprite;
|
||||
var bot: Phaser.Sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
card = myGame.createSprite(200, 220, 'card');
|
||||
|
||||
bot = myGame.createSprite(myGame.stage.width - 100, 300, 'bot');
|
||||
|
||||
// The collision mask is much thinner than the animated sprite
|
||||
bot.collisionMask.offset.x = 16;
|
||||
bot.collisionMask.width = 32;
|
||||
bot.renderDebug = true;
|
||||
|
||||
bot.animations.add('run');
|
||||
bot.animations.play('run', 10, true);
|
||||
|
||||
bot.velocity.x = -150;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (bot.x < -bot.width)
|
||||
{
|
||||
bot.x = myGame.stage.width;
|
||||
bot.velocity.x = -150;
|
||||
card.x = 200;
|
||||
card.velocity.x = 0;
|
||||
}
|
||||
|
||||
myGame.collide(card, bot);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -34,6 +34,5 @@
|
||||
console.log('Collision!!!!!');
|
||||
}
|
||||
function render() {
|
||||
//atari1.ren
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -59,9 +59,6 @@
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
//atari1.ren
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('ball5', 'assets/sprites/purple_ball.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var segment;
|
||||
function create() {
|
||||
myGame.verlet.friction = 1;
|
||||
myGame.verlet.hideNearestEntityCircle = true;
|
||||
var points = [];
|
||||
var startX = 100;
|
||||
var startY = 200;
|
||||
var spacing = 20;
|
||||
for(var i = 0; i < 30; i++) {
|
||||
points.push(new Phaser.Vector2(startX + (i * spacing), startY));
|
||||
}
|
||||
segment = myGame.verlet.createLineSegments(points, 0.5);
|
||||
segment.loadGraphic('ball5');
|
||||
segment.hideConstraints = false;
|
||||
segment.pin(0);
|
||||
segment.pin(points.length - 1);
|
||||
}
|
||||
function update() {
|
||||
}
|
||||
function render() {
|
||||
myGame.verlet.render();
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,255,0)';
|
||||
//myGame.stage.context.fillRect(p1.x, p1.y, 4, 4);
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,0,0)';
|
||||
//myGame.stage.context.fillRect(p2.x, p2.y, 4, 4);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,55 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('ball5', 'assets/sprites/purple_ball.png');
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var segment: Phaser.Verlet.Composite;
|
||||
|
||||
function create() {
|
||||
|
||||
myGame.verlet.friction = 1;
|
||||
myGame.verlet.hideNearestEntityCircle = true;
|
||||
|
||||
var points: Phaser.Vector2[] = [];
|
||||
var startX: number = 100;
|
||||
var startY: number = 200;
|
||||
var spacing: number = 20;
|
||||
|
||||
for (var i = 0; i < 30; i++)
|
||||
{
|
||||
points.push(new Phaser.Vector2(startX + (i * spacing), startY));
|
||||
}
|
||||
|
||||
segment = myGame.verlet.createLineSegments(points, 0.5);
|
||||
segment.loadGraphic('ball5');
|
||||
segment.hideConstraints = false;
|
||||
|
||||
segment.pin(0);
|
||||
segment.pin(points.length - 1);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
myGame.verlet.render();
|
||||
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,255,0)';
|
||||
//myGame.stage.context.fillRect(p1.x, p1.y, 4, 4);
|
||||
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,0,0)';
|
||||
//myGame.stage.context.fillRect(p2.x, p2.y, 4, 4);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -22,9 +22,5 @@
|
||||
}
|
||||
function render() {
|
||||
myGame.verlet.render();
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,255,0)';
|
||||
//myGame.stage.context.fillRect(p1.x, p1.y, 4, 4);
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,0,0)';
|
||||
//myGame.stage.context.fillRect(p2.x, p2.y, 4, 4);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -28,12 +28,6 @@
|
||||
|
||||
myGame.verlet.render();
|
||||
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,255,0)';
|
||||
//myGame.stage.context.fillRect(p1.x, p1.y, 4, 4);
|
||||
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,0,0)';
|
||||
//myGame.stage.context.fillRect(p2.x, p2.y, 4, 4);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
var cube;
|
||||
var b1;
|
||||
var b2;
|
||||
var b3;
|
||||
var b4;
|
||||
function init() {
|
||||
myGame.loader.addImageFile('ball0', 'assets/sprites/yellow_ball.png');
|
||||
myGame.loader.addImageFile('ball1', 'assets/sprites/aqua_ball.png');
|
||||
@@ -15,33 +10,23 @@
|
||||
myGame.loader.addImageFile('ball5', 'assets/sprites/purple_ball.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var wheel;
|
||||
var diamond;
|
||||
var triangle;
|
||||
var cube;
|
||||
function create() {
|
||||
myGame.verlet.friction = 1;
|
||||
myGame.verlet.step = 32;
|
||||
//var wheel = myGame.verlet.createTire(new Phaser.Vector2(200,50), 100, 30, 0.3, 0.9);
|
||||
//var tire2 = myGame.verlet.createTire(new Phaser.Vector2(400,50), 70, 7, 0.1, 0.2);
|
||||
cube = myGame.verlet.createTire(new Phaser.Vector2(300, 50), 100, 4, 1, 1);
|
||||
//var tri = myGame.verlet.createTire(new Phaser.Vector2(700,50), 100, 3, 1, 1);
|
||||
var dc = new Phaser.Verlet.DistanceConstraint(cube.particles[0], cube.particles[1], 1);
|
||||
cube.constraints.push(dc);
|
||||
var dc2 = new Phaser.Verlet.DistanceConstraint(cube.particles[1], cube.particles[2], 1);
|
||||
cube.constraints.push(dc2);
|
||||
var dc3 = new Phaser.Verlet.DistanceConstraint(cube.particles[2], cube.particles[3], 1);
|
||||
cube.constraints.push(dc3);
|
||||
b1 = myGame.createSprite(cube.particles[0].pos.x, cube.particles[0].pos.y, 'ball0');
|
||||
b2 = myGame.createSprite(cube.particles[1].pos.x, cube.particles[1].pos.y, 'ball1');
|
||||
b3 = myGame.createSprite(cube.particles[2].pos.x, cube.particles[2].pos.y, 'ball2');
|
||||
b4 = myGame.createSprite(cube.particles[3].pos.x, cube.particles[3].pos.y, 'ball3');
|
||||
wheel = myGame.verlet.createTire(new Phaser.Vector2(200, 50), 100, 30, 0.3, 0.9);
|
||||
wheel.loadGraphic('ball0');
|
||||
diamond = myGame.verlet.createTire(new Phaser.Vector2(400, 50), 70, 7, 0.1, 0.2);
|
||||
diamond.loadGraphic('ball1');
|
||||
triangle = myGame.verlet.createTire(new Phaser.Vector2(600, 50), 100, 3, 1, 1);
|
||||
triangle.loadGraphic('ball2');
|
||||
cube = myGame.verlet.createTire(new Phaser.Vector2(300, 50), 100, 4, 0.3, 0.9);
|
||||
cube.loadGraphic('ball3');
|
||||
}
|
||||
function update() {
|
||||
b1.x = cube.particles[0].pos.x - 8;
|
||||
b1.y = cube.particles[0].pos.y - 8;
|
||||
b2.x = cube.particles[1].pos.x - 8;
|
||||
b2.y = cube.particles[1].pos.y - 8;
|
||||
b3.x = cube.particles[2].pos.x - 8;
|
||||
b3.y = cube.particles[2].pos.y - 8;
|
||||
b4.x = cube.particles[3].pos.x - 8;
|
||||
b4.y = cube.particles[3].pos.y - 8;
|
||||
}
|
||||
function render() {
|
||||
myGame.verlet.render();
|
||||
|
||||
@@ -4,13 +4,6 @@
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
|
||||
var cube: Phaser.Verlet.Composite;
|
||||
|
||||
var b1: Phaser.Sprite;
|
||||
var b2: Phaser.Sprite;
|
||||
var b3: Phaser.Sprite;
|
||||
var b4: Phaser.Sprite;
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('ball0', 'assets/sprites/yellow_ball.png');
|
||||
@@ -24,46 +17,31 @@
|
||||
|
||||
}
|
||||
|
||||
var wheel: Phaser.Verlet.Composite;
|
||||
var diamond: Phaser.Verlet.Composite;
|
||||
var triangle: Phaser.Verlet.Composite;
|
||||
var cube: Phaser.Verlet.Composite;
|
||||
|
||||
function create() {
|
||||
|
||||
myGame.verlet.friction = 1;
|
||||
myGame.verlet.step = 32;
|
||||
|
||||
//var wheel = myGame.verlet.createTire(new Phaser.Vector2(200,50), 100, 30, 0.3, 0.9);
|
||||
//var tire2 = myGame.verlet.createTire(new Phaser.Vector2(400,50), 70, 7, 0.1, 0.2);
|
||||
cube = myGame.verlet.createTire(new Phaser.Vector2(300, 50), 100, 4, 1, 1);
|
||||
//var tri = myGame.verlet.createTire(new Phaser.Vector2(700,50), 100, 3, 1, 1);
|
||||
|
||||
var dc: Phaser.Verlet.DistanceConstraint = new Phaser.Verlet.DistanceConstraint(cube.particles[0], cube.particles[1], 1);
|
||||
cube.constraints.push(dc);
|
||||
|
||||
var dc2: Phaser.Verlet.DistanceConstraint = new Phaser.Verlet.DistanceConstraint(cube.particles[1], cube.particles[2], 1);
|
||||
cube.constraints.push(dc2);
|
||||
|
||||
var dc3: Phaser.Verlet.DistanceConstraint = new Phaser.Verlet.DistanceConstraint(cube.particles[2], cube.particles[3], 1);
|
||||
cube.constraints.push(dc3);
|
||||
|
||||
b1 = myGame.createSprite(cube.particles[0].pos.x, cube.particles[0].pos.y, 'ball0');
|
||||
b2 = myGame.createSprite(cube.particles[1].pos.x, cube.particles[1].pos.y, 'ball1');
|
||||
b3 = myGame.createSprite(cube.particles[2].pos.x, cube.particles[2].pos.y, 'ball2');
|
||||
b4 = myGame.createSprite(cube.particles[3].pos.x, cube.particles[3].pos.y, 'ball3');
|
||||
wheel = myGame.verlet.createTire(new Phaser.Vector2(200,50), 100, 30, 0.3, 0.9);
|
||||
wheel.loadGraphic('ball0');
|
||||
|
||||
diamond = myGame.verlet.createTire(new Phaser.Vector2(400,50), 70, 7, 0.1, 0.2);
|
||||
diamond.loadGraphic('ball1');
|
||||
|
||||
triangle = myGame.verlet.createTire(new Phaser.Vector2(600,50), 100, 3, 1, 1);
|
||||
triangle.loadGraphic('ball2');
|
||||
|
||||
cube = myGame.verlet.createTire(new Phaser.Vector2(300, 50), 100, 4, 0.3, 0.9);
|
||||
cube.loadGraphic('ball3');
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
b1.x = cube.particles[0].pos.x - 8;
|
||||
b1.y = cube.particles[0].pos.y - 8;
|
||||
|
||||
b2.x = cube.particles[1].pos.x - 8;
|
||||
b2.y = cube.particles[1].pos.y - 8;
|
||||
|
||||
b3.x = cube.particles[2].pos.x - 8;
|
||||
b3.y = cube.particles[2].pos.y - 8;
|
||||
|
||||
b4.x = cube.particles[3].pos.x - 8;
|
||||
b4.y = cube.particles[3].pos.y - 8;
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
+1622
-716
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,113 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
var Physics = (function () {
|
||||
function Physics() {
|
||||
this.max_bodies = 512;
|
||||
this.max_vertices = 1024;
|
||||
this.max_edges = 1024;
|
||||
this.max_body_vertices = 64;
|
||||
this.max_body_edges = 64;
|
||||
this.vertices = [];
|
||||
this.edges = [];
|
||||
this.bodies = [];
|
||||
}
|
||||
Physics.prototype.updateForces = // Sets the force on each vertex to the gravity force. You could of course apply other forces like magnetism etc.
|
||||
function () {
|
||||
for(var i = 0; i < this.vertexCount; i++) {
|
||||
this.vertices[i].acceleration = this.gravity;
|
||||
}
|
||||
};
|
||||
Physics.prototype.updateVerlet = // Updates the vertex position
|
||||
function () {
|
||||
for(var i = 0; i < this.vertexCount; i++) {
|
||||
var v = this.vertices[i];
|
||||
var temp = v.position;
|
||||
//v.position.mutableAdd(
|
||||
//v.position += v.position - v.oldPosition + v.acceleration * this.timestep * this.timestep;
|
||||
}
|
||||
};
|
||||
Physics.prototype.updateEdges = function () {
|
||||
};
|
||||
Physics.prototype.iterateCollisions = function () {
|
||||
};
|
||||
Physics.prototype.detectCollision = function (body1, body2) {
|
||||
};
|
||||
Physics.prototype.processCollision = function () {
|
||||
};
|
||||
Physics.prototype.intervalDistance = function (minA, maxA, minB, maxB) {
|
||||
};
|
||||
Physics.prototype.bodiesOverlap = function (body1, body2) {
|
||||
};
|
||||
Physics.prototype.update = // CollisionInfo
|
||||
// depth, normal, edge, vertex
|
||||
function () {
|
||||
};
|
||||
Physics.prototype.render = function () {
|
||||
};
|
||||
Physics.prototype.addBody = function (body) {
|
||||
this.bodies.push(body);
|
||||
this.bodyCount = this.bodies.length;
|
||||
};
|
||||
Physics.prototype.addEdge = function (edge) {
|
||||
this.edges.push(edge);
|
||||
this.edgeCount = this.edges.length;
|
||||
};
|
||||
Physics.prototype.addVertex = function (vertex) {
|
||||
this.vertices.push(vertex);
|
||||
this.vertexCount = this.vertices.length;
|
||||
};
|
||||
Physics.prototype.findVertex = function (x, y) {
|
||||
};
|
||||
return Physics;
|
||||
})();
|
||||
var PhysicsBody = (function () {
|
||||
function PhysicsBody() {
|
||||
this.vertices = [];
|
||||
this.edges = [];
|
||||
}
|
||||
PhysicsBody.prototype.addEdge = function (edge) {
|
||||
};
|
||||
PhysicsBody.prototype.addVertex = function (vertex) {
|
||||
};
|
||||
PhysicsBody.prototype.projectToAxis = function (axis, min, max) {
|
||||
};
|
||||
PhysicsBody.prototype.calculateCenter = function () {
|
||||
};
|
||||
PhysicsBody.prototype.createBox = function (x, y, width, height) {
|
||||
};
|
||||
return PhysicsBody;
|
||||
})();
|
||||
var Vertex = (function () {
|
||||
function Vertex(body, posX, posY) {
|
||||
}
|
||||
return Vertex;
|
||||
})();
|
||||
var Edge = (function () {
|
||||
function Edge(body, pV1, pV2, pBoundary) {
|
||||
}
|
||||
return Edge;
|
||||
})();
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('atari1', 'assets/sprites/atari130xe.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
function create() {
|
||||
var p = new Physics();
|
||||
//p.max_bodies
|
||||
}
|
||||
function update() {
|
||||
}
|
||||
function render() {
|
||||
//myGame.stage.context.strokeStyle = 'rgb(0,255,0)';
|
||||
//myGame.stage.context.beginPath();
|
||||
//myGame.stage.context.moveTo(poly1.points[0].x + poly1.pos.x, poly1.points[0].y + poly1.pos.y);
|
||||
//for (var i = 1; i < poly1.points.length; i++)
|
||||
//{
|
||||
// myGame.stage.context.lineTo(poly1.points[i].x + poly1.pos.x, poly1.points[i].y + poly1.pos.y);
|
||||
//}
|
||||
//myGame.stage.context.lineTo(poly1.points[0].x + poly1.pos.x, poly1.points[0].y + poly1.pos.y);
|
||||
//myGame.stage.context.stroke();
|
||||
//myGame.stage.context.closePath();
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,200 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
class Physics {
|
||||
|
||||
constructor() {
|
||||
|
||||
this.vertices = [];
|
||||
this.edges = [];
|
||||
this.bodies = [];
|
||||
|
||||
}
|
||||
|
||||
public gravity: Phaser.Vector2;
|
||||
|
||||
public max_bodies: number = 512;
|
||||
public max_vertices: number = 1024;
|
||||
public max_edges: number = 1024;
|
||||
public max_body_vertices: number = 64;
|
||||
public max_body_edges: number = 64;
|
||||
|
||||
public bodyCount: number;
|
||||
public vertexCount: number;
|
||||
public edgeCount: number;
|
||||
public timestep: number;
|
||||
public iterations;
|
||||
|
||||
public vertices: Vertex[];
|
||||
public edges: Edge[];
|
||||
public bodies: PhysicsBody[];
|
||||
|
||||
// Sets the force on each vertex to the gravity force. You could of course apply other forces like magnetism etc.
|
||||
public updateForces() {
|
||||
|
||||
for (var i:number = 0; i < this.vertexCount; i++)
|
||||
{
|
||||
this.vertices[i].acceleration = this.gravity;
|
||||
}
|
||||
}
|
||||
|
||||
// Updates the vertex position
|
||||
public updateVerlet() {
|
||||
|
||||
for (var i:number = 0; i < this.vertexCount; i++)
|
||||
{
|
||||
var v:Vertex = this.vertices[i];
|
||||
var temp: Phaser.Vector2 = v.position;
|
||||
//v.position.mutableAdd(
|
||||
//v.position += v.position - v.oldPosition + v.acceleration * this.timestep * this.timestep;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public updateEdges() {
|
||||
}
|
||||
|
||||
public iterateCollisions() {
|
||||
}
|
||||
|
||||
public detectCollision(body1, body2) {
|
||||
}
|
||||
|
||||
public processCollision() {
|
||||
}
|
||||
|
||||
public intervalDistance(minA, maxA, minB, maxB) {
|
||||
}
|
||||
|
||||
public bodiesOverlap(body1, body2) {
|
||||
}
|
||||
|
||||
// CollisionInfo
|
||||
// depth, normal, edge, vertex
|
||||
|
||||
public update() {
|
||||
}
|
||||
|
||||
public render() {
|
||||
}
|
||||
|
||||
public addBody(body:PhysicsBody) {
|
||||
this.bodies.push(body);
|
||||
this.bodyCount = this.bodies.length;
|
||||
}
|
||||
|
||||
public addEdge(edge:Edge) {
|
||||
this.edges.push(edge);
|
||||
this.edgeCount = this.edges.length;
|
||||
}
|
||||
|
||||
public addVertex(vertex:Vertex) {
|
||||
this.vertices.push(vertex);
|
||||
this.vertexCount = this.vertices.length;
|
||||
}
|
||||
|
||||
public findVertex(x, y) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class PhysicsBody {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
center: Phaser.Vector2;
|
||||
minX;
|
||||
minY;
|
||||
maxX;
|
||||
maxY;
|
||||
vertextCount;
|
||||
edgeCount;
|
||||
|
||||
vertices = [];
|
||||
edges = [];
|
||||
|
||||
public addEdge(edge) {
|
||||
}
|
||||
|
||||
public addVertex(vertex) {
|
||||
|
||||
}
|
||||
|
||||
public projectToAxis(axis, min, max) {
|
||||
}
|
||||
|
||||
public calculateCenter() {
|
||||
}
|
||||
|
||||
public createBox(x, y, width, height) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Vertex {
|
||||
|
||||
constructor(body, posX, posY) {
|
||||
}
|
||||
|
||||
position: Phaser.Vector2;
|
||||
oldPosition: Phaser.Vector2;
|
||||
acceleration: Phaser.Vector2;
|
||||
parent: PhysicsBody;
|
||||
}
|
||||
|
||||
class Edge {
|
||||
|
||||
constructor(body, pV1, pV2, pBoundary) {
|
||||
}
|
||||
|
||||
v1: Vertex;
|
||||
v2: Vertex;
|
||||
length;
|
||||
boundary;
|
||||
parent: PhysicsBody;
|
||||
|
||||
}
|
||||
|
||||
(function () {
|
||||
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('atari1', 'assets/sprites/atari130xe.png');
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
var p = new Physics();
|
||||
//p.max_bodies
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
//myGame.stage.context.strokeStyle = 'rgb(0,255,0)';
|
||||
//myGame.stage.context.beginPath();
|
||||
//myGame.stage.context.moveTo(poly1.points[0].x + poly1.pos.x, poly1.points[0].y + poly1.pos.y);
|
||||
|
||||
//for (var i = 1; i < poly1.points.length; i++)
|
||||
//{
|
||||
// myGame.stage.context.lineTo(poly1.points[i].x + poly1.pos.x, poly1.points[i].y + poly1.pos.y);
|
||||
//}
|
||||
|
||||
//myGame.stage.context.lineTo(poly1.points[0].x + poly1.pos.x, poly1.points[0].y + poly1.pos.y);
|
||||
|
||||
//myGame.stage.context.stroke();
|
||||
//myGame.stage.context.closePath();
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -23,6 +23,7 @@
|
||||
emitter.setRotation(0, 0);
|
||||
// Looks like a smoke trail!
|
||||
//emitter.globalCompositeOperation = 'xor';
|
||||
// Looks way cool :)
|
||||
emitter.globalCompositeOperation = 'lighter';
|
||||
bullets = myGame.createGroup(50);
|
||||
// Create our bullet pool
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var CACTUS = 31;
|
||||
var SIGN_POST = 46;
|
||||
var map: Phaser.Tilemap;
|
||||
var car: Phaser.Sprite;
|
||||
var tile: Phaser.Tile;
|
||||
@@ -28,10 +29,10 @@
|
||||
|
||||
// When the car collides with the cactus tile we'll flash the screen red briefly,
|
||||
// but it won't stop the car (the separateX/Y values are set to false)
|
||||
map.setCollisionByIndex([31], Phaser.Collision.ANY, true, false, false);
|
||||
map.setCollisionByIndex([CACTUS], Phaser.Collision.ANY, true, false, false);
|
||||
|
||||
// When the car collides with the sign post tile we'll stop the car moving (separation is set to true)
|
||||
map.setCollisionByIndex([46], Phaser.Collision.ANY, true, true, true);
|
||||
map.setCollisionByIndex([SIGN_POST], Phaser.Collision.ANY, true, true, true);
|
||||
|
||||
// This is the callback that will be called every time map.collide() returns true
|
||||
map.collisionCallback = collide;
|
||||
@@ -79,12 +80,12 @@
|
||||
// collisionData is an array containing all of the tiles the object overlapped with (can be more than 1)
|
||||
for (var i = 0; i < collisionData.length; i++)
|
||||
{
|
||||
if (collisionData[i].tile.index == 31)
|
||||
if (collisionData[i].tile.index == CACTUS)
|
||||
{
|
||||
console.log('you hit a cactus!');
|
||||
flash.start(0xff0000, 1);
|
||||
}
|
||||
else if (collisionData[i].tile.index == 31)
|
||||
else if (collisionData[i].tile.index == SIGN_POST)
|
||||
{
|
||||
console.log('you hit a sign post!');
|
||||
}
|
||||
|
||||
+18
-16
@@ -11,7 +11,7 @@
|
||||
myGame.loader.load();
|
||||
}
|
||||
var map;
|
||||
var car;
|
||||
var ufo;
|
||||
var tile;
|
||||
var emitter;
|
||||
var test;
|
||||
@@ -19,6 +19,7 @@
|
||||
map = myGame.createTilemap('tiles', 'platform', Phaser.Tilemap.FORMAT_TILED_JSON);
|
||||
map.setCollisionRange(21, 53);
|
||||
map.setCollisionRange(105, 109);
|
||||
myGame.camera.opaque = true;
|
||||
myGame.camera.backgroundColor = 'rgb(47,154,204)';
|
||||
myGame.input.keyboard.addKeyCapture([
|
||||
Phaser.Keyboard.LEFT,
|
||||
@@ -26,36 +27,37 @@
|
||||
Phaser.Keyboard.UP,
|
||||
Phaser.Keyboard.DOWN
|
||||
]);
|
||||
emitter = myGame.createEmitter(32, 80);
|
||||
emitter.width = 700;
|
||||
emitter.makeParticles('chunk', 100, false, 1);
|
||||
emitter.gravity = 200;
|
||||
emitter.bounce = 0.8;
|
||||
emitter.start(false, 10, 0.05);
|
||||
car = myGame.createSprite(250, 64, 'ufo');
|
||||
car.renderRotation = false;
|
||||
//emitter = myGame.createEmitter(32, 80);
|
||||
//emitter.width = 700;
|
||||
//emitter.makeParticles('chunk', 100, false, 1);
|
||||
//emitter.gravity = 200;
|
||||
//emitter.bounce = 0.8;
|
||||
//emitter.start(false, 10, 0.05);
|
||||
ufo = myGame.createSprite(250, 64, 'ufo');
|
||||
ufo.renderDebug = true;
|
||||
ufo.renderRotation = false;
|
||||
test = myGame.createSprite(200, 64, 'ufo');
|
||||
test.elasticity = 1;
|
||||
test.velocity.x = 50;
|
||||
test.velocity.y = 100;
|
||||
car.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
||||
ufo.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
||||
}
|
||||
function update() {
|
||||
// Collide everything with the map
|
||||
map.collide();
|
||||
// And collide everything in the game :)
|
||||
myGame.collide();
|
||||
car.velocity.x = 0;
|
||||
car.velocity.y = 0;
|
||||
ufo.velocity.x = 0;
|
||||
ufo.velocity.y = 0;
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
car.velocity.x = -200;
|
||||
ufo.velocity.x = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
car.velocity.x = 200;
|
||||
ufo.velocity.x = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
car.velocity.y = -200;
|
||||
ufo.velocity.y = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
car.velocity.y = 200;
|
||||
ufo.velocity.y = 200;
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
+18
-16
@@ -18,7 +18,7 @@
|
||||
}
|
||||
|
||||
var map: Phaser.Tilemap;
|
||||
var car: Phaser.Sprite;
|
||||
var ufo: Phaser.Sprite;
|
||||
var tile: Phaser.Tile;
|
||||
var emitter: Phaser.Emitter;
|
||||
var test: Phaser.Sprite;
|
||||
@@ -29,26 +29,28 @@
|
||||
map.setCollisionRange(21,53);
|
||||
map.setCollisionRange(105,109);
|
||||
|
||||
myGame.camera.opaque = true;
|
||||
myGame.camera.backgroundColor = 'rgb(47,154,204)';
|
||||
|
||||
myGame.input.keyboard.addKeyCapture([Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.UP, Phaser.Keyboard.DOWN]);
|
||||
|
||||
emitter = myGame.createEmitter(32, 80);
|
||||
emitter.width = 700;
|
||||
emitter.makeParticles('chunk', 100, false, 1);
|
||||
emitter.gravity = 200;
|
||||
emitter.bounce = 0.8;
|
||||
emitter.start(false, 10, 0.05);
|
||||
//emitter = myGame.createEmitter(32, 80);
|
||||
//emitter.width = 700;
|
||||
//emitter.makeParticles('chunk', 100, false, 1);
|
||||
//emitter.gravity = 200;
|
||||
//emitter.bounce = 0.8;
|
||||
//emitter.start(false, 10, 0.05);
|
||||
|
||||
car = myGame.createSprite(250, 64, 'ufo');
|
||||
car.renderRotation = false;
|
||||
ufo = myGame.createSprite(250, 64, 'ufo');
|
||||
ufo.renderDebug = true;
|
||||
ufo.renderRotation = false;
|
||||
|
||||
test = myGame.createSprite(200, 64, 'ufo');
|
||||
test.elasticity = 1;
|
||||
test.velocity.x = 50;
|
||||
test.velocity.y = 100;
|
||||
|
||||
car.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
||||
ufo.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
||||
|
||||
}
|
||||
|
||||
@@ -60,25 +62,25 @@
|
||||
// And collide everything in the game :)
|
||||
myGame.collide();
|
||||
|
||||
car.velocity.x = 0;
|
||||
car.velocity.y = 0;
|
||||
ufo.velocity.x = 0;
|
||||
ufo.velocity.y = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
car.velocity.x = -200;
|
||||
ufo.velocity.x = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
car.velocity.x = 200;
|
||||
ufo.velocity.x = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
car.velocity.y = -200;
|
||||
ufo.velocity.y = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
car.velocity.y = 200;
|
||||
ufo.velocity.y = 200;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Vendored
+746
-269
File diff suppressed because it is too large
Load Diff
+1622
-716
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user