update() and draw() are automatically called by FlxState/FlxGroup.
+ */
+ public exists: bool;
+
+ /**
+ * Controls whether update() is automatically called by FlxState/FlxGroup.
+ */
+ public active: bool;
+
+ /**
+ * Controls whether draw() is automatically called by FlxState/FlxGroup.
+ */
+ public visible: bool;
+
+ /**
+ * Useful state for many game objects - "dead" (!alive) vs alive.
+ * kill() and revive() both flip this switch (along with exists, but you can override that).
+ */
+ public alive: bool;
+
+ /**
+ * Setting this to true will prevent the object from appearing
+ * when the visual debug mode in the debugger overlay is toggled on.
+ */
+ public ignoreDrawDebug: bool;
+
+ /**
+ * Override this to null out iables or manually call
+ * destroy() on class members if necessary.
+ * Don't forget to call super.destroy()!
+ */
+ public destroy() { }
+
+ /**
+ * Pre-update is called right before update() on each object in the game loop.
+ */
+ public preUpdate() {
+ }
+
+ /**
+ * Override this to update your class's position and appearance.
+ * This is where most of your game rules and behavioral code will go.
+ */
+ public update() {
+ }
+
+ /**
+ * Post-update is called right after update() on each object in the game loop.
+ */
+ public postUpdate() {
+ }
+
+ public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
+ }
+
+ /**
+ * Handy for "killing" game objects.
+ * Default behavior is to flag them as nonexistent AND dead.
+ * However, if you want the "corpse" to remain in the game,
+ * like to animate an effect or whatever, you should override this,
+ * setting only alive to false, and leaving exists true.
+ */
+ public kill() {
+ this.alive = false;
+ this.exists = false;
+ }
+
+ /**
+ * Handy for bringing game objects "back to life". Just sets alive and exists back to true.
+ * In practice, this is most often called by FlxObject.reset().
+ */
+ public revive() {
+ this.alive = true;
+ this.exists = true;
+ }
+
+ /**
+ * Convert object to readable string name. Useful for debugging, save games, etc.
+ */
+ public toString(): string {
+ return "";
+ }
}
- /**
- * The essential reference to the main game object
- */
- public _game: Game;
-
- /**
- * Allows you to give this object a name. Useful for debugging, but not actually used internally.
- */
- public name: string = '';
-
- /**
- * IDs seem like they could be pretty useful, huh?
- * They're not actually used for anything yet though.
- */
- public ID: number;
-
- /**
- * A boolean to store if this object is a Group or not.
- * Saves us an expensive typeof check inside of core loops.
- */
- public isGroup: bool;
-
- /**
- * Controls whether update() and draw() are automatically called by FlxState/FlxGroup.
- */
- public exists: bool;
-
- /**
- * Controls whether update() is automatically called by FlxState/FlxGroup.
- */
- public active: bool;
-
- /**
- * Controls whether draw() is automatically called by FlxState/FlxGroup.
- */
- public visible: bool;
-
- /**
- * Useful state for many game objects - "dead" (!alive) vs alive.
- * kill() and revive() both flip this switch (along with exists, but you can override that).
- */
- public alive: bool;
-
- /**
- * Setting this to true will prevent the object from appearing
- * when the visual debug mode in the debugger overlay is toggled on.
- */
- public ignoreDrawDebug: bool;
-
- /**
- * Override this to null out iables or manually call
- * destroy() on class members if necessary.
- * Don't forget to call super.destroy()!
- */
- public destroy() { }
-
- /**
- * Pre-update is called right before update() on each object in the game loop.
- */
- public preUpdate() {
- }
-
- /**
- * Override this to update your class's position and appearance.
- * This is where most of your game rules and behavioral code will go.
- */
- public update() {
- }
-
- /**
- * Post-update is called right after update() on each object in the game loop.
- */
- public postUpdate() {
- }
-
- public render(camera:Camera, cameraOffsetX: number, cameraOffsetY: number) {
- }
-
- /**
- * Handy for "killing" game objects.
- * Default behavior is to flag them as nonexistent AND dead.
- * However, if you want the "corpse" to remain in the game,
- * like to animate an effect or whatever, you should override this,
- * setting only alive to false, and leaving exists true.
- */
- public kill() {
- this.alive = false;
- this.exists = false;
- }
-
- /**
- * Handy for bringing game objects "back to life". Just sets alive and exists back to true.
- * In practice, this is most often called by FlxObject.reset().
- */
- public revive() {
- this.alive = true;
- this.exists = true;
- }
-
- /**
- * Convert object to readable string name. Useful for debugging, save games, etc.
- */
- public toString(): string {
- //return FlxU.getClassName(this, true);
- return "";
- }
-
-}
-
+}
\ No newline at end of file
diff --git a/Phaser/Cache.ts b/Phaser/Cache.ts
index b9a328e0..13cbd714 100644
--- a/Phaser/Cache.ts
+++ b/Phaser/Cache.ts
@@ -1,163 +1,171 @@
-/// GameObject 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 Group (or even bundling groups together!).
+ *
+ * NOTE: does NOT take objects' scrollfactor into account, all overlaps are checked in world space.
+ * + * @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 twoGameObject parameters - e.g. myOverlapFunction(Object1:GameObject,Object2:GameObject) - that is called if those two objects overlap.
+ * @param ProcessCallback A function with two GameObject parameters - e.g. myOverlapFunction(Object1:GameObject,Object2:GameObject) - 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 Sprite.
+ * @param Object2 Any other Sprite.
+ *
+ * @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 Sprite.
+ * @param Object2 Any other Sprite.
+ *
+ * @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 Sprite.
+ * @param Object2 Any other Sprite.
+ *
+ * @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);
+ }
+
+
+ }
+
+}
\ No newline at end of file
diff --git a/Phaser/DynamicTexture.ts b/Phaser/DynamicTexture.ts
index 2e000cae..c3cff62d 100644
--- a/Phaser/DynamicTexture.ts
+++ b/Phaser/DynamicTexture.ts
@@ -1,205 +1,212 @@
/// Emitter is a lightweight particle emitter.
- * It can be used for one-time explosions or for
- * continuous fx like rain and fire. Emitter
- * is not optimized or anything; all it does is launch
- * Particle objects out at set intervals
- * by setting their positions and velocities accordingly.
- * It is easy to use and relatively efficient,
- * relying on Group's RECYCLE POWERS.
- *
- * @author Adam Atomic
- * @author Richard Davey
- */
-class Emitter extends Group {
-
- /**
- * Creates a new FlxEmitter 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 acceleration.y 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 Particle.
- */
- 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 FlxObject.
- *
- * @param Object The FlxObject 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);
- }
-}
diff --git a/Phaser/Game.ts b/Phaser/Game.ts
index fb0fceb7..44ee807c 100644
--- a/Phaser/Game.ts
+++ b/Phaser/Game.ts
@@ -1,377 +1,401 @@
+/// - * Returns true or false based on the chance value (default 50%). For example if you wanted a player to have a 30% chance - * of getting a bonus, call chanceRoll(30) - true means the chance passed, false means it failed. - *
- * @param chance The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%) - * @return true if the roll passed, or false - */ - public chanceRoll(chance: number = 50): bool { - - if (chance <= 0) - { - return false; + public fuzzyCeil(val: number, epsilon: number = 0.0001): number { + return Math.ceil(val - epsilon); } - else if (chance >= 100) - { - return true; + + public fuzzyFloor(val: number, epsilon: number = 0.0001): number { + return Math.floor(val + epsilon); } - else - { - if (Math.random() * 100 >= chance) + + public average(...args: any[]): number { + var avg: number = 0; + + for (var i = 0; i < args.length; i++) + { + avg += args[i]; + } + + return avg / args.length; + } + + public slam(value: number, target: number, epsilon: number = 0.0001): number { + return (Math.abs(value - target) < epsilon) ? target : value; + } + + /** + * ratio of value to a range + */ + public percentageMinMax(val: number, max: number, min: number = 0): number { + val -= min; + max -= min; + + if (!max) return 0; + else return val / max; + } + + /** + * a value representing the sign of the value. + * -1 for negative, +1 for positive, 0 if value is 0 + */ + public sign(n: number): number { + if (n) return n / Math.abs(n); + else return 0; + } + + public truncate(n: number): number { + return (n > 0) ? Math.floor(n) : Math.ceil(n); + } + + public shear(n: number): number { + return n % 1; + } + + /** + * wrap a value around a range, similar to modulus with a floating minimum + */ + public wrap(val: number, max: number, min: number = 0): number { + val -= min; + max -= min; + if (max == 0) return min; + val %= max; + val += min; + while (val < min) + val += max; + + return val; + } + + /** + * arithmetic version of wrap... need to decide which is more efficient + */ + public arithWrap(value: number, max: number, min: number = 0): number { + max -= min; + if (max == 0) return min; + return value - max * Math.floor((value - min) / max); + } + + /** + * force a value within the boundaries of two values + * + * if max < min, min is returned + */ + public clamp(input: number, max: number, min: number = 0): number { + return Math.max(min, Math.min(max, input)); + } + + /** + * Snap a value to nearest grid slice, using rounding. + * + * example if you have an interval gap of 5 and a position of 12... you will snap to 10. Where as 14 will snap to 15 + * + * @param input - the value to snap + * @param gap - the interval gap of the grid + * @param start - optional starting offset for gap + */ + public snapTo(input: number, gap: number, start: number = 0): number { + if (gap == 0) return input; + + input -= start; + input = gap * Math.round(input / gap); + return start + input; + } + + /** + * Snap a value to nearest grid slice, using floor. + * + * example if you have an interval gap of 5 and a position of 12... you will snap to 10. As will 14 snap to 10... but 16 will snap to 15 + * + * @param input - the value to snap + * @param gap - the interval gap of the grid + * @param start - optional starting offset for gap + */ + public snapToFloor(input: number, gap: number, start: number = 0): number { + if (gap == 0) return input; + + input -= start; + input = gap * Math.floor(input / gap); + return start + input; + } + + /** + * Snap a value to nearest grid slice, using ceil. + * + * example if you have an interval gap of 5 and a position of 12... you will snap to 15. As will 14 will snap to 15... but 16 will snap to 20 + * + * @param input - the value to snap + * @param gap - the interval gap of the grid + * @param start - optional starting offset for gap + */ + public snapToCeil(input: number, gap: number, start: number = 0): number { + if (gap == 0) return input; + + input -= start; + input = gap * Math.ceil(input / gap); + return start + input; + } + + /** + * Snaps a value to the nearest value in an array. + */ + public snapToInArray(input: number, arr: number[], sort?: bool = true): number { + + if (sort) arr.sort(); + if (input < arr[0]) return arr[0]; + + var i: number = 1; + + while (arr[i] < input) + i++; + + var low: number = arr[i - 1]; + var high: number = (i < arr.length) ? arr[i] : Number.POSITIVE_INFINITY; + + return ((high - input) <= (input - low)) ? high : low; + } + + /** + * roundTo some place comparative to a 'base', default is 10 for decimal place + * + * 'place' is represented by the power applied to 'base' to get that place + * + * @param value - the value to round + * @param place - the place to round to + * @param base - the base to round in... default is 10 for decimal + * + * e.g. + * + * 2000/7 ~= 285.714285714285714285714 ~= (bin)100011101.1011011011011011 + * + * roundTo(2000/7,3) == 0 + * roundTo(2000/7,2) == 300 + * roundTo(2000/7,1) == 290 + * roundTo(2000/7,0) == 286 + * roundTo(2000/7,-1) == 285.7 + * roundTo(2000/7,-2) == 285.71 + * roundTo(2000/7,-3) == 285.714 + * roundTo(2000/7,-4) == 285.7143 + * roundTo(2000/7,-5) == 285.71429 + * + * roundTo(2000/7,3,2) == 288 -- 100100000 + * roundTo(2000/7,2,2) == 284 -- 100011100 + * roundTo(2000/7,1,2) == 286 -- 100011110 + * roundTo(2000/7,0,2) == 286 -- 100011110 + * roundTo(2000/7,-1,2) == 285.5 -- 100011101.1 + * roundTo(2000/7,-2,2) == 285.75 -- 100011101.11 + * roundTo(2000/7,-3,2) == 285.75 -- 100011101.11 + * roundTo(2000/7,-4,2) == 285.6875 -- 100011101.1011 + * roundTo(2000/7,-5,2) == 285.71875 -- 100011101.10111 + * + * note what occurs when we round to the 3rd space (8ths place), 100100000, this is to be assumed + * because we are rounding 100011.1011011011011011 which rounds up. + */ + public roundTo(value: number, place: number = 0, base: number = 10): number { + var p: number = Math.pow(base, -place); + return Math.round(value * p) / p; + } + + public floorTo(value: number, place: number = 0, base: number = 10): number { + var p: number = Math.pow(base, -place); + return Math.floor(value * p) / p; + } + + public ceilTo(value: number, place: number = 0, base: number = 10): number { + var p: number = Math.pow(base, -place); + return Math.ceil(value * p) / p; + } + + /** + * a one dimensional linear interpolation of a value. + */ + public interpolateFloat(a: number, b: number, weight: number): number { + return (b - a) * weight + a; + } + + /** + * convert radians to degrees + */ + public radiansToDegrees(angle: number): number { + return angle * GameMath.RAD_TO_DEG; + } + + /** + * convert degrees to radians + */ + public degreesToRadians(angle: number): number { + return angle * GameMath.DEG_TO_RAD; + } + + /** + * Find the angle of a segment from (x1, y1) -> (x2, y2 ) + */ + public angleBetween(x1: number, y1: number, x2: number, y2: number): number { + return Math.atan2(y2 - y1, x2 - x1); + } + + + /** + * set an angle with in the bounds of -PI to PI + */ + public normalizeAngle(angle: number, radians: bool = true): number { + var rd: number = (radians) ? GameMath.PI : 180; + return this.wrap(angle, rd, -rd); + } + + /** + * closest angle between two angles from a1 to a2 + * absolute value the return for exact angle + */ + public nearestAngleBetween(a1: number, a2: number, radians: bool = true): number { + + var rd: number = (radians) ? GameMath.PI : 180; + + a1 = this.normalizeAngle(a1, radians); + a2 = this.normalizeAngle(a2, radians); + + if (a1 < -rd / 2 && a2 > rd / 2) a1 += rd * 2; + if (a2 < -rd / 2 && a1 > rd / 2) a2 += rd * 2; + + return a2 - a1; + } + + /** + * normalizes independent and then sets dep to the nearest value respective to independent + * + * for instance if dep=-170 and ind=170 then 190 will be returned as an alternative to -170 + */ + public normalizeAngleToAnother(dep: number, ind: number, radians: bool = true): number { + return ind + this.nearestAngleBetween(ind, dep, radians); + } + + /** + * normalize independent and dependent and then set dependent to an angle relative to 'after/clockwise' independent + * + * for instance dep=-170 and ind=170, then 190 will be reutrned as alternative to -170 + */ + public normalizeAngleAfterAnother(dep: number, ind: number, radians: bool = true): number { + + dep = this.normalizeAngle(dep - ind, radians); + return ind + dep; + } + + /** + * normalizes indendent and dependent and then sets dependent to an angle relative to 'before/counterclockwise' independent + * + * for instance dep = 190 and ind = 170, then -170 will be returned as an alternative to 190 + */ + public normalizeAngleBeforeAnother(dep: number, ind: number, radians: bool = true): number { + + dep = this.normalizeAngle(ind - dep, radians); + return ind - dep; + } + + /** + * interpolate across the shortest arc between two angles + */ + public interpolateAngles(a1: number, a2: number, weight: number, radians: bool = true, ease = null): number { + + a1 = this.normalizeAngle(a1, radians); + a2 = this.normalizeAngleToAnother(a2, a1, radians); + + return (typeof ease === 'function') ? ease(weight, a1, a2 - a1, 1) : this.interpolateFloat(a1, a2, weight); + } + + /** + * Compute the logarithm of any value of any base + * + * a logarithm is the exponent that some constant (base) would have to be raised to + * to be equal to value. + * + * i.e. + * 4 ^ x = 16 + * can be rewritten as to solve for x + * logB4(16) = x + * which with this function would be + * LoDMath.logBaseOf(16,4) + * + * which would return 2, because 4^2 = 16 + */ + public logBaseOf(value: number, base: number): number { + return Math.log(value) / Math.log(base); + } + + /** + * Greatest Common Denominator using Euclid's algorithm + */ + public GCD(m: number, n: number): number { + var r: number; + + //make sure positive, GCD is always positive + m = Math.abs(m); + n = Math.abs(n); + + //m must be >= n + if (m < n) + { + r = m; + m = n; + n = r; + } + + //now start loop + while (true) + { + r = m % n; + if (!r) return n; + m = n; + n = r; + } + + return 1; + } + + /** + * Lowest Common Multiple + */ + public LCM(m: number, n: number): number { + return (m * n) / this.GCD(m, n); + } + + /** + * Factorial - N! + * + * simple product series + * + * by definition: + * 0! == 1 + */ + public factorial(value: number): number { + if (value == 0) return 1; + + var res: number = value; + + while (--value) + { + res *= value; + } + + return res; + } + + /** + * gamma function + * + * defined: gamma(N) == (N - 1)! + */ + public gammaFunction(value: number): number { + return this.factorial(value - 1); + } + + /** + * falling factorial + * + * defined: (N)! / (N - x)! + * + * written subscript: (N)x OR (base)exp + */ + public fallingFactorial(base: number, exp: number): number { + return this.factorial(base) / this.factorial(base - exp); + } + + /** + * rising factorial + * + * defined: (N + x - 1)! / (N - 1)! + * + * written superscript N^(x) OR base^(exp) + */ + public risingFactorial(base: number, exp: number): number { + //expanded from gammaFunction for speed + return this.factorial(base + exp - 1) / this.factorial(base - 1); + } + + /** + * binomial coefficient + * + * defined: N! / (k!(N-k)!) + * reduced: N! / (N-k)! == (N)k (fallingfactorial) + * reduced: (N)k / k! + */ + public binCoef(n: number, k: number): number { + return this.fallingFactorial(n, k) / this.factorial(k); + } + + /** + * rising binomial coefficient + * + * as one can notice in the analysis of binCoef(...) that + * binCoef is the (N)k divided by k!. Similarly rising binCoef + * is merely N^(k) / k! + */ + public risingBinCoef(n: number, k: number): number { + return this.risingFactorial(n, k) / this.factorial(k); + } + + /** + * Generate a random boolean result based on the chance value + *+ * Returns true or false based on the chance value (default 50%). For example if you wanted a player to have a 30% chance + * of getting a bonus, call chanceRoll(30) - true means the chance passed, false means it failed. + *
+ * @param chance The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%) + * @return true if the roll passed, or false + */ + public chanceRoll(chance: number = 50): bool { + + if (chance <= 0) + { + return false; + } + else if (chance >= 100) + { + return true; + } + else + { + if (Math.random() * 100 >= chance) + { + return false; + } + else + { + return true; + } + } + + } + + /** + * Adds the given amount to the value, but never lets the value go over the specified maximum + * + * @param value The value to add the amount to + * @param amount The amount to add to the value + * @param max The maximum the value is allowed to be + * @return The new value + */ + public maxAdd(value: number, amount: number, max: number): number { + + value += amount; + + if (value > max) + { + value = max; + } + + return value; + + } + + /** + * Subtracts the given amount from the value, but never lets the value go below the specified minimum + * + * @param value The base value + * @param amount The amount to subtract from the base value + * @param min The minimum the value is allowed to be + * @return The new value + */ + public minSub(value: number, amount: number, min: number): number { + + value -= amount; + + if (value < min) + { + value = min; + } + + return value; + } + + /** + * Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around. + *Values must be positive integers, and are passed through Math.abs
+ * + * @param value The value to add the amount to + * @param amount The amount to add to the value + * @param max The maximum the value is allowed to be + * @return The wrapped value + */ + public wrapValue(value: number, amount: number, max: number): number { + + var diff: number; + + value = Math.abs(value); + amount = Math.abs(amount); + max = Math.abs(max); + + diff = (value + amount) % max; + + return diff; + + } + + /** + * Randomly returns either a 1 or -1 + * + * @return 1 or -1 + */ + public randomSign(): number { + return (Math.random() > 0.5) ? 1 : -1; + } + + /** + * Returns true if the number given is odd. + * + * @param n The number to check + * + * @return True if the given number is odd. False if the given number is even. + */ + public isOdd(n: number): bool { + + if (n & 1) + { + return true; + } + else + { + return false; + } + + } + + /** + * Returns true if the number given is even. + * + * @param n The number to check + * + * @return True if the given number is even. False if the given number is odd. + */ + public isEven(n: number): bool { + + if (n & 1) { return false; } @@ -545,480 +653,330 @@ class GameMath { { return true; } + } - } - - /** - * Adds the given amount to the value, but never lets the value go over the specified maximum - * - * @param value The value to add the amount to - * @param amount The amount to add to the value - * @param max The maximum the value is allowed to be - * @return The new value - */ - public maxAdd(value: number, amount: number, max: number): number { - - value += amount; - - if (value > max) - { - value = max; - } - - return value; - - } - - /** - * Subtracts the given amount from the value, but never lets the value go below the specified minimum - * - * @param value The base value - * @param amount The amount to subtract from the base value - * @param min The minimum the value is allowed to be - * @return The new value - */ - public minSub(value: number, amount: number, min: number): number { - - value -= amount; - - if (value < min) - { - value = min; - } - - return value; - } - - /** - * Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around. - *Values must be positive integers, and are passed through Math.abs
- * - * @param value The value to add the amount to - * @param amount The amount to add to the value - * @param max The maximum the value is allowed to be - * @return The wrapped value - */ - public wrapValue(value: number, amount: number, max: number): number { - - var diff: number; - - value = Math.abs(value); - amount = Math.abs(amount); - max = Math.abs(max); - - diff = (value + amount) % max; - - return diff; - - } - - /** - * Randomly returns either a 1 or -1 - * - * @return 1 or -1 - */ - public randomSign(): number { - return (Math.random() > 0.5) ? 1 : -1; - } - - /** - * Returns true if the number given is odd. - * - * @param n The number to check - * - * @return True if the given number is odd. False if the given number is even. - */ - public isOdd(n: number): bool { - - if (n & 1) - { - return true; - } - else - { - return false; - } - - } - - /** - * Returns true if the number given is even. - * - * @param n The number to check - * - * @return True if the given number is even. False if the given number is odd. - */ - public isEven(n: number): bool { - - if (n & 1) - { - return false; - } - else - { - return true; - } - - } - - /** - * Keeps an angle value between -180 and +180Number between 0 and 1.
+ */
+ public random(): number {
+ return this.globalSeed = this.srand(this.globalSeed);
+ }
+
+ /**
+ * Generates a random number based on the seed provided.
+ *
+ * @param Seed A number between 0 and 1, used to generate a predictable random number (very optional).
+ *
+ * @return A Number between 0 and 1.
+ */
+ public srand(Seed: number): number {
+
+ return ((69621 * (Seed * 0x7FFFFFFF)) % 0x7FFFFFFF) / 0x7FFFFFFF;
+
+ }
+
+ /**
+ * Fetch a random entry from the given array.
+ * Will return null if random selection is missing, or array has no entries.
+ * FlxG.getRandom() is deterministic and safe for use with replays/recordings.
+ * HOWEVER, FlxU.getRandom() is NOT deterministic and unsafe for use with replays/recordings.
+ *
+ * @param Objects An array of objects.
+ * @param StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
+ * @param Length Optional restriction on the number of values you want to randomly select from.
+ *
+ * @return The random object that was selected.
+ */
+ public getRandom(Objects, StartIndex: number = 0, Length: number = 0) {
+
+ if (Objects != null)
+ {
+ var l: number = Length;
+
+ if ((l == 0) || (l > Objects.length - StartIndex))
+ {
+ l = Objects.length - StartIndex;
+ }
+
+ if (l > 0)
+ {
+ return Objects[StartIndex + Math.floor(Math.random() * l)];
+ }
+ }
+
+ return null;
+
+ }
+
+ /**
+ * Round down to the next whole number. E.g. floor(1.7) == 1, and floor(-2.7) == -2.
+ *
+ * @param Value Any number.
+ *
+ * @return The rounded value of that number.
+ */
+ public floor(Value: number): number {
+ var n: number = Value | 0;
+ return (Value > 0) ? (n) : ((n != Value) ? (n - 1) : (n));
+ }
+
+ /**
+ * Round up to the next whole number. E.g. ceil(1.3) == 2, and ceil(-2.3) == -3.
+ *
+ * @param Value Any number.
+ *
+ * @return The rounded value of that number.
+ */
+ public ceil(Value: number): number {
+ var n: number = Value | 0;
+ return (Value > 0) ? ((n != Value) ? (n + 1) : (n)) : (n);
+ }
+
+ /**
+ * Generate a sine and cosine table simultaneously and extremely quickly. Based on research by Franky of scene.at
+ * + * The parameters allow you to specify the length, amplitude and frequency of the wave. Once you have called this function + * you should get the results via getSinTable() and getCosTable(). This generator is fast enough to be used in real-time. + *
+ * @param length The length of the wave + * @param sinAmplitude The amplitude to apply to the sine table (default 1.0) if you need values between say -+ 125 then give 125 as the value + * @param cosAmplitude The amplitude to apply to the cosine table (default 1.0) if you need values between say -+ 125 then give 125 as the value + * @param frequency The frequency of the sine and cosine table data + * @return Returns the sine table + * @see getSinTable + * @see getCosTable + */ + public sinCosGenerator(length: number, sinAmplitude?: number = 1.0, cosAmplitude?: number = 1.0, frequency?: number = 1.0) { + + var sin: number = sinAmplitude; + var cos: number = cosAmplitude; + var frq: number = frequency * Math.PI / length; + + this.cosTable = []; + this.sinTable = []; + + for (var c: number = 0; c < length; c++) + { + cos -= sin * frq; + sin += cos * frq; + + this.cosTable[c] = cos; + this.sinTable[c] = sin; + } + + return this.sinTable; + + } + + /** + * Finds the length of the given vector + * + * @param dx + * @param dy + * + * @return + */ + public vectorLength(dx:number, dy:number):number { - if (Velocity > Max) - { - Velocity = Max; - } - else if (Velocity < -Max) - { - Velocity = -Max; - } + return Math.sqrt(dx * dx + dy * dy); } - - 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). - */ - public globalSeed: number = Math.random(); - - /** - * Generates a random number. Deterministic, meaning safe - * to use if you want to record replays in random environments. - * - * @return ANumber between 0 and 1.
- */
- public random(): number {
- return this.globalSeed = this.srand(this.globalSeed);
- }
-
- /**
- * Generates a random number based on the seed provided.
- *
- * @param Seed A number between 0 and 1, used to generate a predictable random number (very optional).
- *
- * @return A Number between 0 and 1.
- */
- public srand(Seed: number): number {
-
- return ((69621 * (Seed * 0x7FFFFFFF)) % 0x7FFFFFFF) / 0x7FFFFFFF;
-
- }
-
- /**
- * Fetch a random entry from the given array.
- * Will return null if random selection is missing, or array has no entries.
- * FlxG.getRandom() is deterministic and safe for use with replays/recordings.
- * HOWEVER, FlxU.getRandom() is NOT deterministic and unsafe for use with replays/recordings.
- *
- * @param Objects An array of objects.
- * @param StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
- * @param Length Optional restriction on the number of values you want to randomly select from.
- *
- * @return The random object that was selected.
- */
- public getRandom(Objects, StartIndex: number = 0, Length: number = 0) {
-
- if (Objects != null)
+
+ /**
+ * 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
{
- var l: number = Length;
-
- if ((l == 0) || (l > Objects.length - StartIndex))
- {
- l = Objects.length - StartIndex;
- }
-
- if (l > 0)
- {
- return Objects[StartIndex + Math.floor(Math.random() * l)];
- }
+ return ax * bx + ay * by;
}
- return null;
}
- /**
- * Round down to the next whole number. E.g. floor(1.7) == 1, and floor(-2.7) == -2.
- *
- * @param Value Any number.
- *
- * @return The rounded value of that number.
- */
- public floor(Value: number): number {
- var n: number = Value | 0;
- return (Value > 0) ? (n) : ((n != Value) ? (n - 1) : (n));
- }
-
- /**
- * Round up to the next whole number. E.g. ceil(1.3) == 2, and ceil(-2.3) == -3.
- *
- * @param Value Any number.
- *
- * @return The rounded value of that number.
- */
- public ceil(Value: number): number {
- var n: number = Value | 0;
- return (Value > 0) ? ((n != Value) ? (n + 1) : (n)) : (n);
- }
-
- /**
- * Generate a sine and cosine table simultaneously and extremely quickly. Based on research by Franky of scene.at
- * - * The parameters allow you to specify the length, amplitude and frequency of the wave. Once you have called this function - * you should get the results via getSinTable() and getCosTable(). This generator is fast enough to be used in real-time. - *
- * @param length The length of the wave - * @param sinAmplitude The amplitude to apply to the sine table (default 1.0) if you need values between say -+ 125 then give 125 as the value - * @param cosAmplitude The amplitude to apply to the cosine table (default 1.0) if you need values between say -+ 125 then give 125 as the value - * @param frequency The frequency of the sine and cosine table data - * @return Returns the sine table - * @see getSinTable - * @see getCosTable - */ - public sinCosGenerator(length: number, sinAmplitude?: number = 1.0, cosAmplitude?: number = 1.0, frequency?: number = 1.0) { - - var sin: number = sinAmplitude; - var cos: number = cosAmplitude; - var frq: number = frequency * Math.PI / length; - - this.cosTable = []; - this.sinTable = []; - - for (var c: number = 0; c < length; c++) - { - cos -= sin * frq; - sin += cos * frq; - - this.cosTable[c] = cos; - this.sinTable[c] = sin; - } - - return this.sinTable; - - } - - -} - +} \ No newline at end of file diff --git a/Phaser/GameObject.ts b/Phaser/GameObject.ts deleted file mode 100644 index 09a972b9..00000000 --- a/Phaser/GameObject.ts +++ /dev/null @@ -1,499 +0,0 @@ -///GameObject overlaps this GameObject or FlxGroup.
- * If the group has a LOT of things in it, it might be faster to use FlxG.overlaps().
- * 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 = GameObject were located at the given position, would it overlap the GameObject or FlxGroup?
- * 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 GameObject 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 Point object and assigns the post-scrolled X and Y values of this object to it.
- *
- * @return The Point you passed in, or a new Point 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 Point object if you're so inclined. Otherwise a new one is created.
- *
- * @return A Point 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 touching.
- * 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;
- }
-
-
-}
\ No newline at end of file
diff --git a/Phaser/Group.ts b/Phaser/Group.ts
index 7a34a23f..cf42a278 100644
--- a/Phaser/Group.ts
+++ b/Phaser/Group.ts
@@ -1,5 +1,5 @@
/// Basics.
@@ -9,72 +9,104 @@
* @author Adam Atomic
* @author Richard Davey
*/
-class Group extends Basic {
- constructor(game: Game, MaxSize?: number = 0) {
+/**
+* Phaser
+*/
- super(game);
+module Phaser {
- this.isGroup = true;
- this.members = [];
- this.length = 0;
- this._maxSize = MaxSize;
- this._marker = 0;
- this._sortIndex = null;
+ export class Group extends Basic {
- }
+ constructor(game: Game, MaxSize?: number = 0) {
- /**
- * Use with sort() to sort in ascending order.
- */
- public static ASCENDING: number = -1;
+ super(game);
- /**
- * Use with sort() to sort in descending order.
- */
- public static DESCENDING: number = 1;
+ this.isGroup = true;
+ this.members = [];
+ this.length = 0;
+ this._maxSize = MaxSize;
+ this._marker = 0;
+ this._sortIndex = null;
- /**
- * Array of all the Basics that exist in this group.
- */
- public members: Basic[];
+ }
- /**
- * The number of entries in the members array.
- * For performance and safety you should check this variable
- * instead of members.length unless you really know what you're doing!
- */
- public length: number;
+ /**
+ * Use with sort() to sort in ascending order.
+ */
+ public static ASCENDING: number = -1;
- /**
- * Internal tracker for the maximum capacity of the group.
- * Default is 0, or no max capacity.
- */
- private _maxSize: number;
+ /**
+ * Use with sort() to sort in descending order.
+ */
+ public static DESCENDING: number = 1;
- /**
- * Internal helper variable for recycling objects a la FlxEmitter.
- */
- private _marker: number;
+ /**
+ * Array of all the Basics that exist in this group.
+ */
+ public members: Basic[];
- /**
- * Helper for sort.
- */
- private _sortIndex: string;
+ /**
+ * The number of entries in the members array.
+ * For performance and safety you should check this variable
+ * instead of members.length unless you really know what you're doing!
+ */
+ public length: number;
- /**
- * Helper for sort.
- */
- private _sortOrder: number;
+ /**
+ * Internal tracker for the maximum capacity of the group.
+ * Default is 0, or no max capacity.
+ */
+ private _maxSize: number;
- /**
- * Override this function to handle any deleting or "shutdown" type operations you might need,
- * such as removing traditional Flash children like Basic objects.
- */
- public destroy() {
+ /**
+ * Internal helper variable for recycling objects a la FlxEmitter.
+ */
+ private _marker: number;
+
+ /**
+ * Helper for sort.
+ */
+ private _sortIndex: string;
+
+ /**
+ * Helper for sort.
+ */
+ private _sortOrder: number;
+
+ /**
+ * Override this function to handle any deleting or "shutdown" type operations you might need,
+ * such as removing traditional Flash children like Basic objects.
+ */
+ public destroy() {
+
+ if (this.members != null)
+ {
+ var basic: Basic;
+ var i: number = 0;
+
+ while (i < this.length)
+ {
+ basic = this.members[i++];
+
+ if (basic != null)
+ {
+ basic.destroy();
+ }
+ }
+
+ this.members.length = 0;
+ }
+
+ this._sortIndex = null;
+
+ }
+
+ /**
+ * Automatically goes through and calls update on everything you added.
+ */
+ public update() {
- if (this.members != null)
- {
var basic: Basic;
var i: number = 0;
@@ -82,204 +114,207 @@ class Group extends Basic {
{
basic = this.members[i++];
+ if ((basic != null) && basic.exists && basic.active)
+ {
+ basic.preUpdate();
+ basic.update();
+ basic.postUpdate();
+ }
+ }
+ }
+
+ /**
+ * Automatically goes through and calls render on everything you added.
+ */
+ public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
+
+ var basic: Basic;
+ var i: number = 0;
+
+ while (i < this.length)
+ {
+ basic = this.members[i++];
+
+ if ((basic != null) && basic.exists && basic.visible)
+ {
+ basic.render(camera, cameraOffsetX, cameraOffsetY);
+ }
+ }
+ }
+
+ /**
+ * The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow.
+ */
+ public get maxSize(): number {
+ return this._maxSize;
+ }
+
+ /**
+ * @private
+ */
+ public set maxSize(Size: number) {
+
+ this._maxSize = Size;
+
+ if (this._marker >= this._maxSize)
+ {
+ this._marker = 0;
+ }
+
+ if ((this._maxSize == 0) || (this.members == null) || (this._maxSize >= this.members.length))
+ {
+ return;
+ }
+
+ //If the max size has shrunk, we need to get rid of some objects
+ var basic: Basic;
+ var i: number = this._maxSize;
+ var l: number = this.members.length;
+
+ while (i < l)
+ {
+ basic = this.members[i++];
+
if (basic != null)
{
basic.destroy();
}
}
- this.members.length = 0;
+ this.length = this.members.length = this._maxSize;
}
- this._sortIndex = null;
+ /**
+ * Adds a new Basic subclass (Basic, FlxBasic, Enemy, etc) to the group.
+ * Group will try to replace a null member of the array first.
+ * Failing that, Group will add it to the end of the member array,
+ * assuming there is room for it, and doubling the size of the array if necessary.
+ *
+ * WARNING: If the group has a maxSize that has already been met, + * the object will NOT be added to the group!
+ * + * @param Object The object you want to add to the group. + * + * @return The sameBasic object that was passed in.
+ */
+ public add(Object: Basic) {
- }
-
- /**
- * Automatically goes through and calls update on everything you added.
- */
- public update() {
-
- var basic: Basic;
- var i: number = 0;
-
- while (i < this.length)
- {
- basic = this.members[i++];
-
- if ((basic != null) && basic.exists && basic.active)
+ //Don't bother adding an object twice.
+ if (this.members.indexOf(Object) >= 0)
{
- basic.preUpdate();
- basic.update();
- basic.postUpdate();
+ return Object;
}
- }
- }
- /**
- * Automatically goes through and calls render on everything you added.
- */
- public render(camera:Camera, cameraOffsetX: number, cameraOffsetY: number) {
+ //First, look for a null entry where we can add the object.
+ var i: number = 0;
+ var l: number = this.members.length;
- var basic:Basic;
- var i:number = 0;
-
- while (i < this.length)
- {
- basic = this.members[i++];
-
- if ((basic != null) && basic.exists && basic.visible)
+ while (i < l)
{
- basic.render(camera, cameraOffsetX, cameraOffsetY);
- }
- }
- }
-
- /**
- * The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow.
- */
- public get maxSize(): number {
- return this._maxSize;
- }
-
- /**
- * @private
- */
- public set maxSize(Size: number) {
-
- this._maxSize = Size;
-
- if (this._marker >= this._maxSize)
- {
- this._marker = 0;
- }
-
- if ((this._maxSize == 0) || (this.members == null) || (this._maxSize >= this.members.length))
- {
- return;
- }
-
- //If the max size has shrunk, we need to get rid of some objects
- var basic: Basic;
- var i: number = this._maxSize;
- var l: number = this.members.length;
-
- while (i < l)
- {
- basic = this.members[i++];
-
- if (basic != null)
- {
- basic.destroy();
- }
- }
-
- this.length = this.members.length = this._maxSize;
- }
-
- /**
- * Adds a new Basic subclass (Basic, FlxBasic, Enemy, etc) to the group.
- * Group will try to replace a null member of the array first.
- * Failing that, Group will add it to the end of the member array,
- * assuming there is room for it, and doubling the size of the array if necessary.
- *
- * WARNING: If the group has a maxSize that has already been met, - * the object will NOT be added to the group!
- * - * @param Object The object you want to add to the group. - * - * @return The sameBasic object that was passed in.
- */
- public add(Object: Basic) {
-
- //Don't bother adding an object twice.
- if (this.members.indexOf(Object) >= 0)
- {
- return Object;
- }
-
- //First, look for a null entry where we can add the object.
- var i: number = 0;
- var l: number = this.members.length;
-
- while (i < l)
- {
- if (this.members[i] == null)
- {
- this.members[i] = Object;
-
- if (i >= this.length)
+ if (this.members[i] == null)
{
- this.length = i + 1;
+ this.members[i] = Object;
+
+ if (i >= this.length)
+ {
+ this.length = i + 1;
+ }
+
+ return Object;
}
- return Object;
+ i++;
}
- i++;
- }
-
- //Failing that, expand the array (if we can) and add the object.
- if (this._maxSize > 0)
- {
- if (this.members.length >= this._maxSize)
+ //Failing that, expand the array (if we can) and add the object.
+ if (this._maxSize > 0)
{
- return Object;
- }
- else if (this.members.length * 2 <= this._maxSize)
- {
- this.members.length *= 2;
+ if (this.members.length >= this._maxSize)
+ {
+ return Object;
+ }
+ else if (this.members.length * 2 <= this._maxSize)
+ {
+ this.members.length *= 2;
+ }
+ else
+ {
+ this.members.length = this._maxSize;
+ }
}
else
{
- this.members.length = this._maxSize;
+ this.members.length *= 2;
}
- }
- else
- {
- this.members.length *= 2;
+
+ //If we made it this far, then we successfully grew the group,
+ //and we can go ahead and add the object at the first open slot.
+ this.members[i] = Object;
+ this.length = i + 1;
+
+ return Object;
+
}
- //If we made it this far, then we successfully grew the group,
- //and we can go ahead and add the object at the first open slot.
- this.members[i] = Object;
- this.length = i + 1;
+ /**
+ * Recycling is designed to help you reuse game objects without always re-allocating or "newing" them.
+ *
+ * If you specified a maximum size for this group (like in Emitter), + * then recycle will employ what we're calling "rotating" recycling. + * Recycle() will first check to see if the group is at capacity yet. + * If group is not yet at capacity, recycle() returns a new object. + * If the group IS at capacity, then recycle() just returns the next object in line.
+ * + *If you did NOT specify a maximum size for this group, + * then recycle() will employ what we're calling "grow-style" recycling. + * Recycle() will return either the first object with exists == false, + * or, finding none, add a new object to the array, + * doubling the size of the array if necessary.
+ * + *WARNING: If this function needs to create a new object, + * and no object class was provided, it will return null + * instead of a valid object!
+ * + * @param ObjectClass The class type you want to recycle (e.g. FlxBasic, EvilRobot, etc). Do NOT "new" the class in the parameter! + * + * @return A reference to the object that was created. Don't forget to cast it back to the Class you want (e.g. myObject = myGroup.recycle(myObjectClass) as myObjectClass;). + */ + public recycle(ObjectClass = null) { - return Object; + var basic; - } - - /** - * Recycling is designed to help you reuse game objects without always re-allocating or "newing" them. - * - *If you specified a maximum size for this group (like in Emitter), - * then recycle will employ what we're calling "rotating" recycling. - * Recycle() will first check to see if the group is at capacity yet. - * If group is not yet at capacity, recycle() returns a new object. - * If the group IS at capacity, then recycle() just returns the next object in line.
- * - *If you did NOT specify a maximum size for this group, - * then recycle() will employ what we're calling "grow-style" recycling. - * Recycle() will return either the first object with exists == false, - * or, finding none, add a new object to the array, - * doubling the size of the array if necessary.
- * - *WARNING: If this function needs to create a new object, - * and no object class was provided, it will return null - * instead of a valid object!
- * - * @param ObjectClass The class type you want to recycle (e.g. FlxBasic, EvilRobot, etc). Do NOT "new" the class in the parameter! - * - * @return A reference to the object that was created. Don't forget to cast it back to the Class you want (e.g. myObject = myGroup.recycle(myObjectClass) as myObjectClass;). - */ - public recycle(ObjectClass = null) { - - var basic; - - if (this._maxSize > 0) - { - if (this.length < this._maxSize) + if (this._maxSize > 0) { + if (this.length < this._maxSize) + { + if (ObjectClass == null) + { + return null; + } + + return this.add(new ObjectClass()); + } + else + { + basic = this.members[this._marker++]; + + if (this._marker >= this._maxSize) + { + this._marker = 0; + } + + return basic; + } + } + else + { + basic = this.getFirstAvailable(ObjectClass); + + if (basic != null) + { + return basic; + } + if (ObjectClass == null) { return null; @@ -287,455 +322,429 @@ class Group extends Basic { return this.add(new ObjectClass()); } - else - { - basic = this.members[this._marker++]; - - if (this._marker >= this._maxSize) - { - this._marker = 0; - } - - return basic; - } } - else - { - basic = this.getFirstAvailable(ObjectClass); - if (basic != null) - { - return basic; - } + /** + * Removes an object from the group. + * + * @param Object TheBasic you want to remove.
+ * @param Splice Whether the object should be cut from the array entirely or not.
+ *
+ * @return The removed object.
+ */
+ public remove(Object: Basic, Splice: bool = false): Basic {
- if (ObjectClass == null)
+ var index: number = this.members.indexOf(Object);
+
+ if ((index < 0) || (index >= this.members.length))
{
return null;
}
- return this.add(new ObjectClass());
- }
- }
-
- /**
- * Removes an object from the group.
- *
- * @param Object The Basic you want to remove.
- * @param Splice Whether the object should be cut from the array entirely or not.
- *
- * @return The removed object.
- */
- public remove(Object: Basic, Splice: bool = false): Basic {
-
- var index: number = this.members.indexOf(Object);
-
- if ((index < 0) || (index >= this.members.length))
- {
- return null;
- }
-
- if (Splice)
- {
- this.members.splice(index, 1);
- this.length--;
- }
- else
- {
- this.members[index] = null;
- }
-
- return Object;
-
- }
-
- /**
- * Replaces an existing Basic with a new one.
- *
- * @param OldObject The object you want to replace.
- * @param NewObject The new object you want to use instead.
- *
- * @return The new object.
- */
- public replace(OldObject: Basic, NewObject: Basic): Basic {
-
- var index: number = this.members.indexOf(OldObject);
-
- if ((index < 0) || (index >= this.members.length))
- {
- return null;
- }
-
- this.members[index] = NewObject;
-
- return NewObject;
-
- }
-
- /**
- * Call this function to sort the group according to a particular value and order.
- * For example, to sort game objects for Zelda-style overlaps you might call
- * myGroup.sort("y",Group.ASCENDING) at the bottom of your
- * FlxState.update() override. To sort all existing objects after
- * a big explosion or bomb attack, you might call myGroup.sort("exists",Group.DESCENDING).
- *
- * @param Index The string name of the member variable you want to sort on. Default value is "y".
- * @param Order A Group constant that defines the sort order. Possible values are Group.ASCENDING and Group.DESCENDING. Default value is Group.ASCENDING.
- */
- public sort(Index: string = "y", Order: number = Group.ASCENDING) {
-
- this._sortIndex = Index;
- this._sortOrder = Order;
- this.members.sort(this.sortHandler);
-
- }
-
- /**
- * Go through and set the specified variable to the specified value on all members of the group.
- *
- * @param VariableName The string representation of the variable name you want to modify, for example "visible" or "scrollFactor".
- * @param Value The value you want to assign to that variable.
- * @param Recurse Default value is true, meaning if setAll() encounters a member that is a group, it will call setAll() on that group rather than modifying its variable.
- */
- public setAll(VariableName: string, Value: Object, Recurse: bool = true) {
-
- var basic: Basic;
- var i: number = 0;
-
- while (i < length)
- {
- basic = this.members[i++];
-
- if (basic != null)
+ if (Splice)
{
- if (Recurse && (basic.isGroup == true))
- {
- callAll() encounters a member that is a group, it will call callAll() on that group rather than calling the group's function.
- */
- public callAll(FunctionName: string, Recurse: bool = true) {
-
- var basic: Basic;
- var i: number = 0;
-
- while (i < this.length)
- {
- basic = this.members[i++];
-
- if (basic != null)
- {
- if (Recurse && (basic.isGroup == true))
- {
- Basic currently flagged as not existing.
- */
- public getFirstAvailable(ObjectClass = null) {
-
- var basic;
- var i: number = 0;
-
- while (i < this.length)
- {
- basic = this.members[i++];
-
- if ((basic != null) && !basic.exists && ((ObjectClass == null) || (typeof basic === ObjectClass)))
- {
- return basic;
- }
-
- }
-
- return null;
- }
-
- /**
- * Call this function to retrieve the first index set to 'null'.
- * Returns -1 if no index stores a null object.
- *
- * @return An int indicating the first null slot in the group.
- */
- public getFirstNull(): number {
-
- var basic: Basic;
- var i: number = 0;
- var l: number = this.members.length;
-
- while (i < l)
- {
- if (this.members[i] == null)
- {
- return i;
+ this.members.splice(index, 1);
+ this.length--;
}
else
{
- i++;
+ this.members[index] = null;
}
+
+ return Object;
+
}
- return -1;
+ /**
+ * Replaces an existing Basic with a new one.
+ *
+ * @param OldObject The object you want to replace.
+ * @param NewObject The new object you want to use instead.
+ *
+ * @return The new object.
+ */
+ public replace(OldObject: Basic, NewObject: Basic): Basic {
- }
+ var index: number = this.members.indexOf(OldObject);
- /**
- * Call this function to retrieve the first object with exists == true in the group.
- * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
- *
- * @return A Basic currently flagged as existing.
- */
- public getFirstExtant(): Basic {
-
- var basic: Basic;
- var i: number = 0;
-
- while (i < length)
- {
- basic = this.members[i++];
-
- if ((basic != null) && basic.exists)
+ if ((index < 0) || (index >= this.members.length))
{
- return basic;
+ return null;
}
+
+ this.members[index] = NewObject;
+
+ return NewObject;
+
}
- return null;
+ /**
+ * Call this function to sort the group according to a particular value and order.
+ * For example, to sort game objects for Zelda-style overlaps you might call
+ * myGroup.sort("y",Group.ASCENDING) at the bottom of your
+ * FlxState.update() override. To sort all existing objects after
+ * a big explosion or bomb attack, you might call myGroup.sort("exists",Group.DESCENDING).
+ *
+ * @param Index The string name of the member variable you want to sort on. Default value is "y".
+ * @param Order A Group constant that defines the sort order. Possible values are Group.ASCENDING and Group.DESCENDING. Default value is Group.ASCENDING.
+ */
+ public sort(Index: string = "y", Order: number = Group.ASCENDING) {
- }
+ this._sortIndex = Index;
+ this._sortOrder = Order;
+ this.members.sort(this.sortHandler);
- /**
- * Call this function to retrieve the first object with dead == false in the group.
- * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
- *
- * @return A Basic currently flagged as not dead.
- */
- public getFirstAlive(): Basic {
-
- var basic: Basic;
- var i: number = 0;
-
- while (i < this.length)
- {
- basic = this.members[i++];
-
- if ((basic != null) && basic.exists && basic.alive)
- {
- return basic;
- }
}
- return null;
+ /**
+ * Go through and set the specified variable to the specified value on all members of the group.
+ *
+ * @param VariableName The string representation of the variable name you want to modify, for example "visible" or "scrollFactor".
+ * @param Value The value you want to assign to that variable.
+ * @param Recurse Default value is true, meaning if setAll() encounters a member that is a group, it will call setAll() on that group rather than modifying its variable.
+ */
+ public setAll(VariableName: string, Value: Object, Recurse: bool = true) {
- }
+ var basic: Basic;
+ var i: number = 0;
- /**
- * Call this function to retrieve the first object with dead == true in the group.
- * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
- *
- * @return A Basic currently flagged as dead.
- */
- public getFirstDead(): Basic {
-
- var basic: Basic;
- var i: number = 0;
-
- while (i < this.length)
- {
- basic = this.members[i++];
-
- if ((basic != null) && !basic.alive)
+ while (i < length)
{
- return basic;
- }
- }
+ basic = this.members[i++];
- return null;
-
- }
-
- /**
- * Call this function to find out how many members of the group are not dead.
- *
- * @return The number of Basics flagged as not dead. Returns -1 if group is empty.
- */
- public countLiving(): number {
-
- var count: number = -1;
- var basic: Basic;
- var i: number = 0;
-
- while (i < this.length)
- {
- basic = this.members[i++];
-
- if (basic != null)
- {
- if (count < 0)
+ if (basic != null)
{
- count = 0;
- }
-
- if (basic.exists && basic.alive)
- {
- count++;
+ if (Recurse && (basic.isGroup == true))
+ {
+ callAll() encounters a member that is a group, it will call callAll() on that group rather than calling the group's function.
+ */
+ public callAll(FunctionName: string, Recurse: bool = true) {
- }
+ var basic: Basic;
+ var i: number = 0;
- /**
- * Call this function to find out how many members of the group are dead.
- *
- * @return The number of Basics flagged as dead. Returns -1 if group is empty.
- */
- public countDead(): number {
-
- var count: number = -1;
- var basic: Basic;
- var i: number = 0;
-
- while (i < this.length)
- {
- basic = this.members[i++];
-
- if (basic != null)
+ while (i < this.length)
{
- if (count < 0)
- {
- count = 0;
- }
+ basic = this.members[i++];
- if (!basic.alive)
+ if (basic != null)
{
- count++;
+ if (Recurse && (basic.isGroup == true))
+ {
+ Basic from the members list.
- */
- public getRandom(StartIndex: number = 0, Length: number = 0): Basic {
-
- if (Length == 0)
- {
- Length = this.length;
- }
-
- return this._game.math.getRandom(this.members, StartIndex, Length);
-
- }
-
- /**
- * Remove all instances of Basic subclass (FlxBasic, FlxBlock, etc) from the list.
- * WARNING: does not destroy() or kill() any of these objects!
- */
- public clear() {
- this.length = this.members.length = 0;
- }
-
- /**
- * Calls kill on the group's members and then on the group itself.
- */
- public kill() {
-
- var basic: Basic;
- var i: number = 0;
-
- while (i < this.length)
- {
- basic = this.members[i++];
-
- if ((basic != null) && basic.exists)
+ while (i < this.length)
{
- basic.kill();
+ basic = this.members[i++];
+
+ if (basic != null)
+ {
+ if (Recurse && (basic.isGroup == true))
+ {
+ basic.forEach(callback, true);
+ }
+ else
+ {
+ callback.call(this, basic);
+ }
+ }
}
+
}
- }
+ /**
+ * Call this function to retrieve the first object with exists == false in the group.
+ * This is handy for recycling in general, e.g. respawning enemies.
+ *
+ * @param ObjectClass An optional parameter that lets you narrow the results to instances of this particular class.
+ *
+ * @return A Basic currently flagged as not existing.
+ */
+ public getFirstAvailable(ObjectClass = null) {
- /**
- * Helper function for the sort process.
- *
- * @param Obj1 The first object being sorted.
- * @param Obj2 The second object being sorted.
- *
- * @return An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
- */
- public sortHandler(Obj1: Basic, Obj2: Basic): number {
+ var basic;
+ var i: number = 0;
- if (Obj1[this._sortIndex] < Obj2[this._sortIndex])
- {
- return this._sortOrder;
- }
- else if (Obj1[this._sortIndex] > Obj2[this._sortIndex])
- {
- return -this._sortOrder;
+ while (i < this.length)
+ {
+ basic = this.members[i++];
+
+ if ((basic != null) && !basic.exists && ((ObjectClass == null) || (typeof basic === ObjectClass)))
+ {
+ return basic;
+ }
+
+ }
+
+ return null;
}
- return 0;
+ /**
+ * Call this function to retrieve the first index set to 'null'.
+ * Returns -1 if no index stores a null object.
+ *
+ * @return An int indicating the first null slot in the group.
+ */
+ public getFirstNull(): number {
+
+ var basic: Basic;
+ var i: number = 0;
+ var l: number = this.members.length;
+
+ while (i < l)
+ {
+ if (this.members[i] == null)
+ {
+ return i;
+ }
+ else
+ {
+ i++;
+ }
+ }
+
+ return -1;
+
+ }
+
+ /**
+ * Call this function to retrieve the first object with exists == true in the group.
+ * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
+ *
+ * @return A Basic currently flagged as existing.
+ */
+ public getFirstExtant(): Basic {
+
+ var basic: Basic;
+ var i: number = 0;
+
+ while (i < length)
+ {
+ basic = this.members[i++];
+
+ if ((basic != null) && basic.exists)
+ {
+ return basic;
+ }
+ }
+
+ return null;
+
+ }
+
+ /**
+ * Call this function to retrieve the first object with dead == false in the group.
+ * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
+ *
+ * @return A Basic currently flagged as not dead.
+ */
+ public getFirstAlive(): Basic {
+
+ var basic: Basic;
+ var i: number = 0;
+
+ while (i < this.length)
+ {
+ basic = this.members[i++];
+
+ if ((basic != null) && basic.exists && basic.alive)
+ {
+ return basic;
+ }
+ }
+
+ return null;
+
+ }
+
+ /**
+ * Call this function to retrieve the first object with dead == true in the group.
+ * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
+ *
+ * @return A Basic currently flagged as dead.
+ */
+ public getFirstDead(): Basic {
+
+ var basic: Basic;
+ var i: number = 0;
+
+ while (i < this.length)
+ {
+ basic = this.members[i++];
+
+ if ((basic != null) && !basic.alive)
+ {
+ return basic;
+ }
+ }
+
+ return null;
+
+ }
+
+ /**
+ * Call this function to find out how many members of the group are not dead.
+ *
+ * @return The number of Basics flagged as not dead. Returns -1 if group is empty.
+ */
+ public countLiving(): number {
+
+ var count: number = -1;
+ var basic: Basic;
+ var i: number = 0;
+
+ while (i < this.length)
+ {
+ basic = this.members[i++];
+
+ if (basic != null)
+ {
+ if (count < 0)
+ {
+ count = 0;
+ }
+
+ if (basic.exists && basic.alive)
+ {
+ count++;
+ }
+ }
+ }
+
+ return count;
+
+ }
+
+ /**
+ * Call this function to find out how many members of the group are dead.
+ *
+ * @return The number of Basics flagged as dead. Returns -1 if group is empty.
+ */
+ public countDead(): number {
+
+ var count: number = -1;
+ var basic: Basic;
+ var i: number = 0;
+
+ while (i < this.length)
+ {
+ basic = this.members[i++];
+
+ if (basic != null)
+ {
+ if (count < 0)
+ {
+ count = 0;
+ }
+
+ if (!basic.alive)
+ {
+ count++;
+ }
+ }
+ }
+
+ return count;
+
+ }
+
+ /**
+ * Returns a member at random from the group.
+ *
+ * @param StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
+ * @param Length Optional restriction on the number of values you want to randomly select from.
+ *
+ * @return A Basic from the members list.
+ */
+ public getRandom(StartIndex: number = 0, Length: number = 0): Basic {
+
+ if (Length == 0)
+ {
+ Length = this.length;
+ }
+
+ return this._game.math.getRandom(this.members, StartIndex, Length);
+
+ }
+
+ /**
+ * Remove all instances of Basic subclass (FlxBasic, FlxBlock, etc) from the list.
+ * WARNING: does not destroy() or kill() any of these objects!
+ */
+ public clear() {
+ this.length = this.members.length = 0;
+ }
+
+ /**
+ * Calls kill on the group's members and then on the group itself.
+ */
+ public kill() {
+
+ var basic: Basic;
+ var i: number = 0;
+
+ while (i < this.length)
+ {
+ basic = this.members[i++];
+
+ if ((basic != null) && basic.exists)
+ {
+ basic.kill();
+ }
+ }
+
+ }
+
+ /**
+ * Helper function for the sort process.
+ *
+ * @param Obj1 The first object being sorted.
+ * @param Obj2 The second object being sorted.
+ *
+ * @return An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
+ */
+ public sortHandler(Obj1: Basic, Obj2: Basic): number {
+
+ if (Obj1[this._sortIndex] < Obj2[this._sortIndex])
+ {
+ return this._sortOrder;
+ }
+ else if (Obj1[this._sortIndex] > Obj2[this._sortIndex])
+ {
+ return -this._sortOrder;
+ }
+
+ return 0;
+
+ }
}
diff --git a/Phaser/Loader.ts b/Phaser/Loader.ts
index 11157d80..4f5823fc 100644
--- a/Phaser/Loader.ts
+++ b/Phaser/Loader.ts
@@ -1,327 +1,335 @@
-/// Sprite to have slightly more specialized behavior
- * common to many game scenarios. You can override and extend this class
- * just like you would Sprite. While Emitter
- * used to work with just any old sprite, it now requires a
- * Particle based class.
- *
- * @author Adam Atomic
- * @author Richard Davey
- */
-class Particle extends Sprite {
-
- /**
- * Instantiate a new particle. Like Sprite, all meaningful creation
- * happens during loadGraphic() or makeGraphic() 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 Emitter.
- * You can override this to add custom behavior like a sound or AI or something.
- */
- public onEmit() {
- }
-}
diff --git a/Phaser/Phaser.csproj b/Phaser/Phaser.csproj
index d17204cd..4e589267 100644
--- a/Phaser/Phaser.csproj
+++ b/Phaser/Phaser.csproj
@@ -1,4 +1,4 @@
-
+
IMPORTANT: Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.
- * @type boolean - */ - public active: bool = true; + /** + * Signals Version Number + * @property VERSION + * @type String + * @const + */ + public static VERSION: string = '1.0.0'; - /** - * - * @method validateListener - * @param {Any} listener - * @param {Any} fnName - */ - public validateListener(listener, fnName) { + /** + * If Signal should keep record of previously dispatched parameters and + * automatically execute listener during `add()`/`addOnce()` if Signal was + * already dispatched before. + * @type boolean + */ + public memorize: bool = false; - if (typeof listener !== 'function') - { - throw new Error('listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName)); - } + /** + * @type boolean + * @private + */ + private _shouldPropagate: bool = true; - } + /** + * If Signal is active and should broadcast events. + *IMPORTANT: Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.
+ * @type boolean + */ + public active: bool = true; - /** - * @param {Function} listener - * @param {boolean} isOnce - * @param {Object} [listenerContext] - * @param {Number} [priority] - * @return {SignalBinding} - * @private - */ - private _registerListener(listener, isOnce: bool, listenerContext, priority: number): SignalBinding { + /** + * + * @method validateListener + * @param {Any} listener + * @param {Any} fnName + */ + public validateListener(listener, fnName) { - var prevIndex: number = this._indexOfListener(listener, listenerContext); - var binding: SignalBinding; - - if (prevIndex !== -1) - { - binding = this._bindings[prevIndex]; - - if (binding.isOnce() !== isOnce) + if (typeof listener !== 'function') { - throw new Error('You cannot add' + (isOnce ? '' : 'Once') + '() then add' + (!isOnce ? '' : 'Once') + '() the same listener without removing the relationship first.'); + throw new Error('listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName)); } - } - else - { - binding = new SignalBinding(this, listener, isOnce, listenerContext, priority); - this._addBinding(binding); } - if (this.memorize && this._prevParams) - { - binding.execute(this._prevParams); - } + /** + * @param {Function} listener + * @param {boolean} isOnce + * @param {Object} [listenerContext] + * @param {Number} [priority] + * @return {SignalBinding} + * @private + */ + private _registerListener(listener, isOnce: bool, listenerContext, priority: number): SignalBinding { - return binding; + var prevIndex: number = this._indexOfListener(listener, listenerContext); + var binding: SignalBinding; - } - - /** - * - * @method _addBinding - * @param {SignalBinding} binding - * @private - */ - private _addBinding(binding: SignalBinding) { - - //simplified insertion sort - - var n: number = this._bindings.length; - - do { --n; } while (this._bindings[n] && binding.priority <= this._bindings[n].priority); - - this._bindings.splice(n + 1, 0, binding); - - } - - /** - * - * @method _indexOfListener - * @param {Function} listener - * @return {number} - * @private - */ - private _indexOfListener(listener, context): number { - - var n: number = this._bindings.length; - var cur: SignalBinding; - - while (n--) - { - cur = this._bindings[n]; - - if (cur.getListener() === listener && cur.context === context) + if (prevIndex !== -1) { - return n; + binding = this._bindings[prevIndex]; + + if (binding.isOnce() !== isOnce) + { + throw new Error('You cannot add' + (isOnce ? '' : 'Once') + '() then add' + (!isOnce ? '' : 'Once') + '() the same listener without removing the relationship first.'); + } } + else + { + binding = new SignalBinding(this, listener, isOnce, listenerContext, priority); + + this._addBinding(binding); + } + + if (this.memorize && this._prevParams) + { + binding.execute(this._prevParams); + } + + return binding; + } - return -1; + /** + * + * @method _addBinding + * @param {SignalBinding} binding + * @private + */ + private _addBinding(binding: SignalBinding) { - } + //simplified insertion sort - /** - * Check if listener was attached to Signal. - * @param {Function} listener - * @param {Object} [context] - * @return {boolean} if Signal has the specified listener. - */ - public has(listener, context?: any = null): bool { + var n: number = this._bindings.length; - return this._indexOfListener(listener, context) !== -1; + do { --n; } while (this._bindings[n] && binding.priority <= this._bindings[n].priority); - } + this._bindings.splice(n + 1, 0, binding); - /** - * Add a listener to the signal. - * @param {Function} listener Signal handler function. - * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). - * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) - * @return {SignalBinding} An Object representing the binding between the Signal and listener. - */ - public add(listener, listenerContext?: any = null, priority?: number = 0): SignalBinding { - - this.validateListener(listener, 'add'); - - return this._registerListener(listener, false, listenerContext, priority); - - } - - /** - * Add listener to the signal that should be removed after first execution (will be executed only once). - * @param {Function} listener Signal handler function. - * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). - * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) - * @return {SignalBinding} An Object representing the binding between the Signal and listener. - */ - public addOnce(listener, listenerContext?: any = null, priority?: number = 0): SignalBinding { - - this.validateListener(listener, 'addOnce'); - - return this._registerListener(listener, true, listenerContext, priority); - - } - - /** - * Remove a single listener from the dispatch queue. - * @param {Function} listener Handler function that should be removed. - * @param {Object} [context] Execution context (since you can add the same handler multiple times if executing in a different context). - * @return {Function} Listener handler function. - */ - public remove(listener, context?: any = null) { - - this.validateListener(listener, 'remove'); - - var i: number = this._indexOfListener(listener, context); - - if (i !== -1) - { - this._bindings[i]._destroy(); //no reason to a SignalBinding exist if it isn't attached to a signal - this._bindings.splice(i, 1); } - return listener; + /** + * + * @method _indexOfListener + * @param {Function} listener + * @return {number} + * @private + */ + private _indexOfListener(listener, context): number { - } + var n: number = this._bindings.length; + var cur: SignalBinding; - /** - * Remove all listeners from the Signal. - */ - public removeAll() { + while (n--) + { + cur = this._bindings[n]; - var n: number = this._bindings.length; + if (cur.getListener() === listener && cur.context === context) + { + return n; + } + } + + return -1; - while (n--) - { - this._bindings[n]._destroy(); } - this._bindings.length = 0; + /** + * Check if listener was attached to Signal. + * @param {Function} listener + * @param {Object} [context] + * @return {boolean} if Signal has the specified listener. + */ + public has(listener, context?: any = null): bool { - } + return this._indexOfListener(listener, context) !== -1; - /** - * @return {number} Number of listeners attached to the Signal. - */ - public getNumListeners(): number { - - return this._bindings.length; - - } - - /** - * Stop propagation of the event, blocking the dispatch to next listeners on the queue. - *IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.
- * @see Signal.prototype.disable - */ - public halt() { - - this._shouldPropagate = false; - - } - - /** - * Dispatch/Broadcast Signal to all listeners added to the queue. - * @param {...*} [params] Parameters that should be passed to each handler. - */ - public dispatch(...paramsArr: any[]) { - - if (!this.active) - { - return; } - var n: number = this._bindings.length; - var bindings: SignalBinding[]; + /** + * Add a listener to the signal. + * @param {Function} listener Signal handler function. + * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). + * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) + * @return {SignalBinding} An Object representing the binding between the Signal and listener. + */ + public add(listener, listenerContext?: any = null, priority?: number = 0): SignalBinding { + + this.validateListener(listener, 'add'); + + return this._registerListener(listener, false, listenerContext, priority); - if (this.memorize) - { - this._prevParams = paramsArr; } - if (!n) - { - //should come after memorize - return; + /** + * Add listener to the signal that should be removed after first execution (will be executed only once). + * @param {Function} listener Signal handler function. + * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). + * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) + * @return {SignalBinding} An Object representing the binding between the Signal and listener. + */ + public addOnce(listener, listenerContext?: any = null, priority?: number = 0): SignalBinding { + + this.validateListener(listener, 'addOnce'); + + return this._registerListener(listener, true, listenerContext, priority); + } - bindings = this._bindings.slice(0); //clone array in case add/remove items during dispatch + /** + * Remove a single listener from the dispatch queue. + * @param {Function} listener Handler function that should be removed. + * @param {Object} [context] Execution context (since you can add the same handler multiple times if executing in a different context). + * @return {Function} Listener handler function. + */ + public remove(listener, context?: any = null) { - this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch. + this.validateListener(listener, 'remove'); - //execute all callbacks until end of the list or until a callback returns `false` or stops propagation - //reverse loop since listeners with higher priority will be added at the end of the list - do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false); + var i: number = this._indexOfListener(listener, context); + + if (i !== -1) + { + this._bindings[i]._destroy(); //no reason to a SignalBinding exist if it isn't attached to a signal + this._bindings.splice(i, 1); + } + + return listener; + + } + + /** + * Remove all listeners from the Signal. + */ + public removeAll() { + + var n: number = this._bindings.length; + + while (n--) + { + this._bindings[n]._destroy(); + } + + this._bindings.length = 0; + + } + + /** + * @return {number} Number of listeners attached to the Signal. + */ + public getNumListeners(): number { + + return this._bindings.length; + + } + + /** + * Stop propagation of the event, blocking the dispatch to next listeners on the queue. + *IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.
+ * @see Signal.prototype.disable + */ + public halt() { + + this._shouldPropagate = false; + + } + + /** + * Dispatch/Broadcast Signal to all listeners added to the queue. + * @param {...*} [params] Parameters that should be passed to each handler. + */ + public dispatch(...paramsArr: any[]) { + + if (!this.active) + { + return; + } + + var n: number = this._bindings.length; + var bindings: SignalBinding[]; + + if (this.memorize) + { + this._prevParams = paramsArr; + } + + if (!n) + { + //should come after memorize + return; + } + + bindings = this._bindings.slice(0); //clone array in case add/remove items during dispatch + + this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch. + + //execute all callbacks until end of the list or until a callback returns `false` or stops propagation + //reverse loop since listeners with higher priority will be added at the end of the list + do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false); + + } + + /** + * Forget memorized arguments. + * @see Signal.memorize + */ + public forget() { + + this._prevParams = null; + + } + + /** + * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object). + *IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.
+ */ + public dispose() { + + this.removeAll(); + + delete this._bindings; + delete this._prevParams; + + } + + /** + * @return {string} String representation of the object. + */ + public toString(): string { + + return '[Signal active:' + this.active + ' numListeners:' + this.getNumListeners() + ']'; + + } } - /** - * Forget memorized arguments. - * @see Signal.memorize - */ - public forget() { - - this._prevParams = null; - - } - - /** - * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object). - *IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.
- */ - public dispose() { - - this.removeAll(); - - delete this._bindings; - delete this._prevParams; - - } - - /** - * @return {string} String representation of the object. - */ - public toString(): string { - - return '[Signal active:' + this.active + ' numListeners:' + this.getNumListeners() + ']'; - - } - -} - +} \ No newline at end of file diff --git a/Phaser/SignalBinding.ts b/Phaser/SignalBinding.ts index 00b6c1a4..eb616566 100644 --- a/Phaser/SignalBinding.ts +++ b/Phaser/SignalBinding.ts @@ -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 @@ } +} \ No newline at end of file diff --git a/Phaser/Sound.ts b/Phaser/Sound.ts index 9551de63..fe62278c 100644 --- a/Phaser/Sound.ts +++ b/Phaser/Sound.ts @@ -1,219 +1,233 @@ -class SoundManager { +///GameObject 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 FlxGroup (or even bundling groups together!).
- *
- * NOTE: does NOT take objects' scrollfactor into account, all overlaps are checked in world space.
- * - * @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 twoGameObject parameters - e.g. myOverlapFunction(Object1:GameObject,Object2:GameObject) - that is called if those two objects overlap.
- * @param ProcessCallback A function with two GameObject parameters - e.g. myOverlapFunction(Object1:GameObject,Object2:GameObject) - 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;
+ public render() {
+
+ // Unlike in flixel our render process is camera driven, not group driven
+ this._cameras.render();
+
}
- QuadTree.divisions = this.worldDivisions;
+ public destroy() {
- var quadTree: QuadTree = new QuadTree(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
+ this.group.destroy();
- quadTree.load(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, ProcessCallback);
+ this._cameras.destroy();
- var result: bool = quadTree.execute();
-
- quadTree.destroy();
-
- quadTree = null;
-
- return result;
-
- }
-
- /**
- * The main collision resolution in flixel.
- *
- * @param Object1 Any Sprite.
- * @param Object2 Any other Sprite.
- *
- * @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 Sprite.
- * @param Object2 Any other Sprite.
- *
- * @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);
- }
+ // World methods
- if (typeof Object2 === 'FlxTilemap')
- {
- return Object2.overlapsWithCallback(Object1, separateX, true);
- }
- */
+ public setSize(width: number, height: number, updateCameraBounds: bool = 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;
+ this.bounds.width = width;
+ this.bounds.height = height;
- 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))
+ if (updateCameraBounds == true)
{
- 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;
+ this._game.camera.setBounds(0, 0, width, height);
}
- return true;
- }
- else
- {
- return false;
}
- }
-
- /**
- * The Y-axis component of the object separation process.
- *
- * @param Object1 Any Sprite.
- * @param Object2 Any other Sprite.
- *
- * @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);
+ public get width(): number {
+ return this.bounds.width;
}
- 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;
- }
- }
- }
+ public set width(value: number) {
+ this.bounds.width = value;
}
- //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;
+ public get height(): number {
+ return this.bounds.height;
}
- else
- {
- return false;
+
+ public set height(value: number) {
+ this.bounds.height = value;
}
+
+ public get centerX(): number {
+ return this.bounds.halfWidth;
+ }
+
+ public get centerY(): number {
+ return this.bounds.halfHeight;
+ }
+
+ public get randomX(): number {
+ return Math.round(Math.random() * this.bounds.width);
+ }
+
+ public get randomY(): number {
+ return Math.round(Math.random() * this.bounds.height);
+ }
+
+ // Cameras
+
+ public addExistingCamera(cam: Camera): Camera {
+ //return this._cameras.addCamera(x, y, width, height);
+ return cam;
+ }
+
+ public createCamera(x: number, y: number, width: number, height: number): Camera {
+ return this._cameras.addCamera(x, y, width, height);
+ }
+
+ public removeCamera(id: number): bool {
+ return this._cameras.removeCamera(id);
+ }
+
+ public getAllCameras(): Camera[] {
+ return this._cameras.getAll();
+ }
+
+ // Sprites
+
+ // Drop this?
+ public addExistingSprite(sprite: Sprite): Sprite {
+ return Emitter is a lightweight particle emitter.
+ * It can be used for one-time explosions or for
+ * continuous fx like rain and fire. Emitter
+ * is not optimized or anything; all it does is launch
+ * Particle objects out at set intervals
+ * by setting their positions and velocities accordingly.
+ * It is easy to use and relatively efficient,
+ * relying on Group's RECYCLE POWERS.
+ *
+ * @author Adam Atomic
+ * @author Richard Davey
+ */
+
+/**
+* Phaser
+*/
+
+module Phaser {
+
+ export class Emitter extends Group {
+
+ /**
+ * Creates a new FlxEmitter 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 acceleration.y 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 Particle.
+ */
+ 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 FlxObject.
+ *
+ * @param Object The FlxObject 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);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/Phaser/gameobjects/GameObject.ts b/Phaser/gameobjects/GameObject.ts
new file mode 100644
index 00000000..6a176501
--- /dev/null
+++ b/Phaser/gameobjects/GameObject.ts
@@ -0,0 +1,494 @@
+/// GameObject overlaps this GameObject or FlxGroup.
+ * If the group has a LOT of things in it, it might be faster to use FlxG.overlaps().
+ * 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 = GameObject were located at the given position, would it overlap the GameObject or FlxGroup?
+ * 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 GameObject 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 Point object and assigns the post-scrolled X and Y values of this object to it.
+ *
+ * @return The Point you passed in, or a new Point 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 Point object if you're so inclined. Otherwise a new one is created.
+ *
+ * @return A Point 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 touching.
+ * 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;
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/Phaser/gameobjects/GeomSprite.ts b/Phaser/gameobjects/GeomSprite.ts
new file mode 100644
index 00000000..4abd43e8
--- /dev/null
+++ b/Phaser/gameobjects/GeomSprite.ts
@@ -0,0 +1,431 @@
+/// Sprite to have slightly more specialized behavior
+ * common to many game scenarios. You can override and extend this class
+ * just like you would Sprite. While Emitter
+ * used to work with just any old sprite, it now requires a
+ * Particle based class.
+ *
+ * @author Adam Atomic
+ * @author Richard Davey
+ */
+
+/**
+* Phaser
+*/
+
+module Phaser {
+
+ export class Particle extends Sprite {
+
+ /**
+ * Instantiate a new particle. Like Sprite, all meaningful creation
+ * happens during loadGraphic() or makeGraphic() 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 Emitter.
+ * You can override this to add custom behavior like a sound or AI or something.
+ */
+ public onEmit() {
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/Phaser/gameobjects/Sprite.ts b/Phaser/gameobjects/Sprite.ts
new file mode 100644
index 00000000..7dae0726
--- /dev/null
+++ b/Phaser/gameobjects/Sprite.ts
@@ -0,0 +1,276 @@
+/// - * Returns true or false based on the chance value (default 50%). For example if you wanted a player to have a 30% chance - * of getting a bonus, call chanceRoll(30) - true means the chance passed, false means it failed. - *
- * @param chance The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%) - * @return true if the roll passed, or false - */ - function (chance) { - if (typeof chance === "undefined") { chance = 50; } - if(chance <= 0) { - return false; - } else if(chance >= 100) { - return true; - } else { - if(Math.random() * 100 >= chance) { - return false; - } else { - return true; - } - } - }; - GameMath.prototype.maxAdd = /** - * Adds the given amount to the value, but never lets the value go over the specified maximum - * - * @param value The value to add the amount to - * @param amount The amount to add to the value - * @param max The maximum the value is allowed to be - * @return The new value - */ - function (value, amount, max) { - value += amount; - if(value > max) { - value = max; - } - return value; - }; - GameMath.prototype.minSub = /** - * Subtracts the given amount from the value, but never lets the value go below the specified minimum - * - * @param value The base value - * @param amount The amount to subtract from the base value - * @param min The minimum the value is allowed to be - * @return The new value - */ - function (value, amount, min) { - value -= amount; - if(value < min) { - value = min; - } - return value; - }; - GameMath.prototype.wrapValue = /** - * Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around. - *Values must be positive integers, and are passed through Math.abs
- * - * @param value The value to add the amount to - * @param amount The amount to add to the value - * @param max The maximum the value is allowed to be - * @return The wrapped value - */ - function (value, amount, max) { - var diff; - value = Math.abs(value); - amount = Math.abs(amount); - max = Math.abs(max); - diff = (value + amount) % max; - return diff; - }; - GameMath.prototype.randomSign = /** - * Randomly returns either a 1 or -1 - * - * @return 1 or -1 - */ - function () { - return (Math.random() > 0.5) ? 1 : -1; - }; - GameMath.prototype.isOdd = /** - * Returns true if the number given is odd. - * - * @param n The number to check - * - * @return True if the given number is odd. False if the given number is even. - */ - function (n) { - if(n & 1) { - return true; - } else { - return false; - } - }; - GameMath.prototype.isEven = /** - * Returns true if the number given is even. - * - * @param n The number to check - * - * @return True if the given number is even. False if the given number is odd. - */ - function (n) { - if(n & 1) { - return false; - } else { - return true; - } - }; - GameMath.prototype.wrapAngle = /** - * Keeps an angle value between -180 and +180Number between 0 and 1.
- */
- function () {
- return this.globalSeed = this.srand(this.globalSeed);
- };
- GameMath.prototype.srand = /**
- * Generates a random number based on the seed provided.
- *
- * @param Seed A number between 0 and 1, used to generate a predictable random number (very optional).
- *
- * @return A Number between 0 and 1.
- */
- function (Seed) {
- return ((69621 * (Seed * 0x7FFFFFFF)) % 0x7FFFFFFF) / 0x7FFFFFFF;
- };
- GameMath.prototype.getRandom = /**
- * Fetch a random entry from the given array.
- * Will return null if random selection is missing, or array has no entries.
- * FlxG.getRandom() is deterministic and safe for use with replays/recordings.
- * HOWEVER, FlxU.getRandom() is NOT deterministic and unsafe for use with replays/recordings.
- *
- * @param Objects An array of objects.
- * @param StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
- * @param Length Optional restriction on the number of values you want to randomly select from.
- *
- * @return The random object that was selected.
- */
- function (Objects, StartIndex, Length) {
- if (typeof StartIndex === "undefined") { StartIndex = 0; }
- if (typeof Length === "undefined") { Length = 0; }
- if(Objects != null) {
- var l = Length;
- if((l == 0) || (l > Objects.length - StartIndex)) {
- l = Objects.length - StartIndex;
- }
- if(l > 0) {
- return Objects[StartIndex + Math.floor(Math.random() * l)];
- }
- }
- return null;
- };
- GameMath.prototype.floor = /**
- * Round down to the next whole number. E.g. floor(1.7) == 1, and floor(-2.7) == -2.
- *
- * @param Value Any number.
- *
- * @return The rounded value of that number.
- */
- function (Value) {
- var n = Value | 0;
- return (Value > 0) ? (n) : ((n != Value) ? (n - 1) : (n));
- };
- GameMath.prototype.ceil = /**
- * Round up to the next whole number. E.g. ceil(1.3) == 2, and ceil(-2.3) == -3.
- *
- * @param Value Any number.
- *
- * @return The rounded value of that number.
- */
- function (Value) {
- var n = Value | 0;
- return (Value > 0) ? ((n != Value) ? (n + 1) : (n)) : (n);
- };
- GameMath.prototype.sinCosGenerator = /**
- * Generate a sine and cosine table simultaneously and extremely quickly. Based on research by Franky of scene.at
- * - * The parameters allow you to specify the length, amplitude and frequency of the wave. Once you have called this function - * you should get the results via getSinTable() and getCosTable(). This generator is fast enough to be used in real-time. - *
- * @param length The length of the wave - * @param sinAmplitude The amplitude to apply to the sine table (default 1.0) if you need values between say -+ 125 then give 125 as the value - * @param cosAmplitude The amplitude to apply to the cosine table (default 1.0) if you need values between say -+ 125 then give 125 as the value - * @param frequency The frequency of the sine and cosine table data - * @return Returns the sine table - * @see getSinTable - * @see getCosTable - */ - function (length, sinAmplitude, cosAmplitude, frequency) { - if (typeof sinAmplitude === "undefined") { sinAmplitude = 1.0; } - if (typeof cosAmplitude === "undefined") { cosAmplitude = 1.0; } - if (typeof frequency === "undefined") { frequency = 1.0; } - var sin = sinAmplitude; - var cos = cosAmplitude; - var frq = frequency * Math.PI / length; - this.cosTable = []; - this.sinTable = []; - for(var c = 0; c < length; c++) { - cos -= sin * frq; - sin += cos * frq; - this.cosTable[c] = cos; - this.sinTable[c] = sin; - } - return this.sinTable; - }; - return GameMath; -})(); -/** -* Point -* -* @desc The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis. -* -* @version 1.2 - 27th February 2013 -* @author Richard Davey -* @todo polar, interpolate -*/ -var Point = (function () { - /** - * Creates a new point. If you pass no parameters to this method, a point is created at (0,0). - * @class Point - * @constructor - * @param {Number} x One-liner. Default is ?. - * @param {Number} y One-liner. Default is ?. - **/ - function Point(x, y) { - if (typeof x === "undefined") { x = 0; } - if (typeof y === "undefined") { y = 0; } - this.setTo(x, y); - } - Point.prototype.add = /** - * Adds the coordinates of another point to the coordinates of this point to create a new point. - * @method add - * @param {Point} point - The point to be added. - * @return {Point} The new Point object. - **/ - function (toAdd, output) { - if (typeof output === "undefined") { output = new Point(); } - return output.setTo(this.x + toAdd.x, this.y + toAdd.y); - }; - Point.prototype.addTo = /** - * Adds the given values to the coordinates of this point and returns it - * @method addTo - * @param {Number} x - The amount to add to the x value of the point - * @param {Number} y - The amount to add to the x value of the point - * @return {Point} This Point object. - **/ - function (x, y) { - if (typeof x === "undefined") { x = 0; } - if (typeof y === "undefined") { y = 0; } - return this.setTo(this.x + x, this.y + y); - }; - Point.prototype.subtractFrom = /** - * Adds the given values to the coordinates of this point and returns it - * @method addTo - * @param {Number} x - The amount to add to the x value of the point - * @param {Number} y - The amount to add to the x value of the point - * @return {Point} This Point object. - **/ - function (x, y) { - if (typeof x === "undefined") { x = 0; } - if (typeof y === "undefined") { y = 0; } - return this.setTo(this.x - x, this.y - y); - }; - Point.prototype.invert = /** - * Inverts the x and y values of this point - * @method invert - * @return {Point} This Point object. - **/ - function () { - return this.setTo(this.y, this.x); - }; - Point.prototype.clamp = /** - * Clamps this Point object to be between the given min and max - * @method clamp - * @param {number} The minimum value to clamp this Point to - * @param {number} The maximum value to clamp this Point to - * @return {Point} This Point object. - **/ - function (min, max) { - this.clampX(min, max); - this.clampY(min, max); - return this; - }; - Point.prototype.clampX = /** - * Clamps the x value of this Point object to be between the given min and max - * @method clampX - * @param {number} The minimum value to clamp this Point to - * @param {number} The maximum value to clamp this Point to - * @return {Point} This Point object. - **/ - function (min, max) { - this.x = Math.max(Math.min(this.x, max), min); - return this; - }; - Point.prototype.clampY = /** - * Clamps the y value of this Point object to be between the given min and max - * @method clampY - * @param {number} The minimum value to clamp this Point to - * @param {number} The maximum value to clamp this Point to - * @return {Point} This Point object. - **/ - function (min, max) { - this.x = Math.max(Math.min(this.x, max), min); - this.y = Math.max(Math.min(this.y, max), min); - return this; - }; - Point.prototype.clone = /** - * Creates a copy of this Point. - * @method clone - * @param {Point} output Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned. - * @return {Point} The new Point object. - **/ - function (output) { - if (typeof output === "undefined") { output = new Point(); } - return output.setTo(this.x, this.y); - }; - Point.prototype.copyFrom = /** - * Copies the point data from the source Point object into this Point object. - * @method copyFrom - * @param {Point} source - The point to copy from. - * @return {Point} This Point object. Useful for chaining method calls. - **/ - function (source) { - return this.setTo(source.x, source.y); - }; - Point.prototype.copyTo = /** - * Copies the point data from this Point object to the given target Point object. - * @method copyTo - * @param {Point} target - The point to copy to. - * @return {Point} The target Point object. - **/ - function (target) { - return target.setTo(this.x, this.y); - }; - Point.prototype.distanceTo = /** - * Returns the distance from this Point object to the given Point object. - * @method distanceFrom - * @param {Point} target - The destination Point object. - * @param {Boolean} round - Round the distance to the nearest integer (default false) - * @return {Number} The distance between this Point object and the destination Point object. - **/ - function (target, round) { - if (typeof round === "undefined") { round = false; } - var dx = this.x - target.x; - var dy = this.y - target.y; - if(round === true) { - return Math.round(Math.sqrt(dx * dx + dy * dy)); - } else { - return Math.sqrt(dx * dx + dy * dy); - } - }; - Point.distanceBetween = /** - * Returns the distance between the two Point objects. - * @method distanceBetween - * @param {Point} pointA - The first Point object. - * @param {Point} pointB - The second Point object. - * @param {Boolean} round - Round the distance to the nearest integer (default false) - * @return {Number} The distance between the two Point objects. - **/ - function distanceBetween(pointA, pointB, round) { - if (typeof round === "undefined") { round = false; } - var dx = pointA.x - pointB.x; - var dy = pointA.y - pointB.y; - if(round === true) { - return Math.round(Math.sqrt(dx * dx + dy * dy)); - } else { - return Math.sqrt(dx * dx + dy * dy); - } - }; - Point.prototype.distanceCompare = /** - * Returns true if the distance between this point and a target point is greater than or equal a specified distance. - * This avoids using a costly square root operation - * @method distanceCompare - * @param {Point} target - The Point object to use for comparison. - * @param {Number} distance - The distance to use for comparison. - * @return {Boolena} True if distance is >= specified distance. - **/ - function (target, distance) { - if(this.distanceTo(target) >= distance) { - return true; - } else { - return false; - } - }; - Point.prototype.equals = /** - * Determines whether this Point object and the given point object are equal. They are equal if they have the same x and y values. - * @method equals - * @param {Point} point - The point to compare against. - * @return {Boolean} A value of true if the object is equal to this Point object; false if it is not equal. - **/ - function (toCompare) { - if(this.x === toCompare.x && this.y === toCompare.y) { - return true; - } else { - return false; - } - }; - Point.prototype.interpolate = /** - * Determines a point between two specified points. The parameter f determines where the new interpolated point is located relative to the two end points specified by parameters pt1 and pt2. - * The closer the value of the parameter f is to 1.0, the closer the interpolated point is to the first point (parameter pt1). The closer the value of the parameter f is to 0, the closer the interpolated point is to the second point (parameter pt2). - * @method interpolate - * @param {Point} pointA - The first Point object. - * @param {Point} pointB - The second Point object. - * @param {Number} f - The level of interpolation between the two points. Indicates where the new point will be, along the line between pt1 and pt2. If f=1, pt1 is returned; if f=0, pt2 is returned. - * @return {Point} The new interpolated Point object. - **/ - function (pointA, pointB, f) { - }; - Point.prototype.offset = /** - * Offsets the Point object by the specified amount. The value of dx is added to the original value of x to create the new x value. - * The value of dy is added to the original value of y to create the new y value. - * @method offset - * @param {Number} dx - The amount by which to offset the horizontal coordinate, x. - * @param {Number} dy - The amount by which to offset the vertical coordinate, y. - * @return {Point} This Point object. Useful for chaining method calls. - **/ - function (dx, dy) { - this.x += dx; - this.y += dy; - return this; - }; - Point.prototype.polar = /** - * Converts a pair of polar coordinates to a Cartesian point coordinate. - * @method polar - * @param {Number} length - The length coordinate of the polar pair. - * @param {Number} angle - The angle, in radians, of the polar pair. - * @return {Point} The new Cartesian Point object. - **/ - function (length, angle) { - }; - Point.prototype.setTo = /** - * Sets the x and y values of this Point object to the given coordinates. - * @method set - * @param {Number} x - The horizontal position of this point. - * @param {Number} y - The vertical position of this point. - * @return {Point} This Point object. Useful for chaining method calls. - **/ - function (x, y) { - this.x = x; - this.y = y; - return this; - }; - Point.prototype.subtract = /** - * Subtracts the coordinates of another point from the coordinates of this point to create a new point. - * @method subtract - * @param {Point} point - The point to be subtracted. - * @param {Point} output Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned. - * @return {Point} The new Point object. - **/ - function (point, output) { - if (typeof output === "undefined") { output = new Point(); } - return output.setTo(this.x - point.x, this.y - point.y); - }; - Point.prototype.toString = /** - * Returns a string representation of this object. - * @method toString - * @return {string} a string representation of the instance. - **/ - function () { - return '[{Point (x=' + this.x + ' y=' + this.y + ')}]'; - }; - return Point; -})(); -///GameObject and Group extend this class,
-* as do the plugins. Has no size, position or graphical data.
-*
-* @author Adam Atomic
-* @author Richard Davey
-*/
-var Basic = (function () {
- /**
- * Instantiate the basic object.
- */
- function Basic(game) {
- /**
- * Allows you to give this object a name. Useful for debugging, but not actually used internally.
- */
- this.name = '';
- this._game = game;
- this.ID = -1;
- this.exists = true;
- this.active = true;
- this.visible = true;
- this.alive = true;
- this.isGroup = false;
- this.ignoreDrawDebug = false;
- }
- Basic.prototype.destroy = /**
- * Override this to null out iables or manually call
- * destroy() on class members if necessary.
- * Don't forget to call super.destroy()!
- */
- function () {
- };
- Basic.prototype.preUpdate = /**
- * Pre-update is called right before update() on each object in the game loop.
- */
- function () {
- };
- Basic.prototype.update = /**
- * Override this to update your class's position and appearance.
- * This is where most of your game rules and behavioral code will go.
- */
- function () {
- };
- Basic.prototype.postUpdate = /**
- * Post-update is called right after update() on each object in the game loop.
- */
- function () {
- };
- Basic.prototype.render = function (camera, cameraOffsetX, cameraOffsetY) {
- };
- Basic.prototype.kill = /**
- * Handy for "killing" game objects.
- * Default behavior is to flag them as nonexistent AND dead.
- * However, if you want the "corpse" to remain in the game,
- * like to animate an effect or whatever, you should override this,
- * setting only alive to false, and leaving exists true.
- */
- function () {
- this.alive = false;
- this.exists = false;
- };
- Basic.prototype.revive = /**
- * Handy for bringing game objects "back to life". Just sets alive and exists back to true.
- * In practice, this is most often called by FlxObject.reset().
- */
- function () {
- this.alive = true;
- this.exists = true;
- };
- Basic.prototype.toString = /**
- * Convert object to readable string name. Useful for debugging, save games, etc.
- */
- function () {
- //return FlxU.getClassName(this, true);
- return "";
- };
- return Basic;
-})();
-/// GameObject overlaps this GameObject or FlxGroup.
- * If the group has a LOT of things in it, it might be faster to use FlxG.overlaps().
- * 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.
- */
- function (ObjectOrGroup, InScreenSpace, Camera) {
- if (typeof InScreenSpace === "undefined") { InScreenSpace = false; }
- if (typeof Camera === "undefined") { Camera = null; }
- if(ObjectOrGroup.isGroup) {
- var results = false;
- var i = 0;
- var members = 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 = 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);
- };
- GameObject.prototype.overlapsAt = /**
- * Checks to see if this GameObject were located at the given position, would it overlap the GameObject or FlxGroup?
- * 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.
- */
- function (X, Y, ObjectOrGroup, InScreenSpace, Camera) {
- if (typeof InScreenSpace === "undefined") { InScreenSpace = false; }
- if (typeof Camera === "undefined") { Camera = null; }
- if(ObjectOrGroup.isGroup) {
- var results = false;
- var basic;
- var i = 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 = 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);
- };
- GameObject.prototype.overlapsPoint = /**
- * Checks to see if a ponumber in 2D world space overlaps this GameObject 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.
- */
- function (point, InScreenSpace, Camera) {
- if (typeof InScreenSpace === "undefined") { InScreenSpace = false; }
- if (typeof Camera === "undefined") { Camera = null; }
- 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 = point.x - Camera.scroll.x;
- var Y = 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);
- };
- GameObject.prototype.onScreen = /**
- * 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.
- */
- function (Camera) {
- if (typeof Camera === "undefined") { Camera = null; }
- 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);
- };
- GameObject.prototype.getScreenXY = /**
- * 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 Point object and assigns the post-scrolled X and Y values of this object to it.
- *
- * @return The Point you passed in, or a new Point if you didn't pass one, containing the screen X and Y position of this object.
- */
- function (point, Camera) {
- if (typeof point === "undefined") { point = null; }
- if (typeof Camera === "undefined") { Camera = null; }
- 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;
- };
- Object.defineProperty(GameObject.prototype, "solid", {
- get: /**
- * 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.
- */
- function () {
- return (this.allowCollisions & GameObject.ANY) > GameObject.NONE;
- },
- set: /**
- * @private
- */
- function (Solid) {
- if(Solid) {
- this.allowCollisions = GameObject.ANY;
- } else {
- this.allowCollisions = GameObject.NONE;
- }
- },
- enumerable: true,
- configurable: true
- });
- GameObject.prototype.getMidpoint = /**
- * Retrieve the midponumber of this object in world coordinates.
- *
- * @Point Allows you to pass in an existing Point object if you're so inclined. Otherwise a new one is created.
- *
- * @return A Point object containing the midponumber of this object in world coordinates.
- */
- function (point) {
- if (typeof point === "undefined") { point = null; }
- if(point == null) {
- point = new Point();
- }
- point.x = this.x + this.width * 0.5;
- point.y = this.y + this.height * 0.5;
- return point;
- };
- GameObject.prototype.reset = /**
- * 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.
- */
- function (X, Y) {
- 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;
- };
- GameObject.prototype.isTouching = /**
- * Handy for checking if this object is touching a particular surface.
- * For slightly better performance you can just & the value directly numbero touching.
- * 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.
- */
- function (Direction) {
- return (this.touching & Direction) > GameObject.NONE;
- };
- GameObject.prototype.justTouched = /**
- * 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.
- */
- function (Direction) {
- return ((this.touching & Direction) > GameObject.NONE) && ((this.wasTouching & Direction) <= GameObject.NONE);
- };
- GameObject.prototype.hurt = /**
- * 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).
- */
- function (Damage) {
- this.health = this.health - Damage;
- if(this.health <= 0) {
- this.kill();
- }
- };
- GameObject.prototype.destroy = function () {
- };
- Object.defineProperty(GameObject.prototype, "x", {
- get: function () {
- return this.bounds.x;
- },
- set: function (value) {
- this.bounds.x = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GameObject.prototype, "y", {
- get: function () {
- return this.bounds.y;
- },
- set: function (value) {
- this.bounds.y = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GameObject.prototype, "rotation", {
- get: function () {
- return this._angle;
- },
- set: function (value) {
- this._angle = this._game.math.wrap(value, 360, 0);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GameObject.prototype, "angle", {
- get: function () {
- return this._angle;
- },
- set: function (value) {
- this._angle = this._game.math.wrap(value, 360, 0);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GameObject.prototype, "width", {
- get: function () {
- return this.bounds.width;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GameObject.prototype, "height", {
- get: function () {
- return this.bounds.height;
- },
- enumerable: true,
- configurable: true
- });
- return GameObject;
-})(Basic);
-/// Basics.
-* NOTE: Although Group extends Basic, it will not automatically
-* add itself to the global collisions quad tree, it will only add its members.
-*
-* @author Adam Atomic
-* @author Richard Davey
-*/
-var Group = (function (_super) {
- __extends(Group, _super);
- function Group(game, MaxSize) {
- if (typeof MaxSize === "undefined") { MaxSize = 0; }
- _super.call(this, game);
- this.isGroup = true;
- this.members = [];
- this.length = 0;
- this._maxSize = MaxSize;
- this._marker = 0;
- this._sortIndex = null;
- }
- Group.ASCENDING = -1;
- Group.DESCENDING = 1;
- Group.prototype.destroy = /**
- * Override this function to handle any deleting or "shutdown" type operations you might need,
- * such as removing traditional Flash children like Basic objects.
- */
- function () {
- if(this.members != null) {
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if(basic != null) {
- basic.destroy();
- }
- }
- this.members.length = 0;
- }
- this._sortIndex = null;
- };
- Group.prototype.update = /**
- * Automatically goes through and calls update on everything you added.
- */
- function () {
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if((basic != null) && basic.exists && basic.active) {
- basic.preUpdate();
- basic.update();
- basic.postUpdate();
- }
- }
- };
- Group.prototype.render = /**
- * Automatically goes through and calls render on everything you added.
- */
- function (camera, cameraOffsetX, cameraOffsetY) {
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if((basic != null) && basic.exists && basic.visible) {
- basic.render(camera, cameraOffsetX, cameraOffsetY);
- }
- }
- };
- Object.defineProperty(Group.prototype, "maxSize", {
- get: /**
- * The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow.
- */
- function () {
- return this._maxSize;
- },
- set: /**
- * @private
- */
- function (Size) {
- this._maxSize = Size;
- if(this._marker >= this._maxSize) {
- this._marker = 0;
- }
- if((this._maxSize == 0) || (this.members == null) || (this._maxSize >= this.members.length)) {
- return;
- }
- //If the max size has shrunk, we need to get rid of some objects
- var basic;
- var i = this._maxSize;
- var l = this.members.length;
- while(i < l) {
- basic = this.members[i++];
- if(basic != null) {
- basic.destroy();
- }
- }
- this.length = this.members.length = this._maxSize;
- },
- enumerable: true,
- configurable: true
- });
- Group.prototype.add = /**
- * Adds a new Basic subclass (Basic, FlxBasic, Enemy, etc) to the group.
- * Group will try to replace a null member of the array first.
- * Failing that, Group will add it to the end of the member array,
- * assuming there is room for it, and doubling the size of the array if necessary.
- *
- * WARNING: If the group has a maxSize that has already been met, - * the object will NOT be added to the group!
- * - * @param Object The object you want to add to the group. - * - * @return The sameBasic object that was passed in.
- */
- function (Object) {
- //Don't bother adding an object twice.
- if(this.members.indexOf(Object) >= 0) {
- return Object;
- }
- //First, look for a null entry where we can add the object.
- var i = 0;
- var l = this.members.length;
- while(i < l) {
- if(this.members[i] == null) {
- this.members[i] = Object;
- if(i >= this.length) {
- this.length = i + 1;
- }
- return Object;
- }
- i++;
- }
- //Failing that, expand the array (if we can) and add the object.
- if(this._maxSize > 0) {
- if(this.members.length >= this._maxSize) {
- return Object;
- } else if(this.members.length * 2 <= this._maxSize) {
- this.members.length *= 2;
- } else {
- this.members.length = this._maxSize;
- }
- } else {
- this.members.length *= 2;
- }
- //If we made it this far, then we successfully grew the group,
- //and we can go ahead and add the object at the first open slot.
- this.members[i] = Object;
- this.length = i + 1;
- return Object;
- };
- Group.prototype.recycle = /**
- * Recycling is designed to help you reuse game objects without always re-allocating or "newing" them.
- *
- * If you specified a maximum size for this group (like in Emitter), - * then recycle will employ what we're calling "rotating" recycling. - * Recycle() will first check to see if the group is at capacity yet. - * If group is not yet at capacity, recycle() returns a new object. - * If the group IS at capacity, then recycle() just returns the next object in line.
- * - *If you did NOT specify a maximum size for this group, - * then recycle() will employ what we're calling "grow-style" recycling. - * Recycle() will return either the first object with exists == false, - * or, finding none, add a new object to the array, - * doubling the size of the array if necessary.
- * - *WARNING: If this function needs to create a new object, - * and no object class was provided, it will return null - * instead of a valid object!
- * - * @param ObjectClass The class type you want to recycle (e.g. FlxBasic, EvilRobot, etc). Do NOT "new" the class in the parameter! - * - * @return A reference to the object that was created. Don't forget to cast it back to the Class you want (e.g. myObject = myGroup.recycle(myObjectClass) as myObjectClass;). - */ - function (ObjectClass) { - if (typeof ObjectClass === "undefined") { ObjectClass = null; } - var basic; - if(this._maxSize > 0) { - if(this.length < this._maxSize) { - if(ObjectClass == null) { - return null; - } - return this.add(new ObjectClass()); - } else { - basic = this.members[this._marker++]; - if(this._marker >= this._maxSize) { - this._marker = 0; - } - return basic; - } - } else { - basic = this.getFirstAvailable(ObjectClass); - if(basic != null) { - return basic; - } - if(ObjectClass == null) { - return null; - } - return this.add(new ObjectClass()); - } - }; - Group.prototype.remove = /** - * Removes an object from the group. - * - * @param Object TheBasic you want to remove.
- * @param Splice Whether the object should be cut from the array entirely or not.
- *
- * @return The removed object.
- */
- function (Object, Splice) {
- if (typeof Splice === "undefined") { Splice = false; }
- var index = this.members.indexOf(Object);
- if((index < 0) || (index >= this.members.length)) {
- return null;
- }
- if(Splice) {
- this.members.splice(index, 1);
- this.length--;
- } else {
- this.members[index] = null;
- }
- return Object;
- };
- Group.prototype.replace = /**
- * Replaces an existing Basic with a new one.
- *
- * @param OldObject The object you want to replace.
- * @param NewObject The new object you want to use instead.
- *
- * @return The new object.
- */
- function (OldObject, NewObject) {
- var index = this.members.indexOf(OldObject);
- if((index < 0) || (index >= this.members.length)) {
- return null;
- }
- this.members[index] = NewObject;
- return NewObject;
- };
- Group.prototype.sort = /**
- * Call this function to sort the group according to a particular value and order.
- * For example, to sort game objects for Zelda-style overlaps you might call
- * myGroup.sort("y",Group.ASCENDING) at the bottom of your
- * FlxState.update() override. To sort all existing objects after
- * a big explosion or bomb attack, you might call myGroup.sort("exists",Group.DESCENDING).
- *
- * @param Index The string name of the member variable you want to sort on. Default value is "y".
- * @param Order A Group constant that defines the sort order. Possible values are Group.ASCENDING and Group.DESCENDING. Default value is Group.ASCENDING.
- */
- function (Index, Order) {
- if (typeof Index === "undefined") { Index = "y"; }
- if (typeof Order === "undefined") { Order = Group.ASCENDING; }
- this._sortIndex = Index;
- this._sortOrder = Order;
- this.members.sort(this.sortHandler);
- };
- Group.prototype.setAll = /**
- * Go through and set the specified variable to the specified value on all members of the group.
- *
- * @param VariableName The string representation of the variable name you want to modify, for example "visible" or "scrollFactor".
- * @param Value The value you want to assign to that variable.
- * @param Recurse Default value is true, meaning if setAll() encounters a member that is a group, it will call setAll() on that group rather than modifying its variable.
- */
- function (VariableName, Value, Recurse) {
- if (typeof Recurse === "undefined") { Recurse = true; }
- var basic;
- var i = 0;
- while(i < length) {
- basic = this.members[i++];
- if(basic != null) {
- if(Recurse && (basic.isGroup == true)) {
- basic['setAll'](VariableName, Value, Recurse);
- } else {
- basic[VariableName] = Value;
- }
- }
- }
- };
- Group.prototype.callAll = /**
- * Go through and call the specified function on all members of the group.
- * Currently only works on functions that have no required parameters.
- *
- * @param FunctionName The string representation of the function you want to call on each object, for example "kill()" or "init()".
- * @param Recurse Default value is true, meaning if callAll() encounters a member that is a group, it will call callAll() on that group rather than calling the group's function.
- */
- function (FunctionName, Recurse) {
- if (typeof Recurse === "undefined") { Recurse = true; }
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if(basic != null) {
- if(Recurse && (basic.isGroup == true)) {
- basic['callAll'](FunctionName, Recurse);
- } else {
- basic[FunctionName]();
- }
- }
- }
- };
- Group.prototype.forEach = function (callback, Recurse) {
- if (typeof Recurse === "undefined") { Recurse = false; }
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if(basic != null) {
- if(Recurse && (basic.isGroup == true)) {
- basic.forEach(callback, true);
- } else {
- callback.call(this, basic);
- }
- }
- }
- };
- Group.prototype.getFirstAvailable = /**
- * Call this function to retrieve the first object with exists == false in the group.
- * This is handy for recycling in general, e.g. respawning enemies.
- *
- * @param ObjectClass An optional parameter that lets you narrow the results to instances of this particular class.
- *
- * @return A Basic currently flagged as not existing.
- */
- function (ObjectClass) {
- if (typeof ObjectClass === "undefined") { ObjectClass = null; }
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if((basic != null) && !basic.exists && ((ObjectClass == null) || (typeof basic === ObjectClass))) {
- return basic;
- }
- }
- return null;
- };
- Group.prototype.getFirstNull = /**
- * Call this function to retrieve the first index set to 'null'.
- * Returns -1 if no index stores a null object.
- *
- * @return An int indicating the first null slot in the group.
- */
- function () {
- var basic;
- var i = 0;
- var l = this.members.length;
- while(i < l) {
- if(this.members[i] == null) {
- return i;
- } else {
- i++;
- }
- }
- return -1;
- };
- Group.prototype.getFirstExtant = /**
- * Call this function to retrieve the first object with exists == true in the group.
- * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
- *
- * @return A Basic currently flagged as existing.
- */
- function () {
- var basic;
- var i = 0;
- while(i < length) {
- basic = this.members[i++];
- if((basic != null) && basic.exists) {
- return basic;
- }
- }
- return null;
- };
- Group.prototype.getFirstAlive = /**
- * Call this function to retrieve the first object with dead == false in the group.
- * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
- *
- * @return A Basic currently flagged as not dead.
- */
- function () {
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if((basic != null) && basic.exists && basic.alive) {
- return basic;
- }
- }
- return null;
- };
- Group.prototype.getFirstDead = /**
- * Call this function to retrieve the first object with dead == true in the group.
- * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
- *
- * @return A Basic currently flagged as dead.
- */
- function () {
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if((basic != null) && !basic.alive) {
- return basic;
- }
- }
- return null;
- };
- Group.prototype.countLiving = /**
- * Call this function to find out how many members of the group are not dead.
- *
- * @return The number of Basics flagged as not dead. Returns -1 if group is empty.
- */
- function () {
- var count = -1;
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if(basic != null) {
- if(count < 0) {
- count = 0;
- }
- if(basic.exists && basic.alive) {
- count++;
- }
- }
- }
- return count;
- };
- Group.prototype.countDead = /**
- * Call this function to find out how many members of the group are dead.
- *
- * @return The number of Basics flagged as dead. Returns -1 if group is empty.
- */
- function () {
- var count = -1;
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if(basic != null) {
- if(count < 0) {
- count = 0;
- }
- if(!basic.alive) {
- count++;
- }
- }
- }
- return count;
- };
- Group.prototype.getRandom = /**
- * Returns a member at random from the group.
- *
- * @param StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
- * @param Length Optional restriction on the number of values you want to randomly select from.
- *
- * @return A Basic from the members list.
- */
- function (StartIndex, Length) {
- if (typeof StartIndex === "undefined") { StartIndex = 0; }
- if (typeof Length === "undefined") { Length = 0; }
- if(Length == 0) {
- Length = this.length;
- }
- return this._game.math.getRandom(this.members, StartIndex, Length);
- };
- Group.prototype.clear = /**
- * Remove all instances of Basic subclass (FlxBasic, FlxBlock, etc) from the list.
- * WARNING: does not destroy() or kill() any of these objects!
- */
- function () {
- this.length = this.members.length = 0;
- };
- Group.prototype.kill = /**
- * Calls kill on the group's members and then on the group itself.
- */
- function () {
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if((basic != null) && basic.exists) {
- basic.kill();
- }
- }
- };
- Group.prototype.sortHandler = /**
- * Helper function for the sort process.
- *
- * @param Obj1 The first object being sorted.
- * @param Obj2 The second object being sorted.
- *
- * @return An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
- */
- function (Obj1, Obj2) {
- if(Obj1[this._sortIndex] < Obj2[this._sortIndex]) {
- return this._sortOrder;
- } else if(Obj1[this._sortIndex] > Obj2[this._sortIndex]) {
- return -this._sortOrder;
- }
- return 0;
- };
- return Group;
-})(Basic);
-/// Sprite to have slightly more specialized behavior
-* common to many game scenarios. You can override and extend this class
-* just like you would Sprite. While Emitter
-* used to work with just any old sprite, it now requires a
-* Particle based class.
-*
-* @author Adam Atomic
-* @author Richard Davey
-*/
-var Particle = (function (_super) {
- __extends(Particle, _super);
- /**
- * Instantiate a new particle. Like Sprite, all meaningful creation
- * happens during loadGraphic() or makeGraphic() or whatever.
- */
- function Particle(game) {
- _super.call(this, game);
- this.lifespan = 0;
- this.friction = 500;
- }
- Particle.prototype.update = /**
- * 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.
- */
- function () {
- //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;
- }
- }
- };
- Particle.prototype.onEmit = /**
- * Triggered whenever this object is launched by a Emitter.
- * You can override this to add custom behavior like a sound or AI or something.
- */
- function () {
- };
- return Particle;
-})(Sprite);
-/// Emitter is a lightweight particle emitter.
-* It can be used for one-time explosions or for
-* continuous fx like rain and fire. Emitter
-* is not optimized or anything; all it does is launch
-* Particle objects out at set intervals
-* by setting their positions and velocities accordingly.
-* It is easy to use and relatively efficient,
-* relying on Group's RECYCLE POWERS.
-*
-* @author Adam Atomic
-* @author Richard Davey
-*/
-var Emitter = (function (_super) {
- __extends(Emitter, _super);
- /**
- * Creates a new FlxEmitter 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.
- */
- function Emitter(game, X, Y, Size) {
- if (typeof X === "undefined") { X = 0; }
- if (typeof Y === "undefined") { Y = 0; }
- if (typeof Size === "undefined") { Size = 0; }
- _super.call(this, 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();
- }
- Emitter.prototype.destroy = /**
- * Clean up memory.
- */
- function () {
- this.minParticleSpeed = null;
- this.maxParticleSpeed = null;
- this.particleDrag = null;
- this.particleClass = null;
- this._point = null;
- _super.prototype.destroy.call(this);
- };
- Emitter.prototype.makeParticles = /**
- * 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).
- */
- function (Graphics, Quantity, BakedRotations, Multiple, Collide) {
- if (typeof Quantity === "undefined") { Quantity = 50; }
- if (typeof BakedRotations === "undefined") { BakedRotations = 16; }
- if (typeof Multiple === "undefined") { Multiple = false; }
- if (typeof Collide === "undefined") { Collide = 0.8; }
- this.maxSize = Quantity;
- var totalFrames = 1;
- /*
- if(Multiple)
- {
- var sprite:Sprite = new Sprite(this._game);
- sprite.loadGraphic(Graphics,true);
- totalFrames = sprite.frames;
- sprite.destroy();
- }
- */
- var randomFrame;
- var particle;
- var i = 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;
- };
- Emitter.prototype.update = /**
- * Called automatically by the game loop, decides when to launch particles and when to "die".
- */
- function () {
- if(this.on) {
- if(this._explode) {
- this.on = false;
- var i = 0;
- var l = 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.prototype.update.call(this);
- };
- Emitter.prototype.kill = /**
- * Call this function to turn off all the particles and the emitter.
- */
- function () {
- this.on = false;
- _super.prototype.kill.call(this);
- };
- Emitter.prototype.start = /**
- * 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".
- */
- function (Explode, Lifespan, Frequency, Quantity) {
- if (typeof Explode === "undefined") { Explode = true; }
- if (typeof Lifespan === "undefined") { Lifespan = 0; }
- if (typeof Frequency === "undefined") { Frequency = 0.1; }
- if (typeof Quantity === "undefined") { Quantity = 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;
- };
- Emitter.prototype.emitParticle = /**
- * This function can be used both internally and externally to emit the next particle.
- */
- function () {
- var 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();
- };
- Emitter.prototype.setSize = /**
- * 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.
- */
- function (Width, Height) {
- this.width = Width;
- this.height = Height;
- };
- Emitter.prototype.setXSpeed = /**
- * 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.
- */
- function (Min, Max) {
- if (typeof Min === "undefined") { Min = 0; }
- if (typeof Max === "undefined") { Max = 0; }
- this.minParticleSpeed.x = Min;
- this.maxParticleSpeed.x = Max;
- };
- Emitter.prototype.setYSpeed = /**
- * 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.
- */
- function (Min, Max) {
- if (typeof Min === "undefined") { Min = 0; }
- if (typeof Max === "undefined") { Max = 0; }
- this.minParticleSpeed.y = Min;
- this.maxParticleSpeed.y = Max;
- };
- Emitter.prototype.setRotation = /**
- * 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.
- */
- function (Min, Max) {
- if (typeof Min === "undefined") { Min = 0; }
- if (typeof Max === "undefined") { Max = 0; }
- this.minRotation = Min;
- this.maxRotation = Max;
- };
- Emitter.prototype.at = /**
- * Change the emitter's midpoint to match the midpoint of a FlxObject.
- *
- * @param Object The FlxObject that you want to sync up with.
- */
- function (Object) {
- Object.getMidpoint(this._point);
- this.x = this._point.x - (this.width >> 1);
- this.y = this._point.y - (this.height >> 1);
- };
- return Emitter;
-})(Group);
-/// QuadTree for how to use it, IF YOU DARE.
-*/
-var LinkedList = (function () {
- /**
- * Creates a new link, and sets object and next to null.
- */
- function LinkedList() {
- this.object = null;
- this.next = null;
- }
- LinkedList.prototype.destroy = /**
- * Clean up memory.
- */
- function () {
- this.object = null;
- if(this.next != null) {
- this.next.destroy();
- }
- this.next = null;
- };
- return LinkedList;
-})();
-/// myFunction(Object1:GameObject,Object2:GameObject) that is called whenever two objects are found to overlap in world space, and either no ProcessCallback is specified, or the ProcessCallback returns true.
- * @param ProcessCallback A function with the form myFunction(Object1:GameObject,Object2:GameObject):bool that is called whenever two objects are found to overlap in world space. The NotifyCallback is only called if this function returns true. See GameObject.separate().
- */
- function (ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, ProcessCallback) {
- if (typeof ObjectOrGroup2 === "undefined") { ObjectOrGroup2 = null; }
- if (typeof NotifyCallback === "undefined") { NotifyCallback = null; }
- if (typeof ProcessCallback === "undefined") { ProcessCallback = null; }
- //console.log('quadtree load', QuadTree.divisions, ObjectOrGroup1, ObjectOrGroup2);
- this.add(ObjectOrGroup1, QuadTree.A_LIST);
- if(ObjectOrGroup2 != null) {
- this.add(ObjectOrGroup2, QuadTree.B_LIST);
- QuadTree._useBothLists = true;
- } else {
- QuadTree._useBothLists = false;
- }
- QuadTree._notifyCallback = NotifyCallback;
- QuadTree._processingCallback = ProcessCallback;
- //console.log('use both', QuadTree._useBothLists);
- //console.log('------------ end of load');
- };
- QuadTree.prototype.add = /**
- * Call this function to add an object to the root of the tree.
- * This function will recursively add all group members, but
- * not the groups themselves.
- *
- * @param ObjectOrGroup GameObjects are just added, Groups are recursed and their applicable members added accordingly.
- * @param List A uint flag indicating the list to which you want to add the objects. Options are QuadTree.A_LIST and QuadTree.B_LIST.
- */
- function (ObjectOrGroup, List) {
- QuadTree._list = List;
- if(ObjectOrGroup.isGroup == true) {
- var i = 0;
- var basic;
- var members = ObjectOrGroup['members'];
- var l = ObjectOrGroup['length'];
- while(i < l) {
- basic = members[i++];
- if((basic != null) && basic.exists) {
- if(basic.isGroup) {
- this.add(basic, List);
- } else {
- QuadTree._object = basic;
- if(QuadTree._object.exists && QuadTree._object.allowCollisions) {
- QuadTree._objectLeftEdge = QuadTree._object.x;
- QuadTree._objectTopEdge = QuadTree._object.y;
- QuadTree._objectRightEdge = QuadTree._object.x + QuadTree._object.width;
- QuadTree._objectBottomEdge = QuadTree._object.y + QuadTree._object.height;
- this.addObject();
- }
- }
- }
- }
- } else {
- QuadTree._object = ObjectOrGroup;
- //console.log('add - not group:', ObjectOrGroup.name);
- if(QuadTree._object.exists && QuadTree._object.allowCollisions) {
- QuadTree._objectLeftEdge = QuadTree._object.x;
- QuadTree._objectTopEdge = QuadTree._object.y;
- QuadTree._objectRightEdge = QuadTree._object.x + QuadTree._object.width;
- QuadTree._objectBottomEdge = QuadTree._object.y + QuadTree._object.height;
- //console.log('object properties', QuadTree._objectLeftEdge, QuadTree._objectTopEdge, QuadTree._objectRightEdge, QuadTree._objectBottomEdge);
- this.addObject();
- }
- }
- };
- QuadTree.prototype.addObject = /**
- * Internal function for recursively navigating and creating the tree
- * while adding objects to the appropriate nodes.
- */
- function () {
- //console.log('addObject');
- //If this quad (not its children) lies entirely inside this object, add it here
- if(!this._canSubdivide || ((this._leftEdge >= QuadTree._objectLeftEdge) && (this._rightEdge <= QuadTree._objectRightEdge) && (this._topEdge >= QuadTree._objectTopEdge) && (this._bottomEdge <= QuadTree._objectBottomEdge))) {
- //console.log('add To List');
- this.addToList();
- return;
- }
- //See if the selected object fits completely inside any of the quadrants
- if((QuadTree._objectLeftEdge > this._leftEdge) && (QuadTree._objectRightEdge < this._midpointX)) {
- if((QuadTree._objectTopEdge > this._topEdge) && (QuadTree._objectBottomEdge < this._midpointY)) {
- //console.log('Adding NW tree');
- if(this._northWestTree == null) {
- this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
- }
- this._northWestTree.addObject();
- return;
- }
- if((QuadTree._objectTopEdge > this._midpointY) && (QuadTree._objectBottomEdge < this._bottomEdge)) {
- //console.log('Adding SW tree');
- if(this._southWestTree == null) {
- this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
- }
- this._southWestTree.addObject();
- return;
- }
- }
- if((QuadTree._objectLeftEdge > this._midpointX) && (QuadTree._objectRightEdge < this._rightEdge)) {
- if((QuadTree._objectTopEdge > this._topEdge) && (QuadTree._objectBottomEdge < this._midpointY)) {
- //console.log('Adding NE tree');
- if(this._northEastTree == null) {
- this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
- }
- this._northEastTree.addObject();
- return;
- }
- if((QuadTree._objectTopEdge > this._midpointY) && (QuadTree._objectBottomEdge < this._bottomEdge)) {
- //console.log('Adding SE tree');
- if(this._southEastTree == null) {
- this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
- }
- this._southEastTree.addObject();
- return;
- }
- }
- //If it wasn't completely contained we have to check out the partial overlaps
- if((QuadTree._objectRightEdge > this._leftEdge) && (QuadTree._objectLeftEdge < this._midpointX) && (QuadTree._objectBottomEdge > this._topEdge) && (QuadTree._objectTopEdge < this._midpointY)) {
- if(this._northWestTree == null) {
- this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
- }
- //console.log('added to north west partial tree');
- this._northWestTree.addObject();
- }
- if((QuadTree._objectRightEdge > this._midpointX) && (QuadTree._objectLeftEdge < this._rightEdge) && (QuadTree._objectBottomEdge > this._topEdge) && (QuadTree._objectTopEdge < this._midpointY)) {
- if(this._northEastTree == null) {
- this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
- }
- //console.log('added to north east partial tree');
- this._northEastTree.addObject();
- }
- if((QuadTree._objectRightEdge > this._midpointX) && (QuadTree._objectLeftEdge < this._rightEdge) && (QuadTree._objectBottomEdge > this._midpointY) && (QuadTree._objectTopEdge < this._bottomEdge)) {
- if(this._southEastTree == null) {
- this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
- }
- //console.log('added to south east partial tree');
- this._southEastTree.addObject();
- }
- if((QuadTree._objectRightEdge > this._leftEdge) && (QuadTree._objectLeftEdge < this._midpointX) && (QuadTree._objectBottomEdge > this._midpointY) && (QuadTree._objectTopEdge < this._bottomEdge)) {
- if(this._southWestTree == null) {
- this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
- }
- //console.log('added to south west partial tree');
- this._southWestTree.addObject();
- }
- };
- QuadTree.prototype.addToList = /**
- * Internal function for recursively adding objects to leaf lists.
- */
- function () {
- //console.log('Adding to List');
- var ot;
- if(QuadTree._list == QuadTree.A_LIST) {
- //console.log('A LIST');
- if(this._tailA.object != null) {
- ot = this._tailA;
- this._tailA = new LinkedList();
- ot.next = this._tailA;
- }
- this._tailA.object = QuadTree._object;
- } else {
- //console.log('B LIST');
- if(this._tailB.object != null) {
- ot = this._tailB;
- this._tailB = new LinkedList();
- ot.next = this._tailB;
- }
- this._tailB.object = QuadTree._object;
- }
- if(!this._canSubdivide) {
- return;
- }
- if(this._northWestTree != null) {
- this._northWestTree.addToList();
- }
- if(this._northEastTree != null) {
- this._northEastTree.addToList();
- }
- if(this._southEastTree != null) {
- this._southEastTree.addToList();
- }
- if(this._southWestTree != null) {
- this._southWestTree.addToList();
- }
- };
- QuadTree.prototype.execute = /**
- * QuadTree's other main function. Call this after adding objects
- * using QuadTree.load() to compare the objects that you loaded.
- *
- * @return Whether or not any overlaps were found.
- */
- function () {
- //console.log('quadtree execute');
- var overlapProcessed = false;
- var iterator;
- if(this._headA.object != null) {
- //console.log('---------------------------------------------------');
- //console.log('headA iterator');
- iterator = this._headA;
- while(iterator != null) {
- QuadTree._object = iterator.object;
- if(QuadTree._useBothLists) {
- QuadTree._iterator = this._headB;
- } else {
- QuadTree._iterator = iterator.next;
- }
- if(QuadTree._object.exists && (QuadTree._object.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode()) {
- //console.log('headA iterator overlapped true');
- overlapProcessed = true;
- }
- iterator = iterator.next;
- }
- }
- //Advance through the tree by calling overlap on each child
- if((this._northWestTree != null) && this._northWestTree.execute()) {
- //console.log('NW quadtree execute');
- overlapProcessed = true;
- }
- if((this._northEastTree != null) && this._northEastTree.execute()) {
- //console.log('NE quadtree execute');
- overlapProcessed = true;
- }
- if((this._southEastTree != null) && this._southEastTree.execute()) {
- //console.log('SE quadtree execute');
- overlapProcessed = true;
- }
- if((this._southWestTree != null) && this._southWestTree.execute()) {
- //console.log('SW quadtree execute');
- overlapProcessed = true;
- }
- return overlapProcessed;
- };
- QuadTree.prototype.overlapNode = /**
- * An private for comparing an object against the contents of a node.
- *
- * @return Whether or not any overlaps were found.
- */
- function () {
- //console.log('overlapNode');
- //Walk the list and check for overlaps
- var overlapProcessed = false;
- var checkObject;
- while(QuadTree._iterator != null) {
- if(!QuadTree._object.exists || (QuadTree._object.allowCollisions <= 0)) {
- //console.log('break 1');
- break;
- }
- checkObject = QuadTree._iterator.object;
- if((QuadTree._object === checkObject) || !checkObject.exists || (checkObject.allowCollisions <= 0)) {
- //console.log('break 2');
- QuadTree._iterator = QuadTree._iterator.next;
- continue;
- }
- //calculate bulk hull for QuadTree._object
- QuadTree._objectHullX = (QuadTree._object.x < QuadTree._object.last.x) ? QuadTree._object.x : QuadTree._object.last.x;
- QuadTree._objectHullY = (QuadTree._object.y < QuadTree._object.last.y) ? QuadTree._object.y : QuadTree._object.last.y;
- QuadTree._objectHullWidth = QuadTree._object.x - QuadTree._object.last.x;
- QuadTree._objectHullWidth = QuadTree._object.width + ((QuadTree._objectHullWidth > 0) ? QuadTree._objectHullWidth : -QuadTree._objectHullWidth);
- QuadTree._objectHullHeight = QuadTree._object.y - QuadTree._object.last.y;
- QuadTree._objectHullHeight = QuadTree._object.height + ((QuadTree._objectHullHeight > 0) ? QuadTree._objectHullHeight : -QuadTree._objectHullHeight);
- //calculate bulk hull for checkObject
- QuadTree._checkObjectHullX = (checkObject.x < checkObject.last.x) ? checkObject.x : checkObject.last.x;
- QuadTree._checkObjectHullY = (checkObject.y < checkObject.last.y) ? checkObject.y : checkObject.last.y;
- QuadTree._checkObjectHullWidth = checkObject.x - checkObject.last.x;
- QuadTree._checkObjectHullWidth = checkObject.width + ((QuadTree._checkObjectHullWidth > 0) ? QuadTree._checkObjectHullWidth : -QuadTree._checkObjectHullWidth);
- QuadTree._checkObjectHullHeight = checkObject.y - checkObject.last.y;
- QuadTree._checkObjectHullHeight = checkObject.height + ((QuadTree._checkObjectHullHeight > 0) ? QuadTree._checkObjectHullHeight : -QuadTree._checkObjectHullHeight);
- //check for intersection of the two hulls
- if((QuadTree._objectHullX + QuadTree._objectHullWidth > QuadTree._checkObjectHullX) && (QuadTree._objectHullX < QuadTree._checkObjectHullX + QuadTree._checkObjectHullWidth) && (QuadTree._objectHullY + QuadTree._objectHullHeight > QuadTree._checkObjectHullY) && (QuadTree._objectHullY < QuadTree._checkObjectHullY + QuadTree._checkObjectHullHeight)) {
- //console.log('intersection!');
- //Execute callback functions if they exist
- if((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, checkObject)) {
- overlapProcessed = true;
- }
- if(overlapProcessed && (QuadTree._notifyCallback != null)) {
- QuadTree._notifyCallback(QuadTree._object, checkObject);
- }
- }
- QuadTree._iterator = QuadTree._iterator.next;
- }
- return overlapProcessed;
- };
- return QuadTree;
-})(Rectangle);
-/// GameObject 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 FlxGroup (or even bundling groups together!).
- *
- * NOTE: does NOT take objects' scrollfactor into account, all overlaps are checked in world space.
- * - * @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 twoGameObject parameters - e.g. myOverlapFunction(Object1:GameObject,Object2:GameObject) - that is called if those two objects overlap.
- * @param ProcessCallback A function with two GameObject parameters - e.g. myOverlapFunction(Object1:GameObject,Object2:GameObject) - 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.
- */
- function (ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, ProcessCallback) {
- if (typeof ObjectOrGroup1 === "undefined") { ObjectOrGroup1 = null; }
- if (typeof ObjectOrGroup2 === "undefined") { ObjectOrGroup2 = null; }
- if (typeof NotifyCallback === "undefined") { NotifyCallback = null; }
- if (typeof ProcessCallback === "undefined") { ProcessCallback = null; }
- if(ObjectOrGroup1 == null) {
- ObjectOrGroup1 = this.group;
- }
- if(ObjectOrGroup2 == ObjectOrGroup1) {
- ObjectOrGroup2 = null;
- }
- QuadTree.divisions = this.worldDivisions;
- var quadTree = new QuadTree(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
- quadTree.load(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, ProcessCallback);
- var result = quadTree.execute();
- quadTree.destroy();
- quadTree = null;
- return result;
- };
- World.separate = /**
- * The main collision resolution in flixel.
- *
- * @param Object1 Any Sprite.
- * @param Object2 Any other Sprite.
- *
- * @return Whether the objects in fact touched and were separated.
- */
- function separate(Object1, Object2) {
- var separatedX = World.separateX(Object1, Object2);
- var separatedY = World.separateY(Object1, Object2);
- return separatedX || separatedY;
- };
- World.separateX = /**
- * The X-axis component of the object separation process.
- *
- * @param Object1 Any Sprite.
- * @param Object2 Any other Sprite.
- *
- * @return Whether the objects in fact touched and were separated along the X axis.
- */
- function separateX(Object1, Object2) {
- //can't separate two immovable objects
- var obj1immovable = Object1.immovable;
- var obj2immovable = 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 = 0;
- var obj1delta = Object1.x - Object1.last.x;
- var obj2delta = Object2.x - Object2.last.x;
- if(obj1delta != obj2delta) {
- //Check if the X hulls actually overlap
- var obj1deltaAbs = (obj1delta > 0) ? obj1delta : -obj1delta;
- var obj2deltaAbs = (obj2delta > 0) ? obj2delta : -obj2delta;
- var obj1rect = new Rectangle(Object1.x - ((obj1delta > 0) ? obj1delta : 0), Object1.last.y, Object1.width + ((obj1delta > 0) ? obj1delta : -obj1delta), Object1.height);
- var obj2rect = 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 = 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 = Object1.velocity.x;
- var obj2v = Object2.velocity.x;
- if(!obj1immovable && !obj2immovable) {
- overlap *= 0.5;
- Object1.x = Object1.x - overlap;
- Object2.x += overlap;
- var obj1velocity = Math.sqrt((obj2v * obj2v * Object2.mass) / Object1.mass) * ((obj2v > 0) ? 1 : -1);
- var obj2velocity = Math.sqrt((obj1v * obj1v * Object1.mass) / Object2.mass) * ((obj1v > 0) ? 1 : -1);
- var average = (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;
- }
- };
- World.separateY = /**
- * The Y-axis component of the object separation process.
- *
- * @param Object1 Any Sprite.
- * @param Object2 Any other Sprite.
- *
- * @return Whether the objects in fact touched and were separated along the Y axis.
- */
- function separateY(Object1, Object2) {
- //can't separate two immovable objects
- var obj1immovable = Object1.immovable;
- var obj2immovable = 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 = 0;
- var obj1delta = Object1.y - Object1.last.y;
- var obj2delta = Object2.y - Object2.last.y;
- if(obj1delta != obj2delta) {
- //Check if the Y hulls actually overlap
- var obj1deltaAbs = (obj1delta > 0) ? obj1delta : -obj1delta;
- var obj2deltaAbs = (obj2delta > 0) ? obj2delta : -obj2delta;
- var obj1rect = new Rectangle(Object1.x, Object1.y - ((obj1delta > 0) ? obj1delta : 0), Object1.width, Object1.height + obj1deltaAbs);
- var obj2rect = 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 = 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 = Object1.velocity.y;
- var obj2v = Object2.velocity.y;
- if(!obj1immovable && !obj2immovable) {
- overlap *= 0.5;
- Object1.y = Object1.y - overlap;
- Object2.y += overlap;
- var obj1velocity = Math.sqrt((obj2v * obj2v * Object2.mass) / Object1.mass) * ((obj2v > 0) ? 1 : -1);
- var obj2velocity = Math.sqrt((obj1v * obj1v * Object1.mass) / Object2.mass) * ((obj1v > 0) ? 1 : -1);
- var average = (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;
- }
- };
- return World;
-})();
-/// If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.
- * @param {Array} [paramsArr] Array of parameters that should be passed to the listener - * @return {*} Value returned by the listener. - */ - function (paramsArr) { - var handlerReturn; - var params; - if(this.active && !!this._listener) { - params = this.params ? this.params.concat(paramsArr) : paramsArr; - handlerReturn = this._listener.apply(this.context, params); - if(this._isOnce) { - this.detach(); - } - } - return handlerReturn; - }; - SignalBinding.prototype.detach = /** - * Detach binding from signal. - * - alias to: mySignal.remove(myBinding.getListener()); - * @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached. - */ - function () { - return this.isBound() ? this._signal.remove(this._listener, this.context) : null; - }; - SignalBinding.prototype.isBound = /** - * @return {Boolean} `true` if binding is still bound to the signal and have a listener. - */ - function () { - return (!!this._signal && !!this._listener); - }; - SignalBinding.prototype.isOnce = /** - * @return {boolean} If SignalBinding will only be executed once. - */ - function () { - return this._isOnce; - }; - SignalBinding.prototype.getListener = /** - * @return {Function} Handler function bound to the signal. - */ - function () { - return this._listener; - }; - SignalBinding.prototype.getSignal = /** - * @return {Signal} Signal that listener is currently bound to. - */ - function () { - return this._signal; - }; - SignalBinding.prototype._destroy = /** - * Delete instance properties - * @private - */ - function () { - delete this._signal; - delete this._listener; - delete this.context; - }; - SignalBinding.prototype.toString = /** - * @return {string} String representation of the object. - */ - function () { - return '[SignalBinding isOnce:' + this._isOnce + ', isBound:' + this.isBound() + ', active:' + this.active + ']'; - }; - return SignalBinding; -})(); -///IMPORTANT: Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.
- * @type boolean - */ - this.active = true; - } - Signal.VERSION = '1.0.0'; - Signal.prototype.validateListener = /** - * - * @method validateListener - * @param {Any} listener - * @param {Any} fnName - */ - function (listener, fnName) { - if(typeof listener !== 'function') { - throw new Error('listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName)); - } - }; - Signal.prototype._registerListener = /** - * @param {Function} listener - * @param {boolean} isOnce - * @param {Object} [listenerContext] - * @param {Number} [priority] - * @return {SignalBinding} - * @private - */ - function (listener, isOnce, listenerContext, priority) { - var prevIndex = this._indexOfListener(listener, listenerContext); - var binding; - if(prevIndex !== -1) { - binding = this._bindings[prevIndex]; - if(binding.isOnce() !== isOnce) { - throw new Error('You cannot add' + (isOnce ? '' : 'Once') + '() then add' + (!isOnce ? '' : 'Once') + '() the same listener without removing the relationship first.'); - } - } else { - binding = new SignalBinding(this, listener, isOnce, listenerContext, priority); - this._addBinding(binding); - } - if(this.memorize && this._prevParams) { - binding.execute(this._prevParams); - } - return binding; - }; - Signal.prototype._addBinding = /** - * - * @method _addBinding - * @param {SignalBinding} binding - * @private - */ - function (binding) { - //simplified insertion sort - var n = this._bindings.length; - do { - --n; - }while(this._bindings[n] && binding.priority <= this._bindings[n].priority); - this._bindings.splice(n + 1, 0, binding); - }; - Signal.prototype._indexOfListener = /** - * - * @method _indexOfListener - * @param {Function} listener - * @return {number} - * @private - */ - function (listener, context) { - var n = this._bindings.length; - var cur; - while(n--) { - cur = this._bindings[n]; - if(cur.getListener() === listener && cur.context === context) { - return n; - } - } - return -1; - }; - Signal.prototype.has = /** - * Check if listener was attached to Signal. - * @param {Function} listener - * @param {Object} [context] - * @return {boolean} if Signal has the specified listener. - */ - function (listener, context) { - if (typeof context === "undefined") { context = null; } - return this._indexOfListener(listener, context) !== -1; - }; - Signal.prototype.add = /** - * Add a listener to the signal. - * @param {Function} listener Signal handler function. - * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). - * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) - * @return {SignalBinding} An Object representing the binding between the Signal and listener. - */ - function (listener, listenerContext, priority) { - if (typeof listenerContext === "undefined") { listenerContext = null; } - if (typeof priority === "undefined") { priority = 0; } - this.validateListener(listener, 'add'); - return this._registerListener(listener, false, listenerContext, priority); - }; - Signal.prototype.addOnce = /** - * Add listener to the signal that should be removed after first execution (will be executed only once). - * @param {Function} listener Signal handler function. - * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). - * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) - * @return {SignalBinding} An Object representing the binding between the Signal and listener. - */ - function (listener, listenerContext, priority) { - if (typeof listenerContext === "undefined") { listenerContext = null; } - if (typeof priority === "undefined") { priority = 0; } - this.validateListener(listener, 'addOnce'); - return this._registerListener(listener, true, listenerContext, priority); - }; - Signal.prototype.remove = /** - * Remove a single listener from the dispatch queue. - * @param {Function} listener Handler function that should be removed. - * @param {Object} [context] Execution context (since you can add the same handler multiple times if executing in a different context). - * @return {Function} Listener handler function. - */ - function (listener, context) { - if (typeof context === "undefined") { context = null; } - this.validateListener(listener, 'remove'); - var i = this._indexOfListener(listener, context); - if(i !== -1) { - this._bindings[i]._destroy()//no reason to a SignalBinding exist if it isn't attached to a signal - ; - this._bindings.splice(i, 1); - } - return listener; - }; - Signal.prototype.removeAll = /** - * Remove all listeners from the Signal. - */ - function () { - var n = this._bindings.length; - while(n--) { - this._bindings[n]._destroy(); - } - this._bindings.length = 0; - }; - Signal.prototype.getNumListeners = /** - * @return {number} Number of listeners attached to the Signal. - */ - function () { - return this._bindings.length; - }; - Signal.prototype.halt = /** - * Stop propagation of the event, blocking the dispatch to next listeners on the queue. - *IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.
- * @see Signal.prototype.disable - */ - function () { - this._shouldPropagate = false; - }; - Signal.prototype.dispatch = /** - * Dispatch/Broadcast Signal to all listeners added to the queue. - * @param {...*} [params] Parameters that should be passed to each handler. - */ - function () { - var paramsArr = []; - for (var _i = 0; _i < (arguments.length - 0); _i++) { - paramsArr[_i] = arguments[_i + 0]; - } - if(!this.active) { - return; - } - var n = this._bindings.length; - var bindings; - if(this.memorize) { - this._prevParams = paramsArr; - } - if(!n) { - //should come after memorize - return; - } - bindings = this._bindings.slice(0)//clone array in case add/remove items during dispatch - ; - this._shouldPropagate = true//in case `halt` was called before dispatch or during the previous dispatch. - ; - //execute all callbacks until end of the list or until a callback returns `false` or stops propagation - //reverse loop since listeners with higher priority will be added at the end of the list - do { - n--; - }while(bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false); - }; - Signal.prototype.forget = /** - * Forget memorized arguments. - * @see Signal.memorize - */ - function () { - this._prevParams = null; - }; - Signal.prototype.dispose = /** - * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object). - *IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.
- */ - function () { - this.removeAll(); - delete this._bindings; - delete this._prevParams; - }; - Signal.prototype.toString = /** - * @return {string} String representation of the object. - */ - function () { - return '[Signal active:' + this.active + ' numListeners:' + this.getNumListeners() + ']'; - }; - return Signal; -})(); -///Tilemap that helps expand collision opportunities and control.
-* You can use Tilemap.setTileProperties() to alter the collision properties and
-* callback functions and filters for this object to do things like one-way tiles or whatever.
-*
-* @author Adam Atomic
-* @author Richard Davey
-*/
-var Tile = (function (_super) {
- __extends(Tile, _super);
- /**
- * Instantiate this new tile object. This is usually called from FlxTilemap.loadMap().
- *
- * @param Tilemap A reference to the tilemap object creating the tile.
- * @param Index The actual core map data index for this tile type.
- * @param Width The width of the tile.
- * @param Height The height of the tile.
- * @param Visible Whether the tile is visible or not.
- * @param AllowCollisions The collision flags for the object. By default this value is ANY or NONE depending on the parameters sent to loadMap().
- */
- function Tile(game, Tilemap, Index, Width, Height, Visible, AllowCollisions) {
- _super.call(this, game, 0, 0, Width, Height);
- this.immovable = true;
- this.moves = false;
- this.callback = null;
- this.filter = null;
- this.tilemap = Tilemap;
- this.index = Index;
- this.visible = Visible;
- this.allowCollisions = AllowCollisions;
- this.mapIndex = 0;
- }
- Tile.prototype.destroy = /**
- * Clean up memory.
- */
- function () {
- _super.prototype.destroy.call(this);
- this.callback = null;
- this.tilemap = null;
- };
- return Tile;
-})(GameObject);
+var Phaser;
+(function (Phaser) {
+ Phaser.VERSION = 'Phaser version 0.9';
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/system/Camera.ts b/Phaser/system/Camera.ts
index c951d1c2..08b1ae1e 100644
--- a/Phaser/system/Camera.ts
+++ b/Phaser/system/Camera.ts
@@ -1,676 +1,682 @@
/// QuadTree for how to use it, IF YOU DARE.
*/
-class LinkedList {
- /**
- * Creates a new link, and sets object and next to null.
- */
- constructor() {
+/**
+* Phaser
+*/
- this.object = null;
- this.next = null;
+module Phaser {
- }
+ export class LinkedList {
- /**
- * Stores a reference to an Basic.
- */
- public object: Basic;
+ /**
+ * Creates a new link, and sets object and next to null.
+ */
+ constructor() {
- /**
- * Stores a reference to the next link in the list.
- */
- public next: LinkedList;
+ this.object = null;
+ this.next = null;
- /**
- * Clean up memory.
- */
- public destroy() {
-
- this.object = null;
-
- if (this.next != null)
- {
- this.next.destroy();
}
- this.next = null;
+ /**
+ * Stores a reference to an Basic.
+ */
+ public object: Basic;
+ /**
+ * Stores a reference to the next link in the list.
+ */
+ public next: LinkedList;
+
+ /**
+ * Clean up memory.
+ */
+ public destroy() {
+
+ this.object = null;
+
+ if (this.next != null)
+ {
+ this.next.destroy();
+ }
+
+ this.next = null;
+
+ }
}
-}
+
+}
\ No newline at end of file
diff --git a/Phaser/system/QuadTree.ts b/Phaser/system/QuadTree.ts
index c996acbd..b2ed792b 100644
--- a/Phaser/system/QuadTree.ts
+++ b/Phaser/system/QuadTree.ts
@@ -1,5 +1,4 @@
-/// overlapNode().
- */
- private static _objectHullX: number;
-
- /**
- * Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
- */
- private static _objectHullY: number;
-
- /**
- * Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
- */
- private static _objectHullWidth: number;
-
- /**
- * Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
- */
- private static _objectHullHeight: number;
-
- /**
- * Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
- */
- private static _checkObjectHullX: number;
-
- /**
- * Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
- */
- private static _checkObjectHullY: number;
-
- /**
- * Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
- */
- private static _checkObjectHullWidth: number;
-
- /**
- * Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
- */
- private static _checkObjectHullHeight: number;
-
- /**
- * Clean up memory.
- */
- public destroy() {
-
- this._tailA.destroy();
- this._tailB.destroy();
- this._headA.destroy();
- this._headB.destroy();
-
- this._tailA = null;
- this._tailB = null;
- this._headA = null;
- this._headB = null;
-
- if (this._northWestTree != null)
- {
- this._northWestTree.destroy();
- }
-
- if (this._northEastTree != null)
- {
- this._northEastTree.destroy();
- }
-
- if (this._southEastTree != null)
- {
- this._southEastTree.destroy();
- }
-
- if (this._southWestTree != null)
- {
- this._southWestTree.destroy();
- }
-
- this._northWestTree = null;
- this._northEastTree = null;
- this._southEastTree = null;
- this._southWestTree = null;
-
- QuadTree._object = null;
- QuadTree._processingCallback = null;
- QuadTree._notifyCallback = null;
-
- }
-
- /**
- * Load objects and/or groups into the quad tree, and register notify and processing callbacks.
- *
- * @param ObjectOrGroup1 Any object that is or extends GameObject or Group.
- * @param ObjectOrGroup2 Any object that is or extends GameObject or Group. If null, the first parameter will be checked against itself.
- * @param NotifyCallback A function with the form myFunction(Object1:GameObject,Object2:GameObject) that is called whenever two objects are found to overlap in world space, and either no ProcessCallback is specified, or the ProcessCallback returns true.
- * @param ProcessCallback A function with the form myFunction(Object1:GameObject,Object2:GameObject):bool that is called whenever two objects are found to overlap in world space. The NotifyCallback is only called if this function returns true. See GameObject.separate().
- */
- public load(ObjectOrGroup1: Basic, ObjectOrGroup2: Basic = null, NotifyCallback = null, ProcessCallback = null) {
-
- //console.log('quadtree load', QuadTree.divisions, ObjectOrGroup1, ObjectOrGroup2);
-
- this.add(ObjectOrGroup1, QuadTree.A_LIST);
-
- if (ObjectOrGroup2 != null)
- {
- this.add(ObjectOrGroup2, QuadTree.B_LIST);
- QuadTree._useBothLists = true;
- }
- else
- {
- QuadTree._useBothLists = false;
- }
-
- QuadTree._notifyCallback = NotifyCallback;
- QuadTree._processingCallback = ProcessCallback;
-
- //console.log('use both', QuadTree._useBothLists);
- //console.log('------------ end of load');
-
- }
-
- /**
- * Call this function to add an object to the root of the tree.
- * This function will recursively add all group members, but
- * not the groups themselves.
- *
- * @param ObjectOrGroup GameObjects are just added, Groups are recursed and their applicable members added accordingly.
- * @param List A uint flag indicating the list to which you want to add the objects. Options are QuadTree.A_LIST and QuadTree.B_LIST.
- */
- public add(ObjectOrGroup: Basic, List: number) {
-
- QuadTree._list = List;
-
- if (ObjectOrGroup.isGroup == true)
- {
- var i: number = 0;
- var basic: Basic;
- var members = overlapNode().
+ */
+ private static _objectHullX: number;
+
+ /**
+ * Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
+ */
+ private static _objectHullY: number;
+
+ /**
+ * Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
+ */
+ private static _objectHullWidth: number;
+
+ /**
+ * Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
+ */
+ private static _objectHullHeight: number;
+
+ /**
+ * Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
+ */
+ private static _checkObjectHullX: number;
+
+ /**
+ * Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
+ */
+ private static _checkObjectHullY: number;
+
+ /**
+ * Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
+ */
+ private static _checkObjectHullWidth: number;
+
+ /**
+ * Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
+ */
+ private static _checkObjectHullHeight: number;
+
+ /**
+ * Clean up memory.
+ */
+ public destroy() {
+
+ this._tailA.destroy();
+ this._tailB.destroy();
+ this._headA.destroy();
+ this._headB.destroy();
+
+ this._tailA = null;
+ this._tailB = null;
+ this._headA = null;
+ this._headB = null;
+
+ if (this._northWestTree != null)
+ {
+ this._northWestTree.destroy();
+ }
+
+ if (this._northEastTree != null)
+ {
+ this._northEastTree.destroy();
+ }
+
+ if (this._southEastTree != null)
+ {
+ this._southEastTree.destroy();
+ }
+
+ if (this._southWestTree != null)
+ {
+ this._southWestTree.destroy();
+ }
+
+ this._northWestTree = null;
+ this._northEastTree = null;
+ this._southEastTree = null;
+ this._southWestTree = null;
+
+ QuadTree._object = null;
+ QuadTree._processingCallback = null;
+ QuadTree._notifyCallback = null;
+
+ }
+
+ /**
+ * Load objects and/or groups into the quad tree, and register notify and processing callbacks.
+ *
+ * @param ObjectOrGroup1 Any object that is or extends GameObject or Group.
+ * @param ObjectOrGroup2 Any object that is or extends GameObject or Group. If null, the first parameter will be checked against itself.
+ * @param NotifyCallback A function with the form myFunction(Object1:GameObject,Object2:GameObject) that is called whenever two objects are found to overlap in world space, and either no ProcessCallback is specified, or the ProcessCallback returns true.
+ * @param ProcessCallback A function with the form myFunction(Object1:GameObject,Object2:GameObject):bool that is called whenever two objects are found to overlap in world space. The NotifyCallback is only called if this function returns true. See GameObject.separate().
+ */
+ public load(ObjectOrGroup1: Basic, ObjectOrGroup2: Basic = null, NotifyCallback = null, ProcessCallback = null) {
+
+ //console.log('quadtree load', QuadTree.divisions, ObjectOrGroup1, ObjectOrGroup2);
+
+ this.add(ObjectOrGroup1, QuadTree.A_LIST);
+
+ if (ObjectOrGroup2 != null)
+ {
+ this.add(ObjectOrGroup2, QuadTree.B_LIST);
+ QuadTree._useBothLists = true;
+ }
+ else
+ {
+ QuadTree._useBothLists = false;
+ }
+
+ QuadTree._notifyCallback = NotifyCallback;
+ QuadTree._processingCallback = ProcessCallback;
+
+ //console.log('use both', QuadTree._useBothLists);
+ //console.log('------------ end of load');
+
+ }
+
+ /**
+ * Call this function to add an object to the root of the tree.
+ * This function will recursively add all group members, but
+ * not the groups themselves.
+ *
+ * @param ObjectOrGroup GameObjects are just added, Groups are recursed and their applicable members added accordingly.
+ * @param List A uint flag indicating the list to which you want to add the objects. Options are QuadTree.A_LIST and QuadTree.B_LIST.
+ */
+ public add(ObjectOrGroup: Basic, List: number) {
+
+ QuadTree._list = List;
+
+ if (ObjectOrGroup.isGroup == true)
+ {
+ var i: number = 0;
+ var basic: Basic;
+ var members = QuadTree's other main function. Call this after adding objects
+ * using QuadTree.load() to compare the objects that you loaded.
+ *
+ * @return Whether or not any overlaps were found.
+ */
+ public execute(): bool {
- /**
- * Internal function for recursively adding objects to leaf lists.
- */
- private addToList() {
+ //console.log('quadtree execute');
- //console.log('Adding to List');
+ var overlapProcessed: bool = false;
+ var iterator: LinkedList;
- var ot: LinkedList;
-
- if (QuadTree._list == QuadTree.A_LIST)
- {
- //console.log('A LIST');
- if (this._tailA.object != null)
+ if (this._headA.object != null)
{
- ot = this._tailA;
- this._tailA = new LinkedList();
- ot.next = this._tailA;
- }
+ //console.log('---------------------------------------------------');
+ //console.log('headA iterator');
- this._tailA.object = QuadTree._object;
- }
- else
- {
- //console.log('B LIST');
- if (this._tailB.object != null)
- {
- ot = this._tailB;
- this._tailB = new LinkedList();
- ot.next = this._tailB;
- }
+ iterator = this._headA;
- this._tailB.object = QuadTree._object;
- }
-
- if (!this._canSubdivide)
- {
- return;
- }
-
- if (this._northWestTree != null)
- {
- this._northWestTree.addToList();
- }
-
- if (this._northEastTree != null)
- {
- this._northEastTree.addToList();
- }
-
- if (this._southEastTree != null)
- {
- this._southEastTree.addToList();
- }
-
- if (this._southWestTree != null)
- {
- this._southWestTree.addToList();
- }
-
- }
-
- /**
- * QuadTree's other main function. Call this after adding objects
- * using QuadTree.load() to compare the objects that you loaded.
- *
- * @return Whether or not any overlaps were found.
- */
- public execute(): bool {
-
- //console.log('quadtree execute');
-
- var overlapProcessed: bool = false;
- var iterator: LinkedList;
-
- if (this._headA.object != null)
- {
- //console.log('---------------------------------------------------');
- //console.log('headA iterator');
-
- iterator = this._headA;
-
- while (iterator != null)
- {
- QuadTree._object = iterator.object;
-
- if (QuadTree._useBothLists)
+ while (iterator != null)
{
- QuadTree._iterator = this._headB;
+ QuadTree._object = iterator.object;
+
+ if (QuadTree._useBothLists)
+ {
+ QuadTree._iterator = this._headB;
+ }
+ else
+ {
+ QuadTree._iterator = iterator.next;
+ }
+
+ if (QuadTree._object.exists && (QuadTree._object.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode())
+ {
+ //console.log('headA iterator overlapped true');
+ overlapProcessed = true;
+ }
+
+ iterator = iterator.next;
+
}
- else
+ }
+
+ //Advance through the tree by calling overlap on each child
+ if ((this._northWestTree != null) && this._northWestTree.execute())
+ {
+ //console.log('NW quadtree execute');
+ overlapProcessed = true;
+ }
+
+ if ((this._northEastTree != null) && this._northEastTree.execute())
+ {
+ //console.log('NE quadtree execute');
+ overlapProcessed = true;
+ }
+
+ if ((this._southEastTree != null) && this._southEastTree.execute())
+ {
+ //console.log('SE quadtree execute');
+ overlapProcessed = true;
+ }
+
+ if ((this._southWestTree != null) && this._southWestTree.execute())
+ {
+ //console.log('SW quadtree execute');
+ overlapProcessed = true;
+ }
+
+ return overlapProcessed;
+
+ }
+
+ /**
+ * An private for comparing an object against the contents of a node.
+ *
+ * @return Whether or not any overlaps were found.
+ */
+ private overlapNode(): bool {
+
+ //console.log('overlapNode');
+
+ //Walk the list and check for overlaps
+ var overlapProcessed: bool = false;
+ var checkObject;
+
+ while (QuadTree._iterator != null)
+ {
+ if (!QuadTree._object.exists || (QuadTree._object.allowCollisions <= 0))
{
- QuadTree._iterator = iterator.next;
+ //console.log('break 1');
+ break;
}
- if (QuadTree._object.exists && (QuadTree._object.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode())
+ checkObject = QuadTree._iterator.object;
+
+ if ((QuadTree._object === checkObject) || !checkObject.exists || (checkObject.allowCollisions <= 0))
{
- //console.log('headA iterator overlapped true');
- overlapProcessed = true;
+ //console.log('break 2');
+ QuadTree._iterator = QuadTree._iterator.next;
+ continue;
}
- iterator = iterator.next;
+ //calculate bulk hull for QuadTree._object
+ QuadTree._objectHullX = (QuadTree._object.x < QuadTree._object.last.x) ? QuadTree._object.x : QuadTree._object.last.x;
+ QuadTree._objectHullY = (QuadTree._object.y < QuadTree._object.last.y) ? QuadTree._object.y : QuadTree._object.last.y;
+ QuadTree._objectHullWidth = QuadTree._object.x - QuadTree._object.last.x;
+ QuadTree._objectHullWidth = QuadTree._object.width + ((QuadTree._objectHullWidth > 0) ? QuadTree._objectHullWidth : -QuadTree._objectHullWidth);
+ QuadTree._objectHullHeight = QuadTree._object.y - QuadTree._object.last.y;
+ QuadTree._objectHullHeight = QuadTree._object.height + ((QuadTree._objectHullHeight > 0) ? QuadTree._objectHullHeight : -QuadTree._objectHullHeight);
- }
- }
+ //calculate bulk hull for checkObject
+ QuadTree._checkObjectHullX = (checkObject.x < checkObject.last.x) ? checkObject.x : checkObject.last.x;
+ QuadTree._checkObjectHullY = (checkObject.y < checkObject.last.y) ? checkObject.y : checkObject.last.y;
+ QuadTree._checkObjectHullWidth = checkObject.x - checkObject.last.x;
+ QuadTree._checkObjectHullWidth = checkObject.width + ((QuadTree._checkObjectHullWidth > 0) ? QuadTree._checkObjectHullWidth : -QuadTree._checkObjectHullWidth);
+ QuadTree._checkObjectHullHeight = checkObject.y - checkObject.last.y;
+ QuadTree._checkObjectHullHeight = checkObject.height + ((QuadTree._checkObjectHullHeight > 0) ? QuadTree._checkObjectHullHeight : -QuadTree._checkObjectHullHeight);
- //Advance through the tree by calling overlap on each child
- if ((this._northWestTree != null) && this._northWestTree.execute())
- {
- //console.log('NW quadtree execute');
- overlapProcessed = true;
- }
-
- if ((this._northEastTree != null) && this._northEastTree.execute())
- {
- //console.log('NE quadtree execute');
- overlapProcessed = true;
- }
-
- if ((this._southEastTree != null) && this._southEastTree.execute())
- {
- //console.log('SE quadtree execute');
- overlapProcessed = true;
- }
-
- if ((this._southWestTree != null) && this._southWestTree.execute())
- {
- //console.log('SW quadtree execute');
- overlapProcessed = true;
- }
+ //check for intersection of the two hulls
+ if ((QuadTree._objectHullX + QuadTree._objectHullWidth > QuadTree._checkObjectHullX) && (QuadTree._objectHullX < QuadTree._checkObjectHullX + QuadTree._checkObjectHullWidth) && (QuadTree._objectHullY + QuadTree._objectHullHeight > QuadTree._checkObjectHullY) && (QuadTree._objectHullY < QuadTree._checkObjectHullY + QuadTree._checkObjectHullHeight))
+ {
+ //console.log('intersection!');
- return overlapProcessed;
+ //Execute callback functions if they exist
+ if ((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, checkObject))
+ {
+ overlapProcessed = true;
+ }
- }
+ if (overlapProcessed && (QuadTree._notifyCallback != null))
+ {
+ QuadTree._notifyCallback(QuadTree._object, checkObject);
+ }
+ }
- /**
- * An private for comparing an object against the contents of a node.
- *
- * @return Whether or not any overlaps were found.
- */
- private overlapNode(): bool {
-
- //console.log('overlapNode');
-
- //Walk the list and check for overlaps
- var overlapProcessed: bool = false;
- var checkObject;
-
- while (QuadTree._iterator != null)
- {
- if (!QuadTree._object.exists || (QuadTree._object.allowCollisions <= 0))
- {
- //console.log('break 1');
- break;
- }
-
- checkObject = QuadTree._iterator.object;
-
- if ((QuadTree._object === checkObject) || !checkObject.exists || (checkObject.allowCollisions <= 0))
- {
- //console.log('break 2');
QuadTree._iterator = QuadTree._iterator.next;
- continue;
+
}
- //calculate bulk hull for QuadTree._object
- QuadTree._objectHullX = (QuadTree._object.x < QuadTree._object.last.x) ? QuadTree._object.x : QuadTree._object.last.x;
- QuadTree._objectHullY = (QuadTree._object.y < QuadTree._object.last.y) ? QuadTree._object.y : QuadTree._object.last.y;
- QuadTree._objectHullWidth = QuadTree._object.x - QuadTree._object.last.x;
- QuadTree._objectHullWidth = QuadTree._object.width + ((QuadTree._objectHullWidth > 0) ? QuadTree._objectHullWidth : -QuadTree._objectHullWidth);
- QuadTree._objectHullHeight = QuadTree._object.y - QuadTree._object.last.y;
- QuadTree._objectHullHeight = QuadTree._object.height + ((QuadTree._objectHullHeight > 0) ? QuadTree._objectHullHeight : -QuadTree._objectHullHeight);
-
- //calculate bulk hull for checkObject
- QuadTree._checkObjectHullX = (checkObject.x < checkObject.last.x) ? checkObject.x : checkObject.last.x;
- QuadTree._checkObjectHullY = (checkObject.y < checkObject.last.y) ? checkObject.y : checkObject.last.y;
- QuadTree._checkObjectHullWidth = checkObject.x - checkObject.last.x;
- QuadTree._checkObjectHullWidth = checkObject.width + ((QuadTree._checkObjectHullWidth > 0) ? QuadTree._checkObjectHullWidth : -QuadTree._checkObjectHullWidth);
- QuadTree._checkObjectHullHeight = checkObject.y - checkObject.last.y;
- QuadTree._checkObjectHullHeight = checkObject.height + ((QuadTree._checkObjectHullHeight > 0) ? QuadTree._checkObjectHullHeight : -QuadTree._checkObjectHullHeight);
-
- //check for intersection of the two hulls
- if ((QuadTree._objectHullX + QuadTree._objectHullWidth > QuadTree._checkObjectHullX) && (QuadTree._objectHullX < QuadTree._checkObjectHullX + QuadTree._checkObjectHullWidth) && (QuadTree._objectHullY + QuadTree._objectHullHeight > QuadTree._checkObjectHullY) && (QuadTree._objectHullY < QuadTree._checkObjectHullY + QuadTree._checkObjectHullHeight))
- {
- //console.log('intersection!');
-
- //Execute callback functions if they exist
- if ((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, checkObject))
- {
- overlapProcessed = true;
- }
-
- if (overlapProcessed && (QuadTree._notifyCallback != null))
- {
- QuadTree._notifyCallback(QuadTree._object, checkObject);
- }
- }
-
- QuadTree._iterator = QuadTree._iterator.next;
+ return overlapProcessed;
}
-
- return overlapProcessed;
-
}
-}
+
+}
\ No newline at end of file
diff --git a/Phaser/system/RandomDataGenerator.ts b/Phaser/system/RandomDataGenerator.ts
index 92857b57..fff84e3c 100644
--- a/Phaser/system/RandomDataGenerator.ts
+++ b/Phaser/system/RandomDataGenerator.ts
@@ -1,3 +1,5 @@
+/// Tilemap that helps expand collision opportunities and control.
@@ -9,79 +8,88 @@
* @author Adam Atomic
* @author Richard Davey
*/
-class Tile extends GameObject {
- /**
- * Instantiate this new tile object. This is usually called from FlxTilemap.loadMap().
- *
- * @param Tilemap A reference to the tilemap object creating the tile.
- * @param Index The actual core map data index for this tile type.
- * @param Width The width of the tile.
- * @param Height The height of the tile.
- * @param Visible Whether the tile is visible or not.
- * @param AllowCollisions The collision flags for the object. By default this value is ANY or NONE depending on the parameters sent to loadMap().
- */
- constructor(game: Game, Tilemap: Tilemap, Index: number, Width: number, Height: number, Visible: bool, AllowCollisions: number) {
+/**
+* Phaser
+*/
- super(game, 0, 0, Width, Height);
+module Phaser {
- this.immovable = true;
- this.moves = false;
- this.callback = null;
- this.filter = null;
+ export class Tile extends GameObject {
- this.tilemap = Tilemap;
- this.index = Index;
- this.visible = Visible;
- this.allowCollisions = AllowCollisions;
+ /**
+ * Instantiate this new tile object. This is usually called from FlxTilemap.loadMap().
+ *
+ * @param Tilemap A reference to the tilemap object creating the tile.
+ * @param Index The actual core map data index for this tile type.
+ * @param Width The width of the tile.
+ * @param Height The height of the tile.
+ * @param Visible Whether the tile is visible or not.
+ * @param AllowCollisions The collision flags for the object. By default this value is ANY or NONE depending on the parameters sent to loadMap().
+ */
+ constructor(game: Game, Tilemap: Tilemap, Index: number, Width: number, Height: number, Visible: bool, AllowCollisions: number) {
- this.mapIndex = 0;
+ super(game, 0, 0, Width, Height);
+
+ this.immovable = true;
+ this.moves = false;
+ this.callback = null;
+ this.filter = null;
+
+ this.tilemap = Tilemap;
+ this.index = Index;
+ this.visible = Visible;
+ this.allowCollisions = AllowCollisions;
+
+ this.mapIndex = 0;
+
+ }
+
+ /**
+ * This function is called whenever an object hits a tile of this type.
+ * This function should take the form myFunction(Tile:FlxTile,Object:FlxObject).
+ * Defaults to null, set through FlxTilemap.setTileProperties().
+ */
+ public callback;
+
+ /**
+ * Each tile can store its own filter class for their callback functions.
+ * That is, the callback will only be triggered if an object with a class
+ * type matching the filter touched it.
+ * Defaults to null, set through FlxTilemap.setTileProperties().
+ */
+ public filter;
+
+ /**
+ * A reference to the tilemap this tile object belongs to.
+ */
+ public tilemap: Tilemap;
+
+ /**
+ * The index of this tile type in the core map data.
+ * For example, if your map only has 16 kinds of tiles in it,
+ * this number is usually between 0 and 15.
+ */
+ public index: number;
+
+ /**
+ * The current map index of this tile object at this moment.
+ * You can think of tile objects as moving around the tilemap helping with collisions.
+ * This value is only reliable and useful if used from the callback function.
+ */
+ public mapIndex: number;
+
+ /**
+ * Clean up memory.
+ */
+ public destroy() {
+
+ super.destroy();
+ this.callback = null;
+ this.tilemap = null;
+
+ }
}
- /**
- * This function is called whenever an object hits a tile of this type.
- * This function should take the form myFunction(Tile:FlxTile,Object:FlxObject).
- * Defaults to null, set through FlxTilemap.setTileProperties().
- */
- public callback;
-
- /**
- * Each tile can store its own filter class for their callback functions.
- * That is, the callback will only be triggered if an object with a class
- * type matching the filter touched it.
- * Defaults to null, set through FlxTilemap.setTileProperties().
- */
- public filter;
-
- /**
- * A reference to the tilemap this tile object belongs to.
- */
- public tilemap: Tilemap;
-
- /**
- * The index of this tile type in the core map data.
- * For example, if your map only has 16 kinds of tiles in it,
- * this number is usually between 0 and 15.
- */
- public index: number;
-
- /**
- * The current map index of this tile object at this moment.
- * You can think of tile objects as moving around the tilemap helping with collisions.
- * This value is only reliable and useful if used from the callback function.
- */
- public mapIndex: number;
-
- /**
- * Clean up memory.
- */
- public destroy() {
-
- super.destroy();
- this.callback = null;
- this.tilemap = null;
-
- }
-
-}
+}
\ No newline at end of file
diff --git a/Phaser/system/TilemapBuffer.ts b/Phaser/system/TilemapBuffer.ts
index ba8e50a3..f00387f2 100644
--- a/Phaser/system/TilemapBuffer.ts
+++ b/Phaser/system/TilemapBuffer.ts
@@ -1,172 +1,173 @@
/// - * Returns true or false based on the chance value (default 50%). For example if you wanted a player to have a 30% chance - * of getting a bonus, call chanceRoll(30) - true means the chance passed, false means it failed. - *
- * @param chance The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%) - * @return true if the roll passed, or false - */ - function (chance) { - if (typeof chance === "undefined") { chance = 50; } - if(chance <= 0) { - return false; - } else if(chance >= 100) { - return true; - } else { - if(Math.random() * 100 >= chance) { - return false; - } else { - return true; - } - } - }; - GameMath.prototype.maxAdd = /** - * Adds the given amount to the value, but never lets the value go over the specified maximum - * - * @param value The value to add the amount to - * @param amount The amount to add to the value - * @param max The maximum the value is allowed to be - * @return The new value - */ - function (value, amount, max) { - value += amount; - if(value > max) { - value = max; - } - return value; - }; - GameMath.prototype.minSub = /** - * Subtracts the given amount from the value, but never lets the value go below the specified minimum - * - * @param value The base value - * @param amount The amount to subtract from the base value - * @param min The minimum the value is allowed to be - * @return The new value - */ - function (value, amount, min) { - value -= amount; - if(value < min) { - value = min; - } - return value; - }; - GameMath.prototype.wrapValue = /** - * Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around. - *Values must be positive integers, and are passed through Math.abs
- * - * @param value The value to add the amount to - * @param amount The amount to add to the value - * @param max The maximum the value is allowed to be - * @return The wrapped value - */ - function (value, amount, max) { - var diff; - value = Math.abs(value); - amount = Math.abs(amount); - max = Math.abs(max); - diff = (value + amount) % max; - return diff; - }; - GameMath.prototype.randomSign = /** - * Randomly returns either a 1 or -1 - * - * @return 1 or -1 - */ - function () { - return (Math.random() > 0.5) ? 1 : -1; - }; - GameMath.prototype.isOdd = /** - * Returns true if the number given is odd. - * - * @param n The number to check - * - * @return True if the given number is odd. False if the given number is even. - */ - function (n) { - if(n & 1) { - return true; - } else { - return false; - } - }; - GameMath.prototype.isEven = /** - * Returns true if the number given is even. - * - * @param n The number to check - * - * @return True if the given number is even. False if the given number is odd. - */ - function (n) { - if(n & 1) { - return false; - } else { - return true; - } - }; - GameMath.prototype.wrapAngle = /** - * Keeps an angle value between -180 and +180Number between 0 and 1.
- */
- function () {
- return this.globalSeed = this.srand(this.globalSeed);
- };
- GameMath.prototype.srand = /**
- * Generates a random number based on the seed provided.
- *
- * @param Seed A number between 0 and 1, used to generate a predictable random number (very optional).
- *
- * @return A Number between 0 and 1.
- */
- function (Seed) {
- return ((69621 * (Seed * 0x7FFFFFFF)) % 0x7FFFFFFF) / 0x7FFFFFFF;
- };
- GameMath.prototype.getRandom = /**
- * Fetch a random entry from the given array.
- * Will return null if random selection is missing, or array has no entries.
- * FlxG.getRandom() is deterministic and safe for use with replays/recordings.
- * HOWEVER, FlxU.getRandom() is NOT deterministic and unsafe for use with replays/recordings.
- *
- * @param Objects An array of objects.
- * @param StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
- * @param Length Optional restriction on the number of values you want to randomly select from.
- *
- * @return The random object that was selected.
- */
- function (Objects, StartIndex, Length) {
- if (typeof StartIndex === "undefined") { StartIndex = 0; }
- if (typeof Length === "undefined") { Length = 0; }
- if(Objects != null) {
- var l = Length;
- if((l == 0) || (l > Objects.length - StartIndex)) {
- l = Objects.length - StartIndex;
- }
- if(l > 0) {
- return Objects[StartIndex + Math.floor(Math.random() * l)];
- }
- }
- return null;
- };
- GameMath.prototype.floor = /**
- * Round down to the next whole number. E.g. floor(1.7) == 1, and floor(-2.7) == -2.
- *
- * @param Value Any number.
- *
- * @return The rounded value of that number.
- */
- function (Value) {
- var n = Value | 0;
- return (Value > 0) ? (n) : ((n != Value) ? (n - 1) : (n));
- };
- GameMath.prototype.ceil = /**
- * Round up to the next whole number. E.g. ceil(1.3) == 2, and ceil(-2.3) == -3.
- *
- * @param Value Any number.
- *
- * @return The rounded value of that number.
- */
- function (Value) {
- var n = Value | 0;
- return (Value > 0) ? ((n != Value) ? (n + 1) : (n)) : (n);
- };
- GameMath.prototype.sinCosGenerator = /**
- * Generate a sine and cosine table simultaneously and extremely quickly. Based on research by Franky of scene.at
- * - * The parameters allow you to specify the length, amplitude and frequency of the wave. Once you have called this function - * you should get the results via getSinTable() and getCosTable(). This generator is fast enough to be used in real-time. - *
- * @param length The length of the wave - * @param sinAmplitude The amplitude to apply to the sine table (default 1.0) if you need values between say -+ 125 then give 125 as the value - * @param cosAmplitude The amplitude to apply to the cosine table (default 1.0) if you need values between say -+ 125 then give 125 as the value - * @param frequency The frequency of the sine and cosine table data - * @return Returns the sine table - * @see getSinTable - * @see getCosTable - */ - function (length, sinAmplitude, cosAmplitude, frequency) { - if (typeof sinAmplitude === "undefined") { sinAmplitude = 1.0; } - if (typeof cosAmplitude === "undefined") { cosAmplitude = 1.0; } - if (typeof frequency === "undefined") { frequency = 1.0; } - var sin = sinAmplitude; - var cos = cosAmplitude; - var frq = frequency * Math.PI / length; - this.cosTable = []; - this.sinTable = []; - for(var c = 0; c < length; c++) { - cos -= sin * frq; - sin += cos * frq; - this.cosTable[c] = cos; - this.sinTable[c] = sin; - } - return this.sinTable; - }; - return GameMath; -})(); -/** -* Point -* -* @desc The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis. -* -* @version 1.2 - 27th February 2013 -* @author Richard Davey -* @todo polar, interpolate -*/ -var Point = (function () { - /** - * Creates a new point. If you pass no parameters to this method, a point is created at (0,0). - * @class Point - * @constructor - * @param {Number} x One-liner. Default is ?. - * @param {Number} y One-liner. Default is ?. - **/ - function Point(x, y) { - if (typeof x === "undefined") { x = 0; } - if (typeof y === "undefined") { y = 0; } - this.setTo(x, y); - } - Point.prototype.add = /** - * Adds the coordinates of another point to the coordinates of this point to create a new point. - * @method add - * @param {Point} point - The point to be added. - * @return {Point} The new Point object. - **/ - function (toAdd, output) { - if (typeof output === "undefined") { output = new Point(); } - return output.setTo(this.x + toAdd.x, this.y + toAdd.y); - }; - Point.prototype.addTo = /** - * Adds the given values to the coordinates of this point and returns it - * @method addTo - * @param {Number} x - The amount to add to the x value of the point - * @param {Number} y - The amount to add to the x value of the point - * @return {Point} This Point object. - **/ - function (x, y) { - if (typeof x === "undefined") { x = 0; } - if (typeof y === "undefined") { y = 0; } - return this.setTo(this.x + x, this.y + y); - }; - Point.prototype.subtractFrom = /** - * Adds the given values to the coordinates of this point and returns it - * @method addTo - * @param {Number} x - The amount to add to the x value of the point - * @param {Number} y - The amount to add to the x value of the point - * @return {Point} This Point object. - **/ - function (x, y) { - if (typeof x === "undefined") { x = 0; } - if (typeof y === "undefined") { y = 0; } - return this.setTo(this.x - x, this.y - y); - }; - Point.prototype.invert = /** - * Inverts the x and y values of this point - * @method invert - * @return {Point} This Point object. - **/ - function () { - return this.setTo(this.y, this.x); - }; - Point.prototype.clamp = /** - * Clamps this Point object to be between the given min and max - * @method clamp - * @param {number} The minimum value to clamp this Point to - * @param {number} The maximum value to clamp this Point to - * @return {Point} This Point object. - **/ - function (min, max) { - this.clampX(min, max); - this.clampY(min, max); - return this; - }; - Point.prototype.clampX = /** - * Clamps the x value of this Point object to be between the given min and max - * @method clampX - * @param {number} The minimum value to clamp this Point to - * @param {number} The maximum value to clamp this Point to - * @return {Point} This Point object. - **/ - function (min, max) { - this.x = Math.max(Math.min(this.x, max), min); - return this; - }; - Point.prototype.clampY = /** - * Clamps the y value of this Point object to be between the given min and max - * @method clampY - * @param {number} The minimum value to clamp this Point to - * @param {number} The maximum value to clamp this Point to - * @return {Point} This Point object. - **/ - function (min, max) { - this.x = Math.max(Math.min(this.x, max), min); - this.y = Math.max(Math.min(this.y, max), min); - return this; - }; - Point.prototype.clone = /** - * Creates a copy of this Point. - * @method clone - * @param {Point} output Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned. - * @return {Point} The new Point object. - **/ - function (output) { - if (typeof output === "undefined") { output = new Point(); } - return output.setTo(this.x, this.y); - }; - Point.prototype.copyFrom = /** - * Copies the point data from the source Point object into this Point object. - * @method copyFrom - * @param {Point} source - The point to copy from. - * @return {Point} This Point object. Useful for chaining method calls. - **/ - function (source) { - return this.setTo(source.x, source.y); - }; - Point.prototype.copyTo = /** - * Copies the point data from this Point object to the given target Point object. - * @method copyTo - * @param {Point} target - The point to copy to. - * @return {Point} The target Point object. - **/ - function (target) { - return target.setTo(this.x, this.y); - }; - Point.prototype.distanceTo = /** - * Returns the distance from this Point object to the given Point object. - * @method distanceFrom - * @param {Point} target - The destination Point object. - * @param {Boolean} round - Round the distance to the nearest integer (default false) - * @return {Number} The distance between this Point object and the destination Point object. - **/ - function (target, round) { - if (typeof round === "undefined") { round = false; } - var dx = this.x - target.x; - var dy = this.y - target.y; - if(round === true) { - return Math.round(Math.sqrt(dx * dx + dy * dy)); - } else { - return Math.sqrt(dx * dx + dy * dy); - } - }; - Point.distanceBetween = /** - * Returns the distance between the two Point objects. - * @method distanceBetween - * @param {Point} pointA - The first Point object. - * @param {Point} pointB - The second Point object. - * @param {Boolean} round - Round the distance to the nearest integer (default false) - * @return {Number} The distance between the two Point objects. - **/ - function distanceBetween(pointA, pointB, round) { - if (typeof round === "undefined") { round = false; } - var dx = pointA.x - pointB.x; - var dy = pointA.y - pointB.y; - if(round === true) { - return Math.round(Math.sqrt(dx * dx + dy * dy)); - } else { - return Math.sqrt(dx * dx + dy * dy); - } - }; - Point.prototype.distanceCompare = /** - * Returns true if the distance between this point and a target point is greater than or equal a specified distance. - * This avoids using a costly square root operation - * @method distanceCompare - * @param {Point} target - The Point object to use for comparison. - * @param {Number} distance - The distance to use for comparison. - * @return {Boolena} True if distance is >= specified distance. - **/ - function (target, distance) { - if(this.distanceTo(target) >= distance) { - return true; - } else { - return false; - } - }; - Point.prototype.equals = /** - * Determines whether this Point object and the given point object are equal. They are equal if they have the same x and y values. - * @method equals - * @param {Point} point - The point to compare against. - * @return {Boolean} A value of true if the object is equal to this Point object; false if it is not equal. - **/ - function (toCompare) { - if(this.x === toCompare.x && this.y === toCompare.y) { - return true; - } else { - return false; - } - }; - Point.prototype.interpolate = /** - * Determines a point between two specified points. The parameter f determines where the new interpolated point is located relative to the two end points specified by parameters pt1 and pt2. - * The closer the value of the parameter f is to 1.0, the closer the interpolated point is to the first point (parameter pt1). The closer the value of the parameter f is to 0, the closer the interpolated point is to the second point (parameter pt2). - * @method interpolate - * @param {Point} pointA - The first Point object. - * @param {Point} pointB - The second Point object. - * @param {Number} f - The level of interpolation between the two points. Indicates where the new point will be, along the line between pt1 and pt2. If f=1, pt1 is returned; if f=0, pt2 is returned. - * @return {Point} The new interpolated Point object. - **/ - function (pointA, pointB, f) { - }; - Point.prototype.offset = /** - * Offsets the Point object by the specified amount. The value of dx is added to the original value of x to create the new x value. - * The value of dy is added to the original value of y to create the new y value. - * @method offset - * @param {Number} dx - The amount by which to offset the horizontal coordinate, x. - * @param {Number} dy - The amount by which to offset the vertical coordinate, y. - * @return {Point} This Point object. Useful for chaining method calls. - **/ - function (dx, dy) { - this.x += dx; - this.y += dy; - return this; - }; - Point.prototype.polar = /** - * Converts a pair of polar coordinates to a Cartesian point coordinate. - * @method polar - * @param {Number} length - The length coordinate of the polar pair. - * @param {Number} angle - The angle, in radians, of the polar pair. - * @return {Point} The new Cartesian Point object. - **/ - function (length, angle) { - }; - Point.prototype.setTo = /** - * Sets the x and y values of this Point object to the given coordinates. - * @method set - * @param {Number} x - The horizontal position of this point. - * @param {Number} y - The vertical position of this point. - * @return {Point} This Point object. Useful for chaining method calls. - **/ - function (x, y) { - this.x = x; - this.y = y; - return this; - }; - Point.prototype.subtract = /** - * Subtracts the coordinates of another point from the coordinates of this point to create a new point. - * @method subtract - * @param {Point} point - The point to be subtracted. - * @param {Point} output Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned. - * @return {Point} The new Point object. - **/ - function (point, output) { - if (typeof output === "undefined") { output = new Point(); } - return output.setTo(this.x - point.x, this.y - point.y); - }; - Point.prototype.toString = /** - * Returns a string representation of this object. - * @method toString - * @return {string} a string representation of the instance. - **/ - function () { - return '[{Point (x=' + this.x + ' y=' + this.y + ')}]'; - }; - return Point; -})(); -///destroy() on class members if necessary.
- * Don't forget to call super.destroy()!
- */
- function () {
- };
- Basic.prototype.preUpdate = /**
- * Pre-update is called right before update() on each object in the game loop.
- */
- function () {
- };
- Basic.prototype.update = /**
- * Override this to update your class's position and appearance.
- * This is where most of your game rules and behavioral code will go.
- */
- function () {
- };
- Basic.prototype.postUpdate = /**
- * Post-update is called right after update() on each object in the game loop.
- */
- function () {
- };
- Basic.prototype.render = function (camera, cameraOffsetX, cameraOffsetY) {
- };
- Basic.prototype.kill = /**
- * Handy for "killing" game objects.
- * Default behavior is to flag them as nonexistent AND dead.
- * However, if you want the "corpse" to remain in the game,
- * like to animate an effect or whatever, you should override this,
- * setting only alive to false, and leaving exists true.
- */
- function () {
- this.alive = false;
- this.exists = false;
- };
- Basic.prototype.revive = /**
- * Handy for bringing game objects "back to life". Just sets alive and exists back to true.
- * In practice, this is most often called by FlxObject.reset().
- */
- function () {
- this.alive = true;
- this.exists = true;
- };
- Basic.prototype.toString = /**
- * Convert object to readable string name. Useful for debugging, save games, etc.
- */
- function () {
- //return FlxU.getClassName(this, true);
- return "";
- };
- return Basic;
-})();
+ function Basic(game) {
+ /**
+ * Allows you to give this object a name. Useful for debugging, but not actually used internally.
+ */
+ this.name = '';
+ this._game = game;
+ this.ID = -1;
+ this.exists = true;
+ this.active = true;
+ this.visible = true;
+ this.alive = true;
+ this.isGroup = false;
+ this.ignoreDrawDebug = false;
+ }
+ Basic.prototype.destroy = /**
+ * Override this to null out iables or manually call
+ * destroy() on class members if necessary.
+ * Don't forget to call super.destroy()!
+ */
+ function () {
+ };
+ Basic.prototype.preUpdate = /**
+ * Pre-update is called right before update() on each object in the game loop.
+ */
+ function () {
+ };
+ Basic.prototype.update = /**
+ * Override this to update your class's position and appearance.
+ * This is where most of your game rules and behavioral code will go.
+ */
+ function () {
+ };
+ Basic.prototype.postUpdate = /**
+ * Post-update is called right after update() on each object in the game loop.
+ */
+ function () {
+ };
+ Basic.prototype.render = function (camera, cameraOffsetX, cameraOffsetY) {
+ };
+ Basic.prototype.kill = /**
+ * Handy for "killing" game objects.
+ * Default behavior is to flag them as nonexistent AND dead.
+ * However, if you want the "corpse" to remain in the game,
+ * like to animate an effect or whatever, you should override this,
+ * setting only alive to false, and leaving exists true.
+ */
+ function () {
+ this.alive = false;
+ this.exists = false;
+ };
+ Basic.prototype.revive = /**
+ * Handy for bringing game objects "back to life". Just sets alive and exists back to true.
+ * In practice, this is most often called by FlxObject.reset().
+ */
+ function () {
+ this.alive = true;
+ this.exists = true;
+ };
+ Basic.prototype.toString = /**
+ * Convert object to readable string name. Useful for debugging, save games, etc.
+ */
+ function () {
+ return "";
+ };
+ return Basic;
+ })();
+ Phaser.Basic = Basic;
+})(Phaser || (Phaser = {}));
/// GameObject overlaps this GameObject or FlxGroup.
- * If the group has a LOT of things in it, it might be faster to use FlxG.overlaps().
- * 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.
- */
- function (ObjectOrGroup, InScreenSpace, Camera) {
- if (typeof InScreenSpace === "undefined") { InScreenSpace = false; }
- if (typeof Camera === "undefined") { Camera = null; }
- if(ObjectOrGroup.isGroup) {
- var results = false;
- var i = 0;
- var members = ObjectOrGroup.members;
- while(i < length) {
- if(this.overlaps(members[i++], InScreenSpace, Camera)) {
- results = true;
+ GameObject.prototype.preUpdate = function () {
+ // flicker time
+ this.last.x = this.bounds.x;
+ this.last.y = this.bounds.y;
+ };
+ GameObject.prototype.update = function () {
+ };
+ GameObject.prototype.postUpdate = function () {
+ if(this.moves) {
+ this.updateMotion();
+ }
+ this.wasTouching = this.touching;
+ this.touching = Phaser.Collision.NONE;
+ };
+ GameObject.prototype.updateMotion = function () {
+ var delta;
+ var velocityDelta;
+ 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;
+ };
+ GameObject.prototype.overlaps = /**
+ * Checks to see if some GameObject overlaps this GameObject or FlxGroup.
+ * If the group has a LOT of things in it, it might be faster to use FlxG.overlaps().
+ * 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.
+ */
+ function (ObjectOrGroup, InScreenSpace, Camera) {
+ if (typeof InScreenSpace === "undefined") { InScreenSpace = false; }
+ if (typeof Camera === "undefined") { Camera = null; }
+ if(ObjectOrGroup.isGroup) {
+ var results = false;
+ var i = 0;
+ var members = ObjectOrGroup.members;
+ while(i < length) {
+ if(this.overlaps(members[i++], InScreenSpace, Camera)) {
+ results = true;
+ }
}
+ return results;
}
- 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);
- }
+ /*
+ 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 = 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);
+ };
+ GameObject.prototype.overlapsAt = /**
+ * Checks to see if this GameObject were located at the given position, would it overlap the GameObject or FlxGroup?
+ * 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.
*/
- //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 = 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);
- };
- GameObject.prototype.overlapsAt = /**
- * Checks to see if this GameObject were located at the given position, would it overlap the GameObject or FlxGroup?
- * 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.
- */
- function (X, Y, ObjectOrGroup, InScreenSpace, Camera) {
- if (typeof InScreenSpace === "undefined") { InScreenSpace = false; }
- if (typeof Camera === "undefined") { Camera = null; }
- if(ObjectOrGroup.isGroup) {
- var results = false;
- var basic;
- var i = 0;
- var members = ObjectOrGroup.members;
- while(i < length) {
- if(this.overlapsAt(X, Y, members[i++], InScreenSpace, Camera)) {
- results = true;
+ function (X, Y, ObjectOrGroup, InScreenSpace, Camera) {
+ if (typeof InScreenSpace === "undefined") { InScreenSpace = false; }
+ if (typeof Camera === "undefined") { Camera = null; }
+ if(ObjectOrGroup.isGroup) {
+ var results = false;
+ var basic;
+ var i = 0;
+ var members = ObjectOrGroup.members;
+ while(i < length) {
+ if(this.overlapsAt(X, Y, members[i++], InScreenSpace, Camera)) {
+ results = true;
+ }
}
+ return results;
}
- 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 = 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);
- };
- GameObject.prototype.overlapsPoint = /**
- * Checks to see if a ponumber in 2D world space overlaps this GameObject 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.
- */
- function (point, InScreenSpace, Camera) {
- if (typeof InScreenSpace === "undefined") { InScreenSpace = false; }
- if (typeof Camera === "undefined") { Camera = null; }
- 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 = point.x - Camera.scroll.x;
- var Y = 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);
- };
- GameObject.prototype.onScreen = /**
- * 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.
- */
- function (Camera) {
- if (typeof Camera === "undefined") { Camera = null; }
- 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);
- };
- GameObject.prototype.getScreenXY = /**
- * 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 Point object and assigns the post-scrolled X and Y values of this object to it.
- *
- * @return The Point you passed in, or a new Point if you didn't pass one, containing the screen X and Y position of this object.
- */
- function (point, Camera) {
- if (typeof point === "undefined") { point = null; }
- if (typeof Camera === "undefined") { Camera = null; }
- 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;
- };
- Object.defineProperty(GameObject.prototype, "solid", {
- get: /**
- * 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.
- */
- function () {
- return (this.allowCollisions & GameObject.ANY) > GameObject.NONE;
- },
- set: /**
- * @private
- */
- function (Solid) {
- if(Solid) {
- this.allowCollisions = GameObject.ANY;
- } else {
- this.allowCollisions = GameObject.NONE;
+ /*
+ 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);
}
- },
- enumerable: true,
- configurable: true
- });
- GameObject.prototype.getMidpoint = /**
- * Retrieve the midponumber of this object in world coordinates.
- *
- * @Point Allows you to pass in an existing Point object if you're so inclined. Otherwise a new one is created.
- *
- * @return A Point object containing the midponumber of this object in world coordinates.
- */
- function (point) {
- if (typeof point === "undefined") { point = null; }
- if(point == null) {
- point = new Point();
- }
- point.x = this.x + this.width * 0.5;
- point.y = this.y + this.height * 0.5;
- return point;
- };
- GameObject.prototype.reset = /**
- * 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.
- */
- function (X, Y) {
- 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;
- };
- GameObject.prototype.isTouching = /**
- * Handy for checking if this object is touching a particular surface.
- * For slightly better performance you can just & the value directly numbero touching.
- * 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.
- */
- function (Direction) {
- return (this.touching & Direction) > GameObject.NONE;
- };
- GameObject.prototype.justTouched = /**
- * 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.
- */
- function (Direction) {
- return ((this.touching & Direction) > GameObject.NONE) && ((this.wasTouching & Direction) <= GameObject.NONE);
- };
- GameObject.prototype.hurt = /**
- * 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).
- */
- function (Damage) {
- this.health = this.health - Damage;
- if(this.health <= 0) {
- this.kill();
- }
- };
- GameObject.prototype.destroy = function () {
- };
- Object.defineProperty(GameObject.prototype, "x", {
- get: function () {
- return this.bounds.x;
- },
- set: function (value) {
- this.bounds.x = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GameObject.prototype, "y", {
- get: function () {
- return this.bounds.y;
- },
- set: function (value) {
- this.bounds.y = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GameObject.prototype, "rotation", {
- get: function () {
- return this._angle;
- },
- set: function (value) {
- this._angle = this._game.math.wrap(value, 360, 0);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GameObject.prototype, "angle", {
- get: function () {
- return this._angle;
- },
- set: function (value) {
- this._angle = this._game.math.wrap(value, 360, 0);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GameObject.prototype, "width", {
- get: function () {
- return this.bounds.width;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(GameObject.prototype, "height", {
- get: function () {
- return this.bounds.height;
- },
- enumerable: true,
- configurable: true
- });
- return GameObject;
-})(Basic);
-/// GameObject 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.
+ */
+ function (point, InScreenSpace, Camera) {
+ if (typeof InScreenSpace === "undefined") { InScreenSpace = false; }
+ if (typeof Camera === "undefined") { Camera = null; }
+ 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 = point.x - Camera.scroll.x;
+ var Y = 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);
+ };
+ GameObject.prototype.onScreen = /**
+ * 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.
+ */
+ function (Camera) {
+ if (typeof Camera === "undefined") { Camera = null; }
+ 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);
+ };
+ GameObject.prototype.getScreenXY = /**
+ * 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 Point object and assigns the post-scrolled X and Y values of this object to it.
+ *
+ * @return The Point you passed in, or a new Point if you didn't pass one, containing the screen X and Y position of this object.
+ */
+ function (point, Camera) {
+ if (typeof point === "undefined") { point = null; }
+ if (typeof Camera === "undefined") { Camera = null; }
+ if(point == null) {
+ point = new Phaser.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;
+ };
+ Object.defineProperty(GameObject.prototype, "solid", {
+ get: /**
+ * 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.
+ */
+ function () {
+ return (this.allowCollisions & Phaser.Collision.ANY) > Phaser.Collision.NONE;
+ },
+ set: /**
+ * @private
+ */
+ function (Solid) {
+ if(Solid) {
+ this.allowCollisions = Phaser.Collision.ANY;
+ } else {
+ this.allowCollisions = Phaser.Collision.NONE;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ GameObject.prototype.getMidpoint = /**
+ * Retrieve the midponumber of this object in world coordinates.
+ *
+ * @Point Allows you to pass in an existing Point object if you're so inclined. Otherwise a new one is created.
+ *
+ * @return A Point object containing the midponumber of this object in world coordinates.
+ */
+ function (point) {
+ if (typeof point === "undefined") { point = null; }
+ if(point == null) {
+ point = new Phaser.Point();
+ }
+ point.x = this.x + this.width * 0.5;
+ point.y = this.y + this.height * 0.5;
+ return point;
+ };
+ GameObject.prototype.reset = /**
+ * 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.
+ */
+ function (X, Y) {
+ this.revive();
+ this.touching = Phaser.Collision.NONE;
+ this.wasTouching = Phaser.Collision.NONE;
+ this.x = X;
+ this.y = Y;
+ this.last.x = X;
+ this.last.y = Y;
+ this.velocity.x = 0;
+ this.velocity.y = 0;
+ };
+ GameObject.prototype.isTouching = /**
+ * Handy for checking if this object is touching a particular surface.
+ * For slightly better performance you can just & the value directly numbero touching.
+ * 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.
+ */
+ function (Direction) {
+ return (this.touching & Direction) > Phaser.Collision.NONE;
+ };
+ GameObject.prototype.justTouched = /**
+ * 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.
+ */
+ function (Direction) {
+ return ((this.touching & Direction) > Phaser.Collision.NONE) && ((this.wasTouching & Direction) <= Phaser.Collision.NONE);
+ };
+ GameObject.prototype.hurt = /**
+ * 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).
+ */
+ function (Damage) {
+ this.health = this.health - Damage;
+ if(this.health <= 0) {
+ this.kill();
+ }
+ };
+ GameObject.prototype.destroy = function () {
+ };
+ Object.defineProperty(GameObject.prototype, "x", {
+ get: function () {
+ return this.bounds.x;
+ },
+ set: function (value) {
+ this.bounds.x = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(GameObject.prototype, "y", {
+ get: function () {
+ return this.bounds.y;
+ },
+ set: function (value) {
+ this.bounds.y = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(GameObject.prototype, "rotation", {
+ get: function () {
+ return this._angle;
+ },
+ set: function (value) {
+ this._angle = this._game.math.wrap(value, 360, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(GameObject.prototype, "angle", {
+ get: function () {
+ return this._angle;
+ },
+ set: function (value) {
+ this._angle = this._game.math.wrap(value, 360, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(GameObject.prototype, "width", {
+ get: function () {
+ return this.bounds.width;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(GameObject.prototype, "height", {
+ get: function () {
+ return this.bounds.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return GameObject;
+ })(Phaser.Basic);
+ Phaser.GameObject = GameObject;
+})(Phaser || (Phaser = {}));
+/// QuadTree for how to use it, IF YOU DARE.
+*/
+/**
+* Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ var LinkedList = (function () {
+ /**
+ * Creates a new link, and sets object and next to null.
+ */
+ function LinkedList() {
+ this.object = null;
+ this.next = null;
+ }
+ LinkedList.prototype.destroy = /**
+ * Clean up memory.
+ */
+ function () {
+ this.object = null;
+ if(this.next != null) {
+ this.next.destroy();
+ }
+ this.next = null;
+ };
+ return LinkedList;
+ })();
+ Phaser.LinkedList = LinkedList;
+})(Phaser || (Phaser = {}));
+/// myFunction(Object1:GameObject,Object2:GameObject) that is called whenever two objects are found to overlap in world space, and either no ProcessCallback is specified, or the ProcessCallback returns true.
+ * @param ProcessCallback A function with the form myFunction(Object1:GameObject,Object2:GameObject):bool that is called whenever two objects are found to overlap in world space. The NotifyCallback is only called if this function returns true. See GameObject.separate().
+ */
+ function (ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, ProcessCallback) {
+ if (typeof ObjectOrGroup2 === "undefined") { ObjectOrGroup2 = null; }
+ if (typeof NotifyCallback === "undefined") { NotifyCallback = null; }
+ if (typeof ProcessCallback === "undefined") { ProcessCallback = null; }
+ //console.log('quadtree load', QuadTree.divisions, ObjectOrGroup1, ObjectOrGroup2);
+ this.add(ObjectOrGroup1, QuadTree.A_LIST);
+ if(ObjectOrGroup2 != null) {
+ this.add(ObjectOrGroup2, QuadTree.B_LIST);
+ QuadTree._useBothLists = true;
+ } else {
+ QuadTree._useBothLists = false;
+ }
+ QuadTree._notifyCallback = NotifyCallback;
+ QuadTree._processingCallback = ProcessCallback;
+ //console.log('use both', QuadTree._useBothLists);
+ //console.log('------------ end of load');
+ };
+ QuadTree.prototype.add = /**
+ * Call this function to add an object to the root of the tree.
+ * This function will recursively add all group members, but
+ * not the groups themselves.
+ *
+ * @param ObjectOrGroup GameObjects are just added, Groups are recursed and their applicable members added accordingly.
+ * @param List A uint flag indicating the list to which you want to add the objects. Options are QuadTree.A_LIST and QuadTree.B_LIST.
+ */
+ function (ObjectOrGroup, List) {
+ QuadTree._list = List;
+ if(ObjectOrGroup.isGroup == true) {
+ var i = 0;
+ var basic;
+ var members = ObjectOrGroup['members'];
+ var l = ObjectOrGroup['length'];
+ while(i < l) {
+ basic = members[i++];
+ if((basic != null) && basic.exists) {
+ if(basic.isGroup) {
+ this.add(basic, List);
+ } else {
+ QuadTree._object = basic;
+ if(QuadTree._object.exists && QuadTree._object.allowCollisions) {
+ QuadTree._objectLeftEdge = QuadTree._object.x;
+ QuadTree._objectTopEdge = QuadTree._object.y;
+ QuadTree._objectRightEdge = QuadTree._object.x + QuadTree._object.width;
+ QuadTree._objectBottomEdge = QuadTree._object.y + QuadTree._object.height;
+ this.addObject();
+ }
+ }
+ }
+ }
+ } else {
+ QuadTree._object = ObjectOrGroup;
+ //console.log('add - not group:', ObjectOrGroup.name);
+ if(QuadTree._object.exists && QuadTree._object.allowCollisions) {
+ QuadTree._objectLeftEdge = QuadTree._object.x;
+ QuadTree._objectTopEdge = QuadTree._object.y;
+ QuadTree._objectRightEdge = QuadTree._object.x + QuadTree._object.width;
+ QuadTree._objectBottomEdge = QuadTree._object.y + QuadTree._object.height;
+ //console.log('object properties', QuadTree._objectLeftEdge, QuadTree._objectTopEdge, QuadTree._objectRightEdge, QuadTree._objectBottomEdge);
+ this.addObject();
+ }
+ }
+ };
+ QuadTree.prototype.addObject = /**
+ * Internal function for recursively navigating and creating the tree
+ * while adding objects to the appropriate nodes.
+ */
+ function () {
+ //console.log('addObject');
+ //If this quad (not its children) lies entirely inside this object, add it here
+ if(!this._canSubdivide || ((this._leftEdge >= QuadTree._objectLeftEdge) && (this._rightEdge <= QuadTree._objectRightEdge) && (this._topEdge >= QuadTree._objectTopEdge) && (this._bottomEdge <= QuadTree._objectBottomEdge))) {
+ //console.log('add To List');
+ this.addToList();
+ return;
+ }
+ //See if the selected object fits completely inside any of the quadrants
+ if((QuadTree._objectLeftEdge > this._leftEdge) && (QuadTree._objectRightEdge < this._midpointX)) {
+ if((QuadTree._objectTopEdge > this._topEdge) && (QuadTree._objectBottomEdge < this._midpointY)) {
+ //console.log('Adding NW tree');
+ if(this._northWestTree == null) {
+ this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northWestTree.addObject();
+ return;
+ }
+ if((QuadTree._objectTopEdge > this._midpointY) && (QuadTree._objectBottomEdge < this._bottomEdge)) {
+ //console.log('Adding SW tree');
+ if(this._southWestTree == null) {
+ this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southWestTree.addObject();
+ return;
+ }
+ }
+ if((QuadTree._objectLeftEdge > this._midpointX) && (QuadTree._objectRightEdge < this._rightEdge)) {
+ if((QuadTree._objectTopEdge > this._topEdge) && (QuadTree._objectBottomEdge < this._midpointY)) {
+ //console.log('Adding NE tree');
+ if(this._northEastTree == null) {
+ this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northEastTree.addObject();
+ return;
+ }
+ if((QuadTree._objectTopEdge > this._midpointY) && (QuadTree._objectBottomEdge < this._bottomEdge)) {
+ //console.log('Adding SE tree');
+ if(this._southEastTree == null) {
+ this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southEastTree.addObject();
+ return;
+ }
+ }
+ //If it wasn't completely contained we have to check out the partial overlaps
+ if((QuadTree._objectRightEdge > this._leftEdge) && (QuadTree._objectLeftEdge < this._midpointX) && (QuadTree._objectBottomEdge > this._topEdge) && (QuadTree._objectTopEdge < this._midpointY)) {
+ if(this._northWestTree == null) {
+ this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ //console.log('added to north west partial tree');
+ this._northWestTree.addObject();
+ }
+ if((QuadTree._objectRightEdge > this._midpointX) && (QuadTree._objectLeftEdge < this._rightEdge) && (QuadTree._objectBottomEdge > this._topEdge) && (QuadTree._objectTopEdge < this._midpointY)) {
+ if(this._northEastTree == null) {
+ this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ //console.log('added to north east partial tree');
+ this._northEastTree.addObject();
+ }
+ if((QuadTree._objectRightEdge > this._midpointX) && (QuadTree._objectLeftEdge < this._rightEdge) && (QuadTree._objectBottomEdge > this._midpointY) && (QuadTree._objectTopEdge < this._bottomEdge)) {
+ if(this._southEastTree == null) {
+ this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ //console.log('added to south east partial tree');
+ this._southEastTree.addObject();
+ }
+ if((QuadTree._objectRightEdge > this._leftEdge) && (QuadTree._objectLeftEdge < this._midpointX) && (QuadTree._objectBottomEdge > this._midpointY) && (QuadTree._objectTopEdge < this._bottomEdge)) {
+ if(this._southWestTree == null) {
+ this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ //console.log('added to south west partial tree');
+ this._southWestTree.addObject();
+ }
+ };
+ QuadTree.prototype.addToList = /**
+ * Internal function for recursively adding objects to leaf lists.
+ */
+ function () {
+ //console.log('Adding to List');
+ var ot;
+ if(QuadTree._list == QuadTree.A_LIST) {
+ //console.log('A LIST');
+ if(this._tailA.object != null) {
+ ot = this._tailA;
+ this._tailA = new Phaser.LinkedList();
+ ot.next = this._tailA;
+ }
+ this._tailA.object = QuadTree._object;
+ } else {
+ //console.log('B LIST');
+ if(this._tailB.object != null) {
+ ot = this._tailB;
+ this._tailB = new Phaser.LinkedList();
+ ot.next = this._tailB;
+ }
+ this._tailB.object = QuadTree._object;
+ }
+ if(!this._canSubdivide) {
+ return;
+ }
+ if(this._northWestTree != null) {
+ this._northWestTree.addToList();
+ }
+ if(this._northEastTree != null) {
+ this._northEastTree.addToList();
+ }
+ if(this._southEastTree != null) {
+ this._southEastTree.addToList();
+ }
+ if(this._southWestTree != null) {
+ this._southWestTree.addToList();
+ }
+ };
+ QuadTree.prototype.execute = /**
+ * QuadTree's other main function. Call this after adding objects
+ * using QuadTree.load() to compare the objects that you loaded.
+ *
+ * @return Whether or not any overlaps were found.
+ */
+ function () {
+ //console.log('quadtree execute');
+ var overlapProcessed = false;
+ var iterator;
+ if(this._headA.object != null) {
+ //console.log('---------------------------------------------------');
+ //console.log('headA iterator');
+ iterator = this._headA;
+ while(iterator != null) {
+ QuadTree._object = iterator.object;
+ if(QuadTree._useBothLists) {
+ QuadTree._iterator = this._headB;
+ } else {
+ QuadTree._iterator = iterator.next;
+ }
+ if(QuadTree._object.exists && (QuadTree._object.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode()) {
+ //console.log('headA iterator overlapped true');
+ overlapProcessed = true;
+ }
+ iterator = iterator.next;
+ }
+ }
+ //Advance through the tree by calling overlap on each child
+ if((this._northWestTree != null) && this._northWestTree.execute()) {
+ //console.log('NW quadtree execute');
+ overlapProcessed = true;
+ }
+ if((this._northEastTree != null) && this._northEastTree.execute()) {
+ //console.log('NE quadtree execute');
+ overlapProcessed = true;
+ }
+ if((this._southEastTree != null) && this._southEastTree.execute()) {
+ //console.log('SE quadtree execute');
+ overlapProcessed = true;
+ }
+ if((this._southWestTree != null) && this._southWestTree.execute()) {
+ //console.log('SW quadtree execute');
+ overlapProcessed = true;
+ }
+ return overlapProcessed;
+ };
+ QuadTree.prototype.overlapNode = /**
+ * An private for comparing an object against the contents of a node.
+ *
+ * @return Whether or not any overlaps were found.
+ */
+ function () {
+ //console.log('overlapNode');
+ //Walk the list and check for overlaps
+ var overlapProcessed = false;
+ var checkObject;
+ while(QuadTree._iterator != null) {
+ if(!QuadTree._object.exists || (QuadTree._object.allowCollisions <= 0)) {
+ //console.log('break 1');
+ break;
+ }
+ checkObject = QuadTree._iterator.object;
+ if((QuadTree._object === checkObject) || !checkObject.exists || (checkObject.allowCollisions <= 0)) {
+ //console.log('break 2');
+ QuadTree._iterator = QuadTree._iterator.next;
+ continue;
+ }
+ //calculate bulk hull for QuadTree._object
+ QuadTree._objectHullX = (QuadTree._object.x < QuadTree._object.last.x) ? QuadTree._object.x : QuadTree._object.last.x;
+ QuadTree._objectHullY = (QuadTree._object.y < QuadTree._object.last.y) ? QuadTree._object.y : QuadTree._object.last.y;
+ QuadTree._objectHullWidth = QuadTree._object.x - QuadTree._object.last.x;
+ QuadTree._objectHullWidth = QuadTree._object.width + ((QuadTree._objectHullWidth > 0) ? QuadTree._objectHullWidth : -QuadTree._objectHullWidth);
+ QuadTree._objectHullHeight = QuadTree._object.y - QuadTree._object.last.y;
+ QuadTree._objectHullHeight = QuadTree._object.height + ((QuadTree._objectHullHeight > 0) ? QuadTree._objectHullHeight : -QuadTree._objectHullHeight);
+ //calculate bulk hull for checkObject
+ QuadTree._checkObjectHullX = (checkObject.x < checkObject.last.x) ? checkObject.x : checkObject.last.x;
+ QuadTree._checkObjectHullY = (checkObject.y < checkObject.last.y) ? checkObject.y : checkObject.last.y;
+ QuadTree._checkObjectHullWidth = checkObject.x - checkObject.last.x;
+ QuadTree._checkObjectHullWidth = checkObject.width + ((QuadTree._checkObjectHullWidth > 0) ? QuadTree._checkObjectHullWidth : -QuadTree._checkObjectHullWidth);
+ QuadTree._checkObjectHullHeight = checkObject.y - checkObject.last.y;
+ QuadTree._checkObjectHullHeight = checkObject.height + ((QuadTree._checkObjectHullHeight > 0) ? QuadTree._checkObjectHullHeight : -QuadTree._checkObjectHullHeight);
+ //check for intersection of the two hulls
+ if((QuadTree._objectHullX + QuadTree._objectHullWidth > QuadTree._checkObjectHullX) && (QuadTree._objectHullX < QuadTree._checkObjectHullX + QuadTree._checkObjectHullWidth) && (QuadTree._objectHullY + QuadTree._objectHullHeight > QuadTree._checkObjectHullY) && (QuadTree._objectHullY < QuadTree._checkObjectHullY + QuadTree._checkObjectHullHeight)) {
+ //console.log('intersection!');
+ //Execute callback functions if they exist
+ if((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, checkObject)) {
+ overlapProcessed = true;
+ }
+ if(overlapProcessed && (QuadTree._notifyCallback != null)) {
+ QuadTree._notifyCallback(QuadTree._object, checkObject);
+ }
+ }
+ QuadTree._iterator = QuadTree._iterator.next;
+ }
+ return overlapProcessed;
+ };
+ return QuadTree;
+ })(Phaser.Rectangle);
+ Phaser.QuadTree = QuadTree;
+})(Phaser || (Phaser = {}));
+/// GameObject 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 Group (or even bundling groups together!).
+ *
+ * NOTE: does NOT take objects' scrollfactor into account, all overlaps are checked in world space.
+ * + * @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 twoGameObject parameters - e.g. myOverlapFunction(Object1:GameObject,Object2:GameObject) - that is called if those two objects overlap.
+ * @param ProcessCallback A function with two GameObject parameters - e.g. myOverlapFunction(Object1:GameObject,Object2:GameObject) - 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.
+ */
+ function (ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, ProcessCallback) {
+ if (typeof ObjectOrGroup1 === "undefined") { ObjectOrGroup1 = null; }
+ if (typeof ObjectOrGroup2 === "undefined") { ObjectOrGroup2 = null; }
+ if (typeof NotifyCallback === "undefined") { NotifyCallback = null; }
+ if (typeof ProcessCallback === "undefined") { ProcessCallback = null; }
+ if(ObjectOrGroup1 == null) {
+ ObjectOrGroup1 = this._game.world.group;
+ }
+ if(ObjectOrGroup2 == ObjectOrGroup1) {
+ ObjectOrGroup2 = null;
+ }
+ Phaser.QuadTree.divisions = this._game.world.worldDivisions;
+ var quadTree = new Phaser.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 = quadTree.execute();
+ quadTree.destroy();
+ quadTree = null;
+ return result;
+ };
+ Collision.separate = /**
+ * The main collision resolution in flixel.
+ *
+ * @param Object1 Any Sprite.
+ * @param Object2 Any other Sprite.
+ *
+ * @return Whether the objects in fact touched and were separated.
+ */
+ function separate(Object1, Object2) {
+ var separatedX = Collision.separateX(Object1, Object2);
+ var separatedY = Collision.separateY(Object1, Object2);
+ return separatedX || separatedY;
+ };
+ Collision.separateX = /**
+ * The X-axis component of the object separation process.
+ *
+ * @param Object1 Any Sprite.
+ * @param Object2 Any other Sprite.
+ *
+ * @return Whether the objects in fact touched and were separated along the X axis.
+ */
+ function separateX(Object1, Object2) {
+ //can't separate two immovable objects
+ var obj1immovable = Object1.immovable;
+ var obj2immovable = 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 = 0;
+ var obj1delta = Object1.x - Object1.last.x;
+ var obj2delta = Object2.x - Object2.last.x;
+ if(obj1delta != obj2delta) {
+ //Check if the X hulls actually overlap
+ var obj1deltaAbs = (obj1delta > 0) ? obj1delta : -obj1delta;
+ var obj2deltaAbs = (obj2delta > 0) ? obj2delta : -obj2delta;
+ var obj1rect = new Phaser.Rectangle(Object1.x - ((obj1delta > 0) ? obj1delta : 0), Object1.last.y, Object1.width + ((obj1delta > 0) ? obj1delta : -obj1delta), Object1.height);
+ var obj2rect = new Phaser.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 = 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 = Object1.velocity.x;
+ var obj2v = Object2.velocity.x;
+ if(!obj1immovable && !obj2immovable) {
+ overlap *= 0.5;
+ Object1.x = Object1.x - overlap;
+ Object2.x += overlap;
+ var obj1velocity = Math.sqrt((obj2v * obj2v * Object2.mass) / Object1.mass) * ((obj2v > 0) ? 1 : -1);
+ var obj2velocity = Math.sqrt((obj1v * obj1v * Object1.mass) / Object2.mass) * ((obj1v > 0) ? 1 : -1);
+ var average = (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;
+ }
+ };
+ Collision.separateY = /**
+ * The Y-axis component of the object separation process.
+ *
+ * @param Object1 Any Sprite.
+ * @param Object2 Any other Sprite.
+ *
+ * @return Whether the objects in fact touched and were separated along the Y axis.
+ */
+ function separateY(Object1, Object2) {
+ //can't separate two immovable objects
+ var obj1immovable = Object1.immovable;
+ var obj2immovable = 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 = 0;
+ var obj1delta = Object1.y - Object1.last.y;
+ var obj2delta = Object2.y - Object2.last.y;
+ if(obj1delta != obj2delta) {
+ //Check if the Y hulls actually overlap
+ var obj1deltaAbs = (obj1delta > 0) ? obj1delta : -obj1delta;
+ var obj2deltaAbs = (obj2delta > 0) ? obj2delta : -obj2delta;
+ var obj1rect = new Phaser.Rectangle(Object1.x, Object1.y - ((obj1delta > 0) ? obj1delta : 0), Object1.width, Object1.height + obj1deltaAbs);
+ var obj2rect = new Phaser.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 = 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 = Object1.velocity.y;
+ var obj2v = Object2.velocity.y;
+ if(!obj1immovable && !obj2immovable) {
+ overlap *= 0.5;
+ Object1.y = Object1.y - overlap;
+ Object2.y += overlap;
+ var obj1velocity = Math.sqrt((obj2v * obj2v * Object2.mass) / Object1.mass) * ((obj2v > 0) ? 1 : -1);
+ var obj2velocity = Math.sqrt((obj1v * obj1v * Object1.mass) / Object2.mass) * ((obj1v > 0) ? 1 : -1);
+ var average = (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;
+ }
+ };
+ Collision.distance = /**
+ * -------------------------------------------------------------------------------------------
+ * Distance
+ * -------------------------------------------------------------------------------------------
+ **/
+ function distance(x1, y1, x2, y2) {
+ return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
+ };
+ Collision.distanceSquared = function distanceSquared(x1, y1, x2, y2) {
+ return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
+ };
+ return Collision;
+ })();
+ Phaser.Collision = Collision;
+})(Phaser || (Phaser = {}));
+/// + * Returns true or false based on the chance value (default 50%). For example if you wanted a player to have a 30% chance + * of getting a bonus, call chanceRoll(30) - true means the chance passed, false means it failed. + *
+ * @param chance The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%) + * @return true if the roll passed, or false + */ + function (chance) { + if (typeof chance === "undefined") { chance = 50; } + if(chance <= 0) { + return false; + } else if(chance >= 100) { + return true; + } else { + if(Math.random() * 100 >= chance) { + return false; + } else { + return true; + } + } + }; + GameMath.prototype.maxAdd = /** + * Adds the given amount to the value, but never lets the value go over the specified maximum + * + * @param value The value to add the amount to + * @param amount The amount to add to the value + * @param max The maximum the value is allowed to be + * @return The new value + */ + function (value, amount, max) { + value += amount; + if(value > max) { + value = max; + } + return value; + }; + GameMath.prototype.minSub = /** + * Subtracts the given amount from the value, but never lets the value go below the specified minimum + * + * @param value The base value + * @param amount The amount to subtract from the base value + * @param min The minimum the value is allowed to be + * @return The new value + */ + function (value, amount, min) { + value -= amount; + if(value < min) { + value = min; + } + return value; + }; + GameMath.prototype.wrapValue = /** + * Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around. + *Values must be positive integers, and are passed through Math.abs
+ * + * @param value The value to add the amount to + * @param amount The amount to add to the value + * @param max The maximum the value is allowed to be + * @return The wrapped value + */ + function (value, amount, max) { + var diff; + value = Math.abs(value); + amount = Math.abs(amount); + max = Math.abs(max); + diff = (value + amount) % max; + return diff; + }; + GameMath.prototype.randomSign = /** + * Randomly returns either a 1 or -1 + * + * @return 1 or -1 + */ + function () { + return (Math.random() > 0.5) ? 1 : -1; + }; + GameMath.prototype.isOdd = /** + * Returns true if the number given is odd. + * + * @param n The number to check + * + * @return True if the given number is odd. False if the given number is even. + */ + function (n) { + if(n & 1) { + return true; + } else { + return false; + } + }; + GameMath.prototype.isEven = /** + * Returns true if the number given is even. + * + * @param n The number to check + * + * @return True if the given number is even. False if the given number is odd. + */ + function (n) { + if(n & 1) { + return false; + } else { + return true; + } + }; + GameMath.prototype.wrapAngle = /** + * Keeps an angle value between -180 and +180Number between 0 and 1.
+ */
+ function () {
+ return this.globalSeed = this.srand(this.globalSeed);
+ };
+ GameMath.prototype.srand = /**
+ * Generates a random number based on the seed provided.
+ *
+ * @param Seed A number between 0 and 1, used to generate a predictable random number (very optional).
+ *
+ * @return A Number between 0 and 1.
+ */
+ function (Seed) {
+ return ((69621 * (Seed * 0x7FFFFFFF)) % 0x7FFFFFFF) / 0x7FFFFFFF;
+ };
+ GameMath.prototype.getRandom = /**
+ * Fetch a random entry from the given array.
+ * Will return null if random selection is missing, or array has no entries.
+ * FlxG.getRandom() is deterministic and safe for use with replays/recordings.
+ * HOWEVER, FlxU.getRandom() is NOT deterministic and unsafe for use with replays/recordings.
+ *
+ * @param Objects An array of objects.
+ * @param StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
+ * @param Length Optional restriction on the number of values you want to randomly select from.
+ *
+ * @return The random object that was selected.
+ */
+ function (Objects, StartIndex, Length) {
+ if (typeof StartIndex === "undefined") { StartIndex = 0; }
+ if (typeof Length === "undefined") { Length = 0; }
+ if(Objects != null) {
+ var l = Length;
+ if((l == 0) || (l > Objects.length - StartIndex)) {
+ l = Objects.length - StartIndex;
+ }
+ if(l > 0) {
+ return Objects[StartIndex + Math.floor(Math.random() * l)];
+ }
+ }
+ return null;
+ };
+ GameMath.prototype.floor = /**
+ * Round down to the next whole number. E.g. floor(1.7) == 1, and floor(-2.7) == -2.
+ *
+ * @param Value Any number.
+ *
+ * @return The rounded value of that number.
+ */
+ function (Value) {
+ var n = Value | 0;
+ return (Value > 0) ? (n) : ((n != Value) ? (n - 1) : (n));
+ };
+ GameMath.prototype.ceil = /**
+ * Round up to the next whole number. E.g. ceil(1.3) == 2, and ceil(-2.3) == -3.
+ *
+ * @param Value Any number.
+ *
+ * @return The rounded value of that number.
+ */
+ function (Value) {
+ var n = Value | 0;
+ return (Value > 0) ? ((n != Value) ? (n + 1) : (n)) : (n);
+ };
+ GameMath.prototype.sinCosGenerator = /**
+ * Generate a sine and cosine table simultaneously and extremely quickly. Based on research by Franky of scene.at
+ * + * The parameters allow you to specify the length, amplitude and frequency of the wave. Once you have called this function + * you should get the results via getSinTable() and getCosTable(). This generator is fast enough to be used in real-time. + *
+ * @param length The length of the wave + * @param sinAmplitude The amplitude to apply to the sine table (default 1.0) if you need values between say -+ 125 then give 125 as the value + * @param cosAmplitude The amplitude to apply to the cosine table (default 1.0) if you need values between say -+ 125 then give 125 as the value + * @param frequency The frequency of the sine and cosine table data + * @return Returns the sine table + * @see getSinTable + * @see getCosTable + */ + function (length, sinAmplitude, cosAmplitude, frequency) { + if (typeof sinAmplitude === "undefined") { sinAmplitude = 1.0; } + if (typeof cosAmplitude === "undefined") { cosAmplitude = 1.0; } + if (typeof frequency === "undefined") { frequency = 1.0; } + var sin = sinAmplitude; + var cos = cosAmplitude; + var frq = frequency * Math.PI / length; + this.cosTable = []; + this.sinTable = []; + for(var c = 0; c < length; c++) { + cos -= sin * frq; + sin += cos * frq; + this.cosTable[c] = cos; + this.sinTable[c] = sin; + } + return this.sinTable; + }; + GameMath.prototype.vectorLength = /** + * Finds the length of the given vector + * + * @param dx + * @param dy + * + * @return + */ + function (dx, dy) { + return Math.sqrt(dx * dx + dy * dy); + }; + GameMath.prototype.dotProduct = /** + * 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 + */ + function (ax, ay, bx, by) { + return ax * bx + ay * by; + }; + return GameMath; + })(); + Phaser.GameMath = GameMath; +})(Phaser || (Phaser = {})); ///Basics.
* NOTE: Although Group extends Basic, it will not automatically
@@ -3014,2988 +5006,1114 @@ var Sprite = (function (_super) {
* @author Adam Atomic
* @author Richard Davey
*/
-var Group = (function (_super) {
- __extends(Group, _super);
- function Group(game, MaxSize) {
- if (typeof MaxSize === "undefined") { MaxSize = 0; }
- _super.call(this, game);
- this.isGroup = true;
- this.members = [];
- this.length = 0;
- this._maxSize = MaxSize;
- this._marker = 0;
- this._sortIndex = null;
- }
- Group.ASCENDING = -1;
- Group.DESCENDING = 1;
- Group.prototype.destroy = /**
- * Override this function to handle any deleting or "shutdown" type operations you might need,
- * such as removing traditional Flash children like Basic objects.
- */
- function () {
- if(this.members != null) {
+/**
+* Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ var Group = (function (_super) {
+ __extends(Group, _super);
+ function Group(game, MaxSize) {
+ if (typeof MaxSize === "undefined") { MaxSize = 0; }
+ _super.call(this, game);
+ this.isGroup = true;
+ this.members = [];
+ this.length = 0;
+ this._maxSize = MaxSize;
+ this._marker = 0;
+ this._sortIndex = null;
+ }
+ Group.ASCENDING = -1;
+ Group.DESCENDING = 1;
+ Group.prototype.destroy = /**
+ * Override this function to handle any deleting or "shutdown" type operations you might need,
+ * such as removing traditional Flash children like Basic objects.
+ */
+ function () {
+ if(this.members != null) {
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if(basic != null) {
+ basic.destroy();
+ }
+ }
+ this.members.length = 0;
+ }
+ this._sortIndex = null;
+ };
+ Group.prototype.update = /**
+ * Automatically goes through and calls update on everything you added.
+ */
+ function () {
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if((basic != null) && basic.exists && basic.active) {
+ basic.preUpdate();
+ basic.update();
+ basic.postUpdate();
+ }
+ }
+ };
+ Group.prototype.render = /**
+ * Automatically goes through and calls render on everything you added.
+ */
+ function (camera, cameraOffsetX, cameraOffsetY) {
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if((basic != null) && basic.exists && basic.visible) {
+ basic.render(camera, cameraOffsetX, cameraOffsetY);
+ }
+ }
+ };
+ Object.defineProperty(Group.prototype, "maxSize", {
+ get: /**
+ * The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow.
+ */
+ function () {
+ return this._maxSize;
+ },
+ set: /**
+ * @private
+ */
+ function (Size) {
+ this._maxSize = Size;
+ if(this._marker >= this._maxSize) {
+ this._marker = 0;
+ }
+ if((this._maxSize == 0) || (this.members == null) || (this._maxSize >= this.members.length)) {
+ return;
+ }
+ //If the max size has shrunk, we need to get rid of some objects
+ var basic;
+ var i = this._maxSize;
+ var l = this.members.length;
+ while(i < l) {
+ basic = this.members[i++];
+ if(basic != null) {
+ basic.destroy();
+ }
+ }
+ this.length = this.members.length = this._maxSize;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Group.prototype.add = /**
+ * Adds a new Basic subclass (Basic, FlxBasic, Enemy, etc) to the group.
+ * Group will try to replace a null member of the array first.
+ * Failing that, Group will add it to the end of the member array,
+ * assuming there is room for it, and doubling the size of the array if necessary.
+ *
+ * WARNING: If the group has a maxSize that has already been met, + * the object will NOT be added to the group!
+ * + * @param Object The object you want to add to the group. + * + * @return The sameBasic object that was passed in.
+ */
+ function (Object) {
+ //Don't bother adding an object twice.
+ if(this.members.indexOf(Object) >= 0) {
+ return Object;
+ }
+ //First, look for a null entry where we can add the object.
+ var i = 0;
+ var l = this.members.length;
+ while(i < l) {
+ if(this.members[i] == null) {
+ this.members[i] = Object;
+ if(i >= this.length) {
+ this.length = i + 1;
+ }
+ return Object;
+ }
+ i++;
+ }
+ //Failing that, expand the array (if we can) and add the object.
+ if(this._maxSize > 0) {
+ if(this.members.length >= this._maxSize) {
+ return Object;
+ } else if(this.members.length * 2 <= this._maxSize) {
+ this.members.length *= 2;
+ } else {
+ this.members.length = this._maxSize;
+ }
+ } else {
+ this.members.length *= 2;
+ }
+ //If we made it this far, then we successfully grew the group,
+ //and we can go ahead and add the object at the first open slot.
+ this.members[i] = Object;
+ this.length = i + 1;
+ return Object;
+ };
+ Group.prototype.recycle = /**
+ * Recycling is designed to help you reuse game objects without always re-allocating or "newing" them.
+ *
+ * If you specified a maximum size for this group (like in Emitter), + * then recycle will employ what we're calling "rotating" recycling. + * Recycle() will first check to see if the group is at capacity yet. + * If group is not yet at capacity, recycle() returns a new object. + * If the group IS at capacity, then recycle() just returns the next object in line.
+ * + *If you did NOT specify a maximum size for this group, + * then recycle() will employ what we're calling "grow-style" recycling. + * Recycle() will return either the first object with exists == false, + * or, finding none, add a new object to the array, + * doubling the size of the array if necessary.
+ * + *WARNING: If this function needs to create a new object, + * and no object class was provided, it will return null + * instead of a valid object!
+ * + * @param ObjectClass The class type you want to recycle (e.g. FlxBasic, EvilRobot, etc). Do NOT "new" the class in the parameter! + * + * @return A reference to the object that was created. Don't forget to cast it back to the Class you want (e.g. myObject = myGroup.recycle(myObjectClass) as myObjectClass;). + */ + function (ObjectClass) { + if (typeof ObjectClass === "undefined") { ObjectClass = null; } + var basic; + if(this._maxSize > 0) { + if(this.length < this._maxSize) { + if(ObjectClass == null) { + return null; + } + return this.add(new ObjectClass()); + } else { + basic = this.members[this._marker++]; + if(this._marker >= this._maxSize) { + this._marker = 0; + } + return basic; + } + } else { + basic = this.getFirstAvailable(ObjectClass); + if(basic != null) { + return basic; + } + if(ObjectClass == null) { + return null; + } + return this.add(new ObjectClass()); + } + }; + Group.prototype.remove = /** + * Removes an object from the group. + * + * @param Object TheBasic you want to remove.
+ * @param Splice Whether the object should be cut from the array entirely or not.
+ *
+ * @return The removed object.
+ */
+ function (Object, Splice) {
+ if (typeof Splice === "undefined") { Splice = false; }
+ var index = this.members.indexOf(Object);
+ if((index < 0) || (index >= this.members.length)) {
+ return null;
+ }
+ if(Splice) {
+ this.members.splice(index, 1);
+ this.length--;
+ } else {
+ this.members[index] = null;
+ }
+ return Object;
+ };
+ Group.prototype.replace = /**
+ * Replaces an existing Basic with a new one.
+ *
+ * @param OldObject The object you want to replace.
+ * @param NewObject The new object you want to use instead.
+ *
+ * @return The new object.
+ */
+ function (OldObject, NewObject) {
+ var index = this.members.indexOf(OldObject);
+ if((index < 0) || (index >= this.members.length)) {
+ return null;
+ }
+ this.members[index] = NewObject;
+ return NewObject;
+ };
+ Group.prototype.sort = /**
+ * Call this function to sort the group according to a particular value and order.
+ * For example, to sort game objects for Zelda-style overlaps you might call
+ * myGroup.sort("y",Group.ASCENDING) at the bottom of your
+ * FlxState.update() override. To sort all existing objects after
+ * a big explosion or bomb attack, you might call myGroup.sort("exists",Group.DESCENDING).
+ *
+ * @param Index The string name of the member variable you want to sort on. Default value is "y".
+ * @param Order A Group constant that defines the sort order. Possible values are Group.ASCENDING and Group.DESCENDING. Default value is Group.ASCENDING.
+ */
+ function (Index, Order) {
+ if (typeof Index === "undefined") { Index = "y"; }
+ if (typeof Order === "undefined") { Order = Group.ASCENDING; }
+ this._sortIndex = Index;
+ this._sortOrder = Order;
+ this.members.sort(this.sortHandler);
+ };
+ Group.prototype.setAll = /**
+ * Go through and set the specified variable to the specified value on all members of the group.
+ *
+ * @param VariableName The string representation of the variable name you want to modify, for example "visible" or "scrollFactor".
+ * @param Value The value you want to assign to that variable.
+ * @param Recurse Default value is true, meaning if setAll() encounters a member that is a group, it will call setAll() on that group rather than modifying its variable.
+ */
+ function (VariableName, Value, Recurse) {
+ if (typeof Recurse === "undefined") { Recurse = true; }
+ var basic;
+ var i = 0;
+ while(i < length) {
+ basic = this.members[i++];
+ if(basic != null) {
+ if(Recurse && (basic.isGroup == true)) {
+ basic['setAll'](VariableName, Value, Recurse);
+ } else {
+ basic[VariableName] = Value;
+ }
+ }
+ }
+ };
+ Group.prototype.callAll = /**
+ * Go through and call the specified function on all members of the group.
+ * Currently only works on functions that have no required parameters.
+ *
+ * @param FunctionName The string representation of the function you want to call on each object, for example "kill()" or "init()".
+ * @param Recurse Default value is true, meaning if callAll() encounters a member that is a group, it will call callAll() on that group rather than calling the group's function.
+ */
+ function (FunctionName, Recurse) {
+ if (typeof Recurse === "undefined") { Recurse = true; }
var basic;
var i = 0;
while(i < this.length) {
basic = this.members[i++];
if(basic != null) {
- basic.destroy();
+ if(Recurse && (basic.isGroup == true)) {
+ basic['callAll'](FunctionName, Recurse);
+ } else {
+ basic[FunctionName]();
+ }
}
}
- this.members.length = 0;
- }
- this._sortIndex = null;
- };
- Group.prototype.update = /**
- * Automatically goes through and calls update on everything you added.
- */
- function () {
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if((basic != null) && basic.exists && basic.active) {
- basic.preUpdate();
- basic.update();
- basic.postUpdate();
- }
- }
- };
- Group.prototype.render = /**
- * Automatically goes through and calls render on everything you added.
- */
- function (camera, cameraOffsetX, cameraOffsetY) {
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if((basic != null) && basic.exists && basic.visible) {
- basic.render(camera, cameraOffsetX, cameraOffsetY);
- }
- }
- };
- Object.defineProperty(Group.prototype, "maxSize", {
- get: /**
- * The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow.
- */
- function () {
- return this._maxSize;
- },
- set: /**
- * @private
- */
- function (Size) {
- this._maxSize = Size;
- if(this._marker >= this._maxSize) {
- this._marker = 0;
- }
- if((this._maxSize == 0) || (this.members == null) || (this._maxSize >= this.members.length)) {
- return;
- }
- //If the max size has shrunk, we need to get rid of some objects
+ };
+ Group.prototype.forEach = function (callback, Recurse) {
+ if (typeof Recurse === "undefined") { Recurse = false; }
var basic;
- var i = this._maxSize;
- var l = this.members.length;
- while(i < l) {
+ var i = 0;
+ while(i < this.length) {
basic = this.members[i++];
if(basic != null) {
- basic.destroy();
- }
- }
- this.length = this.members.length = this._maxSize;
- },
- enumerable: true,
- configurable: true
- });
- Group.prototype.add = /**
- * Adds a new Basic subclass (Basic, FlxBasic, Enemy, etc) to the group.
- * Group will try to replace a null member of the array first.
- * Failing that, Group will add it to the end of the member array,
- * assuming there is room for it, and doubling the size of the array if necessary.
- *
- * WARNING: If the group has a maxSize that has already been met, - * the object will NOT be added to the group!
- * - * @param Object The object you want to add to the group. - * - * @return The sameBasic object that was passed in.
- */
- function (Object) {
- //Don't bother adding an object twice.
- if(this.members.indexOf(Object) >= 0) {
- return Object;
- }
- //First, look for a null entry where we can add the object.
- var i = 0;
- var l = this.members.length;
- while(i < l) {
- if(this.members[i] == null) {
- this.members[i] = Object;
- if(i >= this.length) {
- this.length = i + 1;
- }
- return Object;
- }
- i++;
- }
- //Failing that, expand the array (if we can) and add the object.
- if(this._maxSize > 0) {
- if(this.members.length >= this._maxSize) {
- return Object;
- } else if(this.members.length * 2 <= this._maxSize) {
- this.members.length *= 2;
- } else {
- this.members.length = this._maxSize;
- }
- } else {
- this.members.length *= 2;
- }
- //If we made it this far, then we successfully grew the group,
- //and we can go ahead and add the object at the first open slot.
- this.members[i] = Object;
- this.length = i + 1;
- return Object;
- };
- Group.prototype.recycle = /**
- * Recycling is designed to help you reuse game objects without always re-allocating or "newing" them.
- *
- * If you specified a maximum size for this group (like in Emitter), - * then recycle will employ what we're calling "rotating" recycling. - * Recycle() will first check to see if the group is at capacity yet. - * If group is not yet at capacity, recycle() returns a new object. - * If the group IS at capacity, then recycle() just returns the next object in line.
- * - *If you did NOT specify a maximum size for this group, - * then recycle() will employ what we're calling "grow-style" recycling. - * Recycle() will return either the first object with exists == false, - * or, finding none, add a new object to the array, - * doubling the size of the array if necessary.
- * - *WARNING: If this function needs to create a new object, - * and no object class was provided, it will return null - * instead of a valid object!
- * - * @param ObjectClass The class type you want to recycle (e.g. FlxBasic, EvilRobot, etc). Do NOT "new" the class in the parameter! - * - * @return A reference to the object that was created. Don't forget to cast it back to the Class you want (e.g. myObject = myGroup.recycle(myObjectClass) as myObjectClass;). - */ - function (ObjectClass) { - if (typeof ObjectClass === "undefined") { ObjectClass = null; } - var basic; - if(this._maxSize > 0) { - if(this.length < this._maxSize) { - if(ObjectClass == null) { - return null; - } - return this.add(new ObjectClass()); - } else { - basic = this.members[this._marker++]; - if(this._marker >= this._maxSize) { - this._marker = 0; - } - return basic; - } - } else { - basic = this.getFirstAvailable(ObjectClass); - if(basic != null) { - return basic; - } - if(ObjectClass == null) { - return null; - } - return this.add(new ObjectClass()); - } - }; - Group.prototype.remove = /** - * Removes an object from the group. - * - * @param Object TheBasic you want to remove.
- * @param Splice Whether the object should be cut from the array entirely or not.
- *
- * @return The removed object.
- */
- function (Object, Splice) {
- if (typeof Splice === "undefined") { Splice = false; }
- var index = this.members.indexOf(Object);
- if((index < 0) || (index >= this.members.length)) {
- return null;
- }
- if(Splice) {
- this.members.splice(index, 1);
- this.length--;
- } else {
- this.members[index] = null;
- }
- return Object;
- };
- Group.prototype.replace = /**
- * Replaces an existing Basic with a new one.
- *
- * @param OldObject The object you want to replace.
- * @param NewObject The new object you want to use instead.
- *
- * @return The new object.
- */
- function (OldObject, NewObject) {
- var index = this.members.indexOf(OldObject);
- if((index < 0) || (index >= this.members.length)) {
- return null;
- }
- this.members[index] = NewObject;
- return NewObject;
- };
- Group.prototype.sort = /**
- * Call this function to sort the group according to a particular value and order.
- * For example, to sort game objects for Zelda-style overlaps you might call
- * myGroup.sort("y",Group.ASCENDING) at the bottom of your
- * FlxState.update() override. To sort all existing objects after
- * a big explosion or bomb attack, you might call myGroup.sort("exists",Group.DESCENDING).
- *
- * @param Index The string name of the member variable you want to sort on. Default value is "y".
- * @param Order A Group constant that defines the sort order. Possible values are Group.ASCENDING and Group.DESCENDING. Default value is Group.ASCENDING.
- */
- function (Index, Order) {
- if (typeof Index === "undefined") { Index = "y"; }
- if (typeof Order === "undefined") { Order = Group.ASCENDING; }
- this._sortIndex = Index;
- this._sortOrder = Order;
- this.members.sort(this.sortHandler);
- };
- Group.prototype.setAll = /**
- * Go through and set the specified variable to the specified value on all members of the group.
- *
- * @param VariableName The string representation of the variable name you want to modify, for example "visible" or "scrollFactor".
- * @param Value The value you want to assign to that variable.
- * @param Recurse Default value is true, meaning if setAll() encounters a member that is a group, it will call setAll() on that group rather than modifying its variable.
- */
- function (VariableName, Value, Recurse) {
- if (typeof Recurse === "undefined") { Recurse = true; }
- var basic;
- var i = 0;
- while(i < length) {
- basic = this.members[i++];
- if(basic != null) {
- if(Recurse && (basic.isGroup == true)) {
- basic['setAll'](VariableName, Value, Recurse);
- } else {
- basic[VariableName] = Value;
- }
- }
- }
- };
- Group.prototype.callAll = /**
- * Go through and call the specified function on all members of the group.
- * Currently only works on functions that have no required parameters.
- *
- * @param FunctionName The string representation of the function you want to call on each object, for example "kill()" or "init()".
- * @param Recurse Default value is true, meaning if callAll() encounters a member that is a group, it will call callAll() on that group rather than calling the group's function.
- */
- function (FunctionName, Recurse) {
- if (typeof Recurse === "undefined") { Recurse = true; }
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if(basic != null) {
- if(Recurse && (basic.isGroup == true)) {
- basic['callAll'](FunctionName, Recurse);
- } else {
- basic[FunctionName]();
- }
- }
- }
- };
- Group.prototype.forEach = function (callback, Recurse) {
- if (typeof Recurse === "undefined") { Recurse = false; }
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if(basic != null) {
- if(Recurse && (basic.isGroup == true)) {
- basic.forEach(callback, true);
- } else {
- callback.call(this, basic);
- }
- }
- }
- };
- Group.prototype.getFirstAvailable = /**
- * Call this function to retrieve the first object with exists == false in the group.
- * This is handy for recycling in general, e.g. respawning enemies.
- *
- * @param ObjectClass An optional parameter that lets you narrow the results to instances of this particular class.
- *
- * @return A Basic currently flagged as not existing.
- */
- function (ObjectClass) {
- if (typeof ObjectClass === "undefined") { ObjectClass = null; }
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if((basic != null) && !basic.exists && ((ObjectClass == null) || (typeof basic === ObjectClass))) {
- return basic;
- }
- }
- return null;
- };
- Group.prototype.getFirstNull = /**
- * Call this function to retrieve the first index set to 'null'.
- * Returns -1 if no index stores a null object.
- *
- * @return An int indicating the first null slot in the group.
- */
- function () {
- var basic;
- var i = 0;
- var l = this.members.length;
- while(i < l) {
- if(this.members[i] == null) {
- return i;
- } else {
- i++;
- }
- }
- return -1;
- };
- Group.prototype.getFirstExtant = /**
- * Call this function to retrieve the first object with exists == true in the group.
- * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
- *
- * @return A Basic currently flagged as existing.
- */
- function () {
- var basic;
- var i = 0;
- while(i < length) {
- basic = this.members[i++];
- if((basic != null) && basic.exists) {
- return basic;
- }
- }
- return null;
- };
- Group.prototype.getFirstAlive = /**
- * Call this function to retrieve the first object with dead == false in the group.
- * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
- *
- * @return A Basic currently flagged as not dead.
- */
- function () {
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if((basic != null) && basic.exists && basic.alive) {
- return basic;
- }
- }
- return null;
- };
- Group.prototype.getFirstDead = /**
- * Call this function to retrieve the first object with dead == true in the group.
- * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
- *
- * @return A Basic currently flagged as dead.
- */
- function () {
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if((basic != null) && !basic.alive) {
- return basic;
- }
- }
- return null;
- };
- Group.prototype.countLiving = /**
- * Call this function to find out how many members of the group are not dead.
- *
- * @return The number of Basics flagged as not dead. Returns -1 if group is empty.
- */
- function () {
- var count = -1;
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if(basic != null) {
- if(count < 0) {
- count = 0;
- }
- if(basic.exists && basic.alive) {
- count++;
- }
- }
- }
- return count;
- };
- Group.prototype.countDead = /**
- * Call this function to find out how many members of the group are dead.
- *
- * @return The number of Basics flagged as dead. Returns -1 if group is empty.
- */
- function () {
- var count = -1;
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if(basic != null) {
- if(count < 0) {
- count = 0;
- }
- if(!basic.alive) {
- count++;
- }
- }
- }
- return count;
- };
- Group.prototype.getRandom = /**
- * Returns a member at random from the group.
- *
- * @param StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
- * @param Length Optional restriction on the number of values you want to randomly select from.
- *
- * @return A Basic from the members list.
- */
- function (StartIndex, Length) {
- if (typeof StartIndex === "undefined") { StartIndex = 0; }
- if (typeof Length === "undefined") { Length = 0; }
- if(Length == 0) {
- Length = this.length;
- }
- return this._game.math.getRandom(this.members, StartIndex, Length);
- };
- Group.prototype.clear = /**
- * Remove all instances of Basic subclass (FlxBasic, FlxBlock, etc) from the list.
- * WARNING: does not destroy() or kill() any of these objects!
- */
- function () {
- this.length = this.members.length = 0;
- };
- Group.prototype.kill = /**
- * Calls kill on the group's members and then on the group itself.
- */
- function () {
- var basic;
- var i = 0;
- while(i < this.length) {
- basic = this.members[i++];
- if((basic != null) && basic.exists) {
- basic.kill();
- }
- }
- };
- Group.prototype.sortHandler = /**
- * Helper function for the sort process.
- *
- * @param Obj1 The first object being sorted.
- * @param Obj2 The second object being sorted.
- *
- * @return An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
- */
- function (Obj1, Obj2) {
- if(Obj1[this._sortIndex] < Obj2[this._sortIndex]) {
- return this._sortOrder;
- } else if(Obj1[this._sortIndex] > Obj2[this._sortIndex]) {
- return -this._sortOrder;
- }
- return 0;
- };
- return Group;
-})(Basic);
-/// Sprite to have slightly more specialized behavior
-* common to many game scenarios. You can override and extend this class
-* just like you would Sprite. While Emitter
-* used to work with just any old sprite, it now requires a
-* Particle based class.
-*
-* @author Adam Atomic
-* @author Richard Davey
-*/
-var Particle = (function (_super) {
- __extends(Particle, _super);
- /**
- * Instantiate a new particle. Like Sprite, all meaningful creation
- * happens during loadGraphic() or makeGraphic() or whatever.
- */
- function Particle(game) {
- _super.call(this, game);
- this.lifespan = 0;
- this.friction = 500;
- }
- Particle.prototype.update = /**
- * 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.
- */
- function () {
- //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;
- }
+ if(Recurse && (basic.isGroup == true)) {
+ basic.forEach(callback, true);
} else {
- this.velocity.y = 0;
- this.angularVelocity = 0;
+ callback.call(this, basic);
}
}
- } else {
- this.drag.x = 0;
}
- }
- };
- Particle.prototype.onEmit = /**
- * Triggered whenever this object is launched by a Emitter.
- * You can override this to add custom behavior like a sound or AI or something.
- */
- function () {
- };
- return Particle;
-})(Sprite);
-/// Emitter is a lightweight particle emitter.
-* It can be used for one-time explosions or for
-* continuous fx like rain and fire. Emitter
-* is not optimized or anything; all it does is launch
-* Particle objects out at set intervals
-* by setting their positions and velocities accordingly.
-* It is easy to use and relatively efficient,
-* relying on Group's RECYCLE POWERS.
-*
-* @author Adam Atomic
-* @author Richard Davey
-*/
-var Emitter = (function (_super) {
- __extends(Emitter, _super);
- /**
- * Creates a new FlxEmitter 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.
- */
- function Emitter(game, X, Y, Size) {
- if (typeof X === "undefined") { X = 0; }
- if (typeof Y === "undefined") { Y = 0; }
- if (typeof Size === "undefined") { Size = 0; }
- _super.call(this, 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();
- }
- Emitter.prototype.destroy = /**
- * Clean up memory.
- */
- function () {
- this.minParticleSpeed = null;
- this.maxParticleSpeed = null;
- this.particleDrag = null;
- this.particleClass = null;
- this._point = null;
- _super.prototype.destroy.call(this);
- };
- Emitter.prototype.makeParticles = /**
- * 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).
- */
- function (Graphics, Quantity, BakedRotations, Multiple, Collide) {
- if (typeof Quantity === "undefined") { Quantity = 50; }
- if (typeof BakedRotations === "undefined") { BakedRotations = 16; }
- if (typeof Multiple === "undefined") { Multiple = false; }
- if (typeof Collide === "undefined") { Collide = 0.8; }
- this.maxSize = Quantity;
- var totalFrames = 1;
- /*
- if(Multiple)
- {
- var sprite:Sprite = new Sprite(this._game);
- sprite.loadGraphic(Graphics,true);
- totalFrames = sprite.frames;
- sprite.destroy();
- }
+ };
+ Group.prototype.getFirstAvailable = /**
+ * Call this function to retrieve the first object with exists == false in the group.
+ * This is handy for recycling in general, e.g. respawning enemies.
+ *
+ * @param ObjectClass An optional parameter that lets you narrow the results to instances of this particular class.
+ *
+ * @return A Basic currently flagged as not existing.
*/
- var randomFrame;
- var particle;
- var i = 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);
+ function (ObjectClass) {
+ if (typeof ObjectClass === "undefined") { ObjectClass = null; }
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if((basic != null) && !basic.exists && ((ObjectClass == null) || (typeof basic === ObjectClass))) {
+ return basic;
}
}
- 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;
- };
- Emitter.prototype.update = /**
- * Called automatically by the game loop, decides when to launch particles and when to "die".
- */
- function () {
- if(this.on) {
- if(this._explode) {
- this.on = false;
- var i = 0;
- var l = this._quantity;
- if((l <= 0) || (l > this.length)) {
- l = this.length;
- }
- while(i < l) {
- this.emitParticle();
+ return null;
+ };
+ Group.prototype.getFirstNull = /**
+ * Call this function to retrieve the first index set to 'null'.
+ * Returns -1 if no index stores a null object.
+ *
+ * @return An int indicating the first null slot in the group.
+ */
+ function () {
+ var basic;
+ var i = 0;
+ var l = this.members.length;
+ while(i < l) {
+ if(this.members[i] == null) {
+ return i;
+ } else {
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;
+ }
+ return -1;
+ };
+ Group.prototype.getFirstExtant = /**
+ * Call this function to retrieve the first object with exists == true in the group.
+ * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
+ *
+ * @return A Basic currently flagged as existing.
+ */
+ function () {
+ var basic;
+ var i = 0;
+ while(i < length) {
+ basic = this.members[i++];
+ if((basic != null) && basic.exists) {
+ return basic;
+ }
+ }
+ return null;
+ };
+ Group.prototype.getFirstAlive = /**
+ * Call this function to retrieve the first object with dead == false in the group.
+ * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
+ *
+ * @return A Basic currently flagged as not dead.
+ */
+ function () {
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if((basic != null) && basic.exists && basic.alive) {
+ return basic;
+ }
+ }
+ return null;
+ };
+ Group.prototype.getFirstDead = /**
+ * Call this function to retrieve the first object with dead == true in the group.
+ * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
+ *
+ * @return A Basic currently flagged as dead.
+ */
+ function () {
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if((basic != null) && !basic.alive) {
+ return basic;
+ }
+ }
+ return null;
+ };
+ Group.prototype.countLiving = /**
+ * Call this function to find out how many members of the group are not dead.
+ *
+ * @return The number of Basics flagged as not dead. Returns -1 if group is empty.
+ */
+ function () {
+ var count = -1;
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if(basic != null) {
+ if(count < 0) {
+ count = 0;
+ }
+ if(basic.exists && basic.alive) {
+ count++;
}
}
}
- }
- _super.prototype.update.call(this);
- };
- Emitter.prototype.kill = /**
- * Call this function to turn off all the particles and the emitter.
- */
- function () {
- this.on = false;
- _super.prototype.kill.call(this);
- };
- Emitter.prototype.start = /**
- * 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".
- */
- function (Explode, Lifespan, Frequency, Quantity) {
- if (typeof Explode === "undefined") { Explode = true; }
- if (typeof Lifespan === "undefined") { Lifespan = 0; }
- if (typeof Frequency === "undefined") { Frequency = 0.1; }
- if (typeof Quantity === "undefined") { Quantity = 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;
- };
- Emitter.prototype.emitParticle = /**
- * This function can be used both internally and externally to emit the next particle.
- */
- function () {
- var 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();
- };
- Emitter.prototype.setSize = /**
- * 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.
- */
- function (Width, Height) {
- this.width = Width;
- this.height = Height;
- };
- Emitter.prototype.setXSpeed = /**
- * 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.
- */
- function (Min, Max) {
- if (typeof Min === "undefined") { Min = 0; }
- if (typeof Max === "undefined") { Max = 0; }
- this.minParticleSpeed.x = Min;
- this.maxParticleSpeed.x = Max;
- };
- Emitter.prototype.setYSpeed = /**
- * 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.
- */
- function (Min, Max) {
- if (typeof Min === "undefined") { Min = 0; }
- if (typeof Max === "undefined") { Max = 0; }
- this.minParticleSpeed.y = Min;
- this.maxParticleSpeed.y = Max;
- };
- Emitter.prototype.setRotation = /**
- * 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.
- */
- function (Min, Max) {
- if (typeof Min === "undefined") { Min = 0; }
- if (typeof Max === "undefined") { Max = 0; }
- this.minRotation = Min;
- this.maxRotation = Max;
- };
- Emitter.prototype.at = /**
- * Change the emitter's midpoint to match the midpoint of a FlxObject.
- *
- * @param Object The FlxObject that you want to sync up with.
- */
- function (Object) {
- Object.getMidpoint(this._point);
- this.x = this._point.x - (this.width >> 1);
- this.y = this._point.y - (this.height >> 1);
- };
- return Emitter;
-})(Group);
-/// Basics flagged as dead. Returns -1 if group is empty.
+ */
+ function () {
+ var count = -1;
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if(basic != null) {
+ if(count < 0) {
+ count = 0;
+ }
+ if(!basic.alive) {
+ count++;
+ }
+ }
+ }
+ return count;
+ };
+ Group.prototype.getRandom = /**
+ * Returns a member at random from the group.
+ *
+ * @param StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
+ * @param Length Optional restriction on the number of values you want to randomly select from.
+ *
+ * @return A Basic from the members list.
+ */
+ function (StartIndex, Length) {
+ if (typeof StartIndex === "undefined") { StartIndex = 0; }
+ if (typeof Length === "undefined") { Length = 0; }
+ if(Length == 0) {
+ Length = this.length;
+ }
+ return this._game.math.getRandom(this.members, StartIndex, Length);
+ };
+ Group.prototype.clear = /**
+ * Remove all instances of Basic subclass (FlxBasic, FlxBlock, etc) from the list.
+ * WARNING: does not destroy() or kill() any of these objects!
+ */
+ function () {
+ this.length = this.members.length = 0;
+ };
+ Group.prototype.kill = /**
+ * Calls kill on the group's members and then on the group itself.
+ */
+ function () {
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if((basic != null) && basic.exists) {
+ basic.kill();
+ }
+ }
+ };
+ Group.prototype.sortHandler = /**
+ * Helper function for the sort process.
+ *
+ * @param Obj1 The first object being sorted.
+ * @param Obj2 The second object being sorted.
+ *
+ * @return An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
+ */
+ function (Obj1, Obj2) {
+ if(Obj1[this._sortIndex] < Obj2[this._sortIndex]) {
+ return this._sortOrder;
+ } else if(Obj1[this._sortIndex] > Obj2[this._sortIndex]) {
+ return -this._sortOrder;
+ }
+ return 0;
+ };
+ return Group;
+ })(Phaser.Basic);
+ Phaser.Group = Group;
+})(Phaser || (Phaser = {}));
+/// QuadTree for how to use it, IF YOU DARE.
-*/
-var LinkedList = (function () {
- /**
- * Creates a new link, and sets object and next to null.
- */
- function LinkedList() {
- this.object = null;
- this.next = null;
- }
- LinkedList.prototype.destroy = /**
- * Clean up memory.
- */
- function () {
- this.object = null;
- if(this.next != null) {
- this.next.destroy();
- }
- this.next = null;
- };
- return LinkedList;
-})();
-/// myFunction(Object1:GameObject,Object2:GameObject) that is called whenever two objects are found to overlap in world space, and either no ProcessCallback is specified, or the ProcessCallback returns true.
- * @param ProcessCallback A function with the form myFunction(Object1:GameObject,Object2:GameObject):bool that is called whenever two objects are found to overlap in world space. The NotifyCallback is only called if this function returns true. See GameObject.separate().
- */
- function (ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, ProcessCallback) {
- if (typeof ObjectOrGroup2 === "undefined") { ObjectOrGroup2 = null; }
- if (typeof NotifyCallback === "undefined") { NotifyCallback = null; }
- if (typeof ProcessCallback === "undefined") { ProcessCallback = null; }
- //console.log('quadtree load', QuadTree.divisions, ObjectOrGroup1, ObjectOrGroup2);
- this.add(ObjectOrGroup1, QuadTree.A_LIST);
- if(ObjectOrGroup2 != null) {
- this.add(ObjectOrGroup2, QuadTree.B_LIST);
- QuadTree._useBothLists = true;
- } else {
- QuadTree._useBothLists = false;
- }
- QuadTree._notifyCallback = NotifyCallback;
- QuadTree._processingCallback = ProcessCallback;
- //console.log('use both', QuadTree._useBothLists);
- //console.log('------------ end of load');
- };
- QuadTree.prototype.add = /**
- * Call this function to add an object to the root of the tree.
- * This function will recursively add all group members, but
- * not the groups themselves.
- *
- * @param ObjectOrGroup GameObjects are just added, Groups are recursed and their applicable members added accordingly.
- * @param List A uint flag indicating the list to which you want to add the objects. Options are QuadTree.A_LIST and QuadTree.B_LIST.
- */
- function (ObjectOrGroup, List) {
- QuadTree._list = List;
- if(ObjectOrGroup.isGroup == true) {
- var i = 0;
- var basic;
- var members = ObjectOrGroup['members'];
- var l = ObjectOrGroup['length'];
- while(i < l) {
- basic = members[i++];
- if((basic != null) && basic.exists) {
- if(basic.isGroup) {
- this.add(basic, List);
+ // A json string or object has been given
+ if(typeof jsonData === 'string') {
+ //console.log('A json string has been given');
+ var data = JSON.parse(jsonData);
+ //console.log(data);
+ // Malformed?
+ if(data['frames']) {
+ //console.log('frames array found');
+ this._fileList[key] = {
+ type: 'textureatlas',
+ key: key,
+ url: url,
+ data: null,
+ jsonURL: null,
+ jsonData: data['frames'],
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ }
} else {
- QuadTree._object = basic;
- if(QuadTree._object.exists && QuadTree._object.allowCollisions) {
- QuadTree._objectLeftEdge = QuadTree._object.x;
- QuadTree._objectTopEdge = QuadTree._object.y;
- QuadTree._objectRightEdge = QuadTree._object.x + QuadTree._object.width;
- QuadTree._objectBottomEdge = QuadTree._object.y + QuadTree._object.height;
- this.addObject();
+ //console.log('A json object has been given', jsonData);
+ // Malformed?
+ if(jsonData['frames']) {
+ //console.log('frames array found');
+ this._fileList[key] = {
+ type: 'textureatlas',
+ key: key,
+ url: url,
+ data: null,
+ jsonURL: null,
+ jsonData: jsonData['frames'],
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
}
}
}
}
- } else {
- QuadTree._object = ObjectOrGroup;
- //console.log('add - not group:', ObjectOrGroup.name);
- if(QuadTree._object.exists && QuadTree._object.allowCollisions) {
- QuadTree._objectLeftEdge = QuadTree._object.x;
- QuadTree._objectTopEdge = QuadTree._object.y;
- QuadTree._objectRightEdge = QuadTree._object.x + QuadTree._object.width;
- QuadTree._objectBottomEdge = QuadTree._object.y + QuadTree._object.height;
- //console.log('object properties', QuadTree._objectLeftEdge, QuadTree._objectTopEdge, QuadTree._objectRightEdge, QuadTree._objectBottomEdge);
- this.addObject();
- }
- }
- };
- QuadTree.prototype.addObject = /**
- * Internal function for recursively navigating and creating the tree
- * while adding objects to the appropriate nodes.
- */
- function () {
- //console.log('addObject');
- //If this quad (not its children) lies entirely inside this object, add it here
- if(!this._canSubdivide || ((this._leftEdge >= QuadTree._objectLeftEdge) && (this._rightEdge <= QuadTree._objectRightEdge) && (this._topEdge >= QuadTree._objectTopEdge) && (this._bottomEdge <= QuadTree._objectBottomEdge))) {
- //console.log('add To List');
- this.addToList();
- return;
- }
- //See if the selected object fits completely inside any of the quadrants
- if((QuadTree._objectLeftEdge > this._leftEdge) && (QuadTree._objectRightEdge < this._midpointX)) {
- if((QuadTree._objectTopEdge > this._topEdge) && (QuadTree._objectBottomEdge < this._midpointY)) {
- //console.log('Adding NW tree');
- if(this._northWestTree == null) {
- this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
- }
- this._northWestTree.addObject();
- return;
- }
- if((QuadTree._objectTopEdge > this._midpointY) && (QuadTree._objectBottomEdge < this._bottomEdge)) {
- //console.log('Adding SW tree');
- if(this._southWestTree == null) {
- this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
- }
- this._southWestTree.addObject();
- return;
- }
- }
- if((QuadTree._objectLeftEdge > this._midpointX) && (QuadTree._objectRightEdge < this._rightEdge)) {
- if((QuadTree._objectTopEdge > this._topEdge) && (QuadTree._objectBottomEdge < this._midpointY)) {
- //console.log('Adding NE tree');
- if(this._northEastTree == null) {
- this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
- }
- this._northEastTree.addObject();
- return;
- }
- if((QuadTree._objectTopEdge > this._midpointY) && (QuadTree._objectBottomEdge < this._bottomEdge)) {
- //console.log('Adding SE tree');
- if(this._southEastTree == null) {
- this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
- }
- this._southEastTree.addObject();
- return;
- }
- }
- //If it wasn't completely contained we have to check out the partial overlaps
- if((QuadTree._objectRightEdge > this._leftEdge) && (QuadTree._objectLeftEdge < this._midpointX) && (QuadTree._objectBottomEdge > this._topEdge) && (QuadTree._objectTopEdge < this._midpointY)) {
- if(this._northWestTree == null) {
- this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
- }
- //console.log('added to north west partial tree');
- this._northWestTree.addObject();
- }
- if((QuadTree._objectRightEdge > this._midpointX) && (QuadTree._objectLeftEdge < this._rightEdge) && (QuadTree._objectBottomEdge > this._topEdge) && (QuadTree._objectTopEdge < this._midpointY)) {
- if(this._northEastTree == null) {
- this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
- }
- //console.log('added to north east partial tree');
- this._northEastTree.addObject();
- }
- if((QuadTree._objectRightEdge > this._midpointX) && (QuadTree._objectLeftEdge < this._rightEdge) && (QuadTree._objectBottomEdge > this._midpointY) && (QuadTree._objectTopEdge < this._bottomEdge)) {
- if(this._southEastTree == null) {
- this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
- }
- //console.log('added to south east partial tree');
- this._southEastTree.addObject();
- }
- if((QuadTree._objectRightEdge > this._leftEdge) && (QuadTree._objectLeftEdge < this._midpointX) && (QuadTree._objectBottomEdge > this._midpointY) && (QuadTree._objectTopEdge < this._bottomEdge)) {
- if(this._southWestTree == null) {
- this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
- }
- //console.log('added to south west partial tree');
- this._southWestTree.addObject();
- }
- };
- QuadTree.prototype.addToList = /**
- * Internal function for recursively adding objects to leaf lists.
- */
- function () {
- //console.log('Adding to List');
- var ot;
- if(QuadTree._list == QuadTree.A_LIST) {
- //console.log('A LIST');
- if(this._tailA.object != null) {
- ot = this._tailA;
- this._tailA = new LinkedList();
- ot.next = this._tailA;
- }
- this._tailA.object = QuadTree._object;
- } else {
- //console.log('B LIST');
- if(this._tailB.object != null) {
- ot = this._tailB;
- this._tailB = new LinkedList();
- ot.next = this._tailB;
- }
- this._tailB.object = QuadTree._object;
- }
- if(!this._canSubdivide) {
- return;
- }
- if(this._northWestTree != null) {
- this._northWestTree.addToList();
- }
- if(this._northEastTree != null) {
- this._northEastTree.addToList();
- }
- if(this._southEastTree != null) {
- this._southEastTree.addToList();
- }
- if(this._southWestTree != null) {
- this._southWestTree.addToList();
- }
- };
- QuadTree.prototype.execute = /**
- * QuadTree's other main function. Call this after adding objects
- * using QuadTree.load() to compare the objects that you loaded.
- *
- * @return Whether or not any overlaps were found.
- */
- function () {
- //console.log('quadtree execute');
- var overlapProcessed = false;
- var iterator;
- if(this._headA.object != null) {
- //console.log('---------------------------------------------------');
- //console.log('headA iterator');
- iterator = this._headA;
- while(iterator != null) {
- QuadTree._object = iterator.object;
- if(QuadTree._useBothLists) {
- QuadTree._iterator = this._headB;
- } else {
- QuadTree._iterator = iterator.next;
- }
- if(QuadTree._object.exists && (QuadTree._object.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode()) {
- //console.log('headA iterator overlapped true');
- overlapProcessed = true;
- }
- iterator = iterator.next;
- }
- }
- //Advance through the tree by calling overlap on each child
- if((this._northWestTree != null) && this._northWestTree.execute()) {
- //console.log('NW quadtree execute');
- overlapProcessed = true;
- }
- if((this._northEastTree != null) && this._northEastTree.execute()) {
- //console.log('NE quadtree execute');
- overlapProcessed = true;
- }
- if((this._southEastTree != null) && this._southEastTree.execute()) {
- //console.log('SE quadtree execute');
- overlapProcessed = true;
- }
- if((this._southWestTree != null) && this._southWestTree.execute()) {
- //console.log('SW quadtree execute');
- overlapProcessed = true;
- }
- return overlapProcessed;
- };
- QuadTree.prototype.overlapNode = /**
- * An private for comparing an object against the contents of a node.
- *
- * @return Whether or not any overlaps were found.
- */
- function () {
- //console.log('overlapNode');
- //Walk the list and check for overlaps
- var overlapProcessed = false;
- var checkObject;
- while(QuadTree._iterator != null) {
- if(!QuadTree._object.exists || (QuadTree._object.allowCollisions <= 0)) {
- //console.log('break 1');
- break;
- }
- checkObject = QuadTree._iterator.object;
- if((QuadTree._object === checkObject) || !checkObject.exists || (checkObject.allowCollisions <= 0)) {
- //console.log('break 2');
- QuadTree._iterator = QuadTree._iterator.next;
- continue;
- }
- //calculate bulk hull for QuadTree._object
- QuadTree._objectHullX = (QuadTree._object.x < QuadTree._object.last.x) ? QuadTree._object.x : QuadTree._object.last.x;
- QuadTree._objectHullY = (QuadTree._object.y < QuadTree._object.last.y) ? QuadTree._object.y : QuadTree._object.last.y;
- QuadTree._objectHullWidth = QuadTree._object.x - QuadTree._object.last.x;
- QuadTree._objectHullWidth = QuadTree._object.width + ((QuadTree._objectHullWidth > 0) ? QuadTree._objectHullWidth : -QuadTree._objectHullWidth);
- QuadTree._objectHullHeight = QuadTree._object.y - QuadTree._object.last.y;
- QuadTree._objectHullHeight = QuadTree._object.height + ((QuadTree._objectHullHeight > 0) ? QuadTree._objectHullHeight : -QuadTree._objectHullHeight);
- //calculate bulk hull for checkObject
- QuadTree._checkObjectHullX = (checkObject.x < checkObject.last.x) ? checkObject.x : checkObject.last.x;
- QuadTree._checkObjectHullY = (checkObject.y < checkObject.last.y) ? checkObject.y : checkObject.last.y;
- QuadTree._checkObjectHullWidth = checkObject.x - checkObject.last.x;
- QuadTree._checkObjectHullWidth = checkObject.width + ((QuadTree._checkObjectHullWidth > 0) ? QuadTree._checkObjectHullWidth : -QuadTree._checkObjectHullWidth);
- QuadTree._checkObjectHullHeight = checkObject.y - checkObject.last.y;
- QuadTree._checkObjectHullHeight = checkObject.height + ((QuadTree._checkObjectHullHeight > 0) ? QuadTree._checkObjectHullHeight : -QuadTree._checkObjectHullHeight);
- //check for intersection of the two hulls
- if((QuadTree._objectHullX + QuadTree._objectHullWidth > QuadTree._checkObjectHullX) && (QuadTree._objectHullX < QuadTree._checkObjectHullX + QuadTree._checkObjectHullWidth) && (QuadTree._objectHullY + QuadTree._objectHullHeight > QuadTree._checkObjectHullY) && (QuadTree._objectHullY < QuadTree._checkObjectHullY + QuadTree._checkObjectHullHeight)) {
- //console.log('intersection!');
- //Execute callback functions if they exist
- if((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, checkObject)) {
- overlapProcessed = true;
- }
- if(overlapProcessed && (QuadTree._notifyCallback != null)) {
- QuadTree._notifyCallback(QuadTree._object, checkObject);
- }
- }
- QuadTree._iterator = QuadTree._iterator.next;
- }
- return overlapProcessed;
- };
- return QuadTree;
-})(Rectangle);
-/// GameObject 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 FlxGroup (or even bundling groups together!).
- *
- * NOTE: does NOT take objects' scrollfactor into account, all overlaps are checked in world space.
- * - * @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 twoGameObject parameters - e.g. myOverlapFunction(Object1:GameObject,Object2:GameObject) - that is called if those two objects overlap.
- * @param ProcessCallback A function with two GameObject parameters - e.g. myOverlapFunction(Object1:GameObject,Object2:GameObject) - 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.
- */
- function (ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, ProcessCallback) {
- if (typeof ObjectOrGroup1 === "undefined") { ObjectOrGroup1 = null; }
- if (typeof ObjectOrGroup2 === "undefined") { ObjectOrGroup2 = null; }
- if (typeof NotifyCallback === "undefined") { NotifyCallback = null; }
- if (typeof ProcessCallback === "undefined") { ProcessCallback = null; }
- if(ObjectOrGroup1 == null) {
- ObjectOrGroup1 = this.group;
- }
- if(ObjectOrGroup2 == ObjectOrGroup1) {
- ObjectOrGroup2 = null;
- }
- QuadTree.divisions = this.worldDivisions;
- var quadTree = new QuadTree(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
- quadTree.load(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, ProcessCallback);
- var result = quadTree.execute();
- quadTree.destroy();
- quadTree = null;
- return result;
- };
- World.separate = /**
- * The main collision resolution in flixel.
- *
- * @param Object1 Any Sprite.
- * @param Object2 Any other Sprite.
- *
- * @return Whether the objects in fact touched and were separated.
- */
- function separate(Object1, Object2) {
- var separatedX = World.separateX(Object1, Object2);
- var separatedY = World.separateY(Object1, Object2);
- return separatedX || separatedY;
- };
- World.separateX = /**
- * The X-axis component of the object separation process.
- *
- * @param Object1 Any Sprite.
- * @param Object2 Any other Sprite.
- *
- * @return Whether the objects in fact touched and were separated along the X axis.
- */
- function separateX(Object1, Object2) {
- //can't separate two immovable objects
- var obj1immovable = Object1.immovable;
- var obj2immovable = 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 = 0;
- var obj1delta = Object1.x - Object1.last.x;
- var obj2delta = Object2.x - Object2.last.x;
- if(obj1delta != obj2delta) {
- //Check if the X hulls actually overlap
- var obj1deltaAbs = (obj1delta > 0) ? obj1delta : -obj1delta;
- var obj2deltaAbs = (obj2delta > 0) ? obj2delta : -obj2delta;
- var obj1rect = new Rectangle(Object1.x - ((obj1delta > 0) ? obj1delta : 0), Object1.last.y, Object1.width + ((obj1delta > 0) ? obj1delta : -obj1delta), Object1.height);
- var obj2rect = 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 = 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 = Object1.velocity.x;
- var obj2v = Object2.velocity.x;
- if(!obj1immovable && !obj2immovable) {
- overlap *= 0.5;
- Object1.x = Object1.x - overlap;
- Object2.x += overlap;
- var obj1velocity = Math.sqrt((obj2v * obj2v * Object2.mass) / Object1.mass) * ((obj2v > 0) ? 1 : -1);
- var obj2velocity = Math.sqrt((obj1v * obj1v * Object1.mass) / Object2.mass) * ((obj1v > 0) ? 1 : -1);
- var average = (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;
- }
- };
- World.separateY = /**
- * The Y-axis component of the object separation process.
- *
- * @param Object1 Any Sprite.
- * @param Object2 Any other Sprite.
- *
- * @return Whether the objects in fact touched and were separated along the Y axis.
- */
- function separateY(Object1, Object2) {
- //can't separate two immovable objects
- var obj1immovable = Object1.immovable;
- var obj2immovable = 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 = 0;
- var obj1delta = Object1.y - Object1.last.y;
- var obj2delta = Object2.y - Object2.last.y;
- if(obj1delta != obj2delta) {
- //Check if the Y hulls actually overlap
- var obj1deltaAbs = (obj1delta > 0) ? obj1delta : -obj1delta;
- var obj2deltaAbs = (obj2delta > 0) ? obj2delta : -obj2delta;
- var obj1rect = new Rectangle(Object1.x, Object1.y - ((obj1delta > 0) ? obj1delta : 0), Object1.width, Object1.height + obj1deltaAbs);
- var obj2rect = 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 = 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 = Object1.velocity.y;
- var obj2v = Object2.velocity.y;
- if(!obj1immovable && !obj2immovable) {
- overlap *= 0.5;
- Object1.y = Object1.y - overlap;
- Object2.y += overlap;
- var obj1velocity = Math.sqrt((obj2v * obj2v * Object2.mass) / Object1.mass) * ((obj2v > 0) ? 1 : -1);
- var obj2velocity = Math.sqrt((obj1v * obj1v * Object1.mass) / Object2.mass) * ((obj1v > 0) ? 1 : -1);
- var average = (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;
- }
- };
- return World;
-})();
-/// If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.
- * @param {Array} [paramsArr] Array of parameters that should be passed to the listener - * @return {*} Value returned by the listener. - */ - function (paramsArr) { - var handlerReturn; - var params; - if(this.active && !!this._listener) { - params = this.params ? this.params.concat(paramsArr) : paramsArr; - handlerReturn = this._listener.apply(this.context, params); - if(this._isOnce) { - this.detach(); - } + function SignalBinding(signal, listener, isOnce, listenerContext, priority) { + if (typeof priority === "undefined") { priority = 0; } + /** + * If binding is active and should be executed. + * @type boolean + */ + this.active = true; + /** + * Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute`. (curried parameters) + * @type Array|null + */ + this.params = null; + this._listener = listener; + this._isOnce = isOnce; + this.context = listenerContext; + this._signal = signal; + this.priority = priority || 0; } - return handlerReturn; - }; - SignalBinding.prototype.detach = /** - * Detach binding from signal. - * - alias to: mySignal.remove(myBinding.getListener()); - * @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached. - */ - function () { - return this.isBound() ? this._signal.remove(this._listener, this.context) : null; - }; - SignalBinding.prototype.isBound = /** - * @return {Boolean} `true` if binding is still bound to the signal and have a listener. - */ - function () { - return (!!this._signal && !!this._listener); - }; - SignalBinding.prototype.isOnce = /** - * @return {boolean} If SignalBinding will only be executed once. - */ - function () { - return this._isOnce; - }; - SignalBinding.prototype.getListener = /** - * @return {Function} Handler function bound to the signal. - */ - function () { - return this._listener; - }; - SignalBinding.prototype.getSignal = /** - * @return {Signal} Signal that listener is currently bound to. - */ - function () { - return this._signal; - }; - SignalBinding.prototype._destroy = /** - * Delete instance properties - * @private - */ - function () { - delete this._signal; - delete this._listener; - delete this.context; - }; - SignalBinding.prototype.toString = /** - * @return {string} String representation of the object. - */ - function () { - return '[SignalBinding isOnce:' + this._isOnce + ', isBound:' + this.isBound() + ', active:' + this.active + ']'; - }; - return SignalBinding; -})(); + SignalBinding.prototype.execute = /** + * Call listener passing arbitrary parameters. + *If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.
+ * @param {Array} [paramsArr] Array of parameters that should be passed to the listener + * @return {*} Value returned by the listener. + */ + function (paramsArr) { + var handlerReturn; + var params; + if(this.active && !!this._listener) { + params = this.params ? this.params.concat(paramsArr) : paramsArr; + handlerReturn = this._listener.apply(this.context, params); + if(this._isOnce) { + this.detach(); + } + } + return handlerReturn; + }; + SignalBinding.prototype.detach = /** + * Detach binding from signal. + * - alias to: mySignal.remove(myBinding.getListener()); + * @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached. + */ + function () { + return this.isBound() ? this._signal.remove(this._listener, this.context) : null; + }; + SignalBinding.prototype.isBound = /** + * @return {Boolean} `true` if binding is still bound to the signal and have a listener. + */ + function () { + return (!!this._signal && !!this._listener); + }; + SignalBinding.prototype.isOnce = /** + * @return {boolean} If SignalBinding will only be executed once. + */ + function () { + return this._isOnce; + }; + SignalBinding.prototype.getListener = /** + * @return {Function} Handler function bound to the signal. + */ + function () { + return this._listener; + }; + SignalBinding.prototype.getSignal = /** + * @return {Signal} Signal that listener is currently bound to. + */ + function () { + return this._signal; + }; + SignalBinding.prototype._destroy = /** + * Delete instance properties + * @private + */ + function () { + delete this._signal; + delete this._listener; + delete this.context; + }; + SignalBinding.prototype.toString = /** + * @return {string} String representation of the object. + */ + function () { + return '[SignalBinding isOnce:' + this._isOnce + ', isBound:' + this.isBound() + ', active:' + this.active + ']'; + }; + return SignalBinding; + })(); + Phaser.SignalBinding = SignalBinding; +})(Phaser || (Phaser = {})); ///IMPORTANT: Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.
- * @type boolean - */ - this.active = true; - } - Signal.VERSION = '1.0.0'; - Signal.prototype.validateListener = /** - * - * @method validateListener - * @param {Any} listener - * @param {Any} fnName - */ - function (listener, fnName) { - if(typeof listener !== 'function') { - throw new Error('listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName)); - } - }; - Signal.prototype._registerListener = /** - * @param {Function} listener - * @param {boolean} isOnce - * @param {Object} [listenerContext] - * @param {Number} [priority] - * @return {SignalBinding} - * @private - */ - function (listener, isOnce, listenerContext, priority) { - var prevIndex = this._indexOfListener(listener, listenerContext); - var binding; - if(prevIndex !== -1) { - binding = this._bindings[prevIndex]; - if(binding.isOnce() !== isOnce) { - throw new Error('You cannot add' + (isOnce ? '' : 'Once') + '() then add' + (!isOnce ? '' : 'Once') + '() the same listener without removing the relationship first.'); - } - } else { - binding = new SignalBinding(this, listener, isOnce, listenerContext, priority); - this._addBinding(binding); - } - if(this.memorize && this._prevParams) { - binding.execute(this._prevParams); - } - return binding; - }; - Signal.prototype._addBinding = /** - * - * @method _addBinding - * @param {SignalBinding} binding - * @private - */ - function (binding) { - //simplified insertion sort - var n = this._bindings.length; - do { - --n; - }while(this._bindings[n] && binding.priority <= this._bindings[n].priority); - this._bindings.splice(n + 1, 0, binding); - }; - Signal.prototype._indexOfListener = /** - * - * @method _indexOfListener - * @param {Function} listener - * @return {number} - * @private - */ - function (listener, context) { - var n = this._bindings.length; - var cur; - while(n--) { - cur = this._bindings[n]; - if(cur.getListener() === listener && cur.context === context) { - return n; - } - } - return -1; - }; - Signal.prototype.has = /** - * Check if listener was attached to Signal. - * @param {Function} listener - * @param {Object} [context] - * @return {boolean} if Signal has the specified listener. - */ - function (listener, context) { - if (typeof context === "undefined") { context = null; } - return this._indexOfListener(listener, context) !== -1; - }; - Signal.prototype.add = /** - * Add a listener to the signal. - * @param {Function} listener Signal handler function. - * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). - * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) - * @return {SignalBinding} An Object representing the binding between the Signal and listener. - */ - function (listener, listenerContext, priority) { - if (typeof listenerContext === "undefined") { listenerContext = null; } - if (typeof priority === "undefined") { priority = 0; } - this.validateListener(listener, 'add'); - return this._registerListener(listener, false, listenerContext, priority); - }; - Signal.prototype.addOnce = /** - * Add listener to the signal that should be removed after first execution (will be executed only once). - * @param {Function} listener Signal handler function. - * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). - * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) - * @return {SignalBinding} An Object representing the binding between the Signal and listener. - */ - function (listener, listenerContext, priority) { - if (typeof listenerContext === "undefined") { listenerContext = null; } - if (typeof priority === "undefined") { priority = 0; } - this.validateListener(listener, 'addOnce'); - return this._registerListener(listener, true, listenerContext, priority); - }; - Signal.prototype.remove = /** - * Remove a single listener from the dispatch queue. - * @param {Function} listener Handler function that should be removed. - * @param {Object} [context] Execution context (since you can add the same handler multiple times if executing in a different context). - * @return {Function} Listener handler function. - */ - function (listener, context) { - if (typeof context === "undefined") { context = null; } - this.validateListener(listener, 'remove'); - var i = this._indexOfListener(listener, context); - if(i !== -1) { - this._bindings[i]._destroy()//no reason to a SignalBinding exist if it isn't attached to a signal - ; - this._bindings.splice(i, 1); - } - return listener; - }; - Signal.prototype.removeAll = /** - * Remove all listeners from the Signal. - */ - function () { - var n = this._bindings.length; - while(n--) { - this._bindings[n]._destroy(); - } - this._bindings.length = 0; - }; - Signal.prototype.getNumListeners = /** - * @return {number} Number of listeners attached to the Signal. - */ - function () { - return this._bindings.length; - }; - Signal.prototype.halt = /** - * Stop propagation of the event, blocking the dispatch to next listeners on the queue. - *IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.
- * @see Signal.prototype.disable - */ - function () { - this._shouldPropagate = false; - }; - Signal.prototype.dispatch = /** - * Dispatch/Broadcast Signal to all listeners added to the queue. - * @param {...*} [params] Parameters that should be passed to each handler. - */ - function () { - var paramsArr = []; - for (var _i = 0; _i < (arguments.length - 0); _i++) { - paramsArr[_i] = arguments[_i + 0]; - } - if(!this.active) { - return; - } - var n = this._bindings.length; - var bindings; - if(this.memorize) { - this._prevParams = paramsArr; - } - if(!n) { - //should come after memorize - return; - } - bindings = this._bindings.slice(0)//clone array in case add/remove items during dispatch - ; - this._shouldPropagate = true//in case `halt` was called before dispatch or during the previous dispatch. - ; - //execute all callbacks until end of the list or until a callback returns `false` or stops propagation - //reverse loop since listeners with higher priority will be added at the end of the list - do { - n--; - }while(bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false); - }; - Signal.prototype.forget = /** - * Forget memorized arguments. - * @see Signal.memorize - */ - function () { - this._prevParams = null; - }; - Signal.prototype.dispose = /** - * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object). - *IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.
- */ - function () { - this.removeAll(); - delete this._bindings; - delete this._prevParams; - }; - Signal.prototype.toString = /** - * @return {string} String representation of the object. - */ - function () { - return '[Signal active:' + this.active + ' numListeners:' + this.getNumListeners() + ']'; - }; - return Signal; -})(); -///IMPORTANT: Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.
+ * @type boolean + */ + this.active = true; } - return this._diameter; - }; - Circle.prototype.radius = /** - * 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 - * @param {Number} The radius of the circle. - **/ - function (value) { - if(value && value > 0) { - this._radius = value; - this._diameter = value * 2; - } - return this._radius; - }; - Circle.prototype.circumference = /** - * The circumference of the circle. - * @method circumference - * @return {Number} - **/ - function () { - return 2 * (Math.PI * this._radius); - }; - Circle.prototype.bottom = /** - * 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. - **/ - function (value) { - if(value && !isNaN(value)) { - if(value < this.y) { - this._radius = 0; - this._diameter = 0; - } else { - this.radius(value - this.y); + Signal.VERSION = '1.0.0'; + Signal.prototype.validateListener = /** + * + * @method validateListener + * @param {Any} listener + * @param {Any} fnName + */ + function (listener, fnName) { + if(typeof listener !== 'function') { + throw new Error('listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName)); } - } - return this.y + this._radius; - }; - Circle.prototype.left = /** - * 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 - * @param {Number} The value to adjust the position of the leftmost point of the circle by. - **/ - function (value) { - if(value && !isNaN(value)) { - if(value < this.x) { - this.radius(this.x - value); + }; + Signal.prototype._registerListener = /** + * @param {Function} listener + * @param {boolean} isOnce + * @param {Object} [listenerContext] + * @param {Number} [priority] + * @return {SignalBinding} + * @private + */ + function (listener, isOnce, listenerContext, priority) { + var prevIndex = this._indexOfListener(listener, listenerContext); + var binding; + if(prevIndex !== -1) { + binding = this._bindings[prevIndex]; + if(binding.isOnce() !== isOnce) { + throw new Error('You cannot add' + (isOnce ? '' : 'Once') + '() then add' + (!isOnce ? '' : 'Once') + '() the same listener without removing the relationship first.'); + } } else { - this._radius = 0; - this._diameter = 0; + binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority); + this._addBinding(binding); } - } - return this.x - this._radius; - }; - Circle.prototype.right = /** - * 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 - * @param {Number} The amount to adjust the diameter of the circle by. - **/ - function (value) { - if(value && !isNaN(value)) { - if(value > this.x) { - this.radius(value - this.x); - } else { - this._radius = 0; - this._diameter = 0; + if(this.memorize && this._prevParams) { + binding.execute(this._prevParams); } - } - return this.x + this._radius; - }; - Circle.prototype.top = /** - * 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 - * @param {Number} The amount to adjust the height of the circle by. - **/ - function (value) { - if(value && !isNaN(value)) { - if(value > this.y) { - this._radius = 0; - this._diameter = 0; - } else { - this.radius(this.y - value); + return binding; + }; + Signal.prototype._addBinding = /** + * + * @method _addBinding + * @param {SignalBinding} binding + * @private + */ + function (binding) { + //simplified insertion sort + var n = this._bindings.length; + do { + --n; + }while(this._bindings[n] && binding.priority <= this._bindings[n].priority); + this._bindings.splice(n + 1, 0, binding); + }; + Signal.prototype._indexOfListener = /** + * + * @method _indexOfListener + * @param {Function} listener + * @return {number} + * @private + */ + function (listener, context) { + var n = this._bindings.length; + var cur; + while(n--) { + cur = this._bindings[n]; + if(cur.getListener() === listener && cur.context === context) { + return n; + } } - } - return this.y - this._radius; - }; - Circle.prototype.area = /** - * Gets the area of this Circle. - * @method area - * @return {Number} This area of this circle. - **/ - function () { - if(this._radius > 0) { - return Math.PI * this._radius * this._radius; - } else { - return 0; - } - }; - Circle.prototype.isEmpty = /** - * Determines whether or not this Circle object is empty. - * @method isEmpty - * @return {Boolean} A value of true if the Circle objects diameter is less than or equal to 0; otherwise false. - **/ - function () { - if(this._diameter < 1) { - return true; - } - return false; - }; - Circle.prototype.clone = /** - * 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. - * @method intersectCircleLine - * @param {Object} the line object to check. - * @return {Boolean} - **/ - /* - public intersectCircleLine(line: Line): bool { - - return Intersect.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} - **/ - function (output) { - if (typeof output === "undefined") { output = new Circle(); } - return output.setTo(this.x, this.y, this._diameter); - }; - Circle.prototype.copyFrom = /** - * 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. - * @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,IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.
+ * @see Signal.prototype.disable + */ + function () { + this._shouldPropagate = false; + }; + Signal.prototype.dispatch = /** + * Dispatch/Broadcast Signal to all listeners added to the queue. + * @param {...*} [params] Parameters that should be passed to each handler. + */ + function () { + var paramsArr = []; + for (var _i = 0; _i < (arguments.length - 0); _i++) { + paramsArr[_i] = arguments[_i + 0]; + } + if(!this.active) { + return; + } + var n = this._bindings.length; + var bindings; + if(this.memorize) { + this._prevParams = paramsArr; + } + if(!n) { + //should come after memorize + return; + } + bindings = this._bindings.slice(0)//clone array in case add/remove items during dispatch ; + this._shouldPropagate = true//in case `halt` was called before dispatch or during the previous dispatch. + ; + //execute all callbacks until end of the list or until a callback returns `false` or stops propagation + //reverse loop since listeners with higher priority will be added at the end of the list + do { + n--; + }while(bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false); + }; + Signal.prototype.forget = /** + * Forget memorized arguments. + * @see Signal.memorize + */ + function () { + this._prevParams = null; + }; + Signal.prototype.dispose = /** + * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object). + *IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.
+ */ + function () { + this.removeAll(); + delete this._bindings; + delete this._prevParams; + }; + Signal.prototype.toString = /** + * @return {string} String representation of the object. + */ + function () { + return '[Signal active:' + this.active + ' numListeners:' + this.getNumListeners() + ']'; + }; + return Signal; + })(); + Phaser.Signal = Signal; +})(Phaser || (Phaser = {})); +///Emitter is a lightweight particle emitter.
+* It can be used for one-time explosions or for
+* continuous fx like rain and fire. Emitter
+* is not optimized or anything; all it does is launch
+* Particle objects out at set intervals
+* by setting their positions and velocities accordingly.
+* It is easy to use and relatively efficient,
+* relying on Group's RECYCLE POWERS.
*
-* @desc Loads Sprite Sheets and Texture Atlas formats into a unified FrameData object
-*
-* @version 1.0 - 22nd March 2013
-* @author Richard Davey
+* @author Adam Atomic
+* @author Richard Davey
*/
-var Animation = (function () {
- function Animation(game, parent, frameData, name, frames, delay, looped) {
- this._game = game;
- this._parent = parent;
- this._frames = frames;
- this._frameData = frameData;
- this.name = name;
- this.delay = 1000 / delay;
- this.looped = looped;
- this.isFinished = false;
- this.isPlaying = false;
- }
- Object.defineProperty(Animation.prototype, "frameTotal", {
- get: function () {
- return this._frames.length;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Animation.prototype, "frame", {
- get: function () {
- return this._frameIndex;
- },
- set: function (value) {
- this.currentFrame = this._frameData.getFrame(value);
- if(this.currentFrame !== null) {
- this._parent.bounds.width = this.currentFrame.width;
- this._parent.bounds.height = this.currentFrame.height;
- this._frameIndex = value;
+/**
+* Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ var Emitter = (function (_super) {
+ __extends(Emitter, _super);
+ /**
+ * Creates a new FlxEmitter 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.
+ */
+ function Emitter(game, X, Y, Size) {
+ if (typeof X === "undefined") { X = 0; }
+ if (typeof Y === "undefined") { Y = 0; }
+ if (typeof Size === "undefined") { Size = 0; }
+ _super.call(this, game, Size);
+ this.x = X;
+ this.y = Y;
+ this.width = 0;
+ this.height = 0;
+ this.minParticleSpeed = new Phaser.Point(-100, -100);
+ this.maxParticleSpeed = new Phaser.Point(100, 100);
+ this.minRotation = -360;
+ this.maxRotation = 360;
+ this.gravity = 0;
+ this.particleClass = null;
+ this.particleDrag = new Phaser.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 Phaser.Point();
+ }
+ Emitter.prototype.destroy = /**
+ * Clean up memory.
+ */
+ function () {
+ this.minParticleSpeed = null;
+ this.maxParticleSpeed = null;
+ this.particleDrag = null;
+ this.particleClass = null;
+ this._point = null;
+ _super.prototype.destroy.call(this);
+ };
+ Emitter.prototype.makeParticles = /**
+ * 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).
+ */
+ function (Graphics, Quantity, BakedRotations, Multiple, Collide) {
+ if (typeof Quantity === "undefined") { Quantity = 50; }
+ if (typeof BakedRotations === "undefined") { BakedRotations = 16; }
+ if (typeof Multiple === "undefined") { Multiple = false; }
+ if (typeof Collide === "undefined") { Collide = 0.8; }
+ this.maxSize = Quantity;
+ var totalFrames = 1;
+ /*
+ if(Multiple)
+ {
+ var sprite:Sprite = new Sprite(this._game);
+ sprite.loadGraphic(Graphics,true);
+ totalFrames = sprite.frames;
+ sprite.destroy();
}
- },
- enumerable: true,
- configurable: true
- });
- Animation.prototype.play = function (frameRate, loop) {
- if (typeof frameRate === "undefined") { frameRate = null; }
- if(frameRate !== null) {
- this.delay = 1000 / frameRate;
- }
- if(loop !== undefined) {
- this.looped = loop;
- }
- this.isPlaying = true;
- this.isFinished = false;
- this._timeLastFrame = this._game.time.now;
- this._timeNextFrame = this._game.time.now + this.delay;
- this._frameIndex = 0;
- this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
- };
- Animation.prototype.onComplete = function () {
- this.isPlaying = false;
- this.isFinished = true;
- // callback
- };
- Animation.prototype.stop = function () {
- this.isPlaying = false;
- this.isFinished = true;
- };
- Animation.prototype.update = function () {
- if(this.isPlaying == true && this._game.time.now >= this._timeNextFrame) {
- this._frameIndex++;
- if(this._frameIndex == this._frames.length) {
- if(this.looped) {
- this._frameIndex = 0;
- this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
+ */
+ var randomFrame;
+ var particle;
+ var i = 0;
+ while(i < Quantity) {
+ if(this.particleClass == null) {
+ particle = new Phaser.Particle(this._game);
} else {
- this.onComplete();
+ 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 = Phaser.Collision.NONE;
+ }
+ particle.exists = false;
+ this.add(particle);
+ i++;
+ }
+ return this;
+ };
+ Emitter.prototype.update = /**
+ * Called automatically by the game loop, decides when to launch particles and when to "die".
+ */
+ function () {
+ if(this.on) {
+ if(this._explode) {
+ this.on = false;
+ var i = 0;
+ var l = 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.prototype.update.call(this);
+ };
+ Emitter.prototype.kill = /**
+ * Call this function to turn off all the particles and the emitter.
+ */
+ function () {
+ this.on = false;
+ _super.prototype.kill.call(this);
+ };
+ Emitter.prototype.start = /**
+ * 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".
+ */
+ function (Explode, Lifespan, Frequency, Quantity) {
+ if (typeof Explode === "undefined") { Explode = true; }
+ if (typeof Lifespan === "undefined") { Lifespan = 0; }
+ if (typeof Frequency === "undefined") { Frequency = 0.1; }
+ if (typeof Quantity === "undefined") { Quantity = 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;
+ };
+ Emitter.prototype.emitParticle = /**
+ * This function can be used both internally and externally to emit the next particle.
+ */
+ function () {
+ var particle = this.recycle(Phaser.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 {
- this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
+ particle.velocity.x = this.minParticleSpeed.x;
}
- this._timeLastFrame = this._game.time.now;
- this._timeNextFrame = this._game.time.now + this.delay;
- return true;
- }
- return false;
- };
- Animation.prototype.destroy = function () {
- this._game = null;
- this._parent = null;
- this._frames = null;
- this._frameData = null;
- this.currentFrame = null;
- this.isPlaying = false;
- };
- return Animation;
-})();
-/// FlxObject.
+ *
+ * @param Object The FlxObject that you want to sync up with.
+ */
+ function (Object) {
+ Object.getMidpoint(this._point);
+ this.x = this._point.x - (this.width >> 1);
+ this.y = this._point.y - (this.height >> 1);
};
- this._images[key].frameData = AnimationLoader.parseSpriteSheet(this._game, key, frameWidth, frameHeight, frameMax);
- };
- Cache.prototype.addTextureAtlas = function (key, url, data, jsonData) {
- this._images[key] = {
- url: url,
- data: data,
- spriteSheet: true
+ return Emitter;
+ })(Phaser.Group);
+ Phaser.Emitter = Emitter;
+})(Phaser || (Phaser = {}));
+/// Sprite to have slightly more specialized behavior
+* common to many game scenarios. You can override and extend this class
+* just like you would Sprite. While Emitter
+* used to work with just any old sprite, it now requires a
+* Particle based class.
+*
+* @author Adam Atomic
+* @author Richard Davey
+*/
+/**
+* Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ var Particle = (function (_super) {
+ __extends(Particle, _super);
+ /**
+ * Instantiate a new particle. Like Sprite, all meaningful creation
+ * happens during loadGraphic() or makeGraphic() or whatever.
+ */
+ function Particle(game) {
+ _super.call(this, game);
+ this.lifespan = 0;
+ this.friction = 500;
+ }
+ Particle.prototype.update = /**
+ * 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.
+ */
+ function () {
+ //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 & Phaser.Collision.FLOOR) {
+ this.drag.x = this.friction;
+ if(!(this.wasTouching & Phaser.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;
+ }
+ }
+ };
+ Particle.prototype.onEmit = /**
+ * Triggered whenever this object is launched by a Emitter.
+ * You can override this to add custom behavior like a sound or AI or something.
+ */
+ function () {
+ };
+ return Particle;
+ })(Phaser.Sprite);
+ Phaser.Particle = Particle;
+})(Phaser || (Phaser = {}));
+/// Tilemap that helps expand collision opportunities and control.
* You can use Tilemap.setTileProperties() to alter the collision properties and
@@ -8947,37 +10221,1124 @@ var State = (function () {
* @author Adam Atomic
* @author Richard Davey
*/
-var Tile = (function (_super) {
- __extends(Tile, _super);
- /**
- * Instantiate this new tile object. This is usually called from FlxTilemap.loadMap().
- *
- * @param Tilemap A reference to the tilemap object creating the tile.
- * @param Index The actual core map data index for this tile type.
- * @param Width The width of the tile.
- * @param Height The height of the tile.
- * @param Visible Whether the tile is visible or not.
- * @param AllowCollisions The collision flags for the object. By default this value is ANY or NONE depending on the parameters sent to loadMap().
- */
- function Tile(game, Tilemap, Index, Width, Height, Visible, AllowCollisions) {
- _super.call(this, game, 0, 0, Width, Height);
- this.immovable = true;
- this.moves = false;
- this.callback = null;
- this.filter = null;
- this.tilemap = Tilemap;
- this.index = Index;
- this.visible = Visible;
- this.allowCollisions = AllowCollisions;
- this.mapIndex = 0;
- }
- Tile.prototype.destroy = /**
- * Clean up memory.
- */
- function () {
- _super.prototype.destroy.call(this);
- this.callback = null;
- this.tilemap = null;
- };
- return Tile;
-})(GameObject);
+/**
+* Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ var Tile = (function (_super) {
+ __extends(Tile, _super);
+ /**
+ * Instantiate this new tile object. This is usually called from FlxTilemap.loadMap().
+ *
+ * @param Tilemap A reference to the tilemap object creating the tile.
+ * @param Index The actual core map data index for this tile type.
+ * @param Width The width of the tile.
+ * @param Height The height of the tile.
+ * @param Visible Whether the tile is visible or not.
+ * @param AllowCollisions The collision flags for the object. By default this value is ANY or NONE depending on the parameters sent to loadMap().
+ */
+ function Tile(game, Tilemap, Index, Width, Height, Visible, AllowCollisions) {
+ _super.call(this, game, 0, 0, Width, Height);
+ this.immovable = true;
+ this.moves = false;
+ this.callback = null;
+ this.filter = null;
+ this.tilemap = Tilemap;
+ this.index = Index;
+ this.visible = Visible;
+ this.allowCollisions = AllowCollisions;
+ this.mapIndex = 0;
+ }
+ Tile.prototype.destroy = /**
+ * Clean up memory.
+ */
+ function () {
+ _super.prototype.destroy.call(this);
+ this.callback = null;
+ this.tilemap = null;
+ };
+ return Tile;
+ })(Phaser.GameObject);
+ Phaser.Tile = Tile;
+})(Phaser || (Phaser = {}));
+/// GameObject and Group extend this class,
+* as do the plugins. Has no size, position or graphical data.
+*
+* @author Adam Atomic
+* @author Richard Davey
+*/
+/**
+* Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ var Basic = (function () {
+ /**
+ * Instantiate the basic object.
+ */
+ function Basic(game) {
+ /**
+ * Allows you to give this object a name. Useful for debugging, but not actually used internally.
+ */
+ this.name = '';
+ this._game = game;
+ this.ID = -1;
+ this.exists = true;
+ this.active = true;
+ this.visible = true;
+ this.alive = true;
+ this.isGroup = false;
+ this.ignoreDrawDebug = false;
+ }
+ Basic.prototype.destroy = /**
+ * Override this to null out iables or manually call
+ * destroy() on class members if necessary.
+ * Don't forget to call super.destroy()!
+ */
+ function () {
+ };
+ Basic.prototype.preUpdate = /**
+ * Pre-update is called right before update() on each object in the game loop.
+ */
+ function () {
+ };
+ Basic.prototype.update = /**
+ * Override this to update your class's position and appearance.
+ * This is where most of your game rules and behavioral code will go.
+ */
+ function () {
+ };
+ Basic.prototype.postUpdate = /**
+ * Post-update is called right after update() on each object in the game loop.
+ */
+ function () {
+ };
+ Basic.prototype.render = function (camera, cameraOffsetX, cameraOffsetY) {
+ };
+ Basic.prototype.kill = /**
+ * Handy for "killing" game objects.
+ * Default behavior is to flag them as nonexistent AND dead.
+ * However, if you want the "corpse" to remain in the game,
+ * like to animate an effect or whatever, you should override this,
+ * setting only alive to false, and leaving exists true.
+ */
+ function () {
+ this.alive = false;
+ this.exists = false;
+ };
+ Basic.prototype.revive = /**
+ * Handy for bringing game objects "back to life". Just sets alive and exists back to true.
+ * In practice, this is most often called by FlxObject.reset().
+ */
+ function () {
+ this.alive = true;
+ this.exists = true;
+ };
+ Basic.prototype.toString = /**
+ * Convert object to readable string name. Useful for debugging, save games, etc.
+ */
+ function () {
+ return "";
+ };
+ return Basic;
+ })();
+ Phaser.Basic = Basic;
+})(Phaser || (Phaser = {}));
+/// GameObject overlaps this GameObject or FlxGroup.
+ * If the group has a LOT of things in it, it might be faster to use FlxG.overlaps().
+ * 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.
+ */
+ function (ObjectOrGroup, InScreenSpace, Camera) {
+ if (typeof InScreenSpace === "undefined") { InScreenSpace = false; }
+ if (typeof Camera === "undefined") { Camera = null; }
+ if(ObjectOrGroup.isGroup) {
+ var results = false;
+ var i = 0;
+ var members = 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 = 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);
+ };
+ GameObject.prototype.overlapsAt = /**
+ * Checks to see if this GameObject were located at the given position, would it overlap the GameObject or FlxGroup?
+ * 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.
+ */
+ function (X, Y, ObjectOrGroup, InScreenSpace, Camera) {
+ if (typeof InScreenSpace === "undefined") { InScreenSpace = false; }
+ if (typeof Camera === "undefined") { Camera = null; }
+ if(ObjectOrGroup.isGroup) {
+ var results = false;
+ var basic;
+ var i = 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 = 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);
+ };
+ GameObject.prototype.overlapsPoint = /**
+ * Checks to see if a ponumber in 2D world space overlaps this GameObject 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.
+ */
+ function (point, InScreenSpace, Camera) {
+ if (typeof InScreenSpace === "undefined") { InScreenSpace = false; }
+ if (typeof Camera === "undefined") { Camera = null; }
+ 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 = point.x - Camera.scroll.x;
+ var Y = 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);
+ };
+ GameObject.prototype.onScreen = /**
+ * 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.
+ */
+ function (Camera) {
+ if (typeof Camera === "undefined") { Camera = null; }
+ 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);
+ };
+ GameObject.prototype.getScreenXY = /**
+ * 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 Point object and assigns the post-scrolled X and Y values of this object to it.
+ *
+ * @return The Point you passed in, or a new Point if you didn't pass one, containing the screen X and Y position of this object.
+ */
+ function (point, Camera) {
+ if (typeof point === "undefined") { point = null; }
+ if (typeof Camera === "undefined") { Camera = null; }
+ if(point == null) {
+ point = new Phaser.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;
+ };
+ Object.defineProperty(GameObject.prototype, "solid", {
+ get: /**
+ * 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.
+ */
+ function () {
+ return (this.allowCollisions & Phaser.Collision.ANY) > Phaser.Collision.NONE;
+ },
+ set: /**
+ * @private
+ */
+ function (Solid) {
+ if(Solid) {
+ this.allowCollisions = Phaser.Collision.ANY;
+ } else {
+ this.allowCollisions = Phaser.Collision.NONE;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ GameObject.prototype.getMidpoint = /**
+ * Retrieve the midponumber of this object in world coordinates.
+ *
+ * @Point Allows you to pass in an existing Point object if you're so inclined. Otherwise a new one is created.
+ *
+ * @return A Point object containing the midponumber of this object in world coordinates.
+ */
+ function (point) {
+ if (typeof point === "undefined") { point = null; }
+ if(point == null) {
+ point = new Phaser.Point();
+ }
+ point.x = this.x + this.width * 0.5;
+ point.y = this.y + this.height * 0.5;
+ return point;
+ };
+ GameObject.prototype.reset = /**
+ * 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.
+ */
+ function (X, Y) {
+ this.revive();
+ this.touching = Phaser.Collision.NONE;
+ this.wasTouching = Phaser.Collision.NONE;
+ this.x = X;
+ this.y = Y;
+ this.last.x = X;
+ this.last.y = Y;
+ this.velocity.x = 0;
+ this.velocity.y = 0;
+ };
+ GameObject.prototype.isTouching = /**
+ * Handy for checking if this object is touching a particular surface.
+ * For slightly better performance you can just & the value directly numbero touching.
+ * 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.
+ */
+ function (Direction) {
+ return (this.touching & Direction) > Phaser.Collision.NONE;
+ };
+ GameObject.prototype.justTouched = /**
+ * 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.
+ */
+ function (Direction) {
+ return ((this.touching & Direction) > Phaser.Collision.NONE) && ((this.wasTouching & Direction) <= Phaser.Collision.NONE);
+ };
+ GameObject.prototype.hurt = /**
+ * 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).
+ */
+ function (Damage) {
+ this.health = this.health - Damage;
+ if(this.health <= 0) {
+ this.kill();
+ }
+ };
+ GameObject.prototype.destroy = function () {
+ };
+ Object.defineProperty(GameObject.prototype, "x", {
+ get: function () {
+ return this.bounds.x;
+ },
+ set: function (value) {
+ this.bounds.x = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(GameObject.prototype, "y", {
+ get: function () {
+ return this.bounds.y;
+ },
+ set: function (value) {
+ this.bounds.y = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(GameObject.prototype, "rotation", {
+ get: function () {
+ return this._angle;
+ },
+ set: function (value) {
+ this._angle = this._game.math.wrap(value, 360, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(GameObject.prototype, "angle", {
+ get: function () {
+ return this._angle;
+ },
+ set: function (value) {
+ this._angle = this._game.math.wrap(value, 360, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(GameObject.prototype, "width", {
+ get: function () {
+ return this.bounds.width;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(GameObject.prototype, "height", {
+ get: function () {
+ return this.bounds.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return GameObject;
+ })(Phaser.Basic);
+ Phaser.GameObject = GameObject;
+})(Phaser || (Phaser = {}));
+/// QuadTree for how to use it, IF YOU DARE.
+*/
+/**
+* Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ var LinkedList = (function () {
+ /**
+ * Creates a new link, and sets object and next to null.
+ */
+ function LinkedList() {
+ this.object = null;
+ this.next = null;
+ }
+ LinkedList.prototype.destroy = /**
+ * Clean up memory.
+ */
+ function () {
+ this.object = null;
+ if(this.next != null) {
+ this.next.destroy();
+ }
+ this.next = null;
+ };
+ return LinkedList;
+ })();
+ Phaser.LinkedList = LinkedList;
+})(Phaser || (Phaser = {}));
+/// myFunction(Object1:GameObject,Object2:GameObject) that is called whenever two objects are found to overlap in world space, and either no ProcessCallback is specified, or the ProcessCallback returns true.
+ * @param ProcessCallback A function with the form myFunction(Object1:GameObject,Object2:GameObject):bool that is called whenever two objects are found to overlap in world space. The NotifyCallback is only called if this function returns true. See GameObject.separate().
+ */
+ function (ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, ProcessCallback) {
+ if (typeof ObjectOrGroup2 === "undefined") { ObjectOrGroup2 = null; }
+ if (typeof NotifyCallback === "undefined") { NotifyCallback = null; }
+ if (typeof ProcessCallback === "undefined") { ProcessCallback = null; }
+ //console.log('quadtree load', QuadTree.divisions, ObjectOrGroup1, ObjectOrGroup2);
+ this.add(ObjectOrGroup1, QuadTree.A_LIST);
+ if(ObjectOrGroup2 != null) {
+ this.add(ObjectOrGroup2, QuadTree.B_LIST);
+ QuadTree._useBothLists = true;
+ } else {
+ QuadTree._useBothLists = false;
+ }
+ QuadTree._notifyCallback = NotifyCallback;
+ QuadTree._processingCallback = ProcessCallback;
+ //console.log('use both', QuadTree._useBothLists);
+ //console.log('------------ end of load');
+ };
+ QuadTree.prototype.add = /**
+ * Call this function to add an object to the root of the tree.
+ * This function will recursively add all group members, but
+ * not the groups themselves.
+ *
+ * @param ObjectOrGroup GameObjects are just added, Groups are recursed and their applicable members added accordingly.
+ * @param List A uint flag indicating the list to which you want to add the objects. Options are QuadTree.A_LIST and QuadTree.B_LIST.
+ */
+ function (ObjectOrGroup, List) {
+ QuadTree._list = List;
+ if(ObjectOrGroup.isGroup == true) {
+ var i = 0;
+ var basic;
+ var members = ObjectOrGroup['members'];
+ var l = ObjectOrGroup['length'];
+ while(i < l) {
+ basic = members[i++];
+ if((basic != null) && basic.exists) {
+ if(basic.isGroup) {
+ this.add(basic, List);
+ } else {
+ QuadTree._object = basic;
+ if(QuadTree._object.exists && QuadTree._object.allowCollisions) {
+ QuadTree._objectLeftEdge = QuadTree._object.x;
+ QuadTree._objectTopEdge = QuadTree._object.y;
+ QuadTree._objectRightEdge = QuadTree._object.x + QuadTree._object.width;
+ QuadTree._objectBottomEdge = QuadTree._object.y + QuadTree._object.height;
+ this.addObject();
+ }
+ }
+ }
+ }
+ } else {
+ QuadTree._object = ObjectOrGroup;
+ //console.log('add - not group:', ObjectOrGroup.name);
+ if(QuadTree._object.exists && QuadTree._object.allowCollisions) {
+ QuadTree._objectLeftEdge = QuadTree._object.x;
+ QuadTree._objectTopEdge = QuadTree._object.y;
+ QuadTree._objectRightEdge = QuadTree._object.x + QuadTree._object.width;
+ QuadTree._objectBottomEdge = QuadTree._object.y + QuadTree._object.height;
+ //console.log('object properties', QuadTree._objectLeftEdge, QuadTree._objectTopEdge, QuadTree._objectRightEdge, QuadTree._objectBottomEdge);
+ this.addObject();
+ }
+ }
+ };
+ QuadTree.prototype.addObject = /**
+ * Internal function for recursively navigating and creating the tree
+ * while adding objects to the appropriate nodes.
+ */
+ function () {
+ //console.log('addObject');
+ //If this quad (not its children) lies entirely inside this object, add it here
+ if(!this._canSubdivide || ((this._leftEdge >= QuadTree._objectLeftEdge) && (this._rightEdge <= QuadTree._objectRightEdge) && (this._topEdge >= QuadTree._objectTopEdge) && (this._bottomEdge <= QuadTree._objectBottomEdge))) {
+ //console.log('add To List');
+ this.addToList();
+ return;
+ }
+ //See if the selected object fits completely inside any of the quadrants
+ if((QuadTree._objectLeftEdge > this._leftEdge) && (QuadTree._objectRightEdge < this._midpointX)) {
+ if((QuadTree._objectTopEdge > this._topEdge) && (QuadTree._objectBottomEdge < this._midpointY)) {
+ //console.log('Adding NW tree');
+ if(this._northWestTree == null) {
+ this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northWestTree.addObject();
+ return;
+ }
+ if((QuadTree._objectTopEdge > this._midpointY) && (QuadTree._objectBottomEdge < this._bottomEdge)) {
+ //console.log('Adding SW tree');
+ if(this._southWestTree == null) {
+ this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southWestTree.addObject();
+ return;
+ }
+ }
+ if((QuadTree._objectLeftEdge > this._midpointX) && (QuadTree._objectRightEdge < this._rightEdge)) {
+ if((QuadTree._objectTopEdge > this._topEdge) && (QuadTree._objectBottomEdge < this._midpointY)) {
+ //console.log('Adding NE tree');
+ if(this._northEastTree == null) {
+ this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northEastTree.addObject();
+ return;
+ }
+ if((QuadTree._objectTopEdge > this._midpointY) && (QuadTree._objectBottomEdge < this._bottomEdge)) {
+ //console.log('Adding SE tree');
+ if(this._southEastTree == null) {
+ this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southEastTree.addObject();
+ return;
+ }
+ }
+ //If it wasn't completely contained we have to check out the partial overlaps
+ if((QuadTree._objectRightEdge > this._leftEdge) && (QuadTree._objectLeftEdge < this._midpointX) && (QuadTree._objectBottomEdge > this._topEdge) && (QuadTree._objectTopEdge < this._midpointY)) {
+ if(this._northWestTree == null) {
+ this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ //console.log('added to north west partial tree');
+ this._northWestTree.addObject();
+ }
+ if((QuadTree._objectRightEdge > this._midpointX) && (QuadTree._objectLeftEdge < this._rightEdge) && (QuadTree._objectBottomEdge > this._topEdge) && (QuadTree._objectTopEdge < this._midpointY)) {
+ if(this._northEastTree == null) {
+ this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ //console.log('added to north east partial tree');
+ this._northEastTree.addObject();
+ }
+ if((QuadTree._objectRightEdge > this._midpointX) && (QuadTree._objectLeftEdge < this._rightEdge) && (QuadTree._objectBottomEdge > this._midpointY) && (QuadTree._objectTopEdge < this._bottomEdge)) {
+ if(this._southEastTree == null) {
+ this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ //console.log('added to south east partial tree');
+ this._southEastTree.addObject();
+ }
+ if((QuadTree._objectRightEdge > this._leftEdge) && (QuadTree._objectLeftEdge < this._midpointX) && (QuadTree._objectBottomEdge > this._midpointY) && (QuadTree._objectTopEdge < this._bottomEdge)) {
+ if(this._southWestTree == null) {
+ this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ //console.log('added to south west partial tree');
+ this._southWestTree.addObject();
+ }
+ };
+ QuadTree.prototype.addToList = /**
+ * Internal function for recursively adding objects to leaf lists.
+ */
+ function () {
+ //console.log('Adding to List');
+ var ot;
+ if(QuadTree._list == QuadTree.A_LIST) {
+ //console.log('A LIST');
+ if(this._tailA.object != null) {
+ ot = this._tailA;
+ this._tailA = new Phaser.LinkedList();
+ ot.next = this._tailA;
+ }
+ this._tailA.object = QuadTree._object;
+ } else {
+ //console.log('B LIST');
+ if(this._tailB.object != null) {
+ ot = this._tailB;
+ this._tailB = new Phaser.LinkedList();
+ ot.next = this._tailB;
+ }
+ this._tailB.object = QuadTree._object;
+ }
+ if(!this._canSubdivide) {
+ return;
+ }
+ if(this._northWestTree != null) {
+ this._northWestTree.addToList();
+ }
+ if(this._northEastTree != null) {
+ this._northEastTree.addToList();
+ }
+ if(this._southEastTree != null) {
+ this._southEastTree.addToList();
+ }
+ if(this._southWestTree != null) {
+ this._southWestTree.addToList();
+ }
+ };
+ QuadTree.prototype.execute = /**
+ * QuadTree's other main function. Call this after adding objects
+ * using QuadTree.load() to compare the objects that you loaded.
+ *
+ * @return Whether or not any overlaps were found.
+ */
+ function () {
+ //console.log('quadtree execute');
+ var overlapProcessed = false;
+ var iterator;
+ if(this._headA.object != null) {
+ //console.log('---------------------------------------------------');
+ //console.log('headA iterator');
+ iterator = this._headA;
+ while(iterator != null) {
+ QuadTree._object = iterator.object;
+ if(QuadTree._useBothLists) {
+ QuadTree._iterator = this._headB;
+ } else {
+ QuadTree._iterator = iterator.next;
+ }
+ if(QuadTree._object.exists && (QuadTree._object.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode()) {
+ //console.log('headA iterator overlapped true');
+ overlapProcessed = true;
+ }
+ iterator = iterator.next;
+ }
+ }
+ //Advance through the tree by calling overlap on each child
+ if((this._northWestTree != null) && this._northWestTree.execute()) {
+ //console.log('NW quadtree execute');
+ overlapProcessed = true;
+ }
+ if((this._northEastTree != null) && this._northEastTree.execute()) {
+ //console.log('NE quadtree execute');
+ overlapProcessed = true;
+ }
+ if((this._southEastTree != null) && this._southEastTree.execute()) {
+ //console.log('SE quadtree execute');
+ overlapProcessed = true;
+ }
+ if((this._southWestTree != null) && this._southWestTree.execute()) {
+ //console.log('SW quadtree execute');
+ overlapProcessed = true;
+ }
+ return overlapProcessed;
+ };
+ QuadTree.prototype.overlapNode = /**
+ * An private for comparing an object against the contents of a node.
+ *
+ * @return Whether or not any overlaps were found.
+ */
+ function () {
+ //console.log('overlapNode');
+ //Walk the list and check for overlaps
+ var overlapProcessed = false;
+ var checkObject;
+ while(QuadTree._iterator != null) {
+ if(!QuadTree._object.exists || (QuadTree._object.allowCollisions <= 0)) {
+ //console.log('break 1');
+ break;
+ }
+ checkObject = QuadTree._iterator.object;
+ if((QuadTree._object === checkObject) || !checkObject.exists || (checkObject.allowCollisions <= 0)) {
+ //console.log('break 2');
+ QuadTree._iterator = QuadTree._iterator.next;
+ continue;
+ }
+ //calculate bulk hull for QuadTree._object
+ QuadTree._objectHullX = (QuadTree._object.x < QuadTree._object.last.x) ? QuadTree._object.x : QuadTree._object.last.x;
+ QuadTree._objectHullY = (QuadTree._object.y < QuadTree._object.last.y) ? QuadTree._object.y : QuadTree._object.last.y;
+ QuadTree._objectHullWidth = QuadTree._object.x - QuadTree._object.last.x;
+ QuadTree._objectHullWidth = QuadTree._object.width + ((QuadTree._objectHullWidth > 0) ? QuadTree._objectHullWidth : -QuadTree._objectHullWidth);
+ QuadTree._objectHullHeight = QuadTree._object.y - QuadTree._object.last.y;
+ QuadTree._objectHullHeight = QuadTree._object.height + ((QuadTree._objectHullHeight > 0) ? QuadTree._objectHullHeight : -QuadTree._objectHullHeight);
+ //calculate bulk hull for checkObject
+ QuadTree._checkObjectHullX = (checkObject.x < checkObject.last.x) ? checkObject.x : checkObject.last.x;
+ QuadTree._checkObjectHullY = (checkObject.y < checkObject.last.y) ? checkObject.y : checkObject.last.y;
+ QuadTree._checkObjectHullWidth = checkObject.x - checkObject.last.x;
+ QuadTree._checkObjectHullWidth = checkObject.width + ((QuadTree._checkObjectHullWidth > 0) ? QuadTree._checkObjectHullWidth : -QuadTree._checkObjectHullWidth);
+ QuadTree._checkObjectHullHeight = checkObject.y - checkObject.last.y;
+ QuadTree._checkObjectHullHeight = checkObject.height + ((QuadTree._checkObjectHullHeight > 0) ? QuadTree._checkObjectHullHeight : -QuadTree._checkObjectHullHeight);
+ //check for intersection of the two hulls
+ if((QuadTree._objectHullX + QuadTree._objectHullWidth > QuadTree._checkObjectHullX) && (QuadTree._objectHullX < QuadTree._checkObjectHullX + QuadTree._checkObjectHullWidth) && (QuadTree._objectHullY + QuadTree._objectHullHeight > QuadTree._checkObjectHullY) && (QuadTree._objectHullY < QuadTree._checkObjectHullY + QuadTree._checkObjectHullHeight)) {
+ //console.log('intersection!');
+ //Execute callback functions if they exist
+ if((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, checkObject)) {
+ overlapProcessed = true;
+ }
+ if(overlapProcessed && (QuadTree._notifyCallback != null)) {
+ QuadTree._notifyCallback(QuadTree._object, checkObject);
+ }
+ }
+ QuadTree._iterator = QuadTree._iterator.next;
+ }
+ return overlapProcessed;
+ };
+ return QuadTree;
+ })(Phaser.Rectangle);
+ Phaser.QuadTree = QuadTree;
+})(Phaser || (Phaser = {}));
+/// GameObject 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 Group (or even bundling groups together!).
+ *
+ * NOTE: does NOT take objects' scrollfactor into account, all overlaps are checked in world space.
+ * + * @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 twoGameObject parameters - e.g. myOverlapFunction(Object1:GameObject,Object2:GameObject) - that is called if those two objects overlap.
+ * @param ProcessCallback A function with two GameObject parameters - e.g. myOverlapFunction(Object1:GameObject,Object2:GameObject) - 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.
+ */
+ function (ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, ProcessCallback) {
+ if (typeof ObjectOrGroup1 === "undefined") { ObjectOrGroup1 = null; }
+ if (typeof ObjectOrGroup2 === "undefined") { ObjectOrGroup2 = null; }
+ if (typeof NotifyCallback === "undefined") { NotifyCallback = null; }
+ if (typeof ProcessCallback === "undefined") { ProcessCallback = null; }
+ if(ObjectOrGroup1 == null) {
+ ObjectOrGroup1 = this._game.world.group;
+ }
+ if(ObjectOrGroup2 == ObjectOrGroup1) {
+ ObjectOrGroup2 = null;
+ }
+ Phaser.QuadTree.divisions = this._game.world.worldDivisions;
+ var quadTree = new Phaser.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 = quadTree.execute();
+ quadTree.destroy();
+ quadTree = null;
+ return result;
+ };
+ Collision.separate = /**
+ * The main collision resolution in flixel.
+ *
+ * @param Object1 Any Sprite.
+ * @param Object2 Any other Sprite.
+ *
+ * @return Whether the objects in fact touched and were separated.
+ */
+ function separate(Object1, Object2) {
+ var separatedX = Collision.separateX(Object1, Object2);
+ var separatedY = Collision.separateY(Object1, Object2);
+ return separatedX || separatedY;
+ };
+ Collision.separateX = /**
+ * The X-axis component of the object separation process.
+ *
+ * @param Object1 Any Sprite.
+ * @param Object2 Any other Sprite.
+ *
+ * @return Whether the objects in fact touched and were separated along the X axis.
+ */
+ function separateX(Object1, Object2) {
+ //can't separate two immovable objects
+ var obj1immovable = Object1.immovable;
+ var obj2immovable = 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 = 0;
+ var obj1delta = Object1.x - Object1.last.x;
+ var obj2delta = Object2.x - Object2.last.x;
+ if(obj1delta != obj2delta) {
+ //Check if the X hulls actually overlap
+ var obj1deltaAbs = (obj1delta > 0) ? obj1delta : -obj1delta;
+ var obj2deltaAbs = (obj2delta > 0) ? obj2delta : -obj2delta;
+ var obj1rect = new Phaser.Rectangle(Object1.x - ((obj1delta > 0) ? obj1delta : 0), Object1.last.y, Object1.width + ((obj1delta > 0) ? obj1delta : -obj1delta), Object1.height);
+ var obj2rect = new Phaser.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 = 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 = Object1.velocity.x;
+ var obj2v = Object2.velocity.x;
+ if(!obj1immovable && !obj2immovable) {
+ overlap *= 0.5;
+ Object1.x = Object1.x - overlap;
+ Object2.x += overlap;
+ var obj1velocity = Math.sqrt((obj2v * obj2v * Object2.mass) / Object1.mass) * ((obj2v > 0) ? 1 : -1);
+ var obj2velocity = Math.sqrt((obj1v * obj1v * Object1.mass) / Object2.mass) * ((obj1v > 0) ? 1 : -1);
+ var average = (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;
+ }
+ };
+ Collision.separateY = /**
+ * The Y-axis component of the object separation process.
+ *
+ * @param Object1 Any Sprite.
+ * @param Object2 Any other Sprite.
+ *
+ * @return Whether the objects in fact touched and were separated along the Y axis.
+ */
+ function separateY(Object1, Object2) {
+ //can't separate two immovable objects
+ var obj1immovable = Object1.immovable;
+ var obj2immovable = 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 = 0;
+ var obj1delta = Object1.y - Object1.last.y;
+ var obj2delta = Object2.y - Object2.last.y;
+ if(obj1delta != obj2delta) {
+ //Check if the Y hulls actually overlap
+ var obj1deltaAbs = (obj1delta > 0) ? obj1delta : -obj1delta;
+ var obj2deltaAbs = (obj2delta > 0) ? obj2delta : -obj2delta;
+ var obj1rect = new Phaser.Rectangle(Object1.x, Object1.y - ((obj1delta > 0) ? obj1delta : 0), Object1.width, Object1.height + obj1deltaAbs);
+ var obj2rect = new Phaser.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 = 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 = Object1.velocity.y;
+ var obj2v = Object2.velocity.y;
+ if(!obj1immovable && !obj2immovable) {
+ overlap *= 0.5;
+ Object1.y = Object1.y - overlap;
+ Object2.y += overlap;
+ var obj1velocity = Math.sqrt((obj2v * obj2v * Object2.mass) / Object1.mass) * ((obj2v > 0) ? 1 : -1);
+ var obj2velocity = Math.sqrt((obj1v * obj1v * Object1.mass) / Object2.mass) * ((obj1v > 0) ? 1 : -1);
+ var average = (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;
+ }
+ };
+ Collision.distance = /**
+ * -------------------------------------------------------------------------------------------
+ * Distance
+ * -------------------------------------------------------------------------------------------
+ **/
+ function distance(x1, y1, x2, y2) {
+ return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
+ };
+ Collision.distanceSquared = function distanceSquared(x1, y1, x2, y2) {
+ return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
+ };
+ return Collision;
+ })();
+ Phaser.Collision = Collision;
+})(Phaser || (Phaser = {}));
+/// + * Returns true or false based on the chance value (default 50%). For example if you wanted a player to have a 30% chance + * of getting a bonus, call chanceRoll(30) - true means the chance passed, false means it failed. + *
+ * @param chance The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%) + * @return true if the roll passed, or false + */ + function (chance) { + if (typeof chance === "undefined") { chance = 50; } + if(chance <= 0) { + return false; + } else if(chance >= 100) { + return true; + } else { + if(Math.random() * 100 >= chance) { + return false; + } else { + return true; + } + } + }; + GameMath.prototype.maxAdd = /** + * Adds the given amount to the value, but never lets the value go over the specified maximum + * + * @param value The value to add the amount to + * @param amount The amount to add to the value + * @param max The maximum the value is allowed to be + * @return The new value + */ + function (value, amount, max) { + value += amount; + if(value > max) { + value = max; + } + return value; + }; + GameMath.prototype.minSub = /** + * Subtracts the given amount from the value, but never lets the value go below the specified minimum + * + * @param value The base value + * @param amount The amount to subtract from the base value + * @param min The minimum the value is allowed to be + * @return The new value + */ + function (value, amount, min) { + value -= amount; + if(value < min) { + value = min; + } + return value; + }; + GameMath.prototype.wrapValue = /** + * Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around. + *Values must be positive integers, and are passed through Math.abs
+ * + * @param value The value to add the amount to + * @param amount The amount to add to the value + * @param max The maximum the value is allowed to be + * @return The wrapped value + */ + function (value, amount, max) { + var diff; + value = Math.abs(value); + amount = Math.abs(amount); + max = Math.abs(max); + diff = (value + amount) % max; + return diff; + }; + GameMath.prototype.randomSign = /** + * Randomly returns either a 1 or -1 + * + * @return 1 or -1 + */ + function () { + return (Math.random() > 0.5) ? 1 : -1; + }; + GameMath.prototype.isOdd = /** + * Returns true if the number given is odd. + * + * @param n The number to check + * + * @return True if the given number is odd. False if the given number is even. + */ + function (n) { + if(n & 1) { + return true; + } else { + return false; + } + }; + GameMath.prototype.isEven = /** + * Returns true if the number given is even. + * + * @param n The number to check + * + * @return True if the given number is even. False if the given number is odd. + */ + function (n) { + if(n & 1) { + return false; + } else { + return true; + } + }; + GameMath.prototype.wrapAngle = /** + * Keeps an angle value between -180 and +180Number between 0 and 1.
+ */
+ function () {
+ return this.globalSeed = this.srand(this.globalSeed);
+ };
+ GameMath.prototype.srand = /**
+ * Generates a random number based on the seed provided.
+ *
+ * @param Seed A number between 0 and 1, used to generate a predictable random number (very optional).
+ *
+ * @return A Number between 0 and 1.
+ */
+ function (Seed) {
+ return ((69621 * (Seed * 0x7FFFFFFF)) % 0x7FFFFFFF) / 0x7FFFFFFF;
+ };
+ GameMath.prototype.getRandom = /**
+ * Fetch a random entry from the given array.
+ * Will return null if random selection is missing, or array has no entries.
+ * FlxG.getRandom() is deterministic and safe for use with replays/recordings.
+ * HOWEVER, FlxU.getRandom() is NOT deterministic and unsafe for use with replays/recordings.
+ *
+ * @param Objects An array of objects.
+ * @param StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
+ * @param Length Optional restriction on the number of values you want to randomly select from.
+ *
+ * @return The random object that was selected.
+ */
+ function (Objects, StartIndex, Length) {
+ if (typeof StartIndex === "undefined") { StartIndex = 0; }
+ if (typeof Length === "undefined") { Length = 0; }
+ if(Objects != null) {
+ var l = Length;
+ if((l == 0) || (l > Objects.length - StartIndex)) {
+ l = Objects.length - StartIndex;
+ }
+ if(l > 0) {
+ return Objects[StartIndex + Math.floor(Math.random() * l)];
+ }
+ }
+ return null;
+ };
+ GameMath.prototype.floor = /**
+ * Round down to the next whole number. E.g. floor(1.7) == 1, and floor(-2.7) == -2.
+ *
+ * @param Value Any number.
+ *
+ * @return The rounded value of that number.
+ */
+ function (Value) {
+ var n = Value | 0;
+ return (Value > 0) ? (n) : ((n != Value) ? (n - 1) : (n));
+ };
+ GameMath.prototype.ceil = /**
+ * Round up to the next whole number. E.g. ceil(1.3) == 2, and ceil(-2.3) == -3.
+ *
+ * @param Value Any number.
+ *
+ * @return The rounded value of that number.
+ */
+ function (Value) {
+ var n = Value | 0;
+ return (Value > 0) ? ((n != Value) ? (n + 1) : (n)) : (n);
+ };
+ GameMath.prototype.sinCosGenerator = /**
+ * Generate a sine and cosine table simultaneously and extremely quickly. Based on research by Franky of scene.at
+ * + * The parameters allow you to specify the length, amplitude and frequency of the wave. Once you have called this function + * you should get the results via getSinTable() and getCosTable(). This generator is fast enough to be used in real-time. + *
+ * @param length The length of the wave + * @param sinAmplitude The amplitude to apply to the sine table (default 1.0) if you need values between say -+ 125 then give 125 as the value + * @param cosAmplitude The amplitude to apply to the cosine table (default 1.0) if you need values between say -+ 125 then give 125 as the value + * @param frequency The frequency of the sine and cosine table data + * @return Returns the sine table + * @see getSinTable + * @see getCosTable + */ + function (length, sinAmplitude, cosAmplitude, frequency) { + if (typeof sinAmplitude === "undefined") { sinAmplitude = 1.0; } + if (typeof cosAmplitude === "undefined") { cosAmplitude = 1.0; } + if (typeof frequency === "undefined") { frequency = 1.0; } + var sin = sinAmplitude; + var cos = cosAmplitude; + var frq = frequency * Math.PI / length; + this.cosTable = []; + this.sinTable = []; + for(var c = 0; c < length; c++) { + cos -= sin * frq; + sin += cos * frq; + this.cosTable[c] = cos; + this.sinTable[c] = sin; + } + return this.sinTable; + }; + GameMath.prototype.vectorLength = /** + * Finds the length of the given vector + * + * @param dx + * @param dy + * + * @return + */ + function (dx, dy) { + return Math.sqrt(dx * dx + dy * dy); + }; + GameMath.prototype.dotProduct = /** + * 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 + */ + function (ax, ay, bx, by) { + return ax * bx + ay * by; + }; + return GameMath; + })(); + Phaser.GameMath = GameMath; +})(Phaser || (Phaser = {})); +///Basics.
+* NOTE: Although Group extends Basic, it will not automatically
+* add itself to the global collisions quad tree, it will only add its members.
+*
+* @author Adam Atomic
+* @author Richard Davey
+*/
+/**
+* Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ var Group = (function (_super) {
+ __extends(Group, _super);
+ function Group(game, MaxSize) {
+ if (typeof MaxSize === "undefined") { MaxSize = 0; }
+ _super.call(this, game);
+ this.isGroup = true;
+ this.members = [];
+ this.length = 0;
+ this._maxSize = MaxSize;
+ this._marker = 0;
+ this._sortIndex = null;
+ }
+ Group.ASCENDING = -1;
+ Group.DESCENDING = 1;
+ Group.prototype.destroy = /**
+ * Override this function to handle any deleting or "shutdown" type operations you might need,
+ * such as removing traditional Flash children like Basic objects.
+ */
+ function () {
+ if(this.members != null) {
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if(basic != null) {
+ basic.destroy();
+ }
+ }
+ this.members.length = 0;
+ }
+ this._sortIndex = null;
+ };
+ Group.prototype.update = /**
+ * Automatically goes through and calls update on everything you added.
+ */
+ function () {
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if((basic != null) && basic.exists && basic.active) {
+ basic.preUpdate();
+ basic.update();
+ basic.postUpdate();
+ }
+ }
+ };
+ Group.prototype.render = /**
+ * Automatically goes through and calls render on everything you added.
+ */
+ function (camera, cameraOffsetX, cameraOffsetY) {
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if((basic != null) && basic.exists && basic.visible) {
+ basic.render(camera, cameraOffsetX, cameraOffsetY);
+ }
+ }
+ };
+ Object.defineProperty(Group.prototype, "maxSize", {
+ get: /**
+ * The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow.
+ */
+ function () {
+ return this._maxSize;
+ },
+ set: /**
+ * @private
+ */
+ function (Size) {
+ this._maxSize = Size;
+ if(this._marker >= this._maxSize) {
+ this._marker = 0;
+ }
+ if((this._maxSize == 0) || (this.members == null) || (this._maxSize >= this.members.length)) {
+ return;
+ }
+ //If the max size has shrunk, we need to get rid of some objects
+ var basic;
+ var i = this._maxSize;
+ var l = this.members.length;
+ while(i < l) {
+ basic = this.members[i++];
+ if(basic != null) {
+ basic.destroy();
+ }
+ }
+ this.length = this.members.length = this._maxSize;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Group.prototype.add = /**
+ * Adds a new Basic subclass (Basic, FlxBasic, Enemy, etc) to the group.
+ * Group will try to replace a null member of the array first.
+ * Failing that, Group will add it to the end of the member array,
+ * assuming there is room for it, and doubling the size of the array if necessary.
+ *
+ * WARNING: If the group has a maxSize that has already been met, + * the object will NOT be added to the group!
+ * + * @param Object The object you want to add to the group. + * + * @return The sameBasic object that was passed in.
+ */
+ function (Object) {
+ //Don't bother adding an object twice.
+ if(this.members.indexOf(Object) >= 0) {
+ return Object;
+ }
+ //First, look for a null entry where we can add the object.
+ var i = 0;
+ var l = this.members.length;
+ while(i < l) {
+ if(this.members[i] == null) {
+ this.members[i] = Object;
+ if(i >= this.length) {
+ this.length = i + 1;
+ }
+ return Object;
+ }
+ i++;
+ }
+ //Failing that, expand the array (if we can) and add the object.
+ if(this._maxSize > 0) {
+ if(this.members.length >= this._maxSize) {
+ return Object;
+ } else if(this.members.length * 2 <= this._maxSize) {
+ this.members.length *= 2;
+ } else {
+ this.members.length = this._maxSize;
+ }
+ } else {
+ this.members.length *= 2;
+ }
+ //If we made it this far, then we successfully grew the group,
+ //and we can go ahead and add the object at the first open slot.
+ this.members[i] = Object;
+ this.length = i + 1;
+ return Object;
+ };
+ Group.prototype.recycle = /**
+ * Recycling is designed to help you reuse game objects without always re-allocating or "newing" them.
+ *
+ * If you specified a maximum size for this group (like in Emitter), + * then recycle will employ what we're calling "rotating" recycling. + * Recycle() will first check to see if the group is at capacity yet. + * If group is not yet at capacity, recycle() returns a new object. + * If the group IS at capacity, then recycle() just returns the next object in line.
+ * + *If you did NOT specify a maximum size for this group, + * then recycle() will employ what we're calling "grow-style" recycling. + * Recycle() will return either the first object with exists == false, + * or, finding none, add a new object to the array, + * doubling the size of the array if necessary.
+ * + *WARNING: If this function needs to create a new object, + * and no object class was provided, it will return null + * instead of a valid object!
+ * + * @param ObjectClass The class type you want to recycle (e.g. FlxBasic, EvilRobot, etc). Do NOT "new" the class in the parameter! + * + * @return A reference to the object that was created. Don't forget to cast it back to the Class you want (e.g. myObject = myGroup.recycle(myObjectClass) as myObjectClass;). + */ + function (ObjectClass) { + if (typeof ObjectClass === "undefined") { ObjectClass = null; } + var basic; + if(this._maxSize > 0) { + if(this.length < this._maxSize) { + if(ObjectClass == null) { + return null; + } + return this.add(new ObjectClass()); + } else { + basic = this.members[this._marker++]; + if(this._marker >= this._maxSize) { + this._marker = 0; + } + return basic; + } + } else { + basic = this.getFirstAvailable(ObjectClass); + if(basic != null) { + return basic; + } + if(ObjectClass == null) { + return null; + } + return this.add(new ObjectClass()); + } + }; + Group.prototype.remove = /** + * Removes an object from the group. + * + * @param Object TheBasic you want to remove.
+ * @param Splice Whether the object should be cut from the array entirely or not.
+ *
+ * @return The removed object.
+ */
+ function (Object, Splice) {
+ if (typeof Splice === "undefined") { Splice = false; }
+ var index = this.members.indexOf(Object);
+ if((index < 0) || (index >= this.members.length)) {
+ return null;
+ }
+ if(Splice) {
+ this.members.splice(index, 1);
+ this.length--;
+ } else {
+ this.members[index] = null;
+ }
+ return Object;
+ };
+ Group.prototype.replace = /**
+ * Replaces an existing Basic with a new one.
+ *
+ * @param OldObject The object you want to replace.
+ * @param NewObject The new object you want to use instead.
+ *
+ * @return The new object.
+ */
+ function (OldObject, NewObject) {
+ var index = this.members.indexOf(OldObject);
+ if((index < 0) || (index >= this.members.length)) {
+ return null;
+ }
+ this.members[index] = NewObject;
+ return NewObject;
+ };
+ Group.prototype.sort = /**
+ * Call this function to sort the group according to a particular value and order.
+ * For example, to sort game objects for Zelda-style overlaps you might call
+ * myGroup.sort("y",Group.ASCENDING) at the bottom of your
+ * FlxState.update() override. To sort all existing objects after
+ * a big explosion or bomb attack, you might call myGroup.sort("exists",Group.DESCENDING).
+ *
+ * @param Index The string name of the member variable you want to sort on. Default value is "y".
+ * @param Order A Group constant that defines the sort order. Possible values are Group.ASCENDING and Group.DESCENDING. Default value is Group.ASCENDING.
+ */
+ function (Index, Order) {
+ if (typeof Index === "undefined") { Index = "y"; }
+ if (typeof Order === "undefined") { Order = Group.ASCENDING; }
+ this._sortIndex = Index;
+ this._sortOrder = Order;
+ this.members.sort(this.sortHandler);
+ };
+ Group.prototype.setAll = /**
+ * Go through and set the specified variable to the specified value on all members of the group.
+ *
+ * @param VariableName The string representation of the variable name you want to modify, for example "visible" or "scrollFactor".
+ * @param Value The value you want to assign to that variable.
+ * @param Recurse Default value is true, meaning if setAll() encounters a member that is a group, it will call setAll() on that group rather than modifying its variable.
+ */
+ function (VariableName, Value, Recurse) {
+ if (typeof Recurse === "undefined") { Recurse = true; }
+ var basic;
+ var i = 0;
+ while(i < length) {
+ basic = this.members[i++];
+ if(basic != null) {
+ if(Recurse && (basic.isGroup == true)) {
+ basic['setAll'](VariableName, Value, Recurse);
+ } else {
+ basic[VariableName] = Value;
+ }
+ }
+ }
+ };
+ Group.prototype.callAll = /**
+ * Go through and call the specified function on all members of the group.
+ * Currently only works on functions that have no required parameters.
+ *
+ * @param FunctionName The string representation of the function you want to call on each object, for example "kill()" or "init()".
+ * @param Recurse Default value is true, meaning if callAll() encounters a member that is a group, it will call callAll() on that group rather than calling the group's function.
+ */
+ function (FunctionName, Recurse) {
+ if (typeof Recurse === "undefined") { Recurse = true; }
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if(basic != null) {
+ if(Recurse && (basic.isGroup == true)) {
+ basic['callAll'](FunctionName, Recurse);
+ } else {
+ basic[FunctionName]();
+ }
+ }
+ }
+ };
+ Group.prototype.forEach = function (callback, Recurse) {
+ if (typeof Recurse === "undefined") { Recurse = false; }
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if(basic != null) {
+ if(Recurse && (basic.isGroup == true)) {
+ basic.forEach(callback, true);
+ } else {
+ callback.call(this, basic);
+ }
+ }
+ }
+ };
+ Group.prototype.getFirstAvailable = /**
+ * Call this function to retrieve the first object with exists == false in the group.
+ * This is handy for recycling in general, e.g. respawning enemies.
+ *
+ * @param ObjectClass An optional parameter that lets you narrow the results to instances of this particular class.
+ *
+ * @return A Basic currently flagged as not existing.
+ */
+ function (ObjectClass) {
+ if (typeof ObjectClass === "undefined") { ObjectClass = null; }
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if((basic != null) && !basic.exists && ((ObjectClass == null) || (typeof basic === ObjectClass))) {
+ return basic;
+ }
+ }
+ return null;
+ };
+ Group.prototype.getFirstNull = /**
+ * Call this function to retrieve the first index set to 'null'.
+ * Returns -1 if no index stores a null object.
+ *
+ * @return An int indicating the first null slot in the group.
+ */
+ function () {
+ var basic;
+ var i = 0;
+ var l = this.members.length;
+ while(i < l) {
+ if(this.members[i] == null) {
+ return i;
+ } else {
+ i++;
+ }
+ }
+ return -1;
+ };
+ Group.prototype.getFirstExtant = /**
+ * Call this function to retrieve the first object with exists == true in the group.
+ * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
+ *
+ * @return A Basic currently flagged as existing.
+ */
+ function () {
+ var basic;
+ var i = 0;
+ while(i < length) {
+ basic = this.members[i++];
+ if((basic != null) && basic.exists) {
+ return basic;
+ }
+ }
+ return null;
+ };
+ Group.prototype.getFirstAlive = /**
+ * Call this function to retrieve the first object with dead == false in the group.
+ * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
+ *
+ * @return A Basic currently flagged as not dead.
+ */
+ function () {
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if((basic != null) && basic.exists && basic.alive) {
+ return basic;
+ }
+ }
+ return null;
+ };
+ Group.prototype.getFirstDead = /**
+ * Call this function to retrieve the first object with dead == true in the group.
+ * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
+ *
+ * @return A Basic currently flagged as dead.
+ */
+ function () {
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if((basic != null) && !basic.alive) {
+ return basic;
+ }
+ }
+ return null;
+ };
+ Group.prototype.countLiving = /**
+ * Call this function to find out how many members of the group are not dead.
+ *
+ * @return The number of Basics flagged as not dead. Returns -1 if group is empty.
+ */
+ function () {
+ var count = -1;
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if(basic != null) {
+ if(count < 0) {
+ count = 0;
+ }
+ if(basic.exists && basic.alive) {
+ count++;
+ }
+ }
+ }
+ return count;
+ };
+ Group.prototype.countDead = /**
+ * Call this function to find out how many members of the group are dead.
+ *
+ * @return The number of Basics flagged as dead. Returns -1 if group is empty.
+ */
+ function () {
+ var count = -1;
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if(basic != null) {
+ if(count < 0) {
+ count = 0;
+ }
+ if(!basic.alive) {
+ count++;
+ }
+ }
+ }
+ return count;
+ };
+ Group.prototype.getRandom = /**
+ * Returns a member at random from the group.
+ *
+ * @param StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
+ * @param Length Optional restriction on the number of values you want to randomly select from.
+ *
+ * @return A Basic from the members list.
+ */
+ function (StartIndex, Length) {
+ if (typeof StartIndex === "undefined") { StartIndex = 0; }
+ if (typeof Length === "undefined") { Length = 0; }
+ if(Length == 0) {
+ Length = this.length;
+ }
+ return this._game.math.getRandom(this.members, StartIndex, Length);
+ };
+ Group.prototype.clear = /**
+ * Remove all instances of Basic subclass (FlxBasic, FlxBlock, etc) from the list.
+ * WARNING: does not destroy() or kill() any of these objects!
+ */
+ function () {
+ this.length = this.members.length = 0;
+ };
+ Group.prototype.kill = /**
+ * Calls kill on the group's members and then on the group itself.
+ */
+ function () {
+ var basic;
+ var i = 0;
+ while(i < this.length) {
+ basic = this.members[i++];
+ if((basic != null) && basic.exists) {
+ basic.kill();
+ }
+ }
+ };
+ Group.prototype.sortHandler = /**
+ * Helper function for the sort process.
+ *
+ * @param Obj1 The first object being sorted.
+ * @param Obj2 The second object being sorted.
+ *
+ * @return An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
+ */
+ function (Obj1, Obj2) {
+ if(Obj1[this._sortIndex] < Obj2[this._sortIndex]) {
+ return this._sortOrder;
+ } else if(Obj1[this._sortIndex] > Obj2[this._sortIndex]) {
+ return -this._sortOrder;
+ }
+ return 0;
+ };
+ return Group;
+ })(Phaser.Basic);
+ Phaser.Group = Group;
+})(Phaser || (Phaser = {}));
+/// If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.
+ * @param {Array} [paramsArr] Array of parameters that should be passed to the listener + * @return {*} Value returned by the listener. + */ + function (paramsArr) { + var handlerReturn; + var params; + if(this.active && !!this._listener) { + params = this.params ? this.params.concat(paramsArr) : paramsArr; + handlerReturn = this._listener.apply(this.context, params); + if(this._isOnce) { + this.detach(); + } + } + return handlerReturn; + }; + SignalBinding.prototype.detach = /** + * Detach binding from signal. + * - alias to: mySignal.remove(myBinding.getListener()); + * @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached. + */ + function () { + return this.isBound() ? this._signal.remove(this._listener, this.context) : null; + }; + SignalBinding.prototype.isBound = /** + * @return {Boolean} `true` if binding is still bound to the signal and have a listener. + */ + function () { + return (!!this._signal && !!this._listener); + }; + SignalBinding.prototype.isOnce = /** + * @return {boolean} If SignalBinding will only be executed once. + */ + function () { + return this._isOnce; + }; + SignalBinding.prototype.getListener = /** + * @return {Function} Handler function bound to the signal. + */ + function () { + return this._listener; + }; + SignalBinding.prototype.getSignal = /** + * @return {Signal} Signal that listener is currently bound to. + */ + function () { + return this._signal; + }; + SignalBinding.prototype._destroy = /** + * Delete instance properties + * @private + */ + function () { + delete this._signal; + delete this._listener; + delete this.context; + }; + SignalBinding.prototype.toString = /** + * @return {string} String representation of the object. + */ + function () { + return '[SignalBinding isOnce:' + this._isOnce + ', isBound:' + this.isBound() + ', active:' + this.active + ']'; + }; + return SignalBinding; + })(); + Phaser.SignalBinding = SignalBinding; +})(Phaser || (Phaser = {})); +///IMPORTANT: Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.
+ * @type boolean + */ + this.active = true; + } + Signal.VERSION = '1.0.0'; + Signal.prototype.validateListener = /** + * + * @method validateListener + * @param {Any} listener + * @param {Any} fnName + */ + function (listener, fnName) { + if(typeof listener !== 'function') { + throw new Error('listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName)); + } + }; + Signal.prototype._registerListener = /** + * @param {Function} listener + * @param {boolean} isOnce + * @param {Object} [listenerContext] + * @param {Number} [priority] + * @return {SignalBinding} + * @private + */ + function (listener, isOnce, listenerContext, priority) { + var prevIndex = this._indexOfListener(listener, listenerContext); + var binding; + if(prevIndex !== -1) { + binding = this._bindings[prevIndex]; + if(binding.isOnce() !== isOnce) { + throw new Error('You cannot add' + (isOnce ? '' : 'Once') + '() then add' + (!isOnce ? '' : 'Once') + '() the same listener without removing the relationship first.'); + } + } else { + binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority); + this._addBinding(binding); + } + if(this.memorize && this._prevParams) { + binding.execute(this._prevParams); + } + return binding; + }; + Signal.prototype._addBinding = /** + * + * @method _addBinding + * @param {SignalBinding} binding + * @private + */ + function (binding) { + //simplified insertion sort + var n = this._bindings.length; + do { + --n; + }while(this._bindings[n] && binding.priority <= this._bindings[n].priority); + this._bindings.splice(n + 1, 0, binding); + }; + Signal.prototype._indexOfListener = /** + * + * @method _indexOfListener + * @param {Function} listener + * @return {number} + * @private + */ + function (listener, context) { + var n = this._bindings.length; + var cur; + while(n--) { + cur = this._bindings[n]; + if(cur.getListener() === listener && cur.context === context) { + return n; + } + } + return -1; + }; + Signal.prototype.has = /** + * Check if listener was attached to Signal. + * @param {Function} listener + * @param {Object} [context] + * @return {boolean} if Signal has the specified listener. + */ + function (listener, context) { + if (typeof context === "undefined") { context = null; } + return this._indexOfListener(listener, context) !== -1; + }; + Signal.prototype.add = /** + * Add a listener to the signal. + * @param {Function} listener Signal handler function. + * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). + * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) + * @return {SignalBinding} An Object representing the binding between the Signal and listener. + */ + function (listener, listenerContext, priority) { + if (typeof listenerContext === "undefined") { listenerContext = null; } + if (typeof priority === "undefined") { priority = 0; } + this.validateListener(listener, 'add'); + return this._registerListener(listener, false, listenerContext, priority); + }; + Signal.prototype.addOnce = /** + * Add listener to the signal that should be removed after first execution (will be executed only once). + * @param {Function} listener Signal handler function. + * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). + * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) + * @return {SignalBinding} An Object representing the binding between the Signal and listener. + */ + function (listener, listenerContext, priority) { + if (typeof listenerContext === "undefined") { listenerContext = null; } + if (typeof priority === "undefined") { priority = 0; } + this.validateListener(listener, 'addOnce'); + return this._registerListener(listener, true, listenerContext, priority); + }; + Signal.prototype.remove = /** + * Remove a single listener from the dispatch queue. + * @param {Function} listener Handler function that should be removed. + * @param {Object} [context] Execution context (since you can add the same handler multiple times if executing in a different context). + * @return {Function} Listener handler function. + */ + function (listener, context) { + if (typeof context === "undefined") { context = null; } + this.validateListener(listener, 'remove'); + var i = this._indexOfListener(listener, context); + if(i !== -1) { + this._bindings[i]._destroy()//no reason to a SignalBinding exist if it isn't attached to a signal + ; + this._bindings.splice(i, 1); + } + return listener; + }; + Signal.prototype.removeAll = /** + * Remove all listeners from the Signal. + */ + function () { + var n = this._bindings.length; + while(n--) { + this._bindings[n]._destroy(); + } + this._bindings.length = 0; + }; + Signal.prototype.getNumListeners = /** + * @return {number} Number of listeners attached to the Signal. + */ + function () { + return this._bindings.length; + }; + Signal.prototype.halt = /** + * Stop propagation of the event, blocking the dispatch to next listeners on the queue. + *IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.
+ * @see Signal.prototype.disable + */ + function () { + this._shouldPropagate = false; + }; + Signal.prototype.dispatch = /** + * Dispatch/Broadcast Signal to all listeners added to the queue. + * @param {...*} [params] Parameters that should be passed to each handler. + */ + function () { + var paramsArr = []; + for (var _i = 0; _i < (arguments.length - 0); _i++) { + paramsArr[_i] = arguments[_i + 0]; + } + if(!this.active) { + return; + } + var n = this._bindings.length; + var bindings; + if(this.memorize) { + this._prevParams = paramsArr; + } + if(!n) { + //should come after memorize + return; + } + bindings = this._bindings.slice(0)//clone array in case add/remove items during dispatch + ; + this._shouldPropagate = true//in case `halt` was called before dispatch or during the previous dispatch. + ; + //execute all callbacks until end of the list or until a callback returns `false` or stops propagation + //reverse loop since listeners with higher priority will be added at the end of the list + do { + n--; + }while(bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false); + }; + Signal.prototype.forget = /** + * Forget memorized arguments. + * @see Signal.memorize + */ + function () { + this._prevParams = null; + }; + Signal.prototype.dispose = /** + * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object). + *IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.
+ */ + function () { + this.removeAll(); + delete this._bindings; + delete this._prevParams; + }; + Signal.prototype.toString = /** + * @return {string} String representation of the object. + */ + function () { + return '[Signal active:' + this.active + ' numListeners:' + this.getNumListeners() + ']'; + }; + return Signal; + })(); + Phaser.Signal = Signal; +})(Phaser || (Phaser = {})); +///Emitter is a lightweight particle emitter.
+* It can be used for one-time explosions or for
+* continuous fx like rain and fire. Emitter
+* is not optimized or anything; all it does is launch
+* Particle objects out at set intervals
+* by setting their positions and velocities accordingly.
+* It is easy to use and relatively efficient,
+* relying on Group's RECYCLE POWERS.
+*
+* @author Adam Atomic
+* @author Richard Davey
+*/
+/**
+* Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ var Emitter = (function (_super) {
+ __extends(Emitter, _super);
+ /**
+ * Creates a new FlxEmitter 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.
+ */
+ function Emitter(game, X, Y, Size) {
+ if (typeof X === "undefined") { X = 0; }
+ if (typeof Y === "undefined") { Y = 0; }
+ if (typeof Size === "undefined") { Size = 0; }
+ _super.call(this, game, Size);
+ this.x = X;
+ this.y = Y;
+ this.width = 0;
+ this.height = 0;
+ this.minParticleSpeed = new Phaser.Point(-100, -100);
+ this.maxParticleSpeed = new Phaser.Point(100, 100);
+ this.minRotation = -360;
+ this.maxRotation = 360;
+ this.gravity = 0;
+ this.particleClass = null;
+ this.particleDrag = new Phaser.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 Phaser.Point();
+ }
+ Emitter.prototype.destroy = /**
+ * Clean up memory.
+ */
+ function () {
+ this.minParticleSpeed = null;
+ this.maxParticleSpeed = null;
+ this.particleDrag = null;
+ this.particleClass = null;
+ this._point = null;
+ _super.prototype.destroy.call(this);
+ };
+ Emitter.prototype.makeParticles = /**
+ * 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).
+ */
+ function (Graphics, Quantity, BakedRotations, Multiple, Collide) {
+ if (typeof Quantity === "undefined") { Quantity = 50; }
+ if (typeof BakedRotations === "undefined") { BakedRotations = 16; }
+ if (typeof Multiple === "undefined") { Multiple = false; }
+ if (typeof Collide === "undefined") { Collide = 0.8; }
+ this.maxSize = Quantity;
+ var totalFrames = 1;
+ /*
+ if(Multiple)
+ {
+ var sprite:Sprite = new Sprite(this._game);
+ sprite.loadGraphic(Graphics,true);
+ totalFrames = sprite.frames;
+ sprite.destroy();
+ }
+ */
+ var randomFrame;
+ var particle;
+ var i = 0;
+ while(i < Quantity) {
+ if(this.particleClass == null) {
+ particle = new Phaser.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 = Phaser.Collision.NONE;
+ }
+ particle.exists = false;
+ this.add(particle);
+ i++;
+ }
+ return this;
+ };
+ Emitter.prototype.update = /**
+ * Called automatically by the game loop, decides when to launch particles and when to "die".
+ */
+ function () {
+ if(this.on) {
+ if(this._explode) {
+ this.on = false;
+ var i = 0;
+ var l = 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.prototype.update.call(this);
+ };
+ Emitter.prototype.kill = /**
+ * Call this function to turn off all the particles and the emitter.
+ */
+ function () {
+ this.on = false;
+ _super.prototype.kill.call(this);
+ };
+ Emitter.prototype.start = /**
+ * 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".
+ */
+ function (Explode, Lifespan, Frequency, Quantity) {
+ if (typeof Explode === "undefined") { Explode = true; }
+ if (typeof Lifespan === "undefined") { Lifespan = 0; }
+ if (typeof Frequency === "undefined") { Frequency = 0.1; }
+ if (typeof Quantity === "undefined") { Quantity = 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;
+ };
+ Emitter.prototype.emitParticle = /**
+ * This function can be used both internally and externally to emit the next particle.
+ */
+ function () {
+ var particle = this.recycle(Phaser.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();
+ };
+ Emitter.prototype.setSize = /**
+ * 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.
+ */
+ function (Width, Height) {
+ this.width = Width;
+ this.height = Height;
+ };
+ Emitter.prototype.setXSpeed = /**
+ * 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.
+ */
+ function (Min, Max) {
+ if (typeof Min === "undefined") { Min = 0; }
+ if (typeof Max === "undefined") { Max = 0; }
+ this.minParticleSpeed.x = Min;
+ this.maxParticleSpeed.x = Max;
+ };
+ Emitter.prototype.setYSpeed = /**
+ * 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.
+ */
+ function (Min, Max) {
+ if (typeof Min === "undefined") { Min = 0; }
+ if (typeof Max === "undefined") { Max = 0; }
+ this.minParticleSpeed.y = Min;
+ this.maxParticleSpeed.y = Max;
+ };
+ Emitter.prototype.setRotation = /**
+ * 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.
+ */
+ function (Min, Max) {
+ if (typeof Min === "undefined") { Min = 0; }
+ if (typeof Max === "undefined") { Max = 0; }
+ this.minRotation = Min;
+ this.maxRotation = Max;
+ };
+ Emitter.prototype.at = /**
+ * Change the emitter's midpoint to match the midpoint of a FlxObject.
+ *
+ * @param Object The FlxObject that you want to sync up with.
+ */
+ function (Object) {
+ Object.getMidpoint(this._point);
+ this.x = this._point.x - (this.width >> 1);
+ this.y = this._point.y - (this.height >> 1);
+ };
+ return Emitter;
+ })(Phaser.Group);
+ Phaser.Emitter = Emitter;
+})(Phaser || (Phaser = {}));
+/// Sprite to have slightly more specialized behavior
+* common to many game scenarios. You can override and extend this class
+* just like you would Sprite. While Emitter
+* used to work with just any old sprite, it now requires a
+* Particle based class.
+*
+* @author Adam Atomic
+* @author Richard Davey
+*/
+/**
+* Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ var Particle = (function (_super) {
+ __extends(Particle, _super);
+ /**
+ * Instantiate a new particle. Like Sprite, all meaningful creation
+ * happens during loadGraphic() or makeGraphic() or whatever.
+ */
+ function Particle(game) {
+ _super.call(this, game);
+ this.lifespan = 0;
+ this.friction = 500;
+ }
+ Particle.prototype.update = /**
+ * 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.
+ */
+ function () {
+ //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 & Phaser.Collision.FLOOR) {
+ this.drag.x = this.friction;
+ if(!(this.wasTouching & Phaser.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;
+ }
+ }
+ };
+ Particle.prototype.onEmit = /**
+ * Triggered whenever this object is launched by a Emitter.
+ * You can override this to add custom behavior like a sound or AI or something.
+ */
+ function () {
+ };
+ return Particle;
+ })(Phaser.Sprite);
+ Phaser.Particle = Particle;
+})(Phaser || (Phaser = {}));
+/// Tilemap that helps expand collision opportunities and control.
+* You can use Tilemap.setTileProperties() to alter the collision properties and
+* callback functions and filters for this object to do things like one-way tiles or whatever.
+*
+* @author Adam Atomic
+* @author Richard Davey
+*/
+/**
+* Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ var Tile = (function (_super) {
+ __extends(Tile, _super);
+ /**
+ * Instantiate this new tile object. This is usually called from FlxTilemap.loadMap().
+ *
+ * @param Tilemap A reference to the tilemap object creating the tile.
+ * @param Index The actual core map data index for this tile type.
+ * @param Width The width of the tile.
+ * @param Height The height of the tile.
+ * @param Visible Whether the tile is visible or not.
+ * @param AllowCollisions The collision flags for the object. By default this value is ANY or NONE depending on the parameters sent to loadMap().
+ */
+ function Tile(game, Tilemap, Index, Width, Height, Visible, AllowCollisions) {
+ _super.call(this, game, 0, 0, Width, Height);
+ this.immovable = true;
+ this.moves = false;
+ this.callback = null;
+ this.filter = null;
+ this.tilemap = Tilemap;
+ this.index = Index;
+ this.visible = Visible;
+ this.allowCollisions = AllowCollisions;
+ this.mapIndex = 0;
+ }
+ Tile.prototype.destroy = /**
+ * Clean up memory.
+ */
+ function () {
+ _super.prototype.destroy.call(this);
+ this.callback = null;
+ this.tilemap = null;
+ };
+ return Tile;
+ })(Phaser.GameObject);
+ Phaser.Tile = Tile;
+})(Phaser || (Phaser = {}));
+///