mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 21:53:59 +00:00
Preparing for new release
This commit is contained in:
parent
72a4809dd8
commit
6bb4c5e3fc
165 changed files with 37278 additions and 29038 deletions
|
@ -1,12 +1,13 @@
|
|||
/// <reference path="Cache.ts" />
|
||||
/// <reference path="Game.ts" />
|
||||
/// <reference path="Sprite.ts" />
|
||||
/// <reference path="gameobjects/Sprite.ts" />
|
||||
/// <reference path="system/animation/Animation.ts" />
|
||||
/// <reference path="system/animation/AnimationLoader.ts" />
|
||||
/// <reference path="system/animation/Frame.ts" />
|
||||
/// <reference path="system/animation/FrameData.ts" />
|
||||
|
||||
class Animations {
|
||||
module Phaser {
|
||||
|
||||
export class Animations {
|
||||
|
||||
constructor(game: Game, parent: Sprite) {
|
||||
|
||||
|
@ -34,7 +35,7 @@ class Animations {
|
|||
|
||||
}
|
||||
|
||||
public add(name: string, frames:number[] = null, frameRate: number = 60, loop: bool = false) {
|
||||
public add(name: string, frames: any[] = null, frameRate: number = 60, loop: bool = false, useNumericIndex: bool = true) {
|
||||
|
||||
if (this._frameData == null)
|
||||
{
|
||||
|
@ -47,29 +48,44 @@ class Animations {
|
|||
}
|
||||
else
|
||||
{
|
||||
if (this.validateFrames(frames) == false)
|
||||
if (this.validateFrames(frames, useNumericIndex) == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (useNumericIndex == false)
|
||||
{
|
||||
frames = this._frameData.getFrameIndexesByName(frames);
|
||||
}
|
||||
|
||||
this._anims[name] = new Animation(this._game, this._parent, this._frameData, name, frames, frameRate, loop);
|
||||
|
||||
this.currentAnim = this._anims[name];
|
||||
|
||||
}
|
||||
|
||||
private validateFrames(frames:number[]):bool {
|
||||
|
||||
var result = true;
|
||||
private validateFrames(frames: any[], useNumericIndex: bool): bool {
|
||||
|
||||
for (var i = 0; i < frames.length; i++)
|
||||
{
|
||||
if (useNumericIndex == true)
|
||||
{
|
||||
if (frames[i] > this._frameData.total)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this._frameData.checkFrameName(frames[i]) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
@ -104,6 +120,10 @@ class Animations {
|
|||
|
||||
}
|
||||
|
||||
public get frameData(): FrameData {
|
||||
return this._frameData;
|
||||
}
|
||||
|
||||
public get frameTotal(): number {
|
||||
return this._frameData.total;
|
||||
}
|
||||
|
@ -142,4 +162,6 @@ class Animations {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -9,12 +9,18 @@
|
|||
* @author Richard Davey
|
||||
*/
|
||||
|
||||
class Basic {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Basic {
|
||||
|
||||
/**
|
||||
* Instantiate the basic object.
|
||||
*/
|
||||
constructor(game:Game) {
|
||||
constructor(game: Game) {
|
||||
|
||||
this._game = game;
|
||||
this.ID = -1;
|
||||
|
@ -102,7 +108,7 @@ class Basic {
|
|||
public postUpdate() {
|
||||
}
|
||||
|
||||
public render(camera:Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,9 +136,9 @@ class Basic {
|
|||
* Convert object to readable string name. Useful for debugging, save games, etc.
|
||||
*/
|
||||
public toString(): string {
|
||||
//return FlxU.getClassName(this, true);
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,12 @@
|
|||
/// <reference path="system/animation/AnimationLoader.ts" />
|
||||
/// <reference path="Game.ts" />
|
||||
|
||||
class Cache {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Cache {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
|
@ -20,33 +26,33 @@ class Cache {
|
|||
private _sounds;
|
||||
private _text;
|
||||
|
||||
public addCanvas(key: string, canvas:HTMLCanvasElement, context:CanvasRenderingContext2D) {
|
||||
public addCanvas(key: string, canvas: HTMLCanvasElement, context: CanvasRenderingContext2D) {
|
||||
|
||||
this._canvases[key] = { canvas: canvas, context: context };
|
||||
|
||||
}
|
||||
|
||||
public addSpriteSheet(key: string, url:string, data, frameWidth:number, frameHeight:number, frameMax:number) {
|
||||
public addSpriteSheet(key: string, url: string, data, frameWidth: number, frameHeight: number, frameMax: number) {
|
||||
|
||||
this._images[key] = { url: url, data: data, spriteSheet: true, frameWidth: frameWidth, frameHeight: frameHeight };
|
||||
this._images[key].frameData = AnimationLoader.parseSpriteSheet(this._game, key, frameWidth, frameHeight, frameMax);
|
||||
|
||||
}
|
||||
|
||||
public addTextureAtlas(key: string, url:string, data, jsonData) {
|
||||
public addTextureAtlas(key: string, url: string, data, jsonData) {
|
||||
|
||||
this._images[key] = { url: url, data: data, spriteSheet: true };
|
||||
this._images[key].frameData = AnimationLoader.parseJSONData(this._game, jsonData);
|
||||
|
||||
}
|
||||
|
||||
public addImage(key: string, url:string, data) {
|
||||
public addImage(key: string, url: string, data) {
|
||||
|
||||
this._images[key] = { url: url, data: data, spriteSheet: false };
|
||||
|
||||
}
|
||||
|
||||
public addSound(key: string, url:string, data) {
|
||||
public addSound(key: string, url: string, data) {
|
||||
|
||||
this._sounds[key] = { url: url, data: data, decoded: false };
|
||||
|
||||
|
@ -59,7 +65,7 @@ class Cache {
|
|||
|
||||
}
|
||||
|
||||
public addText(key: string, url:string, data) {
|
||||
public addText(key: string, url: string, data) {
|
||||
|
||||
this._text[key] = { url: url, data: data };
|
||||
|
||||
|
@ -87,7 +93,7 @@ class Cache {
|
|||
|
||||
}
|
||||
|
||||
public getFrameData(key: string):FrameData {
|
||||
public getFrameData(key: string): FrameData {
|
||||
|
||||
if (this._images[key] && this._images[key].spriteSheet == true)
|
||||
{
|
||||
|
@ -162,4 +168,6 @@ class Cache {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,16 @@
|
|||
/// <reference path="Game.ts" />
|
||||
/// <reference path="GameMath.ts" />
|
||||
/// <reference path="geom/Rectangle.ts" />
|
||||
/// <reference path="geom/Point.ts" />
|
||||
/// <reference path="system/Camera.ts" />
|
||||
|
||||
// TODO: If the Camera is larger than the Stage size then the rotation offset isn't correct
|
||||
// TODO: Texture Repeat doesn't scroll, because it's part of the camera not the world, need to think about this more
|
||||
|
||||
class Cameras {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Cameras {
|
||||
|
||||
constructor(game: Game, x: number, y: number, width: number, height: number) {
|
||||
|
||||
|
@ -75,5 +78,6 @@ class Cameras {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
891
Phaser/Collision.ts
Normal file
891
Phaser/Collision.ts
Normal file
|
@ -0,0 +1,891 @@
|
|||
/// <reference path="Game.ts" />
|
||||
/// <reference path="geom/Point.ts" />
|
||||
/// <reference path="geom/Rectangle.ts" />
|
||||
/// <reference path="geom/Circle.ts" />
|
||||
/// <reference path="geom/Line.ts" />
|
||||
/// <reference path="geom/IntersectResult.ts" />
|
||||
/// <reference path="system/QuadTree.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Collision
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Collision {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
this._game = game;
|
||||
|
||||
}
|
||||
|
||||
private _game: Game;
|
||||
|
||||
public static LEFT: number = 0x0001;
|
||||
public static RIGHT: number = 0x0010;
|
||||
public static UP: number = 0x0100;
|
||||
public static DOWN: number = 0x1000;
|
||||
public static NONE: number = 0;
|
||||
public static CEILING: number = Collision.UP;
|
||||
public static FLOOR: number = Collision.DOWN;
|
||||
public static WALL: number = Collision.LEFT | Collision.RIGHT;
|
||||
public static ANY: number = Collision.LEFT | Collision.RIGHT | Collision.UP | Collision.DOWN;
|
||||
public static OVERLAP_BIAS: number = 4;
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Lines
|
||||
* -------------------------------------------------------------------------------------------
|
||||
**/
|
||||
|
||||
/**
|
||||
* Check if the two given Line objects intersect
|
||||
* @method lineToLine
|
||||
* @param {Phaser.Line} The first line object to check
|
||||
* @param {Phaser.Line} The second line object to check
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection in x/y
|
||||
**/
|
||||
public static lineToLine(line1: Line, line2: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
var denom = (line1.x1 - line1.x2) * (line2.y1 - line2.y2) - (line1.y1 - line1.y2) * (line2.x1 - line2.x2);
|
||||
|
||||
if (denom !== 0)
|
||||
{
|
||||
output.result = true;
|
||||
output.x = ((line1.x1 * line1.y2 - line1.y1 * line1.x2) * (line2.x1 - line2.x2) - (line1.x1 - line1.x2) * (line2.x1 * line2.y2 - line2.y1 * line2.x2)) / denom;
|
||||
output.y = ((line1.x1 * line1.y2 - line1.y1 * line1.x2) * (line2.y1 - line2.y2) - (line1.y1 - line1.y2) * (line2.x1 * line2.y2 - line2.y1 * line2.x2)) / denom;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Line and Line Segment intersects
|
||||
* @method lineToLineSegment
|
||||
* @param {Phaser.Line} The line object to check
|
||||
* @param {Phaser.Line} The line segment object to check
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection in x/y
|
||||
**/
|
||||
public static lineToLineSegment(line1: Line, seg: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
var denom = (line1.x1 - line1.x2) * (seg.y1 - seg.y2) - (line1.y1 - line1.y2) * (seg.x1 - seg.x2);
|
||||
|
||||
if (denom !== 0)
|
||||
{
|
||||
output.x = ((line1.x1 * line1.y2 - line1.y1 * line1.x2) * (seg.x1 - seg.x2) - (line1.x1 - line1.x2) * (seg.x1 * seg.y2 - seg.y1 * seg.x2)) / denom;
|
||||
output.y = ((line1.x1 * line1.y2 - line1.y1 * line1.x2) * (seg.y1 - seg.y2) - (line1.y1 - line1.y2) * (seg.x1 * seg.y2 - seg.y1 * seg.x2)) / denom;
|
||||
|
||||
var maxX = Math.max(seg.x1, seg.x2);
|
||||
var minX = Math.min(seg.x1, seg.x2);
|
||||
var maxY = Math.max(seg.y1, seg.y2);
|
||||
var minY = Math.min(seg.y1, seg.y2);
|
||||
|
||||
//if (!(output.x <= maxX && output.x >= minX) || !(output.y <= maxY && output.y >= minY))
|
||||
if ((output.x <= maxX && output.x >= minX) === true || (output.y <= maxY && output.y >= minY) === true)
|
||||
{
|
||||
output.result = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Line and Line Segment intersects
|
||||
* @method lineToLineSegment
|
||||
* @param {Phaser.Line} The line object to check
|
||||
* @param {number} The x1 value
|
||||
* @param {number} The y1 value
|
||||
* @param {number} The x2 value
|
||||
* @param {number} The y2 value
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection in x/y
|
||||
**/
|
||||
public static lineToRawSegment(line: Line, x1: number, y1: number, x2: number, y2: number, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
var denom = (line.x1 - line.x2) * (y1 - y2) - (line.y1 - line.y2) * (x1 - x2);
|
||||
|
||||
if (denom !== 0)
|
||||
{
|
||||
output.x = ((line.x1 * line.y2 - line.y1 * line.x2) * (x1 - x2) - (line.x1 - line.x2) * (x1 * y2 - y1 * x2)) / denom;
|
||||
output.y = ((line.x1 * line.y2 - line.y1 * line.x2) * (y1 - y2) - (line.y1 - line.y2) * (x1 * y2 - y1 * x2)) / denom;
|
||||
|
||||
var maxX = Math.max(x1, x2);
|
||||
var minX = Math.min(x1, x2);
|
||||
var maxY = Math.max(y1, y2);
|
||||
var minY = Math.min(y1, y2);
|
||||
|
||||
if ((output.x <= maxX && output.x >= minX) === true || (output.y <= maxY && output.y >= minY) === true)
|
||||
{
|
||||
output.result = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Line and Ray intersects
|
||||
* @method lineToRay
|
||||
* @param {Phaser.Line} The Line object to check
|
||||
* @param {Phaser.Line} The Ray object to check
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection in x/y
|
||||
**/
|
||||
public static lineToRay(line1: Line, ray: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
var denom = (line1.x1 - line1.x2) * (ray.y1 - ray.y2) - (line1.y1 - line1.y2) * (ray.x1 - ray.x2);
|
||||
|
||||
if (denom !== 0)
|
||||
{
|
||||
output.x = ((line1.x1 * line1.y2 - line1.y1 * line1.x2) * (ray.x1 - ray.x2) - (line1.x1 - line1.x2) * (ray.x1 * ray.y2 - ray.y1 * ray.x2)) / denom;
|
||||
output.y = ((line1.x1 * line1.y2 - line1.y1 * line1.x2) * (ray.y1 - ray.y2) - (line1.y1 - line1.y2) * (ray.x1 * ray.y2 - ray.y1 * ray.x2)) / denom;
|
||||
output.result = true; // true unless either of the 2 following conditions are met
|
||||
|
||||
if (!(ray.x1 >= ray.x2) && output.x < ray.x1)
|
||||
{
|
||||
output.result = false;
|
||||
}
|
||||
|
||||
if (!(ray.y1 >= ray.y2) && output.y < ray.y1)
|
||||
{
|
||||
output.result = false;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Line and Circle intersects
|
||||
* @method lineToCircle
|
||||
* @param {Phaser.Line} The Line object to check
|
||||
* @param {Phaser.Circle} The Circle object to check
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection
|
||||
**/
|
||||
public static lineToCircle(line: Line, circle: Circle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
// Get a perpendicular line running to the center of the circle
|
||||
if (line.perp(circle.x, circle.y).length <= circle.radius)
|
||||
{
|
||||
output.result = true;
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Line intersects each side of the Rectangle
|
||||
* @method lineToRectangle
|
||||
* @param {Phaser.Line} The Line object to check
|
||||
* @param {Phaser.Rectangle} The Rectangle object to check
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection
|
||||
**/
|
||||
public static lineToRectangle(line: Line, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
// Top of the Rectangle vs the Line
|
||||
this.lineToRawSegment(line, rect.x, rect.y, rect.right, rect.y, output);
|
||||
|
||||
if (output.result === true)
|
||||
{
|
||||
return output;
|
||||
}
|
||||
|
||||
// Left of the Rectangle vs the Line
|
||||
this.lineToRawSegment(line, rect.x, rect.y, rect.x, rect.bottom, output);
|
||||
|
||||
if (output.result === true)
|
||||
{
|
||||
return output;
|
||||
}
|
||||
|
||||
// Bottom of the Rectangle vs the Line
|
||||
this.lineToRawSegment(line, rect.x, rect.bottom, rect.right, rect.bottom, output);
|
||||
|
||||
if (output.result === true)
|
||||
{
|
||||
return output;
|
||||
}
|
||||
|
||||
// Right of the Rectangle vs the Line
|
||||
this.lineToRawSegment(line, rect.right, rect.y, rect.right, rect.bottom, output);
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Line Segment
|
||||
* -------------------------------------------------------------------------------------------
|
||||
**/
|
||||
|
||||
/**
|
||||
* Check if Line1 intersects with Line2
|
||||
* @method lineSegmentToLineSegment
|
||||
* @param {Phaser.Line} The first line object to check
|
||||
* @param {Phaser.Line} The second line object to check
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection in x/y
|
||||
**/
|
||||
public static lineSegmentToLineSegment(line1: Line, line2: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
this.lineToLineSegment(line1, line2, output);
|
||||
|
||||
if (output.result === true)
|
||||
{
|
||||
if (!(output.x >= Math.min(line1.x1, line1.x2) && output.x <= Math.max(line1.x1, line1.x2)
|
||||
&& output.y >= Math.min(line1.y1, line1.y2) && output.y <= Math.max(line1.y1, line1.y2)))
|
||||
{
|
||||
output.result = false;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Line Segment intersects with the Ray
|
||||
* @method lineSegmentToRay
|
||||
* @param {Phaser.Line} The Line object to check
|
||||
* @param {Phaser.Line} The Line Ray object to check
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection in x/y
|
||||
**/
|
||||
public static lineSegmentToRay(line1: Line, ray: Line, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
this.lineToRay(line1, ray, output);
|
||||
|
||||
if (output.result === true)
|
||||
{
|
||||
if (!(output.x >= Math.min(line1.x1, line1.x2) && output.x <= Math.max(line1.x1, line1.x2)
|
||||
&& output.y >= Math.min(line1.y1, line1.y2) && output.y <= Math.max(line1.y1, line1.y2)))
|
||||
{
|
||||
output.result = false;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Line Segment intersects with the Circle
|
||||
* @method lineSegmentToCircle
|
||||
* @param {Phaser.Line} The Line object to check
|
||||
* @param {Phaser.Circle} The Circle object to check
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection in x/y
|
||||
**/
|
||||
public static lineSegmentToCircle(seg: Line, circle: Circle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
var perp = seg.perp(circle.x, circle.y);
|
||||
|
||||
if (perp.length <= circle.radius)
|
||||
{
|
||||
// Line intersects circle - check if segment does
|
||||
var maxX = Math.max(seg.x1, seg.x2);
|
||||
var minX = Math.min(seg.x1, seg.x2);
|
||||
var maxY = Math.max(seg.y1, seg.y2);
|
||||
var minY = Math.min(seg.y1, seg.y2);
|
||||
|
||||
if ((perp.x2 <= maxX && perp.x2 >= minX) && (perp.y2 <= maxY && perp.y2 >= minY))
|
||||
{
|
||||
output.result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Worst case - segment doesn't traverse center, so no perpendicular connection.
|
||||
if (this.circleContainsPoint(circle, <Point> { x: seg.x1, y: seg.y1 }) || this.circleContainsPoint(circle, <Point> { x: seg.x2, y: seg.y2 }))
|
||||
{
|
||||
output.result = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Line Segment intersects with the Rectangle
|
||||
* @method lineSegmentToCircle
|
||||
* @param {Phaser.Line} The Line object to check
|
||||
* @param {Phaser.Circle} The Circle object to check
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection in x/y
|
||||
**/
|
||||
public static lineSegmentToRectangle(seg: Line, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
if (rect.contains(seg.x1, seg.y1) && rect.contains(seg.x2, seg.y2))
|
||||
{
|
||||
output.result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Top of the Rectangle vs the Line
|
||||
this.lineToRawSegment(seg, rect.x, rect.y, rect.right, rect.bottom, output);
|
||||
|
||||
if (output.result === true)
|
||||
{
|
||||
return output;
|
||||
}
|
||||
|
||||
// Left of the Rectangle vs the Line
|
||||
this.lineToRawSegment(seg, rect.x, rect.y, rect.x, rect.bottom, output);
|
||||
|
||||
if (output.result === true)
|
||||
{
|
||||
return output;
|
||||
}
|
||||
|
||||
// Bottom of the Rectangle vs the Line
|
||||
this.lineToRawSegment(seg, rect.x, rect.bottom, rect.right, rect.bottom, output);
|
||||
|
||||
if (output.result === true)
|
||||
{
|
||||
return output;
|
||||
}
|
||||
|
||||
// Right of the Rectangle vs the Line
|
||||
this.lineToRawSegment(seg, rect.right, rect.y, rect.right, rect.bottom, output);
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Ray
|
||||
* -------------------------------------------------------------------------------------------
|
||||
**/
|
||||
|
||||
/**
|
||||
* Check if the two given Circle objects intersect
|
||||
* @method circleToCircle
|
||||
* @param {Phaser.Circle} The first circle object to check
|
||||
* @param {Phaser.Circle} The second circle object to check
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection
|
||||
**/
|
||||
public static rayToRectangle(ray: Line, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
// Currently just finds first intersection - might not be closest to ray pt1
|
||||
this.lineToRectangle(ray, rect, output);
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a ray intersects a line segment, returns the parametric value where the intersection occurs.
|
||||
* @method rayToLineSegment
|
||||
* @static
|
||||
* @param {Number} rayx1. The origin x of the ray.
|
||||
* @param {Number} rayy1. The origin y of the ray.
|
||||
* @param {Number} rayx2. The direction x of the ray.
|
||||
* @param {Number} rayy2. The direction y of the ray.
|
||||
* @param {Number} linex1. The x of the first point of the line segment.
|
||||
* @param {Number} liney1. The y of the first point of the line segment.
|
||||
* @param {Number} linex2. The x of the second point of the line segment.
|
||||
* @param {Number} liney2. The y of the second point of the line segment.
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection stored in x
|
||||
**/
|
||||
public static rayToLineSegment(rayx1, rayy1, rayx2, rayy2, linex1, liney1, linex2, liney2, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
var r, s, d;
|
||||
|
||||
// Check lines are not parallel
|
||||
if ((rayy2 - rayy1) / (rayx2 - rayx1) != (liney2 - liney1) / (linex2 - linex1))
|
||||
{
|
||||
d = (((rayx2 - rayx1) * (liney2 - liney1)) - (rayy2 - rayy1) * (linex2 - linex1));
|
||||
|
||||
if (d != 0)
|
||||
{
|
||||
r = (((rayy1 - liney1) * (linex2 - linex1)) - (rayx1 - linex1) * (liney2 - liney1)) / d;
|
||||
s = (((rayy1 - liney1) * (rayx2 - rayx1)) - (rayx1 - linex1) * (rayy2 - rayy1)) / d;
|
||||
|
||||
if (r >= 0)
|
||||
{
|
||||
if (s >= 0 && s <= 1)
|
||||
{
|
||||
output.result = true;
|
||||
output.x = rayx1 + r * (rayx2 - rayx1), rayy1 + r * (rayy2 - rayy1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Rectangles
|
||||
* -------------------------------------------------------------------------------------------
|
||||
**/
|
||||
|
||||
/**
|
||||
* Determines whether the specified point is contained within the rectangular region defined by the Rectangle object.
|
||||
* @method pointToRectangle
|
||||
* @param {Point} point The point object being checked.
|
||||
* @param {Rectangle} rect The rectangle object being checked.
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection in x/y/result
|
||||
**/
|
||||
public static pointToRectangle(point: Point, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
output.setTo(point.x, point.y);
|
||||
|
||||
output.result = rect.containsPoint(point);
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether two axis aligned rectangles intersect. Return the intersecting rectangle dimensions if they do.
|
||||
* @method rectangleToRectangle
|
||||
* @param {Phaser.Rectangle} The first Rectangle object
|
||||
* @param {Phaser.Rectangle} The second Rectangle object
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection in x/y/width/height
|
||||
**/
|
||||
public static rectangleToRectangle(rect1: Rectangle, rect2: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
var leftX = Math.max(rect1.x, rect2.x);
|
||||
var rightX = Math.min(rect1.right, rect2.right);
|
||||
var topY = Math.max(rect1.y, rect2.y);
|
||||
var bottomY = Math.min(rect1.bottom, rect2.bottom);
|
||||
|
||||
output.setTo(leftX, topY, rightX - leftX, bottomY - topY, rightX - leftX, bottomY - topY);
|
||||
|
||||
var cx = output.x + output.width * .5;
|
||||
var cy = output.y + output.height * .5;
|
||||
|
||||
if ((cx > rect1.x && cx < rect1.right) && (cy > rect1.y && cy < rect1.bottom))
|
||||
{
|
||||
output.result = true;
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
public static rectangleToCircle(rect: Rectangle, circle: Circle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
return this.circleToRectangle(circle, rect, output);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Circle
|
||||
* -------------------------------------------------------------------------------------------
|
||||
**/
|
||||
|
||||
/**
|
||||
* Check if the two given Circle objects intersect
|
||||
* @method circleToCircle
|
||||
* @param {Phaser.Circle} The first circle object to check
|
||||
* @param {Phaser.Circle} The second circle object to check
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection
|
||||
**/
|
||||
public static circleToCircle(circle1: Circle, circle2: Circle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
output.result = ((circle1.radius + circle2.radius) * (circle1.radius + circle2.radius)) >= this.distanceSquared(circle1.x, circle1.y, circle2.x, circle2.y);
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given Rectangle intersects with the given Circle
|
||||
* @method circleToRectangle
|
||||
* @param {Phaser.Circle} The circle object to check
|
||||
* @param {Phaser.Rectangle} The Rectangle object to check
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection
|
||||
**/
|
||||
public static circleToRectangle(circle: Circle, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
var inflatedRect: Rectangle = rect.clone();
|
||||
|
||||
inflatedRect.inflate(circle.radius, circle.radius);
|
||||
|
||||
output.result = inflatedRect.contains(circle.x, circle.y);
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given Point is found within the given Circle
|
||||
* @method circleContainsPoint
|
||||
* @param {Phaser.Circle} The circle object to check
|
||||
* @param {Phaser.Point} The point object to check
|
||||
* @param {Phaser.IntersectResult} An optional IntersectResult object to store the intersection values in (one is created if none given)
|
||||
* @return {Phaser.IntersectResult} An IntersectResult object containing the results of this intersection
|
||||
**/
|
||||
public static circleContainsPoint(circle: Circle, point: Point, output?: IntersectResult = new IntersectResult): IntersectResult {
|
||||
|
||||
output.result = circle.radius * circle.radius >= this.distanceSquared(circle.x, circle.y, point.x, point.y);
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Game Object Collision
|
||||
* -------------------------------------------------------------------------------------------
|
||||
**/
|
||||
|
||||
/**
|
||||
* Call this function to see if one <code>GameObject</code> overlaps another.
|
||||
* Can be called with one object and one group, or two groups, or two objects,
|
||||
* whatever floats your boat! For maximum performance try bundling a lot of objects
|
||||
* together using a <code>Group</code> (or even bundling groups together!).
|
||||
*
|
||||
* <p>NOTE: does NOT take objects' scrollfactor into account, all overlaps are checked in world space.</p>
|
||||
*
|
||||
* @param ObjectOrGroup1 The first object or group you want to check.
|
||||
* @param ObjectOrGroup2 The second object or group you want to check. If it is the same as the first it knows to just do a comparison within that group.
|
||||
* @param NotifyCallback A function with two <code>GameObject</code> parameters - e.g. <code>myOverlapFunction(Object1:GameObject,Object2:GameObject)</code> - that is called if those two objects overlap.
|
||||
* @param ProcessCallback A function with two <code>GameObject</code> parameters - e.g. <code>myOverlapFunction(Object1:GameObject,Object2:GameObject)</code> - that is called if those two objects overlap. If a ProcessCallback is provided, then NotifyCallback will only be called if ProcessCallback returns true for those objects!
|
||||
*
|
||||
* @return Whether any overlaps were detected.
|
||||
*/
|
||||
public overlap(ObjectOrGroup1: Basic = null, ObjectOrGroup2: Basic = null, NotifyCallback = null, ProcessCallback = null): bool {
|
||||
|
||||
if (ObjectOrGroup1 == null)
|
||||
{
|
||||
ObjectOrGroup1 = this._game.world.group;
|
||||
}
|
||||
|
||||
if (ObjectOrGroup2 == ObjectOrGroup1)
|
||||
{
|
||||
ObjectOrGroup2 = null;
|
||||
}
|
||||
|
||||
QuadTree.divisions = this._game.world.worldDivisions;
|
||||
|
||||
var quadTree: QuadTree = new QuadTree(this._game.world.bounds.x, this._game.world.bounds.y, this._game.world.bounds.width, this._game.world.bounds.height);
|
||||
|
||||
quadTree.load(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, ProcessCallback);
|
||||
|
||||
var result: bool = quadTree.execute();
|
||||
|
||||
quadTree.destroy();
|
||||
|
||||
quadTree = null;
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The main collision resolution in flixel.
|
||||
*
|
||||
* @param Object1 Any <code>Sprite</code>.
|
||||
* @param Object2 Any other <code>Sprite</code>.
|
||||
*
|
||||
* @return Whether the objects in fact touched and were separated.
|
||||
*/
|
||||
public static separate(Object1, Object2): bool {
|
||||
|
||||
var separatedX: bool = Collision.separateX(Object1, Object2);
|
||||
var separatedY: bool = Collision.separateY(Object1, Object2);
|
||||
|
||||
return separatedX || separatedY;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The X-axis component of the object separation process.
|
||||
*
|
||||
* @param Object1 Any <code>Sprite</code>.
|
||||
* @param Object2 Any other <code>Sprite</code>.
|
||||
*
|
||||
* @return Whether the objects in fact touched and were separated along the X axis.
|
||||
*/
|
||||
public static separateX(Object1, Object2): bool {
|
||||
|
||||
//can't separate two immovable objects
|
||||
var obj1immovable: bool = Object1.immovable;
|
||||
var obj2immovable: bool = Object2.immovable;
|
||||
|
||||
if (obj1immovable && obj2immovable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//If one of the objects is a tilemap, just pass it off.
|
||||
/*
|
||||
if (typeof Object1 === 'Tilemap')
|
||||
{
|
||||
return Object1.overlapsWithCallback(Object2, separateX);
|
||||
}
|
||||
|
||||
if (typeof Object2 === 'Tilemap')
|
||||
{
|
||||
return Object2.overlapsWithCallback(Object1, separateX, true);
|
||||
}
|
||||
*/
|
||||
|
||||
//First, get the two object deltas
|
||||
var overlap: number = 0;
|
||||
var obj1delta: number = Object1.x - Object1.last.x;
|
||||
var obj2delta: number = Object2.x - Object2.last.x;
|
||||
|
||||
if (obj1delta != obj2delta)
|
||||
{
|
||||
//Check if the X hulls actually overlap
|
||||
var obj1deltaAbs: number = (obj1delta > 0) ? obj1delta : -obj1delta;
|
||||
var obj2deltaAbs: number = (obj2delta > 0) ? obj2delta : -obj2delta;
|
||||
var obj1rect: Rectangle = new Rectangle(Object1.x - ((obj1delta > 0) ? obj1delta : 0), Object1.last.y, Object1.width + ((obj1delta > 0) ? obj1delta : -obj1delta), Object1.height);
|
||||
var obj2rect: Rectangle = new Rectangle(Object2.x - ((obj2delta > 0) ? obj2delta : 0), Object2.last.y, Object2.width + ((obj2delta > 0) ? obj2delta : -obj2delta), Object2.height);
|
||||
|
||||
if ((obj1rect.x + obj1rect.width > obj2rect.x) && (obj1rect.x < obj2rect.x + obj2rect.width) && (obj1rect.y + obj1rect.height > obj2rect.y) && (obj1rect.y < obj2rect.y + obj2rect.height))
|
||||
{
|
||||
var maxOverlap: number = obj1deltaAbs + obj2deltaAbs + Collision.OVERLAP_BIAS;
|
||||
|
||||
//If they did overlap (and can), figure out by how much and flip the corresponding flags
|
||||
if (obj1delta > obj2delta)
|
||||
{
|
||||
overlap = Object1.x + Object1.width - Object2.x;
|
||||
|
||||
if ((overlap > maxOverlap) || !(Object1.allowCollisions & Collision.RIGHT) || !(Object2.allowCollisions & Collision.LEFT))
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object1.touching |= Collision.RIGHT;
|
||||
Object2.touching |= Collision.LEFT;
|
||||
}
|
||||
}
|
||||
else if (obj1delta < obj2delta)
|
||||
{
|
||||
overlap = Object1.x - Object2.width - Object2.x;
|
||||
|
||||
if ((-overlap > maxOverlap) || !(Object1.allowCollisions & Collision.LEFT) || !(Object2.allowCollisions & Collision.RIGHT))
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object1.touching |= Collision.LEFT;
|
||||
Object2.touching |= Collision.RIGHT;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (overlap != 0)
|
||||
{
|
||||
var obj1v: number = Object1.velocity.x;
|
||||
var obj2v: number = Object2.velocity.x;
|
||||
|
||||
if (!obj1immovable && !obj2immovable)
|
||||
{
|
||||
overlap *= 0.5;
|
||||
Object1.x = Object1.x - overlap;
|
||||
Object2.x += overlap;
|
||||
|
||||
var obj1velocity: number = Math.sqrt((obj2v * obj2v * Object2.mass) / Object1.mass) * ((obj2v > 0) ? 1 : -1);
|
||||
var obj2velocity: number = Math.sqrt((obj1v * obj1v * Object1.mass) / Object2.mass) * ((obj1v > 0) ? 1 : -1);
|
||||
var average: number = (obj1velocity + obj2velocity) * 0.5;
|
||||
obj1velocity -= average;
|
||||
obj2velocity -= average;
|
||||
Object1.velocity.x = average + obj1velocity * Object1.elasticity;
|
||||
Object2.velocity.x = average + obj2velocity * Object2.elasticity;
|
||||
}
|
||||
else if (!obj1immovable)
|
||||
{
|
||||
Object1.x = Object1.x - overlap;
|
||||
Object1.velocity.x = obj2v - obj1v * Object1.elasticity;
|
||||
}
|
||||
else if (!obj2immovable)
|
||||
{
|
||||
Object2.x += overlap;
|
||||
Object2.velocity.x = obj1v - obj2v * Object2.elasticity;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The Y-axis component of the object separation process.
|
||||
*
|
||||
* @param Object1 Any <code>Sprite</code>.
|
||||
* @param Object2 Any other <code>Sprite</code>.
|
||||
*
|
||||
* @return Whether the objects in fact touched and were separated along the Y axis.
|
||||
*/
|
||||
public static separateY(Object1, Object2): bool {
|
||||
|
||||
//can't separate two immovable objects
|
||||
|
||||
var obj1immovable: bool = Object1.immovable;
|
||||
var obj2immovable: bool = Object2.immovable;
|
||||
|
||||
if (obj1immovable && obj2immovable)
|
||||
return false;
|
||||
|
||||
//If one of the objects is a tilemap, just pass it off.
|
||||
/*
|
||||
if (typeof Object1 === 'Tilemap')
|
||||
{
|
||||
return Object1.overlapsWithCallback(Object2, separateY);
|
||||
}
|
||||
|
||||
if (typeof Object2 === 'Tilemap')
|
||||
{
|
||||
return Object2.overlapsWithCallback(Object1, separateY, true);
|
||||
}
|
||||
*/
|
||||
|
||||
//First, get the two object deltas
|
||||
var overlap: number = 0;
|
||||
var obj1delta: number = Object1.y - Object1.last.y;
|
||||
var obj2delta: number = Object2.y - Object2.last.y;
|
||||
|
||||
if (obj1delta != obj2delta)
|
||||
{
|
||||
//Check if the Y hulls actually overlap
|
||||
var obj1deltaAbs: number = (obj1delta > 0) ? obj1delta : -obj1delta;
|
||||
var obj2deltaAbs: number = (obj2delta > 0) ? obj2delta : -obj2delta;
|
||||
var obj1rect: Rectangle = new Rectangle(Object1.x, Object1.y - ((obj1delta > 0) ? obj1delta : 0), Object1.width, Object1.height + obj1deltaAbs);
|
||||
var obj2rect: Rectangle = new Rectangle(Object2.x, Object2.y - ((obj2delta > 0) ? obj2delta : 0), Object2.width, Object2.height + obj2deltaAbs);
|
||||
|
||||
if ((obj1rect.x + obj1rect.width > obj2rect.x) && (obj1rect.x < obj2rect.x + obj2rect.width) && (obj1rect.y + obj1rect.height > obj2rect.y) && (obj1rect.y < obj2rect.y + obj2rect.height))
|
||||
{
|
||||
var maxOverlap: number = obj1deltaAbs + obj2deltaAbs + Collision.OVERLAP_BIAS;
|
||||
|
||||
//If they did overlap (and can), figure out by how much and flip the corresponding flags
|
||||
if (obj1delta > obj2delta)
|
||||
{
|
||||
overlap = Object1.y + Object1.height - Object2.y;
|
||||
|
||||
if ((overlap > maxOverlap) || !(Object1.allowCollisions & Collision.DOWN) || !(Object2.allowCollisions & Collision.UP))
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object1.touching |= Collision.DOWN;
|
||||
Object2.touching |= Collision.UP;
|
||||
}
|
||||
}
|
||||
else if (obj1delta < obj2delta)
|
||||
{
|
||||
overlap = Object1.y - Object2.height - Object2.y;
|
||||
|
||||
if ((-overlap > maxOverlap) || !(Object1.allowCollisions & Collision.UP) || !(Object2.allowCollisions & Collision.DOWN))
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object1.touching |= Collision.UP;
|
||||
Object2.touching |= Collision.DOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (overlap != 0)
|
||||
{
|
||||
var obj1v: number = Object1.velocity.y;
|
||||
var obj2v: number = Object2.velocity.y;
|
||||
|
||||
if (!obj1immovable && !obj2immovable)
|
||||
{
|
||||
overlap *= 0.5;
|
||||
Object1.y = Object1.y - overlap;
|
||||
Object2.y += overlap;
|
||||
|
||||
var obj1velocity: number = Math.sqrt((obj2v * obj2v * Object2.mass) / Object1.mass) * ((obj2v > 0) ? 1 : -1);
|
||||
var obj2velocity: number = Math.sqrt((obj1v * obj1v * Object1.mass) / Object2.mass) * ((obj1v > 0) ? 1 : -1);
|
||||
var average: number = (obj1velocity + obj2velocity) * 0.5;
|
||||
obj1velocity -= average;
|
||||
obj2velocity -= average;
|
||||
Object1.velocity.y = average + obj1velocity * Object1.elasticity;
|
||||
Object2.velocity.y = average + obj2velocity * Object2.elasticity;
|
||||
}
|
||||
else if (!obj1immovable)
|
||||
{
|
||||
Object1.y = Object1.y - overlap;
|
||||
Object1.velocity.y = obj2v - obj1v * Object1.elasticity;
|
||||
//This is special case code that handles cases like horizontal moving platforms you can ride
|
||||
if (Object2.active && Object2.moves && (obj1delta > obj2delta))
|
||||
{
|
||||
Object1.x += Object2.x - Object2.last.x;
|
||||
}
|
||||
}
|
||||
else if (!obj2immovable)
|
||||
{
|
||||
Object2.y += overlap;
|
||||
Object2.velocity.y = obj1v - obj2v * Object2.elasticity;
|
||||
//This is special case code that handles cases like horizontal moving platforms you can ride
|
||||
if (Object1.active && Object1.moves && (obj1delta < obj2delta))
|
||||
{
|
||||
Object2.x += Object1.x - Object1.last.x;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------------------------
|
||||
* Distance
|
||||
* -------------------------------------------------------------------------------------------
|
||||
**/
|
||||
|
||||
public static distance(x1: number, y1: number, x2: number, y2: number) {
|
||||
return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
|
||||
}
|
||||
|
||||
public static distanceSquared(x1: number, y1: number, x2: number, y2: number) {
|
||||
return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,12 @@
|
|||
/// <reference path="Game.ts" />
|
||||
|
||||
class DynamicTexture {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class DynamicTexture {
|
||||
|
||||
constructor(game: Game, key: string, width: number, height: number) {
|
||||
|
||||
|
@ -53,27 +59,27 @@ class DynamicTexture {
|
|||
}
|
||||
|
||||
// Returns a CanvasPixelArray
|
||||
public getPixels(rect:Rectangle) {
|
||||
public getPixels(rect: Rectangle) {
|
||||
|
||||
return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
|
||||
|
||||
}
|
||||
|
||||
public setPixel(x: number, y: number, color:number) {
|
||||
public setPixel(x: number, y: number, color: number) {
|
||||
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillRect(x, y, 1, 1);
|
||||
|
||||
}
|
||||
|
||||
public setPixel32(x: number, y: number, color:number) {
|
||||
public setPixel32(x: number, y: number, color: number) {
|
||||
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillRect(x, y, 1, 1);
|
||||
|
||||
}
|
||||
|
||||
public setPixels(rect:Rectangle, input) {
|
||||
public setPixels(rect: Rectangle, input) {
|
||||
|
||||
this.context.putImageData(input, rect.x, rect.y);
|
||||
|
||||
|
@ -201,5 +207,6 @@ class DynamicTexture {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,453 +0,0 @@
|
|||
/// <reference path="Group.ts" />
|
||||
/// <reference path="Particle.ts" />
|
||||
/// <reference path="geom/Point.ts" />
|
||||
|
||||
/**
|
||||
* <code>Emitter</code> is a lightweight particle emitter.
|
||||
* It can be used for one-time explosions or for
|
||||
* continuous fx like rain and fire. <code>Emitter</code>
|
||||
* is not optimized or anything; all it does is launch
|
||||
* <code>Particle</code> objects out at set intervals
|
||||
* by setting their positions and velocities accordingly.
|
||||
* It is easy to use and relatively efficient,
|
||||
* relying on <code>Group</code>'s RECYCLE POWERS.
|
||||
*
|
||||
* @author Adam Atomic
|
||||
* @author Richard Davey
|
||||
*/
|
||||
class Emitter extends Group {
|
||||
|
||||
/**
|
||||
* Creates a new <code>FlxEmitter</code> object at a specific position.
|
||||
* Does NOT automatically generate or attach particles!
|
||||
*
|
||||
* @param X The X position of the emitter.
|
||||
* @param Y The Y position of the emitter.
|
||||
* @param Size Optional, specifies a maximum capacity for this emitter.
|
||||
*/
|
||||
constructor(game: Game, X: number = 0, Y: number = 0, Size: number = 0) {
|
||||
super(game, Size);
|
||||
this.x = X;
|
||||
this.y = Y;
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
this.minParticleSpeed = new Point(-100, -100);
|
||||
this.maxParticleSpeed = new Point(100, 100);
|
||||
this.minRotation = -360;
|
||||
this.maxRotation = 360;
|
||||
this.gravity = 0;
|
||||
this.particleClass = null;
|
||||
this.particleDrag = new Point();
|
||||
this.frequency = 0.1;
|
||||
this.lifespan = 3;
|
||||
this.bounce = 0;
|
||||
this._quantity = 0;
|
||||
this._counter = 0;
|
||||
this._explode = true;
|
||||
this.on = false;
|
||||
this._point = new Point();
|
||||
}
|
||||
|
||||
/**
|
||||
* The X position of the top left corner of the emitter in world space.
|
||||
*/
|
||||
public x: number;
|
||||
|
||||
/**
|
||||
* The Y position of the top left corner of emitter in world space.
|
||||
*/
|
||||
public y: number;
|
||||
|
||||
/**
|
||||
* The width of the emitter. Particles can be randomly generated from anywhere within this box.
|
||||
*/
|
||||
public width: number;
|
||||
|
||||
/**
|
||||
* The height of the emitter. Particles can be randomly generated from anywhere within this box.
|
||||
*/
|
||||
public height: number;
|
||||
|
||||
/**
|
||||
* The minimum possible velocity of a particle.
|
||||
* The default value is (-100,-100).
|
||||
*/
|
||||
public minParticleSpeed: Point;
|
||||
|
||||
/**
|
||||
* The maximum possible velocity of a particle.
|
||||
* The default value is (100,100).
|
||||
*/
|
||||
public maxParticleSpeed: Point;
|
||||
|
||||
/**
|
||||
* The X and Y drag component of particles launched from the emitter.
|
||||
*/
|
||||
public particleDrag: Point;
|
||||
|
||||
/**
|
||||
* The minimum possible angular velocity of a particle. The default value is -360.
|
||||
* NOTE: rotating particles are more expensive to draw than non-rotating ones!
|
||||
*/
|
||||
public minRotation: number;
|
||||
|
||||
/**
|
||||
* The maximum possible angular velocity of a particle. The default value is 360.
|
||||
* NOTE: rotating particles are more expensive to draw than non-rotating ones!
|
||||
*/
|
||||
public maxRotation: number;
|
||||
|
||||
/**
|
||||
* Sets the <code>acceleration.y</code> member of each particle to this value on launch.
|
||||
*/
|
||||
public gravity: number;
|
||||
|
||||
/**
|
||||
* Determines whether the emitter is currently emitting particles.
|
||||
* It is totally safe to directly toggle this.
|
||||
*/
|
||||
public on: bool;
|
||||
|
||||
/**
|
||||
* How often a particle is emitted (if emitter is started with Explode == false).
|
||||
*/
|
||||
public frequency: number;
|
||||
|
||||
/**
|
||||
* How long each particle lives once it is emitted.
|
||||
* Set lifespan to 'zero' for particles to live forever.
|
||||
*/
|
||||
public lifespan: number;
|
||||
|
||||
/**
|
||||
* How much each particle should bounce. 1 = full bounce, 0 = no bounce.
|
||||
*/
|
||||
public bounce: number;
|
||||
|
||||
/**
|
||||
* Set your own particle class type here.
|
||||
* Default is <code>Particle</code>.
|
||||
*/
|
||||
public particleClass;
|
||||
|
||||
/**
|
||||
* Internal helper for deciding how many particles to launch.
|
||||
*/
|
||||
private _quantity: number;
|
||||
|
||||
/**
|
||||
* Internal helper for the style of particle emission (all at once, or one at a time).
|
||||
*/
|
||||
private _explode: bool;
|
||||
|
||||
/**
|
||||
* Internal helper for deciding when to launch particles or kill them.
|
||||
*/
|
||||
private _timer: number;
|
||||
|
||||
/**
|
||||
* Internal counter for figuring out how many particles to launch.
|
||||
*/
|
||||
private _counter: number;
|
||||
|
||||
/**
|
||||
* Internal point object, handy for reusing for memory mgmt purposes.
|
||||
*/
|
||||
private _point: Point;
|
||||
|
||||
/**
|
||||
* Clean up memory.
|
||||
*/
|
||||
public destroy() {
|
||||
this.minParticleSpeed = null;
|
||||
this.maxParticleSpeed = null;
|
||||
this.particleDrag = null;
|
||||
this.particleClass = null;
|
||||
this._point = null;
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function generates a new array of particle sprites to attach to the emitter.
|
||||
*
|
||||
* @param Graphics If you opted to not pre-configure an array of FlxSprite objects, you can simply pass in a particle image or sprite sheet.
|
||||
* @param Quantity The number of particles to generate when using the "create from image" option.
|
||||
* @param BakedRotations How many frames of baked rotation to use (boosts performance). Set to zero to not use baked rotations.
|
||||
* @param Multiple Whether the image in the Graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!).
|
||||
* @param Collide Whether the particles should be flagged as not 'dead' (non-colliding particles are higher performance). 0 means no collisions, 0-1 controls scale of particle's bounding box.
|
||||
*
|
||||
* @return This FlxEmitter instance (nice for chaining stuff together, if you're into that).
|
||||
*/
|
||||
public makeParticles(Graphics, Quantity: number = 50, BakedRotations: number = 16, Multiple: bool = false, Collide: number = 0.8): Emitter {
|
||||
|
||||
this.maxSize = Quantity;
|
||||
|
||||
var totalFrames: number = 1;
|
||||
|
||||
/*
|
||||
if(Multiple)
|
||||
{
|
||||
var sprite:Sprite = new Sprite(this._game);
|
||||
sprite.loadGraphic(Graphics,true);
|
||||
totalFrames = sprite.frames;
|
||||
sprite.destroy();
|
||||
}
|
||||
*/
|
||||
|
||||
var randomFrame: number;
|
||||
var particle: Particle;
|
||||
var i: number = 0;
|
||||
|
||||
while (i < Quantity)
|
||||
{
|
||||
if (this.particleClass == null)
|
||||
{
|
||||
particle = new Particle(this._game);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle = new this.particleClass(this._game);
|
||||
}
|
||||
|
||||
if (Multiple)
|
||||
{
|
||||
/*
|
||||
randomFrame = this._game.math.random()*totalFrames;
|
||||
if(BakedRotations > 0)
|
||||
particle.loadRotatedGraphic(Graphics,BakedRotations,randomFrame);
|
||||
else
|
||||
{
|
||||
particle.loadGraphic(Graphics,true);
|
||||
particle.frame = randomFrame;
|
||||
}
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
if (BakedRotations > 0)
|
||||
particle.loadRotatedGraphic(Graphics,BakedRotations);
|
||||
else
|
||||
particle.loadGraphic(Graphics);
|
||||
*/
|
||||
|
||||
if (Graphics)
|
||||
{
|
||||
particle.loadGraphic(Graphics);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Collide > 0)
|
||||
{
|
||||
particle.width *= Collide;
|
||||
particle.height *= Collide;
|
||||
//particle.centerOffsets();
|
||||
}
|
||||
else
|
||||
{
|
||||
particle.allowCollisions = GameObject.NONE;
|
||||
}
|
||||
|
||||
particle.exists = false;
|
||||
|
||||
this.add(particle);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called automatically by the game loop, decides when to launch particles and when to "die".
|
||||
*/
|
||||
public update() {
|
||||
|
||||
if (this.on)
|
||||
{
|
||||
if (this._explode)
|
||||
{
|
||||
this.on = false;
|
||||
|
||||
var i: number = 0;
|
||||
var l: number = this._quantity;
|
||||
|
||||
if ((l <= 0) || (l > this.length))
|
||||
{
|
||||
l = this.length;
|
||||
}
|
||||
|
||||
while (i < l)
|
||||
{
|
||||
this.emitParticle();
|
||||
i++;
|
||||
}
|
||||
|
||||
this._quantity = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._timer += this._game.time.elapsed;
|
||||
|
||||
while ((this.frequency > 0) && (this._timer > this.frequency) && this.on)
|
||||
{
|
||||
this._timer -= this.frequency;
|
||||
this.emitParticle();
|
||||
|
||||
if ((this._quantity > 0) && (++this._counter >= this._quantity))
|
||||
{
|
||||
this.on = false;
|
||||
this._quantity = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.update();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this function to turn off all the particles and the emitter.
|
||||
*/
|
||||
public kill() {
|
||||
|
||||
this.on = false;
|
||||
|
||||
super.kill();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this function to start emitting particles.
|
||||
*
|
||||
* @param Explode Whether the particles should all burst out at once.
|
||||
* @param Lifespan How long each particle lives once emitted. 0 = forever.
|
||||
* @param Frequency Ignored if Explode is set to true. Frequency is how often to emit a particle. 0 = never emit, 0.1 = 1 particle every 0.1 seconds, 5 = 1 particle every 5 seconds.
|
||||
* @param Quantity How many particles to launch. 0 = "all of the particles".
|
||||
*/
|
||||
public start(Explode: bool = true, Lifespan: number = 0, Frequency: number = 0.1, Quantity: number = 0) {
|
||||
|
||||
this.revive();
|
||||
|
||||
this.visible = true;
|
||||
this.on = true;
|
||||
|
||||
this._explode = Explode;
|
||||
this.lifespan = Lifespan;
|
||||
this.frequency = Frequency;
|
||||
this._quantity += Quantity;
|
||||
|
||||
this._counter = 0;
|
||||
this._timer = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function can be used both internally and externally to emit the next particle.
|
||||
*/
|
||||
public emitParticle() {
|
||||
|
||||
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.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);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle.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);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle.velocity.y = this.minParticleSpeed.y;
|
||||
}
|
||||
|
||||
particle.acceleration.y = this.gravity;
|
||||
|
||||
if (this.minRotation != this.maxRotation)
|
||||
{
|
||||
particle.angularVelocity = this.minRotation + this._game.math.random() * (this.maxRotation - this.minRotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle.angularVelocity = this.minRotation;
|
||||
}
|
||||
|
||||
if (particle.angularVelocity != 0)
|
||||
{
|
||||
particle.angle = this._game.math.random() * 360 - 180;
|
||||
}
|
||||
|
||||
particle.drag.x = this.particleDrag.x;
|
||||
particle.drag.y = this.particleDrag.y;
|
||||
particle.onEmit();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A more compact way of setting the width and height of the emitter.
|
||||
*
|
||||
* @param Width The desired width of the emitter (particles are spawned randomly within these dimensions).
|
||||
* @param Height The desired height of the emitter.
|
||||
*/
|
||||
public setSize(Width: number, Height: number) {
|
||||
this.width = Width;
|
||||
this.height = Height;
|
||||
}
|
||||
|
||||
/**
|
||||
* A more compact way of setting the X velocity range of the emitter.
|
||||
*
|
||||
* @param Min The minimum value for this range.
|
||||
* @param Max The maximum value for this range.
|
||||
*/
|
||||
public setXSpeed(Min: number = 0, Max: number = 0) {
|
||||
this.minParticleSpeed.x = Min;
|
||||
this.maxParticleSpeed.x = Max;
|
||||
}
|
||||
|
||||
/**
|
||||
* A more compact way of setting the Y velocity range of the emitter.
|
||||
*
|
||||
* @param Min The minimum value for this range.
|
||||
* @param Max The maximum value for this range.
|
||||
*/
|
||||
public setYSpeed(Min: number = 0, Max: number = 0) {
|
||||
this.minParticleSpeed.y = Min;
|
||||
this.maxParticleSpeed.y = Max;
|
||||
}
|
||||
|
||||
/**
|
||||
* A more compact way of setting the angular velocity constraints of the emitter.
|
||||
*
|
||||
* @param Min The minimum value for this range.
|
||||
* @param Max The maximum value for this range.
|
||||
*/
|
||||
public setRotation(Min: number = 0, Max: number = 0) {
|
||||
this.minRotation = Min;
|
||||
this.maxRotation = Max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the emitter's midpoint to match the midpoint of a <code>FlxObject</code>.
|
||||
*
|
||||
* @param Object The <code>FlxObject</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);
|
||||
}
|
||||
}
|
|
@ -1,37 +1,46 @@
|
|||
/// <reference path="Animations.ts" />
|
||||
/// <reference path="Basic.ts" />
|
||||
/// <reference path="Cache.ts" />
|
||||
/// <reference path="Cameras.ts" />
|
||||
/// <reference path="Emitter.ts" />
|
||||
/// <reference path="Collision.ts" />
|
||||
/// <reference path="DynamicTexture.ts" />
|
||||
/// <reference path="GameMath.ts" />
|
||||
/// <reference path="Group.ts" />
|
||||
/// <reference path="Loader.ts" />
|
||||
/// <reference path="Motion.ts" />
|
||||
/// <reference path="Signal.ts" />
|
||||
/// <reference path="SignalBinding.ts" />
|
||||
/// <reference path="Sound.ts" />
|
||||
/// <reference path="Sprite.ts" />
|
||||
/// <reference path="Stage.ts" />
|
||||
/// <reference path="Time.ts" />
|
||||
/// <reference path="GameMath.ts" />
|
||||
/// <reference path="TweenManager.ts" />
|
||||
/// <reference path="World.ts" />
|
||||
/// <reference path="system/input/Input.ts" />
|
||||
/// <reference path="system/RequestAnimationFrame.ts" />
|
||||
/// <reference path="system/RandomDataGenerator.ts" />
|
||||
/// <reference path="system/Device.ts" />
|
||||
/// <reference path="system/RandomDataGenerator.ts" />
|
||||
/// <reference path="system/RequestAnimationFrame.ts" />
|
||||
/// <reference path="system/input/Input.ts" />
|
||||
/// <reference path="system/input/Keyboard.ts" />
|
||||
/// <reference path="system/input/Mouse.ts" />
|
||||
/// <reference path="system/input/Touch.ts" />
|
||||
/// <reference path="gameobjects/Emitter.ts" />
|
||||
/// <reference path="gameobjects/GameObject.ts" />
|
||||
/// <reference path="gameobjects/GeomSprite.ts" />
|
||||
/// <reference path="gameobjects/Particle.ts" />
|
||||
/// <reference path="gameobjects/Sprite.ts" />
|
||||
/// <reference path="gameobjects/Tilemap.ts" />
|
||||
|
||||
/**
|
||||
* Phaser
|
||||
*
|
||||
* v0.8 - April 15th 2013
|
||||
*
|
||||
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
||||
*
|
||||
* Richard Davey (@photonstorm)
|
||||
* Adam Saltsman (@ADAMATOMIC) (original Flixel code)
|
||||
*
|
||||
* "If you want your children to be intelligent, read them fairy tales."
|
||||
* "If you want them to be more intelligent, read them more fairy tales."
|
||||
* -- Albert Einstein
|
||||
*/
|
||||
|
||||
class Game {
|
||||
module Phaser {
|
||||
|
||||
constructor(callbackContext, parent?:string = '', width?: number = 800, height?: number = 600, initCallback = null, createCallback = null, updateCallback = null, renderCallback = null) {
|
||||
export class Game {
|
||||
|
||||
constructor(callbackContext, parent?: string = '', width?: number = 800, height?: number = 600, initCallback = null, createCallback = null, updateCallback = null, renderCallback = null) {
|
||||
|
||||
this.callbackContext = callbackContext;
|
||||
this.onInitCallback = initCallback;
|
||||
|
@ -50,8 +59,6 @@ class Game {
|
|||
|
||||
}
|
||||
|
||||
public static VERSION: string = 'Phaser version 0.8';
|
||||
|
||||
private _raf: RequestAnimationFrame;
|
||||
private _maxAccumulation: number = 32;
|
||||
private _accumulator: number = 0;
|
||||
|
@ -70,19 +77,22 @@ class Game {
|
|||
|
||||
public camera: Camera; // quick reference to the default created camera, access the rest via .world
|
||||
public cache: Cache;
|
||||
public collision: Collision;
|
||||
public input: Input;
|
||||
public loader: Loader;
|
||||
public math: GameMath;
|
||||
public motion: Motion;
|
||||
public sound: SoundManager;
|
||||
public stage: Stage;
|
||||
public time: Time;
|
||||
public math: GameMath;
|
||||
public tweens: TweenManager;
|
||||
public world: World;
|
||||
public rnd: RandomDataGenerator;
|
||||
public device: Device;
|
||||
|
||||
public isBooted: bool = false;
|
||||
|
||||
private boot(parent:string, width: number, height: number) {
|
||||
private boot(parent: string, width: number, height: number) {
|
||||
|
||||
if (!document.body)
|
||||
{
|
||||
|
@ -91,14 +101,17 @@ class Game {
|
|||
else
|
||||
{
|
||||
this.device = new Device();
|
||||
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.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);
|
||||
this.input = new Input(this);
|
||||
this.math = new GameMath(this);
|
||||
this.rnd = new RandomDataGenerator([(Date.now() * Math.random()).toString()]);
|
||||
|
||||
this.framerate = 60;
|
||||
|
@ -140,6 +153,9 @@ class Game {
|
|||
|
||||
private loop() {
|
||||
|
||||
this.time.update();
|
||||
this.tweens.update();
|
||||
|
||||
if (this._paused == true)
|
||||
{
|
||||
if (this.onPausedCallback !== null)
|
||||
|
@ -151,7 +167,6 @@ class Game {
|
|||
|
||||
}
|
||||
|
||||
this.time.update();
|
||||
this.input.update();
|
||||
this.stage.update();
|
||||
|
||||
|
@ -211,7 +226,7 @@ class Game {
|
|||
|
||||
}
|
||||
|
||||
public switchState(state, clearWorld: bool = true, clearCache:bool = false) {
|
||||
public switchState(state, clearWorld: bool = true, clearCache: bool = false) {
|
||||
|
||||
if (this.isBooted == false)
|
||||
{
|
||||
|
@ -300,17 +315,16 @@ class Game {
|
|||
this.sound = null;
|
||||
this.stage = null;
|
||||
this.time = null;
|
||||
this.math = null;
|
||||
this.world = null;
|
||||
this.isBooted = false;
|
||||
|
||||
}
|
||||
|
||||
public get pause(): bool {
|
||||
public get paused(): bool {
|
||||
return this._paused;
|
||||
}
|
||||
|
||||
public set pause(value:bool) {
|
||||
public set paused(value: bool) {
|
||||
|
||||
if (value == true && this._paused == false)
|
||||
{
|
||||
|
@ -346,6 +360,10 @@ class Game {
|
|||
return this.world.createCamera(x, y, width, height);
|
||||
}
|
||||
|
||||
public createGeomSprite(x: number, y: number): GeomSprite {
|
||||
return this.world.createGeomSprite(x, y);
|
||||
}
|
||||
|
||||
public createSprite(x: number, y: number, key?: string = ''): Sprite {
|
||||
return this.world.createSprite(x, y, key);
|
||||
}
|
||||
|
@ -362,16 +380,22 @@ class Game {
|
|||
return this.world.createParticle();
|
||||
}
|
||||
|
||||
public createEmitter(x?: number = 0, y?: number = 0, size?:number = 0): Emitter {
|
||||
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
||||
return this.world.createEmitter(x, y, size);
|
||||
}
|
||||
|
||||
public createTilemap(key:string, mapData:string, format:number, tileWidth?:number,tileHeight?:number): Tilemap {
|
||||
public createTilemap(key: string, mapData: string, format: number, tileWidth?: number, tileHeight?: number): Tilemap {
|
||||
return this.world.createTilemap(key, mapData, format, tileWidth, tileHeight);
|
||||
}
|
||||
|
||||
public createTween(obj): Tween {
|
||||
return this.tweens.create(obj);
|
||||
}
|
||||
|
||||
public collide(ObjectOrGroup1: Basic = null, ObjectOrGroup2: Basic = null, NotifyCallback = null): bool {
|
||||
return this.world.overlap(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, World.separate);
|
||||
return this.collision.overlap(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, Collision.separate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -10,7 +10,9 @@
|
|||
* @author Richard Davey
|
||||
*/
|
||||
|
||||
class GameMath {
|
||||
module Phaser {
|
||||
|
||||
export class GameMath {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
|
@ -64,14 +66,6 @@ class GameMath {
|
|||
public cosTable = [];
|
||||
public sinTable = [];
|
||||
|
||||
public computeMachineEpsilon(): number {
|
||||
// Machine epsilon ala Eispack
|
||||
var fourThirds: number = 4.0 / 3.0;
|
||||
var third: number = fourThirds - 1.0;
|
||||
var one: number = third + third + third;
|
||||
return Math.abs(1.0 - one);
|
||||
}
|
||||
|
||||
public fuzzyEqual(a: number, b: number, epsilon: number = 0.0001): bool {
|
||||
return Math.abs(a - b) < epsilon;
|
||||
}
|
||||
|
@ -833,71 +827,6 @@ class GameMath {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* A tween-like function that takes a starting velocity
|
||||
* and some other factors and returns an altered velocity.
|
||||
*
|
||||
* @param Velocity Any component of velocity (e.g. 20).
|
||||
* @param Acceleration Rate at which the velocity is changing.
|
||||
* @param Drag Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
|
||||
* @param Max An absolute value cap for the velocity.
|
||||
*
|
||||
* @return 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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the angle and speed calculate the velocity and return it as a Point
|
||||
*
|
||||
* @param angle The angle (in degrees) calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
|
||||
* @param speed The speed it will move, in pixels per second sq
|
||||
*
|
||||
* @return A Point where Point.x contains the velocity x value and Point.y contains the velocity y value
|
||||
*/
|
||||
public velocityFromAngle(angle: number, speed: number): Point {
|
||||
var a: number = this.degreesToRadians(angle);
|
||||
|
||||
return new Point((Math.cos(a) * speed), (Math.sin(a) * speed));
|
||||
}
|
||||
|
||||
/**
|
||||
* The global random number generator seed (for deterministic behavior in recordings and saves).
|
||||
*/
|
||||
|
@ -1019,6 +948,35 @@ class GameMath {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,499 +0,0 @@
|
|||
/// <reference path="Basic.ts" />
|
||||
/// <reference path="Game.ts" />
|
||||
/// <reference path="GameMath.ts" />
|
||||
/// <reference path="geom/Rectangle.ts" />
|
||||
/// <reference path="geom/Point.ts" />
|
||||
|
||||
class GameObject extends Basic {
|
||||
|
||||
constructor(game:Game, x?: number = 0, y?: number = 0, width?: number = 16, height?: number = 16) {
|
||||
|
||||
super(game);
|
||||
|
||||
this.bounds = 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 Point(1, 1);
|
||||
|
||||
this.last = new Point(x, y);
|
||||
this.origin = new Point(this.bounds.halfWidth, this.bounds.halfHeight);
|
||||
this.mass = 1.0;
|
||||
this.elasticity = 0.0;
|
||||
this.health = 1;
|
||||
this.immovable = false;
|
||||
this.moves = true;
|
||||
|
||||
this.touching = GameObject.NONE;
|
||||
this.wasTouching = GameObject.NONE;
|
||||
this.allowCollisions = GameObject.ANY;
|
||||
|
||||
this.velocity = new Point();
|
||||
this.acceleration = new Point();
|
||||
this.drag = new Point();
|
||||
this.maxVelocity = new Point(10000, 10000);
|
||||
|
||||
this.angle = 0;
|
||||
this.angularVelocity = 0;
|
||||
this.angularAcceleration = 0;
|
||||
this.angularDrag = 0;
|
||||
this.maxAngular = 10000;
|
||||
|
||||
this.scrollFactor = new Point(1.0, 1.0);
|
||||
|
||||
}
|
||||
|
||||
private _angle: number = 0;
|
||||
public _point: Point;
|
||||
|
||||
public static LEFT: number = 0x0001;
|
||||
public static RIGHT: number = 0x0010;
|
||||
public static UP: number = 0x0100;
|
||||
public static DOWN: number = 0x1000;
|
||||
public static NONE: number = 0;
|
||||
public static CEILING: number = GameObject.UP;
|
||||
public static FLOOR: number = GameObject.DOWN;
|
||||
public static WALL: number = GameObject.LEFT | GameObject.RIGHT;
|
||||
public static ANY: number = GameObject.LEFT | GameObject.RIGHT | GameObject.UP | GameObject.DOWN;
|
||||
public static OVERLAP_BIAS: number = 4;
|
||||
|
||||
public bounds: Rectangle;
|
||||
public alpha: number;
|
||||
public scale: Point;
|
||||
public origin: Point;
|
||||
|
||||
// Physics properties
|
||||
public immovable: bool;
|
||||
public velocity: Point;
|
||||
public mass: number;
|
||||
public elasticity: number;
|
||||
public acceleration: Point;
|
||||
public drag: Point;
|
||||
public maxVelocity: Point;
|
||||
public angularVelocity: number;
|
||||
public angularAcceleration: number;
|
||||
public angularDrag: number;
|
||||
public maxAngular: number;
|
||||
public scrollFactor: Point;
|
||||
|
||||
public health: number;
|
||||
public moves: bool = true;
|
||||
public touching: number;
|
||||
public wasTouching: number;
|
||||
public allowCollisions: number;
|
||||
public last: Point;
|
||||
|
||||
public preUpdate() {
|
||||
|
||||
// flicker time
|
||||
|
||||
this.last.x = this.bounds.x;
|
||||
this.last.y = this.bounds.y;
|
||||
|
||||
}
|
||||
|
||||
public update() {
|
||||
}
|
||||
|
||||
public postUpdate() {
|
||||
|
||||
if (this.moves)
|
||||
{
|
||||
this.updateMotion();
|
||||
}
|
||||
|
||||
this.wasTouching = this.touching;
|
||||
this.touching = GameObject.NONE;
|
||||
|
||||
}
|
||||
|
||||
private updateMotion() {
|
||||
|
||||
var delta: number;
|
||||
var velocityDelta: number;
|
||||
|
||||
velocityDelta = (this._game.math.computeVelocity(this.angularVelocity, this.angularAcceleration, this.angularDrag, this.maxAngular) - this.angularVelocity) / 2;
|
||||
this.angularVelocity += velocityDelta;
|
||||
this._angle += this.angularVelocity * this._game.time.elapsed;
|
||||
this.angularVelocity += velocityDelta;
|
||||
|
||||
velocityDelta = (this._game.math.computeVelocity(this.velocity.x, this.acceleration.x, this.drag.x, this.maxVelocity.x) - this.velocity.x) / 2;
|
||||
this.velocity.x += velocityDelta;
|
||||
delta = this.velocity.x * this._game.time.elapsed;
|
||||
this.velocity.x += velocityDelta;
|
||||
this.bounds.x += delta;
|
||||
|
||||
velocityDelta = (this._game.math.computeVelocity(this.velocity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y) - this.velocity.y) / 2;
|
||||
this.velocity.y += velocityDelta;
|
||||
delta = this.velocity.y * this._game.time.elapsed;
|
||||
this.velocity.y += velocityDelta;
|
||||
this.bounds.y += delta;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if some <code>GameObject</code> overlaps this <code>GameObject</code> or <code>FlxGroup</code>.
|
||||
* If the group has a LOT of things in it, it might be faster to use <code>FlxG.overlaps()</code>.
|
||||
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
|
||||
*
|
||||
* @param ObjectOrGroup The object or group being tested.
|
||||
* @param InScreenSpace Whether to take scroll factors numbero account when checking for overlap. Default is false, or "only compare in world space."
|
||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
*
|
||||
* @return Whether or not the two objects overlap.
|
||||
*/
|
||||
public overlaps(ObjectOrGroup, InScreenSpace: bool = false, Camera: Camera = null): bool {
|
||||
|
||||
if (ObjectOrGroup.isGroup)
|
||||
{
|
||||
var results: bool = false;
|
||||
var i: number = 0;
|
||||
var members = <Group> ObjectOrGroup.members;
|
||||
|
||||
while (i < length)
|
||||
{
|
||||
if (this.overlaps(members[i++], InScreenSpace, Camera))
|
||||
{
|
||||
results = true;
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
if (typeof ObjectOrGroup === 'FlxTilemap')
|
||||
{
|
||||
//Since tilemap's have to be the caller, not the target, to do proper tile-based collisions,
|
||||
// we redirect the call to the tilemap overlap here.
|
||||
return ObjectOrGroup.overlaps(this, InScreenSpace, Camera);
|
||||
}
|
||||
*/
|
||||
|
||||
//var object: GameObject = ObjectOrGroup;
|
||||
|
||||
if (!InScreenSpace)
|
||||
{
|
||||
return (ObjectOrGroup.x + ObjectOrGroup.width > this.x) && (ObjectOrGroup.x < this.x + this.width) &&
|
||||
(ObjectOrGroup.y + ObjectOrGroup.height > this.y) && (ObjectOrGroup.y < this.y + this.height);
|
||||
}
|
||||
|
||||
if (Camera == null)
|
||||
{
|
||||
Camera = this._game.camera;
|
||||
}
|
||||
|
||||
var objectScreenPos: Point = ObjectOrGroup.getScreenXY(null, Camera);
|
||||
|
||||
this.getScreenXY(this._point, Camera);
|
||||
|
||||
return (objectScreenPos.x + ObjectOrGroup.width > this._point.x) && (objectScreenPos.x < this._point.x + this.width) &&
|
||||
(objectScreenPos.y + ObjectOrGroup.height > this._point.y) && (objectScreenPos.y < this._point.y + this.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if this <code>GameObject</code> were located at the given position, would it overlap the <code>GameObject</code> or <code>FlxGroup</code>?
|
||||
* This is distinct from overlapsPoint(), which just checks that ponumber, rather than taking the object's size numbero account.
|
||||
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
|
||||
*
|
||||
* @param X The X position you want to check. Pretends this object (the caller, not the parameter) is located here.
|
||||
* @param Y The Y position you want to check. Pretends this object (the caller, not the parameter) is located here.
|
||||
* @param ObjectOrGroup The object or group being tested.
|
||||
* @param InScreenSpace Whether to take scroll factors numbero account when checking for overlap. Default is false, or "only compare in world space."
|
||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
*
|
||||
* @return Whether or not the two objects overlap.
|
||||
*/
|
||||
public overlapsAt(X: number, Y: number, ObjectOrGroup, InScreenSpace: bool = false, Camera: Camera = null): bool {
|
||||
|
||||
if (ObjectOrGroup.isGroup)
|
||||
{
|
||||
var results: bool = false;
|
||||
var basic;
|
||||
var i: number = 0;
|
||||
var members = ObjectOrGroup.members;
|
||||
|
||||
while (i < length)
|
||||
{
|
||||
if (this.overlapsAt(X, Y, members[i++], InScreenSpace, Camera))
|
||||
{
|
||||
results = true;
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/*
|
||||
if (typeof ObjectOrGroup === 'FlxTilemap')
|
||||
{
|
||||
//Since tilemap's have to be the caller, not the target, to do proper tile-based collisions,
|
||||
// we redirect the call to the tilemap overlap here.
|
||||
//However, since this is overlapsAt(), we also have to invent the appropriate position for the tilemap.
|
||||
//So we calculate the offset between the player and the requested position, and subtract that from the tilemap.
|
||||
var tilemap: FlxTilemap = ObjectOrGroup;
|
||||
return tilemap.overlapsAt(tilemap.x - (X - this.x), tilemap.y - (Y - this.y), this, InScreenSpace, Camera);
|
||||
}
|
||||
*/
|
||||
|
||||
//var object: GameObject = ObjectOrGroup;
|
||||
|
||||
if (!InScreenSpace)
|
||||
{
|
||||
return (ObjectOrGroup.x + ObjectOrGroup.width > X) && (ObjectOrGroup.x < X + this.width) &&
|
||||
(ObjectOrGroup.y + ObjectOrGroup.height > Y) && (ObjectOrGroup.y < Y + this.height);
|
||||
}
|
||||
|
||||
if (Camera == null)
|
||||
{
|
||||
Camera = this._game.camera;
|
||||
}
|
||||
|
||||
var objectScreenPos: Point = ObjectOrGroup.getScreenXY(null, Camera);
|
||||
|
||||
this._point.x = X - Camera.scroll.x * this.scrollFactor.x; //copied from getScreenXY()
|
||||
this._point.y = Y - Camera.scroll.y * this.scrollFactor.y;
|
||||
this._point.x += (this._point.x > 0) ? 0.0000001 : -0.0000001;
|
||||
this._point.y += (this._point.y > 0) ? 0.0000001 : -0.0000001;
|
||||
|
||||
return (objectScreenPos.x + ObjectOrGroup.width > this._point.x) && (objectScreenPos.x < this._point.x + this.width) &&
|
||||
(objectScreenPos.y + ObjectOrGroup.height > this._point.y) && (objectScreenPos.y < this._point.y + this.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a ponumber in 2D world space overlaps this <code>GameObject</code> object.
|
||||
*
|
||||
* @param Point The ponumber in world space you want to check.
|
||||
* @param InScreenSpace Whether to take scroll factors numbero account when checking for overlap.
|
||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
*
|
||||
* @return Whether or not the ponumber overlaps this object.
|
||||
*/
|
||||
public overlapsPoint(point: Point, InScreenSpace: bool = false, Camera: Camera = null): bool {
|
||||
|
||||
if (!InScreenSpace)
|
||||
{
|
||||
return (point.x > this.x) && (point.x < this.x + this.width) && (point.y > this.y) && (point.y < this.y + this.height);
|
||||
}
|
||||
|
||||
if (Camera == null)
|
||||
{
|
||||
Camera = this._game.camera;
|
||||
}
|
||||
|
||||
var X: number = point.x - Camera.scroll.x;
|
||||
var Y: number = point.y - Camera.scroll.y;
|
||||
|
||||
this.getScreenXY(this._point, Camera);
|
||||
|
||||
return (X > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and see if this object is currently on screen.
|
||||
*
|
||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
*
|
||||
* @return Whether the object is on screen or not.
|
||||
*/
|
||||
public onScreen(Camera: Camera = null): bool {
|
||||
|
||||
if (Camera == null)
|
||||
{
|
||||
Camera = this._game.camera;
|
||||
}
|
||||
|
||||
this.getScreenXY(this._point, Camera);
|
||||
|
||||
return (this._point.x + this.width > 0) && (this._point.x < Camera.width) && (this._point.y + this.height > 0) && (this._point.y < Camera.height);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this to figure out the on-screen position of the object.
|
||||
*
|
||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
* @param Point Takes a <code>Point</code> object and assigns the post-scrolled X and Y values of this object to it.
|
||||
*
|
||||
* @return 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.
|
||||
*/
|
||||
public getScreenXY(point: Point = null, Camera: Camera = null): Point {
|
||||
|
||||
if (point == null)
|
||||
{
|
||||
point = new Point();
|
||||
}
|
||||
|
||||
if (Camera == null)
|
||||
{
|
||||
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 += (point.x > 0) ? 0.0000001 : -0.0000001;
|
||||
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
|
||||
|
||||
return point;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the object collides or not. For more control over what directions
|
||||
* the object will collide from, use collision constants (like LEFT, FLOOR, etc)
|
||||
* to set the value of allowCollisions directly.
|
||||
*/
|
||||
public get solid(): bool {
|
||||
return (this.allowCollisions & GameObject.ANY) > GameObject.NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
public set solid(Solid: bool) {
|
||||
|
||||
if (Solid)
|
||||
{
|
||||
this.allowCollisions = GameObject.ANY;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.allowCollisions = GameObject.NONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the midponumber of this object in world coordinates.
|
||||
*
|
||||
* @Point Allows you to pass in an existing <code>Point</code> object if you're so inclined. Otherwise a new one is created.
|
||||
*
|
||||
* @return A <code>Point</code> object containing the midponumber of this object in world coordinates.
|
||||
*/
|
||||
public getMidpoint(point: Point = null): Point {
|
||||
|
||||
if (point == null)
|
||||
{
|
||||
point = new Point();
|
||||
}
|
||||
|
||||
point.x = this.x + this.width * 0.5;
|
||||
point.y = this.y + this.height * 0.5;
|
||||
|
||||
return point;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handy for reviving game objects.
|
||||
* Resets their existence flags and position.
|
||||
*
|
||||
* @param X The new X position of this object.
|
||||
* @param Y The new Y position of this object.
|
||||
*/
|
||||
public reset(X: number, Y: number) {
|
||||
|
||||
this.revive();
|
||||
this.touching = GameObject.NONE;
|
||||
this.wasTouching = GameObject.NONE;
|
||||
this.x = X;
|
||||
this.y = Y;
|
||||
this.last.x = X;
|
||||
this.last.y = Y;
|
||||
this.velocity.x = 0;
|
||||
this.velocity.y = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handy for checking if this object is touching a particular surface.
|
||||
* For slightly better performance you can just & the value directly numbero <code>touching</code>.
|
||||
* However, this method is good for readability and accessibility.
|
||||
*
|
||||
* @param Direction Any of the collision flags (e.g. LEFT, FLOOR, etc).
|
||||
*
|
||||
* @return Whether the object is touching an object in (any of) the specified direction(s) this frame.
|
||||
*/
|
||||
public isTouching(Direction: number): bool {
|
||||
return (this.touching & Direction) > GameObject.NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handy for checking if this object is just landed on a particular surface.
|
||||
*
|
||||
* @param Direction Any of the collision flags (e.g. LEFT, FLOOR, etc).
|
||||
*
|
||||
* @return Whether the object just landed on (any of) the specified surface(s) this frame.
|
||||
*/
|
||||
public justTouched(Direction: number): bool {
|
||||
return ((this.touching & Direction) > GameObject.NONE) && ((this.wasTouching & Direction) <= GameObject.NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces the "health" variable of this sprite by the amount specified in Damage.
|
||||
* Calls kill() if health drops to or below zero.
|
||||
*
|
||||
* @param Damage 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
|
||||
}
|
||||
|
||||
public get x(): number {
|
||||
return this.bounds.x;
|
||||
}
|
||||
|
||||
public set x(value: number) {
|
||||
this.bounds.x = value;
|
||||
}
|
||||
|
||||
public get y(): number {
|
||||
return this.bounds.y;
|
||||
}
|
||||
|
||||
public set y(value: number) {
|
||||
this.bounds.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 get width(): number {
|
||||
return this.bounds.width;
|
||||
}
|
||||
|
||||
public get height(): number {
|
||||
return this.bounds.height;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/// <reference path="Basic.ts" />
|
||||
/// <reference path="Sprite.ts" />
|
||||
/// <reference path="Game.ts" />
|
||||
|
||||
/**
|
||||
* This is an organizational class that can update and render a bunch of <code>Basic</code>s.
|
||||
|
@ -9,7 +9,14 @@
|
|||
* @author Adam Atomic
|
||||
* @author Richard Davey
|
||||
*/
|
||||
class Group extends Basic {
|
||||
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Group extends Basic {
|
||||
|
||||
constructor(game: Game, MaxSize?: number = 0) {
|
||||
|
||||
|
@ -119,10 +126,10 @@ class Group extends Basic {
|
|||
/**
|
||||
* Automatically goes through and calls render on everything you added.
|
||||
*/
|
||||
public render(camera:Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
||||
|
||||
var basic:Basic;
|
||||
var i:number = 0;
|
||||
var basic: Basic;
|
||||
var i: number = 0;
|
||||
|
||||
while (i < this.length)
|
||||
{
|
||||
|
@ -739,4 +746,6 @@ class Group extends Basic {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,12 @@
|
|||
/// <reference path="Cache.ts" />
|
||||
/// <reference path="Game.ts" />
|
||||
|
||||
class Loader {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Loader {
|
||||
|
||||
constructor(game: Game, callback) {
|
||||
|
||||
|
@ -13,7 +19,7 @@ class Loader {
|
|||
}
|
||||
|
||||
private _game: Game;
|
||||
private _keys: string [];
|
||||
private _keys: string[];
|
||||
private _fileList;
|
||||
private _gameCreateComplete;
|
||||
private _onComplete;
|
||||
|
@ -37,7 +43,7 @@ class Loader {
|
|||
|
||||
}
|
||||
|
||||
public addImageFile(key:string, url: string) {
|
||||
public addImageFile(key: string, url: string) {
|
||||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
|
@ -47,7 +53,7 @@ class Loader {
|
|||
|
||||
}
|
||||
|
||||
public addSpriteSheet(key:string, url: string, frameWidth:number, frameHeight:number, frameMax?:number = -1) {
|
||||
public addSpriteSheet(key: string, url: string, frameWidth: number, frameHeight: number, frameMax?: number = -1) {
|
||||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
|
@ -57,7 +63,7 @@ class Loader {
|
|||
|
||||
}
|
||||
|
||||
public addTextureAtlas(key: string, url: string, jsonURL?:string = null, jsonData? = null) {
|
||||
public addTextureAtlas(key: string, url: string, jsonURL?: string = null, jsonData? = null) {
|
||||
|
||||
//console.log('addTextureAtlas');
|
||||
//console.log(typeof jsonData);
|
||||
|
@ -105,7 +111,7 @@ class Loader {
|
|||
|
||||
}
|
||||
|
||||
public addAudioFile(key:string, url: string) {
|
||||
public addAudioFile(key: string, url: string) {
|
||||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
|
@ -115,7 +121,7 @@ class Loader {
|
|||
|
||||
}
|
||||
|
||||
public addTextFile(key:string, url: string) {
|
||||
public addTextFile(key: string, url: string) {
|
||||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
|
@ -216,7 +222,7 @@ class Loader {
|
|||
|
||||
}
|
||||
|
||||
private fileComplete(key:string) {
|
||||
private fileComplete(key: string) {
|
||||
|
||||
this._fileList[key].loaded = true;
|
||||
|
||||
|
@ -270,7 +276,7 @@ class Loader {
|
|||
|
||||
}
|
||||
|
||||
private jsonLoadComplete(key:string) {
|
||||
private jsonLoadComplete(key: string) {
|
||||
|
||||
//console.log('json load complete');
|
||||
|
||||
|
@ -289,7 +295,7 @@ class Loader {
|
|||
|
||||
}
|
||||
|
||||
private jsonLoadError(key:string) {
|
||||
private jsonLoadError(key: string) {
|
||||
|
||||
//console.log('json load error');
|
||||
|
||||
|
@ -299,7 +305,7 @@ class Loader {
|
|||
|
||||
}
|
||||
|
||||
private nextFile(previousKey:string, success:bool) {
|
||||
private nextFile(previousKey: string, success: bool) {
|
||||
|
||||
this.progress = Math.round(this.progress + this._progressChunk);
|
||||
|
||||
|
@ -326,4 +332,6 @@ class Loader {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
403
Phaser/Motion.ts
Normal file
403
Phaser/Motion.ts
Normal file
|
@ -0,0 +1,403 @@
|
|||
/// <reference path="Game.ts" />
|
||||
/// <reference path="gameobjects/GameObject.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Motion
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Motion {
|
||||
|
||||
constructor(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 Velocity Any component of velocity (e.g. 20).
|
||||
* @param Acceleration Rate at which the velocity is changing.
|
||||
* @param Drag Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
|
||||
* @param Max An absolute value cap for the velocity.
|
||||
*
|
||||
* @return 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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the angle and speed calculate the velocity and return it as a Point
|
||||
*
|
||||
* @param angle The angle (in degrees) calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative)
|
||||
* @param speed The speed it will move, in pixels per second sq
|
||||
*
|
||||
* @return A Point where Point.x contains the velocity x value and Point.y contains the velocity y value
|
||||
*/
|
||||
public velocityFromAngle(angle: number, speed: number): Point {
|
||||
|
||||
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>
|
||||
* The source object doesn't stop moving automatically should it ever reach the destination coordinates.<br>
|
||||
* 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 source The Sprite on which the velocity will be set
|
||||
* @param dest The Sprite where the source object will move to
|
||||
* @param speed The speed it will move, in pixels per second (default is 60 pixels/sec)
|
||||
* @param 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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
source.velocity.x = Math.cos(a) * speed;
|
||||
source.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 source The Sprite on which the acceleration will be set
|
||||
* @param dest The Sprite where the source object will move towards
|
||||
* @param speed The speed it will accelerate in pixels per second
|
||||
* @param xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally
|
||||
* @param 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);
|
||||
|
||||
source.velocity.x = 0;
|
||||
source.velocity.y = 0;
|
||||
|
||||
source.acceleration.x = Math.cos(a) * speed;
|
||||
source.acceleration.y = Math.sin(a) * speed;
|
||||
|
||||
source.maxVelocity.x = xSpeedMax;
|
||||
source.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 source The Sprite to move
|
||||
* @param speed The speed it will move, in pixels per second (default is 60 pixels/sec)
|
||||
* @param 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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
source.velocity.x = Math.cos(a) * speed;
|
||||
source.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 source The Sprite on which the acceleration will be set
|
||||
* @param speed The speed it will accelerate in pixels per second
|
||||
* @param xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally
|
||||
* @param 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);
|
||||
|
||||
source.velocity.x = 0;
|
||||
source.velocity.y = 0;
|
||||
|
||||
source.acceleration.x = Math.cos(a) * speed;
|
||||
source.acceleration.y = Math.sin(a) * speed;
|
||||
|
||||
source.maxVelocity.x = xSpeedMax;
|
||||
source.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 source The Sprite to move
|
||||
* @param target The Point coordinates to move the source Sprite towards
|
||||
* @param speed The speed it will move, in pixels per second (default is 60 pixels/sec)
|
||||
* @param 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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
source.velocity.x = Math.cos(a) * speed;
|
||||
source.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 source The Sprite on which the acceleration will be set
|
||||
* @param target The Point coordinates to move the source Sprite towards
|
||||
* @param speed The speed it will accelerate in pixels per second
|
||||
* @param xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally
|
||||
* @param 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);
|
||||
|
||||
source.velocity.x = 0;
|
||||
source.velocity.y = 0;
|
||||
|
||||
source.acceleration.x = Math.cos(a) * speed;
|
||||
source.acceleration.y = Math.sin(a) * speed;
|
||||
|
||||
source.maxVelocity.x = xSpeedMax;
|
||||
source.maxVelocity.y = ySpeedMax;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the distance (in pixels, rounded) between two Sprites, taking their origin into account
|
||||
*
|
||||
* @param a The first Sprite
|
||||
* @param b The second Sprite
|
||||
* @return 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);
|
||||
|
||||
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
|
||||
*
|
||||
* @param a The Sprite
|
||||
* @param target The Point
|
||||
* @return int 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);
|
||||
|
||||
return this._game.math.vectorLength(dx, dy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the distance (in pixels, rounded) from the object x/y and the mouse x/y
|
||||
*
|
||||
* @param a The Sprite to test against
|
||||
* @return int 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;
|
||||
|
||||
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 a The Sprite to test from
|
||||
* @param target The Point to angle the Sprite towards
|
||||
* @param 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);
|
||||
|
||||
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 a The Sprite to test from
|
||||
* @param b The Sprite to test to
|
||||
* @param 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);
|
||||
|
||||
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
|
||||
*
|
||||
* @param parent The Sprite to get the facing value from
|
||||
* @param speed The speed it will move, in pixels per second sq
|
||||
*
|
||||
* @return 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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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 a The Object to test from
|
||||
* @param 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:Point = a.getScreenXY();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
/// <reference path="Sprite.ts" />
|
||||
|
||||
/**
|
||||
* This is a simple particle class that extends the default behavior
|
||||
* of <code>Sprite</code> to have slightly more specialized behavior
|
||||
* common to many game scenarios. You can override and extend this class
|
||||
* just like you would <code>Sprite</code>. While <code>Emitter</code>
|
||||
* used to work with just any old sprite, it now requires a
|
||||
* <code>Particle</code> based class.
|
||||
*
|
||||
* @author Adam Atomic
|
||||
* @author Richard Davey
|
||||
*/
|
||||
class Particle extends Sprite {
|
||||
|
||||
/**
|
||||
* Instantiate a new particle. Like <code>Sprite</code>, all meaningful creation
|
||||
* happens during <code>loadGraphic()</code> or <code>makeGraphic()</code> or whatever.
|
||||
*/
|
||||
constructor(game: Game) {
|
||||
|
||||
super(game);
|
||||
|
||||
this.lifespan = 0;
|
||||
this.friction = 500;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long this particle lives before it disappears.
|
||||
* NOTE: this is a maximum, not a minimum; the object
|
||||
* could get recycled before its lifespan is up.
|
||||
*/
|
||||
public lifespan: number;
|
||||
|
||||
/**
|
||||
* Determines how quickly the particles come to rest on the ground.
|
||||
* Only used if the particle has gravity-like acceleration applied.
|
||||
* @default 500
|
||||
*/
|
||||
public friction: number;
|
||||
|
||||
/**
|
||||
* The particle's main update logic. Basically it checks to see if it should
|
||||
* be dead yet, and then has some special bounce behavior if there is some gravity on it.
|
||||
*/
|
||||
public update() {
|
||||
//lifespan behavior
|
||||
if (this.lifespan <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.lifespan -= this._game.time.elapsed;
|
||||
|
||||
if (this.lifespan <= 0)
|
||||
{
|
||||
this.kill();
|
||||
}
|
||||
|
||||
//simpler bounce/spin behavior for now
|
||||
if (this.touching)
|
||||
{
|
||||
if (this.angularVelocity != 0)
|
||||
{
|
||||
this.angularVelocity = -this.angularVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.acceleration.y > 0) //special behavior for particles with gravity
|
||||
{
|
||||
if (this.touching & GameObject.FLOOR)
|
||||
{
|
||||
this.drag.x = this.friction;
|
||||
|
||||
if (!(this.wasTouching & GameObject.FLOOR))
|
||||
{
|
||||
if (this.velocity.y < -this.elasticity * 10)
|
||||
{
|
||||
if (this.angularVelocity != 0)
|
||||
{
|
||||
this.angularVelocity *= -this.elasticity;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.velocity.y = 0;
|
||||
this.angularVelocity = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.drag.x = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered whenever this object is launched by a <code>Emitter</code>.
|
||||
* You can override this to add custom behavior like a sound or AI or something.
|
||||
*/
|
||||
public onEmit() {
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
|
@ -46,31 +46,32 @@
|
|||
<TypeScriptTarget>ES5</TypeScriptTarget>
|
||||
<TypeScriptIncludeComments>true</TypeScriptIncludeComments>
|
||||
<TypeScriptSourceMap>false</TypeScriptSourceMap>
|
||||
<TypeScriptOutFile>phaser.js</TypeScriptOutFile>
|
||||
<TypeScriptOutFile>../build/phaser.js</TypeScriptOutFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<TypeScriptTarget>ES5</TypeScriptTarget>
|
||||
<TypeScriptIncludeComments>false</TypeScriptIncludeComments>
|
||||
<TypeScriptSourceMap>true</TypeScriptSourceMap>
|
||||
<TypeScriptOutFile>phaser.js</TypeScriptOutFile>
|
||||
<TypeScriptSourceMap>false</TypeScriptSourceMap>
|
||||
<TypeScriptOutFile>../build/phaser.js</TypeScriptOutFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<TypeScriptCompile Include="Phaser.ts" />
|
||||
<TypeScriptCompile Include="Animations.ts" />
|
||||
<TypeScriptCompile Include="Basic.ts" />
|
||||
<TypeScriptCompile Include="Cache.ts" />
|
||||
<TypeScriptCompile Include="Cameras.ts" />
|
||||
<TypeScriptCompile Include="Emitter.ts" />
|
||||
<TypeScriptCompile Include="gameobjects\Emitter.ts" />
|
||||
<TypeScriptCompile Include="Game.ts" />
|
||||
<TypeScriptCompile Include="GameMath.ts" />
|
||||
<TypeScriptCompile Include="GameObject.ts" />
|
||||
<TypeScriptCompile Include="gameobjects\GameObject.ts" />
|
||||
<TypeScriptCompile Include="Group.ts" />
|
||||
<TypeScriptCompile Include="Loader.ts" />
|
||||
<TypeScriptCompile Include="Particle.ts" />
|
||||
<TypeScriptCompile Include="gameobjects\Particle.ts" />
|
||||
<TypeScriptCompile Include="geom\Circle.ts" />
|
||||
<TypeScriptCompile Include="geom\Point.ts" />
|
||||
<TypeScriptCompile Include="geom\Rectangle.ts" />
|
||||
<TypeScriptCompile Include="Sound.ts" />
|
||||
<TypeScriptCompile Include="Sprite.ts" />
|
||||
<TypeScriptCompile Include="gameobjects\Sprite.ts" />
|
||||
<TypeScriptCompile Include="Stage.ts" />
|
||||
<TypeScriptCompile Include="State.ts" />
|
||||
<TypeScriptCompile Include="Signal.ts" />
|
||||
|
@ -93,21 +94,35 @@
|
|||
<TypeScriptCompile Include="system\StageScaleMode.ts" />
|
||||
<TypeScriptCompile Include="system\Tile.ts" />
|
||||
<TypeScriptCompile Include="system\TilemapBuffer.ts" />
|
||||
<TypeScriptCompile Include="Tilemap.ts" />
|
||||
<TypeScriptCompile Include="gameobjects\Tilemap.ts" />
|
||||
<TypeScriptCompile Include="Time.ts" />
|
||||
<TypeScriptCompile Include="World.ts" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<TypeScriptCompile Include="DynamicTexture.ts" />
|
||||
<TypeScriptCompile Include="Collision.ts" />
|
||||
<TypeScriptCompile Include="system\Tween.ts" />
|
||||
<TypeScriptCompile Include="geom\Line.ts" />
|
||||
<TypeScriptCompile Include="gameobjects\GeomSprite.ts" />
|
||||
<TypeScriptCompile Include="geom\IntersectResult.ts" />
|
||||
<TypeScriptCompile Include="Motion.ts" />
|
||||
<TypeScriptCompile Include="TweenManager.ts" />
|
||||
<TypeScriptCompile Include="system\easing\Back.ts" />
|
||||
<TypeScriptCompile Include="system\easing\Bounce.ts" />
|
||||
<TypeScriptCompile Include="system\easing\Circular.ts" />
|
||||
<TypeScriptCompile Include="system\easing\Cubic.ts" />
|
||||
<TypeScriptCompile Include="system\easing\Elastic.ts" />
|
||||
<TypeScriptCompile Include="system\easing\Exponential.ts" />
|
||||
<TypeScriptCompile Include="system\easing\Linear.ts" />
|
||||
<TypeScriptCompile Include="system\easing\Quadratic.ts" />
|
||||
<TypeScriptCompile Include="system\easing\Quartic.ts" />
|
||||
<TypeScriptCompile Include="system\easing\Quintic.ts" />
|
||||
<TypeScriptCompile Include="system\easing\Sinusoidal.ts" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="DynamicTexture.js">
|
||||
<DependentUpon>DynamicTexture.ts</DependentUpon>
|
||||
</Content>
|
||||
<Folder Include="plugins\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>cd $(ProjectDir)
|
||||
copy $(ProjectDir)phaser.js ..\Tests\</PostBuildEvent>
|
||||
<PostBuildEvent>cd $(ProjectDir)..\build
|
||||
copy phaser.js ..\Tests\</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
20
Phaser/Phaser.ts
Normal file
20
Phaser/Phaser.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* Phaser
|
||||
*
|
||||
* v0.9 - April 18th 2013
|
||||
*
|
||||
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
||||
*
|
||||
* Richard Davey (@photonstorm)
|
||||
* Adam Saltsman (@ADAMATOMIC) (original Flixel code)
|
||||
*
|
||||
* "If you want your children to be intelligent, read them fairy tales."
|
||||
* "If you want them to be more intelligent, read them more fairy tales."
|
||||
* -- Albert Einstein
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export var VERSION: string = 'Phaser version 0.9';
|
||||
|
||||
}
|
|
@ -21,7 +21,14 @@
|
|||
* @author Miller Medeiros
|
||||
* @constructor
|
||||
*/
|
||||
class Signal {
|
||||
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Signal {
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -332,5 +339,6 @@ class Signal {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -14,7 +14,13 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class SignalBinding {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class SignalBinding {
|
||||
|
||||
/**
|
||||
* Object that represents a binding between a Signal and a listener function.
|
||||
|
@ -184,3 +190,4 @@
|
|||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,14 @@
|
|||
class SoundManager {
|
||||
/// <reference path="Game.ts" />
|
||||
|
||||
constructor(game:Game) {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class SoundManager {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
this._game = game;
|
||||
|
||||
|
@ -79,7 +87,7 @@ class SoundManager {
|
|||
|
||||
}
|
||||
|
||||
public play(key:string, volume?: number = 1, loop?: bool = false): Sound {
|
||||
public play(key: string, volume?: number = 1, loop?: bool = false): Sound {
|
||||
|
||||
if (this._context === null)
|
||||
{
|
||||
|
@ -108,9 +116,13 @@ class SoundManager {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Sound {
|
||||
module Phaser {
|
||||
|
||||
export class Sound {
|
||||
|
||||
constructor(context, gainNode, data, volume?: number = 1, loop?: bool = false) {
|
||||
|
||||
|
@ -182,7 +194,7 @@ class Sound {
|
|||
|
||||
}
|
||||
|
||||
public stop () {
|
||||
public stop() {
|
||||
|
||||
if (this.isPlaying === true)
|
||||
{
|
||||
|
@ -216,4 +228,6 @@ class Sound {
|
|||
return this._volume;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
273
Phaser/Sprite.ts
273
Phaser/Sprite.ts
|
@ -1,273 +0,0 @@
|
|||
/// <reference path="Animations.ts" />
|
||||
/// <reference path="DynamicTexture.ts" />
|
||||
/// <reference path="GameObject.ts" />
|
||||
/// <reference path="Game.ts" />
|
||||
/// <reference path="GameMath.ts" />
|
||||
/// <reference path="geom/Rectangle.ts" />
|
||||
/// <reference path="geom/Point.ts" />
|
||||
|
||||
class Sprite extends GameObject {
|
||||
|
||||
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null) {
|
||||
|
||||
super(game, x, y);
|
||||
|
||||
this._texture = null;
|
||||
|
||||
this.animations = new Animations(this._game, this);
|
||||
|
||||
if (key !== null)
|
||||
{
|
||||
this.loadGraphic(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bounds.width = 16;
|
||||
this.bounds.height = 16;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private _texture;
|
||||
private _canvas: HTMLCanvasElement;
|
||||
private _context: CanvasRenderingContext2D;
|
||||
private _dynamicTexture: bool = false;
|
||||
|
||||
public animations: Animations;
|
||||
|
||||
// local rendering related temp vars to help avoid gc spikes
|
||||
private _sx: number = 0;
|
||||
private _sy: number = 0;
|
||||
private _sw: number = 0;
|
||||
private _sh: number = 0;
|
||||
private _dx: number = 0;
|
||||
private _dy: number = 0;
|
||||
private _dw: number = 0;
|
||||
private _dh: number = 0;
|
||||
|
||||
public loadGraphic(key: string): Sprite {
|
||||
|
||||
if (this._game.cache.getImage(key) !== null)
|
||||
{
|
||||
if (this._game.cache.isSpriteSheet(key) == false)
|
||||
{
|
||||
this._texture = this._game.cache.getImage(key);
|
||||
this.bounds.width = this._texture.width;
|
||||
this.bounds.height = this._texture.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._texture = this._game.cache.getImage(key);
|
||||
this.animations.loadFrameData(this._game.cache.getFrameData(key));
|
||||
}
|
||||
|
||||
this._dynamicTexture = false;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public loadDynamicTexture(texture: DynamicTexture): Sprite {
|
||||
|
||||
this._texture = texture;
|
||||
|
||||
this.bounds.width = this._texture.width;
|
||||
this.bounds.height = this._texture.height;
|
||||
|
||||
this._dynamicTexture = true;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public makeGraphic(width: number, height: number, color: number = 0xffffffff): Sprite {
|
||||
|
||||
this._texture = null;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
this._dynamicTexture = false;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public inCamera(camera: Rectangle): bool {
|
||||
|
||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
||||
{
|
||||
this._dx = this.bounds.x - (camera.x * this.scrollFactor.x);
|
||||
this._dy = this.bounds.y - (camera.y * this.scrollFactor.x);
|
||||
this._dw = this.bounds.width * this.scale.x;
|
||||
this._dh = this.bounds.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.overlap(this.bounds);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public postUpdate() {
|
||||
|
||||
this.animations.update();
|
||||
|
||||
super.postUpdate();
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public render(camera:Camera, cameraOffsetX: number, cameraOffsetY: number): bool {
|
||||
|
||||
// Render checks
|
||||
if (this.visible === false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.inCamera(camera.worldView) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Alpha
|
||||
if (this.alpha !== 1)
|
||||
{
|
||||
var globalAlpha = this._game.stage.context.globalAlpha;
|
||||
this._game.stage.context.globalAlpha = this.alpha;
|
||||
}
|
||||
|
||||
//if (this.flip === true)
|
||||
//{
|
||||
// this.context.save();
|
||||
// this.context.translate(game.canvas.width, 0);
|
||||
// this.context.scale(-1, 1);
|
||||
//}
|
||||
|
||||
this._sx = 0;
|
||||
this._sy = 0;
|
||||
this._sw = this.bounds.width;
|
||||
this._sh = this.bounds.height;
|
||||
this._dx = cameraOffsetX + (this.bounds.x - camera.worldView.x);
|
||||
this._dy = cameraOffsetY + (this.bounds.y - camera.worldView.y);
|
||||
this._dw = this.bounds.width * this.scale.x;
|
||||
this._dh = this.bounds.height * this.scale.y;
|
||||
|
||||
if (this._dynamicTexture == false && this.animations.currentFrame !== null)
|
||||
{
|
||||
this._sx = this.animations.currentFrame.x;
|
||||
this._sy = this.animations.currentFrame.y;
|
||||
|
||||
if (this.animations.currentFrame.trimmed)
|
||||
{
|
||||
this._dx += this.animations.currentFrame.spriteSourceSizeX;
|
||||
this._dy += this.animations.currentFrame.spriteSourceSizeY;
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
if (this.angle !== 0)
|
||||
{
|
||||
this._game.stage.context.save();
|
||||
this._game.stage.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
||||
this._game.stage.context.rotate(this.angle * (Math.PI / 180));
|
||||
this._dx = -(this._dw / 2);
|
||||
this._dy = -(this._dh / 2);
|
||||
}
|
||||
|
||||
this._sx = Math.round(this._sx);
|
||||
this._sy = Math.round(this._sy);
|
||||
this._sw = Math.round(this._sw);
|
||||
this._sh = Math.round(this._sh);
|
||||
this._dx = Math.round(this._dx);
|
||||
this._dy = Math.round(this._dy);
|
||||
this._dw = Math.round(this._dw);
|
||||
this._dh = Math.round(this._dh);
|
||||
|
||||
// Debug test
|
||||
//this._game.stage.context.fillStyle = 'rgba(255,0,0,0.3)';
|
||||
//this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||
|
||||
if (this._texture != null)
|
||||
{
|
||||
if (this._dynamicTexture)
|
||||
{
|
||||
this._game.stage.context.drawImage(
|
||||
this._texture.canvas, // Source Image
|
||||
this._sx, // Source X (location within the source image)
|
||||
this._sy, // Source Y
|
||||
this._sw, // Source Width
|
||||
this._sh, // Source Height
|
||||
this._dx, // Destination X (where on the canvas it'll be drawn)
|
||||
this._dy, // Destination Y
|
||||
this._dw, // Destination Width (always same as Source Width unless scaled)
|
||||
this._dh // Destination Height (always same as Source Height unless scaled)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._game.stage.context.drawImage(
|
||||
this._texture, // Source Image
|
||||
this._sx, // Source X (location within the source image)
|
||||
this._sy, // Source Y
|
||||
this._sw, // Source Width
|
||||
this._sh, // Source Height
|
||||
this._dx, // Destination X (where on the canvas it'll be drawn)
|
||||
this._dy, // Destination Y
|
||||
this._dw, // Destination Width (always same as Source Width unless scaled)
|
||||
this._dh // Destination Height (always same as Source Height unless scaled)
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this._game.stage.context.fillStyle = 'rgb(255,255,255)';
|
||||
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||
}
|
||||
|
||||
//if (this.flip === true || this.rotation !== 0)
|
||||
if (this.rotation !== 0)
|
||||
{
|
||||
this._game.stage.context.translate(0, 0);
|
||||
this._game.stage.context.restore();
|
||||
}
|
||||
|
||||
if (globalAlpha > -1)
|
||||
{
|
||||
this._game.stage.context.globalAlpha = globalAlpha;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
this._game.stage.context.fillStyle = color;
|
||||
this._game.stage.context.fillText('Sprite: ' + this.name + ' (' + this.bounds.width + ' x ' + this.bounds.height + ')', x, y);
|
||||
this._game.stage.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' rotation: ' + this.angle.toFixed(1), x, y + 14);
|
||||
this._game.stage.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._game.stage.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);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,16 @@
|
|||
/// <reference path="Phaser.ts" />
|
||||
/// <reference path="Game.ts" />
|
||||
/// <reference path="geom/Point.ts" />
|
||||
/// <reference path="geom/Rectangle.ts" />
|
||||
/// <reference path="system/StageScaleMode.ts" />
|
||||
|
||||
class Stage {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
constructor(game:Game, parent:string, width: number, height: number) {
|
||||
module Phaser {
|
||||
|
||||
export class Stage {
|
||||
|
||||
constructor(game: Game, parent: string, width: number, height: number) {
|
||||
|
||||
this._game = game;
|
||||
|
||||
|
@ -42,8 +47,8 @@ class Stage {
|
|||
private _bgColor: string;
|
||||
|
||||
|
||||
public static ORIENTATION_LANDSCAPE:number = 0;
|
||||
public static ORIENTATION_PORTRAIT:number = 1;
|
||||
public static ORIENTATION_LANDSCAPE: number = 0;
|
||||
public static ORIENTATION_PORTRAIT: number = 1;
|
||||
|
||||
public bounds: Rectangle;
|
||||
public aspectRatio: number;
|
||||
|
@ -74,7 +79,7 @@ class Stage {
|
|||
public renderDebugInfo() {
|
||||
|
||||
this.context.fillStyle = 'rgb(255,255,255)';
|
||||
this.context.fillText(Game.VERSION, 10, 20);
|
||||
this.context.fillText(Phaser.VERSION, 10, 20);
|
||||
this.context.fillText('Game Size: ' + this.width + ' x ' + this.height, 10, 40);
|
||||
this.context.fillText('x: ' + this.x + ' y: ' + this.y, 10, 60);
|
||||
|
||||
|
@ -82,14 +87,14 @@ class Stage {
|
|||
|
||||
private visibilityChange(event) {
|
||||
|
||||
if (event.type == 'blur' && this._game.pause == false && this._game.isBooted == true)
|
||||
if (event.type == 'blur' && this._game.paused == false && this._game.isBooted == true)
|
||||
{
|
||||
this._game.pause = true;
|
||||
this._game.paused = true;
|
||||
this.drawPauseScreen();
|
||||
}
|
||||
else if (event.type == 'focus')
|
||||
{
|
||||
this._game.pause = false;
|
||||
this._game.paused = false;
|
||||
}
|
||||
|
||||
//if (document['hidden'] === true || document['webkitHidden'] === true)
|
||||
|
@ -104,7 +109,7 @@ class Stage {
|
|||
this.context.fillStyle = 'rgb(255,255,255)';
|
||||
this.context.font = 'bold 18px Arial';
|
||||
this.context.textBaseline = 'top';
|
||||
this.context.fillText(Game.VERSION, 54, 32);
|
||||
this.context.fillText(Phaser.VERSION, 54, 32);
|
||||
this.context.fillText('Game Size: ' + this.width + ' x ' + this.height, 32, 64);
|
||||
this.context.fillText('www.photonstorm.com', 32, 96);
|
||||
this.context.font = '16px Arial';
|
||||
|
@ -114,7 +119,7 @@ class Stage {
|
|||
var image = new Image();
|
||||
var that = this;
|
||||
|
||||
image.onload = function() {
|
||||
image.onload = function () {
|
||||
that.context.drawImage(image, 32, 32);
|
||||
};
|
||||
|
||||
|
@ -124,6 +129,8 @@ class Stage {
|
|||
|
||||
private drawPauseScreen() {
|
||||
|
||||
this.saveCanvasValues();
|
||||
|
||||
this.context.fillStyle = 'rgba(0, 0, 0, 0.4)';
|
||||
this.context.fillRect(0, 0, this.width, this.height);
|
||||
|
||||
|
@ -138,14 +145,15 @@ class Stage {
|
|||
this.context.moveTo(sx, sy);
|
||||
this.context.lineTo(sx, sy + arrowHeight);
|
||||
this.context.lineTo(sx + arrowWidth, this.centerY);
|
||||
this.context.closePath();
|
||||
|
||||
this.context.fillStyle = 'rgba(255, 255, 255, 0.8)';
|
||||
this.context.fill();
|
||||
this.context.closePath();
|
||||
|
||||
this.restoreCanvasValues();
|
||||
|
||||
}
|
||||
|
||||
private getOffset(element):Point {
|
||||
private getOffset(element): Point {
|
||||
|
||||
var box = element.getBoundingClientRect();
|
||||
|
||||
|
@ -158,11 +166,31 @@ class Stage {
|
|||
|
||||
}
|
||||
|
||||
public strokeStyle: string;
|
||||
public lineWidth: number;
|
||||
public fillStyle: string;
|
||||
|
||||
public saveCanvasValues() {
|
||||
|
||||
this.strokeStyle = this.context.strokeStyle;
|
||||
this.lineWidth = this.context.lineWidth;
|
||||
this.fillStyle = this.context.fillStyle;
|
||||
|
||||
}
|
||||
|
||||
public restoreCanvasValues() {
|
||||
|
||||
this.context.strokeStyle = this.strokeStyle;
|
||||
this.context.lineWidth = this.lineWidth;
|
||||
this.context.fillStyle = this.fillStyle;
|
||||
|
||||
}
|
||||
|
||||
public set backgroundColor(color: string) {
|
||||
this.canvas.style.backgroundColor = color;
|
||||
}
|
||||
|
||||
public get backgroundColor():string {
|
||||
public get backgroundColor(): string {
|
||||
return this._bgColor;
|
||||
}
|
||||
|
||||
|
@ -198,6 +226,8 @@ class Stage {
|
|||
return Math.round(Math.random() * this.bounds.height);
|
||||
}
|
||||
|
||||
private _logo:string = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAO1JREFUeNpi/P//PwM6YGRkxBQEAqBaRnQxFmwa10d6MAjrMqMofHv5L1we2SBGmAtAktg0ogOQQYHLd8ANYYFpPtTmzUAMAFmwnsEDrAdkCAvMZlIAsiFMMAEYsKvaSrQhIMCELkGsV2AAbIC8gCQYgwKIUABiNYBf9yoYH7n7n6CzN274g2IYEyFbsNmKLIaSkHpP7WSwUfbA0ASzFQRslBlxp0RcAF0TRhggA3zhAJIDpUKU5A9KyshpHDkjFZu5g2nJMFcwXVJSgqIGnBKx5bKenh4w/XzVbgbPtlIUcVgSxuoCUgHIIIAAAwArtXwJBABO6QAAAABJRU5ErkJggg==";
|
||||
private _logo: string = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAO1JREFUeNpi/P//PwM6YGRkxBQEAqBaRnQxFmwa10d6MAjrMqMofHv5L1we2SBGmAtAktg0ogOQQYHLd8ANYYFpPtTmzUAMAFmwnsEDrAdkCAvMZlIAsiFMMAEYsKvaSrQhIMCELkGsV2AAbIC8gCQYgwKIUABiNYBf9yoYH7n7n6CzN274g2IYEyFbsNmKLIaSkHpP7WSwUfbA0ASzFQRslBlxp0RcAF0TRhggA3zhAJIDpUKU5A9KyshpHDkjFZu5g2nJMFcwXVJSgqIGnBKx5bKenh4w/XzVbgbPtlIUcVgSxuoCUgHIIIAAAwArtXwJBABO6QAAAABJRU5ErkJggg==";
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,12 @@
|
|||
/// <reference path="Game.ts" />
|
||||
|
||||
class State {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class State {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
|
@ -8,12 +14,15 @@ class State {
|
|||
|
||||
this.camera = game.camera;
|
||||
this.cache = game.cache;
|
||||
this.collision = game.collision;
|
||||
this.input = game.input;
|
||||
this.loader = game.loader;
|
||||
this.math = game.math;
|
||||
this.motion = game.motion;
|
||||
this.sound = game.sound;
|
||||
this.stage = game.stage;
|
||||
this.time = game.time;
|
||||
this.math = game.math;
|
||||
this.tweens = game.tweens;
|
||||
this.world = game.world;
|
||||
|
||||
}
|
||||
|
@ -22,21 +31,24 @@ class State {
|
|||
|
||||
public camera: Camera;
|
||||
public cache: Cache;
|
||||
public collision: Collision;
|
||||
public input: Input;
|
||||
public loader: Loader;
|
||||
public math: GameMath;
|
||||
public motion: Motion;
|
||||
public sound: SoundManager;
|
||||
public stage: Stage;
|
||||
public time: Time;
|
||||
public math: GameMath;
|
||||
public tweens: TweenManager;
|
||||
public world: World;
|
||||
|
||||
|
||||
// Overload these in your own States
|
||||
public init() {}
|
||||
public create() {}
|
||||
public update() {}
|
||||
public render() {}
|
||||
public paused() {}
|
||||
public init() { }
|
||||
public create() { }
|
||||
public update() { }
|
||||
public render() { }
|
||||
public paused() { }
|
||||
|
||||
// Handy Proxy methods
|
||||
|
||||
|
@ -44,10 +56,18 @@ class State {
|
|||
return this.game.world.createCamera(x, y, width, height);
|
||||
}
|
||||
|
||||
public createGeomSprite(x: number, y: number): GeomSprite {
|
||||
return this.world.createGeomSprite(x, y);
|
||||
}
|
||||
|
||||
public createSprite(x: number, y: number, key?: string = ''): Sprite {
|
||||
return this.game.world.createSprite(x, y, key);
|
||||
}
|
||||
|
||||
public createDynamicTexture(key: string, width: number, height: number): DynamicTexture {
|
||||
return this.game.world.createDynamicTexture(key, width, height);
|
||||
}
|
||||
|
||||
public createGroup(MaxSize?: number = 0): Group {
|
||||
return this.game.world.createGroup(MaxSize);
|
||||
}
|
||||
|
@ -56,16 +76,22 @@ class State {
|
|||
return this.game.world.createParticle();
|
||||
}
|
||||
|
||||
public createEmitter(x?: number = 0, y?: number = 0, size?:number = 0): Emitter {
|
||||
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
||||
return this.game.world.createEmitter(x, y, size);
|
||||
}
|
||||
|
||||
public createTilemap(key:string, mapData:string, format:number, tileWidth?:number,tileHeight?:number): Tilemap {
|
||||
public createTilemap(key: string, mapData: string, format: number, tileWidth?: number, tileHeight?: number): Tilemap {
|
||||
return this.game.world.createTilemap(key, mapData, format, tileWidth, tileHeight);
|
||||
}
|
||||
|
||||
public createTween(obj): Tween {
|
||||
return this.game.tweens.create(obj);
|
||||
}
|
||||
|
||||
public collide(ObjectOrGroup1: Basic = null, ObjectOrGroup2: Basic = null, NotifyCallback = null): bool {
|
||||
return this.game.world.overlap(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, World.separate);
|
||||
return this.collision.overlap(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, Collision.separate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,261 +0,0 @@
|
|||
/// <reference path="Game.ts" />
|
||||
/// <reference path="GameObject.ts" />
|
||||
/// <reference path="geom/Point.ts" />
|
||||
/// <reference path="geom/Rectangle.ts" />
|
||||
/// <reference path="system/TilemapBuffer.ts" />
|
||||
|
||||
class Tilemap extends GameObject {
|
||||
|
||||
constructor(game: Game, key: string, mapData: string, format:number, tileWidth?: number = 0, tileHeight?: number = 0) {
|
||||
|
||||
super(game);
|
||||
|
||||
this._texture = this._game.cache.getImage(key);
|
||||
this._tilemapBuffers = [];
|
||||
|
||||
this.isGroup = false;
|
||||
|
||||
this.tileWidth = tileWidth;
|
||||
this.tileHeight = tileHeight;
|
||||
this.boundsInTiles = new Rectangle();
|
||||
this.mapFormat = format;
|
||||
|
||||
switch (format)
|
||||
{
|
||||
case Tilemap.FORMAT_CSV:
|
||||
this.parseCSV(game.cache.getText(mapData));
|
||||
break;
|
||||
|
||||
case Tilemap.FORMAT_TILED_JSON:
|
||||
this.parseTiledJSON(game.cache.getText(mapData));
|
||||
break;
|
||||
}
|
||||
|
||||
this.parseTileOffsets();
|
||||
this.createTilemapBuffers();
|
||||
|
||||
}
|
||||
|
||||
private _texture;
|
||||
private _tileOffsets;
|
||||
private _tilemapBuffers: TilemapBuffer[];
|
||||
private _dx: number = 0;
|
||||
private _dy: number = 0;
|
||||
|
||||
public static FORMAT_CSV:number = 0;
|
||||
public static FORMAT_TILED_JSON:number = 1;
|
||||
|
||||
public mapData;
|
||||
public mapFormat: number;
|
||||
public boundsInTiles: Rectangle;
|
||||
|
||||
public tileWidth: number;
|
||||
public tileHeight: number;
|
||||
|
||||
public widthInTiles: number = 0;
|
||||
public heightInTiles: number = 0;
|
||||
|
||||
public widthInPixels: number = 0;
|
||||
public heightInPixels: number = 0;
|
||||
|
||||
// How many extra tiles to draw around the edge of the screen (for fast scrolling games, or to optimise mobile performance try increasing this)
|
||||
// The number is the amount of extra tiles PER SIDE, so a value of 10 would be (10 tiles + screen size + 10 tiles)
|
||||
public tileBoundary: number = 10;
|
||||
|
||||
private parseCSV(data: string) {
|
||||
|
||||
//console.log('parseMapData');
|
||||
|
||||
this.mapData = [];
|
||||
|
||||
// Trim any rogue whitespace from the data
|
||||
data = data.trim();
|
||||
|
||||
var rows = data.split("\n");
|
||||
//console.log('rows', rows);
|
||||
|
||||
for (var i = 0; i < rows.length; i++)
|
||||
{
|
||||
var column = rows[i].split(",");
|
||||
//console.log('column', column);
|
||||
var output = [];
|
||||
|
||||
if (column.length > 0)
|
||||
{
|
||||
// Set the width based on the first row
|
||||
if (this.widthInTiles == 0)
|
||||
{
|
||||
// Maybe -1?
|
||||
this.widthInTiles = column.length;
|
||||
}
|
||||
|
||||
// We have a new row of tiles
|
||||
this.heightInTiles++;
|
||||
|
||||
// Parse it
|
||||
for (var c = 0; c < column.length; c++)
|
||||
{
|
||||
output[c] = parseInt(column[c]);
|
||||
}
|
||||
|
||||
this.mapData.push(output);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//console.log('final map array');
|
||||
//console.log(this.mapData);
|
||||
|
||||
if (this.widthInTiles > 0)
|
||||
{
|
||||
this.widthInPixels = this.tileWidth * this.widthInTiles;
|
||||
}
|
||||
|
||||
if (this.heightInTiles > 0)
|
||||
{
|
||||
this.heightInPixels = this.tileHeight * this.heightInTiles;
|
||||
}
|
||||
|
||||
this.boundsInTiles.setTo(0, 0, this.widthInTiles, this.heightInTiles);
|
||||
|
||||
}
|
||||
|
||||
private parseTiledJSON(data: string) {
|
||||
|
||||
console.log('parseTiledJSON');
|
||||
|
||||
this.mapData = [];
|
||||
|
||||
// Trim any rogue whitespace from the data
|
||||
data = data.trim();
|
||||
|
||||
// We ought to change this soon, so we have layer support, but for now let's just get it working
|
||||
var json = JSON.parse(data);
|
||||
|
||||
// Right now we assume no errors at all with the parsing (safe I know)
|
||||
this.tileWidth = json.tilewidth;
|
||||
this.tileHeight = json.tileheight;
|
||||
|
||||
// Parse the first layer only
|
||||
this.widthInTiles = json.layers[0].width;
|
||||
this.heightInTiles = json.layers[0].height;
|
||||
this.widthInPixels = this.widthInTiles * this.tileWidth;
|
||||
this.heightInPixels = this.heightInTiles * this.tileHeight;
|
||||
this.boundsInTiles.setTo(0, 0, this.widthInTiles, this.heightInTiles);
|
||||
|
||||
console.log('width in tiles', this.widthInTiles);
|
||||
console.log('height in tiles', this.heightInTiles);
|
||||
console.log('width in px', this.widthInPixels);
|
||||
console.log('height in px', this.heightInPixels);
|
||||
|
||||
// Now let's get the data
|
||||
|
||||
var c = 0;
|
||||
var row;
|
||||
|
||||
for (var i = 0; i < json.layers[0].data.length; i++)
|
||||
{
|
||||
if (c == 0)
|
||||
{
|
||||
row = [];
|
||||
}
|
||||
|
||||
row.push(json.layers[0].data[i]);
|
||||
|
||||
c++;
|
||||
|
||||
if (c == this.widthInTiles)
|
||||
{
|
||||
this.mapData.push(row);
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//console.log('mapData');
|
||||
//console.log(this.mapData);
|
||||
|
||||
}
|
||||
|
||||
public getMapSegment(area: Rectangle) {
|
||||
}
|
||||
|
||||
private createTilemapBuffers() {
|
||||
|
||||
var cams = this._game.world.getAllCameras();
|
||||
|
||||
for (var i = 0; i < cams.length; i++)
|
||||
{
|
||||
this._tilemapBuffers[cams[i].ID] = new TilemapBuffer(this._game, cams[i], this, this._texture, this._tileOffsets);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private parseTileOffsets() {
|
||||
|
||||
this._tileOffsets = [];
|
||||
|
||||
var i = 0;
|
||||
|
||||
if (this.mapFormat == Tilemap.FORMAT_TILED_JSON)
|
||||
{
|
||||
// For some reason Tiled counts from 1 not 0
|
||||
this._tileOffsets[0] = null;
|
||||
i = 1;
|
||||
}
|
||||
|
||||
for (var ty = 0; ty < this._texture.height; ty += this.tileHeight)
|
||||
{
|
||||
for (var tx = 0; tx < this._texture.width; tx += this.tileWidth)
|
||||
{
|
||||
this._tileOffsets[i] = { x: tx, y: ty };
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
// Use a Signal?
|
||||
public addTilemapBuffers(camera:Camera) {
|
||||
|
||||
console.log('added new camera to tilemap');
|
||||
this._tilemapBuffers[camera.ID] = new TilemapBuffer(this._game, camera, this, this._texture, this._tileOffsets);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
public update() {
|
||||
|
||||
// Check if any of the cameras have scrolled far enough for us to need to refresh a TilemapBuffer
|
||||
this._tilemapBuffers[0].update();
|
||||
|
||||
}
|
||||
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
this._tilemapBuffers[0].renderDebugInfo(x, y, color);
|
||||
}
|
||||
|
||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {
|
||||
|
||||
if (this.visible === false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this._dx = cameraOffsetX + (this.bounds.x - camera.worldView.x);
|
||||
this._dy = cameraOffsetY + (this.bounds.y - camera.worldView.y);
|
||||
|
||||
this._dx = Math.round(this._dx);
|
||||
this._dy = Math.round(this._dy);
|
||||
|
||||
if (this._tilemapBuffers[camera.ID])
|
||||
{
|
||||
//this._tilemapBuffers[camera.ID].render(this._dx, this._dy);
|
||||
this._tilemapBuffers[camera.ID].render(cameraOffsetX, cameraOffsetY);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,12 @@
|
|||
/// <reference path="Game.ts" />
|
||||
|
||||
class Time {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Time {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
|
@ -127,4 +133,6 @@ class Time {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
108
Phaser/TweenManager.ts
Normal file
108
Phaser/TweenManager.ts
Normal file
|
@ -0,0 +1,108 @@
|
|||
/// <reference path="Game.ts" />
|
||||
/// <reference path="system/Tween.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Tween Manager
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js) converted to TypeScript, patched and integrated into Phaser
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration
|
||||
* @author sole / http://soledadpenades.com
|
||||
* @author mrdoob / http://mrdoob.com
|
||||
* @author Robert Eisele / http://www.xarg.org
|
||||
* @author Philippe / http://philippe.elsass.me
|
||||
* @author Robert Penner / http://www.robertpenner.com/easing_terms_of_use.html
|
||||
* @author Paul Lewis / http://www.aerotwist.com/
|
||||
* @author lechecacharro
|
||||
* @author Josh Faul / http://jocafa.com/
|
||||
* @author egraether / http://egraether.com/
|
||||
*
|
||||
* @todo
|
||||
* 1) Allow for tweening direct numeric values, not just object properties
|
||||
* 2) YoYo support
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class TweenManager {
|
||||
|
||||
constructor(game: Phaser.Game) {
|
||||
|
||||
this._game = game;
|
||||
this._tweens = [];
|
||||
|
||||
}
|
||||
|
||||
private _game: Phaser.Game;
|
||||
private _tweens: Phaser.Tween[];
|
||||
|
||||
public getAll() {
|
||||
|
||||
return this._tweens;
|
||||
|
||||
}
|
||||
|
||||
public removeAll() {
|
||||
|
||||
this._tweens.length = 0;
|
||||
|
||||
}
|
||||
|
||||
public create(object): Phaser.Tween {
|
||||
|
||||
return new Phaser.Tween(object, this._game);
|
||||
|
||||
}
|
||||
|
||||
public add(tween: Phaser.Tween) {
|
||||
|
||||
tween.parent = this._game;
|
||||
|
||||
this._tweens.push(tween);
|
||||
|
||||
return tween;
|
||||
|
||||
}
|
||||
|
||||
public remove(tween: Phaser.Tween) {
|
||||
|
||||
var i = this._tweens.indexOf(tween);
|
||||
|
||||
if (i !== -1)
|
||||
{
|
||||
this._tweens.splice(i, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public update() {
|
||||
|
||||
if (this._tweens.length === 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
var numTweens = this._tweens.length;
|
||||
|
||||
while (i < numTweens)
|
||||
{
|
||||
if (this._tweens[i].update(this._game.time.now))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._tweens.splice(i, 1);
|
||||
numTweens--;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
340
Phaser/World.ts
340
Phaser/World.ts
|
@ -1,15 +1,12 @@
|
|||
/// <reference path="Cameras.ts" />
|
||||
/// <reference path="Game.ts" />
|
||||
/// <reference path="GameMath.ts" />
|
||||
/// <reference path="Group.ts" />
|
||||
/// <reference path="geom/Rectangle.ts" />
|
||||
/// <reference path="geom/Point.ts" />
|
||||
/// <reference path="Sprite.ts" />
|
||||
/// <reference path="Tilemap.ts" />
|
||||
/// <reference path="system/Camera.ts" />
|
||||
/// <reference path="system/QuadTree.ts" />
|
||||
|
||||
class World {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class World {
|
||||
|
||||
constructor(game: Game, width: number, height: number) {
|
||||
|
||||
|
@ -126,6 +123,7 @@ class World {
|
|||
|
||||
// Sprites
|
||||
|
||||
// Drop this?
|
||||
public addExistingSprite(sprite: Sprite): Sprite {
|
||||
return <Sprite> this.group.add(sprite);
|
||||
}
|
||||
|
@ -134,7 +132,11 @@ class World {
|
|||
return <Sprite> this.group.add(new Sprite(this._game, x, y, key));
|
||||
}
|
||||
|
||||
public createDynamicTexture(key:string, width: number, height: number): DynamicTexture {
|
||||
public createGeomSprite(x: number, y: number): GeomSprite {
|
||||
return <GeomSprite> this.group.add(new GeomSprite(this._game, x, y));
|
||||
}
|
||||
|
||||
public createDynamicTexture(key: string, width: number, height: number): DynamicTexture {
|
||||
return new DynamicTexture(this._game, key, width, height);
|
||||
}
|
||||
|
||||
|
@ -144,7 +146,7 @@ class World {
|
|||
|
||||
// Tilemaps
|
||||
|
||||
public createTilemap(key:string, mapData:string, format:number, tileWidth?:number,tileHeight?:number): Tilemap {
|
||||
public createTilemap(key: string, mapData: string, format: number, tileWidth?: number, tileHeight?: number): Tilemap {
|
||||
return <Tilemap> this.group.add(new Tilemap(this._game, key, mapData, format, tileWidth, tileHeight));
|
||||
}
|
||||
|
||||
|
@ -154,322 +156,10 @@ class World {
|
|||
return new Particle(this._game);
|
||||
}
|
||||
|
||||
public createEmitter(x?: number = 0, y?: number = 0, size?:number = 0): Emitter {
|
||||
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
||||
return <Emitter> this.group.add(new Emitter(this._game, x, y, size));
|
||||
}
|
||||
|
||||
// Collision
|
||||
|
||||
/**
|
||||
* Call this function to see if one <code>GameObject</code> overlaps another.
|
||||
* Can be called with one object and one group, or two groups, or two objects,
|
||||
* whatever floats your boat! For maximum performance try bundling a lot of objects
|
||||
* together using a <code>FlxGroup</code> (or even bundling groups together!).
|
||||
*
|
||||
* <p>NOTE: does NOT take objects' scrollfactor into account, all overlaps are checked in world space.</p>
|
||||
*
|
||||
* @param ObjectOrGroup1 The first object or group you want to check.
|
||||
* @param ObjectOrGroup2 The second object or group you want to check. If it is the same as the first, flixel knows to just do a comparison within that group.
|
||||
* @param NotifyCallback A function with two <code>GameObject</code> parameters - e.g. <code>myOverlapFunction(Object1:GameObject,Object2:GameObject)</code> - that is called if those two objects overlap.
|
||||
* @param ProcessCallback A function with two <code>GameObject</code> parameters - e.g. <code>myOverlapFunction(Object1:GameObject,Object2:GameObject)</code> - that is called if those two objects overlap. If a ProcessCallback is provided, then NotifyCallback will only be called if ProcessCallback returns true for those objects!
|
||||
*
|
||||
* @return Whether any overlaps were detected.
|
||||
*/
|
||||
public overlap(ObjectOrGroup1: Basic = null, ObjectOrGroup2: Basic = null, NotifyCallback = null, ProcessCallback = null): bool {
|
||||
|
||||
if (ObjectOrGroup1 == null)
|
||||
{
|
||||
ObjectOrGroup1 = this.group;
|
||||
}
|
||||
|
||||
if (ObjectOrGroup2 == ObjectOrGroup1)
|
||||
{
|
||||
ObjectOrGroup2 = null;
|
||||
}
|
||||
|
||||
QuadTree.divisions = this.worldDivisions;
|
||||
|
||||
var quadTree: QuadTree = new QuadTree(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
|
||||
quadTree.load(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, ProcessCallback);
|
||||
|
||||
var result: bool = quadTree.execute();
|
||||
|
||||
quadTree.destroy();
|
||||
|
||||
quadTree = null;
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The main collision resolution in flixel.
|
||||
*
|
||||
* @param Object1 Any <code>Sprite</code>.
|
||||
* @param Object2 Any other <code>Sprite</code>.
|
||||
*
|
||||
* @return Whether the objects in fact touched and were separated.
|
||||
*/
|
||||
public static separate(Object1, Object2): bool {
|
||||
|
||||
var separatedX: bool = World.separateX(Object1, Object2);
|
||||
var separatedY: bool = World.separateY(Object1, Object2);
|
||||
|
||||
return separatedX || separatedY;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The X-axis component of the object separation process.
|
||||
*
|
||||
* @param Object1 Any <code>Sprite</code>.
|
||||
* @param Object2 Any other <code>Sprite</code>.
|
||||
*
|
||||
* @return Whether the objects in fact touched and were separated along the X axis.
|
||||
*/
|
||||
public static separateX(Object1, Object2): bool {
|
||||
|
||||
//can't separate two immovable objects
|
||||
var obj1immovable: bool = Object1.immovable;
|
||||
var obj2immovable: bool = Object2.immovable;
|
||||
|
||||
if (obj1immovable && obj2immovable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//If one of the objects is a tilemap, just pass it off.
|
||||
/*
|
||||
if (typeof Object1 === 'FlxTilemap')
|
||||
{
|
||||
return Object1.overlapsWithCallback(Object2, separateX);
|
||||
}
|
||||
|
||||
if (typeof Object2 === 'FlxTilemap')
|
||||
{
|
||||
return Object2.overlapsWithCallback(Object1, separateX, true);
|
||||
}
|
||||
*/
|
||||
|
||||
//First, get the two object deltas
|
||||
var overlap: number = 0;
|
||||
var obj1delta: number = Object1.x - Object1.last.x;
|
||||
var obj2delta: number = Object2.x - Object2.last.x;
|
||||
|
||||
if (obj1delta != obj2delta)
|
||||
{
|
||||
//Check if the X hulls actually overlap
|
||||
var obj1deltaAbs: number = (obj1delta > 0) ? obj1delta : -obj1delta;
|
||||
var obj2deltaAbs: number = (obj2delta > 0) ? obj2delta : -obj2delta;
|
||||
var obj1rect: Rectangle = new Rectangle(Object1.x - ((obj1delta > 0) ? obj1delta : 0), Object1.last.y, Object1.width + ((obj1delta > 0) ? obj1delta : -obj1delta), Object1.height);
|
||||
var obj2rect: Rectangle = new Rectangle(Object2.x - ((obj2delta > 0) ? obj2delta : 0), Object2.last.y, Object2.width + ((obj2delta > 0) ? obj2delta : -obj2delta), Object2.height);
|
||||
|
||||
if ((obj1rect.x + obj1rect.width > obj2rect.x) && (obj1rect.x < obj2rect.x + obj2rect.width) && (obj1rect.y + obj1rect.height > obj2rect.y) && (obj1rect.y < obj2rect.y + obj2rect.height))
|
||||
{
|
||||
var maxOverlap: number = obj1deltaAbs + obj2deltaAbs + GameObject.OVERLAP_BIAS;
|
||||
|
||||
//If they did overlap (and can), figure out by how much and flip the corresponding flags
|
||||
if (obj1delta > obj2delta)
|
||||
{
|
||||
overlap = Object1.x + Object1.width - Object2.x;
|
||||
|
||||
if ((overlap > maxOverlap) || !(Object1.allowCollisions & GameObject.RIGHT) || !(Object2.allowCollisions & GameObject.LEFT))
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object1.touching |= GameObject.RIGHT;
|
||||
Object2.touching |= GameObject.LEFT;
|
||||
}
|
||||
}
|
||||
else if (obj1delta < obj2delta)
|
||||
{
|
||||
overlap = Object1.x - Object2.width - Object2.x;
|
||||
|
||||
if ((-overlap > maxOverlap) || !(Object1.allowCollisions & GameObject.LEFT) || !(Object2.allowCollisions & GameObject.RIGHT))
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object1.touching |= GameObject.LEFT;
|
||||
Object2.touching |= GameObject.RIGHT;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (overlap != 0)
|
||||
{
|
||||
var obj1v: number = Object1.velocity.x;
|
||||
var obj2v: number = Object2.velocity.x;
|
||||
|
||||
if (!obj1immovable && !obj2immovable)
|
||||
{
|
||||
overlap *= 0.5;
|
||||
Object1.x = Object1.x - overlap;
|
||||
Object2.x += overlap;
|
||||
|
||||
var obj1velocity: number = Math.sqrt((obj2v * obj2v * Object2.mass) / Object1.mass) * ((obj2v > 0) ? 1 : -1);
|
||||
var obj2velocity: number = Math.sqrt((obj1v * obj1v * Object1.mass) / Object2.mass) * ((obj1v > 0) ? 1 : -1);
|
||||
var average: number = (obj1velocity + obj2velocity) * 0.5;
|
||||
obj1velocity -= average;
|
||||
obj2velocity -= average;
|
||||
Object1.velocity.x = average + obj1velocity * Object1.elasticity;
|
||||
Object2.velocity.x = average + obj2velocity * Object2.elasticity;
|
||||
}
|
||||
else if (!obj1immovable)
|
||||
{
|
||||
Object1.x = Object1.x - overlap;
|
||||
Object1.velocity.x = obj2v - obj1v * Object1.elasticity;
|
||||
}
|
||||
else if (!obj2immovable)
|
||||
{
|
||||
Object2.x += overlap;
|
||||
Object2.velocity.x = obj1v - obj2v * Object2.elasticity;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The Y-axis component of the object separation process.
|
||||
*
|
||||
* @param Object1 Any <code>Sprite</code>.
|
||||
* @param Object2 Any other <code>Sprite</code>.
|
||||
*
|
||||
* @return Whether the objects in fact touched and were separated along the Y axis.
|
||||
*/
|
||||
public static separateY(Object1, Object2): bool {
|
||||
|
||||
//can't separate two immovable objects
|
||||
|
||||
var obj1immovable: bool = Object1.immovable;
|
||||
var obj2immovable: bool = Object2.immovable;
|
||||
|
||||
if (obj1immovable && obj2immovable)
|
||||
return false;
|
||||
|
||||
//If one of the objects is a tilemap, just pass it off.
|
||||
/*
|
||||
if (typeof Object1 === 'FlxTilemap')
|
||||
{
|
||||
return Object1.overlapsWithCallback(Object2, separateY);
|
||||
}
|
||||
|
||||
if (typeof Object2 === 'FlxTilemap')
|
||||
{
|
||||
return Object2.overlapsWithCallback(Object1, separateY, true);
|
||||
}
|
||||
*/
|
||||
|
||||
//First, get the two object deltas
|
||||
var overlap: number = 0;
|
||||
var obj1delta: number = Object1.y - Object1.last.y;
|
||||
var obj2delta: number = Object2.y - Object2.last.y;
|
||||
|
||||
if (obj1delta != obj2delta)
|
||||
{
|
||||
//Check if the Y hulls actually overlap
|
||||
var obj1deltaAbs: number = (obj1delta > 0) ? obj1delta : -obj1delta;
|
||||
var obj2deltaAbs: number = (obj2delta > 0) ? obj2delta : -obj2delta;
|
||||
var obj1rect: Rectangle = new Rectangle(Object1.x, Object1.y - ((obj1delta > 0) ? obj1delta : 0), Object1.width, Object1.height + obj1deltaAbs);
|
||||
var obj2rect: Rectangle = new Rectangle(Object2.x, Object2.y - ((obj2delta > 0) ? obj2delta : 0), Object2.width, Object2.height + obj2deltaAbs);
|
||||
|
||||
if ((obj1rect.x + obj1rect.width > obj2rect.x) && (obj1rect.x < obj2rect.x + obj2rect.width) && (obj1rect.y + obj1rect.height > obj2rect.y) && (obj1rect.y < obj2rect.y + obj2rect.height))
|
||||
{
|
||||
var maxOverlap: number = obj1deltaAbs + obj2deltaAbs + GameObject.OVERLAP_BIAS;
|
||||
|
||||
//If they did overlap (and can), figure out by how much and flip the corresponding flags
|
||||
if (obj1delta > obj2delta)
|
||||
{
|
||||
overlap = Object1.y + Object1.height - Object2.y;
|
||||
|
||||
if ((overlap > maxOverlap) || !(Object1.allowCollisions & GameObject.DOWN) || !(Object2.allowCollisions & GameObject.UP))
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object1.touching |= GameObject.DOWN;
|
||||
Object2.touching |= GameObject.UP;
|
||||
}
|
||||
}
|
||||
else if (obj1delta < obj2delta)
|
||||
{
|
||||
overlap = Object1.y - Object2.height - Object2.y;
|
||||
|
||||
if ((-overlap > maxOverlap) || !(Object1.allowCollisions & GameObject.UP) || !(Object2.allowCollisions & GameObject.DOWN))
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object1.touching |= GameObject.UP;
|
||||
Object2.touching |= GameObject.DOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (overlap != 0)
|
||||
{
|
||||
var obj1v: number = Object1.velocity.y;
|
||||
var obj2v: number = Object2.velocity.y;
|
||||
|
||||
if (!obj1immovable && !obj2immovable)
|
||||
{
|
||||
overlap *= 0.5;
|
||||
Object1.y = Object1.y - overlap;
|
||||
Object2.y += overlap;
|
||||
|
||||
var obj1velocity: number = Math.sqrt((obj2v * obj2v * Object2.mass) / Object1.mass) * ((obj2v > 0) ? 1 : -1);
|
||||
var obj2velocity: number = Math.sqrt((obj1v * obj1v * Object1.mass) / Object2.mass) * ((obj1v > 0) ? 1 : -1);
|
||||
var average: number = (obj1velocity + obj2velocity) * 0.5;
|
||||
obj1velocity -= average;
|
||||
obj2velocity -= average;
|
||||
Object1.velocity.y = average + obj1velocity * Object1.elasticity;
|
||||
Object2.velocity.y = average + obj2velocity * Object2.elasticity;
|
||||
}
|
||||
else if (!obj1immovable)
|
||||
{
|
||||
Object1.y = Object1.y - overlap;
|
||||
Object1.velocity.y = obj2v - obj1v * Object1.elasticity;
|
||||
//This is special case code that handles cases like horizontal moving platforms you can ride
|
||||
if (Object2.active && Object2.moves && (obj1delta > obj2delta))
|
||||
{
|
||||
Object1.x += Object2.x - Object2.last.x;
|
||||
}
|
||||
}
|
||||
else if (!obj2immovable)
|
||||
{
|
||||
Object2.y += overlap;
|
||||
Object2.velocity.y = obj1v - obj2v * Object2.elasticity;
|
||||
//This is special case code that handles cases like horizontal moving platforms you can ride
|
||||
if (Object1.active && Object1.moves && (obj1delta < obj2delta))
|
||||
{
|
||||
Object2.x += Object1.x - Object1.last.x;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
461
Phaser/gameobjects/Emitter.ts
Normal file
461
Phaser/gameobjects/Emitter.ts
Normal file
|
@ -0,0 +1,461 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../Group.ts" />
|
||||
|
||||
/**
|
||||
* <code>Emitter</code> is a lightweight particle emitter.
|
||||
* It can be used for one-time explosions or for
|
||||
* continuous fx like rain and fire. <code>Emitter</code>
|
||||
* is not optimized or anything; all it does is launch
|
||||
* <code>Particle</code> objects out at set intervals
|
||||
* by setting their positions and velocities accordingly.
|
||||
* It is easy to use and relatively efficient,
|
||||
* relying on <code>Group</code>'s RECYCLE POWERS.
|
||||
*
|
||||
* @author Adam Atomic
|
||||
* @author Richard Davey
|
||||
*/
|
||||
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Emitter extends Group {
|
||||
|
||||
/**
|
||||
* Creates a new <code>FlxEmitter</code> object at a specific position.
|
||||
* Does NOT automatically generate or attach particles!
|
||||
*
|
||||
* @param X The X position of the emitter.
|
||||
* @param Y The Y position of the emitter.
|
||||
* @param Size Optional, specifies a maximum capacity for this emitter.
|
||||
*/
|
||||
constructor(game: Game, X: number = 0, Y: number = 0, Size: number = 0) {
|
||||
super(game, Size);
|
||||
this.x = X;
|
||||
this.y = Y;
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
this.minParticleSpeed = new Point(-100, -100);
|
||||
this.maxParticleSpeed = new Point(100, 100);
|
||||
this.minRotation = -360;
|
||||
this.maxRotation = 360;
|
||||
this.gravity = 0;
|
||||
this.particleClass = null;
|
||||
this.particleDrag = new Point();
|
||||
this.frequency = 0.1;
|
||||
this.lifespan = 3;
|
||||
this.bounce = 0;
|
||||
this._quantity = 0;
|
||||
this._counter = 0;
|
||||
this._explode = true;
|
||||
this.on = false;
|
||||
this._point = new Point();
|
||||
}
|
||||
|
||||
/**
|
||||
* The X position of the top left corner of the emitter in world space.
|
||||
*/
|
||||
public x: number;
|
||||
|
||||
/**
|
||||
* The Y position of the top left corner of emitter in world space.
|
||||
*/
|
||||
public y: number;
|
||||
|
||||
/**
|
||||
* The width of the emitter. Particles can be randomly generated from anywhere within this box.
|
||||
*/
|
||||
public width: number;
|
||||
|
||||
/**
|
||||
* The height of the emitter. Particles can be randomly generated from anywhere within this box.
|
||||
*/
|
||||
public height: number;
|
||||
|
||||
/**
|
||||
* The minimum possible velocity of a particle.
|
||||
* The default value is (-100,-100).
|
||||
*/
|
||||
public minParticleSpeed: Point;
|
||||
|
||||
/**
|
||||
* The maximum possible velocity of a particle.
|
||||
* The default value is (100,100).
|
||||
*/
|
||||
public maxParticleSpeed: Point;
|
||||
|
||||
/**
|
||||
* The X and Y drag component of particles launched from the emitter.
|
||||
*/
|
||||
public particleDrag: Point;
|
||||
|
||||
/**
|
||||
* The minimum possible angular velocity of a particle. The default value is -360.
|
||||
* NOTE: rotating particles are more expensive to draw than non-rotating ones!
|
||||
*/
|
||||
public minRotation: number;
|
||||
|
||||
/**
|
||||
* The maximum possible angular velocity of a particle. The default value is 360.
|
||||
* NOTE: rotating particles are more expensive to draw than non-rotating ones!
|
||||
*/
|
||||
public maxRotation: number;
|
||||
|
||||
/**
|
||||
* Sets the <code>acceleration.y</code> member of each particle to this value on launch.
|
||||
*/
|
||||
public gravity: number;
|
||||
|
||||
/**
|
||||
* Determines whether the emitter is currently emitting particles.
|
||||
* It is totally safe to directly toggle this.
|
||||
*/
|
||||
public on: bool;
|
||||
|
||||
/**
|
||||
* How often a particle is emitted (if emitter is started with Explode == false).
|
||||
*/
|
||||
public frequency: number;
|
||||
|
||||
/**
|
||||
* How long each particle lives once it is emitted.
|
||||
* Set lifespan to 'zero' for particles to live forever.
|
||||
*/
|
||||
public lifespan: number;
|
||||
|
||||
/**
|
||||
* How much each particle should bounce. 1 = full bounce, 0 = no bounce.
|
||||
*/
|
||||
public bounce: number;
|
||||
|
||||
/**
|
||||
* Set your own particle class type here.
|
||||
* Default is <code>Particle</code>.
|
||||
*/
|
||||
public particleClass;
|
||||
|
||||
/**
|
||||
* Internal helper for deciding how many particles to launch.
|
||||
*/
|
||||
private _quantity: number;
|
||||
|
||||
/**
|
||||
* Internal helper for the style of particle emission (all at once, or one at a time).
|
||||
*/
|
||||
private _explode: bool;
|
||||
|
||||
/**
|
||||
* Internal helper for deciding when to launch particles or kill them.
|
||||
*/
|
||||
private _timer: number;
|
||||
|
||||
/**
|
||||
* Internal counter for figuring out how many particles to launch.
|
||||
*/
|
||||
private _counter: number;
|
||||
|
||||
/**
|
||||
* Internal point object, handy for reusing for memory mgmt purposes.
|
||||
*/
|
||||
private _point: Point;
|
||||
|
||||
/**
|
||||
* Clean up memory.
|
||||
*/
|
||||
public destroy() {
|
||||
this.minParticleSpeed = null;
|
||||
this.maxParticleSpeed = null;
|
||||
this.particleDrag = null;
|
||||
this.particleClass = null;
|
||||
this._point = null;
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function generates a new array of particle sprites to attach to the emitter.
|
||||
*
|
||||
* @param Graphics If you opted to not pre-configure an array of FlxSprite objects, you can simply pass in a particle image or sprite sheet.
|
||||
* @param Quantity The number of particles to generate when using the "create from image" option.
|
||||
* @param BakedRotations How many frames of baked rotation to use (boosts performance). Set to zero to not use baked rotations.
|
||||
* @param Multiple Whether the image in the Graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!).
|
||||
* @param Collide Whether the particles should be flagged as not 'dead' (non-colliding particles are higher performance). 0 means no collisions, 0-1 controls scale of particle's bounding box.
|
||||
*
|
||||
* @return This FlxEmitter instance (nice for chaining stuff together, if you're into that).
|
||||
*/
|
||||
public makeParticles(Graphics, Quantity: number = 50, BakedRotations: number = 16, Multiple: bool = false, Collide: number = 0.8): Emitter {
|
||||
|
||||
this.maxSize = Quantity;
|
||||
|
||||
var totalFrames: number = 1;
|
||||
|
||||
/*
|
||||
if(Multiple)
|
||||
{
|
||||
var sprite:Sprite = new Sprite(this._game);
|
||||
sprite.loadGraphic(Graphics,true);
|
||||
totalFrames = sprite.frames;
|
||||
sprite.destroy();
|
||||
}
|
||||
*/
|
||||
|
||||
var randomFrame: number;
|
||||
var particle: Particle;
|
||||
var i: number = 0;
|
||||
|
||||
while (i < Quantity)
|
||||
{
|
||||
if (this.particleClass == null)
|
||||
{
|
||||
particle = new Particle(this._game);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle = new this.particleClass(this._game);
|
||||
}
|
||||
|
||||
if (Multiple)
|
||||
{
|
||||
/*
|
||||
randomFrame = this._game.math.random()*totalFrames;
|
||||
if(BakedRotations > 0)
|
||||
particle.loadRotatedGraphic(Graphics,BakedRotations,randomFrame);
|
||||
else
|
||||
{
|
||||
particle.loadGraphic(Graphics,true);
|
||||
particle.frame = randomFrame;
|
||||
}
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
if (BakedRotations > 0)
|
||||
particle.loadRotatedGraphic(Graphics,BakedRotations);
|
||||
else
|
||||
particle.loadGraphic(Graphics);
|
||||
*/
|
||||
|
||||
if (Graphics)
|
||||
{
|
||||
particle.loadGraphic(Graphics);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Collide > 0)
|
||||
{
|
||||
particle.width *= Collide;
|
||||
particle.height *= Collide;
|
||||
//particle.centerOffsets();
|
||||
}
|
||||
else
|
||||
{
|
||||
particle.allowCollisions = Collision.NONE;
|
||||
}
|
||||
|
||||
particle.exists = false;
|
||||
|
||||
this.add(particle);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called automatically by the game loop, decides when to launch particles and when to "die".
|
||||
*/
|
||||
public update() {
|
||||
|
||||
if (this.on)
|
||||
{
|
||||
if (this._explode)
|
||||
{
|
||||
this.on = false;
|
||||
|
||||
var i: number = 0;
|
||||
var l: number = this._quantity;
|
||||
|
||||
if ((l <= 0) || (l > this.length))
|
||||
{
|
||||
l = this.length;
|
||||
}
|
||||
|
||||
while (i < l)
|
||||
{
|
||||
this.emitParticle();
|
||||
i++;
|
||||
}
|
||||
|
||||
this._quantity = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._timer += this._game.time.elapsed;
|
||||
|
||||
while ((this.frequency > 0) && (this._timer > this.frequency) && this.on)
|
||||
{
|
||||
this._timer -= this.frequency;
|
||||
this.emitParticle();
|
||||
|
||||
if ((this._quantity > 0) && (++this._counter >= this._quantity))
|
||||
{
|
||||
this.on = false;
|
||||
this._quantity = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.update();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this function to turn off all the particles and the emitter.
|
||||
*/
|
||||
public kill() {
|
||||
|
||||
this.on = false;
|
||||
|
||||
super.kill();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this function to start emitting particles.
|
||||
*
|
||||
* @param Explode Whether the particles should all burst out at once.
|
||||
* @param Lifespan How long each particle lives once emitted. 0 = forever.
|
||||
* @param Frequency Ignored if Explode is set to true. Frequency is how often to emit a particle. 0 = never emit, 0.1 = 1 particle every 0.1 seconds, 5 = 1 particle every 5 seconds.
|
||||
* @param Quantity How many particles to launch. 0 = "all of the particles".
|
||||
*/
|
||||
public start(Explode: bool = true, Lifespan: number = 0, Frequency: number = 0.1, Quantity: number = 0) {
|
||||
|
||||
this.revive();
|
||||
|
||||
this.visible = true;
|
||||
this.on = true;
|
||||
|
||||
this._explode = Explode;
|
||||
this.lifespan = Lifespan;
|
||||
this.frequency = Frequency;
|
||||
this._quantity += Quantity;
|
||||
|
||||
this._counter = 0;
|
||||
this._timer = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function can be used both internally and externally to emit the next particle.
|
||||
*/
|
||||
public emitParticle() {
|
||||
|
||||
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.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);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle.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);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle.velocity.y = this.minParticleSpeed.y;
|
||||
}
|
||||
|
||||
particle.acceleration.y = this.gravity;
|
||||
|
||||
if (this.minRotation != this.maxRotation)
|
||||
{
|
||||
particle.angularVelocity = this.minRotation + this._game.math.random() * (this.maxRotation - this.minRotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle.angularVelocity = this.minRotation;
|
||||
}
|
||||
|
||||
if (particle.angularVelocity != 0)
|
||||
{
|
||||
particle.angle = this._game.math.random() * 360 - 180;
|
||||
}
|
||||
|
||||
particle.drag.x = this.particleDrag.x;
|
||||
particle.drag.y = this.particleDrag.y;
|
||||
particle.onEmit();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A more compact way of setting the width and height of the emitter.
|
||||
*
|
||||
* @param Width The desired width of the emitter (particles are spawned randomly within these dimensions).
|
||||
* @param Height The desired height of the emitter.
|
||||
*/
|
||||
public setSize(Width: number, Height: number) {
|
||||
this.width = Width;
|
||||
this.height = Height;
|
||||
}
|
||||
|
||||
/**
|
||||
* A more compact way of setting the X velocity range of the emitter.
|
||||
*
|
||||
* @param Min The minimum value for this range.
|
||||
* @param Max The maximum value for this range.
|
||||
*/
|
||||
public setXSpeed(Min: number = 0, Max: number = 0) {
|
||||
this.minParticleSpeed.x = Min;
|
||||
this.maxParticleSpeed.x = Max;
|
||||
}
|
||||
|
||||
/**
|
||||
* A more compact way of setting the Y velocity range of the emitter.
|
||||
*
|
||||
* @param Min The minimum value for this range.
|
||||
* @param Max The maximum value for this range.
|
||||
*/
|
||||
public setYSpeed(Min: number = 0, Max: number = 0) {
|
||||
this.minParticleSpeed.y = Min;
|
||||
this.maxParticleSpeed.y = Max;
|
||||
}
|
||||
|
||||
/**
|
||||
* A more compact way of setting the angular velocity constraints of the emitter.
|
||||
*
|
||||
* @param Min The minimum value for this range.
|
||||
* @param Max The maximum value for this range.
|
||||
*/
|
||||
public setRotation(Min: number = 0, Max: number = 0) {
|
||||
this.minRotation = Min;
|
||||
this.maxRotation = Max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the emitter's midpoint to match the midpoint of a <code>FlxObject</code>.
|
||||
*
|
||||
* @param Object The <code>FlxObject</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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
494
Phaser/gameobjects/GameObject.ts
Normal file
494
Phaser/gameobjects/GameObject.ts
Normal file
|
@ -0,0 +1,494 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../Basic.ts" />
|
||||
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class GameObject extends Basic {
|
||||
|
||||
constructor(game: Game, x?: number = 0, y?: number = 0, width?: number = 16, height?: number = 16) {
|
||||
|
||||
super(game);
|
||||
|
||||
this.bounds = 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 Point(1, 1);
|
||||
|
||||
this.last = new Point(x, y);
|
||||
this.origin = new Point(this.bounds.halfWidth, this.bounds.halfHeight);
|
||||
this.mass = 1.0;
|
||||
this.elasticity = 0.0;
|
||||
this.health = 1;
|
||||
this.immovable = false;
|
||||
this.moves = true;
|
||||
|
||||
this.touching = Collision.NONE;
|
||||
this.wasTouching = Collision.NONE;
|
||||
this.allowCollisions = Collision.ANY;
|
||||
|
||||
this.velocity = new Point();
|
||||
this.acceleration = new Point();
|
||||
this.drag = new Point();
|
||||
this.maxVelocity = new Point(10000, 10000);
|
||||
|
||||
this.angle = 0;
|
||||
this.angularVelocity = 0;
|
||||
this.angularAcceleration = 0;
|
||||
this.angularDrag = 0;
|
||||
this.maxAngular = 10000;
|
||||
|
||||
this.scrollFactor = new Point(1.0, 1.0);
|
||||
|
||||
}
|
||||
|
||||
private _angle: number = 0;
|
||||
public _point: Point;
|
||||
|
||||
public bounds: Rectangle;
|
||||
public facing: number;
|
||||
public alpha: number;
|
||||
public scale: Point;
|
||||
public origin: Point;
|
||||
public z: number = 0;
|
||||
|
||||
// Physics properties
|
||||
public immovable: bool;
|
||||
public velocity: Point;
|
||||
public mass: number;
|
||||
public elasticity: number;
|
||||
public acceleration: Point;
|
||||
public drag: Point;
|
||||
public maxVelocity: Point;
|
||||
public angularVelocity: number;
|
||||
public angularAcceleration: number;
|
||||
public angularDrag: number;
|
||||
public maxAngular: number;
|
||||
public scrollFactor: Point;
|
||||
|
||||
public health: number;
|
||||
public moves: bool = true;
|
||||
public touching: number;
|
||||
public wasTouching: number;
|
||||
public allowCollisions: number;
|
||||
public last: Point;
|
||||
|
||||
public preUpdate() {
|
||||
|
||||
// flicker time
|
||||
|
||||
this.last.x = this.bounds.x;
|
||||
this.last.y = this.bounds.y;
|
||||
|
||||
}
|
||||
|
||||
public update() {
|
||||
}
|
||||
|
||||
public postUpdate() {
|
||||
|
||||
if (this.moves)
|
||||
{
|
||||
this.updateMotion();
|
||||
}
|
||||
|
||||
this.wasTouching = this.touching;
|
||||
this.touching = Collision.NONE;
|
||||
|
||||
}
|
||||
|
||||
private updateMotion() {
|
||||
|
||||
var delta: number;
|
||||
var velocityDelta: number;
|
||||
|
||||
velocityDelta = (this._game.motion.computeVelocity(this.angularVelocity, this.angularAcceleration, this.angularDrag, this.maxAngular) - this.angularVelocity) / 2;
|
||||
this.angularVelocity += velocityDelta;
|
||||
this._angle += this.angularVelocity * this._game.time.elapsed;
|
||||
this.angularVelocity += velocityDelta;
|
||||
|
||||
velocityDelta = (this._game.motion.computeVelocity(this.velocity.x, this.acceleration.x, this.drag.x, this.maxVelocity.x) - this.velocity.x) / 2;
|
||||
this.velocity.x += velocityDelta;
|
||||
delta = this.velocity.x * this._game.time.elapsed;
|
||||
this.velocity.x += velocityDelta;
|
||||
this.bounds.x += delta;
|
||||
|
||||
velocityDelta = (this._game.motion.computeVelocity(this.velocity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y) - this.velocity.y) / 2;
|
||||
this.velocity.y += velocityDelta;
|
||||
delta = this.velocity.y * this._game.time.elapsed;
|
||||
this.velocity.y += velocityDelta;
|
||||
this.bounds.y += delta;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if some <code>GameObject</code> overlaps this <code>GameObject</code> or <code>FlxGroup</code>.
|
||||
* If the group has a LOT of things in it, it might be faster to use <code>FlxG.overlaps()</code>.
|
||||
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
|
||||
*
|
||||
* @param ObjectOrGroup The object or group being tested.
|
||||
* @param InScreenSpace Whether to take scroll factors numbero account when checking for overlap. Default is false, or "only compare in world space."
|
||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
*
|
||||
* @return Whether or not the two objects overlap.
|
||||
*/
|
||||
public overlaps(ObjectOrGroup, InScreenSpace: bool = false, Camera: Camera = null): bool {
|
||||
|
||||
if (ObjectOrGroup.isGroup)
|
||||
{
|
||||
var results: bool = false;
|
||||
var i: number = 0;
|
||||
var members = <Group> ObjectOrGroup.members;
|
||||
|
||||
while (i < length)
|
||||
{
|
||||
if (this.overlaps(members[i++], InScreenSpace, Camera))
|
||||
{
|
||||
results = true;
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
if (typeof ObjectOrGroup === 'FlxTilemap')
|
||||
{
|
||||
//Since tilemap's have to be the caller, not the target, to do proper tile-based collisions,
|
||||
// we redirect the call to the tilemap overlap here.
|
||||
return ObjectOrGroup.overlaps(this, InScreenSpace, Camera);
|
||||
}
|
||||
*/
|
||||
|
||||
//var object: GameObject = ObjectOrGroup;
|
||||
|
||||
if (!InScreenSpace)
|
||||
{
|
||||
return (ObjectOrGroup.x + ObjectOrGroup.width > this.x) && (ObjectOrGroup.x < this.x + this.width) &&
|
||||
(ObjectOrGroup.y + ObjectOrGroup.height > this.y) && (ObjectOrGroup.y < this.y + this.height);
|
||||
}
|
||||
|
||||
if (Camera == null)
|
||||
{
|
||||
Camera = this._game.camera;
|
||||
}
|
||||
|
||||
var objectScreenPos: Point = ObjectOrGroup.getScreenXY(null, Camera);
|
||||
|
||||
this.getScreenXY(this._point, Camera);
|
||||
|
||||
return (objectScreenPos.x + ObjectOrGroup.width > this._point.x) && (objectScreenPos.x < this._point.x + this.width) &&
|
||||
(objectScreenPos.y + ObjectOrGroup.height > this._point.y) && (objectScreenPos.y < this._point.y + this.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if this <code>GameObject</code> were located at the given position, would it overlap the <code>GameObject</code> or <code>FlxGroup</code>?
|
||||
* This is distinct from overlapsPoint(), which just checks that ponumber, rather than taking the object's size numbero account.
|
||||
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
|
||||
*
|
||||
* @param X The X position you want to check. Pretends this object (the caller, not the parameter) is located here.
|
||||
* @param Y The Y position you want to check. Pretends this object (the caller, not the parameter) is located here.
|
||||
* @param ObjectOrGroup The object or group being tested.
|
||||
* @param InScreenSpace Whether to take scroll factors numbero account when checking for overlap. Default is false, or "only compare in world space."
|
||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
*
|
||||
* @return Whether or not the two objects overlap.
|
||||
*/
|
||||
public overlapsAt(X: number, Y: number, ObjectOrGroup, InScreenSpace: bool = false, Camera: Camera = null): bool {
|
||||
|
||||
if (ObjectOrGroup.isGroup)
|
||||
{
|
||||
var results: bool = false;
|
||||
var basic;
|
||||
var i: number = 0;
|
||||
var members = ObjectOrGroup.members;
|
||||
|
||||
while (i < length)
|
||||
{
|
||||
if (this.overlapsAt(X, Y, members[i++], InScreenSpace, Camera))
|
||||
{
|
||||
results = true;
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/*
|
||||
if (typeof ObjectOrGroup === 'FlxTilemap')
|
||||
{
|
||||
//Since tilemap's have to be the caller, not the target, to do proper tile-based collisions,
|
||||
// we redirect the call to the tilemap overlap here.
|
||||
//However, since this is overlapsAt(), we also have to invent the appropriate position for the tilemap.
|
||||
//So we calculate the offset between the player and the requested position, and subtract that from the tilemap.
|
||||
var tilemap: FlxTilemap = ObjectOrGroup;
|
||||
return tilemap.overlapsAt(tilemap.x - (X - this.x), tilemap.y - (Y - this.y), this, InScreenSpace, Camera);
|
||||
}
|
||||
*/
|
||||
|
||||
//var object: GameObject = ObjectOrGroup;
|
||||
|
||||
if (!InScreenSpace)
|
||||
{
|
||||
return (ObjectOrGroup.x + ObjectOrGroup.width > X) && (ObjectOrGroup.x < X + this.width) &&
|
||||
(ObjectOrGroup.y + ObjectOrGroup.height > Y) && (ObjectOrGroup.y < Y + this.height);
|
||||
}
|
||||
|
||||
if (Camera == null)
|
||||
{
|
||||
Camera = this._game.camera;
|
||||
}
|
||||
|
||||
var objectScreenPos: Point = ObjectOrGroup.getScreenXY(null, Camera);
|
||||
|
||||
this._point.x = X - Camera.scroll.x * this.scrollFactor.x; //copied from getScreenXY()
|
||||
this._point.y = Y - Camera.scroll.y * this.scrollFactor.y;
|
||||
this._point.x += (this._point.x > 0) ? 0.0000001 : -0.0000001;
|
||||
this._point.y += (this._point.y > 0) ? 0.0000001 : -0.0000001;
|
||||
|
||||
return (objectScreenPos.x + ObjectOrGroup.width > this._point.x) && (objectScreenPos.x < this._point.x + this.width) &&
|
||||
(objectScreenPos.y + ObjectOrGroup.height > this._point.y) && (objectScreenPos.y < this._point.y + this.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a ponumber in 2D world space overlaps this <code>GameObject</code> object.
|
||||
*
|
||||
* @param Point The ponumber in world space you want to check.
|
||||
* @param InScreenSpace Whether to take scroll factors numbero account when checking for overlap.
|
||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
*
|
||||
* @return Whether or not the ponumber overlaps this object.
|
||||
*/
|
||||
public overlapsPoint(point: Point, InScreenSpace: bool = false, Camera: Camera = null): bool {
|
||||
|
||||
if (!InScreenSpace)
|
||||
{
|
||||
return (point.x > this.x) && (point.x < this.x + this.width) && (point.y > this.y) && (point.y < this.y + this.height);
|
||||
}
|
||||
|
||||
if (Camera == null)
|
||||
{
|
||||
Camera = this._game.camera;
|
||||
}
|
||||
|
||||
var X: number = point.x - Camera.scroll.x;
|
||||
var Y: number = point.y - Camera.scroll.y;
|
||||
|
||||
this.getScreenXY(this._point, Camera);
|
||||
|
||||
return (X > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and see if this object is currently on screen.
|
||||
*
|
||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
*
|
||||
* @return Whether the object is on screen or not.
|
||||
*/
|
||||
public onScreen(Camera: Camera = null): bool {
|
||||
|
||||
if (Camera == null)
|
||||
{
|
||||
Camera = this._game.camera;
|
||||
}
|
||||
|
||||
this.getScreenXY(this._point, Camera);
|
||||
|
||||
return (this._point.x + this.width > 0) && (this._point.x < Camera.width) && (this._point.y + this.height > 0) && (this._point.y < Camera.height);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this to figure out the on-screen position of the object.
|
||||
*
|
||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
||||
* @param Point Takes a <code>Point</code> object and assigns the post-scrolled X and Y values of this object to it.
|
||||
*
|
||||
* @return 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.
|
||||
*/
|
||||
public getScreenXY(point: Point = null, Camera: Camera = null): Point {
|
||||
|
||||
if (point == null)
|
||||
{
|
||||
point = new Point();
|
||||
}
|
||||
|
||||
if (Camera == null)
|
||||
{
|
||||
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 += (point.x > 0) ? 0.0000001 : -0.0000001;
|
||||
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
|
||||
|
||||
return point;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the object collides or not. For more control over what directions
|
||||
* the object will collide from, use collision constants (like LEFT, FLOOR, etc)
|
||||
* to set the value of allowCollisions directly.
|
||||
*/
|
||||
public get solid(): bool {
|
||||
return (this.allowCollisions & Collision.ANY) > Collision.NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
public set solid(Solid: bool) {
|
||||
|
||||
if (Solid)
|
||||
{
|
||||
this.allowCollisions = Collision.ANY;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.allowCollisions = Collision.NONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the midponumber of this object in world coordinates.
|
||||
*
|
||||
* @Point Allows you to pass in an existing <code>Point</code> object if you're so inclined. Otherwise a new one is created.
|
||||
*
|
||||
* @return A <code>Point</code> object containing the midponumber of this object in world coordinates.
|
||||
*/
|
||||
public getMidpoint(point: Point = null): Point {
|
||||
|
||||
if (point == null)
|
||||
{
|
||||
point = new Point();
|
||||
}
|
||||
|
||||
point.x = this.x + this.width * 0.5;
|
||||
point.y = this.y + this.height * 0.5;
|
||||
|
||||
return point;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handy for reviving game objects.
|
||||
* Resets their existence flags and position.
|
||||
*
|
||||
* @param X The new X position of this object.
|
||||
* @param Y The new Y position of this object.
|
||||
*/
|
||||
public reset(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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handy for checking if this object is touching a particular surface.
|
||||
* For slightly better performance you can just & the value directly numbero <code>touching</code>.
|
||||
* However, this method is good for readability and accessibility.
|
||||
*
|
||||
* @param Direction Any of the collision flags (e.g. LEFT, FLOOR, etc).
|
||||
*
|
||||
* @return Whether the object is touching an object in (any of) the specified direction(s) this frame.
|
||||
*/
|
||||
public isTouching(Direction: number): bool {
|
||||
return (this.touching & Direction) > Collision.NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handy for checking if this object is just landed on a particular surface.
|
||||
*
|
||||
* @param Direction Any of the collision flags (e.g. LEFT, FLOOR, etc).
|
||||
*
|
||||
* @return Whether the object just landed on (any of) the specified surface(s) this frame.
|
||||
*/
|
||||
public justTouched(Direction: number): bool {
|
||||
return ((this.touching & Direction) > Collision.NONE) && ((this.wasTouching & Direction) <= Collision.NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces the "health" variable of this sprite by the amount specified in Damage.
|
||||
* Calls kill() if health drops to or below zero.
|
||||
*
|
||||
* @param Damage 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
|
||||
}
|
||||
|
||||
public get x(): number {
|
||||
return this.bounds.x;
|
||||
}
|
||||
|
||||
public set x(value: number) {
|
||||
this.bounds.x = value;
|
||||
}
|
||||
|
||||
public get y(): number {
|
||||
return this.bounds.y;
|
||||
}
|
||||
|
||||
public set y(value: number) {
|
||||
this.bounds.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 get width(): number {
|
||||
return this.bounds.width;
|
||||
}
|
||||
|
||||
public get height(): number {
|
||||
return this.bounds.height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
431
Phaser/gameobjects/GeomSprite.ts
Normal file
431
Phaser/gameobjects/GeomSprite.ts
Normal file
|
@ -0,0 +1,431 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class GeomSprite extends GameObject {
|
||||
|
||||
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;
|
||||
|
||||
public type: number = 0;
|
||||
|
||||
public static UNASSIGNED: number = 0;
|
||||
public static CIRCLE: number = 1;
|
||||
public static LINE: number = 2;
|
||||
public static POINT: number = 3;
|
||||
public static RECTANGLE: number = 4;
|
||||
|
||||
public circle: Circle;
|
||||
public line: Line;
|
||||
public point: Point;
|
||||
public rect: Rectangle;
|
||||
|
||||
public renderOutline: bool = true;
|
||||
public renderFill: bool = true;
|
||||
|
||||
public lineWidth: number = 1;
|
||||
public lineColor: string = 'rgb(0,255,0)';
|
||||
public fillColor: string = 'rgb(0,100,0)';
|
||||
|
||||
loadCircle(circle:Circle): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.circle = circle;
|
||||
this.type = GeomSprite.CIRCLE;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
loadLine(line:Line): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.line = line;
|
||||
this.type = GeomSprite.LINE;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
loadPoint(point:Point): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.point = point;
|
||||
this.type = GeomSprite.POINT;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
loadRectangle(rect:Rectangle): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.rect = rect;
|
||||
this.type = GeomSprite.RECTANGLE;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
createCircle(diameter: number): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.circle = new Circle(this.x, this.y, diameter);
|
||||
this.type = GeomSprite.CIRCLE;
|
||||
this.bounds.setTo(this.circle.x - this.circle.radius, this.circle.y - this.circle.radius, this.circle.diameter, this.circle.diameter);
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
createLine(x: number, y: number): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.line = new Line(this.x, this.y, x, y);
|
||||
this.type = GeomSprite.LINE;
|
||||
this.bounds.setTo(this.x, this.y, this.line.width, this.line.height);
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
createPoint(): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.point = new Point(this.x, this.y);
|
||||
this.type = GeomSprite.POINT;
|
||||
this.bounds.width = 1;
|
||||
this.bounds.height = 1;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
createRectangle(width: number, height: number): GeomSprite {
|
||||
|
||||
this.refresh();
|
||||
this.rect = new Rectangle(this.x, this.y, width, height);
|
||||
this.type = GeomSprite.RECTANGLE;
|
||||
this.bounds.copyFrom(this.rect);
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
refresh() {
|
||||
|
||||
this.circle = null;
|
||||
this.line = null;
|
||||
this.point = null;
|
||||
this.rect = null;
|
||||
|
||||
}
|
||||
|
||||
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.bounds.width = this.circle.diameter;
|
||||
this.bounds.height = this.circle.diameter;
|
||||
}
|
||||
else if (this.type == GeomSprite.LINE)
|
||||
{
|
||||
this.line.x1 = this.x;
|
||||
this.line.y1 = this.y;
|
||||
this.bounds.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.bounds.copyFrom(this.rect);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public inCamera(camera: Rectangle): bool {
|
||||
|
||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
||||
{
|
||||
this._dx = this.bounds.x - (camera.x * this.scrollFactor.x);
|
||||
this._dy = this.bounds.y - (camera.y * this.scrollFactor.x);
|
||||
this._dw = this.bounds.width * this.scale.x;
|
||||
this._dh = this.bounds.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.overlap(this.bounds);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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.inCamera(camera.worldView) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Alpha
|
||||
if (this.alpha !== 1)
|
||||
{
|
||||
var globalAlpha = this._game.stage.context.globalAlpha;
|
||||
this._game.stage.context.globalAlpha = this.alpha;
|
||||
}
|
||||
|
||||
this._dx = cameraOffsetX + (this.bounds.x - camera.worldView.x);
|
||||
this._dy = cameraOffsetY + (this.bounds.y - camera.worldView.y);
|
||||
this._dw = this.bounds.width * this.scale.x;
|
||||
this._dh = this.bounds.height * this.scale.y;
|
||||
|
||||
// Circles are drawn center based
|
||||
if (this.type == GeomSprite.CIRCLE)
|
||||
{
|
||||
this._dx += this.circle.radius;
|
||||
this._dy += this.circle.radius;
|
||||
}
|
||||
|
||||
// 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 (misleading?)
|
||||
if (this.angle !== 0)
|
||||
{
|
||||
this._game.stage.context.save();
|
||||
this._game.stage.context.translate(this._dx + (this._dw / 2) - this.origin.x, this._dy + (this._dh / 2) - this.origin.y);
|
||||
this._game.stage.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._game.stage.context.fillStyle = 'rgba(255,0,0,0.5)';
|
||||
this._game.stage.context.fillRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
|
||||
this._game.stage.context.lineWidth = this.lineWidth;
|
||||
this._game.stage.context.strokeStyle = this.lineColor;
|
||||
this._game.stage.context.fillStyle = this.fillColor;
|
||||
|
||||
if (this._game.stage.fillStyle !== this.fillColor)
|
||||
{
|
||||
}
|
||||
|
||||
// Primitive Renderer
|
||||
if (this.type == GeomSprite.CIRCLE)
|
||||
{
|
||||
this._game.stage.context.beginPath();
|
||||
this._game.stage.context.arc(this._dx, this._dy, this.circle.radius, 0, Math.PI * 2);
|
||||
this._game.stage.context.stroke();
|
||||
|
||||
if (this.renderFill)
|
||||
{
|
||||
this._game.stage.context.fill();
|
||||
}
|
||||
|
||||
this._game.stage.context.closePath();
|
||||
}
|
||||
else if (this.type == GeomSprite.LINE)
|
||||
{
|
||||
this._game.stage.context.beginPath();
|
||||
this._game.stage.context.moveTo(this._dx, this._dy);
|
||||
this._game.stage.context.lineTo(this.line.x2, this.line.y2);
|
||||
this._game.stage.context.stroke();
|
||||
this._game.stage.context.closePath();
|
||||
}
|
||||
else if (this.type == GeomSprite.POINT)
|
||||
{
|
||||
this._game.stage.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._game.stage.context.fillRect(this._dx, this._dy, this.rect.width, this.rect.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._game.stage.context.beginPath();
|
||||
|
||||
this._game.stage.context.rect(this._dx, this._dy, this.rect.width, this.rect.height);
|
||||
this._game.stage.context.stroke();
|
||||
|
||||
if (this.renderFill)
|
||||
{
|
||||
this._game.stage.context.fill();
|
||||
}
|
||||
|
||||
this._game.stage.context.closePath();
|
||||
}
|
||||
}
|
||||
|
||||
this._game.stage.restoreCanvasValues();
|
||||
|
||||
if (this.rotation !== 0)
|
||||
{
|
||||
this._game.stage.context.translate(0, 0);
|
||||
this._game.stage.context.restore();
|
||||
}
|
||||
|
||||
if (globalAlpha > -1)
|
||||
{
|
||||
this._game.stage.context.globalAlpha = globalAlpha;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
//this._game.stage.context.fillStyle = color;
|
||||
//this._game.stage.context.fillText('Sprite: ' + this.name + ' (' + this.bounds.width + ' x ' + this.bounds.height + ')', x, y);
|
||||
//this._game.stage.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' rotation: ' + this.angle.toFixed(1), x, y + 14);
|
||||
//this._game.stage.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._game.stage.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.
|
||||
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.LINE)
|
||||
{
|
||||
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.LINE)
|
||||
{
|
||||
return this.line.isPointOnLine(source.point.x, source.point.y);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
115
Phaser/gameobjects/Particle.ts
Normal file
115
Phaser/gameobjects/Particle.ts
Normal file
|
@ -0,0 +1,115 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="Sprite.ts" />
|
||||
|
||||
/**
|
||||
* This is a simple particle class that extends the default behavior
|
||||
* of <code>Sprite</code> to have slightly more specialized behavior
|
||||
* common to many game scenarios. You can override and extend this class
|
||||
* just like you would <code>Sprite</code>. While <code>Emitter</code>
|
||||
* used to work with just any old sprite, it now requires a
|
||||
* <code>Particle</code> based class.
|
||||
*
|
||||
* @author Adam Atomic
|
||||
* @author Richard Davey
|
||||
*/
|
||||
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Particle extends Sprite {
|
||||
|
||||
/**
|
||||
* Instantiate a new particle. Like <code>Sprite</code>, all meaningful creation
|
||||
* happens during <code>loadGraphic()</code> or <code>makeGraphic()</code> or whatever.
|
||||
*/
|
||||
constructor(game: Game) {
|
||||
|
||||
super(game);
|
||||
|
||||
this.lifespan = 0;
|
||||
this.friction = 500;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long this particle lives before it disappears.
|
||||
* NOTE: this is a maximum, not a minimum; the object
|
||||
* could get recycled before its lifespan is up.
|
||||
*/
|
||||
public lifespan: number;
|
||||
|
||||
/**
|
||||
* Determines how quickly the particles come to rest on the ground.
|
||||
* Only used if the particle has gravity-like acceleration applied.
|
||||
* @default 500
|
||||
*/
|
||||
public friction: number;
|
||||
|
||||
/**
|
||||
* The particle's main update logic. Basically it checks to see if it should
|
||||
* be dead yet, and then has some special bounce behavior if there is some gravity on it.
|
||||
*/
|
||||
public update() {
|
||||
//lifespan behavior
|
||||
if (this.lifespan <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.lifespan -= this._game.time.elapsed;
|
||||
|
||||
if (this.lifespan <= 0)
|
||||
{
|
||||
this.kill();
|
||||
}
|
||||
|
||||
//simpler bounce/spin behavior for now
|
||||
if (this.touching)
|
||||
{
|
||||
if (this.angularVelocity != 0)
|
||||
{
|
||||
this.angularVelocity = -this.angularVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.acceleration.y > 0) //special behavior for particles with gravity
|
||||
{
|
||||
if (this.touching & Collision.FLOOR)
|
||||
{
|
||||
this.drag.x = this.friction;
|
||||
|
||||
if (!(this.wasTouching & Collision.FLOOR))
|
||||
{
|
||||
if (this.velocity.y < -this.elasticity * 10)
|
||||
{
|
||||
if (this.angularVelocity != 0)
|
||||
{
|
||||
this.angularVelocity *= -this.elasticity;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.velocity.y = 0;
|
||||
this.angularVelocity = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.drag.x = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered whenever this object is launched by a <code>Emitter</code>.
|
||||
* You can override this to add custom behavior like a sound or AI or something.
|
||||
*/
|
||||
public onEmit() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
276
Phaser/gameobjects/Sprite.ts
Normal file
276
Phaser/gameobjects/Sprite.ts
Normal file
|
@ -0,0 +1,276 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="GameObject.ts" />
|
||||
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Sprite extends GameObject {
|
||||
|
||||
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null) {
|
||||
|
||||
super(game, x, y);
|
||||
|
||||
this._texture = null;
|
||||
|
||||
this.animations = new Animations(this._game, this);
|
||||
|
||||
if (key !== null)
|
||||
{
|
||||
this.loadGraphic(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bounds.width = 16;
|
||||
this.bounds.height = 16;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private _texture;
|
||||
private _canvas: HTMLCanvasElement;
|
||||
private _context: CanvasRenderingContext2D;
|
||||
private _dynamicTexture: bool = false;
|
||||
|
||||
public animations: Animations;
|
||||
|
||||
// local rendering related temp vars to help avoid gc spikes
|
||||
private _sx: number = 0;
|
||||
private _sy: number = 0;
|
||||
private _sw: number = 0;
|
||||
private _sh: number = 0;
|
||||
private _dx: number = 0;
|
||||
private _dy: number = 0;
|
||||
private _dw: number = 0;
|
||||
private _dh: number = 0;
|
||||
|
||||
public loadGraphic(key: string): Sprite {
|
||||
|
||||
if (this._game.cache.getImage(key) !== null)
|
||||
{
|
||||
if (this._game.cache.isSpriteSheet(key) == false)
|
||||
{
|
||||
this._texture = this._game.cache.getImage(key);
|
||||
this.bounds.width = this._texture.width;
|
||||
this.bounds.height = this._texture.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._texture = this._game.cache.getImage(key);
|
||||
this.animations.loadFrameData(this._game.cache.getFrameData(key));
|
||||
}
|
||||
|
||||
this._dynamicTexture = false;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public loadDynamicTexture(texture: DynamicTexture): Sprite {
|
||||
|
||||
this._texture = texture;
|
||||
|
||||
this.bounds.width = this._texture.width;
|
||||
this.bounds.height = this._texture.height;
|
||||
|
||||
this._dynamicTexture = true;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public makeGraphic(width: number, height: number, color: number = 0xffffffff): Sprite {
|
||||
|
||||
this._texture = null;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
this._dynamicTexture = false;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public inCamera(camera: Rectangle): bool {
|
||||
|
||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
||||
{
|
||||
this._dx = this.bounds.x - (camera.x * this.scrollFactor.x);
|
||||
this._dy = this.bounds.y - (camera.y * this.scrollFactor.x);
|
||||
this._dw = this.bounds.width * this.scale.x;
|
||||
this._dh = this.bounds.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.overlap(this.bounds);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public postUpdate() {
|
||||
|
||||
this.animations.update();
|
||||
|
||||
super.postUpdate();
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {
|
||||
|
||||
// Render checks
|
||||
if (this.visible === false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.inCamera(camera.worldView) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Alpha
|
||||
if (this.alpha !== 1)
|
||||
{
|
||||
var globalAlpha = this._game.stage.context.globalAlpha;
|
||||
this._game.stage.context.globalAlpha = this.alpha;
|
||||
}
|
||||
|
||||
//if (this.flip === true)
|
||||
//{
|
||||
// this.context.save();
|
||||
// this.context.translate(game.canvas.width, 0);
|
||||
// this.context.scale(-1, 1);
|
||||
//}
|
||||
|
||||
this._sx = 0;
|
||||
this._sy = 0;
|
||||
this._sw = this.bounds.width;
|
||||
this._sh = this.bounds.height;
|
||||
this._dx = cameraOffsetX + (this.bounds.x - camera.worldView.x);
|
||||
this._dy = cameraOffsetY + (this.bounds.y - camera.worldView.y);
|
||||
this._dw = this.bounds.width * this.scale.x;
|
||||
this._dh = this.bounds.height * this.scale.y;
|
||||
|
||||
if (this._dynamicTexture == false && this.animations.currentFrame !== null)
|
||||
{
|
||||
this._sx = this.animations.currentFrame.x;
|
||||
this._sy = this.animations.currentFrame.y;
|
||||
|
||||
if (this.animations.currentFrame.trimmed)
|
||||
{
|
||||
this._dx += this.animations.currentFrame.spriteSourceSizeX;
|
||||
this._dy += this.animations.currentFrame.spriteSourceSizeY;
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
if (this.angle !== 0)
|
||||
{
|
||||
this._game.stage.context.save();
|
||||
this._game.stage.context.translate(this._dx + (this._dw / 2) - this.origin.x, this._dy + (this._dh / 2) - this.origin.y);
|
||||
this._game.stage.context.rotate(this.angle * (Math.PI / 180));
|
||||
this._dx = -(this._dw / 2);
|
||||
this._dy = -(this._dh / 2);
|
||||
}
|
||||
|
||||
this._sx = Math.round(this._sx);
|
||||
this._sy = Math.round(this._sy);
|
||||
this._sw = Math.round(this._sw);
|
||||
this._sh = Math.round(this._sh);
|
||||
this._dx = Math.round(this._dx);
|
||||
this._dy = Math.round(this._dy);
|
||||
this._dw = Math.round(this._dw);
|
||||
this._dh = Math.round(this._dh);
|
||||
|
||||
// Debug test
|
||||
//this._game.stage.context.fillStyle = 'rgba(255,0,0,0.3)';
|
||||
//this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||
|
||||
if (this._texture != null)
|
||||
{
|
||||
if (this._dynamicTexture)
|
||||
{
|
||||
this._game.stage.context.drawImage(
|
||||
this._texture.canvas, // Source Image
|
||||
this._sx, // Source X (location within the source image)
|
||||
this._sy, // Source Y
|
||||
this._sw, // Source Width
|
||||
this._sh, // Source Height
|
||||
this._dx, // Destination X (where on the canvas it'll be drawn)
|
||||
this._dy, // Destination Y
|
||||
this._dw, // Destination Width (always same as Source Width unless scaled)
|
||||
this._dh // Destination Height (always same as Source Height unless scaled)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._game.stage.context.drawImage(
|
||||
this._texture, // Source Image
|
||||
this._sx, // Source X (location within the source image)
|
||||
this._sy, // Source Y
|
||||
this._sw, // Source Width
|
||||
this._sh, // Source Height
|
||||
this._dx, // Destination X (where on the canvas it'll be drawn)
|
||||
this._dy, // Destination Y
|
||||
this._dw, // Destination Width (always same as Source Width unless scaled)
|
||||
this._dh // Destination Height (always same as Source Height unless scaled)
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this._game.stage.context.fillStyle = 'rgb(255,255,255)';
|
||||
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||
}
|
||||
|
||||
//if (this.flip === true || this.rotation !== 0)
|
||||
if (this.rotation !== 0)
|
||||
{
|
||||
this._game.stage.context.translate(0, 0);
|
||||
this._game.stage.context.restore();
|
||||
}
|
||||
|
||||
if (globalAlpha > -1)
|
||||
{
|
||||
this._game.stage.context.globalAlpha = globalAlpha;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
this._game.stage.context.fillStyle = color;
|
||||
this._game.stage.context.fillText('Sprite: ' + this.name + ' (' + this.bounds.width + ' x ' + this.bounds.height + ')', x, y);
|
||||
this._game.stage.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' rotation: ' + this.angle.toFixed(1), x, y + 14);
|
||||
this._game.stage.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._game.stage.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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
268
Phaser/gameobjects/Tilemap.ts
Normal file
268
Phaser/gameobjects/Tilemap.ts
Normal file
|
@ -0,0 +1,268 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="GameObject.ts" />
|
||||
/// <reference path="../system/Tile.ts" />
|
||||
/// <reference path="../system/TilemapBuffer.ts" />
|
||||
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Tilemap extends GameObject {
|
||||
|
||||
constructor(game: Game, key: string, mapData: string, format: number, tileWidth?: number = 0, tileHeight?: number = 0) {
|
||||
|
||||
super(game);
|
||||
|
||||
this._texture = this._game.cache.getImage(key);
|
||||
this._tilemapBuffers = [];
|
||||
|
||||
this.isGroup = false;
|
||||
|
||||
this.tileWidth = tileWidth;
|
||||
this.tileHeight = tileHeight;
|
||||
this.boundsInTiles = new Rectangle();
|
||||
this.mapFormat = format;
|
||||
|
||||
switch (format)
|
||||
{
|
||||
case Tilemap.FORMAT_CSV:
|
||||
this.parseCSV(game.cache.getText(mapData));
|
||||
break;
|
||||
|
||||
case Tilemap.FORMAT_TILED_JSON:
|
||||
this.parseTiledJSON(game.cache.getText(mapData));
|
||||
break;
|
||||
}
|
||||
|
||||
this.parseTileOffsets();
|
||||
this.createTilemapBuffers();
|
||||
|
||||
}
|
||||
|
||||
private _texture;
|
||||
private _tileOffsets;
|
||||
private _tilemapBuffers: TilemapBuffer[];
|
||||
private _dx: number = 0;
|
||||
private _dy: number = 0;
|
||||
|
||||
public static FORMAT_CSV: number = 0;
|
||||
public static FORMAT_TILED_JSON: number = 1;
|
||||
|
||||
public mapData;
|
||||
public mapFormat: number;
|
||||
public boundsInTiles: Rectangle;
|
||||
|
||||
public tileWidth: number;
|
||||
public tileHeight: number;
|
||||
|
||||
public widthInTiles: number = 0;
|
||||
public heightInTiles: number = 0;
|
||||
|
||||
public widthInPixels: number = 0;
|
||||
public heightInPixels: number = 0;
|
||||
|
||||
// How many extra tiles to draw around the edge of the screen (for fast scrolling games, or to optimise mobile performance try increasing this)
|
||||
// The number is the amount of extra tiles PER SIDE, so a value of 10 would be (10 tiles + screen size + 10 tiles)
|
||||
public tileBoundary: number = 10;
|
||||
|
||||
private parseCSV(data: string) {
|
||||
|
||||
//console.log('parseMapData');
|
||||
|
||||
this.mapData = [];
|
||||
|
||||
// Trim any rogue whitespace from the data
|
||||
data = data.trim();
|
||||
|
||||
var rows = data.split("\n");
|
||||
//console.log('rows', rows);
|
||||
|
||||
for (var i = 0; i < rows.length; i++)
|
||||
{
|
||||
var column = rows[i].split(",");
|
||||
//console.log('column', column);
|
||||
var output = [];
|
||||
|
||||
if (column.length > 0)
|
||||
{
|
||||
// Set the width based on the first row
|
||||
if (this.widthInTiles == 0)
|
||||
{
|
||||
// Maybe -1?
|
||||
this.widthInTiles = column.length;
|
||||
}
|
||||
|
||||
// We have a new row of tiles
|
||||
this.heightInTiles++;
|
||||
|
||||
// Parse it
|
||||
for (var c = 0; c < column.length; c++)
|
||||
{
|
||||
output[c] = parseInt(column[c]);
|
||||
}
|
||||
|
||||
this.mapData.push(output);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//console.log('final map array');
|
||||
//console.log(this.mapData);
|
||||
|
||||
if (this.widthInTiles > 0)
|
||||
{
|
||||
this.widthInPixels = this.tileWidth * this.widthInTiles;
|
||||
}
|
||||
|
||||
if (this.heightInTiles > 0)
|
||||
{
|
||||
this.heightInPixels = this.tileHeight * this.heightInTiles;
|
||||
}
|
||||
|
||||
this.boundsInTiles.setTo(0, 0, this.widthInTiles, this.heightInTiles);
|
||||
|
||||
}
|
||||
|
||||
private parseTiledJSON(data: string) {
|
||||
|
||||
//console.log('parseTiledJSON');
|
||||
|
||||
this.mapData = [];
|
||||
|
||||
// Trim any rogue whitespace from the data
|
||||
data = data.trim();
|
||||
|
||||
// We ought to change this soon, so we have layer support, but for now let's just get it working
|
||||
var json = JSON.parse(data);
|
||||
|
||||
// Right now we assume no errors at all with the parsing (safe I know)
|
||||
this.tileWidth = json.tilewidth;
|
||||
this.tileHeight = json.tileheight;
|
||||
|
||||
// Parse the first layer only
|
||||
this.widthInTiles = json.layers[0].width;
|
||||
this.heightInTiles = json.layers[0].height;
|
||||
this.widthInPixels = this.widthInTiles * this.tileWidth;
|
||||
this.heightInPixels = this.heightInTiles * this.tileHeight;
|
||||
this.boundsInTiles.setTo(0, 0, this.widthInTiles, this.heightInTiles);
|
||||
|
||||
//console.log('width in tiles', this.widthInTiles);
|
||||
//console.log('height in tiles', this.heightInTiles);
|
||||
//console.log('width in px', this.widthInPixels);
|
||||
//console.log('height in px', this.heightInPixels);
|
||||
|
||||
// Now let's get the data
|
||||
|
||||
var c = 0;
|
||||
var row;
|
||||
|
||||
for (var i = 0; i < json.layers[0].data.length; i++)
|
||||
{
|
||||
if (c == 0)
|
||||
{
|
||||
row = [];
|
||||
}
|
||||
|
||||
row.push(json.layers[0].data[i]);
|
||||
|
||||
c++;
|
||||
|
||||
if (c == this.widthInTiles)
|
||||
{
|
||||
this.mapData.push(row);
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//console.log('mapData');
|
||||
//console.log(this.mapData);
|
||||
|
||||
}
|
||||
|
||||
public getMapSegment(area: Rectangle) {
|
||||
}
|
||||
|
||||
private createTilemapBuffers() {
|
||||
|
||||
var cams = this._game.world.getAllCameras();
|
||||
|
||||
for (var i = 0; i < cams.length; i++)
|
||||
{
|
||||
this._tilemapBuffers[cams[i].ID] = new TilemapBuffer(this._game, cams[i], this, this._texture, this._tileOffsets);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private parseTileOffsets() {
|
||||
|
||||
this._tileOffsets = [];
|
||||
|
||||
var i = 0;
|
||||
|
||||
if (this.mapFormat == Tilemap.FORMAT_TILED_JSON)
|
||||
{
|
||||
// For some reason Tiled counts from 1 not 0
|
||||
this._tileOffsets[0] = null;
|
||||
i = 1;
|
||||
}
|
||||
|
||||
for (var ty = 0; ty < this._texture.height; ty += this.tileHeight)
|
||||
{
|
||||
for (var tx = 0; tx < this._texture.width; tx += this.tileWidth)
|
||||
{
|
||||
this._tileOffsets[i] = { x: tx, y: ty };
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
// Use a Signal?
|
||||
public addTilemapBuffers(camera:Camera) {
|
||||
|
||||
console.log('added new camera to tilemap');
|
||||
this._tilemapBuffers[camera.ID] = new TilemapBuffer(this._game, camera, this, this._texture, this._tileOffsets);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
public update() {
|
||||
|
||||
// Check if any of the cameras have scrolled far enough for us to need to refresh a TilemapBuffer
|
||||
this._tilemapBuffers[0].update();
|
||||
|
||||
}
|
||||
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
this._tilemapBuffers[0].renderDebugInfo(x, y, color);
|
||||
}
|
||||
|
||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {
|
||||
|
||||
if (this.visible === false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this._dx = cameraOffsetX + (this.bounds.x - camera.worldView.x);
|
||||
this._dy = cameraOffsetY + (this.bounds.y - camera.worldView.y);
|
||||
|
||||
this._dx = Math.round(this._dx);
|
||||
this._dy = Math.round(this._dy);
|
||||
|
||||
if (this._tilemapBuffers[camera.ID])
|
||||
{
|
||||
//this._tilemapBuffers[camera.ID].render(this._dx, this._dy);
|
||||
this._tilemapBuffers[camera.ID].render(cameraOffsetX, cameraOffsetY);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,18 +1,17 @@
|
|||
/// <reference path="Point.ts" />
|
||||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* Geom - Circle
|
||||
* Phaser - Geom - Circle
|
||||
*
|
||||
* @desc A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
|
||||
*
|
||||
* @version 1.2 - 27th February 2013
|
||||
* @version 1.1 - 11th October 2012
|
||||
* @author Richard Davey
|
||||
* @author Ross Kettle
|
||||
*
|
||||
* @todo Intersections
|
||||
*/
|
||||
|
||||
class Circle {
|
||||
module Phaser {
|
||||
|
||||
export class Circle {
|
||||
|
||||
/**
|
||||
* Creates a new Circle object with the center coordinate specified by the x and y parameters and the diameter specified by the diameter parameter. If you call this function without parameters, a circle with x, y, diameter and radius properties set to 0 is created.
|
||||
|
@ -28,18 +27,7 @@ class Circle {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* The diameter of the circle
|
||||
* @property _diameter
|
||||
* @type Number
|
||||
**/
|
||||
private _diameter: number = 0;
|
||||
|
||||
/**
|
||||
* The radius of the circle
|
||||
* @property _radius
|
||||
* @type Number
|
||||
**/
|
||||
private _radius: number = 0;
|
||||
|
||||
/**
|
||||
|
@ -59,18 +47,37 @@ class Circle {
|
|||
/**
|
||||
* The diameter of the circle. The largest distance between any two points on the circle. The same as the radius * 2.
|
||||
* @method diameter
|
||||
* @param {Number} The diameter of the circle.
|
||||
* @return {Number}
|
||||
**/
|
||||
public diameter(value?: number): number {
|
||||
get diameter(): number {
|
||||
|
||||
if (value && value > 0)
|
||||
return this._diameter;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The diameter of the circle. The largest distance between any two points on the circle. The same as the radius * 2.
|
||||
* @method diameter
|
||||
* @param {Number} The diameter of the circle.
|
||||
**/
|
||||
set diameter(value: number) {
|
||||
|
||||
if (value > 0)
|
||||
{
|
||||
this._diameter = value;
|
||||
this._radius = value * 0.5;
|
||||
}
|
||||
|
||||
return this._diameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* The radius of the circle. The length of a line extending from the center of the circle to any point on the circle itself. The same as half the diameter.
|
||||
* @method radius
|
||||
* @return {Number}
|
||||
**/
|
||||
get radius(): number {
|
||||
|
||||
return this._radius;
|
||||
|
||||
}
|
||||
|
||||
|
@ -79,16 +86,14 @@ class Circle {
|
|||
* @method radius
|
||||
* @param {Number} The radius of the circle.
|
||||
**/
|
||||
public radius(value?: number) {
|
||||
set radius(value: number) {
|
||||
|
||||
if (value && value > 0)
|
||||
if (value > 0)
|
||||
{
|
||||
this._radius = value;
|
||||
this._diameter = value * 2;
|
||||
}
|
||||
|
||||
return this._radius;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,14 +107,25 @@ class Circle {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* The sum of the y and radius properties. Changing the bottom property of a Circle object has no effect on the x and y properties, but does change the diameter.
|
||||
* @method bottom
|
||||
* @return {Number}
|
||||
**/
|
||||
get bottom(): number {
|
||||
|
||||
return this.y + this._radius;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The sum of the y and radius properties. Changing the bottom property of a Circle object has no effect on the x and y properties, but does change the diameter.
|
||||
* @method bottom
|
||||
* @param {Number} The value to adjust the height of the circle by.
|
||||
**/
|
||||
public bottom(value?: number) {
|
||||
set bottom(value: number) {
|
||||
|
||||
if (value && !isNaN(value))
|
||||
if (!isNaN(value))
|
||||
{
|
||||
if (value < this.y)
|
||||
{
|
||||
|
@ -119,11 +135,20 @@ class Circle {
|
|||
else
|
||||
{
|
||||
|
||||
this.radius(value - this.y);
|
||||
this.radius = value - this.y;
|
||||
}
|
||||
}
|
||||
|
||||
return this.y + this._radius;
|
||||
}
|
||||
|
||||
/**
|
||||
* The x coordinate of the leftmost point of the circle. Changing the left property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
|
||||
* @method left
|
||||
* @return {Number} The x coordinate of the leftmost point of the circle.
|
||||
**/
|
||||
get left(): number {
|
||||
|
||||
return this.x - this._radius;
|
||||
|
||||
}
|
||||
|
||||
|
@ -132,13 +157,13 @@ class Circle {
|
|||
* @method left
|
||||
* @param {Number} The value to adjust the position of the leftmost point of the circle by.
|
||||
**/
|
||||
public left(value?: number) {
|
||||
set left(value: number) {
|
||||
|
||||
if (value && !isNaN(value))
|
||||
if (!isNaN(value))
|
||||
{
|
||||
if (value < this.x)
|
||||
{
|
||||
this.radius(this.x - value);
|
||||
this.radius = this.x - value;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -147,7 +172,16 @@ class Circle {
|
|||
}
|
||||
}
|
||||
|
||||
return this.x - this._radius;
|
||||
}
|
||||
|
||||
/**
|
||||
* The x coordinate of the rightmost point of the circle. Changing the right property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
|
||||
* @method right
|
||||
* @return {Number}
|
||||
**/
|
||||
get right(): number {
|
||||
|
||||
return this.x + this._radius;
|
||||
|
||||
}
|
||||
|
||||
|
@ -156,13 +190,13 @@ class Circle {
|
|||
* @method right
|
||||
* @param {Number} The amount to adjust the diameter of the circle by.
|
||||
**/
|
||||
public right(value?: number) {
|
||||
set right(value: number) {
|
||||
|
||||
if (value && !isNaN(value))
|
||||
if (!isNaN(value))
|
||||
{
|
||||
if (value > this.x)
|
||||
{
|
||||
this.radius(value - this.x);
|
||||
this.radius = value - this.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -171,7 +205,16 @@ class Circle {
|
|||
}
|
||||
}
|
||||
|
||||
return this.x + this._radius;
|
||||
}
|
||||
|
||||
/**
|
||||
* The sum of the y minus the radius property. Changing the top property of a Circle object has no effect on the x and y properties, but does change the diameter.
|
||||
* @method bottom
|
||||
* @return {Number}
|
||||
**/
|
||||
get top(): number {
|
||||
|
||||
return this.y - this._radius;
|
||||
|
||||
}
|
||||
|
||||
|
@ -180,9 +223,9 @@ class Circle {
|
|||
* @method bottom
|
||||
* @param {Number} The amount to adjust the height of the circle by.
|
||||
**/
|
||||
public top(value?: number) {
|
||||
set top(value: number) {
|
||||
|
||||
if (value && !isNaN(value))
|
||||
if (!isNaN(value))
|
||||
{
|
||||
if (value > this.y)
|
||||
{
|
||||
|
@ -191,12 +234,10 @@ class Circle {
|
|||
}
|
||||
else
|
||||
{
|
||||
this.radius(this.y - value);
|
||||
this.radius = this.y - value;
|
||||
}
|
||||
}
|
||||
|
||||
return this.y - this._radius;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -204,7 +245,7 @@ class Circle {
|
|||
* @method area
|
||||
* @return {Number} This area of this circle.
|
||||
**/
|
||||
public area(): number {
|
||||
get area(): number {
|
||||
|
||||
if (this._radius > 0)
|
||||
{
|
||||
|
@ -222,7 +263,7 @@ class Circle {
|
|||
* @method isEmpty
|
||||
* @return {Boolean} A value of true if the Circle objects diameter is less than or equal to 0; otherwise false.
|
||||
**/
|
||||
public isEmpty(): bool {
|
||||
get isEmpty(): bool {
|
||||
|
||||
if (this._diameter < 1)
|
||||
{
|
||||
|
@ -235,24 +276,22 @@ class Circle {
|
|||
|
||||
/**
|
||||
* Whether the circle intersects with a line. Checks against infinite line defined by the two points on the line, not the line segment.
|
||||
* If you need details about the intersection then use Kiwi.Geom.Intersect.lineToCircle instead.
|
||||
* If you need details about the intersection then use Collision.lineToCircle instead.
|
||||
* @method intersectCircleLine
|
||||
* @param {Object} the line object to check.
|
||||
* @return {Boolean}
|
||||
**/
|
||||
/*
|
||||
public intersectCircleLine(line: Line): bool {
|
||||
|
||||
return Intersect.lineToCircle(line, this).result;
|
||||
return Collision.lineToCircle(line, this).result;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a new Circle object with the same values for the x, y, width, and height properties as the original Circle object.
|
||||
* @method clone
|
||||
* @param {Circle} output Optional Circle object. If given the values will be set into the object, otherwise a brand new Circle object will be created and returned.
|
||||
* @return {Kiwi.Geom.Circle}
|
||||
* @return {Phaser.Circle}
|
||||
**/
|
||||
public clone(output?: Circle = new Circle): Circle {
|
||||
|
||||
|
@ -262,49 +301,43 @@ class Circle {
|
|||
|
||||
/**
|
||||
* Return true if the given x/y coordinates are within this Circle object.
|
||||
* If you need details about the intersection then use Kiwi.Geom.Intersect.circleContainsPoint instead.
|
||||
* If you need details about the intersection then use Phaser.Intersect.circleContainsPoint instead.
|
||||
* @method contains
|
||||
* @param {Number} The X value of the coordinate to test.
|
||||
* @param {Number} The Y value of the coordinate to test.
|
||||
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
|
||||
**/
|
||||
/*
|
||||
public contains(x: number, y: number): bool {
|
||||
|
||||
return Intersect.circleContainsPoint(this, <Point> { x: x, y: y }).result;
|
||||
return Collision.circleContainsPoint(this, <Point> { x: x, y: y }).result;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return true if the coordinates of the given Point object are within this Circle object.
|
||||
* If you need details about the intersection then use Kiwi.Geom.Intersect.circleContainsPoint instead.
|
||||
* If you need details about the intersection then use Phaser.Intersect.circleContainsPoint instead.
|
||||
* @method containsPoint
|
||||
* @param {Kiwi.Geom.Point} The Point object to test.
|
||||
* @param {Phaser.Point} The Point object to test.
|
||||
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
|
||||
**/
|
||||
/*
|
||||
public containsPoint(point:Point): bool {
|
||||
|
||||
return Intersect.circleContainsPoint(this, point).result;
|
||||
return Collision.circleContainsPoint(this, point).result;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return true if the given Circle is contained entirely within this Circle object.
|
||||
* If you need details about the intersection then use Kiwi.Geom.Intersect.circleToCircle instead.
|
||||
* If you need details about the intersection then use Phaser.Intersect.circleToCircle instead.
|
||||
* @method containsCircle
|
||||
* @param {Kiwi.Geom.Circle} The Circle object to test.
|
||||
* @param {Phaser.Circle} The Circle object to test.
|
||||
* @return {Boolean} True if the coordinates are within this circle, otherwise false.
|
||||
**/
|
||||
/*
|
||||
public containsCircle(circle:Circle): bool {
|
||||
|
||||
return Intersect.circleToCircle(this, circle).result;
|
||||
return Collision.circleToCircle(this, circle).result;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Copies all of circle data from the source Circle object into the calling Circle object.
|
||||
|
@ -314,7 +347,7 @@ class Circle {
|
|||
**/
|
||||
public copyFrom(source: Circle): Circle {
|
||||
|
||||
return this.setTo(source.x, source.y, source.diameter());
|
||||
return this.setTo(source.x, source.y, source.diameter);
|
||||
|
||||
}
|
||||
|
||||
|
@ -361,13 +394,12 @@ class Circle {
|
|||
**/
|
||||
public equals(toCompare: Circle): bool {
|
||||
|
||||
if (this.x === toCompare.x && this.y === toCompare.y && this.diameter() === toCompare.diameter())
|
||||
if (this.x === toCompare.x && this.y === toCompare.y && this.diameter === toCompare.diameter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -378,8 +410,7 @@ class Circle {
|
|||
**/
|
||||
public intersects(toIntersect: Circle): bool {
|
||||
|
||||
if (this.distanceTo(toIntersect, false) < (this._radius + toIntersect._radius))
|
||||
{
|
||||
if (this.distanceTo(toIntersect, false) < (this._radius + toIntersect._radius)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -392,15 +423,14 @@ class Circle {
|
|||
* @method circumferencePoint
|
||||
* @param {Number} The angle in radians (unless asDegrees is true) to return the point from.
|
||||
* @param {Boolean} Is the given angle in radians (false) or degrees (true)?
|
||||
* @param {Kiwi.Geom.Point} An optional Point object to put the result in to. If none specified a new Point object will be created.
|
||||
* @return {Kiwi.Geom.Point} The Point object holding the result.
|
||||
* @param {Phaser.Point} An optional Point object to put the result in to. If none specified a new Point object will be created.
|
||||
* @return {Phaser.Point} The Point object holding the result.
|
||||
**/
|
||||
public circumferencePoint(angle: number, asDegrees: bool = false, output?: Point = new Point): Point {
|
||||
|
||||
if (asDegrees === true)
|
||||
{
|
||||
//angle = angle * (Math.PI / 180); // Degrees to Radians
|
||||
angle = angle * (180 / Math.PI); // Radians to Degrees
|
||||
angle = angle * GameMath.DEG_TO_RAD;
|
||||
}
|
||||
|
||||
output.x = this.x + this._radius * Math.cos(angle);
|
||||
|
@ -467,7 +497,9 @@ class Circle {
|
|||
**/
|
||||
public toString(): string {
|
||||
|
||||
return "[{Circle (x=" + this.x + " y=" + this.y + " diameter=" + this.diameter() + " radius=" + this.radius() + ")}]";
|
||||
return "[{Circle (x=" + this.x + " y=" + this.y + " diameter=" + this.diameter + " radius=" + this.radius + ")}]";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
99
Phaser/geom/IntersectResult.ts
Normal file
99
Phaser/geom/IntersectResult.ts
Normal file
|
@ -0,0 +1,99 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Geom - IntersectResult
|
||||
*
|
||||
* @desc A light-weight result object to hold the results of an intersection
|
||||
*
|
||||
* @version 1.0 - 15th October 2012
|
||||
* @author Richard Davey
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class IntersectResult {
|
||||
|
||||
/**
|
||||
* Did they intersect or not?
|
||||
* @property result
|
||||
* @type Boolean
|
||||
*/
|
||||
result: bool = false;
|
||||
|
||||
/**
|
||||
* @property x
|
||||
* @type Number
|
||||
*/
|
||||
x: number;
|
||||
|
||||
/**
|
||||
* @property y
|
||||
* @type Number
|
||||
*/
|
||||
y: number;
|
||||
|
||||
/**
|
||||
* @property x1
|
||||
* @type Number
|
||||
*/
|
||||
x1: number;
|
||||
|
||||
/**
|
||||
* @property y1
|
||||
* @type Number
|
||||
*/
|
||||
y1: number;
|
||||
|
||||
/**
|
||||
* @property x2
|
||||
* @type Number
|
||||
*/
|
||||
x2: number;
|
||||
|
||||
/**
|
||||
* @property y2
|
||||
* @type Number
|
||||
*/
|
||||
y2: number;
|
||||
|
||||
/**
|
||||
* @property width
|
||||
* @type Number
|
||||
*/
|
||||
width: number;
|
||||
|
||||
/**
|
||||
* @property height
|
||||
* @type Number
|
||||
*/
|
||||
height: number;
|
||||
|
||||
/**
|
||||
*
|
||||
* @method setTo
|
||||
* @param {Number} x1
|
||||
* @param {Number} y1
|
||||
* @param {Number} [x2]
|
||||
* @param {Number} [y2]
|
||||
* @param {Number} [width]
|
||||
* @param {Number} [height]
|
||||
*/
|
||||
setTo(x1: number, y1: number, x2?: number = 0, y2?: number = 0, width?: number = 0, height?: number = 0) {
|
||||
|
||||
this.x = x1;
|
||||
this.y = y1;
|
||||
|
||||
this.x1 = x1;
|
||||
this.y1 = y1;
|
||||
|
||||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
309
Phaser/geom/Line.ts
Normal file
309
Phaser/geom/Line.ts
Normal file
|
@ -0,0 +1,309 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Geom - Line
|
||||
*
|
||||
* @desc A Line object is an infinte line through space. The two sets of x/y coordinates define the Line Segment.
|
||||
*
|
||||
* @version 1.0 - 11th October 2012
|
||||
* @author Ross Kettle
|
||||
* @author Richard Davey
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Line {
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
* @param {Number} x1
|
||||
* @param {Number} y1
|
||||
* @param {Number} x2
|
||||
* @param {Number} y2
|
||||
* @return {Phaser.Line} This Object
|
||||
*/
|
||||
constructor(x1: number = 0, y1: number = 0, x2: number = 0, y2: number = 0) {
|
||||
|
||||
this.setTo(x1, y1, x2, y2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @property x1
|
||||
* @type Number
|
||||
*/
|
||||
public x1: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property y1
|
||||
* @type Number
|
||||
*/
|
||||
public y1: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property x2
|
||||
* @type Number
|
||||
*/
|
||||
public x2: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property y2
|
||||
* @type Number
|
||||
*/
|
||||
public y2: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @method clone
|
||||
* @param {Phaser.Line} [output]
|
||||
* @return {Phaser.Line}
|
||||
*/
|
||||
public clone(output?: Line = new Line): Line {
|
||||
|
||||
return output.setTo(this.x1, this.y1, this.x2, this.y2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method copyFrom
|
||||
* @param {Phaser.Line} source
|
||||
* @return {Phaser.Line}
|
||||
*/
|
||||
public copyFrom(source: Line): Line {
|
||||
|
||||
return this.setTo(source.x1, source.y1, source.x2, source.y2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method copyTo
|
||||
* @param {Phaser.Line} target
|
||||
* @return {Phaser.Line}
|
||||
*/
|
||||
public copyTo(target: Line): Line {
|
||||
|
||||
return target.copyFrom(this);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method setTo
|
||||
* @param {Number} x1
|
||||
* @param {Number} y1
|
||||
* @param {Number} x2
|
||||
* @param {Number} y2
|
||||
* @return {Phaser.Line}
|
||||
*/
|
||||
public setTo(x1: number = 0, y1: number = 0, x2: number = 0, y2: number = 0): Line {
|
||||
|
||||
this.x1 = x1;
|
||||
this.y1 = y1;
|
||||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public get width(): number {
|
||||
|
||||
return Math.max(this.x1, this.x2) - Math.min(this.x1, this.x2);
|
||||
|
||||
}
|
||||
|
||||
public get height(): number {
|
||||
|
||||
return Math.max(this.y1, this.y2) - Math.min(this.y1, this.y2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method length
|
||||
* @return {Number}
|
||||
*/
|
||||
public get length(): number {
|
||||
|
||||
return Math.sqrt((this.x2 - this.x1) * (this.x2 - this.x1) + (this.y2 - this.y1) * (this.y2 - this.y1));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method getY
|
||||
* @param {Number} x
|
||||
* @return {Number}
|
||||
*/
|
||||
public getY(x: number): number {
|
||||
|
||||
return this.slope * x + this.yIntercept;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method angle
|
||||
* @return {Number}
|
||||
*/
|
||||
public get angle(): number {
|
||||
|
||||
return Math.atan2(this.x2 - this.x1, this.y2 - this.y1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method slope
|
||||
* @return {Number}
|
||||
*/
|
||||
public get slope(): number {
|
||||
|
||||
return (this.y2 - this.y1) / (this.x2 - this.x1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method perpSlope
|
||||
* @return {Number}
|
||||
*/
|
||||
public get perpSlope(): number {
|
||||
|
||||
return -((this.x2 - this.x1) / (this.y2 - this.y1));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method yIntercept
|
||||
* @return {Number}
|
||||
*/
|
||||
public get yIntercept(): number {
|
||||
|
||||
return (this.y1 - this.slope * this.x1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method isPointOnLine
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
* @return {Boolean}
|
||||
*/
|
||||
public isPointOnLine(x: number, y: number): bool {
|
||||
|
||||
if ((x - this.x1) * (this.y2 - this.y1) === (this.x2 - this.x1) * (y - this.y1))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method isPointOnLineSegment
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
* @return {Boolean}
|
||||
*/
|
||||
public isPointOnLineSegment(x: number, y: number): bool {
|
||||
|
||||
var xMin = Math.min(this.x1, this.x2);
|
||||
var xMax = Math.max(this.x1, this.x2);
|
||||
var yMin = Math.min(this.y1, this.y2);
|
||||
var yMax = Math.max(this.y1, this.y2);
|
||||
|
||||
if (this.isPointOnLine(x, y) && (x >= xMin && x <= xMax) && (y >= yMin && y <= yMax))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method intersectLineLine
|
||||
* @param {Any} line
|
||||
* @return {Any}
|
||||
*/
|
||||
public intersectLineLine(line): any {
|
||||
//return Phaser.intersectLineLine(this,line);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method perp
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
* @param {Phaser.Line} [output]
|
||||
* @return {Phaser.Line}
|
||||
*/
|
||||
public perp(x: number, y: number, output?: Line): Line {
|
||||
|
||||
if (this.y1 === this.y2)
|
||||
{
|
||||
if (output)
|
||||
{
|
||||
output.setTo(x, y, x, this.y1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Line(x, y, x, this.y1);
|
||||
}
|
||||
}
|
||||
|
||||
var yInt: number = (y - this.perpSlope * x);
|
||||
|
||||
var pt: any = this.intersectLineLine({ x1: x, y1: y, x2: 0, y2: yInt });
|
||||
|
||||
if (output)
|
||||
{
|
||||
output.setTo(x, y, pt.x, pt.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Line(x, y, pt.x, pt.y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
intersectLineCircle (circle:Circle)
|
||||
{
|
||||
var perp = this.perp()
|
||||
return Phaser.intersectLineCircle(this,circle);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @method toString
|
||||
* @return {String}
|
||||
*/
|
||||
public toString(): string {
|
||||
|
||||
return "[{Line (x1=" + this.x1 + " y1=" + this.y1 + " x2=" + this.x2 + " y2=" + this.y2 + ")}]";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* Point
|
||||
*
|
||||
|
@ -8,7 +10,13 @@
|
|||
* @todo polar, interpolate
|
||||
*/
|
||||
|
||||
class Point {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Point {
|
||||
|
||||
/**
|
||||
* Creates a new point. If you pass no parameters to this method, a point is created at (0,0).
|
||||
|
@ -336,4 +344,6 @@ class Point {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/// <reference path="Point.ts" />
|
||||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* Rectangle
|
||||
|
@ -9,7 +9,13 @@
|
|||
* @author Richard Davey
|
||||
*/
|
||||
|
||||
class Rectangle {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Rectangle {
|
||||
|
||||
/**
|
||||
* Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a rectangle with x, y, width, and height properties set to 0 is created.
|
||||
|
@ -601,4 +607,6 @@ class Rectangle {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
8975
Phaser/phaser.js
8975
Phaser/phaser.js
File diff suppressed because it is too large
Load diff
|
@ -1,9 +1,13 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../GameMath.ts" />
|
||||
/// <reference path="../geom/Rectangle.ts" />
|
||||
/// <reference path="../geom/Point.ts" />
|
||||
/// <reference path="../gameobjects/Sprite.ts" />
|
||||
|
||||
class Camera {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Camera {
|
||||
|
||||
/**
|
||||
* Instantiates a new camera at the specified location, with the specified size and zoom level.
|
||||
|
@ -579,7 +583,7 @@ class Camera {
|
|||
return this._bgColor;
|
||||
}
|
||||
|
||||
public setTexture(key:string, repeat?: string = 'repeat') {
|
||||
public setTexture(key: string, repeat?: string = 'repeat') {
|
||||
|
||||
this._bgTexture = this._game.stage.context.createPattern(this._game.cache.getImage(key), repeat);
|
||||
this._bgTextureRepeat = repeat;
|
||||
|
@ -675,4 +679,6 @@ class Camera {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,13 @@
|
|||
* @author Modernizr team
|
||||
*/
|
||||
|
||||
class Device {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Device {
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -559,4 +565,6 @@ class Device {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,18 @@
|
|||
/// <reference path="../Basic.ts" />
|
||||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* A miniature linked list class.
|
||||
* Useful for optimizing time-critical or highly repetitive tasks!
|
||||
* See <code>QuadTree</code> for how to use it, IF YOU DARE.
|
||||
*/
|
||||
class LinkedList {
|
||||
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class LinkedList {
|
||||
|
||||
/**
|
||||
* Creates a new link, and sets <code>object</code> and <code>next</code> to <code>null</code>.
|
||||
|
@ -42,4 +49,6 @@ class LinkedList {
|
|||
this.next = null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
/// <reference path="../geom/Rectangle.ts" />
|
||||
/// <reference path="../Basic.ts" />
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="LinkedList.ts" />
|
||||
|
||||
/**
|
||||
|
@ -9,7 +8,14 @@
|
|||
* When you do an overlap check, you can compare the A list to itself,
|
||||
* or the A list against the B list. Handy for different things!
|
||||
*/
|
||||
class QuadTree extends Rectangle {
|
||||
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class QuadTree extends Rectangle {
|
||||
|
||||
/**
|
||||
* Instantiate a new Quad Tree node.
|
||||
|
@ -765,4 +771,6 @@ class QuadTree extends Rectangle {
|
|||
return overlapProcessed;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* Repeatable Random Data Generator
|
||||
*
|
||||
|
@ -10,12 +12,18 @@
|
|||
* @author Richard Davey, TypeScript conversion and additional methods
|
||||
*/
|
||||
|
||||
class RandomDataGenerator {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class RandomDataGenerator {
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Array} seeds
|
||||
* @return {Kiwi.Utils.RandomDataGenerator}
|
||||
* @return {Phaser.RandomDataGenerator}
|
||||
*/
|
||||
constructor(seeds?: string[] = []) {
|
||||
|
||||
|
@ -263,7 +271,7 @@ class RandomDataGenerator {
|
|||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
*/
|
||||
public timestamp(min?: number = 946684800000, max?: number = 1577862000000):number {
|
||||
public timestamp(min?: number = 946684800000, max?: number = 1577862000000): number {
|
||||
|
||||
return this.realInRange(min, max);
|
||||
|
||||
|
@ -273,10 +281,12 @@ class RandomDataGenerator {
|
|||
* Returns a random angle between -180 and 180
|
||||
* @method angle
|
||||
*/
|
||||
public get angle():number {
|
||||
public get angle(): number {
|
||||
|
||||
return this.integerInRange(-180, 180);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* RequestAnimationFrame
|
||||
*
|
||||
|
@ -7,7 +9,13 @@
|
|||
* @author Richard Davey
|
||||
*/
|
||||
|
||||
class RequestAnimationFrame {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class RequestAnimationFrame {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -202,4 +210,6 @@ class RequestAnimationFrame {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -9,7 +9,13 @@
|
|||
* https://raw.github.com/zynga/viewporter/master/MIT-LICENSE.txt
|
||||
*/
|
||||
|
||||
class StageScaleMode {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class StageScaleMode {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
|
@ -27,13 +33,13 @@ class StageScaleMode {
|
|||
private _check;
|
||||
|
||||
// Specifies that the game be visible in the specified area without trying to preserve the original aspect ratio.
|
||||
public static EXACT_FIT:number = 0;
|
||||
public static EXACT_FIT: number = 0;
|
||||
|
||||
// Specifies that the size of the game be fixed, so that it remains unchanged even if the size of the window changes.
|
||||
public static NO_SCALE:number = 1;
|
||||
public static NO_SCALE: number = 1;
|
||||
|
||||
// Specifies that the entire game be visible in the specified area without distortion while maintaining the original aspect ratio.
|
||||
public static SHOW_ALL:number = 2;
|
||||
public static SHOW_ALL: number = 2;
|
||||
|
||||
public width: number = 0;
|
||||
public height: number = 0;
|
||||
|
@ -163,4 +169,6 @@ class StageScaleMode {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
/// <reference path="../GameObject.ts" />
|
||||
/// <reference path="../Tilemap.ts" />
|
||||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* A simple helper object for <code>Tilemap</code> that helps expand collision opportunities and control.
|
||||
|
@ -9,7 +8,14 @@
|
|||
* @author Adam Atomic
|
||||
* @author Richard Davey
|
||||
*/
|
||||
class Tile extends GameObject {
|
||||
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Tile extends GameObject {
|
||||
|
||||
/**
|
||||
* Instantiate this new tile object. This is usually called from <code>FlxTilemap.loadMap()</code>.
|
||||
|
@ -84,4 +90,6 @@ class Tile extends GameObject {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +1,16 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../GameObject.ts" />
|
||||
/// <reference path="../Tilemap.ts" />
|
||||
/// <reference path="../geom/Rectangle.ts" />
|
||||
/// <reference path="Camera.ts" />
|
||||
|
||||
/**
|
||||
* A Tilemap Buffer
|
||||
*
|
||||
* @author Richard Davey
|
||||
*/
|
||||
class TilemapBuffer {
|
||||
|
||||
constructor(game: Game, camera:Camera, tilemap:Tilemap, texture, tileOffsets) {
|
||||
module Phaser {
|
||||
|
||||
export class TilemapBuffer {
|
||||
|
||||
constructor(game: Game, camera: Camera, tilemap: Tilemap, texture, tileOffsets) {
|
||||
|
||||
//console.log('New TilemapBuffer created for Camera ' + camera.ID);
|
||||
|
||||
|
@ -169,4 +168,6 @@ class TilemapBuffer {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
240
Phaser/system/Tween.ts
Normal file
240
Phaser/system/Tween.ts
Normal file
|
@ -0,0 +1,240 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="easing/Back.ts" />
|
||||
/// <reference path="easing/Bounce.ts" />
|
||||
/// <reference path="easing/Circular.ts" />
|
||||
/// <reference path="easing/Cubic.ts" />
|
||||
/// <reference path="easing/Elastic.ts" />
|
||||
/// <reference path="easing/Exponential.ts" />
|
||||
/// <reference path="easing/Linear.ts" />
|
||||
/// <reference path="easing/Quadratic.ts" />
|
||||
/// <reference path="easing/Quartic.ts" />
|
||||
/// <reference path="easing/Quintic.ts" />
|
||||
/// <reference path="easing/Sinusoidal.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Tween
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js) converted to TypeScript and integrated into Phaser
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Tween {
|
||||
|
||||
constructor(object, game:Phaser.Game) {
|
||||
|
||||
this._object = object;
|
||||
|
||||
this._game = game;
|
||||
this._manager = this._game.tweens;
|
||||
this._interpolationFunction = this._game.math.linearInterpolation;
|
||||
this._easingFunction = Phaser.Easing.Linear.None;
|
||||
|
||||
this.onStart = new Phaser.Signal();
|
||||
this.onUpdate = new Phaser.Signal();
|
||||
this.onComplete = new Phaser.Signal();
|
||||
|
||||
}
|
||||
|
||||
private _game: Phaser.Game;
|
||||
private _manager: Phaser.TweenManager;
|
||||
private _object = null;
|
||||
private _pausedTime: number = 0;
|
||||
|
||||
private _valuesStart = {};
|
||||
private _valuesEnd = {};
|
||||
private _duration = 1000;
|
||||
private _delayTime = 0;
|
||||
private _startTime = null;
|
||||
private _easingFunction;
|
||||
private _interpolationFunction;
|
||||
private _chainedTweens = [];
|
||||
|
||||
public onStart: Phaser.Signal;
|
||||
public onUpdate: Phaser.Signal;
|
||||
public onComplete: Phaser.Signal;
|
||||
|
||||
public to(properties, duration?: number = 1000, ease?: any = null, autoStart?: bool = false) {
|
||||
|
||||
this._duration = duration;
|
||||
|
||||
// If properties isn't an object this will fail, sanity check it here somehow?
|
||||
this._valuesEnd = properties;
|
||||
|
||||
if (ease !== null)
|
||||
{
|
||||
this._easingFunction = ease;
|
||||
}
|
||||
|
||||
if (autoStart === true)
|
||||
{
|
||||
return this.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public start() {
|
||||
|
||||
if (this._game === null || this._object === null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this._manager.add(this);
|
||||
|
||||
this.onStart.dispatch(this._object);
|
||||
|
||||
this._startTime = this._game.time.now + this._delayTime;
|
||||
|
||||
for (var property in this._valuesEnd)
|
||||
{
|
||||
// This prevents the interpolation of null values or of non-existing properties
|
||||
if (this._object[property] === null || !(property in this._object))
|
||||
{
|
||||
throw Error('Phaser.Tween interpolation of null value of non-existing property');
|
||||
continue;
|
||||
}
|
||||
|
||||
// check if an Array was provided as property value
|
||||
if (this._valuesEnd[property] instanceof Array)
|
||||
{
|
||||
if (this._valuesEnd[property].length === 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// create a local copy of the Array with the start value at the front
|
||||
this._valuesEnd[property] = [this._object[property]].concat(this._valuesEnd[property]);
|
||||
}
|
||||
|
||||
this._valuesStart[property] = this._object[property];
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public stop() {
|
||||
|
||||
if (this._manager !== null)
|
||||
{
|
||||
this._manager.remove(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public set parent(value:Phaser.Game) {
|
||||
|
||||
this._game = value;
|
||||
this._manager = this._game.tweens;
|
||||
|
||||
}
|
||||
|
||||
public set delay(amount:number) {
|
||||
this._delayTime = amount;
|
||||
}
|
||||
|
||||
public get delay(): number {
|
||||
return this._delayTime;
|
||||
}
|
||||
|
||||
public set easing(easing) {
|
||||
this._easingFunction = easing;
|
||||
}
|
||||
|
||||
public get easing():any {
|
||||
return this._easingFunction;
|
||||
}
|
||||
|
||||
public set interpolation(interpolation) {
|
||||
this._interpolationFunction = interpolation;
|
||||
}
|
||||
|
||||
public get interpolation():any {
|
||||
return this._interpolationFunction;
|
||||
}
|
||||
|
||||
public chain(tween:Phaser.Tween) {
|
||||
|
||||
this._chainedTweens.push(tween);
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public debugValue;
|
||||
|
||||
public update(time) {
|
||||
|
||||
if (this._game.paused == true)
|
||||
{
|
||||
if (this._pausedTime == 0)
|
||||
{
|
||||
this._pausedTime = time;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ok we aren't paused, but was there some time gained?
|
||||
if (this._pausedTime > 0)
|
||||
{
|
||||
this._startTime += (time - this._pausedTime);
|
||||
this._pausedTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (time < this._startTime)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var elapsed = (time - this._startTime) / this._duration;
|
||||
elapsed = elapsed > 1 ? 1 : elapsed;
|
||||
|
||||
var value = this._easingFunction(elapsed);
|
||||
|
||||
for (var property in this._valuesStart)
|
||||
{
|
||||
// Add checks for object, array, numeric up front
|
||||
if (this._valuesEnd[property] instanceof Array)
|
||||
{
|
||||
this._object[property] = this._interpolationFunction(this._valuesEnd[property], value);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._object[property] = this._valuesStart[property] + (this._valuesEnd[property] - this._valuesStart[property]) * value;
|
||||
}
|
||||
}
|
||||
|
||||
this.onUpdate.dispatch(this._object, value);
|
||||
|
||||
if (elapsed == 1)
|
||||
{
|
||||
this.onComplete.dispatch(this._object);
|
||||
|
||||
for (var i = 0; i < this._chainedTweens.length; i++)
|
||||
{
|
||||
this._chainedTweens[i].start();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,8 +1,4 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../Sprite.ts" />
|
||||
/// <reference path="AnimationLoader.ts" />
|
||||
/// <reference path="Frame.ts" />
|
||||
/// <reference path="FrameData.ts" />
|
||||
|
||||
/**
|
||||
* Animation
|
||||
|
@ -13,9 +9,15 @@
|
|||
* @author Richard Davey
|
||||
*/
|
||||
|
||||
class Animation {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
constructor(game: Game, parent: Sprite, frameData: FrameData, name, frames, delay, looped) {
|
||||
module Phaser {
|
||||
|
||||
export class Animation {
|
||||
|
||||
constructor(game: Game, parent: Sprite, frameData: FrameData, name: string, frames, delay: number, looped: bool) {
|
||||
|
||||
this._game = game;
|
||||
this._parent = parent;
|
||||
|
@ -107,7 +109,7 @@ class Animation {
|
|||
|
||||
}
|
||||
|
||||
public update():bool {
|
||||
public update(): bool {
|
||||
|
||||
if (this.isPlaying == true && this._game.time.now >= this._timeNextFrame)
|
||||
{
|
||||
|
@ -151,4 +153,6 @@ class Animation {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,12 +1,14 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../Sprite.ts" />
|
||||
/// <reference path="Animation.ts" />
|
||||
/// <reference path="Frame.ts" />
|
||||
/// <reference path="FrameData.ts" />
|
||||
|
||||
class AnimationLoader {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
public static parseSpriteSheet(game: Game, key: string, frameWidth: number, frameHeight: number, frameMax:number): FrameData {
|
||||
module Phaser {
|
||||
|
||||
export class AnimationLoader {
|
||||
|
||||
public static parseSpriteSheet(game: Game, key: string, frameWidth: number, frameHeight: number, frameMax: number): FrameData {
|
||||
|
||||
// How big is our image?
|
||||
|
||||
|
@ -67,7 +69,7 @@ class AnimationLoader {
|
|||
// By this stage frames is a fully parsed array
|
||||
var frames = json;
|
||||
|
||||
var newFrame:Frame;
|
||||
var newFrame: Frame;
|
||||
|
||||
for (var i = 0; i < frames.length; i++)
|
||||
{
|
||||
|
@ -79,5 +81,6 @@ class AnimationLoader {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../Sprite.ts" />
|
||||
/// <reference path="Animation.ts" />
|
||||
/// <reference path="AnimationLoader.ts" />
|
||||
/// <reference path="FrameData.ts" />
|
||||
|
||||
class Frame {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Frame {
|
||||
|
||||
constructor(x: number, y: number, width: number, height: number, name: string) {
|
||||
|
||||
|
@ -65,4 +67,6 @@ class Frame {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../Sprite.ts" />
|
||||
/// <reference path="Animation.ts" />
|
||||
/// <reference path="AnimationLoader.ts" />
|
||||
/// <reference path="Frame.ts" />
|
||||
|
||||
class FrameData {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class FrameData {
|
||||
|
||||
constructor() {
|
||||
|
||||
|
@ -20,7 +22,7 @@ class FrameData {
|
|||
return this._frames.length;
|
||||
}
|
||||
|
||||
public addFrame(frame: Frame):Frame {
|
||||
public addFrame(frame: Frame): Frame {
|
||||
|
||||
frame.index = this._frames.length;
|
||||
|
||||
|
@ -35,7 +37,7 @@ class FrameData {
|
|||
|
||||
}
|
||||
|
||||
public getFrame(index: number):Frame {
|
||||
public getFrame(index: number): Frame {
|
||||
|
||||
if (this._frames[index])
|
||||
{
|
||||
|
@ -46,7 +48,7 @@ class FrameData {
|
|||
|
||||
}
|
||||
|
||||
public getFrameByName(name: string):Frame {
|
||||
public getFrameByName(name: string): Frame {
|
||||
|
||||
if (this._frameNames[name] >= 0)
|
||||
{
|
||||
|
@ -57,7 +59,18 @@ class FrameData {
|
|||
|
||||
}
|
||||
|
||||
public getFrameRange(start: number, end: number, output?:Frame[] = []):Frame[] {
|
||||
public checkFrameName(name: string): bool {
|
||||
|
||||
if (this._frameNames[name] >= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public getFrameRange(start: number, end: number, output?: Frame[] = []): Frame[] {
|
||||
|
||||
for (var i = start; i <= end; i++)
|
||||
{
|
||||
|
@ -68,7 +81,7 @@ class FrameData {
|
|||
|
||||
}
|
||||
|
||||
public getFrameIndexes(output?:number[] = []):number[] {
|
||||
public getFrameIndexes(output?: number[] = []): number[] {
|
||||
|
||||
output.length = 0;
|
||||
|
||||
|
@ -81,7 +94,23 @@ class FrameData {
|
|||
|
||||
}
|
||||
|
||||
public getAllFrames():Frame[] {
|
||||
public getFrameIndexesByName(input: string[]): number[] {
|
||||
|
||||
var output: number[] = [];
|
||||
|
||||
for (var i = 0; i < input.length; i++)
|
||||
{
|
||||
if (this.getFrameByName(input[i]))
|
||||
{
|
||||
output.push(this.getFrameByName(input[i]).index);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
public getAllFrames(): Frame[] {
|
||||
return this._frames;
|
||||
}
|
||||
|
||||
|
@ -98,4 +127,6 @@ class FrameData {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
41
Phaser/system/easing/Back.ts
Normal file
41
Phaser/system/easing/Back.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
module Phaser.Easing {
|
||||
|
||||
export class Back {
|
||||
|
||||
public static In(k) {
|
||||
|
||||
var s = 1.70158;
|
||||
return k * k * ((s + 1) * k - s);
|
||||
|
||||
}
|
||||
|
||||
public static Out(k) {
|
||||
|
||||
var s = 1.70158;
|
||||
return --k * k * ((s + 1) * k + s) + 1;
|
||||
|
||||
}
|
||||
|
||||
public static InOut(k) {
|
||||
|
||||
var s = 1.70158 * 1.525;
|
||||
if ((k *= 2) < 1) return 0.5 * (k * k * ((s + 1) * k - s));
|
||||
return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
53
Phaser/system/easing/Bounce.ts
Normal file
53
Phaser/system/easing/Bounce.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
module Phaser.Easing {
|
||||
|
||||
export class Bounce {
|
||||
|
||||
public static In(k) {
|
||||
|
||||
return 1 - Phaser.Easing.Bounce.Out(1 - k);
|
||||
|
||||
}
|
||||
|
||||
public static Out(k) {
|
||||
|
||||
if (k < (1 / 2.75))
|
||||
{
|
||||
return 7.5625 * k * k;
|
||||
}
|
||||
else if (k < (2 / 2.75))
|
||||
{
|
||||
return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
|
||||
}
|
||||
else if (k < (2.5 / 2.75))
|
||||
{
|
||||
return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static InOut(k) {
|
||||
|
||||
if (k < 0.5) return Phaser.Easing.Bounce.In(k * 2) * 0.5;
|
||||
return Phaser.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
38
Phaser/system/easing/Circular.ts
Normal file
38
Phaser/system/easing/Circular.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
module Phaser.Easing {
|
||||
|
||||
export class Circular {
|
||||
|
||||
public static In(k) {
|
||||
|
||||
return 1 - Math.sqrt(1 - k * k);
|
||||
|
||||
}
|
||||
|
||||
public static Out(k) {
|
||||
|
||||
return Math.sqrt(1 - (--k * k));
|
||||
|
||||
}
|
||||
|
||||
public static InOut(k) {
|
||||
|
||||
if ((k *= 2) < 1) return -0.5 * (Math.sqrt(1 - k * k) - 1);
|
||||
return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
38
Phaser/system/easing/Cubic.ts
Normal file
38
Phaser/system/easing/Cubic.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
module Phaser.Easing {
|
||||
|
||||
export class Cubic {
|
||||
|
||||
public static In(k) {
|
||||
|
||||
return k * k * k;
|
||||
|
||||
}
|
||||
|
||||
public static Out(k) {
|
||||
|
||||
return --k * k * k + 1;
|
||||
|
||||
}
|
||||
|
||||
public static InOut(k) {
|
||||
|
||||
if ((k *= 2) < 1) return 0.5 * k * k * k;
|
||||
return 0.5 * ((k -= 2) * k * k + 2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
53
Phaser/system/easing/Elastic.ts
Normal file
53
Phaser/system/easing/Elastic.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
module Phaser.Easing {
|
||||
|
||||
export class Elastic {
|
||||
|
||||
public static In(k) {
|
||||
|
||||
var s, a = 0.1, p = 0.4;
|
||||
if (k === 0) return 0;
|
||||
if (k === 1) return 1;
|
||||
if (!a || a < 1) { a = 1; s = p / 4; }
|
||||
else s = p * Math.asin(1 / a) / (2 * Math.PI);
|
||||
return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
|
||||
|
||||
}
|
||||
|
||||
public static Out(k) {
|
||||
|
||||
var s, a = 0.1, p = 0.4;
|
||||
if (k === 0) return 0;
|
||||
if (k === 1) return 1;
|
||||
if (!a || a < 1) { a = 1; s = p / 4; }
|
||||
else s = p * Math.asin(1 / a) / (2 * Math.PI);
|
||||
return (a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
|
||||
|
||||
}
|
||||
|
||||
public static InOut(k) {
|
||||
|
||||
var s, a = 0.1, p = 0.4;
|
||||
if (k === 0) return 0;
|
||||
if (k === 1) return 1;
|
||||
if (!a || a < 1) { a = 1; s = p / 4; }
|
||||
else s = p * Math.asin(1 / a) / (2 * Math.PI);
|
||||
if ((k *= 2) < 1) return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
|
||||
return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
40
Phaser/system/easing/Exponential.ts
Normal file
40
Phaser/system/easing/Exponential.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
module Phaser.Easing {
|
||||
|
||||
export class Exponential {
|
||||
|
||||
public static In(k) {
|
||||
|
||||
return k === 0 ? 0 : Math.pow(1024, k - 1);
|
||||
|
||||
}
|
||||
|
||||
public static Out(k) {
|
||||
|
||||
return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
|
||||
|
||||
}
|
||||
|
||||
public static InOut(k) {
|
||||
|
||||
if (k === 0) return 0;
|
||||
if (k === 1) return 1;
|
||||
if ((k *= 2) < 1) return 0.5 * Math.pow(1024, k - 1);
|
||||
return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
25
Phaser/system/easing/Linear.ts
Normal file
25
Phaser/system/easing/Linear.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
module Phaser.Easing {
|
||||
|
||||
export class Linear {
|
||||
|
||||
public static None(k) {
|
||||
|
||||
return k;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
38
Phaser/system/easing/Quadratic.ts
Normal file
38
Phaser/system/easing/Quadratic.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
module Phaser.Easing {
|
||||
|
||||
export class Quadratic {
|
||||
|
||||
public static In(k) {
|
||||
|
||||
return k * k;
|
||||
|
||||
}
|
||||
|
||||
public static Out(k) {
|
||||
|
||||
return k * (2 - k);
|
||||
|
||||
}
|
||||
|
||||
public static InOut(k) {
|
||||
|
||||
if ((k *= 2) < 1) return 0.5 * k * k;
|
||||
return -0.5 * (--k * (k - 2) - 1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
38
Phaser/system/easing/Quartic.ts
Normal file
38
Phaser/system/easing/Quartic.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
module Phaser.Easing {
|
||||
|
||||
export class Quartic {
|
||||
|
||||
public static In(k) {
|
||||
|
||||
return k * k * k * k;
|
||||
|
||||
}
|
||||
|
||||
public static Out(k) {
|
||||
|
||||
return 1 - (--k * k * k * k);
|
||||
|
||||
}
|
||||
|
||||
public static InOut(k) {
|
||||
|
||||
if ((k *= 2) < 1) return 0.5 * k * k * k * k;
|
||||
return -0.5 * ((k -= 2) * k * k * k - 2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
38
Phaser/system/easing/Quintic.ts
Normal file
38
Phaser/system/easing/Quintic.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
module Phaser.Easing {
|
||||
|
||||
export class Quintic {
|
||||
|
||||
public static In(k) {
|
||||
|
||||
return k * k * k * k * k;
|
||||
|
||||
}
|
||||
|
||||
public static Out(k) {
|
||||
|
||||
return --k * k * k * k * k + 1;
|
||||
|
||||
}
|
||||
|
||||
public static InOut(k) {
|
||||
|
||||
if ((k *= 2) < 1) return 0.5 * k * k * k * k * k;
|
||||
return 0.5 * ((k -= 2) * k * k * k * k + 2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
37
Phaser/system/easing/Sinusoidal.ts
Normal file
37
Phaser/system/easing/Sinusoidal.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
module Phaser.Easing {
|
||||
|
||||
export class Sinusoidal {
|
||||
|
||||
public static In(k) {
|
||||
|
||||
return 1 - Math.cos(k * Math.PI / 2);
|
||||
|
||||
}
|
||||
|
||||
public static Out(k) {
|
||||
|
||||
return Math.sin(k * Math.PI / 2);
|
||||
|
||||
}
|
||||
|
||||
public static InOut(k) {
|
||||
|
||||
return 0.5 * (1 - Math.cos(Math.PI * k));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../geom/Point.ts" />
|
||||
/// <reference path="../../geom/Circle.ts" />
|
||||
|
||||
/**
|
||||
* Input - Finger
|
||||
|
@ -13,12 +11,18 @@
|
|||
* @todo Lots
|
||||
*/
|
||||
|
||||
class Finger {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Finger {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Kiwi.Game} game.
|
||||
* @return {Kiwi.Input.Finger} This object.
|
||||
* @param {Phaser.Game} game.
|
||||
* @return {Phaser.Finger} This object.
|
||||
*/
|
||||
constructor(game: Game) {
|
||||
|
||||
|
@ -30,7 +34,7 @@ class Finger {
|
|||
/**
|
||||
*
|
||||
* @property _game
|
||||
* @type Kiwi.Game
|
||||
* @type Phaser.Game
|
||||
* @private
|
||||
**/
|
||||
private _game: Game;
|
||||
|
@ -319,5 +323,6 @@ class Finger {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,12 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="Mouse.ts" />
|
||||
/// <reference path="Keyboard.ts" />
|
||||
/// <reference path="Touch.ts" />
|
||||
|
||||
class Input {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Input {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
|
@ -73,4 +76,6 @@ class Input {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,12 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="Input.ts" />
|
||||
|
||||
class Keyboard {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Keyboard {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
|
@ -11,8 +16,8 @@ class Keyboard {
|
|||
}
|
||||
|
||||
private _game: Game;
|
||||
|
||||
private _keys = {};
|
||||
private _capture = {};
|
||||
|
||||
public start() {
|
||||
|
||||
|
@ -21,9 +26,26 @@ class Keyboard {
|
|||
|
||||
}
|
||||
|
||||
public addKeyCapture(keycode: number) {
|
||||
this._capture[keycode] = true;
|
||||
}
|
||||
|
||||
public removeKeyCapture(keycode: number) {
|
||||
delete this._capture[keycode];
|
||||
}
|
||||
|
||||
public clearCaptures() {
|
||||
|
||||
this._capture = {};
|
||||
|
||||
}
|
||||
|
||||
public onKeyDown(event: KeyboardEvent) {
|
||||
|
||||
//event.preventDefault();
|
||||
if (this._capture[event.keyCode])
|
||||
{
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if (!this._keys[event.keyCode])
|
||||
{
|
||||
|
@ -39,7 +61,10 @@ class Keyboard {
|
|||
|
||||
public onKeyUp(event: KeyboardEvent) {
|
||||
|
||||
//event.preventDefault();
|
||||
if (this._capture[event.keyCode])
|
||||
{
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if (!this._keys[event.keyCode])
|
||||
{
|
||||
|
@ -211,4 +236,6 @@ class Keyboard {
|
|||
public static HELP: number = 47;
|
||||
public static NUM_LOCK: number = 144;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,12 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="Input.ts" />
|
||||
|
||||
class Mouse {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Mouse {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
|
@ -98,4 +103,6 @@ class Mouse {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../Signal.ts" />
|
||||
/// <reference path="Finger.ts" />
|
||||
|
||||
/**
|
||||
|
@ -20,7 +19,13 @@
|
|||
* Input Zones (mouse and touch) - lock entities within them + axis aligned drags
|
||||
*/
|
||||
|
||||
class Touch {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Touch {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -445,5 +450,6 @@ class Touch {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
15
README.md
15
README.md
|
@ -1,9 +1,9 @@
|
|||
Phaser
|
||||
======
|
||||
|
||||
Version 0.8
|
||||
Version 0.9
|
||||
|
||||
15th April 2013
|
||||
18th April 2013
|
||||
|
||||
By Richard Davey, [Photon Storm](http://www.photonstorm.com)
|
||||
|
||||
|
@ -18,6 +18,17 @@ For support post to the Phaser board on the [HTML5 Game Devs forum](http://www.h
|
|||
Change Log
|
||||
----------
|
||||
|
||||
V0.9
|
||||
Large refactoring. Everything now lives inside the Phaser module, so all code and all tests have been updated to reflect this. Makes coding a tiny bit
|
||||
more verbose but stops the framework from globbing up the global namespace. Also should make code-insight work in WebStorm and similar editors.<br />
|
||||
Added the new GeomSprite object. This is a sprite that uses a geometry class for display (Circle, Rectangle, Point, Line). It's extremely flexible!<br />
|
||||
Added Geometry intersection results objects.<br />
|
||||
Added new Collision class and moved some functions there. Contains all the Game Object and Geometry Intersection methods.<br />
|
||||
Can now create a sprite animation based on frame names rather than indexes. Useful when you've an animation inside a texture atlas. Added test to show.<br />
|
||||
Added addKeyCapture(), removeKeyCapture() and clearCaptures() to Input.Keyboard. Calls event.preventDefault() on any keycode set to capture, allowing you to avoid page scrolling when using the cursor keys in a game for example.<br />
|
||||
Added new Motion class which contains lots of handy functions like 'moveTowardsObject', 'velocityFromAngle' and more.<br />
|
||||
Tween Manager added. You can now create tweens via Game.createTween (or for more control game.tweens). All the usual suspects are here: Bounce, Elastic, Quintic, etc and it's hooked into the core game clock, so if your game pauses and resumes your tweens adjust accordingly.
|
||||
|
||||
V0.8
|
||||
|
||||
Added ability to set Sprite frame by name (sprite.frameName), useful when you've loaded a Texture Atlas with filename values set rather than using frame indexes.<br />
|
||||
|
|
|
@ -96,12 +96,48 @@
|
|||
<TypeScriptCompile Include="sprites\dynamic texture 1.ts" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="tweens\bounce.js">
|
||||
<DependentUpon>bounce.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="tweens\elastic.js">
|
||||
<DependentUpon>elastic.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="tweens\elastic.ts" />
|
||||
<TypeScriptCompile Include="tweens\bounce.ts" />
|
||||
<TypeScriptCompile Include="sprites\animate by framename.ts" />
|
||||
<TypeScriptCompile Include="geometry\rectangle.ts" />
|
||||
<TypeScriptCompile Include="geometry\rect vs rect.ts" />
|
||||
<TypeScriptCompile Include="geometry\circle.ts" />
|
||||
<Content Include="geometry\circle.js">
|
||||
<DependentUpon>circle.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="geometry\point.ts" />
|
||||
<TypeScriptCompile Include="geometry\line.ts" />
|
||||
<Content Include="geometry\line.js">
|
||||
<DependentUpon>line.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="geometry\point.js">
|
||||
<DependentUpon>point.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="geometry\rect vs rect.js">
|
||||
<DependentUpon>rect vs rect.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="geometry\rectangle.js">
|
||||
<DependentUpon>rectangle.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="sprites\animate by framename.js">
|
||||
<DependentUpon>animate by framename.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="sprites\dynamic texture 1.js">
|
||||
<DependentUpon>dynamic texture 1.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="sprites\dynamic texture 2.js">
|
||||
<DependentUpon>dynamic texture 2.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="sprites\rotation.js">
|
||||
<DependentUpon>rotation.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="sprites\rotation.ts" />
|
||||
<TypeScriptCompile Include="sprites\dynamic texture 2.ts" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{"frames": [
|
||||
|
||||
{
|
||||
"filename": "running bot.swf/0000",
|
||||
"filename": "run00",
|
||||
"frame": {"x":34,"y":128,"w":56,"h":60},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
|
@ -9,7 +9,7 @@
|
|||
"sourceSize": {"w":56,"h":64}
|
||||
},
|
||||
{
|
||||
"filename": "running bot.swf/0001",
|
||||
"filename": "run01",
|
||||
"frame": {"x":54,"y":0,"w":56,"h":58},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
|
@ -17,7 +17,7 @@
|
|||
"sourceSize": {"w":56,"h":64}
|
||||
},
|
||||
{
|
||||
"filename": "running bot.swf/0002",
|
||||
"filename": "run02",
|
||||
"frame": {"x":54,"y":58,"w":56,"h":58},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
|
@ -25,7 +25,7 @@
|
|||
"sourceSize": {"w":56,"h":64}
|
||||
},
|
||||
{
|
||||
"filename": "running bot.swf/0003",
|
||||
"filename": "run03",
|
||||
"frame": {"x":0,"y":192,"w":34,"h":64},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
|
@ -33,7 +33,7 @@
|
|||
"sourceSize": {"w":56,"h":64}
|
||||
},
|
||||
{
|
||||
"filename": "running bot.swf/0004",
|
||||
"filename": "run04",
|
||||
"frame": {"x":0,"y":64,"w":54,"h":64},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
|
@ -41,7 +41,7 @@
|
|||
"sourceSize": {"w":56,"h":64}
|
||||
},
|
||||
{
|
||||
"filename": "running bot.swf/0005",
|
||||
"filename": "run05",
|
||||
"frame": {"x":196,"y":0,"w":56,"h":58},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
|
@ -49,7 +49,7 @@
|
|||
"sourceSize": {"w":56,"h":64}
|
||||
},
|
||||
{
|
||||
"filename": "running bot.swf/0006",
|
||||
"filename": "run06",
|
||||
"frame": {"x":0,"y":0,"w":54,"h":64},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
|
@ -57,7 +57,7 @@
|
|||
"sourceSize": {"w":56,"h":64}
|
||||
},
|
||||
{
|
||||
"filename": "running bot.swf/0007",
|
||||
"filename": "run07",
|
||||
"frame": {"x":140,"y":0,"w":56,"h":58},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
|
@ -65,7 +65,7 @@
|
|||
"sourceSize": {"w":56,"h":64}
|
||||
},
|
||||
{
|
||||
"filename": "running bot.swf/0008",
|
||||
"filename": "run08",
|
||||
"frame": {"x":34,"y":188,"w":50,"h":60},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
|
@ -73,7 +73,7 @@
|
|||
"sourceSize": {"w":56,"h":64}
|
||||
},
|
||||
{
|
||||
"filename": "running bot.swf/0009",
|
||||
"filename": "run09",
|
||||
"frame": {"x":0,"y":128,"w":34,"h":64},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
|
@ -81,7 +81,7 @@
|
|||
"sourceSize": {"w":56,"h":64}
|
||||
},
|
||||
{
|
||||
"filename": "running bot.swf/0010",
|
||||
"filename": "run10",
|
||||
"frame": {"x":84,"y":188,"w":56,"h":58},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.world.setSize(2240, 2240);
|
||||
myGame.loader.addImageFile('grid', 'assets/tests/debug-grid-1920x1920.png');
|
||||
|
@ -12,10 +12,10 @@
|
|||
function create() {
|
||||
myGame.createSprite(0, 0, 'grid');
|
||||
car = myGame.createSprite(400, 300, 'car');
|
||||
myGame.camera.follow(car, Camera.STYLE_TOPDOWN);
|
||||
myGame.camera.follow(car, Phaser.Camera.STYLE_TOPDOWN);
|
||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
miniCam = myGame.createCamera(0, 0, 300, 300);
|
||||
miniCam.follow(car, Camera.STYLE_TOPDOWN_TIGHT);
|
||||
miniCam.follow(car, Phaser.Camera.STYLE_TOPDOWN_TIGHT);
|
||||
miniCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
miniCam.showBorder = true;
|
||||
miniCam.alpha = 0.7;
|
||||
|
@ -25,13 +25,13 @@
|
|||
car.velocity.y = 0;
|
||||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
car.angularVelocity = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
var motion = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
var motion = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
|
@ -15,8 +15,8 @@
|
|||
|
||||
}
|
||||
|
||||
var car: Sprite;
|
||||
var miniCam: Camera;
|
||||
var car: Phaser.Sprite;
|
||||
var miniCam: Phaser.Camera;
|
||||
|
||||
function create() {
|
||||
|
||||
|
@ -24,11 +24,11 @@
|
|||
|
||||
car = myGame.createSprite(400, 300, 'car');
|
||||
|
||||
myGame.camera.follow(car, Camera.STYLE_TOPDOWN);
|
||||
myGame.camera.follow(car, Phaser.Camera.STYLE_TOPDOWN);
|
||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
|
||||
miniCam = myGame.createCamera(0, 0, 300, 300);
|
||||
miniCam.follow(car, Camera.STYLE_TOPDOWN_TIGHT);
|
||||
miniCam.follow(car, Phaser.Camera.STYLE_TOPDOWN_TIGHT);
|
||||
miniCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
miniCam.showBorder = true;
|
||||
miniCam.alpha = 0.7;
|
||||
|
@ -42,18 +42,18 @@
|
|||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.LEFT))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
car.angularVelocity = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.UP))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
var motion:Point = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
var motion:Phaser.Point = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.world.setSize(1920, 1200);
|
||||
myGame.camera.setBounds(0, 0, 1920, 1200);
|
||||
|
@ -17,14 +16,14 @@
|
|||
}
|
||||
function update() {
|
||||
myGame.camera.renderDebugInfo(32, 32);
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
myGame.camera.scroll.x -= 4;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
myGame.camera.scroll.x += 4;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
myGame.camera.scroll.y -= 4;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.DOWN)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
myGame.camera.scroll.y += 4;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
|
@ -32,20 +31,20 @@
|
|||
|
||||
myGame.camera.renderDebugInfo(32, 32);
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.LEFT))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
myGame.camera.scroll.x -= 4;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
myGame.camera.scroll.x += 4;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.UP))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
myGame.camera.scroll.y -= 4;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.DOWN))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
myGame.camera.scroll.y += 4;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.world.setSize(3000, 3000);
|
||||
myGame.loader.addImageFile('melon', 'assets/sprites/melon.png');
|
||||
|
@ -23,17 +22,17 @@
|
|||
function update() {
|
||||
myGame.camera.renderDebugInfo(16, 16);
|
||||
cam2.renderDebugInfo(200, 16);
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
myGame.camera.x -= 4;
|
||||
cam2.x -= 2;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
myGame.camera.x += 4;
|
||||
cam2.x += 2;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
myGame.camera.y -= 4;
|
||||
cam2.y -= 2;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.DOWN)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
myGame.camera.y += 4;
|
||||
cam2.y += 2;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
|
@ -15,7 +14,7 @@
|
|||
|
||||
}
|
||||
|
||||
var cam2: Camera;
|
||||
var cam2: Phaser.Camera;
|
||||
|
||||
function create() {
|
||||
|
||||
|
@ -40,23 +39,23 @@
|
|||
myGame.camera.renderDebugInfo(16, 16);
|
||||
cam2.renderDebugInfo(200, 16);
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.LEFT))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
myGame.camera.x -= 4;
|
||||
cam2.x -= 2;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
myGame.camera.x += 4;
|
||||
cam2.x += 2;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.UP))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
myGame.camera.y -= 4;
|
||||
cam2.y -= 2;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.DOWN))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
myGame.camera.y += 4;
|
||||
cam2.y += 2;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.world.setSize(3000, 3000);
|
||||
myGame.loader.addImageFile('car', 'assets/sprites/car.png');
|
||||
|
@ -21,14 +20,14 @@
|
|||
}
|
||||
function update() {
|
||||
myGame.camera.renderDebugInfo(600, 32);
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
myGame.camera.rotation -= 2;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
myGame.camera.rotation += 2;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
myGame.camera.scroll.y -= 4;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.DOWN)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
myGame.camera.scroll.y += 4;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
|
@ -39,20 +38,20 @@
|
|||
|
||||
myGame.camera.renderDebugInfo(600, 32);
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.LEFT))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
myGame.camera.rotation -= 2;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
myGame.camera.rotation += 2;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.UP))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
myGame.camera.scroll.y -= 4;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.DOWN))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
myGame.camera.scroll.y += 4;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.world.setSize(2240, 2240);
|
||||
myGame.loader.addImageFile('grid', 'assets/tests/debug-grid-1920x1920.png');
|
||||
|
@ -15,15 +14,15 @@
|
|||
myGame.createSprite(0, 0, 'grid');
|
||||
car = myGame.createSprite(400, 300, 'car');
|
||||
myGame.camera.follow(car);
|
||||
myGame.camera.deadzone = new Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.deadzone = new Phaser.Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
miniCam = myGame.createCamera(600, 32, 200, 200);
|
||||
miniCam.follow(car, Camera.STYLE_LOCKON);
|
||||
miniCam.follow(car, Phaser.Camera.STYLE_LOCKON);
|
||||
miniCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
miniCam.showBorder = true;
|
||||
miniCam.scale.setTo(0.5, 0.5);
|
||||
bigCam = myGame.createCamera(32, 32, 200, 200);
|
||||
bigCam.follow(car, Camera.STYLE_LOCKON);
|
||||
bigCam.follow(car, Phaser.Camera.STYLE_LOCKON);
|
||||
bigCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
bigCam.showBorder = true;
|
||||
bigCam.scale.setTo(2, 2);
|
||||
|
@ -33,13 +32,13 @@
|
|||
car.velocity.y = 0;
|
||||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
car.angularVelocity = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
var motion = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
var motion = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
|
@ -16,9 +15,9 @@
|
|||
|
||||
}
|
||||
|
||||
var car: Sprite;
|
||||
var miniCam: Camera;
|
||||
var bigCam: Camera;
|
||||
var car: Phaser.Sprite;
|
||||
var miniCam: Phaser.Camera;
|
||||
var bigCam: Phaser.Camera;
|
||||
|
||||
function create() {
|
||||
|
||||
|
@ -27,17 +26,17 @@
|
|||
car = myGame.createSprite(400, 300, 'car');
|
||||
|
||||
myGame.camera.follow(car);
|
||||
myGame.camera.deadzone = new Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.deadzone = new Phaser.Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
|
||||
miniCam = myGame.createCamera(600, 32, 200, 200);
|
||||
miniCam.follow(car, Camera.STYLE_LOCKON);
|
||||
miniCam.follow(car, Phaser.Camera.STYLE_LOCKON);
|
||||
miniCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
miniCam.showBorder = true;
|
||||
miniCam.scale.setTo(0.5, 0.5);
|
||||
|
||||
bigCam = myGame.createCamera(32, 32, 200, 200);
|
||||
bigCam.follow(car, Camera.STYLE_LOCKON);
|
||||
bigCam.follow(car, Phaser.Camera.STYLE_LOCKON);
|
||||
bigCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
bigCam.showBorder = true;
|
||||
bigCam.scale.setTo(2, 2);
|
||||
|
@ -51,18 +50,18 @@
|
|||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.LEFT))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
car.angularVelocity = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.UP))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
var motion:Point = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
var motion:Phaser.Point = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.world.setSize(2240, 2240);
|
||||
myGame.loader.addImageFile('grid', 'assets/tests/debug-grid-1920x1920.png');
|
||||
|
@ -15,16 +14,16 @@
|
|||
myGame.createSprite(0, 0, 'grid');
|
||||
car = myGame.createSprite(400, 300, 'car');
|
||||
myGame.camera.follow(car);
|
||||
myGame.camera.deadzone = new Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.deadzone = new Phaser.Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
miniCam = myGame.createCamera(600, 32, 200, 200);
|
||||
miniCam.follow(car, Camera.STYLE_LOCKON);
|
||||
miniCam.follow(car, Phaser.Camera.STYLE_LOCKON);
|
||||
miniCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
miniCam.showBorder = true;
|
||||
miniCam.scale.setTo(0.5, 0.5);
|
||||
miniCam.showShadow = true;
|
||||
bigCam = myGame.createCamera(32, 32, 200, 200);
|
||||
bigCam.follow(car, Camera.STYLE_LOCKON);
|
||||
bigCam.follow(car, Phaser.Camera.STYLE_LOCKON);
|
||||
bigCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
bigCam.showBorder = true;
|
||||
bigCam.scale.setTo(2, 2);
|
||||
|
@ -35,13 +34,13 @@
|
|||
car.velocity.y = 0;
|
||||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
car.angularVelocity = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
var motion = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
var motion = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
|
@ -16,9 +15,9 @@
|
|||
|
||||
}
|
||||
|
||||
var car: Sprite;
|
||||
var miniCam: Camera;
|
||||
var bigCam: Camera;
|
||||
var car: Phaser.Sprite;
|
||||
var miniCam: Phaser.Camera;
|
||||
var bigCam: Phaser.Camera;
|
||||
|
||||
function create() {
|
||||
|
||||
|
@ -27,18 +26,18 @@
|
|||
car = myGame.createSprite(400, 300, 'car');
|
||||
|
||||
myGame.camera.follow(car);
|
||||
myGame.camera.deadzone = new Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.deadzone = new Phaser.Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
|
||||
miniCam = myGame.createCamera(600, 32, 200, 200);
|
||||
miniCam.follow(car, Camera.STYLE_LOCKON);
|
||||
miniCam.follow(car, Phaser.Camera.STYLE_LOCKON);
|
||||
miniCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
miniCam.showBorder = true;
|
||||
miniCam.scale.setTo(0.5, 0.5);
|
||||
miniCam.showShadow = true;
|
||||
|
||||
bigCam = myGame.createCamera(32, 32, 200, 200);
|
||||
bigCam.follow(car, Camera.STYLE_LOCKON);
|
||||
bigCam.follow(car, Phaser.Camera.STYLE_LOCKON);
|
||||
bigCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
bigCam.showBorder = true;
|
||||
bigCam.scale.setTo(2, 2);
|
||||
|
@ -53,18 +52,18 @@
|
|||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.LEFT))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
car.angularVelocity = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.UP))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
var motion:Point = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
var motion:Phaser.Point = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.world.setSize(2240, 2240);
|
||||
myGame.loader.addImageFile('balls', 'assets/sprites/balls.png');
|
||||
|
@ -16,7 +15,7 @@
|
|||
car = myGame.createSprite(400, 300, 'car');
|
||||
myGame.camera.setTexture('balls');
|
||||
myGame.camera.follow(car);
|
||||
myGame.camera.deadzone = new Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.deadzone = new Phaser.Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
//miniCam = myGame.createCamera(600, 32, 200, 200);
|
||||
//miniCam.follow(car, Camera.STYLE_LOCKON);
|
||||
|
@ -34,13 +33,13 @@
|
|||
car.velocity.y = 0;
|
||||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
car.angularVelocity = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
var motion = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
var motion = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
|
@ -16,9 +15,9 @@
|
|||
|
||||
}
|
||||
|
||||
var car: Sprite;
|
||||
var miniCam: Camera;
|
||||
var bigCam: Camera;
|
||||
var car: Phaser.Sprite;
|
||||
var miniCam: Phaser.Camera;
|
||||
var bigCam: Phaser.Camera;
|
||||
|
||||
function create() {
|
||||
|
||||
|
@ -28,7 +27,7 @@
|
|||
|
||||
myGame.camera.setTexture('balls');
|
||||
myGame.camera.follow(car);
|
||||
myGame.camera.deadzone = new Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.deadzone = new Phaser.Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
|
||||
//miniCam = myGame.createCamera(600, 32, 200, 200);
|
||||
|
@ -52,18 +51,18 @@
|
|||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.LEFT))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
car.angularVelocity = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.UP))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
var motion:Point = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
var motion:Phaser.Point = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('background', 'assets/pics/large-color-wheel.png');
|
||||
myGame.loader.addImageFile('car', 'assets/sprites/car90.png');
|
||||
|
@ -18,13 +17,13 @@
|
|||
car.velocity.y = 0;
|
||||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
car.angularVelocity = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
var motion = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
var motion = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
// Fade when the car hits the edges, a different colour per edge
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
|
@ -14,7 +13,7 @@
|
|||
|
||||
}
|
||||
|
||||
var car: Sprite;
|
||||
var car: Phaser.Sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
|
@ -33,18 +32,18 @@
|
|||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.LEFT))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
car.angularVelocity = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.UP))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
var motion:Point = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
var motion:Phaser.Point = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('background', 'assets/pics/large-color-wheel.png');
|
||||
myGame.loader.addImageFile('car', 'assets/sprites/car90.png');
|
||||
|
@ -18,13 +17,13 @@
|
|||
car.velocity.y = 0;
|
||||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
car.angularVelocity = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
var motion = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
var motion = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
// Flash when the car hits the edges, a different colour per edge
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
|
@ -14,7 +13,7 @@
|
|||
|
||||
}
|
||||
|
||||
var car: Sprite;
|
||||
var car: Phaser.Sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
|
@ -33,18 +32,18 @@
|
|||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.LEFT))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
car.angularVelocity = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.UP))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
var motion:Point = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
var motion:Phaser.Point = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.world.setSize(1920, 1920);
|
||||
myGame.loader.addImageFile('grid', 'assets/tests/debug-grid-1920x1920.png');
|
||||
|
@ -24,13 +23,13 @@
|
|||
function update() {
|
||||
myGame.camera.renderDebugInfo(32, 32);
|
||||
melon.renderDebugInfo(200, 32);
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
myGame.camera.focusOnXY(640, 640);
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
myGame.camera.focusOnXY(1234, 800);
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
myGame.camera.focusOnXY(50, 200);
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.DOWN)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
myGame.camera.focusOnXY(1700, 1700);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
|
@ -17,7 +16,7 @@
|
|||
|
||||
}
|
||||
|
||||
var melon: Sprite;
|
||||
var melon: Phaser.Sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
|
@ -41,19 +40,19 @@
|
|||
myGame.camera.renderDebugInfo(32, 32);
|
||||
melon.renderDebugInfo(200, 32);
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.LEFT))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
myGame.camera.focusOnXY(640, 640);
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
myGame.camera.focusOnXY(1234, 800);
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.UP))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
myGame.camera.focusOnXY(50, 200);
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.DOWN))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
myGame.camera.focusOnXY(1700, 1700);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.world.setSize(2240, 2240);
|
||||
myGame.loader.addImageFile('grid', 'assets/tests/debug-grid-1920x1920.png');
|
||||
|
@ -14,7 +13,7 @@
|
|||
car = myGame.createSprite(400, 300, 'car');
|
||||
myGame.camera.follow(car);
|
||||
// Here we'll set our own custom deadzone which is 64px smaller than the stage size on all sides
|
||||
myGame.camera.deadzone = new Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.deadzone = new Phaser.Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
}
|
||||
function update() {
|
||||
|
@ -24,13 +23,13 @@
|
|||
car.velocity.y = 0;
|
||||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
car.angularVelocity = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
var motion = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
var motion = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
|
@ -16,7 +15,7 @@
|
|||
|
||||
}
|
||||
|
||||
var car: Sprite;
|
||||
var car: Phaser.Sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
|
@ -26,7 +25,7 @@
|
|||
|
||||
myGame.camera.follow(car);
|
||||
// Here we'll set our own custom deadzone which is 64px smaller than the stage size on all sides
|
||||
myGame.camera.deadzone = new Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.deadzone = new Phaser.Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
|
||||
}
|
||||
|
@ -41,18 +40,18 @@
|
|||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.LEFT))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
car.angularVelocity = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.UP))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
var motion:Point = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
var motion:Phaser.Point = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.world.setSize(1920, 1920);
|
||||
myGame.loader.addImageFile('grid', 'assets/tests/debug-grid-1920x1920.png');
|
||||
|
@ -21,13 +20,13 @@
|
|||
car.velocity.y = 0;
|
||||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
car.angularVelocity = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
var motion = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
var motion = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
|
@ -38,18 +37,18 @@
|
|||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.LEFT))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
car.angularVelocity = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.UP))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
var motion:Point = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
var motion:Phaser.Point = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.world.setSize(2240, 2240);
|
||||
myGame.loader.addImageFile('grid', 'assets/tests/debug-grid-1920x1920.png');
|
||||
|
@ -12,7 +11,7 @@
|
|||
function create() {
|
||||
myGame.createSprite(0, 0, 'grid');
|
||||
car = myGame.createSprite(400, 300, 'car');
|
||||
myGame.camera.follow(car, Camera.STYLE_TOPDOWN);
|
||||
myGame.camera.follow(car, Phaser.Camera.STYLE_TOPDOWN);
|
||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
}
|
||||
function update() {
|
||||
|
@ -22,13 +21,13 @@
|
|||
car.velocity.y = 0;
|
||||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
car.angularVelocity = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
var motion = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
var motion = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
|
@ -16,7 +15,7 @@
|
|||
|
||||
}
|
||||
|
||||
var car: Sprite;
|
||||
var car: Phaser.Sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
|
@ -24,7 +23,7 @@
|
|||
|
||||
car = myGame.createSprite(400, 300, 'car');
|
||||
|
||||
myGame.camera.follow(car, Camera.STYLE_TOPDOWN);
|
||||
myGame.camera.follow(car, Phaser.Camera.STYLE_TOPDOWN);
|
||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
||||
|
||||
}
|
||||
|
@ -39,18 +38,18 @@
|
|||
car.angularVelocity = 0;
|
||||
car.angularAcceleration = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.LEFT))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
car.angularVelocity = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
car.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.UP))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
var motion:Point = myGame.math.velocityFromAngle(car.angle, 300);
|
||||
var motion:Phaser.Point = myGame.motion.velocityFromAngle(car.angle, 300);
|
||||
|
||||
car.velocity.copyFrom(motion);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.world.setSize(3000, 3000);
|
||||
myGame.loader.addImageFile('car', 'assets/sprites/car.png');
|
||||
|
@ -27,17 +26,17 @@
|
|||
function update() {
|
||||
myGame.camera.renderDebugInfo(16, 16);
|
||||
cam2.renderDebugInfo(200, 16);
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
myGame.camera.scroll.x -= 4;
|
||||
cam2.scroll.x -= 2;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
myGame.camera.scroll.x += 4;
|
||||
cam2.scroll.x += 2;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
myGame.camera.scroll.y -= 4;
|
||||
cam2.scroll.y -= 2;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.DOWN)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
myGame.camera.scroll.y += 4;
|
||||
cam2.scroll.y += 2;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
|
@ -17,7 +16,7 @@
|
|||
|
||||
}
|
||||
|
||||
var cam2: Camera;
|
||||
var cam2: Phaser.Camera;
|
||||
|
||||
function create() {
|
||||
|
||||
|
@ -44,23 +43,23 @@
|
|||
myGame.camera.renderDebugInfo(16, 16);
|
||||
cam2.renderDebugInfo(200, 16);
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.LEFT))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
myGame.camera.scroll.x -= 4;
|
||||
cam2.scroll.x -= 2;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
myGame.camera.scroll.x += 4;
|
||||
cam2.scroll.x += 2;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Keyboard.UP))
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
myGame.camera.scroll.y -= 4;
|
||||
cam2.scroll.y -= 2;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Keyboard.DOWN))
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
myGame.camera.scroll.y += 4;
|
||||
cam2.scroll.y += 2;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/Sprite.ts" />
|
||||
/// <reference path="../../Phaser/Phaser.ts" />
|
||||
(function () {
|
||||
var myGame = new Game(this, 'game', 800, 600, init, create, update);
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.world.setSize(1920, 1200);
|
||||
myGame.loader.addImageFile('backdrop', 'assets/pics/remember-me.jpg');
|
||||
|
@ -24,14 +23,14 @@
|
|||
function update() {
|
||||
myGame.camera.renderDebugInfo(32, 32);
|
||||
melon.renderDebugInfo(200, 32);
|
||||
if(myGame.input.keyboard.isDown(Keyboard.LEFT)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
myGame.camera.scroll.x -= 1;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.RIGHT)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
myGame.camera.scroll.x += 1;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Keyboard.UP)) {
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
myGame.camera.scroll.y -= 1;
|
||||
} else if(myGame.input.keyboard.isDown(Keyboard.DOWN)) {
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
myGame.camera.scroll.y += 1;
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue