Putting everything back together again :)

This commit is contained in:
Richard Davey
2013-05-31 18:21:32 +01:00
parent fe372af453
commit d510b785b1
46 changed files with 15176 additions and 15082 deletions
-1702
View File
File diff suppressed because it is too large Load Diff
+12 -12
View File
@@ -1,17 +1,24 @@
/// <reference path="core/Rectangle.ts" />
/// <reference path="math/LinkedList.ts" />
/// <reference path="math/QuadTree.ts" />
/// <reference path="core/Point.ts" />
/// <reference path="core/Vec2.ts" />
/// <reference path="core/Circle.ts" />
/// <reference path="core/Group.ts" />
/// <reference path="core/Signal.ts" />
/// <reference path="core/SignalBinding.ts" />
/// <reference path="loader/Loader.ts" />
/// <reference path="loader/Cache.ts" />
/// <reference path="math/GameMath.ts" />
/// <reference path="math/RandomDataGenerator.ts" />
/// <reference path="cameras/CameraManager.ts" />
/// <reference path="gameobjects/GameObjectFactory.ts" />
/// <reference path="core/Group.ts" />
/// <reference path="core/Signal.ts" />
/// <reference path="core/SignalBinding.ts" />
/// <reference path="sound/SoundManager.ts" />
/// <reference path="Stage.ts" />
/// <reference path="Time.ts" />
/// <reference path="tweens/TweenManager.ts" />
/// <reference path="World.ts" />
/// <reference path="Motion.ts" />
/// <reference path="system/Device.ts" />
/// <reference path="system/RequestAnimationFrame.ts" />
/// <reference path="input/Input.ts" />
@@ -169,12 +176,6 @@ module Phaser {
*/
public cache: Cache;
/**
* Reference to the collision helper.
* @type {Collision}
*/
//public collision: Collision;
/**
* Reference to the input manager
* @type {Input}
@@ -197,7 +198,7 @@ module Phaser {
* Reference to the motion helper.
* @type {Motion}
*/
//public motion: Motion;
public motion: Motion;
/**
* Reference to the sound manager.
@@ -279,14 +280,13 @@ module Phaser {
else
{
this.device = new Device();
//this.motion = new Motion(this);
this.motion = new Motion(this);
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);
this.loader = new Loader(this, this.loadComplete);
this.time = new Time(this);
this.tweens = new TweenManager(this);
+168 -235
View File
@@ -1,5 +1,5 @@
/// <reference path="Game.ts" />
/// <reference path="gameobjects/GameObject.ts" />
/// <reference path="gameobjects/Sprite.ts" />
/**
* Phaser - Motion
@@ -12,62 +12,10 @@ module Phaser {
export class Motion {
constructor(game: Game) {
this._game = game;
this.game = game;
}
private _game: Game;
/**
* A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
*
* @param {number} Velocity Any component of velocity (e.g. 20).
* @param {number} Acceleration Rate at which the velocity is changing.
* @param {number} Drag Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
* @param {number} Max An absolute value cap for the velocity.
*
* @return {number} The altered Velocity value.
*/
public computeVelocity(Velocity: number, Acceleration: number = 0, Drag: number = 0, Max: number = 10000): number {
if (Acceleration !== 0)
{
Velocity += Acceleration * this._game.time.elapsed;
}
else if (Drag !== 0)
{
var drag: number = Drag * this._game.time.elapsed;
if (Velocity - drag > 0)
{
Velocity = Velocity - drag;
}
else if (Velocity + drag < 0)
{
Velocity += drag;
}
else
{
Velocity = 0;
}
}
if ((Velocity != 0) && (Max != 10000))
{
if (Velocity > Max)
{
Velocity = Max;
}
else if (Velocity < -Max)
{
Velocity = -Max;
}
}
return Velocity;
}
public game: Game;
/**
* Given the angle and speed calculate the velocity and return it as a Point
@@ -84,13 +32,13 @@ module Phaser {
speed = 0;
}
var a: number = this._game.math.degreesToRadians(angle);
var a: number = this.game.math.degreesToRadians(angle);
return new Point((Math.cos(a) * speed), (Math.sin(a) * speed));
}
/**
/**
* Sets the source Sprite x/y velocity so it will move directly towards the destination Sprite at the speed given (in pixels per second)<br>
* If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.<br>
* Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms.<br>
@@ -98,311 +46,296 @@ module Phaser {
* If you need the object to accelerate, see accelerateTowardsObject() instead
* Note: Doesn't take into account acceleration, maxVelocity or drag (if you set drag or acceleration too high this object may not move at all)
*
* @param {GameObject} source The Sprite on which the velocity will be set
* @param {GameObject} dest The Sprite where the source object will move to
* @param {Sprite} source The Sprite on which the velocity will be set
* @param {Sprite} dest The Sprite where the source object will move to
* @param {number} speed The speed it will move, in pixels per second (default is 60 pixels/sec)
* @param {number} maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms
*/
public moveTowardsObject(source:GameObject, dest:GameObject, speed:number= 60, maxTime:number = 0)
{
var a:number = this.angleBetween(source, dest);
public moveTowardsObject(source: Sprite, dest: Sprite, speed: number = 60, maxTime: number = 0) {
var a: number = this.angleBetween(source, dest);
if (maxTime > 0)
{
var d:number = this.distanceBetween(source, dest);
if (maxTime > 0)
{
var d: number = this.distanceBetween(source, dest);
// We know how many pixels we need to move, but how fast?
speed = d / (maxTime / 1000);
}
// We know how many pixels we need to move, but how fast?
speed = d / (maxTime / 1000);
}
source.velocity.x = Math.cos(a) * speed;
source.velocity.y = Math.sin(a) * speed;
source.body.velocity.x = Math.cos(a) * speed;
source.body.velocity.y = Math.sin(a) * speed;
}
}
/**
/**
* Sets the x/y acceleration on the source Sprite so it will move towards the destination Sprite at the speed given (in pixels per second)<br>
* You must give a maximum speed value, beyond which the Sprite won't go any faster.<br>
* If you don't need acceleration look at moveTowardsObject() instead.
*
* @param {GameObject} source The Sprite on which the acceleration will be set
* @param {GameObject} dest The Sprite where the source object will move towards
* @param {Sprite} source The Sprite on which the acceleration will be set
* @param {Sprite} dest The Sprite where the source object will move towards
* @param {number} speed The speed it will accelerate in pixels per second
* @param {number} xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally
* @param {number} ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically
*/
public accelerateTowardsObject(source:GameObject, dest:GameObject, speed:number, xSpeedMax:number, ySpeedMax:number)
{
var a:number = this.angleBetween(source, dest);
public accelerateTowardsObject(source: Sprite, dest: Sprite, speed: number, xSpeedMax: number, ySpeedMax: number) {
var a: number = this.angleBetween(source, dest);
source.velocity.x = 0;
source.velocity.y = 0;
source.body.velocity.x = 0;
source.body.velocity.y = 0;
source.acceleration.x = Math.cos(a) * speed;
source.acceleration.y = Math.sin(a) * speed;
source.body.acceleration.x = Math.cos(a) * speed;
source.body.acceleration.y = Math.sin(a) * speed;
source.maxVelocity.x = xSpeedMax;
source.maxVelocity.y = ySpeedMax;
source.body.maxVelocity.x = xSpeedMax;
source.body.maxVelocity.y = ySpeedMax;
}
}
/**
/**
* Move the given Sprite towards the mouse pointer coordinates at a steady velocity
* If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.<br>
* Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms.<br>
* The source object doesn't stop moving automatically should it ever reach the destination coordinates.<br>
*
* @param {GameObject} source The Sprite to move
* @param {Sprite} source The Sprite to move
* @param {number} speed The speed it will move, in pixels per second (default is 60 pixels/sec)
* @param {number} maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms
*/
public moveTowardsMouse(source:GameObject, speed:number = 60, maxTime:number = 0)
{
var a:number = this.angleBetweenMouse(source);
public moveTowardsMouse(source: Sprite, speed: number = 60, maxTime: number = 0) {
var a: number = this.angleBetweenMouse(source);
if (maxTime > 0)
{
var d:number = this.distanceToMouse(source);
if (maxTime > 0)
{
var d: number = this.distanceToMouse(source);
// We know how many pixels we need to move, but how fast?
speed = d / (maxTime / 1000);
}
// We know how many pixels we need to move, but how fast?
speed = d / (maxTime / 1000);
}
source.velocity.x = Math.cos(a) * speed;
source.velocity.y = Math.sin(a) * speed;
source.body.velocity.x = Math.cos(a) * speed;
source.body.velocity.y = Math.sin(a) * speed;
}
}
/**
/**
* Sets the x/y acceleration on the source Sprite so it will move towards the mouse coordinates at the speed given (in pixels per second)<br>
* You must give a maximum speed value, beyond which the Sprite won't go any faster.<br>
* If you don't need acceleration look at moveTowardsMouse() instead.
*
* @param {GameObject} source The Sprite on which the acceleration will be set
* @param {Sprite} source The Sprite on which the acceleration will be set
* @param {number} speed The speed it will accelerate in pixels per second
* @param {number} xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally
* @param {number} ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically
*/
public accelerateTowardsMouse(source:GameObject, speed:number, xSpeedMax:number, ySpeedMax:number)
{
var a:number = this.angleBetweenMouse(source);
public accelerateTowardsMouse(source: Sprite, speed: number, xSpeedMax: number, ySpeedMax: number) {
var a: number = this.angleBetweenMouse(source);
source.velocity.x = 0;
source.velocity.y = 0;
source.body.velocity.x = 0;
source.body.velocity.y = 0;
source.acceleration.x = Math.cos(a) * speed;
source.acceleration.y = Math.sin(a) * speed;
source.body.acceleration.x = Math.cos(a) * speed;
source.body.acceleration.y = Math.sin(a) * speed;
source.maxVelocity.x = xSpeedMax;
source.maxVelocity.y = ySpeedMax;
}
source.body.maxVelocity.x = xSpeedMax;
source.body.maxVelocity.y = ySpeedMax;
}
/**
/**
* Sets the x/y velocity on the source Sprite so it will move towards the target coordinates at the speed given (in pixels per second)<br>
* If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.<br>
* Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms.<br>
* The source object doesn't stop moving automatically should it ever reach the destination coordinates.<br>
*
* @param {GameObject} source The Sprite to move
* @param {Sprite} source The Sprite to move
* @param {Point} target The Point coordinates to move the source Sprite towards
* @param {number} speed The speed it will move, in pixels per second (default is 60 pixels/sec)
* @param {number} maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms
*/
public moveTowardsPoint(source:GameObject, target:Point, speed:number = 60, maxTime:number = 0)
{
var a:number = this.angleBetweenPoint(source, target);
public moveTowardsPoint(source: Sprite, target: Point, speed: number = 60, maxTime: number = 0) {
var a: number = this.angleBetweenPoint(source, target);
if (maxTime > 0)
{
var d:number = this.distanceToPoint(source, target);
if (maxTime > 0)
{
var d: number = this.distanceToPoint(source, target);
// We know how many pixels we need to move, but how fast?
speed = d / (maxTime / 1000);
}
// We know how many pixels we need to move, but how fast?
speed = d / (maxTime / 1000);
}
source.velocity.x = Math.cos(a) * speed;
source.velocity.y = Math.sin(a) * speed;
}
source.body.velocity.x = Math.cos(a) * speed;
source.body.velocity.y = Math.sin(a) * speed;
}
/**
/**
* Sets the x/y acceleration on the source Sprite so it will move towards the target coordinates at the speed given (in pixels per second)<br>
* You must give a maximum speed value, beyond which the Sprite won't go any faster.<br>
* If you don't need acceleration look at moveTowardsPoint() instead.
*
* @param {GameObject} source The Sprite on which the acceleration will be set
* @param {Sprite} source The Sprite on which the acceleration will be set
* @param {Point} target The Point coordinates to move the source Sprite towards
* @param {number} speed The speed it will accelerate in pixels per second
* @param {number} xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally
* @param {number} ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically
*/
public accelerateTowardsPoint(source:GameObject, target:Point, speed:number, xSpeedMax:number, ySpeedMax:number)
{
var a:number = this.angleBetweenPoint(source, target);
public accelerateTowardsPoint(source: Sprite, target: Point, speed: number, xSpeedMax: number, ySpeedMax: number) {
var a: number = this.angleBetweenPoint(source, target);
source.velocity.x = 0;
source.velocity.y = 0;
source.body.velocity.x = 0;
source.body.velocity.y = 0;
source.acceleration.x = Math.cos(a) * speed;
source.acceleration.y = Math.sin(a) * speed;
source.body.acceleration.x = Math.cos(a) * speed;
source.body.acceleration.y = Math.sin(a) * speed;
source.maxVelocity.x = xSpeedMax;
source.maxVelocity.y = ySpeedMax;
}
source.body.maxVelocity.x = xSpeedMax;
source.body.maxVelocity.y = ySpeedMax;
}
/**
* Find the distance (in pixels, rounded) between two Sprites, taking their origin into account
/**
* Find the distance between two Sprites, taking their origin into account
*
* @param {GameObject} a The first Sprite
* @param {GameObject} b The second Sprite
* @param {Sprite} a The first Sprite
* @param {Sprite} b The second Sprite
* @return {number} int Distance (in pixels)
*/
public distanceBetween(a:GameObject, b:GameObject):number
{
var dx:number = (a.x + a.origin.x) - (b.x + b.origin.x);
var dy:number = (a.y + a.origin.y) - (b.y + b.origin.y);
public distanceBetween(a: Sprite, b: Sprite): number {
return Vec2Utils.distance(a.body.position, b.body.position);
}
return this._game.math.vectorLength(dx, dy);
}
/**
* Find the distance (in pixels, rounded) from an Sprite to the given Point, taking the source origin into account
/**
* Find the distance from an Sprite to the given Point, taking the source origin into account
*
* @param {GameObject} a The Sprite
* @param {Sprite} a The Sprite
* @param {Point} target The Point
* @return {number} Distance (in pixels)
*/
public distanceToPoint(a:GameObject, target:Point):number
{
var dx:number = (a.x + a.origin.x) - (target.x);
var dy:number = (a.y + a.origin.y) - (target.y);
public distanceToPoint(a: Sprite, target: Point): number {
var dx: number = (a.x + a.origin.x) - (target.x);
var dy: number = (a.y + a.origin.y) - (target.y);
return this._game.math.vectorLength(dx, dy);
}
return this.game.math.vectorLength(dx, dy);
}
/**
/**
* Find the distance (in pixels, rounded) from the object x/y and the mouse x/y
*
* @param {GameObject} a Sprite to test against
* @param {Sprite} a Sprite to test against
* @return {number} The distance between the given sprite and the mouse coordinates
*/
public distanceToMouse(a:GameObject):number
{
var dx: number = (a.x + a.origin.x) - this._game.input.x;
var dy: number = (a.y + a.origin.y) - this._game.input.y;
public distanceToMouse(a: Sprite): number {
var dx: number = (a.x + a.origin.x) - this.game.input.x;
var dy: number = (a.y + a.origin.y) - this.game.input.y;
return this._game.math.vectorLength(dx, dy);
}
return this.game.math.vectorLength(dx, dy);
}
/**
/**
* Find the angle (in radians) between an Sprite and an Point. The source sprite takes its x/y and origin into account.
* The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
*
* @param {GameObject} a The Sprite to test from
* @param {Sprite} a The Sprite to test from
* @param {Point} target The Point to angle the Sprite towards
* @param {boolean} asDegrees If you need the value in degrees instead of radians, set to true
*
* @return {number} The angle (in radians unless asDegrees is true)
*/
public angleBetweenPoint(a:GameObject, target:Point, asDegrees:bool = false):number
{
var dx:number = (target.x) - (a.x + a.origin.x);
var dy:number = (target.y) - (a.y + a.origin.y);
public angleBetweenPoint(a: Sprite, target: Point, asDegrees: bool = false): number {
var dx: number = (target.x) - (a.x + a.origin.x);
var dy: number = (target.y) - (a.y + a.origin.y);
if (asDegrees)
{
return this._game.math.radiansToDegrees(Math.atan2(dy, dx));
}
else
{
return Math.atan2(dy, dx);
}
if (asDegrees)
{
return this.game.math.radiansToDegrees(Math.atan2(dy, dx));
}
else
{
return Math.atan2(dy, dx);
}
}
/**
/**
* Find the angle (in radians) between the two Sprite, taking their x/y and origin into account.
* The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
*
* @param {GameObject} a The Sprite to test from
* @param {GameObject} b The Sprite to test to
* @param {Sprite} a The Sprite to test from
* @param {Sprite} b The Sprite to test to
* @param {boolean} asDegrees If you need the value in degrees instead of radians, set to true
*
* @return {number} The angle (in radians unless asDegrees is true)
*/
public angleBetween(a:GameObject, b:GameObject, asDegrees:bool = false):number
{
var dx:number = (b.x + b.origin.x) - (a.x + a.origin.x);
var dy:number = (b.y + b.origin.y) - (a.y + a.origin.y);
public angleBetween(a: Sprite, b: Sprite, asDegrees: bool = false): number {
if (asDegrees)
{
return this._game.math.radiansToDegrees(Math.atan2(dy, dx));
}
else
{
return Math.atan2(dy, dx);
}
var dx: number = (b.x + b.origin.x) - (a.x + a.origin.x);
var dy: number = (b.y + b.origin.y) - (a.y + a.origin.y);
if (asDegrees)
{
return this.game.math.radiansToDegrees(Math.atan2(dy, dx));
}
else
{
return Math.atan2(dy, dx);
}
}
/**
* Given the GameObject and speed calculate the velocity and return it as an Point based on the direction the sprite is facing
/**
* Given the Sprite and speed calculate the velocity and return it as an Point based on the direction the sprite is facing
*
* @param {GameObject} parent The Sprite to get the facing value from
* @param {Sprite} parent The Sprite to get the facing value from
* @param {number} speed The speed it will move, in pixels per second sq
*
* @return {Point} An Point where Point.x contains the velocity x value and Point.y contains the velocity y value
*/
public velocityFromFacing(parent:GameObject, speed:number):Point
{
var a:number;
public velocityFromFacing(parent: Sprite, speed: number): Point {
var a: number;
if (parent.facing == Collision.LEFT)
{
a = this._game.math.degreesToRadians(180);
}
else if (parent.facing == Collision.RIGHT)
{
a = this._game.math.degreesToRadians(0);
}
else if (parent.facing == Collision.UP)
{
a = this._game.math.degreesToRadians(-90);
}
else if (parent.facing == Collision.DOWN)
{
a = this._game.math.degreesToRadians(90);
}
if (parent.body.facing == Types.LEFT)
{
a = this.game.math.degreesToRadians(180);
}
else if (parent.body.facing == Types.RIGHT)
{
a = this.game.math.degreesToRadians(0);
}
else if (parent.body.facing == Types.UP)
{
a = this.game.math.degreesToRadians(-90);
}
else if (parent.body.facing == Types.DOWN)
{
a = this.game.math.degreesToRadians(90);
}
return new Point(Math.cos(a) * speed, Math.sin(a) * speed);
return new Point(Math.cos(a) * speed, Math.sin(a) * speed);
}
}
/**
/**
* Find the angle (in radians) between an Sprite and the mouse, taking their x/y and origin into account.
* The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
*
* @param {GameObject} a The Object to test from
* @param {Sprite} a The Object to test from
* @param {boolean} asDegrees If you need the value in degrees instead of radians, set to true
*
* @return {number} The angle (in radians unless asDegrees is true)
*/
public angleBetweenMouse(a:GameObject, asDegrees:bool = false):number
{
// In order to get the angle between the object and mouse, we need the objects screen coordinates (rather than world coordinates)
var p:MicroPoint = a.getScreenXY();
public angleBetweenMouse(a: Sprite, asDegrees: bool = false): number {
var dx:number = a._game.input.x - p.x;
var dy:number = a._game.input.y - p.y;
// In order to get the angle between the object and mouse, we need the objects screen coordinates (rather than world coordinates)
var p: Point = SpriteUtils.getScreenXY(a);
if (asDegrees)
{
return this._game.math.radiansToDegrees(Math.atan2(dy, dx));
}
else
{
return Math.atan2(dy, dx);
}
}
var dx: number = a.game.input.x - p.x;
var dy: number = a.game.input.y - p.y;
if (asDegrees)
{
return this.game.math.radiansToDegrees(Math.atan2(dy, dx));
}
else
{
return Math.atan2(dy, dx);
}
}
}
+35 -33
View File
@@ -61,7 +61,20 @@
<Content Include="components\animation\AnimationManager.js">
<DependentUpon>AnimationManager.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="components\sprite\Physics.ts" />
<TypeScriptCompile Include="Game.ts" />
<TypeScriptCompile Include="components\sprite\Events.ts" />
<TypeScriptCompile Include="components\sprite\Debug.ts" />
<Content Include="components\sprite\Debug.js">
<DependentUpon>Debug.ts</DependentUpon>
</Content>
<Content Include="components\sprite\Events.js">
<DependentUpon>Events.ts</DependentUpon>
</Content>
<Content Include="components\Tile.ts" />
<Content Include="components\TilemapLayer.ts" />
<Content Include="Game.js">
<DependentUpon>Game.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="core\Rectangle.ts" />
<TypeScriptCompile Include="core\Point.ts" />
<TypeScriptCompile Include="components\sprite\Texture.ts" />
@@ -90,15 +103,21 @@
<Content Include="gameobjects\DynamicTexture.js">
<DependentUpon>DynamicTexture.ts</DependentUpon>
</Content>
<Content Include="Game.js">
<DependentUpon>Game.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="gameobjects\Sprite.ts" />
<TypeScriptCompile Include="gameobjects\IGameObject.ts" />
<TypeScriptCompile Include="gameobjects\Emitter.ts" />
<Content Include="gameobjects\Emitter.js">
<DependentUpon>Emitter.ts</DependentUpon>
</Content>
<Content Include="gameobjects\IGameObject.js">
<DependentUpon>IGameObject.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="gameobjects\ScrollZone.ts" />
<Content Include="gameobjects\Particle.ts" />
<TypeScriptCompile Include="gameobjects\Tilemap.ts" />
<Content Include="gameobjects\Tilemap.js">
<DependentUpon>Tilemap.ts</DependentUpon>
</Content>
<Content Include="math\GameMath.js">
<DependentUpon>GameMath.ts</DependentUpon>
</Content>
@@ -115,30 +134,22 @@
<TypeScriptCompile Include="Statics.ts" />
<TypeScriptCompile Include="renderers\HeadlessRenderer.ts" />
<TypeScriptCompile Include="physics\PhysicsManager.ts" />
<TypeScriptCompile Include="physics\AABB.ts" />
<Content Include="physics\AABB.js">
<DependentUpon>AABB.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="physics\IPhysicsShape.ts" />
<TypeScriptCompile Include="physics\Circle.ts" />
<TypeScriptCompile Include="physics\Body.ts" />
<TypeScriptCompile Include="math\QuadTree.ts" />
<Content Include="math\QuadTree.js">
<DependentUpon>QuadTree.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="math\LinkedList.ts" />
<Content Include="math\LinkedList.js">
<DependentUpon>LinkedList.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="Motion.ts" />
<Content Include="Motion.js">
<DependentUpon>Motion.ts</DependentUpon>
</Content>
<Content Include="physics\Body.js">
<DependentUpon>Body.ts</DependentUpon>
</Content>
<Content Include="physics\Circle.js">
<DependentUpon>Circle.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="physics\IPhysicsBody.ts" />
<TypeScriptCompile Include="physics\Fixture.ts" />
<Content Include="physics\Fixture.js">
<DependentUpon>Fixture.ts</DependentUpon>
</Content>
<Content Include="physics\IPhysicsBody.js">
<DependentUpon>IPhysicsBody.ts</DependentUpon>
</Content>
<Content Include="physics\IPhysicsShape.js">
<DependentUpon>IPhysicsShape.ts</DependentUpon>
</Content>
<Content Include="physics\PhysicsManager.js">
<DependentUpon>PhysicsManager.ts</DependentUpon>
</Content>
@@ -224,12 +235,6 @@
<Content Include="system\Device.js">
<DependentUpon>Device.ts</DependentUpon>
</Content>
<Content Include="math\LinkedList.js">
<DependentUpon>LinkedList.ts</DependentUpon>
</Content>
<Content Include="physics\QuadTree.js">
<DependentUpon>QuadTree.ts</DependentUpon>
</Content>
<Content Include="math\RandomDataGenerator.js">
<DependentUpon>RandomDataGenerator.ts</DependentUpon>
</Content>
@@ -246,8 +251,6 @@
<TypeScriptCompile Include="system\StageScaleMode.ts" />
<TypeScriptCompile Include="system\RequestAnimationFrame.ts" />
<TypeScriptCompile Include="math\RandomDataGenerator.ts" />
<TypeScriptCompile Include="physics\QuadTree.ts" />
<TypeScriptCompile Include="math\LinkedList.ts" />
<TypeScriptCompile Include="system\Device.ts" />
<TypeScriptCompile Include="cameras\Camera.ts" />
<Content Include="tweens\easing\Back.js">
@@ -362,7 +365,6 @@
<TypeScriptCompile Include="loader\Loader.ts" />
<TypeScriptCompile Include="core\Group.ts" />
<TypeScriptCompile Include="math\GameMath.ts" />
<TypeScriptCompile Include="Game.ts" />
<TypeScriptCompile Include="gameobjects\DynamicTexture.ts" />
<TypeScriptCompile Include="components\animation\AnimationManager.ts" />
<Content Include="loader\Cache.js">
+7 -7
View File
@@ -27,7 +27,7 @@ module Phaser {
this.width = width;
this.height = height;
this.allowCollisions = Collision.NONE;
this.allowCollisions = Types.NONE;
}
@@ -144,7 +144,7 @@ module Phaser {
this.allowCollisions = collision;
if (collision & Collision.ANY)
if (collision & Types.ANY)
{
this.collideLeft = true;
this.collideRight = true;
@@ -153,22 +153,22 @@ module Phaser {
return;
}
if (collision & Collision.LEFT || collision & Collision.WALL)
if (collision & Types.LEFT || collision & Types.WALL)
{
this.collideLeft = true;
}
if (collision & Collision.RIGHT || collision & Collision.WALL)
if (collision & Types.RIGHT || collision & Types.WALL)
{
this.collideRight = true;
}
if (collision & Collision.UP || collision & Collision.CEILING)
if (collision & Types.UP || collision & Types.CEILING)
{
this.collideUp = true;
}
if (collision & Collision.DOWN || collision & Collision.CEILING)
if (collision & Types.DOWN || collision & Types.CEILING)
{
this.collideDown = true;
}
@@ -180,7 +180,7 @@ module Phaser {
*/
public resetCollision() {
this.allowCollisions = Collision.NONE;
this.allowCollisions = Types.NONE;
this.collideLeft = false;
this.collideRight = false;
this.collideUp = false;
+9 -9
View File
@@ -356,30 +356,30 @@ module Phaser {
* @param object {GameObject} Tiles you want to get that overlaps this.
* @return {array} Array with tiles informations. (Each contains x, y and the tile.)
*/
public getTileOverlaps(object: IGameObject) {
public getTileOverlaps(object: Sprite) {
// If the object is outside of the world coordinates then abort the check (tilemap has to exist within world bounds)
if (object.collisionMask.x < 0 || object.collisionMask.x > this.widthInPixels || object.collisionMask.y < 0 || object.collisionMask.bottom > this.heightInPixels)
if (object.body.bounds.x < 0 || object.body.bounds.x > this.widthInPixels || object.body.bounds.y < 0 || object.body.bounds.bottom > this.heightInPixels)
{
return;
}
// What tiles do we need to check against?
this._tempTileX = this._game.math.snapToFloor(object.collisionMask.x, this.tileWidth) / this.tileWidth;
this._tempTileY = this._game.math.snapToFloor(object.collisionMask.y, this.tileHeight) / this.tileHeight;
this._tempTileW = (this._game.math.snapToCeil(object.collisionMask.width, this.tileWidth) + this.tileWidth) / this.tileWidth;
this._tempTileH = (this._game.math.snapToCeil(object.collisionMask.height, this.tileHeight) + this.tileHeight) / this.tileHeight;
this._tempTileX = this._game.math.snapToFloor(object.body.bounds.x, this.tileWidth) / this.tileWidth;
this._tempTileY = this._game.math.snapToFloor(object.body.bounds.y, this.tileHeight) / this.tileHeight;
this._tempTileW = (this._game.math.snapToCeil(object.body.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth;
this._tempTileH = (this._game.math.snapToCeil(object.body.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight;
// Loop through the tiles we've got and check overlaps accordingly (the results are stored in this._tempTileBlock)
this._tempBlockResults = [];
this.getTempBlock(this._tempTileX, this._tempTileY, this._tempTileW, this._tempTileH, true);
Collision.TILE_OVERLAP = false;
Phaser.Physics.PhysicsManager.TILE_OVERLAP = false;
for (var r = 0; r < this._tempTileBlock.length; r++)
{
if (Collision.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true)
if (this._game.world.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true)
{
this._tempBlockResults.push({ x: this._tempTileBlock[r].x, y: this._tempTileBlock[r].y, tile: this._tempTileBlock[r].tile });
}
@@ -428,7 +428,7 @@ module Phaser {
if (collisionOnly)
{
// We only want to consider the tile for checking if you can actually collide with it
if (this.mapData[ty] && this.mapData[ty][tx] && this._parent.tiles[this.mapData[ty][tx]].allowCollisions != Collision.NONE)
if (this.mapData[ty] && this.mapData[ty][tx] && this._parent.tiles[this.mapData[ty][tx]].allowCollisions != Types.NONE)
{
this._tempTileBlock.push({ x: tx, y: ty, tile: this._parent.tiles[this.mapData[ty][tx]] });
}
-501
View File
@@ -1,501 +0,0 @@
/// <reference path="../Game.ts" />
/**
* Phaser - CollisionMask
*/
module Phaser {
export class CollisionMask {
/**
* CollisionMask constructor. Creates a new <code>CollisionMask</code> for the given GameObject.
*
* @param game {Phaser.Game} Current game instance.
* @param parent {Phaser.GameObject} The GameObject this CollisionMask belongs to.
* @param x {number} The initial x position of the CollisionMask.
* @param y {number} The initial y position of the CollisionMask.
* @param width {number} The width of the CollisionMask.
* @param height {number} The height of the CollisionMask.
*/
constructor(game: Game, parent: GameObject, x: number, y: number, width: number, height: number) {
this._game = game;
this._parent = parent;
// By default the CollisionMask is a quad
this.type = CollisionMask.QUAD;
this.quad = new Phaser.Quad(this._parent.x, this._parent.y, this._parent.width, this._parent.height);
this.offset = new MicroPoint(0, 0);
this.last = new MicroPoint(0, 0);
this._ref = this.quad;
return this;
}
private _game;
private _parent;
// An internal reference to the active collision shape
private _ref;
/**
* Geom type of this sprite. (available: QUAD, POINT, CIRCLE, LINE, RECTANGLE, POLYGON)
* @type {number}
*/
public type: number = 0;
/**
* Quad (a smaller version of Rectangle).
* @type {number}
*/
public static QUAD: number = 0;
/**
* Point.
* @type {number}
*/
public static POINT: number = 1;
/**
* Circle.
* @type {number}
*/
public static CIRCLE: number = 2;
/**
* Line.
* @type {number}
*/
public static LINE: number = 3;
/**
* Rectangle.
* @type {number}
*/
public static RECTANGLE: number = 4;
/**
* Polygon.
* @type {number}
*/
public static POLYGON: number = 5;
/**
* Rectangle shape container. A Rectangle instance.
* @type {Rectangle}
*/
public quad: Quad;
/**
* Point shape container. A Point instance.
* @type {Point}
*/
public point: Point;
/**
* Circle shape container. A Circle instance.
* @type {Circle}
*/
public circle: Circle;
/**
* Line shape container. A Line instance.
* @type {Line}
*/
public line: Line;
/**
* Rectangle shape container. A Rectangle instance.
* @type {Rectangle}
*/
public rect: Rectangle;
/**
* A value from the top-left of the GameObject frame that this collisionMask is offset to.
* If the CollisionMask is a Quad/Rectangle the offset relates to the top-left of that Quad.
* If the CollisionMask is a Circle the offset relates to the center of the circle.
* @type {MicroPoint}
*/
public offset: MicroPoint;
/**
* The previous x/y coordinates of the CollisionMask, used for hull calculations
* @type {MicroPoint}
*/
public last: MicroPoint;
/**
* Create a circle shape with specific diameter.
* @param diameter {number} Diameter of the circle.
* @return {CollisionMask} This
*/
createCircle(diameter: number): CollisionMask {
this.type = CollisionMask.CIRCLE;
this.circle = new Circle(this.last.x, this.last.y, diameter);
this._ref = this.circle;
return this;
}
/**
* Pre-update is called right before update() on each object in the game loop.
*/
public preUpdate() {
this.last.x = this.x;
this.last.y = this.y;
}
public update() {
this._ref.x = this._parent.x + this.offset.x;
this._ref.y = this._parent.y + this.offset.y;
}
/**
* Renders the bounding box around this Sprite and the contact points. Useful for visually debugging.
* @param camera {Camera} Camera the bound will be rendered to.
* @param cameraOffsetX {number} X offset of bound to the camera.
* @param cameraOffsetY {number} Y offset of bound to the camera.
*/
public render(camera:Camera, cameraOffsetX:number, cameraOffsetY:number) {
var _dx = cameraOffsetX + (this.x - camera.worldView.x);
var _dy = cameraOffsetY + (this.y - camera.worldView.y);
this._parent.context.fillStyle = this._parent.renderDebugColor;
if (this.type == CollisionMask.QUAD)
{
this._parent.context.fillRect(_dx, _dy, this.width, this.height);
}
else if (this.type == CollisionMask.CIRCLE)
{
this._parent.context.beginPath();
this._parent.context.arc(_dx, _dy, this.circle.radius, 0, Math.PI * 2);
this._parent.context.fill();
this._parent.context.closePath();
}
}
/**
* Destroy all objects and references belonging to this CollisionMask
*/
public destroy() {
this._game = null;
this._parent = null;
this._ref = null;
this.quad = null;
this.point = null;
this.circle = null;
this.rect = null;
this.line = null;
this.offset = null;
}
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.
* @param source {GeomSprite} Sprite you want to check.
* @return {boolean} Whether they overlaps or not.
*/
public intersects(source: CollisionMask): bool {
// Quad vs. Quad
if (this.type == CollisionMask.QUAD && source.type == CollisionMask.QUAD)
{
return this.quad.intersects(source.quad);
}
// Circle vs. Circle
if (this.type == CollisionMask.CIRCLE && source.type == CollisionMask.CIRCLE)
{
return Collision.circleToCircle(this.circle, source.circle).result;
}
// Circle vs. Rect
if (this.type == CollisionMask.CIRCLE && source.type == CollisionMask.RECTANGLE)
{
return Collision.circleToRectangle(this.circle, source.rect).result;
}
// Circle vs. Point
if (this.type == CollisionMask.CIRCLE && source.type == CollisionMask.POINT)
{
return Collision.circleContainsPoint(this.circle, source.point).result;
}
// Circle vs. Line
if (this.type == CollisionMask.CIRCLE && source.type == CollisionMask.LINE)
{
return Collision.lineToCircle(source.line, this.circle).result;
}
// Rect vs. Rect
if (this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.RECTANGLE)
{
return Collision.rectangleToRectangle(this.rect, source.rect).result;
}
// Rect vs. Circle
if (this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.CIRCLE)
{
return Collision.circleToRectangle(source.circle, this.rect).result;
}
// Rect vs. Point
if (this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.POINT)
{
return Collision.pointToRectangle(source.point, this.rect).result;
}
// Rect vs. Line
if (this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.LINE)
{
return Collision.lineToRectangle(source.line, this.rect).result;
}
// Point vs. Point
if (this.type == CollisionMask.POINT && source.type == CollisionMask.POINT)
{
return this.point.equals(source.point);
}
// Point vs. Circle
if (this.type == CollisionMask.POINT && source.type == CollisionMask.CIRCLE)
{
return Collision.circleContainsPoint(source.circle, this.point).result;
}
// Point vs. Rect
if (this.type == CollisionMask.POINT && source.type == CollisionMask.RECTANGLE)
{
return Collision.pointToRectangle(this.point, source.rect).result;
}
// Point vs. Line
if (this.type == CollisionMask.POINT && source.type == CollisionMask.LINE)
{
return source.line.isPointOnLine(this.point.x, this.point.y);
}
// Line vs. Line
if (this.type == CollisionMask.LINE && source.type == CollisionMask.LINE)
{
return Collision.lineSegmentToLineSegment(this.line, source.line).result;
}
// Line vs. Circle
if (this.type == CollisionMask.LINE && source.type == CollisionMask.CIRCLE)
{
return Collision.lineToCircle(this.line, source.circle).result;
}
// Line vs. Rect
if (this.type == CollisionMask.LINE && source.type == CollisionMask.RECTANGLE)
{
return Collision.lineSegmentToRectangle(this.line, source.rect).result;
}
// Line vs. Point
if (this.type == CollisionMask.LINE && source.type == CollisionMask.POINT)
{
return this.line.isPointOnLine(source.point.x, source.point.y);
}
return false;
}
public checkHullIntersection(mask: CollisionMask): bool {
if ((this.hullX + this.hullWidth > mask.hullX) && (this.hullX < mask.hullX + mask.width) && (this.hullY + this.hullHeight > mask.hullY) && (this.hullY < mask.hullY + mask.hullHeight))
{
return true;
}
else
{
return false;
}
}
public get hullWidth(): number {
if (this.deltaX > 0)
{
return this.width + this.deltaX;
}
else
{
return this.width - this.deltaX;
}
}
public get hullHeight(): number {
if (this.deltaY > 0)
{
return this.height + this.deltaY;
}
else
{
return this.height - this.deltaY;
}
}
public get hullX(): number {
if (this.x < this.last.x)
{
return this.x;
}
else
{
return this.last.x;
}
}
public get hullY(): number {
if (this.y < this.last.y)
{
return this.y;
}
else
{
return this.last.y;
}
}
public get deltaXAbs(): number {
return (this.deltaX > 0 ? this.deltaX : -this.deltaX);
}
public get deltaYAbs(): number {
return (this.deltaY > 0 ? this.deltaY : -this.deltaY);
}
public get deltaX(): number {
return this.x - this.last.x;
}
public get deltaY(): number {
return this.y - this.last.y;
}
public get x(): number {
return this._ref.x;
//return this.quad.x;
}
public set x(value: number) {
this._ref.x = value;
//this.quad.x = value;
}
public get y(): number {
return this._ref.y;
//return this.quad.y;
}
public set y(value: number) {
this._ref.y = value;
//this.quad.y = value;
}
//public get rotation(): number {
// return this._angle;
//}
//public set rotation(value: number) {
// this._angle = this._game.math.wrap(value, 360, 0);
//}
//public get angle(): number {
// return this._angle;
//}
//public set angle(value: number) {
// this._angle = this._game.math.wrap(value, 360, 0);
//}
public set width(value:number) {
//this.quad.width = value;
this._ref.width = value;
}
public set height(value:number) {
//this.quad.height = value;
this._ref.height = value;
}
public get width(): number {
//return this.quad.width;
return this._ref.width;
}
public get height(): number {
//return this.quad.height;
return this._ref.height;
}
public get left(): number {
return this.x;
}
public get right(): number {
return this.x + this.width;
}
public get top(): number {
return this.y;
}
public get bottom(): number {
return this.y + this.height;
}
public get halfWidth(): number {
return this.width / 2;
}
public get halfHeight(): number {
return this.height / 2;
}
}
}
+39
View File
@@ -0,0 +1,39 @@
/// <reference path="../../Game.ts" />
/// <reference path="../../gameobjects/DynamicTexture.ts" />
/// <reference path="../../utils/SpriteUtils.ts" />
/**
* Phaser - Components - Events
*
*
*/
module Phaser.Components {
export class Events {
constructor(parent: Sprite, key?: string = '') {
this._game = parent.game;
this._sprite = parent;
}
/**
*
*/
private _game: Game;
/**
* Reference to the Image stored in the Game.Cache that is used as the texture for the Sprite.
*/
private _sprite: Sprite;
public onInputOver: Phaser.Signal;
public onInputOut: Phaser.Signal;
public onInputDown: Phaser.Signal;
public onInputUp: Phaser.Signal;
}
}
-29
View File
@@ -1,29 +0,0 @@
/**
* Phaser - Components - Input
*
*
*/
module Phaser.Components {
export class Input {
// Input
//public inputEnabled: bool = false;
//private _inputOver: bool = false;
//public onInputOver: Phaser.Signal;
//public onInputOut: Phaser.Signal;
//public onInputDown: Phaser.Signal;
//public onInputUp: Phaser.Signal;
/**
* Update input.
*/
private updateInput() {
}
}
}
-108
View File
@@ -1,108 +0,0 @@
/// <reference path="../../core/Vec2.ts" />
/// <reference path="../../core/Point.ts" />
/// <reference path="../../math/Vec2Utils.ts" />
/// <reference path="../../physics/AABB.ts" />
/// <reference path="../../physics/Circle.ts" />
/// <reference path="../../physics/IPhysicsShape.ts" />
/// <reference path="../../physics/IPhysicsBody.ts" />
/**
* Phaser - Components - Physics
*/
module Phaser.Components {
export class Physics implements Phaser.Physics.IPhysicsBody {
constructor(parent: Sprite) {
this.game = parent.game;
this._sprite = parent;
this.gravity = Vec2Utils.clone(this.game.world.physics.gravity);
this.drag = Vec2Utils.clone(this.game.world.physics.drag);
this.bounce = Vec2Utils.clone(this.game.world.physics.bounce);
this.friction = Vec2Utils.clone(this.game.world.physics.friction);
this.velocity = new Vec2;
this.acceleration = new Vec2;
this.touching = Phaser.Types.NONE;
this.wasTouching = Phaser.Types.NONE;
this.allowCollisions = Phaser.Types.ANY;
this.shape = this.game.world.physics.add(new Phaser.Physics.AABB(this.game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height));
}
private _sprite: Sprite;
public game: Game;
public shape: Phaser.Physics.IPhysicsShape;
/**
* Whether this object will be moved by impacts with other objects or not.
* @type {boolean}
*/
public immovable: bool = false;
/**
* Set this to false if you want to skip the automatic movement stuff
* @type {boolean}
*/
public moves: bool = true;
public gravity: Vec2;
public drag: Vec2;
public bounce: Vec2;
public friction: Vec2;
public velocity: Vec2;
public acceleration: Vec2;
public touching: number;
public allowCollisions: number;
public wasTouching: number;
public mass: number = 1;
public setCircle(diameter: number) {
// Here is the stuff I want to remove
this.game.world.physics.remove(this.shape);
this.shape = this.game.world.physics.add(new Phaser.Physics.Circle(this.game, this._sprite, this._sprite.x, this._sprite.y, diameter));
this._sprite.physics.shape.physics = this;
}
/**
* Internal function for updating the position and speed of this object.
*/
public update() {
// if this is all it does maybe move elsewhere? Sprite postUpdate?
if (this.moves && this.shape)
{
this._sprite.x = (this.shape.position.x - this.shape.bounds.halfWidth) - this.shape.offset.x;
this._sprite.y = (this.shape.position.y - this.shape.bounds.halfHeight) - this.shape.offset.y;
}
}
/**
* Render debug infos. (including name, bounds info, position and some other properties)
* @param x {number} X position of the debug info to be rendered.
* @param y {number} Y position of the debug info to be rendered.
* @param [color] {number} color of the debug info to be rendered. (format is css color string)
*/
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
this._sprite.texture.context.fillStyle = color;
this._sprite.texture.context.fillText('Sprite: (' + this._sprite.frameBounds.width + ' x ' + this._sprite.frameBounds.height + ')', x, y);
//this._sprite.texture.context.fillText('x: ' + this._sprite.frameBounds.x.toFixed(1) + ' y: ' + this._sprite.frameBounds.y.toFixed(1) + ' rotation: ' + this._sprite.rotation.toFixed(1), x, y + 14);
this._sprite.texture.context.fillText('x: ' + this.shape.bounds.x.toFixed(1) + ' y: ' + this.shape.bounds.y.toFixed(1) + ' rotation: ' + this._sprite.rotation.toFixed(1), x, y + 14);
this._sprite.texture.context.fillText('vx: ' + this.velocity.x.toFixed(1) + ' vy: ' + this.velocity.y.toFixed(1), x, y + 28);
this._sprite.texture.context.fillText('ax: ' + this.acceleration.x.toFixed(1) + ' ay: ' + this.acceleration.y.toFixed(1), x, y + 42);
}
}
}
-36
View File
@@ -1,36 +0,0 @@
/**
* Phaser - Components - Properties
*
*
*/
module Phaser.Components {
export class Properties {
/**
* Handy for storing health percentage or armor points or whatever.
* @type {number}
*/
public health: number;
/**
* Reduces the "health" variable of this sprite by the amount specified in Damage.
* Calls kill() if health drops to or below zero.
*
* @param Damage {number} How much health to take away (use a negative number to give a health bonus).
*/
public hurt(damage: number) {
this.health = this.health - damage;
if (this.health <= 0)
{
//this.kill();
}
}
}
}
+50 -38
View File
@@ -1,5 +1,7 @@
/// <reference path="../Game.ts" />
/// <reference path="../Group.ts" />
/// <reference path="../core/Group.ts" />
/// <reference path="Particle.ts" />
/// <reference path="../utils/SpriteUtils.ts" />
/**
* Phaser - Emitter
@@ -29,13 +31,13 @@ module Phaser {
this.y = y;
this.width = 0;
this.height = 0;
this.minParticleSpeed = new MicroPoint(-100, -100);
this.maxParticleSpeed = new MicroPoint(100, 100);
this.minParticleSpeed = new Vec2(-100, -100);
this.maxParticleSpeed = new Vec2(100, 100);
this.minRotation = -360;
this.maxRotation = 360;
this.gravity = 0;
this.particleClass = null;
this.particleDrag = new MicroPoint();
this.particleDrag = new Vec2();
this.frequency = 0.1;
this.lifespan = 3;
this.bounce = 0;
@@ -43,7 +45,6 @@ module Phaser {
this._counter = 0;
this._explode = true;
this.on = false;
this._point = new MicroPoint();
}
@@ -67,22 +68,27 @@ module Phaser {
*/
public height: number;
/**
*
*/
public alive: bool;
/**
* The minimum possible velocity of a particle.
* The default value is (-100,-100).
*/
public minParticleSpeed: MicroPoint;
public minParticleSpeed: Vec2;
/**
* The maximum possible velocity of a particle.
* The default value is (100,100).
*/
public maxParticleSpeed: MicroPoint;
public maxParticleSpeed: Vec2;
/**
* The X and Y drag component of particles launched from the emitter.
*/
public particleDrag: MicroPoint;
public particleDrag: Vec2;
/**
* The minimum possible angular velocity of a particle. The default value is -360.
@@ -152,7 +158,7 @@ module Phaser {
/**
* Internal point object, handy for reusing for memory mgmt purposes.
*/
private _point: MicroPoint;
private _point: Vec2;
/**
* Clean up memory.
@@ -185,7 +191,7 @@ module Phaser {
/*
if(Multiple)
{
var sprite:Sprite = new Sprite(this._game);
var sprite:Sprite = new Sprite(this.game);
sprite.loadGraphic(Graphics,true);
totalFrames = sprite.frames;
sprite.destroy();
@@ -200,17 +206,17 @@ module Phaser {
{
if (this.particleClass == null)
{
particle = new Particle(this._game);
particle = new Particle(this.game);
}
else
{
particle = new this.particleClass(this._game);
particle = new this.particleClass(this.game);
}
if (multiple)
{
/*
randomFrame = this._game.math.random()*totalFrames;
randomFrame = this.game.math.random()*totalFrames;
if(BakedRotations > 0)
particle.loadRotatedGraphic(Graphics,BakedRotations,randomFrame);
else
@@ -231,21 +237,21 @@ module Phaser {
if (graphics)
{
particle.loadGraphic(graphics);
particle.texture.loadImage(graphics);
}
}
if (collide > 0)
{
particle.allowCollisions = Collision.ANY;
particle.body.allowCollisions = Types.ANY;
particle.body.type = Types.BODY_DYNAMIC;
particle.width *= collide;
particle.height *= collide;
//particle.centerOffsets();
}
else
{
particle.allowCollisions = Collision.NONE;
particle.body.allowCollisions = Types.NONE;
}
particle.exists = false;
@@ -287,7 +293,7 @@ module Phaser {
}
else
{
this._timer += this._game.time.elapsed;
this._timer += this.game.time.elapsed;
while ((this.frequency > 0) && (this._timer > this.frequency) && this.on)
{
@@ -311,11 +317,18 @@ module Phaser {
* Call this function to turn off all the particles and the emitter.
*/
public kill() {
this.on = false;
this.alive = false;
this.exists = false;
}
super.kill();
/**
* Handy for bringing game objects "back to life". Just sets alive and exists back to true.
* In practice, this is most often called by <code>Object.reset()</code>.
*/
public revive() {
this.alive = true;
this.exists = true;
}
/**
@@ -351,46 +364,46 @@ module Phaser {
var particle: Particle = this.recycle(Particle);
particle.lifespan = this.lifespan;
particle.elasticity = this.bounce;
particle.reset(this.x - (particle.width >> 1) + this._game.math.random() * this.width, this.y - (particle.height >> 1) + this._game.math.random() * this.height);
particle.body.bounce.setTo(this.bounce, this.bounce);
SpriteUtils.reset(particle, this.x - (particle.width >> 1) + this.game.math.random() * this.width, this.y - (particle.height >> 1) + this.game.math.random() * this.height);
particle.visible = true;
if (this.minParticleSpeed.x != this.maxParticleSpeed.x)
{
particle.velocity.x = this.minParticleSpeed.x + this._game.math.random() * (this.maxParticleSpeed.x - this.minParticleSpeed.x);
particle.body.velocity.x = this.minParticleSpeed.x + this.game.math.random() * (this.maxParticleSpeed.x - this.minParticleSpeed.x);
}
else
{
particle.velocity.x = this.minParticleSpeed.x;
particle.body.velocity.x = this.minParticleSpeed.x;
}
if (this.minParticleSpeed.y != this.maxParticleSpeed.y)
{
particle.velocity.y = this.minParticleSpeed.y + this._game.math.random() * (this.maxParticleSpeed.y - this.minParticleSpeed.y);
particle.body.velocity.y = this.minParticleSpeed.y + this.game.math.random() * (this.maxParticleSpeed.y - this.minParticleSpeed.y);
}
else
{
particle.velocity.y = this.minParticleSpeed.y;
particle.body.velocity.y = this.minParticleSpeed.y;
}
particle.acceleration.y = this.gravity;
particle.body.acceleration.y = this.gravity;
if (this.minRotation != this.maxRotation && this.minRotation !== 0 && this.maxRotation !== 0)
{
particle.angularVelocity = this.minRotation + this._game.math.random() * (this.maxRotation - this.minRotation);
particle.body.angularVelocity = this.minRotation + this.game.math.random() * (this.maxRotation - this.minRotation);
}
else
{
particle.angularVelocity = this.minRotation;
particle.body.angularVelocity = this.minRotation;
}
if (particle.angularVelocity != 0)
if (particle.body.angularVelocity != 0)
{
particle.angle = this._game.math.random() * 360 - 180;
particle.angle = this.game.math.random() * 360 - 180;
}
particle.drag.x = this.particleDrag.x;
particle.drag.y = this.particleDrag.y;
particle.body.drag.x = this.particleDrag.x;
particle.body.drag.y = this.particleDrag.y;
particle.onEmit();
}
@@ -444,10 +457,9 @@ module Phaser {
*
* @param Object {object} The <code>Object</code> that you want to sync up with.
*/
public at(object) {
object.getMidpoint(this._point);
this.x = this._point.x - (this.width >> 1);
this.y = this._point.y - (this.height >> 1);
public at(object: Sprite) {
this.x = object.body.bounds.halfWidth - (this.width >> 1);
this.y = object.body.bounds.halfHeight - (this.height >> 1);
}
}
+21 -16
View File
@@ -1,6 +1,11 @@
/// <reference path="../Game.ts" />
/// <reference path="../tweens/Tween.ts" />
/// <reference path="../physics/AABB.ts" />
/// <reference path="../gameobjects/Emitter.ts" />
/// <reference path="../gameobjects/Particle.ts" />
/// <reference path="../gameobjects/Sprite.ts" />
/// <reference path="../gameobjects/ScrollZone.ts" />
/// <reference path="../gameobjects/DynamicTexture.ts" />
/// <reference path="../gameobjects/Tilemap.ts" />
/**
* Phaser - GameObjectFactory
@@ -97,9 +102,9 @@ module Phaser {
*
* @return {Particle} The newly created particle object.
*/
//public particle(): Particle {
// return new Particle(this._game);
//}
public particle(): Particle {
return new Particle(this._game);
}
/**
* Create a new Emitter.
@@ -109,9 +114,9 @@ module Phaser {
* @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 <Emitter> this._world.group.add(new Emitter(this._game, x, y, size));
//}
public emitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
return <Emitter> this._world.group.add(new Emitter(this._game, x, y, size));
}
/**
* Create a new ScrollZone object with image key, position and size.
@@ -138,9 +143,9 @@ module Phaser {
* @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 <Tilemap> this._world.group.add(new Tilemap(this._game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
//}
public tilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
return <Tilemap> this._world.group.add(new Tilemap(this._game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
}
/**
* Create a tween object for a specific object.
@@ -181,9 +186,9 @@ module Phaser {
* @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);
//}
public existingEmitter(emitter: Emitter): Emitter {
return this._world.group.add(emitter);
}
/**
* Add an existing ScrollZone to the current world.
@@ -203,9 +208,9 @@ module Phaser {
* @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);
//}
public existingTilemap(tilemap: Tilemap): Tilemap {
return this._world.group.add(tilemap);
}
/**
* Add an existing Tween to the current world.
-645
View File
@@ -1,645 +0,0 @@
/// <reference path="../Game.ts" />
/// <reference path="../geom/Polygon.ts" />
/// <reference path="../utils/RectangleUtils.ts" />
/**
* Phaser - GeomSprite
*
* A GeomSprite is a special kind of GameObject that contains a base geometry class (Circle, Line, Point, Rectangle).
* They can be rendered in the game and used for collision just like any other game object. Display of them is controlled
* via the lineWidth / lineColor / fillColor and renderOutline / renderFill properties.
*/
module Phaser {
export class GeomSprite extends Sprite {
/**
* GeomSprite constructor
* Create a new <code>GeomSprite</code>.
*
* @param game {Phaser.Game} Current game instance.
* @param [x] {number} the initial x position of the sprite.
* @param [y] {number} the initial y position of the sprite.
*/
constructor(game: Game, x?: number = 0, y?: number = 0) {
super(game, x, y);
this.type = GeomSprite.UNASSIGNED;
return this;
}
// local rendering related temp vars to help avoid gc spikes
private _dx: number = 0;
private _dy: number = 0;
private _dw: number = 0;
private _dh: number = 0;
/**
* Geom type of this sprite. (available: UNASSIGNED, CIRCLE, LINE, POINT, RECTANGLE)
* @type {number}
*/
public type: number = 0;
/**
* Not completely set yet. (the default type)
*/
public static UNASSIGNED: number = 0;
/**
* Circle.
* @type {number}
*/
public static CIRCLE: number = 1;
/**
* Line.
* @type {number}
*/
public static LINE: number = 2;
/**
* Point.
* @type {number}
*/
public static POINT: number = 3;
/**
* Rectangle.
* @type {number}
*/
public static RECTANGLE: number = 4;
/**
* Polygon.
* @type {number}
*/
public static POLYGON: number = 5;
/**
* Circle shape container. A Circle instance.
* @type {Circle}
*/
public circle: Circle;
/**
* Line shape container. A Line instance.
* @type {Line}
*/
public line: Line;
/**
* Point shape container. A Point instance.
* @type {Point}
*/
public point: Point;
/**
* Rectangle shape container. A Rectangle instance.
* @type {Rectangle}
*/
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}
*/
public renderOutline: bool = true;
/**
* Fill the shape or not. (default is true)
* @type {boolean}
*/
public renderFill: bool = true;
/**
* Width of outline. (default is 1)
* @type {number}
*/
public lineWidth: number = 1;
/**
* Width of outline. (default is 1)
* @type {number}
*/
public lineColor: string = 'rgb(0,255,0)';
/**
* The color of the filled area in rgb or rgba string format
* @type {string} Defaults to rgb(0,100,0) - a green color
*/
public fillColor: string = 'rgb(0,100,0)';
/**
* Just like Sprite.loadGraphic(), this will load a circle and set its shape to Circle.
* @param circle {Circle} Circle geometry define.
* @return {GeomSprite} GeomSprite instance itself.
*/
loadCircle(circle:Circle): GeomSprite {
this.refresh();
this.circle = circle;
this.type = GeomSprite.CIRCLE;
return this;
}
/**
* Just like Sprite.loadGraphic(), this will load a line and set its shape to Line.
* @param line {Line} Line geometry define.
* @return {GeomSprite} GeomSprite instance itself.
*/
loadLine(line:Line): GeomSprite {
this.refresh();
this.line = line;
this.type = GeomSprite.LINE;
return this;
}
/**
* Just like Sprite.loadGraphic(), this will load a point and set its shape to Point.
* @param point {Point} Point geometry define.
* @return {GeomSprite} GeomSprite instance itself.
*/
loadPoint(point:Point): GeomSprite {
this.refresh();
this.point = point;
this.type = GeomSprite.POINT;
return this;
}
/**
* Just like Sprite.loadGraphic(), this will load a rect and set its shape to Rectangle.
* @param rect {Rectangle} Rectangle geometry define.
* @return {GeomSprite} GeomSprite instance itself.
*/
loadRectangle(rect:Rectangle): GeomSprite {
this.refresh();
this.rect = rect;
this.type = GeomSprite.RECTANGLE;
return this;
}
/**
* Create a circle shape with specific diameter.
* @param diameter {number} Diameter of the circle.
* @return {GeomSprite} GeomSprite instance itself.
*/
createCircle(diameter: number): GeomSprite {
this.refresh();
this.circle = new Circle(this.x, this.y, diameter);
this.type = GeomSprite.CIRCLE;
this.frameBounds.setTo(this.circle.x - this.circle.radius, this.circle.y - this.circle.radius, this.circle.diameter, this.circle.diameter);
return this;
}
/**
* Create a line shape with specific end point.
* @param x {number} X position of the end point.
* @param y {number} Y position of the end point.
* @return {GeomSprite} GeomSprite instance itself.
*/
createLine(x: number, y: number): GeomSprite {
this.refresh();
this.line = new Line(this.x, this.y, x, y);
this.type = GeomSprite.LINE;
this.frameBounds.setTo(this.x, this.y, this.line.width, this.line.height);
return this;
}
/**
* Create a point shape at spriter's position.
* @return {GeomSprite} GeomSprite instance itself.
*/
createPoint(): GeomSprite {
this.refresh();
this.point = new Point(this.x, this.y);
this.type = GeomSprite.POINT;
this.frameBounds.width = 1;
this.frameBounds.height = 1;
return this;
}
/**
* Create a rectangle shape of the given width and height size
* @param width {Number} Width of the rectangle
* @param height {Number} Height of the rectangle
* @return {GeomSprite} GeomSprite instance.
*/
createRectangle(width: number, height: number): GeomSprite {
this.refresh();
this.rect = new Rectangle(this.x, this.y, width, height);
this.type = GeomSprite.RECTANGLE;
this.frameBounds.copyFrom(this.rect);
return this;
}
/**
* Create a polygon object
* @param width {Number} Width of the rectangle
* @param height {Number} Height of the rectangle
* @return {GeomSprite} GeomSprite instance.
*/
createPolygon(points?: Vec2[] = []): GeomSprite {
//this.refresh();
//this.polygon = new Polygon(new Vec2(this.x, this.y), points);
//this.type = GeomSprite.POLYGON;
//this.frameBounds.copyFrom(this.rect);
return this;
}
/**
* Destroy all geom shapes of this sprite.
*/
refresh() {
this.circle = null;
this.line = null;
this.point = null;
this.rect = null;
}
/**
* Update bounds.
*/
update() {
// Update bounds and position?
if (this.type == GeomSprite.UNASSIGNED)
{
return;
}
else if (this.type == GeomSprite.CIRCLE)
{
this.circle.x = this.x;
this.circle.y = this.y;
this.frameBounds.width = this.circle.diameter;
this.frameBounds.height = this.circle.diameter;
}
else if (this.type == GeomSprite.LINE)
{
this.line.x1 = this.x;
this.line.y1 = this.y;
this.frameBounds.setTo(this.x, this.y, this.line.width, this.line.height);
}
else if (this.type == GeomSprite.POINT)
{
this.point.x = this.x;
this.point.y = this.y;
}
else if (this.type == GeomSprite.RECTANGLE)
{
this.rect.x = this.x;
this.rect.y = this.y;
this.frameBounds.copyFrom(this.rect);
}
}
/**
* Check whether this object is visible in a specific camera rectangle.
* @param camera {Rectangle} The rectangle you want to check.
* @return {boolean} Return true if bounds of this sprite intersects the given rectangle, otherwise return false.
*/
/*
public inCamera(camera: Rectangle): bool {
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
{
this._dx = this.frameBounds.x - (camera.x * this.scrollFactor.x);
this._dy = this.frameBounds.y - (camera.y * this.scrollFactor.x);
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);
}
}
*/
/**
* Render this sprite to specific camera. Called by game loop after update().
* @param camera {Camera} Camera this sprite will be rendered to.
* @cameraOffsetX {number} X offset to the camera.
* @cameraOffsetY {number} Y offset to the camera.
* @return {boolean} Return false if not rendered, otherwise return true.
*/
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {
// Render checks
//if (this.type == GeomSprite.UNASSIGNED || this.visible === false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.cameraBlacklist.indexOf(camera.ID) !== -1 || this.inCamera(camera.worldView) == false)
//{
// return false;
//}
// Alpha
if (this.alpha !== 1)
{
var globalAlpha = this.context.globalAlpha;
this.context.globalAlpha = this.alpha;
}
this._dx = cameraOffsetX + (this.frameBounds.x - camera.worldView.x);
this._dy = cameraOffsetY + (this.frameBounds.y - camera.worldView.y);
this._dw = this.frameBounds.width * this.scale.x;
this._dh = this.frameBounds.height * this.scale.y;
// Apply camera difference
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
{
this._dx -= (camera.worldView.x * this.scrollFactor.x);
this._dy -= (camera.worldView.y * this.scrollFactor.y);
}
// Rotation is disabled for now as I don't want it to be misleading re: collision
/*
if (this.angle !== 0)
{
this.context.save();
this.context.translate(this._dx + (this._dw / 2) - this.origin.x, this._dy + (this._dh / 2) - this.origin.y);
this.context.rotate(this.angle * (Math.PI / 180));
this._dx = -(this._dw / 2);
this._dy = -(this._dh / 2);
}
*/
this._dx = Math.round(this._dx);
this._dy = Math.round(this._dy);
this._dw = Math.round(this._dw);
this._dh = Math.round(this._dh);
this._game.stage.saveCanvasValues();
// Debug
//this.context.fillStyle = 'rgba(255,0,0,0.5)';
//this.context.fillRect(this.frameBounds.x, this.frameBounds.y, this.frameBounds.width, this.frameBounds.height);
this.context.lineWidth = this.lineWidth;
this.context.strokeStyle = this.lineColor;
this.context.fillStyle = this.fillColor;
if (this._game.stage.fillStyle !== this.fillColor)
{
}
// Primitive Renderer
if (this.type == GeomSprite.CIRCLE)
{
this.context.beginPath();
this.context.arc(this._dx, this._dy, this.circle.radius, 0, Math.PI * 2);
if (this.renderOutline)
{
this.context.stroke();
}
if (this.renderFill)
{
this.context.fill();
}
this.context.closePath();
}
else if (this.type == GeomSprite.LINE)
{
this.context.beginPath();
this.context.moveTo(this._dx, this._dy);
this.context.lineTo(this.line.x2, this.line.y2);
this.context.stroke();
this.context.closePath();
}
else if (this.type == GeomSprite.POINT)
{
this.context.fillRect(this._dx, this._dy, 2, 2);
}
else if (this.type == GeomSprite.RECTANGLE)
{
// We can use the faster fillRect if we don't need the outline
if (this.renderOutline == false)
{
this.context.fillRect(this._dx, this._dy, this.rect.width, this.rect.height);
}
else
{
this.context.beginPath();
this.context.rect(this._dx, this._dy, this.rect.width, this.rect.height);
this.context.stroke();
if (this.renderFill)
{
this.context.fill();
}
this.context.closePath();
}
// And now the edge points
this.context.fillStyle = 'rgb(255,255,255)';
//this.renderPoint(this.rect.topLeft, this._dx, this._dy, 2);
//this.renderPoint(this.rect.topCenter, this._dx, this._dy, 2);
//this.renderPoint(this.rect.topRight, this._dx, this._dy, 2);
//this.renderPoint(this.rect.leftCenter, this._dx, this._dy, 2);
//this.renderPoint(this.rect.center, this._dx, this._dy, 2);
//this.renderPoint(this.rect.rightCenter, this._dx, this._dy, 2);
//this.renderPoint(this.rect.bottomLeft, this._dx, this._dy, 2);
//this.renderPoint(this.rect.bottomCenter, this._dx, this._dy, 2);
//this.renderPoint(this.rect.bottomRight, this._dx, this._dy, 2);
this.renderPoint(this.rect.topLeft, 0, 0, 2);
this.renderPoint(this.rect.topCenter, 0, 0, 2);
this.renderPoint(this.rect.topRight, 0, 0, 2);
this.renderPoint(this.rect.leftCenter, 0, 0, 2);
this.renderPoint(this.rect.center, 0, 0, 2);
this.renderPoint(this.rect.rightCenter, 0, 0, 2);
this.renderPoint(this.rect.bottomLeft, 0, 0, 2);
this.renderPoint(this.rect.bottomCenter, 0, 0, 2);
this.renderPoint(this.rect.bottomRight, 0, 0, 2);
}
this._game.stage.restoreCanvasValues();
if (this.rotation !== 0)
{
this.context.translate(0, 0);
this.context.restore();
}
if (globalAlpha > -1)
{
this.context.globalAlpha = globalAlpha;
}
return true;
}
/**
* Render a point of geometry.
* @param point {Point} Position of the point.
* @param offsetX {number} X offset to its position.
* @param offsetY {number} Y offset to its position.
* @param [size] {number} point size.
*/
public renderPoint(point, offsetX?: number = 0, offsetY?: number = 0, size?: number = 1) {
this.context.fillRect(offsetX + point.x, offsetY + point.y, size, size);
}
/**
* Render debug infos. (this method does not work now)
* @param x {number} X position of the debug info to be rendered.
* @param y {number} Y position of the debug info to be rendered.
* @param [color] {number} color of the debug info to be rendered. (format is css color string)
*/
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
//this.context.fillStyle = color;
//this.context.fillText('Sprite: ' + this.name + ' (' + this.frameBounds.width + ' x ' + this.frameBounds.height + ')', x, y);
//this.context.fillText('x: ' + this.frameBounds.x.toFixed(1) + ' y: ' + this.frameBounds.y.toFixed(1) + ' rotation: ' + this.angle.toFixed(1), x, y + 14);
//this.context.fillText('dx: ' + this._dx.toFixed(1) + ' dy: ' + this._dy.toFixed(1) + ' dw: ' + this._dw.toFixed(1) + ' dh: ' + this._dh.toFixed(1), x, y + 28);
//this.context.fillText('sx: ' + this._sx.toFixed(1) + ' sy: ' + this._sy.toFixed(1) + ' sw: ' + this._sw.toFixed(1) + ' sh: ' + this._sh.toFixed(1), x, y + 42);
}
/**
* Gives a basic boolean response to a geometric collision.
* If you need the details of the collision use the Collision functions instead and inspect the IntersectResult object.
* @param source {GeomSprite} Sprite you want to check.
* @return {boolean} Whether they overlaps or not.
*/
public collide(source: GeomSprite): bool {
// Circle vs. Circle
if (this.type == GeomSprite.CIRCLE && source.type == GeomSprite.CIRCLE)
{
return Collision.circleToCircle(this.circle, source.circle).result;
}
// Circle vs. Rect
if (this.type == GeomSprite.CIRCLE && source.type == GeomSprite.RECTANGLE)
{
return Collision.circleToRectangle(this.circle, source.rect).result;
}
// Circle vs. Point
if (this.type == GeomSprite.CIRCLE && source.type == GeomSprite.POINT)
{
return Collision.circleContainsPoint(this.circle, source.point).result;
}
// Circle vs. Line
if (this.type == GeomSprite.CIRCLE && source.type == GeomSprite.LINE)
{
return Collision.lineToCircle(source.line, this.circle).result;
}
// Rect vs. Rect
if (this.type == GeomSprite.RECTANGLE && source.type == GeomSprite.RECTANGLE)
{
return Collision.rectangleToRectangle(this.rect, source.rect).result;
}
// Rect vs. Circle
if (this.type == GeomSprite.RECTANGLE && source.type == GeomSprite.CIRCLE)
{
return Collision.circleToRectangle(source.circle, this.rect).result;
}
// Rect vs. Point
if (this.type == GeomSprite.RECTANGLE && source.type == GeomSprite.POINT)
{
return Collision.pointToRectangle(source.point, this.rect).result;
}
// Rect vs. Line
if (this.type == GeomSprite.RECTANGLE && source.type == GeomSprite.LINE)
{
return Collision.lineToRectangle(source.line, this.rect).result;
}
// Point vs. Point
if (this.type == GeomSprite.POINT && source.type == GeomSprite.POINT)
{
return this.point.equals(source.point);
}
// Point vs. Circle
if (this.type == GeomSprite.POINT && source.type == GeomSprite.CIRCLE)
{
return Collision.circleContainsPoint(source.circle, this.point).result;
}
// Point vs. Rect
if (this.type == GeomSprite.POINT && source.type == GeomSprite.RECTANGLE)
{
return Collision.pointToRectangle(this.point, source.rect).result;
}
// Point vs. Line
if (this.type == GeomSprite.POINT && source.type == GeomSprite.LINE)
{
return source.line.isPointOnLine(this.point.x, this.point.y);
}
// Line vs. Line
if (this.type == GeomSprite.LINE && source.type == GeomSprite.LINE)
{
return Collision.lineSegmentToLineSegment(this.line, source.line).result;
}
// Line vs. Circle
if (this.type == GeomSprite.LINE && source.type == GeomSprite.CIRCLE)
{
return Collision.lineToCircle(this.line, source.circle).result;
}
// Line vs. Rect
if (this.type == GeomSprite.LINE && source.type == GeomSprite.RECTANGLE)
{
return Collision.lineSegmentToRectangle(this.line, source.rect).result;
}
// Line vs. Point
if (this.type == GeomSprite.LINE && source.type == GeomSprite.POINT)
{
return this.line.isPointOnLine(source.point.x, source.point.y);
}
return false;
}
}
}
-355
View File
@@ -1,355 +0,0 @@
/// <reference path="../Game.ts" />
/// <reference path="../AnimationManager.ts" />
/// <reference path="GameObject.ts" />
/// <reference path="../system/Camera.ts" />
/**
* Phaser - Sprite
*
* The Sprite GameObject is an extension of the core GameObject that includes support for animation and dynamic textures.
* It's probably the most used GameObject of all.
*/
module Phaser {
export class OldSprite {
/**
* Sprite constructor
* Create a new <code>Sprite</code>.
*
* @param game {Phaser.Game} Current game instance.
* @param [x] {number} the initial x position of the sprite.
* @param [y] {number} the initial y position of the sprite.
* @param [key] {string} Key of the graphic you want to load for this sprite.
* @param [width] {number} The width of the object.
* @param [height] {number} The height of the object.
*/
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, width?: number = 16, height?: number = 16) {
this.canvas = game.stage.canvas;
this.context = game.stage.context;
this.frameBounds = new Rectangle(x, y, width, height);
this.exists = true;
this.active = true;
this.visible = true;
this.alive = true;
this.isGroup = false;
this.alpha = 1;
this.scale = new MicroPoint(1, 1);
this.last = new MicroPoint(x, y);
this.align = GameObject.ALIGN_TOP_LEFT;
this.mass = 1;
this.elasticity = 0;
this.health = 1;
this.immovable = false;
this.moves = true;
this.worldBounds = null;
this.touching = Collision.NONE;
this.wasTouching = Collision.NONE;
this.allowCollisions = Collision.ANY;
this.velocity = new MicroPoint();
this.acceleration = new MicroPoint();
this.drag = new MicroPoint();
this.maxVelocity = new MicroPoint(10000, 10000);
this.angle = 0;
this.angularVelocity = 0;
this.angularAcceleration = 0;
this.angularDrag = 0;
this.maxAngular = 10000;
this.cameraBlacklist = [];
this.scrollFactor = new MicroPoint(1, 1);
this.collisionMask = new CollisionMask(game, this, x, y, width, height);
this._texture = null;
this.animations = new AnimationManager(this._game, this);
if (key !== null)
{
this.cacheKey = key;
this.loadGraphic(key);
}
else
{
this.frameBounds.width = 16;
this.frameBounds.height = 16;
}
}
/**
* The essential reference to the main game object
*/
public _game: Game;
/**
* Controls whether <code>update()</code> is automatically called by State/Group.
*/
public active: bool;
/**
* Controls whether <code>draw()</code> is automatically called by State/Group.
*/
public visible: bool;
/**
* Setting this to true will prevent the object from being updated during the main game loop (you will have to call update on it yourself)
*/
public ignoreGlobalUpdate: bool;
/**
* Setting this to true will prevent the object from being rendered during the main game loop (you will have to call render on it yourself)
*/
public ignoreGlobalRender: bool;
/**
* An Array of Cameras to which this GameObject won't render
* @type {Array}
*/
public cameraBlacklist: number[];
/**
* Orientation of the object.
* @type {number}
*/
public facing: number;
/**
* Set alpha to a number between 0 and 1 to change the opacity.
* @type {number}
*/
public alpha: number;
/**
* Scale factor of the object.
* @type {MicroPoint}
*/
public scale: MicroPoint;
/**
* Controls if the GameObject is rendered rotated or not.
* If renderRotation is false then the object can still rotate but it will never be rendered rotated.
* @type {boolean}
*/
public renderRotation: bool = true;
/**
* A point that can store numbers from 0 to 1 (for X and Y independently)
* which governs how much this object is affected by the camera .
* @type {MicroPoint}
*/
public scrollFactor: MicroPoint;
/**
* Rectangle container of this object.
* @type {Rectangle}
*/
public frameBounds: Rectangle;
/**
* This objects CollisionMask
* @type {CollisionMask}
*/
public collisionMask: CollisionMask;
/**
* A rectangular area which is object is allowed to exist within. If it travels outside of this area it will perform the outOfBoundsAction.
* @type {Quad}
*/
public worldBounds: Quad;
/**
* A reference to the Canvas this GameObject will render to
* @type {HTMLCanvasElement}
*/
public canvas: HTMLCanvasElement;
/**
* A reference to the Canvas Context2D this GameObject will render to
* @type {CanvasRenderingContext2D}
*/
public context: CanvasRenderingContext2D;
/**
* Texture of this sprite to be rendered.
*/
private _texture;
/**
* Texture of this sprite is DynamicTexture? (default to false)
* @type {boolean}
*/
private _dynamicTexture: bool = false;
/**
* This manages animations of the sprite. You can modify animations though it. (see AnimationManager)
* @type AnimationManager
*/
public animations: AnimationManager;
/**
* The cache key that was used for this texture (if any)
*/
public cacheKey: string;
/**
* Flip the graphic horizontally? (defaults to false)
* @type {boolean}
*/
public flipped: bool = false;
/**
* Pre-update is called right before update() on each object in the game loop.
*/
public preUpdate() {
this.last.x = this.frameBounds.x;
this.last.y = this.frameBounds.y;
this.collisionMask.preUpdate();
}
/**
* Override this function to update your class's position and appearance.
*/
public update() {
}
/**
* Automatically called after update() by the game loop.
*/
public postUpdate() {
this.animations.update();
if (this.moves)
{
this.updateMotion();
}
if (this.worldBounds != null)
{
if (this.outOfBoundsAction == GameObject.OUT_OF_BOUNDS_KILL)
{
if (this.x < this.worldBounds.x || this.x > this.worldBounds.right || this.y < this.worldBounds.y || this.y > this.worldBounds.bottom)
{
this.kill();
}
}
else
{
if (this.x < this.worldBounds.x)
{
this.x = this.worldBounds.x;
}
else if (this.x > this.worldBounds.right)
{
this.x = this.worldBounds.right;
}
if (this.y < this.worldBounds.y)
{
this.y = this.worldBounds.y;
}
else if (this.y > this.worldBounds.bottom)
{
this.y = this.worldBounds.bottom;
}
}
}
this.collisionMask.update();
if (this.inputEnabled)
{
this.updateInput();
}
this.wasTouching = this.touching;
this.touching = Collision.NONE;
}
/**
* Clean up memory.
*/
public destroy() {
}
public set width(value:number) {
this.frameBounds.width = value;
}
public set height(value:number) {
this.frameBounds.height = value;
}
public get width(): number {
return this.frameBounds.width;
}
public get height(): number {
return this.frameBounds.height;
}
public set frame(value: number) {
this.animations.frame = value;
}
public get frame(): number {
return this.animations.frame;
}
public set frameName(value: string) {
this.animations.frameName = value;
}
public get frameName(): string {
return this.animations.frameName;
}
/**
* Handy for "killing" game objects.
* Default behavior is to flag them as nonexistent AND dead.
* However, if you want the "corpse" to remain in the game,
* like to animate an effect or whatever, you should override this,
* setting only alive to false, and leaving exists true.
*/
public kill() {
this.alive = false;
this.exists = false;
}
/**
* Handy for bringing game objects "back to life". Just sets alive and exists back to true.
* In practice, this is most often called by <code>Object.reset()</code>.
*/
public revive() {
this.alive = true;
this.exists = true;
}
/**
* Convert object to readable string name. Useful for debugging, save games, etc.
*/
public toString(): string {
return "";
}
}
}
+14 -14
View File
@@ -51,7 +51,7 @@ module Phaser {
return;
}
this.lifespan -= this._game.time.elapsed;
this.lifespan -= this.game.time.elapsed;
if (this.lifespan <= 0)
{
@@ -59,39 +59,39 @@ module Phaser {
}
//simpler bounce/spin behavior for now
if (this.touching)
if (this.body.touching)
{
if (this.angularVelocity != 0)
if (this.body.angularVelocity != 0)
{
this.angularVelocity = -this.angularVelocity;
this.body.angularVelocity = -this.body.angularVelocity;
}
}
if (this.acceleration.y > 0) //special behavior for particles with gravity
if (this.body.acceleration.y > 0) //special behavior for particles with gravity
{
if (this.touching & Collision.FLOOR)
if (this.body.touching & Types.FLOOR)
{
this.drag.x = this.friction;
this.body.drag.x = this.friction;
if (!(this.wasTouching & Collision.FLOOR))
if (!(this.body.wasTouching & Types.FLOOR))
{
if (this.velocity.y < -this.elasticity * 10)
if (this.body.velocity.y < -this.body.bounce.y * 10)
{
if (this.angularVelocity != 0)
if (this.body.angularVelocity != 0)
{
this.angularVelocity *= -this.elasticity;
this.body.angularVelocity *= -this.body.bounce.y;
}
}
else
{
this.velocity.y = 0;
this.angularVelocity = 0;
this.body.velocity.y = 0;
this.body.angularVelocity = 0;
}
}
}
else
{
this.drag.x = 0;
this.body.drag.x = 0;
}
}
}
+1 -2
View File
@@ -28,11 +28,10 @@ module Phaser {
*/
constructor(game: Game, key:string, x: number = 0, y: number = 0, width?: number = 0, height?: number = 0) {
super(game, x, y, key, width, height);
super(game, x, y, key);
this.type = Phaser.Types.SCROLLZONE;
this.render = game.renderer.renderScrollZone;
this.physics.moves = false;
this.regions = [];
+29 -3
View File
@@ -3,7 +3,6 @@
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../components/animation/AnimationManager.ts" />
/// <reference path="../components/sprite/Texture.ts" />
/// <reference path="../components/sprite/Physics.ts" />
/// <reference path="../physics/Body.ts" />
/**
@@ -24,7 +23,6 @@ module Phaser {
* @param [key] {string} Key of the graphic you want to load for this sprite.
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
*/
//constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, width?: number = 16, height?: number = 16) {
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, bodyType?: number = Phaser.Types.BODY_DISABLED) {
this.game = game;
@@ -46,6 +44,7 @@ module Phaser {
this.animations = new Phaser.Components.AnimationManager(this);
this.texture = new Phaser.Components.Texture(this, key);
this.cameraBlacklist = [];
// Transform related (if we add any more then move to a component)
this.origin = new Phaser.Vec2(0, 0);
@@ -108,6 +107,12 @@ module Phaser {
*/
public animations: Phaser.Components.AnimationManager;
/**
* An Array of Cameras to which this GameObject won't render
* @type {Array}
*/
public cameraBlacklist: number[];
/**
* The frame boundary around this Sprite.
* For non-animated sprites this matches the loaded texture dimensions.
@@ -290,7 +295,7 @@ module Phaser {
*/
if (this.modified == true && this.scale.equals(1) && this.skew.equals(0) && this.rotation == 0 && this.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false)
if (this.modified == true && this.scale.equals(1) && this.skew.equals(0) && this.angle == 0 && this.angleOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false)
{
this.modified = false;
}
@@ -303,6 +308,27 @@ module Phaser {
public destroy() {
}
/**
* Handy for "killing" game objects.
* Default behavior is to flag them as nonexistent AND dead.
* However, if you want the "corpse" to remain in the game,
* like to animate an effect or whatever, you should override this,
* setting only alive to false, and leaving exists true.
*/
public kill() {
this.alive = false;
this.exists = false;
}
/**
* Handy for bringing game objects "back to life". Just sets alive and exists back to true.
* In practice, this is most often called by <code>Object.reset()</code>.
*/
public revive() {
this.alive = true;
this.exists = true;
}
}
}
+61 -13
View File
@@ -27,12 +27,17 @@ module Phaser {
*/
constructor(game: Game, key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0) {
//super(game);
this.game = game;
this.type = Phaser.Types.TILEMAP;
this.isGroup = false;
this.exists = true;
this.active = true;
this.visible = true;
this.alive = true;
this.tiles = [];
this.layers = [];
this.cameraBlacklist = [];
this.mapFormat = format;
@@ -49,18 +54,49 @@ module Phaser {
if (this.currentLayer && resizeWorld)
{
this._game.world.setSize(this.currentLayer.widthInPixels, this.currentLayer.heightInPixels, true);
this.game.world.setSize(this.currentLayer.widthInPixels, this.currentLayer.heightInPixels, true);
}
}
private _tempCollisionData;
/**
* Reference to the main game object
*/
public game: Game;
/**
* The type of game object.
*/
public type: number;
/**
* Controls if both <code>update</code> and render are called by the core game loop.
*/
public exists: bool;
/**
* Controls if <code>update()</code> is automatically called by the core game loop.
*/
public active: bool;
/**
* Controls if this Sprite is rendered or skipped during the core game loop.
*/
public visible: bool;
/**
*
*/
public alive: bool;
/**
* Tilemap data format enum: CSV.
* @type {number}
*/
public static FORMAT_CSV: number = 0;
/**
* Tilemap data format enum: Tiled JSON.
* @type {number}
@@ -72,36 +108,48 @@ module Phaser {
* @type {Tile[]}
*/
public tiles : Tile[];
/**
* Array contains tilemap layer objects of this map.
* @type {TilemapLayer[]}
*/
public layers : TilemapLayer[];
/**
* Current tilemap layer.
* @type {TilemapLayer}
*/
public currentLayer: TilemapLayer;
/**
* The tilemap layer for collision.
* @type {TilemapLayer}
*/
public collisionLayer: TilemapLayer;
/**
* Tilemap collision callback.
* @type {function}
*/
public collisionCallback = null;
/**
* Context for the collision callback called with.
*/
public collisionCallbackContext;
/**
* Format of this tilemap data. Available values: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
* @type {number}
*/
public mapFormat: number;
/**
* An Array of Cameras to which this GameObject won't render
* @type {Array}
*/
public cameraBlacklist: number[];
/**
* Inherited update method.
*/
@@ -136,7 +184,7 @@ module Phaser {
*/
private parseCSV(data: string, key: string, tileWidth: number, tileHeight: number) {
var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight);
var layer: TilemapLayer = new TilemapLayer(this.game, this, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight);
// Trim any rogue whitespace from the data
data = data.trim();
@@ -179,7 +227,7 @@ module Phaser {
for (var i = 0; i < json.layers.length; i++)
{
var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
var layer: TilemapLayer = new TilemapLayer(this.game, this, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
layer.alpha = json.layers[i].opacity;
layer.visible = json.layers[i].visible;
@@ -230,7 +278,7 @@ module Phaser {
for (var i = 0; i < qty; i++)
{
this.tiles.push(new Tile(this._game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight));
this.tiles.push(new Tile(this.game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight));
}
}
@@ -266,7 +314,7 @@ module Phaser {
* @param separateX {boolean} Enable seprate at x-axis.
* @param separateY {boolean} Enable seprate at y-axis.
*/
public setCollisionRange(start: number, end: number, collision?:number = Collision.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
public setCollisionRange(start: number, end: number, collision?:number = Types.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
for (var i = start; i < end; i++)
{
@@ -283,7 +331,7 @@ module Phaser {
* @param separateX {boolean} Enable seprate at x-axis.
* @param separateY {boolean} Enable seprate at y-axis.
*/
public setCollisionByIndex(values:number[], collision?:number = Collision.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
public setCollisionByIndex(values:number[], collision?:number = Types.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
for (var i = 0; i < values.length; i++)
{
@@ -338,7 +386,7 @@ module Phaser {
public getTileFromInputXY(layer?: number = 0):Tile {
return this.tiles[this.layers[layer].getTileFromWorldXY(this._game.input.getWorldX(), this._game.input.getWorldY())];
return this.tiles[this.layers[layer].getTileFromWorldXY(this.game.input.getWorldX(), this.game.input.getWorldY())];
}
@@ -347,7 +395,7 @@ module Phaser {
* @param object {GameObject} Tiles you want to get that overlaps this.
* @return {array} Array with tiles informations. (Each contains x, y and the tile.)
*/
public getTileOverlaps(object: GameObject) {
public getTileOverlaps(object: Sprite) {
return this.currentLayer.getTileOverlaps(object);
@@ -371,7 +419,7 @@ module Phaser {
if (objectOrGroup == null)
{
objectOrGroup = this._game.world.group;
objectOrGroup = this.game.world.group;
}
// Group?
@@ -391,9 +439,9 @@ module Phaser {
* @param object {GameObject} Target object you want to check.
* @return {boolean} Return true if this collides with given object, otherwise return false.
*/
public collideGameObject(object: GameObject): bool {
public collideGameObject(object: Sprite): bool {
if (object !== this && object.immovable == false && object.exists == true && object.allowCollisions != Collision.NONE)
if (object.body.type == Types.BODY_DYNAMIC && object.exists == true && object.body.allowCollisions != Types.NONE)
{
this._tempCollisionData = this.collisionLayer.getTileOverlaps(object);
+56 -73
View File
@@ -12,53 +12,51 @@ module Phaser {
export class GameMath {
constructor(game: Game) {
this._game = game;
this.game = game;
}
private _game: Game;
public game: Game;
public static PI: number = 3.141592653589793; //number pi
public static PI_2: number = 1.5707963267948965; //PI / 2 OR 90 deg
public static PI_4: number = 0.7853981633974483; //PI / 4 OR 45 deg
public static PI_8: number = 0.39269908169872413; //PI / 8 OR 22.5 deg
public static PI_16: number = 0.19634954084936206; //PI / 16 OR 11.25 deg
public static TWO_PI: number = 6.283185307179586; //2 * PI OR 180 deg
public static THREE_PI_2: number = 4.7123889803846895; //3 * PI_2 OR 270 deg
public static E: number = 2.71828182845905; //number e
public static LN10: number = 2.302585092994046; //ln(10)
public static LN2: number = 0.6931471805599453; //ln(2)
public static LOG10E: number = 0.4342944819032518; //logB10(e)
public static LOG2E: number = 1.442695040888963387; //logB2(e)
public static SQRT1_2: number = 0.7071067811865476; //sqrt( 1 / 2 )
public static SQRT2: number = 1.4142135623730951; //sqrt( 2 )
public static DEG_TO_RAD: number = 0.017453292519943294444444444444444; //PI / 180;
public static RAD_TO_DEG: number = 57.295779513082325225835265587527; // 180.0 / PI;
static PI: number = 3.141592653589793; //number pi
static PI_2: number = 1.5707963267948965; //PI / 2 OR 90 deg
static PI_4: number = 0.7853981633974483; //PI / 4 OR 45 deg
static PI_8: number = 0.39269908169872413; //PI / 8 OR 22.5 deg
static PI_16: number = 0.19634954084936206; //PI / 16 OR 11.25 deg
static TWO_PI: number = 6.283185307179586; //2 * PI OR 180 deg
static THREE_PI_2: number = 4.7123889803846895; //3 * PI_2 OR 270 deg
static E: number = 2.71828182845905; //number e
static LN10: number = 2.302585092994046; //ln(10)
static LN2: number = 0.6931471805599453; //ln(2)
static LOG10E: number = 0.4342944819032518; //logB10(e)
static LOG2E: number = 1.442695040888963387; //logB2(e)
static SQRT1_2: number = 0.7071067811865476; //sqrt( 1 / 2 )
static SQRT2: number = 1.4142135623730951; //sqrt( 2 )
static DEG_TO_RAD: number = 0.017453292519943294444444444444444; //PI / 180;
static RAD_TO_DEG: number = 57.295779513082325225835265587527; // 180.0 / PI;
public static B_16: number = 65536;//2^16
public static B_31: number = 2147483648;//2^31
public static B_32: number = 4294967296;//2^32
public static B_48: number = 281474976710656;//2^48
public static B_53: number = 9007199254740992;//2^53 !!NOTE!! largest accurate double floating point whole value
public static B_64: number = 18446744073709551616;//2^64 !!NOTE!! Not accurate see B_53
static B_16: number = 65536;//2^16
static B_31: number = 2147483648;//2^31
static B_32: number = 4294967296;//2^32
static B_48: number = 281474976710656;//2^48
static B_53: number = 9007199254740992;//2^53 !!NOTE!! largest accurate double floating point whole value
static B_64: number = 18446744073709551616;//2^64 !!NOTE!! Not accurate see B_53
public static ONE_THIRD: number = 0.333333333333333333333333333333333; // 1.0/3.0;
public static TWO_THIRDS: number = 0.666666666666666666666666666666666; // 2.0/3.0;
public static ONE_SIXTH: number = 0.166666666666666666666666666666666; // 1.0/6.0;
static ONE_THIRD: number = 0.333333333333333333333333333333333; // 1.0/3.0;
static TWO_THIRDS: number = 0.666666666666666666666666666666666; // 2.0/3.0;
static ONE_SIXTH: number = 0.166666666666666666666666666666666; // 1.0/6.0;
public static COS_PI_3: number = 0.86602540378443864676372317075294;//COS( PI / 3 )
public static SIN_2PI_3: number = 0.03654595;// SIN( 2*PI/3 )
static COS_PI_3: number = 0.86602540378443864676372317075294;//COS( PI / 3 )
static SIN_2PI_3: number = 0.03654595;// SIN( 2*PI/3 )
public static CIRCLE_ALPHA: number = 0.5522847498307933984022516322796; //4*(Math.sqrt(2)-1)/3.0;
static CIRCLE_ALPHA: number = 0.5522847498307933984022516322796; //4*(Math.sqrt(2)-1)/3.0;
public static ON: bool = true;
public static OFF: bool = false;
static ON: bool = true;
static OFF: bool = false;
public static SHORT_EPSILON: number = 0.1;//round integer epsilon
public static PERC_EPSILON: number = 0.001;//percentage epsilon
public static EPSILON: number = 0.0001;//single float average epsilon
public static LONG_EPSILON: number = 0.00000001;//arbitrary 8 digit epsilon
static SHORT_EPSILON: number = 0.1;//round integer epsilon
static PERC_EPSILON: number = 0.001;//percentage epsilon
static EPSILON: number = 0.0001;//single float average epsilon
static LONG_EPSILON: number = 0.00000001;//arbitrary 8 digit epsilon
public cosTable = [];
public sinTable = [];
@@ -712,7 +710,7 @@ module Phaser {
* @method linear
* @param {Any} v
* @param {Any} k
* @static
* @public
*/
public linearInterpolation(v, k) {
@@ -731,7 +729,7 @@ module Phaser {
* @method Bezier
* @param {Any} v
* @param {Any} k
* @static
* @public
*/
public bezierInterpolation(v, k) {
@@ -751,7 +749,7 @@ module Phaser {
* @method CatmullRom
* @param {Any} v
* @param {Any} k
* @static
* @public
*/
public catmullRomInterpolation(v, k) {
@@ -782,7 +780,7 @@ module Phaser {
* @param {Any} p0
* @param {Any} p1
* @param {Any} t
* @static
* @public
*/
public linear(p0, p1, t) {
@@ -794,7 +792,7 @@ module Phaser {
* @method Bernstein
* @param {Any} n
* @param {Any} i
* @static
* @public
*/
public bernstein(n, i) {
@@ -809,7 +807,7 @@ module Phaser {
* @param {Any} p2
* @param {Any} p3
* @param {Any} t
* @static
* @public
*/
public catmullRom(p0, p1, p2, p3, t) {
@@ -975,34 +973,6 @@ module Phaser {
}
/**
* Finds the length of the given vector
*
* @param dx
* @param dy
*
* @return
*/
public vectorLength(dx:number, dy:number):number
{
return Math.sqrt(dx * dx + dy * dy);
}
/**
* Finds the dot product value of two vectors
*
* @param ax Vector X
* @param ay Vector Y
* @param bx Vector X
* @param by Vector Y
*
* @return Dot product
*/
public dotProduct(ax:number, ay:number, bx:number, by:number):number
{
return ax * bx + ay * by;
}
/**
* Shuffles the data in the given array into a new order
* @param array The array to shuffle
@@ -1029,7 +999,7 @@ module Phaser {
* @param {Boolean} round - Round the distance to the nearest integer (default false)
* @return {Number} The distance between this Point object and the destination Point object.
**/
public static distanceBetween(x1: number, y1: number, x2: number, y2: number): number {
public distanceBetween(x1: number, y1: number, x2: number, y2: number): number {
var dx = x1 - x2;
var dy = y1 - y2;
@@ -1038,6 +1008,19 @@ module Phaser {
}
/**
* Finds the length of the given vector
*
* @param dx
* @param dy
*
* @return
*/
public vectorLength(dx:number, dy:number):number
{
return Math.sqrt(dx * dx + dy * dy);
}
/**
* 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
-1
View File
@@ -1,4 +1,3 @@
/// <reference path="../Game.ts" />
/// <reference path="../gameobjects/IGameObject.ts" />
/**
@@ -1,6 +1,6 @@
/// <reference path="../Game.ts" />
/// <reference path="../math/LinkedList.ts" />
/// <reference path="../gameobjects/IGameObject.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="LinkedList.ts" />
/**
* Phaser - QuadTree
@@ -10,7 +10,7 @@
* or the A list against the B list. Handy for different things!
*/
module Phaser.Physics {
module Phaser {
export class QuadTree extends Rectangle {
@@ -27,8 +27,8 @@ module Phaser.Physics {
super(x, y, width, height);
this._headA = this._tailA = new LinkedList();
this._headB = this._tailB = new LinkedList();
this._headA = this._tailA = new Phaser.LinkedList();
this._headB = this._tailB = new Phaser.LinkedList();
//Copy the parent's children (if there are any)
if (parent != null)
@@ -42,7 +42,7 @@ module Phaser.Physics {
if (this._tailA.object != null)
{
this._ot = this._tailA;
this._tailA = new LinkedList();
this._tailA = new Phaser.LinkedList();
this._ot.next = this._tailA;
}
@@ -60,7 +60,7 @@ module Phaser.Physics {
if (this._tailB.object != null)
{
this._ot = this._tailB;
this._tailB = new LinkedList();
this._tailB = new Phaser.LinkedList();
this._ot.next = this._tailB;
}
@@ -93,8 +93,8 @@ module Phaser.Physics {
}
// Reused temporary vars to help avoid gc spikes
private _iterator: LinkedList;
private _ot: LinkedList;
private _iterator: Phaser.LinkedList;
private _ot: Phaser.LinkedList;
private _i;
private _basic;
private _members;
@@ -126,25 +126,25 @@ module Phaser.Physics {
* Refers to the internal A and B linked lists,
* which are used to store objects in the leaves.
*/
private _headA: LinkedList;
private _headA: Phaser.LinkedList;
/**
* Refers to the internal A and B linked lists,
* which are used to store objects in the leaves.
*/
private _tailA: LinkedList;
private _tailA: Phaser.LinkedList;
/**
* Refers to the internal A and B linked lists,
* which are used to store objects in the leaves.
*/
private _headB: LinkedList;
private _headB: Phaser.LinkedList;
/**
* Refers to the internal A and B linked lists,
* which are used to store objects in the leaves.
*/
private _tailB: LinkedList;
private _tailB: Phaser.LinkedList;
/**
* Internal, governs and assists with the formation of the tree.
@@ -244,7 +244,7 @@ module Phaser.Physics {
/**
* Internal, used during tree processing and overlap checks.
*/
private static _iterator: LinkedList;
private static _iterator: Phaser.LinkedList;
/**
* Clean up memory.
-208
View File
@@ -1,208 +0,0 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../math/Vec2Utils.ts" />
/// <reference path="PhysicsManager.ts" />
/// <reference path="IPhysicsShape.ts" />
/**
* Phaser - Physics - AABB
*/
module Phaser.Physics {
export class AABB implements IPhysicsShape {
constructor(game: Game, sprite: Sprite, x: number, y: number, width: number, height: number) {
this.game = game;
this.world = game.world.physics;
if (sprite !== null)
{
this.sprite = sprite;
this.scale = Vec2Utils.clone(this.sprite.scale);
}
else
{
this.sprite = null;
this.physics = null;
this.scale = new Vec2(1, 1);
}
this.bounds = new Rectangle(x + Math.round(width / 2), y + Math.round(height / 2), width, height);
this.position = new Vec2(x + this.bounds.halfWidth, y + this.bounds.halfHeight);
this.oldPosition = new Vec2(x + this.bounds.halfWidth, y + this.bounds.halfHeight);
this.offset = new Vec2(0, 0);
}
public game: Game;
public world: PhysicsManager;
public sprite: Sprite;
public physics: Phaser.Components.Physics;
public position: Vec2;
public oldPosition: Vec2;
public offset: Vec2;
public scale: Vec2;
public bounds: Rectangle;
public preUpdate() {
this.oldPosition.copyFrom(this.position);
this.bounds.x = this.position.x - this.bounds.halfWidth;
this.bounds.y = this.position.y - this.bounds.halfHeight;
if (this.sprite)
{
this.position.setTo((this.sprite.x + this.bounds.halfWidth) + this.offset.x, (this.sprite.y + this.bounds.halfHeight) + this.offset.y);
// Update scale / dimensions
if (Vec2Utils.equals(this.scale, this.sprite.scale) == false)
{
this.scale.copyFrom(this.sprite.scale);
this.bounds.width = this.sprite.width;
this.bounds.height = this.sprite.height;
}
}
}
public update() {
//this.bounds.x = this.position.x;
//this.bounds.y = this.position.y;
}
public setSize(width: number, height: number) {
this.bounds.width = width;
this.bounds.height = height;
}
public render(context:CanvasRenderingContext2D) {
context.beginPath();
context.strokeStyle = 'rgb(0,255,0)';
context.strokeRect(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight, this.bounds.width, this.bounds.height);
context.stroke();
context.closePath();
// center point
context.fillStyle = 'rgb(0,255,0)';
context.fillRect(this.position.x, this.position.y, 2, 2);
if (this.physics.touching & Phaser.Types.LEFT)
{
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.lineTo(this.position.x - this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.stroke();
context.closePath();
}
if (this.physics.touching & Phaser.Types.RIGHT)
{
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x + this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.stroke();
context.closePath();
}
if (this.physics.touching & Phaser.Types.UP)
{
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.stroke();
context.closePath();
}
if (this.physics.touching & Phaser.Types.DOWN)
{
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.stroke();
context.closePath();
}
}
public get hullWidth(): number {
if (this.deltaX > 0)
{
return this.bounds.width + this.deltaX;
}
else
{
return this.bounds.width - this.deltaX;
}
}
public get hullHeight(): number {
if (this.deltaY > 0)
{
return this.bounds.height + this.deltaY;
}
else
{
return this.bounds.height - this.deltaY;
}
}
public get hullX(): number {
if (this.position.x < this.oldPosition.x)
{
return this.position.x;
}
else
{
return this.oldPosition.x;
}
}
public get hullY(): number {
if (this.position.y < this.oldPosition.y)
{
return this.position.y;
}
else
{
return this.oldPosition.y;
}
}
public get deltaXAbs(): number {
return (this.deltaX > 0 ? this.deltaX : -this.deltaX);
}
public get deltaYAbs(): number {
return (this.deltaY > 0 ? this.deltaY : -this.deltaY);
}
public get deltaX(): number {
return this.position.x - this.oldPosition.x;
}
public get deltaY(): number {
return this.position.y - this.oldPosition.y;
}
}
}
+1 -4
View File
@@ -1,9 +1,6 @@
/// <reference path="../core/Vec2.ts" />
/// <reference path="../core/Point.ts" />
/// <reference path="../math/Vec2Utils.ts" />
/// <reference path="../physics/AABB.ts" />
/// <reference path="../physics/Circle.ts" />
/// <reference path="../physics/IPhysicsBody.ts" />
/**
* Phaser - Physics - Body
@@ -273,7 +270,7 @@ module Phaser.Physics {
this.parent.texture.context.fillStyle = color;
this.parent.texture.context.fillText('Sprite: (' + this.parent.frameBounds.width + ' x ' + this.parent.frameBounds.height + ')', x, y);
//this.parent.texture.context.fillText('x: ' + this._parent.frameBounds.x.toFixed(1) + ' y: ' + this._parent.frameBounds.y.toFixed(1) + ' rotation: ' + this._parent.rotation.toFixed(1), x, y + 14);
this.parent.texture.context.fillText('x: ' + this.shape.bounds.x.toFixed(1) + ' y: ' + this.shape.bounds.y.toFixed(1) + ' rotation: ' + this._parent.rotation.toFixed(1), x, y + 14);
this.parent.texture.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' angle: ' + this.angle.toFixed(1), x, y + 14);
this.parent.texture.context.fillText('vx: ' + this.velocity.x.toFixed(1) + ' vy: ' + this.velocity.y.toFixed(1), x, y + 28);
this.parent.texture.context.fillText('ax: ' + this.acceleration.x.toFixed(1) + ' ay: ' + this.acceleration.y.toFixed(1), x, y + 42);
-216
View File
@@ -1,216 +0,0 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../math/Vec2Utils.ts" />
/// <reference path="PhysicsManager.ts" />
/// <reference path="IPhysicsShape.ts" />
/**
* Phaser - Physics - Circle
*/
module Phaser.Physics {
export class Circle implements IPhysicsShape {
constructor(game: Game, sprite: Sprite, x: number, y: number, diameter: number) {
this.game = game;
this.world = game.world.physics;
if (sprite !== null)
{
this.sprite = sprite;
this.scale = Vec2Utils.clone(this.sprite.scale);
}
else
{
this.sprite = null;
this.physics = null;
this.scale = new Vec2(1, 1);
}
this.diameter = diameter;
this.radius = diameter / 2;
this.bounds = new Rectangle(x + Math.round(diameter / 2), y + Math.round(diameter / 2), diameter, diameter);
this.position = new Vec2(x + this.bounds.halfWidth, y + this.bounds.halfHeight);
this.oldPosition = new Vec2(x + this.bounds.halfWidth, y + this.bounds.halfHeight);
this.offset = new Vec2(0, 0);
}
public game: Game;
public world: PhysicsManager;
public sprite: Sprite;
public physics: Phaser.Components.Physics;
public position: Vec2;
public oldPosition: Vec2;
public offset: Vec2;
public scale: Vec2;
public bounds: Rectangle;
public radius: number;
public diameter: number;
public preUpdate() {
this.oldPosition.copyFrom(this.position);
this.bounds.x = this.position.x - this.bounds.halfWidth;
this.bounds.y = this.position.y - this.bounds.halfHeight;
if (this.sprite)
{
this.position.setTo((this.sprite.x + this.bounds.halfWidth) + this.offset.x, (this.sprite.y + this.bounds.halfHeight) + this.offset.y);
// Update scale / dimensions
if (Vec2Utils.equals(this.scale, this.sprite.scale) == false)
{
this.scale.copyFrom(this.sprite.scale);
// needs to be radius based (+ square)
//this.bounds.width = this.sprite.width;
//this.bounds.height = this.sprite.height;
}
}
}
public update() {
//this.bounds.x = this.position.x;
//this.bounds.y = this.position.y;
}
public setSize(width: number, height: number) {
this.bounds.width = width;
this.bounds.height = height;
}
public render(context:CanvasRenderingContext2D) {
// center point
context.fillStyle = 'rgba(255,0,0,0.5)';
context.arc(this.position.x, this.position.y, this.radius, 0, Math.PI * 2);
context.rect(this.position.x, this.position.y, 2, 2);
context.fill();
/*
if (this.oH == 1)
{
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.lineTo(this.position.x - this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.stroke();
context.closePath();
}
else if (this.oH == -1)
{
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x + this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.stroke();
context.closePath();
}
if (this.oV == 1)
{
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.stroke();
context.closePath();
}
else if (this.oV == -1)
{
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.stroke();
context.closePath();
}
*/
}
public get hullWidth(): number {
if (this.deltaX > 0)
{
//return this.bounds.width + this.deltaX;
return this.diameter + this.deltaX;
}
else
{
//return this.bounds.width - this.deltaX;
return this.diameter - this.deltaX;
}
}
public get hullHeight(): number {
if (this.deltaY > 0)
{
//return this.bounds.height + this.deltaY;
return this.diameter + this.deltaY;
}
else
{
//return this.bounds.height - this.deltaY;
return this.diameter - this.deltaY;
}
}
public get hullX(): number {
if (this.position.x < this.oldPosition.x)
{
return this.position.x;
}
else
{
return this.oldPosition.x;
}
}
public get hullY(): number {
if (this.position.y < this.oldPosition.y)
{
return this.position.y;
}
else
{
return this.oldPosition.y;
}
}
public get deltaXAbs(): number {
return (this.deltaX > 0 ? this.deltaX : -this.deltaX);
}
public get deltaYAbs(): number {
return (this.deltaY > 0 ? this.deltaY : -this.deltaY);
}
public get deltaX(): number {
return this.position.x - this.oldPosition.x;
}
public get deltaY(): number {
return this.position.y - this.oldPosition.y;
}
}
}
-31
View File
@@ -1,31 +0,0 @@
/// <reference path="../core/Vec2.ts" />
/// <reference path="../core/Point.ts" />
/// <reference path="../math/Vec2Utils.ts" />
/// <reference path="../physics/AABB.ts" />
/// <reference path="../physics/Circle.ts" />
/// <reference path="../physics/IPhysicsBody.ts" />
/**
* Phaser - Physics - Fixture
*/
module Phaser.Physics {
export class Fixture {
constructor(parent: Sprite, type: number) {
this.parent = parent;
// these are shape properties really
this.bounce = Vec2Utils.clone(this.game.world.physics.bounce);
this.friction = Vec2Utils.clone(this.game.world.physics.friction);
}
public game: Game;
public parent: Sprite;
}
}
-40
View File
@@ -1,40 +0,0 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="PhysicsManager.ts" />
/**
* Phaser - Physics - IPhysicsShape
*/
module Phaser.Physics {
export interface IPhysicsBody {
//game: Game;
//world: PhysicsManager;
//sprite: Sprite;
//physics: Phaser.Components.Physics;
//position: Vec2;
//oldPosition: Vec2;
//offset: Vec2;
//bounds: Rectangle;
//setSize(width: number, height: number);
//preUpdate();
//update();
//render(context:CanvasRenderingContext2D);
//hullX;
//hullY;
//hullWidth;
//hullHeight;
//deltaX;
//deltaY;
//deltaXAbs;
//deltaYAbs;
}
}
-42
View File
@@ -1,42 +0,0 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="PhysicsManager.ts" />
/**
* Phaser - Physics - IPhysicsShape
*/
module Phaser.Physics {
export interface IPhysicsShape {
game: Game;
world: PhysicsManager;
sprite: Sprite;
physics: Phaser.Components.Physics;
position: Vec2;
oldPosition: Vec2;
offset: Vec2;
bounds: Rectangle;
//oH: number;
//oV: number;
setSize(width: number, height: number);
preUpdate();
update();
render(context:CanvasRenderingContext2D);
hullX;
hullY;
hullWidth;
hullHeight;
deltaX;
deltaY;
deltaXAbs;
deltaYAbs;
}
}
+379 -104
View File
@@ -2,7 +2,7 @@
/// <reference path="../utils/RectangleUtils.ts" />
/// <reference path="../utils/CircleUtils.ts" />
/// <reference path="Body.ts" />
/// <reference path="QuadTree.ts" />
/// <reference path="../math/QuadTree.ts" />
/**
* Phaser - PhysicsManager
@@ -72,37 +72,25 @@ module Phaser.Physics {
public bounce: Vec2;
public angularDrag: number;
/**
* The overlap bias is used when calculating hull overlap before separation - change it if you have especially small or large GameObjects
* @type {number}
*/
static OVERLAP_BIAS: number = 4;
/**
* The overlap bias is used when calculating hull overlap before separation - change it if you have especially small or large GameObjects
* @type {number}
*/
static TILE_OVERLAP: bool = false;
/**
* @type {number}
*/
public worldDivisions: number = 6;
// Add some sanity checks here + remove method, etc
/*
public add(shape: IPhysicsShape): IPhysicsShape {
this._objects.push(shape);
return shape;
}
public remove(shape: IPhysicsShape) {
this._length = this._objects.length;
for (var i = 0; i < this._length; i++)
{
if (this._objects[i] === shape)
{
this._objects[i] = null;
}
}
}
public update() {
this._length = this._objects.length;
@@ -222,74 +210,6 @@ module Phaser.Physics {
}
private collideShapes(shapeA: IPhysicsShape, shapeB: IPhysicsShape) {
if (shapeA.physics.immovable && shapeB.physics.immovable)
{
return;
}
this._distance.setTo(0, 0);
this._tangent.setTo(0, 0);
// Simple bounds check first
if (RectangleUtils.intersects(shapeA.bounds, shapeB.bounds))
{
// Collide on the x-axis
if (shapeA.physics.velocity.x > 0 && shapeA.bounds.right > shapeB.bounds.x && shapeA.bounds.right <= shapeB.bounds.right)
{
// The right side of ShapeA hit the left side of ShapeB
this._distance.x = shapeB.bounds.x - shapeA.bounds.right;
if (this._distance.x != 0)
{
this._tangent.x = -1;
}
}
else if (shapeA.physics.velocity.x < 0 && shapeA.bounds.x < shapeB.bounds.right && shapeA.bounds.x >= shapeB.bounds.x)
{
// The left side of ShapeA hit the right side of ShapeB
this._distance.x = shapeB.bounds.right - shapeA.bounds.x;
if (this._distance.x != 0)
{
this._tangent.x = 1;
}
}
// Collide on the y-axis
if (shapeA.physics.velocity.y < 0 && shapeA.bounds.y < shapeB.bounds.bottom && shapeA.bounds.y > shapeB.bounds.y)
{
console.log('top A -> bot B');
// The top of ShapeA hit the bottom of ShapeB
this._distance.y = shapeB.bounds.bottom - shapeA.bounds.y;
console.log(shapeA.bounds, shapeB.bounds, this._distance.y);
if (this._distance.y != 0)
{
this._tangent.y = 1;
}
}
else if (shapeA.physics.velocity.y > 0 && shapeA.bounds.bottom > shapeB.bounds.y && shapeA.bounds.bottom < shapeB.bounds.bottom)
{
// The bottom of ShapeA hit the top of ShapeB
this._distance.y = shapeB.bounds.y - shapeA.bounds.bottom;
if (this._distance.y != 0)
{
this._tangent.y = -1;
}
}
// Separate
if (this._distance.equals(0) == false)
{
//this.separate(shapeA, shapeB, this._distance, this._tangent);
}
}
}
/**
* The core Collision separation method.
* @param body1 The first Physics.Body to separate
@@ -305,18 +225,18 @@ module Phaser.Physics {
}
private checkHullIntersection(shape1:IPhysicsShape, shape2:IPhysicsShape): bool {
private checkHullIntersection(body1: Body, body2:Body): bool {
//if ((shape1.hullX + shape1.hullWidth > shape2.hullX) && (shape1.hullX < shape2.hullX + shape2.bounds.width) && (shape1.hullY + shape1.hullHeight > shape2.hullY) && (shape1.hullY < shape2.hullY + shape2.hullHeight))
// maybe not bounds.width?
if ((shape1.hullX + shape1.hullWidth > shape2.hullX) && (shape1.hullX < shape2.hullX + shape2.hullWidth) && (shape1.hullY + shape1.hullHeight > shape2.hullY) && (shape1.hullY < shape2.hullY + shape2.hullHeight))
{
return true;
}
else
{
return false;
}
return ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight));
//if ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight))
//{
// return true;
//}
//else
//{
// return false;
//}
}
@@ -547,8 +467,8 @@ module Phaser.Physics {
private OLDseparate(shapeA: IPhysicsShape, shapeB: IPhysicsShape, distance: Vec2, tangent: Vec2) {
/*
private TILEseparate(shapeA: IPhysicsShape, shapeB: IPhysicsShape, distance: Vec2, tangent: Vec2) {
if (tangent.x == 1)
{
@@ -807,6 +727,7 @@ module Phaser.Physics {
shapeA.position.y += distance.y;
}
*/
/**
* Checks for overlaps between two objects using the world QuadTree. Can be Sprite vs. Sprite, Sprite vs. Group or Group vs. Group.
@@ -846,6 +767,360 @@ module Phaser.Physics {
}
/**
* Collision resolution specifically for GameObjects vs. Tiles.
* @param object The GameObject to separate
* @param tile The Tile to separate
* @returns {boolean} Whether the objects in fact touched and were separated
*/
public separateTile(object:Sprite, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool, collideUp: bool, collideDown: bool, separateX: bool, separateY: bool): bool {
//var separatedX: bool = this.separateTileX(object, x, y, width, height, mass, collideLeft, collideRight, separateX);
//var separatedY: bool = this.separateTileY(object, x, y, width, height, mass, collideUp, collideDown, separateY);
//return separatedX || separatedY;
return false;
}
/**
* 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 separateTileX(object:Sprite, 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;
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: Rectangle = new Rectangle(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))
{
var maxOverlap: number = objDeltaAbs + Collision.OVERLAP_BIAS;
// If they did overlap (and can), figure out by how much and flip the corresponding flags
if (objDelta > 0)
{
overlap = object.x + object.width - x;
if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.RIGHT) || collideLeft == false)
{
overlap = 0;
}
else
{
object.touching |= Collision.RIGHT;
}
}
else if (objDelta < 0)
{
overlap = object.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)
{
//console.log('
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 separateTileY(object: Sprite, 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 (objDelta != 0)
{
// Check if the Y hulls actually overlap
var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta;
var objBounds: Rectangle = new Rectangle(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))
{
var maxOverlap: number = objDeltaAbs + Collision.OVERLAP_BIAS;
// If they did overlap (and can), figure out by how much and flip the corresponding flags
if (objDelta > 0)
{
overlap = object.y + object.height - y;
if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.DOWN) || collideUp == false)
{
overlap = 0;
}
else
{
object.touching |= Collision.DOWN;
}
}
else if (objDelta < 0)
{
overlap = object.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 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:Sprite, 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: Rectangle = new Rectangle(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 NEWseparateTileY(object: Sprite, 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: Rectangle = new Rectangle(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;
}
}
*/
}
}
+18 -84
View File
@@ -8,69 +8,13 @@
* Phaser - SpriteUtils
*
* A collection of methods useful for manipulating and checking Sprites.
*
* TODO:
*/
module Phaser {
export class SpriteUtils {
/**
* Pivot position enum: at the top-left corner.
* @type {number}
*/
static ALIGN_TOP_LEFT: number = 0;
/**
* Pivot position enum: at the top-center corner.
* @type {number}
*/
static ALIGN_TOP_CENTER: number = 1;
/**
* Pivot position enum: at the top-right corner.
* @type {number}
*/
static ALIGN_TOP_RIGHT: number = 2;
/**
* Pivot position enum: at the center-left corner.
* @type {number}
*/
static ALIGN_CENTER_LEFT: number = 3;
/**
* Pivot position enum: at the center corner.
* @type {number}
*/
static ALIGN_CENTER: number = 4;
/**
* Pivot position enum: at the center-right corner.
* @type {number}
*/
static ALIGN_CENTER_RIGHT: number = 5;
/**
* Pivot position enum: at the bottom-left corner.
* @type {number}
*/
static ALIGN_BOTTOM_LEFT: number = 6;
/**
* Pivot position enum: at the bottom-center corner.
* @type {number}
*/
static ALIGN_BOTTOM_CENTER: number = 7;
/**
* Pivot position enum: at the bottom-right corner.
* @type {number}
*/
static ALIGN_BOTTOM_RIGHT: number = 8;
static _tempPoint: Point;
static getAsPoints(sprite: Sprite): Phaser.Point[] {
@@ -240,20 +184,18 @@ module Phaser {
*
* @return {boolean} Whether the object is on screen or not.
*/
/*
static onScreen(camera: Camera = null): bool {
static onScreen(sprite: Sprite, camera: Camera = null): bool {
if (camera == null)
{
camera = this._game.camera;
camera = sprite.game.camera;
}
this.getScreenXY(this._point, camera);
SpriteUtils.getScreenXY(sprite, SpriteUtils._tempPoint, camera);
return (this._point.x + this.width > 0) && (this._point.x < camera.width) && (this._point.y + this.height > 0) && (this._point.y < camera.height);
return (SpriteUtils._tempPoint.x + sprite.width > 0) && (SpriteUtils._tempPoint.x < camera.width) && (SpriteUtils._tempPoint.y + sprite.height > 0) && (SpriteUtils._tempPoint.y < camera.height);
}
*/
/**
* Call this to figure out the on-screen position of the object.
@@ -261,14 +203,13 @@ module Phaser {
* @param point {Point} Takes a <code>MicroPoint</code> object and assigns the post-scrolled X and Y values of this object to it.
* @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
*
* @return {MicroPoint} The <code>MicroPoint</code> you passed in, or a new <code>Point</code> if you didn't pass one, containing the screen X and Y position of this object.
* @return {Point} The <code>Point</code> you passed in, or a new <code>Point</code> if you didn't pass one, containing the screen X and Y position of this object.
*/
/*
static getScreenXY(point: MicroPoint = null, camera: Camera = null): MicroPoint {
static getScreenXY(sprite: Sprite, point: Point = null, camera: Camera = null): Point {
if (point == null)
{
point = new MicroPoint();
point = new Point();
}
if (camera == null)
@@ -276,15 +217,14 @@ module Phaser {
camera = this._game.camera;
}
point.x = this.x - camera.scroll.x * this.scrollFactor.x;
point.y = this.y - camera.scroll.y * this.scrollFactor.y;
point.x = sprite.x - camera.scroll.x * sprite.scrollFactor.x;
point.y = sprite.y - camera.scroll.y * sprite.scrollFactor.y;
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
return point;
}
*/
/**
* Set the world bounds that this GameObject can exist within based on the size of the current game world.
@@ -305,7 +245,6 @@ module Phaser {
* @param camera {Rectangle} The rectangle you want to check.
* @return {boolean} Return true if bounds of this sprite intersects the given rectangle, otherwise return false.
*/
/*
static inCamera(camera: Rectangle, cameraOffsetX: number, cameraOffsetY: number): bool {
// Object fixed in place regardless of the camera scrolling? Then it's always visible
@@ -322,7 +261,6 @@ module Phaser {
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
}
*/
/**
* Handy for reviving game objects.
@@ -331,21 +269,17 @@ module Phaser {
* @param x {number} The new X position of this object.
* @param y {number} The new Y position of this object.
*/
/*
static reset(x: number, y: number) {
static reset(sprite: Sprite, x: number, y: number) {
this.revive();
this.touching = Collision.NONE;
this.wasTouching = Collision.NONE;
this.x = x;
this.y = y;
this.last.x = x;
this.last.y = y;
this.velocity.x = 0;
this.velocity.y = 0;
sprite.revive();
sprite.body.touching = Types.NONE;
sprite.body.wasTouching = Types.NONE;
sprite.x = x;
sprite.y = y;
sprite.body.velocity.x = 0;
sprite.body.velocity.y = 0;
}
*/
/**
* Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
+3 -9
View File
@@ -74,18 +74,10 @@
<TypeScriptCompile Include="scrollzones\region demo.ts" />
<TypeScriptCompile Include="scrollzones\parallax.ts" />
<TypeScriptCompile Include="scrollzones\ballscroller.ts" />
<TypeScriptCompile Include="physics\circle 1.ts" />
<TypeScriptCompile Include="physics\aabb vs aabb 1.ts" />
<Content Include="physics\aabb vs aabb 1.js">
<DependentUpon>aabb vs aabb 1.ts</DependentUpon>
</Content>
<Content Include="physics\circle 1.js">
<DependentUpon>circle 1.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="physics\test 1.ts" />
<Content Include="physics\test 1.js">
<DependentUpon>test 1.ts</DependentUpon>
</Content>
<Content Include="scrollzones\ballscroller.js">
<DependentUpon>ballscroller.ts</DependentUpon>
</Content>
@@ -166,6 +158,8 @@
<DependentUpon>boot screen.ts</DependentUpon>
</Content>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="particles\" />
</ItemGroup>
<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
</Project>
+5820 -4048
View File
File diff suppressed because it is too large Load Diff
+9 -9
View File
@@ -14,24 +14,24 @@
//atari.physics.shape.setSize(150, 50);
//atari.physics.shape.offset.setTo(50, 25);
//atari.physics.gravity.setTo(0, 2);
atari.physics.bounce.setTo(0.7, 0.7);
atari.physics.drag.setTo(10, 10);
atari.body.bounce.setTo(0.7, 0.7);
atari.body.drag.setTo(10, 10);
}
function update() {
atari.physics.acceleration.x = 0;
atari.physics.acceleration.y = 0;
atari.body.acceleration.x = 0;
atari.body.acceleration.y = 0;
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
atari.physics.acceleration.x = -150;
atari.body.acceleration.x = -150;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
atari.physics.acceleration.x = 150;
atari.body.acceleration.x = 150;
}
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
atari.physics.acceleration.y = -150;
atari.body.acceleration.y = -150;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
atari.physics.acceleration.y = 150;
atari.body.acceleration.y = 150;
}
}
function render() {
atari.physics.renderDebugInfo(16, 16);
atari.body.renderDebugInfo(16, 16);
}
})();
+9 -9
View File
@@ -24,39 +24,39 @@
//atari.physics.shape.offset.setTo(50, 25);
//atari.physics.gravity.setTo(0, 2);
atari.physics.bounce.setTo(0.7, 0.7);
atari.physics.drag.setTo(10, 10);
atari.body.bounce.setTo(0.7, 0.7);
atari.body.drag.setTo(10, 10);
}
function update() {
atari.physics.acceleration.x = 0;
atari.physics.acceleration.y = 0;
atari.body.acceleration.x = 0;
atari.body.acceleration.y = 0;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
atari.physics.acceleration.x = -150;
atari.body.acceleration.x = -150;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
atari.physics.acceleration.x = 150;
atari.body.acceleration.x = 150;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
atari.physics.acceleration.y = -150;
atari.body.acceleration.y = -150;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
atari.physics.acceleration.y = 150;
atari.body.acceleration.y = 150;
}
}
function render() {
atari.physics.renderDebugInfo(16, 16);
atari.body.renderDebugInfo(16, 16);
}
+16 -16
View File
@@ -14,34 +14,34 @@
//atari = game.add.sprite(350, 500, 'atari');
atari = game.add.sprite(0, 310, 'atari');
card = game.add.sprite(400, 300, 'card');
//card.physics.immovable = true;
//card.body.immovable = true;
//atari.texture.alpha = 0.5;
//atari.scale.setTo(1.5, 1.5);
atari.physics.shape.setSize(150, 50);
atari.physics.shape.offset.setTo(50, 25);
//atari.physics.gravity.setTo(0, 2);
atari.physics.bounce.setTo(1, 1);
//atari.physics.drag.setTo(10, 10);
card.physics.bounce.setTo(0.7, 0.7);
//card.physics.velocity.x = -50;
//atari.body.shape.setSize(150, 50);
//atari.body.shape.offset.setTo(50, 25);
//atari.body.gravity.setTo(0, 2);
atari.body.bounce.setTo(1, 1);
//atari.body.drag.setTo(10, 10);
card.body.bounce.setTo(0.7, 0.7);
//card.body.velocity.x = -50;
}
function update() {
atari.physics.acceleration.x = 0;
atari.physics.acceleration.y = 0;
atari.body.acceleration.x = 0;
atari.body.acceleration.y = 0;
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
atari.physics.acceleration.x = -150;
atari.body.acceleration.x = -150;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
atari.physics.acceleration.x = 150;
atari.body.acceleration.x = 150;
}
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
atari.physics.acceleration.y = -150;
atari.body.acceleration.y = -150;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
atari.physics.acceleration.y = 150;
atari.body.acceleration.y = 150;
}
// collide?
}
function render() {
atari.physics.renderDebugInfo(16, 16);
card.physics.renderDebugInfo(200, 16);
atari.body.renderDebugInfo(16, 16);
card.body.renderDebugInfo(200, 16);
}
})();
+16 -16
View File
@@ -23,44 +23,44 @@
atari = game.add.sprite(0, 310, 'atari');
card = game.add.sprite(400, 300, 'card');
//card.physics.immovable = true;
//card.body.immovable = true;
//atari.texture.alpha = 0.5;
//atari.scale.setTo(1.5, 1.5);
atari.physics.shape.setSize(150, 50);
atari.physics.shape.offset.setTo(50, 25);
//atari.body.shape.setSize(150, 50);
//atari.body.shape.offset.setTo(50, 25);
//atari.physics.gravity.setTo(0, 2);
atari.physics.bounce.setTo(1, 1);
//atari.physics.drag.setTo(10, 10);
//atari.body.gravity.setTo(0, 2);
atari.body.bounce.setTo(1, 1);
//atari.body.drag.setTo(10, 10);
card.physics.bounce.setTo(0.7, 0.7);
//card.physics.velocity.x = -50;
card.body.bounce.setTo(0.7, 0.7);
//card.body.velocity.x = -50;
}
function update() {
atari.physics.acceleration.x = 0;
atari.physics.acceleration.y = 0;
atari.body.acceleration.x = 0;
atari.body.acceleration.y = 0;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
atari.physics.acceleration.x = -150;
atari.body.acceleration.x = -150;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
atari.physics.acceleration.x = 150;
atari.body.acceleration.x = 150;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
atari.physics.acceleration.y = -150;
atari.body.acceleration.y = -150;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
atari.physics.acceleration.y = 150;
atari.body.acceleration.y = 150;
}
// collide?
@@ -69,8 +69,8 @@
function render() {
atari.physics.renderDebugInfo(16, 16);
card.physics.renderDebugInfo(200, 16);
atari.body.renderDebugInfo(16, 16);
card.body.renderDebugInfo(200, 16);
}
-42
View File
@@ -1,42 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.loader.addImageFile('atari', 'assets/sprites/mushroom2.png');
game.loader.addImageFile('card', 'assets/sprites/mana_card.png');
game.loader.load();
}
var atari;
var card;
function create() {
atari = game.add.sprite(200, 300, 'atari');
card = game.add.sprite(400, 300, 'card');
//atari.texture.alpha = 0.5;
//atari.scale.setTo(1.5, 1.5);
atari.physics.setCircle(100);
//atari.physics.shape.setSize(150, 50);
//atari.physics.shape.offset.setTo(7, 5);
//atari.physics.gravity.setTo(0, 2);
atari.physics.bounce.setTo(0.7, 0.7);
//atari.physics.drag.setTo(10, 10);
card.physics.bounce.setTo(0.7, 0.7);
}
function update() {
atari.physics.acceleration.x = 0;
atari.physics.acceleration.y = 0;
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
atari.physics.acceleration.x = -150;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
atari.physics.acceleration.x = 150;
}
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
atari.physics.acceleration.y = -150;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
atari.physics.acceleration.y = 150;
}
}
function render() {
atari.physics.renderDebugInfo(16, 16);
}
})();
-70
View File
@@ -1,70 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.loader.addImageFile('atari', 'assets/sprites/mushroom2.png');
game.loader.addImageFile('card', 'assets/sprites/mana_card.png');
game.loader.load();
}
var atari: Phaser.Sprite;
var card: Phaser.Sprite;
function create() {
atari = game.add.sprite(200, 300, 'atari');
card = game.add.sprite(400, 300, 'card');
//atari.texture.alpha = 0.5;
//atari.scale.setTo(1.5, 1.5);
atari.physics.setCircle(100);
//atari.physics.shape.setSize(150, 50);
//atari.physics.shape.offset.setTo(7, 5);
//atari.physics.gravity.setTo(0, 2);
atari.physics.bounce.setTo(0.7, 0.7);
//atari.physics.drag.setTo(10, 10);
card.physics.bounce.setTo(0.7, 0.7);
}
function update() {
atari.physics.acceleration.x = 0;
atari.physics.acceleration.y = 0;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
atari.physics.acceleration.x = -150;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
atari.physics.acceleration.x = 150;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
atari.physics.acceleration.y = -150;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
atari.physics.acceleration.y = 150;
}
}
function render() {
atari.physics.renderDebugInfo(16, 16);
}
})();
-42
View File
@@ -1,42 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
/// <reference path="../../Phaser/core/Polygon.ts" />
/// <reference path="../../Phaser/utils/SpriteUtils.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.loader.addImageFile('atari', 'assets/sprites/atari800xl.png');
game.loader.load();
}
var atari;
var p;
var atari2;
var p2;
function create() {
atari = game.add.sprite(200, 300, 'atari');
atari.texture.alpha = 0.2;
atari2 = game.add.sprite(500, 300, 'atari');
atari2.texture.alpha = 0.2;
p = new Phaser.Polygon(game, Phaser.SpriteUtils.getAsPoints(atari));
p2 = new Phaser.Polygon(game, Phaser.SpriteUtils.getAsPoints(atari2));
}
function update() {
atari.physics.acceleration.x = 0;
atari.physics.acceleration.y = 0;
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
atari.physics.acceleration.x = -150;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
atari.physics.acceleration.x = 150;
}
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
atari.physics.acceleration.y = -150;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
atari.physics.acceleration.y = 150;
}
}
function render() {
atari.physics.renderDebugInfo(16, 16);
p.render();
p2.render();
}
})();
-70
View File
@@ -1,70 +0,0 @@
/// <reference path="../../Phaser/Game.ts" />
/// <reference path="../../Phaser/core/Polygon.ts" />
/// <reference path="../../Phaser/utils/SpriteUtils.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.loader.addImageFile('atari', 'assets/sprites/atari800xl.png');
game.loader.load();
}
var atari: Phaser.Sprite;
var p: Phaser.Polygon;
var atari2: Phaser.Sprite;
var p2: Phaser.Polygon;
function create() {
atari = game.add.sprite(200, 300, 'atari');
atari.texture.alpha = 0.2;
atari2 = game.add.sprite(500, 300, 'atari');
atari2.texture.alpha = 0.2;
p = new Phaser.Polygon(game, Phaser.SpriteUtils.getAsPoints(atari));
p2 = new Phaser.Polygon(game, Phaser.SpriteUtils.getAsPoints(atari2));
}
function update() {
atari.physics.acceleration.x = 0;
atari.physics.acceleration.y = 0;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
atari.physics.acceleration.x = -150;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
atari.physics.acceleration.x = 150;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
atari.physics.acceleration.y = -150;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
atari.physics.acceleration.y = 150;
}
}
function render() {
atari.physics.renderDebugInfo(16, 16);
p.render();
p2.render();
}
})();
+1 -1
View File
@@ -14,7 +14,7 @@
// The sprite is 320 x 200 pixels in size
// If we don't set an origin then the sprite will rotate around 0,0 - the top left corner
game.add.tween(fuji).to({
rotation: 360
angle: 360
}, 2000, Phaser.Easing.Linear.None, true, 0, true);
}
})();
+1 -1
View File
@@ -23,7 +23,7 @@
// The sprite is 320 x 200 pixels in size
// If we don't set an origin then the sprite will rotate around 0,0 - the top left corner
game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
game.add.tween(fuji).to({ angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true);
}
-136
View File
@@ -1,8 +1,3 @@
/**
* Phaser - FX - Camera - Flash
*
* The camera is filled with the given color and returns to normal at the given duration.
*/
module Phaser.FX.Camera {
class Flash {
constructor(game: Game);
@@ -11,95 +6,35 @@ module Phaser.FX.Camera {
private _fxFlashComplete;
private _fxFlashDuration;
private _fxFlashAlpha;
/**
* The camera is filled with this color and returns to normal at the given duration.
*
* @param Color The color you want to use in 0xRRGGBB format, i.e. 0xffffff for white.
* @param Duration How long it takes for the flash to fade.
* @param OnComplete An optional function you want to run when the flash finishes. Set to null for no callback.
* @param Force Force an already running flash effect to reset.
*/
public start(color?: number, duration?: number, onComplete?, force?: bool): void;
public postUpdate(): void;
public postRender(camera: Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number): void;
}
}
/**
* Phaser - FX - Camera - Border
*
* Creates a border around a camera.
*/
module Phaser.FX.Camera {
class Border {
constructor(game: Game, parent: Camera);
private _game;
private _parent;
/**
* Whether render border of this camera or not. (default is false)
* @type {boolean}
*/
public showBorder: bool;
/**
* Color of border of this camera. (in css color string)
* @type {string}
*/
public borderColor: string;
/**
* You can name the function that starts the effect whatever you like, but we used 'start' in our effects.
*/
public start(): void;
/**
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
* It happens directly BEFORE a canvas context.restore has happened if added to a Camera.
*/
public postRender(camera: Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number): void;
}
}
/**
* Phaser - FX - Camera - Template
*
* A Template FX file you can use to create your own Camera FX.
* If you don't use any of the methods below (i.e. preUpdate, render, etc) then DELETE THEM to avoid un-necessary calls by the FXManager.
*/
module Phaser.FX.Camera {
class Template {
constructor(game: Game, parent: Camera);
private _game;
private _parent;
/**
* You can name the function that starts the effect whatever you like, but we used 'start' in our effects.
*/
public start(): void;
/**
* Pre-update is called at the start of the objects update cycle, before any other updates have taken place.
*/
public preUpdate(): void;
/**
* Post-update is called at the end of the objects update cycle, after other update logic has taken place.
*/
public postUpdate(): void;
/**
* Pre-render is called at the start of the object render cycle, before any transforms have taken place.
* It happens directly AFTER a canvas context.save has happened if added to a Camera.
*/
public preRender(camera: Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number): void;
/**
* render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered.
*/
public render(camera: Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number): void;
/**
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
* It happens directly BEFORE a canvas context.restore has happened if added to a Camera.
*/
public postRender(camera: Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number): void;
}
}
/**
* Phaser - FX - Camera - Mirror
*
* Creates a mirror effect for a camera.
* Can mirror the camera image horizontally, vertically or both with an optional fill color overlay.
*/
module Phaser.FX.Camera {
class Mirror {
constructor(game: Game, parent: Camera);
@@ -119,68 +54,24 @@ module Phaser.FX.Camera {
public x: number;
public y: number;
public cls: bool;
/**
* This is the rectangular region to grab from the Camera used in the Mirror effect
* It is rendered to the Stage at Mirror.x/y (note the use of Stage coordinates, not World coordinates)
*/
public start(x: number, y: number, region: Rectangle, fillColor?: string): void;
/**
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
* It happens directly BEFORE a canvas context.restore has happened if added to a Camera.
*/
public postRender(camera: Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number): void;
}
}
/**
* Phaser - FX - Camera - Shadow
*
* Creates a drop-shadow effect on the camera window.
*/
module Phaser.FX.Camera {
class Shadow {
constructor(game: Game, parent: Camera);
private _game;
private _parent;
/**
* Render camera shadow or not. (default is false)
* @type {boolean}
*/
public showShadow: bool;
/**
* Color of shadow, in css color string.
* @type {string}
*/
public shadowColor: string;
/**
* Blur factor of shadow.
* @type {number}
*/
public shadowBlur: number;
/**
* Offset of the shadow from camera's position.
* @type {Point}
*/
public shadowOffset: Point;
/**
* You can name the function that starts the effect whatever you like, but we used 'start' in our effects.
*/
public start(): void;
/**
* Pre-render is called at the start of the object render cycle, before any transforms have taken place.
* It happens directly AFTER a canvas context.save has happened if added to a Camera.
*/
public preRender(camera: Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number): void;
/**
* render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered.
*/
public render(camera: Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number): void;
}
}
/**
* Phaser - FX - Camera - Scanlines
*
* Give your game that classic retro feel!
*/
module Phaser.FX.Camera {
class Scanlines {
constructor(game: Game, parent: Camera);
@@ -191,11 +82,6 @@ module Phaser.FX.Camera {
public postRender(camera: Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number): void;
}
}
/**
* Phaser - FX - Camera - Shake
*
* A simple camera shake effect.
*/
module Phaser.FX.Camera {
class Shake {
constructor(game: Game, camera: Camera);
@@ -211,25 +97,11 @@ module Phaser.FX.Camera {
static SHAKE_BOTH_AXES: number;
static SHAKE_HORIZONTAL_ONLY: number;
static SHAKE_VERTICAL_ONLY: number;
/**
* A simple camera shake effect.
*
* @param Intensity Percentage of screen size representing the maximum distance that the screen can move while shaking.
* @param Duration The length in seconds that the shaking effect should last.
* @param OnComplete A function you want to run when the shake effect finishes.
* @param Force Force the effect to reset (default = true, unlike flash() and fade()!).
* @param Direction Whether to shake on both axes, just up and down, or just side to side (use class constants SHAKE_BOTH_AXES, SHAKE_VERTICAL_ONLY, or SHAKE_HORIZONTAL_ONLY).
*/
public start(intensity?: number, duration?: number, onComplete?, force?: bool, direction?: number): void;
public postUpdate(): void;
public preRender(camera: Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number): void;
}
}
/**
* Phaser - FX - Camera - Fade
*
* The camera is filled with the given color and returns to normal at the given duration.
*/
module Phaser.FX.Camera {
class Fade {
constructor(game: Game);
@@ -238,14 +110,6 @@ module Phaser.FX.Camera {
private _fxFadeComplete;
private _fxFadeDuration;
private _fxFadeAlpha;
/**
* The camera is gradually filled with this color.
*
* @param Color The color you want to use in 0xRRGGBB format, i.e. 0xffffff for white.
* @param Duration How long it takes for the flash to fade.
* @param OnComplete An optional function you want to run when the flash finishes. Set to null for no callback.
* @param Force Force an already running flash effect to reset.
*/
public start(color?: number, duration?: number, onComplete?, force?: bool): void;
public postUpdate(): void;
public postRender(camera: Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number): void;
+17 -185
View File
@@ -1,12 +1,6 @@
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Flash
*
* The camera is filled with the given color and returns to normal at the given duration.
*/
(function (Camera) {
var Flash = (function () {
function Flash(game) {
@@ -15,21 +9,12 @@ var Phaser;
this._fxFlashAlpha = 0;
this._game = game;
}
Flash.prototype.start = /**
* The camera is filled with this color and returns to normal at the given duration.
*
* @param Color The color you want to use in 0xRRGGBB format, i.e. 0xffffff for white.
* @param Duration How long it takes for the flash to fade.
* @param OnComplete An optional function you want to run when the flash finishes. Set to null for no callback.
* @param Force Force an already running flash effect to reset.
*/
function (color, duration, onComplete, force) {
Flash.prototype.start = function (color, duration, onComplete, force) {
if (typeof color === "undefined") { color = 0xffffff; }
if (typeof duration === "undefined") { duration = 1; }
if (typeof onComplete === "undefined") { onComplete = null; }
if (typeof force === "undefined") { force = false; }
if(force === false && this._fxFlashAlpha > 0) {
// You can't flash again unless you force it
return;
}
if(duration <= 0) {
@@ -44,7 +29,6 @@ var Phaser;
this._fxFlashComplete = onComplete;
};
Flash.prototype.postUpdate = function () {
// Update the Flash effect
if(this._fxFlashAlpha > 0) {
this._fxFlashAlpha -= this._game.time.elapsed / this._fxFlashDuration;
if(this._game.math.roundTo(this._fxFlashAlpha, -2) <= 0) {
@@ -72,38 +56,17 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Border
*
* Creates a border around a camera.
*/
(function (Camera) {
var Border = (function () {
function Border(game, parent) {
/**
* Whether render border of this camera or not. (default is false)
* @type {boolean}
*/
this.showBorder = false;
/**
* Color of border of this camera. (in css color string)
* @type {string}
*/
this.borderColor = 'rgb(255,255,255)';
this._game = game;
this._parent = parent;
}
Border.prototype.start = /**
* You can name the function that starts the effect whatever you like, but we used 'start' in our effects.
*/
function () {
Border.prototype.start = function () {
};
Border.prototype.postRender = /**
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
* It happens directly BEFORE a canvas context.restore has happened if added to a Camera.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
Border.prototype.postRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
if(this.showBorder == true) {
this._game.stage.context.strokeStyle = this.borderColor;
this._game.stage.context.lineWidth = 1;
@@ -122,50 +85,23 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Template
*
* A Template FX file you can use to create your own Camera FX.
* If you don't use any of the methods below (i.e. preUpdate, render, etc) then DELETE THEM to avoid un-necessary calls by the FXManager.
*/
(function (Camera) {
var Template = (function () {
function Template(game, parent) {
this._game = game;
this._parent = parent;
}
Template.prototype.start = /**
* You can name the function that starts the effect whatever you like, but we used 'start' in our effects.
*/
function () {
Template.prototype.start = function () {
};
Template.prototype.preUpdate = /**
* Pre-update is called at the start of the objects update cycle, before any other updates have taken place.
*/
function () {
Template.prototype.preUpdate = function () {
};
Template.prototype.postUpdate = /**
* Post-update is called at the end of the objects update cycle, after other update logic has taken place.
*/
function () {
Template.prototype.postUpdate = function () {
};
Template.prototype.preRender = /**
* Pre-render is called at the start of the object render cycle, before any transforms have taken place.
* It happens directly AFTER a canvas context.save has happened if added to a Camera.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
Template.prototype.preRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
};
Template.prototype.render = /**
* render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
Template.prototype.render = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
};
Template.prototype.postRender = /**
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
* It happens directly BEFORE a canvas context.restore has happened if added to a Camera.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
Template.prototype.postRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
};
return Template;
})();
@@ -178,13 +114,6 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Mirror
*
* Creates a mirror effect for a camera.
* Can mirror the camera image horizontally, vertically or both with an optional fill color overlay.
*/
(function (Camera) {
var Mirror = (function () {
function Mirror(game, parent) {
@@ -199,11 +128,7 @@ var Phaser;
this._canvas.height = parent.height;
this._context = this._canvas.getContext('2d');
}
Mirror.prototype.start = /**
* This is the rectangular region to grab from the Camera used in the Mirror effect
* It is rendered to the Stage at Mirror.x/y (note the use of Stage coordinates, not World coordinates)
*/
function (x, y, region, fillColor) {
Mirror.prototype.start = function (x, y, region, fillColor) {
if (typeof fillColor === "undefined") { fillColor = 'rgba(0, 0, 100, 0.5)'; }
this.x = x;
this.y = y;
@@ -216,15 +141,7 @@ var Phaser;
this._context.fillStyle = this._mirrorColor;
}
};
Mirror.prototype.postRender = /**
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
* It happens directly BEFORE a canvas context.restore has happened if added to a Camera.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
//if (this.cls)
//{
// this._context.clearRect(0, 0, this._mirrorWidth, this._mirrorHeight);
//}
Mirror.prototype.postRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
this._sx = cameraX + this._mirrorX;
this._sy = cameraY + this._mirrorY;
if(this.flipX == true && this.flipY == false) {
@@ -232,16 +149,7 @@ var Phaser;
} else if(this.flipY == true && this.flipX == false) {
this._sy = 0;
}
this._context.drawImage(this._game.stage.canvas, // Source Image
this._sx, // Source X (location within the source image)
this._sy, // Source Y
this._mirrorWidth, // Source Width
this._mirrorHeight, // Source Height
0, // Destination X (where on the canvas it'll be drawn)
0, // Destination Y
this._mirrorWidth, // Destination Width (always same as Source Width unless scaled)
this._mirrorHeight);
// Destination Height (always same as Source Height unless scaled)
this._context.drawImage(this._game.stage.canvas, this._sx, this._sy, this._mirrorWidth, this._mirrorHeight, 0, 0, this._mirrorWidth, this._mirrorHeight);
if(this._mirrorColor) {
this._context.fillRect(0, 0, this._mirrorWidth, this._mirrorHeight);
}
@@ -267,49 +175,19 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Shadow
*
* Creates a drop-shadow effect on the camera window.
*/
(function (Camera) {
var Shadow = (function () {
function Shadow(game, parent) {
/**
* Render camera shadow or not. (default is false)
* @type {boolean}
*/
this.showShadow = false;
/**
* Color of shadow, in css color string.
* @type {string}
*/
this.shadowColor = 'rgb(0,0,0)';
/**
* Blur factor of shadow.
* @type {number}
*/
this.shadowBlur = 10;
/**
* Offset of the shadow from camera's position.
* @type {Point}
*/
this.shadowOffset = new Phaser.Point(4, 4);
this._game = game;
this._parent = parent;
}
Shadow.prototype.start = /**
* You can name the function that starts the effect whatever you like, but we used 'start' in our effects.
*/
function () {
Shadow.prototype.start = function () {
};
Shadow.prototype.preRender = /**
* Pre-render is called at the start of the object render cycle, before any transforms have taken place.
* It happens directly AFTER a canvas context.save has happened if added to a Camera.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
// Shadow
Shadow.prototype.preRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
if(this.showShadow == true) {
this._game.stage.context.shadowColor = this.shadowColor;
this._game.stage.context.shadowBlur = this.shadowBlur;
@@ -317,11 +195,7 @@ var Phaser;
this._game.stage.context.shadowOffsetY = this.shadowOffset.y;
}
};
Shadow.prototype.render = /**
* render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
// Shadow off
Shadow.prototype.render = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
if(this.showShadow == true) {
this._game.stage.context.shadowBlur = 0;
this._game.stage.context.shadowOffsetX = 0;
@@ -339,12 +213,6 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Scanlines
*
* Give your game that classic retro feel!
*/
(function (Camera) {
var Scanlines = (function () {
function Scanlines(game, parent) {
@@ -370,12 +238,6 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Shake
*
* A simple camera shake effect.
*/
(function (Camera) {
var Shake = (function () {
function Shake(game, camera) {
@@ -392,16 +254,7 @@ var Phaser;
Shake.SHAKE_BOTH_AXES = 0;
Shake.SHAKE_HORIZONTAL_ONLY = 1;
Shake.SHAKE_VERTICAL_ONLY = 2;
Shake.prototype.start = /**
* A simple camera shake effect.
*
* @param Intensity Percentage of screen size representing the maximum distance that the screen can move while shaking.
* @param Duration The length in seconds that the shaking effect should last.
* @param OnComplete A function you want to run when the shake effect finishes.
* @param Force Force the effect to reset (default = true, unlike flash() and fade()!).
* @param Direction Whether to shake on both axes, just up and down, or just side to side (use class constants SHAKE_BOTH_AXES, SHAKE_VERTICAL_ONLY, or SHAKE_HORIZONTAL_ONLY).
*/
function (intensity, duration, onComplete, force, direction) {
Shake.prototype.start = function (intensity, duration, onComplete, force, direction) {
if (typeof intensity === "undefined") { intensity = 0.05; }
if (typeof duration === "undefined") { duration = 0.5; }
if (typeof onComplete === "undefined") { onComplete = null; }
@@ -410,7 +263,6 @@ var Phaser;
if(!force && ((this._fxShakeOffset.x != 0) || (this._fxShakeOffset.y != 0))) {
return;
}
// If a shake is not already running we need to store the offsets here
if(this._fxShakeOffset.x == 0 && this._fxShakeOffset.y == 0) {
this._fxShakePrevX = this._parent.x;
this._fxShakePrevY = this._parent.y;
@@ -422,7 +274,6 @@ var Phaser;
this._fxShakeOffset.setTo(0, 0);
};
Shake.prototype.postUpdate = function () {
// Update the "shake" special effect
if(this._fxShakeDuration > 0) {
this._fxShakeDuration -= this._game.time.elapsed;
if(this._game.math.roundTo(this._fxShakeDuration, -2) <= 0) {
@@ -435,11 +286,9 @@ var Phaser;
}
} else {
if((this._fxShakeDirection == Shake.SHAKE_BOTH_AXES) || (this._fxShakeDirection == Shake.SHAKE_HORIZONTAL_ONLY)) {
//this._fxShakeOffset.x = ((this._game.math.random() * this._fxShakeIntensity * this.worldView.width * 2 - this._fxShakeIntensity * this.worldView.width) * this._zoom;
this._fxShakeOffset.x = (this._game.math.random() * this._fxShakeIntensity * this._parent.worldView.width * 2 - this._fxShakeIntensity * this._parent.worldView.width);
}
if((this._fxShakeDirection == Shake.SHAKE_BOTH_AXES) || (this._fxShakeDirection == Shake.SHAKE_VERTICAL_ONLY)) {
//this._fxShakeOffset.y = (this._game.math.random() * this._fxShakeIntensity * this.worldView.height * 2 - this._fxShakeIntensity * this.worldView.height) * this._zoom;
this._fxShakeOffset.y = (this._game.math.random() * this._fxShakeIntensity * this._parent.worldView.height * 2 - this._fxShakeIntensity * this._parent.worldView.height);
}
}
@@ -462,12 +311,6 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Fade
*
* The camera is filled with the given color and returns to normal at the given duration.
*/
(function (Camera) {
var Fade = (function () {
function Fade(game) {
@@ -476,21 +319,12 @@ var Phaser;
this._fxFadeAlpha = 0;
this._game = game;
}
Fade.prototype.start = /**
* The camera is gradually filled with this color.
*
* @param Color The color you want to use in 0xRRGGBB format, i.e. 0xffffff for white.
* @param Duration How long it takes for the flash to fade.
* @param OnComplete An optional function you want to run when the flash finishes. Set to null for no callback.
* @param Force Force an already running flash effect to reset.
*/
function (color, duration, onComplete, force) {
Fade.prototype.start = function (color, duration, onComplete, force) {
if (typeof color === "undefined") { color = 0x000000; }
if (typeof duration === "undefined") { duration = 1; }
if (typeof onComplete === "undefined") { onComplete = null; }
if (typeof force === "undefined") { force = false; }
if(force === false && this._fxFadeAlpha > 0) {
// You can't fade again unless you force it
return;
}
if(duration <= 0) {
@@ -505,7 +339,6 @@ var Phaser;
this._fxFadeComplete = onComplete;
};
Fade.prototype.postUpdate = function () {
// Update the Fade effect
if(this._fxFadeAlpha > 0) {
this._fxFadeAlpha += this._game.time.elapsed / this._fxFadeDuration;
if(this._game.math.roundTo(this._fxFadeAlpha, -2) >= 1) {
@@ -517,7 +350,6 @@ var Phaser;
}
};
Fade.prototype.postRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
// "Fade" FX
if(this._fxFadeAlpha > 0) {
this._game.stage.context.fillStyle = this._fxFadeColor + this._fxFadeAlpha + ')';
this._game.stage.context.fillRect(cameraX, cameraY, cameraWidth, cameraHeight);
+3052 -2048
View File
File diff suppressed because it is too large Load Diff
+5318 -3805
View File
File diff suppressed because it is too large Load Diff