diff --git a/README.md b/README.md index f00c2651..88db2db8 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ Updates: * Updated Pixi.js so that removing filters now works correctly without breaking the display list. * Phaser.Canvas.create updated to it can be given an ID as the 3rd parameter. * Updated display/fullscreen example to reflect new full screen change. +* Loads of updates to the TypeScript definitions files - games fully compile now and lots of missing classes added :) +* Removed 'null parent' check from Group constructor. Will parent to game.world only if parent value is undefined. Bug Fixes: @@ -66,7 +68,7 @@ Bug Fixes: * Group.length now returns the number of children in the Group regardless of their exists/alive state, or 0 if the Group is has no children. * Switch Camera.setBoundsToWorld to match world.bounds instead of world (thanks cocoademon) * Fixed an issue where passing null as the Group parent wouldn't set it to game.world as it should have (thanks tito100) -* Fixed Pixi bug (#425) incorrect width property for multi-line Bitmap (thanks jcd-as) +* Fixed Pixi bug (#425) incorrect width property for multi-line BitmapText (thanks jcd-as) You can view the Change Log for all previous versions at https://github.com/photonstorm/phaser/changelog.md @@ -81,6 +83,16 @@ We also provide a Grunt script that will build Phaser from source along with all Run `grunt` in the phaser folder for a list of command-line options. + +Bower +----- + +If you use bowser you can install phaser with: + +`bower install phaser` + +Nice and easy :) + ![Tanks](http://www.photonstorm.com/wp-content/uploads/2013/10/phaser_tanks-640x480.png) diff --git a/bower.json b/bower.json new file mode 100644 index 00000000..74bd4116 --- /dev/null +++ b/bower.json @@ -0,0 +1,37 @@ +{ + "name": "phaser", + "version": "1.1.3", + "homepage": "http://phaser.io", + "authors": [ + "photonstorm " + ], + "description": "A fun, free and fast 2D game framework for making HTML5 games for desktop and mobile, supporting Canvas and WebGL.", + "main": "build/phaser.min.js", + "keywords": [ + "html5", + "game", + "games", + "framework", + "canvas", + "WebGL", + "tilemaps", + "physics", + "sprites", + "fonts", + "images", + "audio", + "Web", + "Audio", + "touch", + "input", + "mobile" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ] +} diff --git a/build/phaser.d.ts b/build/phaser.d.ts index 4d4654ac..4148ead4 100644 --- a/build/phaser.d.ts +++ b/build/phaser.d.ts @@ -260,7 +260,7 @@ declare module Phaser { } class Game { - constructor(width: number, height: number, renderer: number, parent: string, state: Object, transparent: boolean, antialias: boolean); + constructor(width: number, height: number, renderer: number, parent: string, state: Object, transparent?: boolean, antialias?: boolean); id: number; width: number; height: number; @@ -655,7 +655,7 @@ declare module Phaser { onAnimationStart: Phaser.Signal; onAnimationComplete: Phaser.Signal; onAnimationLoop: Phaser.Signal; - } + } class GameObjectFactory { constructor(game: Phaser.Game); @@ -687,7 +687,7 @@ declare module Phaser { type: number; renderOrderID: number; lifespan: number; - events: Phaser.Event[]; + events: Phaser.Events; animations: Phaser.AnimationManager; input: Phaser.InputHandler; key: string; @@ -707,8 +707,6 @@ declare module Phaser { bottomLeft: Phaser.Point; bounds: Phaser.Rectangle; body: Phaser.Physics.Arcade.Body; - velocity: number; - acceleration: number; inWorld: boolean; inWorldThreshold: number; angle: number; @@ -731,6 +729,24 @@ declare module Phaser { getBounds(rect: Phaser.Rectangle): Phaser.Rectangle; } + class Events { + parent: Phaser.Sprite; + onAddedToGroup: Phaser.Signal; + onRemovedFromGroup: Phaser.Signal; + onKilled: Phaser.Signal; + onRevived: Phaser.Signal; + onOutOfBounds: Phaser.Signal; + onInputOver: Phaser.Signal; + onInputOut: Phaser.Signal; + onInputDown: Phaser.Signal; + onInputUp: Phaser.Signal; + onDragStart: Phaser.Signal; + onDragStop: Phaser.Signal; + onAnimationStart: Phaser.Signal; + onAnimationComplete: Phaser.Signal; + onAnimationLoop: Phaser.Signal; + } + class TileSprite { constructor(game: Phaser.Game, x: number, y: number, width: number, height: number, key?: string, frame?: number); texture: Phaser.RenderTexture; @@ -1166,60 +1182,68 @@ declare module Phaser { update(time: number): boolean; } - class Easing { - Linear: { - None: (k: number) => number; - }; - Quadratic: { - In: (k: number) => number; - Out: (k: number) => number; - InOut: (k: number) => number; - }; - Cubic: { - In: (k: number) => number; - Out: (k: number) => number; - InOut: (k: number) => number; - }; - Quartic: { - In: (k: number) => number; - Out: (k: number) => number; - InOut: (k: number) => number; - }; - Quintic: { - In: (k: number) => number; - Out: (k: number) => number; - InOut: (k: number) => number; - }; - Sinusoidal: { - In: (k: number) => number; - Out: (k: number) => number; - InOut: (k: number) => number; - }; - Exponential: { - In: (k: number) => number; - Out: (k: number) => number; - InOut: (k: number) => number; - }; - Circular: { - In: (k: number) => number; - Out: (k: number) => number; - InOut: (k: number) => number; - }; - Elastic: { - In: (k: number) => number; - Out: (k: number) => number; - InOut: (k: number) => number; - }; - Back: { - In: (k: number) => number; - Out: (k: number) => number; - InOut: (k: number) => number; - }; - Bounce: { - In: (k: number) => number; - Out: (k: number) => number; - InOut: (k: number) => number; - }; + class Easing.Linear { + static None(k: number); + } + + class Easing.Quadratic { + static In(k: number); + static Out(k: number); + static InOut(k: number); + } + + class Easing.Cubic { + static In(k: number); + static Out(k: number); + static InOut(k: number); + } + + class Easing.Quartic { + static In(k: number); + static Out(k: number); + static InOut(k: number); + } + + class Easing.Quintic { + static In(k: number); + static Out(k: number); + static InOut(k: number); + } + + class Easing.Sinusoidal { + static In(k: number); + static Out(k: number); + static InOut(k: number); + } + + class Easing.Exponential { + static In(k: number); + static Out(k: number); + static InOut(k: number); + } + + class Easing.Circular { + static In(k: number); + static Out(k: number); + static InOut(k: number); + } + + class Easing.Elastic { + static In(k: number); + static Out(k: number); + static InOut(k: number); + } + + class Easing.Back { + static In(k: number); + static Out(k: number); + static InOut(k: number); + } + + class Easing.Bounce { + static In(k: number); + static Out(k: number); + static InOut(k: number); } class Time { @@ -1286,48 +1310,46 @@ declare module Phaser { onComplete(): void; } - module Animation { - class Frame { - constructor(index: number, x: number, y: number, width: number, height: number, name: string, uuid: string); - index: number; - x: number; - y: number; - width: number; - height: number; - centerX: number; - centerY: number; - distance: number; - name: string; - uuid: string; - rotated: boolean; - rotationDirection: string; - trimmed: boolean; - sourceSizeW: number; - sourceSizeH: number; - spriteSourceSizeX: number; - spriteSourceSizeY: number; - spriteSourceSizeW: number; - spriteSourcesizeH: number; - setTrim(trimmed: boolean, actualWidth: number, actualHeight: number, destX: number, destY: number, destWidth: number, destHeight: number): void; - } + class Frame { + constructor(index: number, x: number, y: number, width: number, height: number, name: string, uuid: string); + index: number; + x: number; + y: number; + width: number; + height: number; + centerX: number; + centerY: number; + distance: number; + name: string; + uuid: string; + rotated: boolean; + rotationDirection: string; + trimmed: boolean; + sourceSizeW: number; + sourceSizeH: number; + spriteSourceSizeX: number; + spriteSourceSizeY: number; + spriteSourceSizeW: number; + spriteSourcesizeH: number; + setTrim(trimmed: boolean, actualWidth: number, actualHeight: number, destX: number, destY: number, destWidth: number, destHeight: number): void; + } - class FrameData { - addFrame(frame: Frame): Frame; - getFrame(index: number): Frame; - getFrameByName(name: string): Frame; - checkFrame(name: string): boolean; - getFrameRange(start: number, end: number, output: Array): Array; - getFrames(frames: Array, useNumericIndex?: boolean, output?: Array): Array; - getFrameIndexes(frames: Array, useNumericIndex?: boolean, output?: Array): Array; - total: number; - } + class FrameData { + addFrame(frame: Frame): Frame; + getFrame(index: number): Frame; + getFrameByName(name: string): Frame; + checkFrame(name: string): boolean; + getFrameRange(start: number, end: number, output: Array): Array; + getFrames(frames: Array, useNumericIndex?: boolean, output?: Array): Array; + getFrameIndexes(frames: Array, useNumericIndex?: boolean, output?: Array): Array; + total: number; + } - class Parser { - spriteSheet(game: Phaser.Game, key: string, frameWidth: number, frameHeight: number, frameMax?: number): Phaser.Animation.FrameData; - JSONData(game: Phaser.Game, json: Object, cacheKey: string): Phaser.Animation.FrameData; - JSONDataHash(game: Phaser.Game, json: Object, cacheKey: string): Phaser.Animation.FrameData; - XMLData(game: Phaser.Game, xml: Object, cacheKey: string): Phaser.Animation.FrameData; - } + class AnimationParser { + spriteSheet(game: Phaser.Game, key: string, frameWidth: number, frameHeight: number, frameMax?: number): Phaser.Animation.FrameData; + JSONData(game: Phaser.Game, json: Object, cacheKey: string): Phaser.Animation.FrameData; + JSONDataHash(game: Phaser.Game, json: Object, cacheKey: string): Phaser.Animation.FrameData; + XMLData(game: Phaser.Game, xml: Object, cacheKey: string): Phaser.Animation.FrameData; } class Cache { @@ -1420,10 +1442,8 @@ declare module Phaser { nextFile(previousKey: string, success: boolean): void; } - module Loader { - class Parser { - bitmapFont(game: Phaser.Game, xml: Object, cacheKey: Phaser.Animation.FrameData): void; - } + class LoaderParser { + bitmapFont(game: Phaser.Game, xml: Object, cacheKey: Phaser.Animation.FrameData): void; } class Sound { diff --git a/examples/assets/tiles/tiles_spritesheet.png b/examples/assets/tiles/tiles_spritesheet.png new file mode 100644 index 00000000..57ee83b6 Binary files /dev/null and b/examples/assets/tiles/tiles_spritesheet.png differ diff --git a/examples/display/bitmapdata wobble.js b/examples/display/bitmapdata wobble.js index 53190772..07224ba6 100644 --- a/examples/display/bitmapdata wobble.js +++ b/examples/display/bitmapdata wobble.js @@ -17,7 +17,7 @@ var waveDataCounter; function create() { // Create our BitmapData object at a size of 32x64 - bmd = game.add.bitmapData('ball', 32, 64); + bmd = game.add.bitmapData(32, 64); // And apply it to 100 randomly positioned sprites for (var i = 0; i < 100; i++) @@ -62,7 +62,7 @@ function updateWobblyBall() // Now all the pixel data has been redrawn we render it to the BitmapData object. // In CANVAS mode this doesn't do anything, but on WebGL it pushes the new texture to the GPU. - // If your game is exclusively running under Canvas you ca safely ignore this step. + // If your game is exclusively running under Canvas you can safely ignore this step. bmd.render(); // Cycle through the wave data - this is what causes the image to "undulate" diff --git a/examples/wip/bmd.js b/examples/wip/bmd.js index dda21b51..36d4e42a 100644 --- a/examples/wip/bmd.js +++ b/examples/wip/bmd.js @@ -14,7 +14,7 @@ var bmd; function create() { - bmd = game.add.bitmapData('ball', 32, 64); + bmd = game.add.bitmapData(32, 64); console.log(bmd); diff --git a/examples/wip/tilemap.js b/examples/wip/tilemap.js index 93633159..4df1e197 100644 --- a/examples/wip/tilemap.js +++ b/examples/wip/tilemap.js @@ -3,6 +3,9 @@ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: function preload() { + // game.load.tilemap('map', 'assets/maps/mario1.json', null, Phaser.Tilemap.TILED_JSON); + // game.load.tileset('marioTiles', 'assets/maps/mario1.png', 16, 16); + game.load.tilemap('map', 'assets/maps/newtest.json', null, Phaser.Tilemap.TILED_JSON); game.load.tileset('tiles', 'assets/maps/ground_1x1.png', 32, 32); // game.load.image('phaser', 'assets/sprites/phaser-ship.png'); @@ -21,25 +24,20 @@ var sprite; function create() { - game.stage.backgroundColor = '#5c94fc'; + // game.stage.backgroundColor = '#5c94fc'; map = game.add.tilemap('map'); + // map.setCollisionByIndexRange(80, 97); // mario map.setCollisionByIndex(1); // Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, tilemap, layer) { - - // layer = game.add.tilemapLayer(0, 0, 800, 600, null, map, 0); layer = game.add.tilemapLayer(0, 0, 800, 600, null, map, 0); // layer2 = game.add.tilemapLayer(0, 0, 400, 600, null, map, 0); // layer.cameraOffset.x = 400; // layer.alpha = 0.5; - // tileset = game.add.tileset('tilesNes'); - // layer = game.add.tilemapLayer(0, 0, map.layers[0].width*tilesetNes.tileWidth, 600, tileset, map, 0); - // disable this and you can place anywhere, but will almost certainly screw collision - layer.resizeWorld(); sprite = game.add.sprite(260, 100, 'phaser'); @@ -51,10 +49,6 @@ function create() { // In this case the box is 50px in and 25px down. sprite.body.setSize(16, 16, 8, 8); - - - - // We'll set a lower max angular velocity here to keep it from going totally nuts sprite.body.maxAngular = 500; diff --git a/src/core/Game.js b/src/core/Game.js index 692f6387..b195f6c7 100644 --- a/src/core/Game.js +++ b/src/core/Game.js @@ -17,8 +17,8 @@ * @param {number} [width=800] - The width of your game in game pixels. * @param {number} [height=600] - The height of your game in game pixels. * @param {number} [renderer=Phaser.AUTO] - Which renderer to use: Phaser.AUTO will auto-detect, Phaser.WEBGL, Phaser.CANVAS or Phaser.HEADLESS (no rendering at all). -* @param {HTMLElement} [parent=''] - The Games DOM parent. -* @param {any} [state=null] - Description. +* @param {string|HTMLElement} [parent=''] - The DOM element into which this games canvas will be injected. Either a DOM ID (string) or the element itself. +* @param {object} [state=null] - The default state object. A object consisting of Phaser.State functions (preload, create, update, render) or null. * @param {boolean} [transparent=false] - Use a transparent canvas background or not. * @param {boolean} [antialias=true] - Anti-alias graphics. */ diff --git a/src/core/Group.js b/src/core/Group.js index 0fe18896..6e23200f 100644 --- a/src/core/Group.js +++ b/src/core/Group.js @@ -10,7 +10,7 @@ * @classdesc A Group is a container for display objects that allows for fast pooling, recycling and collision checks. * @constructor * @param {Phaser.Game} game - A reference to the currently running game. -* @param {*} parent - The parent Group or DisplayObjectContainer that will hold this group, if any. If not set, or set to null, it will use game.world. +* @param {*} parent - The parent Group or DisplayObjectContainer that will hold this group, if any. If undefined it will use game.world. * @param {string} [name=group] - A name for this Group. Not used internally but useful for debugging. * @param {boolean} [useStage=false] - Should the DisplayObjectContainer this Group creates be added to the World (default, false) or direct to the Stage (true). */ @@ -21,7 +21,7 @@ Phaser.Group = function (game, parent, name, useStage) { */ this.game = game; - if (typeof parent === 'undefined' || parent === null) + if (typeof parent === 'undefined') { parent = game.world; } diff --git a/src/gameobjects/DOMSprite.js b/src/gameobjects/DOMSprite.js new file mode 100644 index 00000000..d990bc5b --- /dev/null +++ b/src/gameobjects/DOMSprite.js @@ -0,0 +1,88 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +*/ + +/** +* Create a new DOMSprite. +* @class Phaser.DOMSprite +* @constructor +* @param {Phaser.Game} game - Current game instance. +* @param {string} id - DOM ID. +* @param {number} x - X position of the new text object. +* @param {number} y - Y position of the new text object. +* @param {string} text - The actual text that will be written. +* @param {object} style - The style object containing style attributes like font, font size , +*/ +Phaser.DOMSprite = function (game, element, x, y, style) { + + x = x || 0; + y = y || 0; + style = style || ''; + + /** + * @property {Phaser.Game} game - A reference to the currently running Game. + */ + this.game = game; + + /** + * @property {boolean} exists - If exists = false then the Text isn't updated by the core game loop. + * @default + */ + this.exists = true; + + /** + * @property {boolean} alive - This is a handy little var your game can use to determine if an object is alive or not, it doesn't effect rendering. + * @default + */ + this.alive = true; + + /** + * @property {Phaser.Group} group - The parent Group of this Text object. + */ + this.group = null; + + /** + * @property {string} name - The user defined name given to this object. + * @default + */ + this.name = ''; + + /** + * @property {number} type - The const type of this object. + * @default + */ + this.type = Phaser.DOMSPRITE; + + /** + * @property {boolean} visible - Sets the visible state of this DOMSprite. + * @default + */ + this.visible = true; + + /* + if (parent) + { + if (typeof parent === 'string') + { + // hopefully an element ID + target = document.getElementById(parent); + } + else if (typeof parent === 'object' && parent.nodeType === 1) + { + // quick test for a HTMLelement + target = parent; + } + + if (overflowHidden) + { + target.style.overflow = 'hidden'; + } + } + */ + +}; + +// Phaser.DOMSprite.prototype = Object.create(PIXI.DOMSprite.prototype); +// Phaser.DOMSprite.prototype.constructor = Phaser.DOMSprite; diff --git a/src/gameobjects/Text.js b/src/gameobjects/Text.js index b5be0621..aa20c490 100644 --- a/src/gameobjects/Text.js +++ b/src/gameobjects/Text.js @@ -5,7 +5,7 @@ */ /** -* Create a new Text. +* Create a new `Text` object. * @class Phaser.Text * @constructor * @param {Phaser.Game} game - Current game instance. diff --git a/src/loader/Cache.js b/src/loader/Cache.js index 40ce6d0a..7d0bad59 100644 --- a/src/loader/Cache.js +++ b/src/loader/Cache.js @@ -415,8 +415,10 @@ Phaser.Cache.prototype = { { return this._canvases[key].canvas; } - - return null; + else + { + console.warn('Phaser.Cache.getCanvas: Invalid key: "' + key + '"'); + } }, @@ -433,8 +435,10 @@ Phaser.Cache.prototype = { { return this._bitmapDatas[key]; } - - return null; + else + { + console.warn('Phaser.Cache.getBitmapData: Invalid key: "' + key + '"'); + } }, @@ -469,8 +473,10 @@ Phaser.Cache.prototype = { { return this._images[key].data; } - - return null; + else + { + console.warn('Phaser.Cache.getImage: Invalid key: "' + key + '"'); + } }, @@ -487,8 +493,10 @@ Phaser.Cache.prototype = { { return this._tilesets[key].data; } - - return null; + else + { + console.warn('Phaser.Cache.getTilesetImage: Invalid key: "' + key + '"'); + } }, @@ -505,8 +513,10 @@ Phaser.Cache.prototype = { { return this._tilesets[key].tileData; } - - return null; + else + { + console.warn('Phaser.Cache.getTileset: Invalid key: "' + key + '"'); + } }, @@ -523,8 +533,11 @@ Phaser.Cache.prototype = { { return this._tilemaps[key]; } + else + { + console.warn('Phaser.Cache.getTilemapData: Invalid key: "' + key + '"'); + } - return null; }, /** @@ -625,8 +638,10 @@ Phaser.Cache.prototype = { { return this._textures[key]; } - - return null; + else + { + console.warn('Phaser.Cache.getTexture: Invalid key: "' + key + '"'); + } }, @@ -643,8 +658,10 @@ Phaser.Cache.prototype = { { return this._sounds[key]; } - - return null; + else + { + console.warn('Phaser.Cache.getSound: Invalid key: "' + key + '"'); + } }, @@ -661,8 +678,10 @@ Phaser.Cache.prototype = { { return this._sounds[key].data; } - - return null; + else + { + console.warn('Phaser.Cache.getSoundData: Invalid key: "' + key + '"'); + } }, @@ -726,8 +745,10 @@ Phaser.Cache.prototype = { { return this._text[key].data; } - - return null; + else + { + console.warn('Phaser.Cache.getText: Invalid key: "' + key + '"'); + } }, diff --git a/src/tilemap/Tilemap.js b/src/tilemap/Tilemap.js index 58dcbbb4..1078fe14 100644 --- a/src/tilemap/Tilemap.js +++ b/src/tilemap/Tilemap.js @@ -21,7 +21,7 @@ Phaser.Tilemap = function (game, key) { this.game = game; /** - * @property {array} layers - An array of Tilemap layers. + * @property {array} layers - An array of Tilemap layer data. */ this.layers = null; @@ -30,7 +30,6 @@ Phaser.Tilemap = function (game, key) { this.key = key; this.layers = game.cache.getTilemapData(key).layers; - this.calculateIndexes(); } else { @@ -45,7 +44,6 @@ Phaser.Tilemap = function (game, key) { /** * @property {array} debugMap - Map data used for debug values only. */ - this.debugMap = []; /** @@ -117,25 +115,40 @@ Phaser.Tilemap.prototype = { data: data, indexes: [], dirty: true + }); this.currentLayer = this.layers.length - 1; }, + createTilemapLayer: function (x, y, renderWidth, renderHeight, tileset, layer) { + + return this.game.world.add(new Phaser.TilemapLayer(this.game, x, y, renderWidth, renderHeight, tileset, this, layer)); + + }, + + setCollisionByIndexRange: function (start, stop, layer) { + + if (start > stop) + { + return; + } + + for (var i = start; i <= stop; i++) + { + this.setCollisionByIndex(i, layer); + } + + }, + /** * Sets collision values on a tile in the set. * * @method Phaser.Tileset#setCollision - * @param {number} index - The index of the tile within the set. - * @param {boolean} left - Should the tile collide on the left? - * @param {boolean} right - Should the tile collide on the right? - * @param {boolean} up - Should the tile collide on the top? - * @param {boolean} down - Should the tile collide on the bottom? + * @param {number} index - The index of the tile on the layer. + * @param {number} layer - The layer to operate on. */ - - // Sets all tiles matching the given index to collide on the given faces - // Recalculates the collision map setCollisionByIndex: function (index, layer) { if (typeof layer === "undefined") { layer = this.currentLayer; } @@ -157,6 +170,9 @@ Phaser.Tilemap.prototype = { } } + // Sets all tiles matching the given index to collide on the given faces + // Recalculates the collision map + // Now re-calculate interesting faces this.calculateFaces(layer); @@ -169,7 +185,7 @@ Phaser.Tilemap.prototype = { var left = null; var right = null; -console.log(this.layers[layer].width, 'x', this.layers[layer].height); + // console.log(this.layers[layer].width, 'x', this.layers[layer].height); for (var y = 0; y < this.layers[layer].height ; y++) { diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js index 8fb940b3..28da86e7 100644 --- a/src/tilemap/TilemapLayer.js +++ b/src/tilemap/TilemapLayer.js @@ -16,7 +16,7 @@ * @param {number} renderHeight - Height of the layer. * @param {Phaser.Tileset|string} tileset - The tile set used for rendering. * @param {Phaser.Tilemap} tilemap - The tilemap to which this layer belongs. -* @param {number} layer - The layer index within the map. +* @param {number|string} [layer=0] - The layer within the tilemap this TilemapLayer represents. */ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, tilemap, layer) { @@ -48,7 +48,7 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, /** * @property {Phaser.Frame} textureFrame - Dimensions of the renderable area. */ - this.textureFrame = new Phaser.Frame(0, 0, 0, renderWidth, renderHeight, 'tilemaplayer', game.rnd.uuid()); + this.textureFrame = new Phaser.Frame(0, 0, 0, renderWidth, renderHeight, 'tilemapLayer', game.rnd.uuid()); Phaser.Sprite.call(this, this.game, x, y, this.texture, this.textureFrame); @@ -248,12 +248,12 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, this.tilemap = null; /** - * @property {number} layer - Tilemap layer index. + * @property {object} layer - The layer object within the Tilemap that this layer represents. */ this.layer = null; /** - * @property {number} index + * @property {number} index - The index of this layer within the Tilemap. */ this.index = 0; @@ -349,13 +349,13 @@ Phaser.TilemapLayer.prototype.updateTileset = function (tileset) { */ Phaser.TilemapLayer.prototype.updateMapData = function (tilemap, layer) { - if (typeof layer === 'undefined') - { - layer = 0; - } - if (tilemap instanceof Phaser.Tilemap) { + if (typeof layer === 'undefined') + { + layer = 0; + } + this.tilemap = tilemap; this.layer = this.tilemap.layers[layer]; this.tileWidth = this.layer.tileWidth; @@ -690,7 +690,8 @@ Phaser.TilemapLayer.prototype.render = function () { this.dirty = true; } - if (!this.dirty || !this.tileset || !this.tilemap || !this.visible) + // if (!this.dirty || !this.tileset || !this.tilemap || !this.visible) + if (!this.dirty || !this.tilemap || !this.visible) { return; } @@ -710,10 +711,8 @@ Phaser.TilemapLayer.prototype.render = function () { this._ty = this._dy; this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); - // this.context.fillStyle = '#000000'; - // this.context.fillRect(0, 0, this.canvas.width, this.canvas.height); - - this.context.strokeStyle = '#00ff00'; + this.context.fillStyle = 'rgba(0,255,0,0.3)'; + this.context.strokeStyle = 'rgba(0,255,0,0.9)'; for (var y = this._startY, lenY = this._startY + this._maxY; y < lenY; y++) { @@ -725,25 +724,27 @@ Phaser.TilemapLayer.prototype.render = function () { // var tile = this.tileset.tiles[this._column[x] - 1]; - if (tile) - { - // this.context.drawImage( - // this.tileset.image, - // tile.x, - // tile.y, - // this.tileWidth, - // this.tileHeight, - // Math.floor(this._tx), - // Math.floor(this._ty), - // this.tileWidth, - // this.tileHeight - // ); - } + // if (tile && this.tileset) + // { + // this.context.drawImage( + // this.tileset.image, + // tile.x, + // tile.y, + // this.tileWidth, + // this.tileHeight, + // Math.floor(this._tx), + // Math.floor(this._ty), + // this.tileWidth, + // this.tileHeight + // ); + // } if (tile && (tile.faceTop || tile.faceBottom || tile.faceLeft || tile.faceRight)) { this._tx = Math.floor(this._tx); + this.context.fillRect(this._tx, this._ty, this.tileWidth, this.tileHeight); + this.context.beginPath(); if (tile.faceTop) @@ -770,9 +771,9 @@ Phaser.TilemapLayer.prototype.render = function () { this.context.lineTo(this._tx + this.tileWidth, this._ty + this.tileHeight); } + // this.context.closePath(); this.context.stroke(); - // this.context.fillRect(this._tx, this._ty, this.tileWidth, this.tileHeight); // this.context.strokeRect(this._tx, this._ty, this.tileWidth, this.tileHeight); } diff --git a/wip/examples/a_template.php b/wip/examples/a_template.php deleted file mode 100644 index 69811ff7..00000000 --- a/wip/examples/a_template.php +++ /dev/null @@ -1,39 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/anchor1.php b/wip/examples/anchor1.php deleted file mode 100644 index f0407a48..00000000 --- a/wip/examples/anchor1.php +++ /dev/null @@ -1,57 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/bitmapFont1.php b/wip/examples/bitmapFont1.php deleted file mode 100644 index b76db46a..00000000 --- a/wip/examples/bitmapFont1.php +++ /dev/null @@ -1,39 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/body1.php b/wip/examples/body1.php deleted file mode 100644 index 07cf8781..00000000 --- a/wip/examples/body1.php +++ /dev/null @@ -1,62 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/body2.php b/wip/examples/body2.php deleted file mode 100644 index c6272e94..00000000 --- a/wip/examples/body2.php +++ /dev/null @@ -1,63 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/body3.php b/wip/examples/body3.php deleted file mode 100644 index d07f9c3b..00000000 --- a/wip/examples/body3.php +++ /dev/null @@ -1,69 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/bring to top.php b/wip/examples/bring to top.php deleted file mode 100644 index c405cf91..00000000 --- a/wip/examples/bring to top.php +++ /dev/null @@ -1,54 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/bring to top2.php b/wip/examples/bring to top2.php deleted file mode 100644 index f693a7a8..00000000 --- a/wip/examples/bring to top2.php +++ /dev/null @@ -1,55 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/bringToTop.php b/wip/examples/bringToTop.php deleted file mode 100644 index 26c663be..00000000 --- a/wip/examples/bringToTop.php +++ /dev/null @@ -1,341 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/bringToTop2.php b/wip/examples/bringToTop2.php deleted file mode 100644 index 8fba2e33..00000000 --- a/wip/examples/bringToTop2.php +++ /dev/null @@ -1,41 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/bringToTop3.php b/wip/examples/bringToTop3.php deleted file mode 100644 index 34796a8b..00000000 --- a/wip/examples/bringToTop3.php +++ /dev/null @@ -1,94 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/button1.php b/wip/examples/button1.php deleted file mode 100644 index 08d7b7d2..00000000 --- a/wip/examples/button1.php +++ /dev/null @@ -1,67 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/camera1.php b/wip/examples/camera1.php deleted file mode 100644 index 254a027a..00000000 --- a/wip/examples/camera1.php +++ /dev/null @@ -1,72 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/camera2.php b/wip/examples/camera2.php deleted file mode 100644 index 87295cec..00000000 --- a/wip/examples/camera2.php +++ /dev/null @@ -1,175 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/camera3.php b/wip/examples/camera3.php deleted file mode 100644 index 8b3b46ac..00000000 --- a/wip/examples/camera3.php +++ /dev/null @@ -1,74 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/camera4.php b/wip/examples/camera4.php deleted file mode 100644 index 81df4f6a..00000000 --- a/wip/examples/camera4.php +++ /dev/null @@ -1,56 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/camera5.php b/wip/examples/camera5.php deleted file mode 100644 index 123dbe0d..00000000 --- a/wip/examples/camera5.php +++ /dev/null @@ -1,70 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/camera_cull1.php b/wip/examples/camera_cull1.php deleted file mode 100644 index d332703b..00000000 --- a/wip/examples/camera_cull1.php +++ /dev/null @@ -1,68 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/camerafollow.php b/wip/examples/camerafollow.php deleted file mode 100644 index 97e4dcc5..00000000 --- a/wip/examples/camerafollow.php +++ /dev/null @@ -1,79 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/circle.html b/wip/examples/circle.html deleted file mode 100644 index 8175a630..00000000 --- a/wip/examples/circle.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/collision_group_vs_group.php b/wip/examples/collision_group_vs_group.php deleted file mode 100644 index 0d921cf9..00000000 --- a/wip/examples/collision_group_vs_group.php +++ /dev/null @@ -1,117 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/collision_sprite_vs_group.php b/wip/examples/collision_sprite_vs_group.php deleted file mode 100644 index 4f2fac73..00000000 --- a/wip/examples/collision_sprite_vs_group.php +++ /dev/null @@ -1,100 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/collision_sprite_vs_sprite.php b/wip/examples/collision_sprite_vs_sprite.php deleted file mode 100644 index 24c4d55a..00000000 --- a/wip/examples/collision_sprite_vs_sprite.php +++ /dev/null @@ -1,65 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/collision_sprite_vs_sprite_custom_process.php b/wip/examples/collision_sprite_vs_sprite_custom_process.php deleted file mode 100644 index f691580c..00000000 --- a/wip/examples/collision_sprite_vs_sprite_custom_process.php +++ /dev/null @@ -1,96 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/crop.php b/wip/examples/crop.php deleted file mode 100644 index 598fb4ac..00000000 --- a/wip/examples/crop.php +++ /dev/null @@ -1,46 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/crop2.php b/wip/examples/crop2.php deleted file mode 100644 index 7df1b996..00000000 --- a/wip/examples/crop2.php +++ /dev/null @@ -1,46 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/crop3.php b/wip/examples/crop3.php deleted file mode 100644 index 45551cd3..00000000 --- a/wip/examples/crop3.php +++ /dev/null @@ -1,48 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/drag.php b/wip/examples/drag.php deleted file mode 100644 index 8ee651eb..00000000 --- a/wip/examples/drag.php +++ /dev/null @@ -1,43 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/fullscreen.php b/wip/examples/fullscreen.php deleted file mode 100644 index a65cd53a..00000000 --- a/wip/examples/fullscreen.php +++ /dev/null @@ -1,63 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/get_bounds.php b/wip/examples/get_bounds.php deleted file mode 100644 index 415eb9d9..00000000 --- a/wip/examples/get_bounds.php +++ /dev/null @@ -1,47 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/graphics.php b/wip/examples/graphics.php deleted file mode 100644 index efac7411..00000000 --- a/wip/examples/graphics.php +++ /dev/null @@ -1,80 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/group1.php b/wip/examples/group1.php deleted file mode 100644 index ef2febcf..00000000 --- a/wip/examples/group1.php +++ /dev/null @@ -1,84 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/inherit.php b/wip/examples/inherit.php deleted file mode 100644 index 89dc7e2c..00000000 --- a/wip/examples/inherit.php +++ /dev/null @@ -1,167 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/input1.php b/wip/examples/input1.php deleted file mode 100644 index fc892ea6..00000000 --- a/wip/examples/input1.php +++ /dev/null @@ -1,48 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - -
- - - - - \ No newline at end of file diff --git a/wip/examples/input2.php b/wip/examples/input2.php deleted file mode 100644 index 4f8c94f1..00000000 --- a/wip/examples/input2.php +++ /dev/null @@ -1,60 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/invaders.php b/wip/examples/invaders.php deleted file mode 100644 index ae429829..00000000 --- a/wip/examples/invaders.php +++ /dev/null @@ -1,63 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/js-physics.php b/wip/examples/js-physics.php deleted file mode 100644 index da3f186b..00000000 --- a/wip/examples/js-physics.php +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/wip/examples/js.php b/wip/examples/js.php deleted file mode 100644 index f49d52a6..00000000 --- a/wip/examples/js.php +++ /dev/null @@ -1,109 +0,0 @@ - -?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/wip/examples/js_full.php b/wip/examples/js_full.php deleted file mode 100644 index faf156c2..00000000 --- a/wip/examples/js_full.php +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/wip/examples/linkedlist1.php b/wip/examples/linkedlist1.php deleted file mode 100644 index c877264f..00000000 --- a/wip/examples/linkedlist1.php +++ /dev/null @@ -1,74 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/loader 2.html b/wip/examples/loader 2.html deleted file mode 100644 index 048ac00e..00000000 --- a/wip/examples/loader 2.html +++ /dev/null @@ -1,59 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/loader atlas json.html b/wip/examples/loader atlas json.html deleted file mode 100644 index df0a42f5..00000000 --- a/wip/examples/loader atlas json.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/loader atlas xml.html b/wip/examples/loader atlas xml.html deleted file mode 100644 index e89d70e6..00000000 --- a/wip/examples/loader atlas xml.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/loader audio.html b/wip/examples/loader audio.html deleted file mode 100644 index 137ade9b..00000000 --- a/wip/examples/loader audio.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/loader spritesheet.html b/wip/examples/loader spritesheet.html deleted file mode 100644 index 12cf925f..00000000 --- a/wip/examples/loader spritesheet.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/loader.html b/wip/examples/loader.html deleted file mode 100644 index 955593f6..00000000 --- a/wip/examples/loader.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/mapcollide.php b/wip/examples/mapcollide.php deleted file mode 100644 index 9d8f888b..00000000 --- a/wip/examples/mapcollide.php +++ /dev/null @@ -1,85 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/mario.php b/wip/examples/mario.php deleted file mode 100644 index c05900fd..00000000 --- a/wip/examples/mario.php +++ /dev/null @@ -1,60 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/mariocombo.php b/wip/examples/mariocombo.php deleted file mode 100644 index 551db25b..00000000 --- a/wip/examples/mariocombo.php +++ /dev/null @@ -1,48 +0,0 @@ - - - - phaser.js - Super Mario Combo - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/mariotogether.php b/wip/examples/mariotogether.php deleted file mode 100644 index 908a2361..00000000 --- a/wip/examples/mariotogether.php +++ /dev/null @@ -1,45 +0,0 @@ - - - - phaser.js - Super Mario Combo - - - - - - - - \ No newline at end of file diff --git a/wip/examples/math sincos.html b/wip/examples/math sincos.html deleted file mode 100644 index 061282ff..00000000 --- a/wip/examples/math sincos.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/motion1.php b/wip/examples/motion1.php deleted file mode 100644 index b3171080..00000000 --- a/wip/examples/motion1.php +++ /dev/null @@ -1,98 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/pixi 1.html b/wip/examples/pixi 1.html deleted file mode 100644 index 4bd70188..00000000 --- a/wip/examples/pixi 1.html +++ /dev/null @@ -1,139 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/point.html b/wip/examples/point.html deleted file mode 100644 index 716778e9..00000000 --- a/wip/examples/point.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/quadtree.php b/wip/examples/quadtree.php deleted file mode 100644 index afee3f4c..00000000 --- a/wip/examples/quadtree.php +++ /dev/null @@ -1,110 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/quadtree2.php b/wip/examples/quadtree2.php deleted file mode 100644 index e7746bd0..00000000 --- a/wip/examples/quadtree2.php +++ /dev/null @@ -1,90 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/raf.html b/wip/examples/raf.html deleted file mode 100644 index 939844a7..00000000 --- a/wip/examples/raf.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - - - - - - - - - - - - - -
?
-
Game Time: 
- - - - - \ No newline at end of file diff --git a/wip/examples/rect1.php b/wip/examples/rect1.php deleted file mode 100644 index f88d102d..00000000 --- a/wip/examples/rect1.php +++ /dev/null @@ -1,22 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/rendertexture.php b/wip/examples/rendertexture.php deleted file mode 100644 index 1746e071..00000000 --- a/wip/examples/rendertexture.php +++ /dev/null @@ -1,42 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/rnd.html b/wip/examples/rnd.html deleted file mode 100644 index a6bd1f57..00000000 --- a/wip/examples/rnd.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/signals.html b/wip/examples/signals.html deleted file mode 100644 index 0871cc32..00000000 --- a/wip/examples/signals.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/snap.php b/wip/examples/snap.php deleted file mode 100644 index bbc78ef4..00000000 --- a/wip/examples/snap.php +++ /dev/null @@ -1,54 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/sound1.php b/wip/examples/sound1.php deleted file mode 100644 index 4def5f6e..00000000 --- a/wip/examples/sound1.php +++ /dev/null @@ -1,71 +0,0 @@ - - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/sprite1.php b/wip/examples/sprite1.php deleted file mode 100644 index 18b58c5f..00000000 --- a/wip/examples/sprite1.php +++ /dev/null @@ -1,43 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/sprite2.php b/wip/examples/sprite2.php deleted file mode 100644 index 79244eb2..00000000 --- a/wip/examples/sprite2.php +++ /dev/null @@ -1,55 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/sprite3.php b/wip/examples/sprite3.php deleted file mode 100644 index ccaba885..00000000 --- a/wip/examples/sprite3.php +++ /dev/null @@ -1,65 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/sprite4.php b/wip/examples/sprite4.php deleted file mode 100644 index 295eed61..00000000 --- a/wip/examples/sprite4.php +++ /dev/null @@ -1,70 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/sprite_extend.php b/wip/examples/sprite_extend.php deleted file mode 100644 index 77853a9b..00000000 --- a/wip/examples/sprite_extend.php +++ /dev/null @@ -1,56 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/stage 1.php b/wip/examples/stage 1.php deleted file mode 100644 index b90f8c86..00000000 --- a/wip/examples/stage 1.php +++ /dev/null @@ -1,55 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/stage 2.php b/wip/examples/stage 2.php deleted file mode 100644 index f30ed092..00000000 --- a/wip/examples/stage 2.php +++ /dev/null @@ -1,66 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/stage 3.php b/wip/examples/stage 3.php deleted file mode 100644 index 859fae54..00000000 --- a/wip/examples/stage 3.php +++ /dev/null @@ -1,68 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/stagecolor.php b/wip/examples/stagecolor.php deleted file mode 100644 index 2e744126..00000000 --- a/wip/examples/stagecolor.php +++ /dev/null @@ -1,31 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/statetest.php b/wip/examples/statetest.php deleted file mode 100644 index 9d8f888b..00000000 --- a/wip/examples/statetest.php +++ /dev/null @@ -1,85 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/test.php b/wip/examples/test.php deleted file mode 100644 index d85c2305..00000000 --- a/wip/examples/test.php +++ /dev/null @@ -1,79 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - \ No newline at end of file diff --git a/wip/examples/text1.php b/wip/examples/text1.php deleted file mode 100644 index 4ccbb80d..00000000 --- a/wip/examples/text1.php +++ /dev/null @@ -1,31 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/text2.php b/wip/examples/text2.php deleted file mode 100644 index 64226d1c..00000000 --- a/wip/examples/text2.php +++ /dev/null @@ -1,41 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/text3.php b/wip/examples/text3.php deleted file mode 100644 index aec89013..00000000 --- a/wip/examples/text3.php +++ /dev/null @@ -1,82 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/tilemap.php b/wip/examples/tilemap.php deleted file mode 100644 index b37e1945..00000000 --- a/wip/examples/tilemap.php +++ /dev/null @@ -1,62 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/tilesprite1.php b/wip/examples/tilesprite1.php deleted file mode 100644 index fb522309..00000000 --- a/wip/examples/tilesprite1.php +++ /dev/null @@ -1,63 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/tilesprite2.php b/wip/examples/tilesprite2.php deleted file mode 100644 index 5ad09c6f..00000000 --- a/wip/examples/tilesprite2.php +++ /dev/null @@ -1,54 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/touch1.php b/wip/examples/touch1.php deleted file mode 100644 index 120b6e4d..00000000 --- a/wip/examples/touch1.php +++ /dev/null @@ -1,62 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/tween.html b/wip/examples/tween.html deleted file mode 100644 index 609e4b0b..00000000 --- a/wip/examples/tween.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/tween2.php b/wip/examples/tween2.php deleted file mode 100644 index 8df04a3e..00000000 --- a/wip/examples/tween2.php +++ /dev/null @@ -1,42 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/examples/wip1.html b/wip/examples/wip1.html deleted file mode 100644 index aa95919c..00000000 --- a/wip/examples/wip1.html +++ /dev/null @@ -1,141 +0,0 @@ - - - - phaser.js - a(nother) new beginning - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/wip/examples/world.php b/wip/examples/world.php deleted file mode 100644 index 1061a3a8..00000000 --- a/wip/examples/world.php +++ /dev/null @@ -1,106 +0,0 @@ - - - - phaser.js - a new beginning - - - - - - - - \ No newline at end of file diff --git a/wip/phaser clean up/ArcadePhysics.ts b/wip/phaser clean up/ArcadePhysics.ts deleted file mode 100644 index 00ae9b18..00000000 --- a/wip/phaser clean up/ArcadePhysics.ts +++ /dev/null @@ -1,1121 +0,0 @@ -/// -/// -/// -/// -/// - -/** -* Phaser - PhysicsManager -* -* Your game only has one PhysicsManager instance and it's responsible for looking after, creating and colliding -* all of the physics objects in the world. -*/ - - -module Phaser.Physics { - - export class ArcadePhysics { - - constructor(game: Game, width: number, height: number) { - - this.game = game; - - this.gravity = new Vec2; - this.drag = new Vec2; - this.bounce = new Vec2; - this.angularDrag = 0; - - this.bounds = new Rectangle(0, 0, width, height); - - this._distance = new Vec2; - this._tangent = new Vec2; - - this.members = new Group(game); - - } - - /** - * Local private reference to Game. - */ - public game: Game; - - /** - * Physics object pool - */ - public members: Group; - - // Temp calculation vars - private _drag: number; - private _delta: number; - private _velocityDelta: number; - private _length: number = 0; - private _distance: Vec2; - private _tangent: Vec2; - private _separatedX: bool; - private _separatedY: bool; - private _overlap: number; - private _maxOverlap: number; - private _obj1Velocity: number; - private _obj2Velocity: number; - private _obj1NewVelocity: number; - private _obj2NewVelocity: number; - private _average: number; - private _quadTree: QuadTree; - private _quadTreeResult: bool; - - public bounds: Rectangle; - - public gravity: Vec2; - public drag: Vec2; - public bounce: Vec2; - public angularDrag: number; - - /** - * The overlap bias is used when calculating hull overlap before separation - change it if you have especially small or large GameObjects - * @type {number} - */ - static OVERLAP_BIAS: number = 4; - - /** - * The overlap bias is used when calculating hull overlap before separation - change it if you have especially small or large GameObjects - * @type {number} - */ - static TILE_OVERLAP: bool = false; - - /** - * @type {number} - */ - public worldDivisions: number = 6; - - - /* - public update() { - - this._length = this._objects.length; - - for (var i = 0; i < this._length; i++) - { - if (this._objects[i]) - { - this._objects[i].preUpdate(); - this.updateMotion(this._objects[i]); - this.collideWorld(this._objects[i]); - - for (var x = 0; x < this._length; x++) - { - if (this._objects[x] && this._objects[x] !== this._objects[i]) - { - //this.collideShapes(this._objects[i], this._objects[x]); - var r = this.NEWseparate(this._objects[i], this._objects[x]); - //console.log('sep', r); - } - } - - } - } - - } - - public render() { - - // iterate through the objects here, updating and colliding - for (var i = 0; i < this._length; i++) - { - if (this._objects[i]) - { - this._objects[i].render(this.game.stage.context); - } - } - - } -*/ - - public updateMotion(body: Phaser.Physics.Body) { - - if (body.type == Types.BODY_DISABLED) - { - return; - } - - this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2; - body.angularVelocity += this._velocityDelta; - body.sprite.transform.rotation += body.angularVelocity * this.game.time.elapsed; - body.angularVelocity += this._velocityDelta; - - this._velocityDelta = (this.computeVelocity(body.velocity.x, body.gravity.x, body.acceleration.x, body.drag.x) - body.velocity.x) / 2; - body.velocity.x += this._velocityDelta; - this._delta = body.velocity.x * this.game.time.elapsed; - body.velocity.x += this._velocityDelta; - //body.position.x += this._delta; - body.sprite.x += this._delta; - - this._velocityDelta = (this.computeVelocity(body.velocity.y, body.gravity.y, body.acceleration.y, body.drag.y) - body.velocity.y) / 2; - body.velocity.y += this._velocityDelta; - this._delta = body.velocity.y * this.game.time.elapsed; - body.velocity.y += this._velocityDelta; - //body.position.y += this._delta; - body.sprite.y += this._delta; - - } - - /** - * A tween-like function that takes a starting velocity and some other factors and returns an altered velocity. - * - * @param {number} Velocity Any component of velocity (e.g. 20). - * @param {number} Acceleration Rate at which the velocity is changing. - * @param {number} Drag Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set. - * @param {number} Max An absolute value cap for the velocity. - * - * @return {number} The altered Velocity value. - */ - public computeVelocity(velocity: number, gravity: number = 0, acceleration: number = 0, drag: number = 0, max: number = 10000): number { - - if (acceleration !== 0) - { - velocity += (acceleration + gravity) * this.game.time.elapsed; - } - else if (drag !== 0) - { - this._drag = drag * this.game.time.elapsed; - - if (velocity - this._drag > 0) - { - velocity = velocity - this._drag; - } - else if (velocity + this._drag < 0) - { - velocity += this._drag; - } - else - { - velocity = 0; - } - - velocity += gravity; - } - - if ((velocity != 0) && (max != 10000)) - { - if (velocity > max) - { - velocity = max; - } - else if (velocity < -max) - { - velocity = -max; - } - } - - return velocity; - - } - - /** - * The core Collision separation method. - * @param body1 The first Physics.Body to separate - * @param body2 The second Physics.Body to separate - * @returns {boolean} Returns true if the bodies were separated, otherwise false. - */ - public separate(body1: Body, body2: Body): bool { - - this._separatedX = this.separateBodyX(body1, body2); - this._separatedY = this.separateBodyY(body1, body2); - - return this._separatedX || this._separatedY; - - } - - public checkHullIntersection(body1: Body, body2:Body): bool { - return ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight)); - } - - /** - * Separates the two objects on their x axis - * @param object1 The first GameObject to separate - * @param object2 The second GameObject to separate - * @returns {boolean} Whether the objects in fact touched and were separated along the X axis. - */ - public separateBodyX(body1: Body, body2: Body): bool { - - // Can't separate two disabled or static objects - if ((body1.type == Types.BODY_DISABLED || body1.type == Types.BODY_STATIC) && (body2.type == Types.BODY_DISABLED || body2.type == Types.BODY_STATIC)) - { - return false; - } - - // First, get the two object deltas - this._overlap = 0; - - if (body1.deltaX != body2.deltaX) - { - if (RectangleUtils.intersects(body1.bounds, body2.bounds)) - { - this._maxOverlap = body1.deltaXAbs + body2.deltaXAbs + PhysicsManager.OVERLAP_BIAS; - - // If they did overlap (and can), figure out by how much and flip the corresponding flags - if (body1.deltaX > body2.deltaX) - { - this._overlap = body1.bounds.right - body2.bounds.x; - - if ((this._overlap > this._maxOverlap) || !(body1.allowCollisions & Types.RIGHT) || !(body2.allowCollisions & Types.LEFT)) - { - this._overlap = 0; - } - else - { - body1.touching |= Types.RIGHT; - body2.touching |= Types.LEFT; - } - } - else if (body1.deltaX < body2.deltaX) - { - this._overlap = body1.bounds.x - body2.bounds.width - body2.bounds.x; - - if ((-this._overlap > this._maxOverlap) || !(body1.allowCollisions & Types.LEFT) || !(body2.allowCollisions & Types.RIGHT)) - { - this._overlap = 0; - } - else - { - body1.touching |= Types.LEFT; - body2.touching |= Types.RIGHT; - } - } - } - } - - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (this._overlap != 0) - { - this._obj1Velocity = body1.velocity.x; - this._obj2Velocity = body2.velocity.x; - - /** - * Dynamic = gives and receives impacts - * Static = gives but doesn't receive impacts, cannot be moved by physics - * Kinematic = gives impacts, but never receives, can be moved by physics - */ - - // 2 dynamic bodies will exchange velocities - if (body1.type == Types.BODY_DYNAMIC && body2.type == Types.BODY_DYNAMIC) - { - this._overlap *= 0.5; - body1.position.x = body1.position.x - this._overlap; - body2.position.x += this._overlap; - - this._obj1NewVelocity = Math.sqrt((this._obj2Velocity * this._obj2Velocity * body2.mass) / body1.mass) * ((this._obj2Velocity > 0) ? 1 : -1); - this._obj2NewVelocity = Math.sqrt((this._obj1Velocity * this._obj1Velocity * body1.mass) / body2.mass) * ((this._obj1Velocity > 0) ? 1 : -1); - this._average = (this._obj1NewVelocity + this._obj2NewVelocity) * 0.5; - this._obj1NewVelocity -= this._average; - this._obj2NewVelocity -= this._average; - body1.velocity.x = this._average + this._obj1NewVelocity * body1.bounce.x; - body2.velocity.x = this._average + this._obj2NewVelocity * body2.bounce.x; - } - else if (body2.type != Types.BODY_DYNAMIC) - { - // Body 2 is Static or Kinematic - this._overlap *= 2; - body1.position.x -= this._overlap; - body1.velocity.x = this._obj2Velocity - this._obj1Velocity * body1.bounce.x; - } - else if (body1.type != Types.BODY_DYNAMIC) - { - // Body 1 is Static or Kinematic - this._overlap *= 2; - body2.position.x += this._overlap; - body2.velocity.x = this._obj1Velocity - this._obj2Velocity * body2.bounce.x; - } - - return true; - } - else - { - return false; - } - - } - - /** - * Separates the two objects on their y axis - * @param object1 The first GameObject to separate - * @param object2 The second GameObject to separate - * @returns {boolean} Whether the objects in fact touched and were separated along the Y axis. - */ - public separateBodyY(body1: Body, body2: Body): bool { - - // Can't separate two immovable objects - if ((body1.type == Types.BODY_DISABLED || body1.type == Types.BODY_STATIC) && (body2.type == Types.BODY_DISABLED || body2.type == Types.BODY_STATIC)) - { - return false; - } - - // First, get the two object deltas - this._overlap = 0; - - if (body1.deltaY != body2.deltaY) - { - if (RectangleUtils.intersects(body1.bounds, body2.bounds)) - { - // This is the only place to use the DeltaAbs values - this._maxOverlap = body1.deltaYAbs + body2.deltaYAbs + PhysicsManager.OVERLAP_BIAS; - - // If they did overlap (and can), figure out by how much and flip the corresponding flags - if (body1.deltaY > body2.deltaY) - { - this._overlap = body1.bounds.bottom - body2.bounds.y; - - if ((this._overlap > this._maxOverlap) || !(body1.allowCollisions & Types.DOWN) || !(body2.allowCollisions & Types.UP)) - { - this._overlap = 0; - } - else - { - body1.touching |= Types.DOWN; - body2.touching |= Types.UP; - } - } - else if (body1.deltaY < body2.deltaY) - { - this._overlap = body1.bounds.y - body2.bounds.height - body2.bounds.y; - - if ((-this._overlap > this._maxOverlap) || !(body1.allowCollisions & Types.UP) || !(body2.allowCollisions & Types.DOWN)) - { - this._overlap = 0; - } - else - { - body1.touching |= Types.UP; - body2.touching |= Types.DOWN; - } - } - } - } - - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (this._overlap != 0) - { - this._obj1Velocity = body1.velocity.y; - this._obj2Velocity = body2.velocity.y; - - /** - * Dynamic = gives and receives impacts - * Static = gives but doesn't receive impacts, cannot be moved by physics - * Kinematic = gives impacts, but never receives, can be moved by physics - */ - - if (body1.type == Types.BODY_DYNAMIC && body2.type == Types.BODY_DYNAMIC) - { - this._overlap *= 0.5; - body1.position.y = body1.position.y - this._overlap; - body2.position.y += this._overlap; - - this._obj1NewVelocity = Math.sqrt((this._obj2Velocity * this._obj2Velocity * body2.mass) / body1.mass) * ((this._obj2Velocity > 0) ? 1 : -1); - this._obj2NewVelocity = Math.sqrt((this._obj1Velocity * this._obj1Velocity * body1.mass) / body2.mass) * ((this._obj1Velocity > 0) ? 1 : -1); - var average: number = (this._obj1NewVelocity + this._obj2NewVelocity) * 0.5; - this._obj1NewVelocity -= average; - this._obj2NewVelocity -= average; - body1.velocity.y = average + this._obj1NewVelocity * body1.bounce.y; - body2.velocity.y = average + this._obj2NewVelocity * body2.bounce.y; - } - else if (body2.type != Types.BODY_DYNAMIC) - { - this._overlap *= 2; - body1.position.y -= this._overlap; - body1.velocity.y = this._obj2Velocity - this._obj1Velocity * body1.bounce.y; - // This is special case code that handles things like horizontal moving platforms you can ride - //if (body2.parent.active && body2.moves && (body1.deltaY > body2.deltaY)) - if (body2.sprite.active && (body1.deltaY > body2.deltaY)) - { - body1.position.x += body2.position.x - body2.oldPosition.x; - } - } - else if (body1.type != Types.BODY_DYNAMIC) - { - this._overlap *= 2; - body2.position.y += this._overlap; - body2.velocity.y = this._obj1Velocity - this._obj2Velocity * body2.bounce.y; - // This is special case code that handles things like horizontal moving platforms you can ride - //if (object1.active && body1.moves && (body1.deltaY < body2.deltaY)) - if (body1.sprite.active && (body1.deltaY < body2.deltaY)) - { - body2.position.x += body1.position.x - body1.oldPosition.x; - } - } - - return true; - } - else - { - return false; - } - } - - - - - - - - /* - private TILEseparate(shapeA: IPhysicsShape, shapeB: IPhysicsShape, distance: Vec2, tangent: Vec2) { - - if (tangent.x == 1) - { - console.log('1 The left side of ShapeA hit the right side of ShapeB', Math.floor(distance.x)); - shapeA.physics.touching |= Phaser.Types.LEFT; - shapeB.physics.touching |= Phaser.Types.RIGHT; - } - else if (tangent.x == -1) - { - console.log('2 The right side of ShapeA hit the left side of ShapeB', Math.floor(distance.x)); - shapeA.physics.touching |= Phaser.Types.RIGHT; - shapeB.physics.touching |= Phaser.Types.LEFT; - } - - if (tangent.y == 1) - { - console.log('3 The top of ShapeA hit the bottom of ShapeB', Math.floor(distance.y)); - shapeA.physics.touching |= Phaser.Types.UP; - shapeB.physics.touching |= Phaser.Types.DOWN; - } - else if (tangent.y == -1) - { - console.log('4 The bottom of ShapeA hit the top of ShapeB', Math.floor(distance.y)); - shapeA.physics.touching |= Phaser.Types.DOWN; - shapeB.physics.touching |= Phaser.Types.UP; - } - - - // only apply collision response forces if the object is travelling into, and not out of, the collision - var dot = Vec2Utils.dot(shapeA.physics.velocity, tangent); - - if (dot < 0) - { - console.log('in to', dot); - - // Apply horizontal bounce - if (shapeA.physics.bounce.x > 0) - { - shapeA.physics.velocity.x *= -(shapeA.physics.bounce.x); - } - else - { - shapeA.physics.velocity.x = 0; - } - // Apply horizontal bounce - if (shapeA.physics.bounce.y > 0) - { - shapeA.physics.velocity.y *= -(shapeA.physics.bounce.y); - } - else - { - shapeA.physics.velocity.y = 0; - } - } - else - { - console.log('out of', dot); - } - - shapeA.position.x += Math.floor(distance.x); - //shapeA.bounds.x += Math.floor(distance.x); - - shapeA.position.y += Math.floor(distance.y); - //shapeA.bounds.y += distance.y; - - console.log('------------------------------------------------'); - - } - - private collideWorld(shape:IPhysicsShape) { - - // Collide on the x-axis - this._distance.x = shape.world.bounds.x - (shape.position.x - shape.bounds.halfWidth); - - if (0 < this._distance.x) - { - // Hit Left - this._tangent.setTo(1, 0); - this.separateXWall(shape, this._distance, this._tangent); - } - else - { - this._distance.x = (shape.position.x + shape.bounds.halfWidth) - shape.world.bounds.right; - - if (0 < this._distance.x) - { - // Hit Right - this._tangent.setTo(-1, 0); - this._distance.reverse(); - this.separateXWall(shape, this._distance, this._tangent); - } - } - - // Collide on the y-axis - this._distance.y = shape.world.bounds.y - (shape.position.y - shape.bounds.halfHeight); - - if (0 < this._distance.y) - { - // Hit Top - this._tangent.setTo(0, 1); - this.separateYWall(shape, this._distance, this._tangent); - } - else - { - this._distance.y = (shape.position.y + shape.bounds.halfHeight) - shape.world.bounds.bottom; - - if (0 < this._distance.y) - { - // Hit Bottom - this._tangent.setTo(0, -1); - this._distance.reverse(); - this.separateYWall(shape, this._distance, this._tangent); - } - } - - } - - private separateX(shapeA: IPhysicsShape, shapeB: IPhysicsShape, distance: Vec2, tangent: Vec2) { - - if (tangent.x == 1) - { - console.log('The left side of ShapeA hit the right side of ShapeB', distance.x); - shapeA.physics.touching |= Phaser.Types.LEFT; - shapeB.physics.touching |= Phaser.Types.RIGHT; - } - else - { - console.log('The right side of ShapeA hit the left side of ShapeB', distance.x); - shapeA.physics.touching |= Phaser.Types.RIGHT; - shapeB.physics.touching |= Phaser.Types.LEFT; - } - - // collision edges - //shapeA.oH = tangent.x; - - // only apply collision response forces if the object is travelling into, and not out of, the collision - if (Vec2Utils.dot(shapeA.physics.velocity, tangent) < 0) - { - // Apply horizontal bounce - if (shapeA.physics.bounce.x > 0) - { - shapeA.physics.velocity.x *= -(shapeA.physics.bounce.x); - } - else - { - shapeA.physics.velocity.x = 0; - } - } - - shapeA.position.x += distance.x; - shapeA.bounds.x += distance.x; - - } - - private separateY(shapeA: IPhysicsShape, shapeB: IPhysicsShape, distance: Vec2, tangent: Vec2) { - - if (tangent.y == 1) - { - console.log('The top of ShapeA hit the bottom of ShapeB', distance.y); - shapeA.physics.touching |= Phaser.Types.UP; - shapeB.physics.touching |= Phaser.Types.DOWN; - } - else - { - console.log('The bottom of ShapeA hit the top of ShapeB', distance.y); - shapeA.physics.touching |= Phaser.Types.DOWN; - shapeB.physics.touching |= Phaser.Types.UP; - } - - // collision edges - //shapeA.oV = tangent.y; - - // only apply collision response forces if the object is travelling into, and not out of, the collision - if (Vec2Utils.dot(shapeA.physics.velocity, tangent) < 0) - { - // Apply horizontal bounce - if (shapeA.physics.bounce.y > 0) - { - shapeA.physics.velocity.y *= -(shapeA.physics.bounce.y); - } - else - { - shapeA.physics.velocity.y = 0; - } - } - - shapeA.position.y += distance.y; - shapeA.bounds.y += distance.y; - - } - - private separateXWall(shapeA: IPhysicsShape, distance: Vec2, tangent: Vec2) { - - if (tangent.x == 1) - { - console.log('The left side of ShapeA hit the right side of ShapeB', distance.x); - shapeA.physics.touching |= Phaser.Types.LEFT; - } - else - { - console.log('The right side of ShapeA hit the left side of ShapeB', distance.x); - shapeA.physics.touching |= Phaser.Types.RIGHT; - } - - // collision edges - //shapeA.oH = tangent.x; - - // only apply collision response forces if the object is travelling into, and not out of, the collision - if (Vec2Utils.dot(shapeA.physics.velocity, tangent) < 0) - { - // Apply horizontal bounce - if (shapeA.physics.bounce.x > 0) - { - shapeA.physics.velocity.x *= -(shapeA.physics.bounce.x); - } - else - { - shapeA.physics.velocity.x = 0; - } - } - - shapeA.position.x += distance.x; - - } - - private separateYWall(shapeA: IPhysicsShape, distance: Vec2, tangent: Vec2) { - - if (tangent.y == 1) - { - console.log('The top of ShapeA hit the bottom of ShapeB', distance.y); - shapeA.physics.touching |= Phaser.Types.UP; - } - else - { - console.log('The bottom of ShapeA hit the top of ShapeB', distance.y); - shapeA.physics.touching |= Phaser.Types.DOWN; - } - - // collision edges - //shapeA.oV = tangent.y; - - // only apply collision response forces if the object is travelling into, and not out of, the collision - if (Vec2Utils.dot(shapeA.physics.velocity, tangent) < 0) - { - // Apply horizontal bounce - if (shapeA.physics.bounce.y > 0) - { - shapeA.physics.velocity.y *= -(shapeA.physics.bounce.y); - } - else - { - shapeA.physics.velocity.y = 0; - } - } - - shapeA.position.y += distance.y; - - } - */ - - /** - * Checks for overlaps between two objects using the world QuadTree. Can be Sprite vs. Sprite, Sprite vs. Group or Group vs. Group. - * Note: Does not take the objects scrollFactor into account. All overlaps are check in world space. - * @param object1 The first Sprite or Group to check. If null the world.group is used. - * @param object2 The second Sprite or Group to check. - * @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap. - * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true. - * @param context The context in which the callbacks will be called - * @returns {boolean} true if the objects overlap, otherwise false. - */ - public overlap(object1 = null, object2 = null, notifyCallback = null, processCallback = null, context = null): bool { - - /* - if (object1 == null) - { - object1 = this.game.world.group; - } - - if (object2 == object1) - { - object2 = null; - } - - QuadTree.divisions = this.worldDivisions; - - this._quadTree = new Phaser.QuadTree(this, this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height); - - this._quadTree.load(object1, object2, notifyCallback, processCallback, context); - - this._quadTreeResult = this._quadTree.execute(); - - console.log('over', this._quadTreeResult); - - this._quadTree.destroy(); - - this._quadTree = null; - - return this._quadTreeResult; - */ - - return false; - - } - - - - - - - /** - * Collision resolution specifically for GameObjects vs. Tiles. - * @param object The GameObject to separate - * @param tile The Tile to separate - * @returns {boolean} Whether the objects in fact touched and were separated - */ - public separateTile(object:Sprite, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool, collideUp: bool, collideDown: bool, separateX: bool, separateY: bool): bool { - - //var separatedX: bool = this.separateTileX(object, x, y, width, height, mass, collideLeft, collideRight, separateX); - //var separatedY: bool = this.separateTileY(object, x, y, width, height, mass, collideUp, collideDown, separateY); - - //return separatedX || separatedY; - - return false; - - } - - /** - * Separates the two objects on their x axis - * @param object The GameObject to separate - * @param tile The Tile to separate - * @returns {boolean} Whether the objects in fact touched and were separated along the X axis. - */ - /* - public separateTileX(object:Sprite, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool, separate: bool): bool { - - // Can't separate two immovable objects (tiles are always immovable) - if (object.immovable) - { - return false; - } - - // First, get the object delta - var overlap: number = 0; - var objDelta: number = object.x - object.last.x; - //var objDelta: number = object.collisionMask.deltaX; - - if (objDelta != 0) - { - // Check if the X hulls actually overlap - var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta; - //var objDeltaAbs: number = object.collisionMask.deltaXAbs; - var objBounds: Rectangle = new Rectangle(object.x - ((objDelta > 0) ? objDelta : 0), object.last.y, object.width + ((objDelta > 0) ? objDelta : -objDelta), object.height); - - if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height)) - { - var maxOverlap: number = objDeltaAbs + Collision.OVERLAP_BIAS; - - // If they did overlap (and can), figure out by how much and flip the corresponding flags - if (objDelta > 0) - { - overlap = object.x + object.width - x; - - if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.RIGHT) || collideLeft == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.RIGHT; - } - } - else if (objDelta < 0) - { - overlap = object.x - width - x; - - if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.LEFT) || collideRight == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.LEFT; - } - - } - - } - } - - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (overlap != 0) - { - if (separate == true) - { - //console.log(' - object.x = object.x - overlap; - object.velocity.x = -(object.velocity.x * object.elasticity); - } - - Collision.TILE_OVERLAP = true; - return true; - } - else - { - return false; - } - - } - */ - - /** - * Separates the two objects on their y axis - * @param object The first GameObject to separate - * @param tile The second GameObject to separate - * @returns {boolean} Whether the objects in fact touched and were separated along the Y axis. - */ - /* - public separateTileY(object: Sprite, x: number, y: number, width: number, height: number, mass: number, collideUp: bool, collideDown: bool, separate: bool): bool { - - // Can't separate two immovable objects (tiles are always immovable) - if (object.immovable) - { - return false; - } - - // First, get the two object deltas - var overlap: number = 0; - var objDelta: number = object.y - object.last.y; - - if (objDelta != 0) - { - // Check if the Y hulls actually overlap - var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta; - var objBounds: Rectangle = new Rectangle(object.x, object.y - ((objDelta > 0) ? objDelta : 0), object.width, object.height + objDeltaAbs); - - if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height)) - { - var maxOverlap: number = objDeltaAbs + Collision.OVERLAP_BIAS; - - // If they did overlap (and can), figure out by how much and flip the corresponding flags - if (objDelta > 0) - { - overlap = object.y + object.height - y; - - if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.DOWN) || collideUp == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.DOWN; - } - } - else if (objDelta < 0) - { - overlap = object.y - height - y; - - if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.UP) || collideDown == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.UP; - } - } - } - } - - // TODO - with super low velocities you get lots of stuttering, set some kind of base minimum here - - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (overlap != 0) - { - if (separate == true) - { - object.y = object.y - overlap; - object.velocity.y = -(object.velocity.y * object.elasticity); - } - - Collision.TILE_OVERLAP = true; - return true; - } - else - { - return false; - } - } - */ - - - /** - * Separates the two objects on their x axis - * @param object The GameObject to separate - * @param tile The Tile to separate - * @returns {boolean} Whether the objects in fact touched and were separated along the X axis. - */ - /* - public static NEWseparateTileX(object:Sprite, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool, separate: bool): bool { - - // Can't separate two immovable objects (tiles are always immovable) - if (object.immovable) - { - return false; - } - - // First, get the object delta - var overlap: number = 0; - - if (object.collisionMask.deltaX != 0) - { - // Check if the X hulls actually overlap - //var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta; - //var objBounds: Rectangle = new Rectangle(object.x - ((objDelta > 0) ? objDelta : 0), object.last.y, object.width + ((objDelta > 0) ? objDelta : -objDelta), object.height); - - //if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height)) - if (object.collisionMask.intersectsRaw(x, x + width, y, y + height)) - { - var maxOverlap: number = object.collisionMask.deltaXAbs + Collision.OVERLAP_BIAS; - - // If they did overlap (and can), figure out by how much and flip the corresponding flags - if (object.collisionMask.deltaX > 0) - { - //overlap = object.x + object.width - x; - overlap = object.collisionMask.right - x; - - if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.RIGHT) || collideLeft == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.RIGHT; - } - } - else if (object.collisionMask.deltaX < 0) - { - //overlap = object.x - width - x; - overlap = object.collisionMask.x - width - x; - - if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.LEFT) || collideRight == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.LEFT; - } - - } - - } - } - - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (overlap != 0) - { - if (separate == true) - { - object.x = object.x - overlap; - object.velocity.x = -(object.velocity.x * object.elasticity); - } - - Collision.TILE_OVERLAP = true; - return true; - } - else - { - return false; - } - - } - */ - - /** - * Separates the two objects on their y axis - * @param object The first GameObject to separate - * @param tile The second GameObject to separate - * @returns {boolean} Whether the objects in fact touched and were separated along the Y axis. - */ - /* - public NEWseparateTileY(object: Sprite, x: number, y: number, width: number, height: number, mass: number, collideUp: bool, collideDown: bool, separate: bool): bool { - - // Can't separate two immovable objects (tiles are always immovable) - if (object.immovable) - { - return false; - } - - // First, get the two object deltas - var overlap: number = 0; - //var objDelta: number = object.y - object.last.y; - - if (object.collisionMask.deltaY != 0) - { - // Check if the Y hulls actually overlap - //var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta; - //var objBounds: Rectangle = new Rectangle(object.x, object.y - ((objDelta > 0) ? objDelta : 0), object.width, object.height + objDeltaAbs); - - //if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height)) - if (object.collisionMask.intersectsRaw(x, x + width, y, y + height)) - { - //var maxOverlap: number = objDeltaAbs + Collision.OVERLAP_BIAS; - var maxOverlap: number = object.collisionMask.deltaYAbs + Collision.OVERLAP_BIAS; - - // If they did overlap (and can), figure out by how much and flip the corresponding flags - if (object.collisionMask.deltaY > 0) - { - //overlap = object.y + object.height - y; - overlap = object.collisionMask.bottom - y; - - if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.DOWN) || collideUp == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.DOWN; - } - } - else if (object.collisionMask.deltaY < 0) - { - //overlap = object.y - height - y; - overlap = object.collisionMask.y - height - y; - - if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.UP) || collideDown == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.UP; - } - } - } - } - - // TODO - with super low velocities you get lots of stuttering, set some kind of base minimum here - - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (overlap != 0) - { - if (separate == true) - { - object.y = object.y - overlap; - object.velocity.y = -(object.velocity.y * object.elasticity); - } - - Collision.TILE_OVERLAP = true; - return true; - } - else - { - return false; - } - } - */ - - } - -} \ No newline at end of file diff --git a/wip/phaser clean up/Collision.ts b/wip/phaser clean up/Collision.ts deleted file mode 100644 index 13684b81..00000000 --- a/wip/phaser clean up/Collision.ts +++ /dev/null @@ -1,1702 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// - -/** -* Phaser - Collision -* -* A set of extremely useful collision and geometry intersection functions. -*/ - -module Phaser { - - export class Collision { - - /** - * Collision constructor - * @param game A reference to the current Game - */ - constructor(game: Game) { - - this._game = game; - - Collision.T_VECTORS = []; - - for (var i = 0; i < 10; i++) - { - Collision.T_VECTORS.push(new Vec2); - } - - Collision.T_ARRAYS = []; - - for (var i = 0; i < 5; i++) - { - Collision.T_ARRAYS.push([]); - } - - } - - /** - * Local private reference to Game - */ - private _game: Game; - - /** - * Flag used to allow GameObjects to collide on their left side - * @type {number} - */ - public static LEFT: number = 0x0001; - - /** - * Flag used to allow GameObjects to collide on their right side - * @type {number} - */ - public static RIGHT: number = 0x0010; - - /** - * Flag used to allow GameObjects to collide on their top side - * @type {number} - */ - public static UP: number = 0x0100; - - /** - * Flag used to allow GameObjects to collide on their bottom side - * @type {number} - */ - public static DOWN: number = 0x1000; - - /** - * Flag used with GameObjects to disable collision - * @type {number} - */ - public static NONE: number = 0; - - /** - * Flag used to allow GameObjects to collide with a ceiling - * @type {number} - */ - public static CEILING: number = Collision.UP; - - /** - * Flag used to allow GameObjects to collide with a floor - * @type {number} - */ - public static FLOOR: number = Collision.DOWN; - - /** - * Flag used to allow GameObjects to collide with a wall (same as LEFT+RIGHT) - * @type {number} - */ - public static WALL: number = Collision.LEFT | Collision.RIGHT; - - /** - * Flag used to allow GameObjects to collide on any face - * @type {number} - */ - public static ANY: number = Collision.LEFT | Collision.RIGHT | Collision.UP | Collision.DOWN; - - /** - * The overlap bias is used when calculating hull overlap before separation - change it if you have especially small or large GameObjects - * @type {number} - */ - public static OVERLAP_BIAS: number = 4; - - /** - * This holds the result of the tile separation check, true if the object was moved, otherwise false - * @type {boolean} - */ - public static TILE_OVERLAP: bool = false; - - /** - * A temporary Rectangle used in the separation process to help avoid gc spikes - * @type {Rectangle} - */ - public static _tempBounds: Rectangle; - - /** - * Checks for Line to Line intersection and returns an IntersectResult object containing the results of the intersection. - * @param line1 The first Line object to check - * @param line2 The second Line object to check - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static lineToLine(line1: Line, line2: Line, output?: IntersectResult = new IntersectResult): IntersectResult { - - var denominator = (line1.x1 - line1.x2) * (line2.y1 - line2.y2) - (line1.y1 - line1.y2) * (line2.x1 - line2.x2); - - if (denominator !== 0) - { - output.result = true; - output.x = ((line1.x1 * line1.y2 - line1.y1 * line1.x2) * (line2.x1 - line2.x2) - (line1.x1 - line1.x2) * (line2.x1 * line2.y2 - line2.y1 * line2.x2)) / denominator; - output.y = ((line1.x1 * line1.y2 - line1.y1 * line1.x2) * (line2.y1 - line2.y2) - (line1.y1 - line1.y2) * (line2.x1 * line2.y2 - line2.y1 * line2.x2)) / denominator; - } - - return output; - } - - /** - * Checks for Line to Line Segment intersection and returns an IntersectResult object containing the results of the intersection. - * @param line The Line object to check - * @param seg The Line segment object to check - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static lineToLineSegment(line: Line, seg: Line, output?: IntersectResult = new IntersectResult): IntersectResult { - - var denominator = (line.x1 - line.x2) * (seg.y1 - seg.y2) - (line.y1 - line.y2) * (seg.x1 - seg.x2); - - if (denominator !== 0) - { - output.x = ((line.x1 * line.y2 - line.y1 * line.x2) * (seg.x1 - seg.x2) - (line.x1 - line.x2) * (seg.x1 * seg.y2 - seg.y1 * seg.x2)) / denominator; - output.y = ((line.x1 * line.y2 - line.y1 * line.x2) * (seg.y1 - seg.y2) - (line.y1 - line.y2) * (seg.x1 * seg.y2 - seg.y1 * seg.x2)) / denominator; - - var maxX = Math.max(seg.x1, seg.x2); - var minX = Math.min(seg.x1, seg.x2); - var maxY = Math.max(seg.y1, seg.y2); - var minY = Math.min(seg.y1, seg.y2); - - if ((output.x <= maxX && output.x >= minX) === true || (output.y <= maxY && output.y >= minY) === true) - { - output.result = true; - } - - } - - return output; - - } - - /** - * Checks for Line to Raw Line Segment intersection and returns the result in the IntersectResult object. - * @param line The Line object to check - * @param x1 The start x coordinate of the raw segment - * @param y1 The start y coordinate of the raw segment - * @param x2 The end x coordinate of the raw segment - * @param y2 The end y coordinate of the raw segment - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static lineToRawSegment(line: Line, x1: number, y1: number, x2: number, y2: number, output?: IntersectResult = new IntersectResult): IntersectResult { - - var denominator = (line.x1 - line.x2) * (y1 - y2) - (line.y1 - line.y2) * (x1 - x2); - - if (denominator !== 0) - { - output.x = ((line.x1 * line.y2 - line.y1 * line.x2) * (x1 - x2) - (line.x1 - line.x2) * (x1 * y2 - y1 * x2)) / denominator; - output.y = ((line.x1 * line.y2 - line.y1 * line.x2) * (y1 - y2) - (line.y1 - line.y2) * (x1 * y2 - y1 * x2)) / denominator; - - var maxX = Math.max(x1, x2); - var minX = Math.min(x1, x2); - var maxY = Math.max(y1, y2); - var minY = Math.min(y1, y2); - - if ((output.x <= maxX && output.x >= minX) === true || (output.y <= maxY && output.y >= minY) === true) - { - output.result = true; - } - - } - - return output; - - } - - /** - * Checks for Line to Ray intersection and returns the result in an IntersectResult object. - * @param line1 The Line object to check - * @param ray The Ray object to check - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static lineToRay(line1: Line, ray: Line, output?: IntersectResult = new IntersectResult): IntersectResult { - - var denominator = (line1.x1 - line1.x2) * (ray.y1 - ray.y2) - (line1.y1 - line1.y2) * (ray.x1 - ray.x2); - - if (denominator !== 0) - { - output.x = ((line1.x1 * line1.y2 - line1.y1 * line1.x2) * (ray.x1 - ray.x2) - (line1.x1 - line1.x2) * (ray.x1 * ray.y2 - ray.y1 * ray.x2)) / denominator; - output.y = ((line1.x1 * line1.y2 - line1.y1 * line1.x2) * (ray.y1 - ray.y2) - (line1.y1 - line1.y2) * (ray.x1 * ray.y2 - ray.y1 * ray.x2)) / denominator; - output.result = true; // true unless either of the 2 following conditions are met - - if (!(ray.x1 >= ray.x2) && output.x < ray.x1) - { - output.result = false; - } - - if (!(ray.y1 >= ray.y2) && output.y < ray.y1) - { - output.result = false; - } - } - - return output; - - } - - - /** - * Check if the Line and Circle objects intersect - * @param line The Line object to check - * @param circle The Circle object to check - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static lineToCircle(line: Line, circle: Circle, output?: IntersectResult = new IntersectResult): IntersectResult { - - // Get a perpendicular line running to the center of the circle - if (line.perp(circle.x, circle.y).length <= circle.radius) - { - output.result = true; - } - - return output; - - } - - /** - * Check if the Line intersects each side of the Rectangle - * @param line The Line object to check - * @param rect The Rectangle object to check - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static lineToRectangle(line: Line, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult { - - // Top of the Rectangle vs the Line - Collision.lineToRawSegment(line, rect.x, rect.y, rect.right, rect.y, output); - - if (output.result === true) - { - return output; - } - - // Left of the Rectangle vs the Line - Collision.lineToRawSegment(line, rect.x, rect.y, rect.x, rect.bottom, output); - - if (output.result === true) - { - return output; - } - - // Bottom of the Rectangle vs the Line - Collision.lineToRawSegment(line, rect.x, rect.bottom, rect.right, rect.bottom, output); - - if (output.result === true) - { - return output; - } - - // Right of the Rectangle vs the Line - Collision.lineToRawSegment(line, rect.right, rect.y, rect.right, rect.bottom, output); - - return output; - - } - - /** - * Check if the two Line Segments intersect and returns the result in an IntersectResult object. - * @param line1 The first Line Segment to check - * @param line2 The second Line Segment to check - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static lineSegmentToLineSegment(line1: Line, line2: Line, output?: IntersectResult = new IntersectResult): IntersectResult { - - Collision.lineToLineSegment(line1, line2); - - if (output.result === true) - { - if (!(output.x >= Math.min(line1.x1, line1.x2) && output.x <= Math.max(line1.x1, line1.x2) - && output.y >= Math.min(line1.y1, line1.y2) && output.y <= Math.max(line1.y1, line1.y2))) - { - output.result = false; - } - } - - return output; - } - - /** - * Check if the Line Segment intersects with the Ray and returns the result in an IntersectResult object. - * @param line The Line Segment to check. - * @param ray The Ray to check. - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static lineSegmentToRay(line: Line, ray: Line, output?: IntersectResult = new IntersectResult): IntersectResult { - - Collision.lineToRay(line, ray, output); - - if (output.result === true) - { - if (!(output.x >= Math.min(line.x1, line.x2) && output.x <= Math.max(line.x1, line.x2) - && output.y >= Math.min(line.y1, line.y2) && output.y <= Math.max(line.y1, line.y2))) - { - output.result = false; - } - } - - return output; - - } - - /** - * Check if the Line Segment intersects with the Circle and returns the result in an IntersectResult object. - * @param seg The Line Segment to check. - * @param circle The Circle to check - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static lineSegmentToCircle(seg: Line, circle: Circle, output?: IntersectResult = new IntersectResult): IntersectResult { - - var perp = seg.perp(circle.x, circle.y); - - if (perp.length <= circle.radius) - { - // Line intersects circle - check if segment does - var maxX = Math.max(seg.x1, seg.x2); - var minX = Math.min(seg.x1, seg.x2); - var maxY = Math.max(seg.y1, seg.y2); - var minY = Math.min(seg.y1, seg.y2); - - if ((perp.x2 <= maxX && perp.x2 >= minX) && (perp.y2 <= maxY && perp.y2 >= minY)) - { - output.result = true; - } - else - { - // Worst case - segment doesn't traverse center, so no perpendicular connection. - if (Collision.circleContainsPoint(circle, { x: seg.x1, y: seg.y1 }) || Collision.circleContainsPoint(circle, { x: seg.x2, y: seg.y2 })) - { - output.result = true; - } - } - - } - - return output; - } - - /** - * Check if the Line Segment intersects with the Rectangle and returns the result in an IntersectResult object. - * @param seg The Line Segment to check. - * @param rect The Rectangle to check. - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static lineSegmentToRectangle(seg: Line, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult { - - if (rect.contains(seg.x1, seg.y1) && rect.contains(seg.x2, seg.y2)) - { - output.result = true; - } - else - { - // Top of the Rectangle vs the Line - Collision.lineToRawSegment(seg, rect.x, rect.y, rect.right, rect.bottom, output); - - if (output.result === true) - { - return output; - } - - // Left of the Rectangle vs the Line - Collision.lineToRawSegment(seg, rect.x, rect.y, rect.x, rect.bottom, output); - - if (output.result === true) - { - return output; - } - - // Bottom of the Rectangle vs the Line - Collision.lineToRawSegment(seg, rect.x, rect.bottom, rect.right, rect.bottom, output); - - if (output.result === true) - { - return output; - } - - // Right of the Rectangle vs the Line - Collision.lineToRawSegment(seg, rect.right, rect.y, rect.right, rect.bottom, output); - - return output; - - } - - return output; - - } - - /** - * Check for Ray to Rectangle intersection and returns the result in an IntersectResult object. - * @param ray The Ray to check. - * @param rect The Rectangle to check. - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static rayToRectangle(ray: Line, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult { - - // Currently just finds first intersection - might not be closest to ray pt1 - Collision.lineToRectangle(ray, rect, output); - - return output; - - } - - - /** - * Check whether a Ray intersects a Line segment and returns the parametric value where the intersection occurs in an IntersectResult object. - * @param rayX1 - * @param rayY1 - * @param rayX2 - * @param rayY2 - * @param lineX1 - * @param lineY1 - * @param lineX2 - * @param lineY2 - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static rayToLineSegment(rayX1, rayY1, rayX2, rayY2, lineX1, lineY1, lineX2, lineY2, output?: IntersectResult = new IntersectResult): IntersectResult { - - var r:number; - var s:number; - var d:number; - - // Check lines are not parallel - if ((rayY2 - rayY1) / (rayX2 - rayX1) != (lineY2 - lineY1) / (lineX2 - lineX1)) - { - d = (((rayX2 - rayX1) * (lineY2 - lineY1)) - (rayY2 - rayY1) * (lineX2 - lineX1)); - - if (d != 0) - { - r = (((rayY1 - lineY1) * (lineX2 - lineX1)) - (rayX1 - lineX1) * (lineY2 - lineY1)) / d; - s = (((rayY1 - lineY1) * (rayX2 - rayX1)) - (rayX1 - lineX1) * (rayY2 - rayY1)) / d; - - if (r >= 0) - { - if (s >= 0 && s <= 1) - { - output.result = true; - output.x = rayX1 + r * (rayX2 - rayX1); - output.y = rayY1 + r * (rayY2 - rayY1); - } - } - } - } - - return output; - - } - - /** - * Determines whether the specified point is contained within the rectangular region defined by the Rectangle object and returns the result in an IntersectResult object. - * @param point The Point or Point object to check, or any object with x and y properties. - * @param rect The Rectangle object to check the point against - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static pointToRectangle(point, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult { - - output.setTo(point.x, point.y); - - //output.result = rect.containsPoint(point); - - - return output; - - } - - /** - * Check whether two axis aligned Rectangles intersect and returns the intersecting rectangle dimensions in an IntersectResult object if they do. - * @param rect1 The first Rectangle object. - * @param rect2 The second Rectangle object. - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static rectangleToRectangle(rect1: Rectangle, rect2: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult { - - var leftX = Math.max(rect1.x, rect2.x); - var rightX = Math.min(rect1.right, rect2.right); - var topY = Math.max(rect1.y, rect2.y); - var bottomY = Math.min(rect1.bottom, rect2.bottom); - - output.setTo(leftX, topY, rightX - leftX, bottomY - topY, rightX - leftX, bottomY - topY); - - var cx = output.x + output.width * .5; - var cy = output.y + output.height * .5; - - if ((cx > rect1.x && cx < rect1.right) && (cy > rect1.y && cy < rect1.bottom)) - { - output.result = true; - } - - return output; - - } - - /** - * Checks if the Rectangle and Circle objects intersect and returns the result in an IntersectResult object. - * @param rect The Rectangle object to check - * @param circle The Circle object to check - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static rectangleToCircle(rect: Rectangle, circle: Circle, output?: IntersectResult = new IntersectResult): IntersectResult { - - return Collision.circleToRectangle(circle, rect, output); - - } - - /** - * Checks if the two Circle objects intersect and returns the result in an IntersectResult object. - * @param circle1 The first Circle object to check - * @param circle2 The second Circle object to check - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static circleToCircle(circle1: Circle, circle2: Circle, output?: IntersectResult = new IntersectResult): IntersectResult { - - output.result = ((circle1.radius + circle2.radius) * (circle1.radius + circle2.radius)) >= Collision.distanceSquared(circle1.x, circle1.y, circle2.x, circle2.y); - - return output; - - } - - /** - * Checks if the Circle object intersects with the Rectangle and returns the result in an IntersectResult object. - * @param circle The Circle object to check - * @param rect The Rectangle object to check - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static circleToRectangle(circle: Circle, rect: Rectangle, output?: IntersectResult = new IntersectResult): IntersectResult { - - var inflatedRect: Rectangle = rect.clone(); - - inflatedRect.inflate(circle.radius, circle.radius); - - output.result = inflatedRect.contains(circle.x, circle.y); - - return output; - - } - - /** - * Checks if the Point object is contained within the Circle and returns the result in an IntersectResult object. - * @param circle The Circle object to check - * @param point A Point or Point object to check, or any object with x and y properties - * @param [output] An optional IntersectResult object to store the intersection values in. One is created if none given. - * @returns {IntersectResult=} An IntersectResult object containing the results of the intersection - */ - public static circleContainsPoint(circle: Circle, point, output?: IntersectResult = new IntersectResult): IntersectResult { - - output.result = circle.radius * circle.radius >= Collision.distanceSquared(circle.x, circle.y, point.x, point.y); - - return output; - - } - - /** - * Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group. - * Note: Does not take the objects scrollFactor into account. All overlaps are check in world space. - * @param object1 The first GameObject or Group to check. If null the world.group is used. - * @param object2 The second GameObject or Group to check. - * @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap. - * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true. - * @param context The context in which the callbacks will be called - * @returns {boolean} true if the objects overlap, otherwise false. - */ - public overlap(object1: Basic = null, object2: Basic = null, notifyCallback = null, processCallback = null, context = null): bool { - - if (object1 == null) - { - object1 = this._game.world.group; - } - - if (object2 == object1) - { - object2 = 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(object1, object2, notifyCallback, processCallback, context); - - var result: bool = quadTree.execute(); - - quadTree.destroy(); - - quadTree = null; - - return result; - - } - - /** - * The core Collision separation function used by Collision.overlap. - * @param object1 The first GameObject to separate - * @param object2 The second GameObject to separate - * @returns {boolean} Returns true if the objects were separated, otherwise false. - */ - public static separate(object1, object2): bool { - - object1.collisionMask.update(); - object2.collisionMask.update(); - - var separatedX: bool = Collision.separateX(object1, object2); - var separatedY: bool = Collision.separateY(object1, object2); - - return separatedX || separatedY; - - } - - /** - * Collision resolution specifically for GameObjects vs. Tiles. - * @param object The GameObject to separate - * @param tile The Tile to separate - * @returns {boolean} Whether the objects in fact touched and were separated - */ - public static separateTile(object:GameObject, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool, collideUp: bool, collideDown: bool, separateX: bool, separateY: bool): bool { - - object.collisionMask.update(); - - var separatedX: bool = Collision.separateTileX(object, x, y, width, height, mass, collideLeft, collideRight, separateX); - var separatedY: bool = Collision.separateTileY(object, x, y, width, height, mass, collideUp, collideDown, separateY); - - return separatedX || separatedY; - - } - - /** - * Separates the two objects on their x axis - * @param object The GameObject to separate - * @param tile The Tile to separate - * @returns {boolean} Whether the objects in fact touched and were separated along the X axis. - */ - public static separateTileX(object:GameObject, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool, separate: bool): bool { - - // Can't separate two immovable objects (tiles are always immovable) - if (object.immovable) - { - return false; - } - - // First, get the object delta - var overlap: number = 0; - var objDelta: number = object.x - object.last.x; - //var objDelta: number = object.collisionMask.deltaX; - - if (objDelta != 0) - { - // Check if the X hulls actually overlap - var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta; - //var objDeltaAbs: number = object.collisionMask.deltaXAbs; - var objBounds: Rectangle = new Rectangle(object.x - ((objDelta > 0) ? objDelta : 0), object.last.y, object.width + ((objDelta > 0) ? objDelta : -objDelta), object.height); - - if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height)) - { - var maxOverlap: number = objDeltaAbs + Collision.OVERLAP_BIAS; - - // If they did overlap (and can), figure out by how much and flip the corresponding flags - if (objDelta > 0) - { - overlap = object.x + object.width - x; - - if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.RIGHT) || collideLeft == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.RIGHT; - } - } - else if (objDelta < 0) - { - overlap = object.x - width - x; - - if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.LEFT) || collideRight == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.LEFT; - } - - } - - } - } - - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (overlap != 0) - { - if (separate == true) - { - //console.log(' - object.x = object.x - overlap; - object.velocity.x = -(object.velocity.x * object.elasticity); - } - - Collision.TILE_OVERLAP = true; - return true; - } - else - { - return false; - } - - } - - /** - * Separates the two objects on their y axis - * @param object The first GameObject to separate - * @param tile The second GameObject to separate - * @returns {boolean} Whether the objects in fact touched and were separated along the Y axis. - */ - public static separateTileY(object: GameObject, x: number, y: number, width: number, height: number, mass: number, collideUp: bool, collideDown: bool, separate: bool): bool { - - // Can't separate two immovable objects (tiles are always immovable) - if (object.immovable) - { - return false; - } - - // First, get the two object deltas - var overlap: number = 0; - var objDelta: number = object.y - object.last.y; - - if (objDelta != 0) - { - // Check if the Y hulls actually overlap - var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta; - var objBounds: Rectangle = new Rectangle(object.x, object.y - ((objDelta > 0) ? objDelta : 0), object.width, object.height + objDeltaAbs); - - if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height)) - { - var maxOverlap: number = objDeltaAbs + Collision.OVERLAP_BIAS; - - // If they did overlap (and can), figure out by how much and flip the corresponding flags - if (objDelta > 0) - { - overlap = object.y + object.height - y; - - if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.DOWN) || collideUp == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.DOWN; - } - } - else if (objDelta < 0) - { - overlap = object.y - height - y; - - if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.UP) || collideDown == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.UP; - } - } - } - } - - // TODO - with super low velocities you get lots of stuttering, set some kind of base minimum here - - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (overlap != 0) - { - if (separate == true) - { - object.y = object.y - overlap; - object.velocity.y = -(object.velocity.y * object.elasticity); - } - - Collision.TILE_OVERLAP = true; - return true; - } - else - { - return false; - } - } - - - /** - * Separates the two objects on their x axis - * @param object The GameObject to separate - * @param tile The Tile to separate - * @returns {boolean} Whether the objects in fact touched and were separated along the X axis. - */ - public static NEWseparateTileX(object:GameObject, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool, separate: bool): bool { - - // Can't separate two immovable objects (tiles are always immovable) - if (object.immovable) - { - return false; - } - - // First, get the object delta - var overlap: number = 0; - - if (object.collisionMask.deltaX != 0) - { - // Check if the X hulls actually overlap - //var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta; - //var objBounds: Rectangle = new Rectangle(object.x - ((objDelta > 0) ? objDelta : 0), object.last.y, object.width + ((objDelta > 0) ? objDelta : -objDelta), object.height); - - //if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height)) - if (object.collisionMask.intersectsRaw(x, x + width, y, y + height)) - { - var maxOverlap: number = object.collisionMask.deltaXAbs + Collision.OVERLAP_BIAS; - - // If they did overlap (and can), figure out by how much and flip the corresponding flags - if (object.collisionMask.deltaX > 0) - { - //overlap = object.x + object.width - x; - overlap = object.collisionMask.right - x; - - if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.RIGHT) || collideLeft == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.RIGHT; - } - } - else if (object.collisionMask.deltaX < 0) - { - //overlap = object.x - width - x; - overlap = object.collisionMask.x - width - x; - - if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.LEFT) || collideRight == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.LEFT; - } - - } - - } - } - - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (overlap != 0) - { - if (separate == true) - { - object.x = object.x - overlap; - object.velocity.x = -(object.velocity.x * object.elasticity); - } - - Collision.TILE_OVERLAP = true; - return true; - } - else - { - return false; - } - - } - - /** - * Separates the two objects on their y axis - * @param object The first GameObject to separate - * @param tile The second GameObject to separate - * @returns {boolean} Whether the objects in fact touched and were separated along the Y axis. - */ - public static NEWseparateTileY(object: GameObject, x: number, y: number, width: number, height: number, mass: number, collideUp: bool, collideDown: bool, separate: bool): bool { - - // Can't separate two immovable objects (tiles are always immovable) - if (object.immovable) - { - return false; - } - - // First, get the two object deltas - var overlap: number = 0; - //var objDelta: number = object.y - object.last.y; - - if (object.collisionMask.deltaY != 0) - { - // Check if the Y hulls actually overlap - //var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta; - //var objBounds: Rectangle = new Rectangle(object.x, object.y - ((objDelta > 0) ? objDelta : 0), object.width, object.height + objDeltaAbs); - - //if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height)) - if (object.collisionMask.intersectsRaw(x, x + width, y, y + height)) - { - //var maxOverlap: number = objDeltaAbs + Collision.OVERLAP_BIAS; - var maxOverlap: number = object.collisionMask.deltaYAbs + Collision.OVERLAP_BIAS; - - // If they did overlap (and can), figure out by how much and flip the corresponding flags - if (object.collisionMask.deltaY > 0) - { - //overlap = object.y + object.height - y; - overlap = object.collisionMask.bottom - y; - - if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.DOWN) || collideUp == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.DOWN; - } - } - else if (object.collisionMask.deltaY < 0) - { - //overlap = object.y - height - y; - overlap = object.collisionMask.y - height - y; - - if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.UP) || collideDown == false) - { - overlap = 0; - } - else - { - object.touching |= Collision.UP; - } - } - } - } - - // TODO - with super low velocities you get lots of stuttering, set some kind of base minimum here - - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (overlap != 0) - { - if (separate == true) - { - object.y = object.y - overlap; - object.velocity.y = -(object.velocity.y * object.elasticity); - } - - Collision.TILE_OVERLAP = true; - return true; - } - else - { - return false; - } - } - - /** - * Separates the two objects on their x axis - * @param object1 The first GameObject to separate - * @param object2 The second GameObject to separate - * @returns {boolean} Whether the objects in fact touched and were separated along the X axis. - */ - public static separateX(object1, object2): bool { - - // Can't separate two immovable objects - if (object1.immovable && object2.immovable) - { - return false; - } - - // First, get the two object deltas - var overlap: number = 0; - - if (object1.collisionMask.deltaX != object2.collisionMask.deltaX) - { - if (object1.collisionMask.intersects(object2.collisionMask)) - { - var maxOverlap: number = object1.collisionMask.deltaXAbs + object2.collisionMask.deltaXAbs + Collision.OVERLAP_BIAS; - - // If they did overlap (and can), figure out by how much and flip the corresponding flags - if (object1.collisionMask.deltaX > object2.collisionMask.deltaX) - { - overlap = object1.collisionMask.right - object2.collisionMask.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 (object1.collisionMask.deltaX < object2.collisionMask.deltaX) - { - overlap = object1.collisionMask.x - object2.collisionMask.width - object2.collisionMask.x; - - if ((-overlap > maxOverlap) || !(object1.allowCollisions & Collision.LEFT) || !(object2.allowCollisions & Collision.RIGHT)) - { - overlap = 0; - } - else - { - object1.touching |= Collision.LEFT; - object2.touching |= Collision.RIGHT; - } - - } - - } - } - - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (overlap != 0) - { - var obj1Velocity: number = object1.velocity.x; - var obj2Velocity: number = object2.velocity.x; - - if (!object1.immovable && !object2.immovable) - { - overlap *= 0.5; - object1.x = object1.x - overlap; - object2.x += overlap; - - var obj1NewVelocity: number = Math.sqrt((obj2Velocity * obj2Velocity * object2.mass) / object1.mass) * ((obj2Velocity > 0) ? 1 : -1); - var obj2NewVelocity: number = Math.sqrt((obj1Velocity * obj1Velocity * object1.mass) / object2.mass) * ((obj1Velocity > 0) ? 1 : -1); - var average: number = (obj1NewVelocity + obj2NewVelocity) * 0.5; - obj1NewVelocity -= average; - obj2NewVelocity -= average; - object1.velocity.x = average + obj1NewVelocity * object1.elasticity; - object2.velocity.x = average + obj2NewVelocity * object2.elasticity; - } - else if (!object1.immovable) - { - object1.x = object1.x - overlap; - object1.velocity.x = obj2Velocity - obj1Velocity * object1.elasticity; - } - else if (!object2.immovable) - { - object2.x += overlap; - object2.velocity.x = obj1Velocity - obj2Velocity * object2.elasticity; - } - - return true; - } - else - { - return false; - } - - } - - /** - * Separates the two objects on their y axis - * @param object1 The first GameObject to separate - * @param object2 The second GameObject to separate - * @returns {boolean} Whether the objects in fact touched and were separated along the Y axis. - */ - public static separateY(object1, object2): bool { - - // Can't separate two immovable objects - if (object1.immovable && object2.immovable) { - return false; - } - - // First, get the two object deltas - var overlap: number = 0; - - if (object1.collisionMask.deltaY != object2.collisionMask.deltaY) - { - if (object1.collisionMask.intersects(object2.collisionMask)) - { - // This is the only place to use the DeltaAbs values - var maxOverlap: number = object1.collisionMask.deltaYAbs + object2.collisionMask.deltaYAbs + Collision.OVERLAP_BIAS; - - // If they did overlap (and can), figure out by how much and flip the corresponding flags - if (object1.collisionMask.deltaY > object2.collisionMask.deltaY) - { - overlap = object1.collisionMask.bottom - object2.collisionMask.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 (object1.collisionMask.deltaY < object2.collisionMask.deltaY) - { - overlap = object1.collisionMask.y - object2.collisionMask.height - object2.collisionMask.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 obj1Velocity: number = object1.velocity.y; - var obj2Velocity: number = object2.velocity.y; - - if (!object1.immovable && !object2.immovable) - { - overlap *= 0.5; - object1.y = object1.y - overlap; - object2.y += overlap; - - var obj1NewVelocity: number = Math.sqrt((obj2Velocity * obj2Velocity * object2.mass) / object1.mass) * ((obj2Velocity > 0) ? 1 : -1); - var obj2NewVelocity: number = Math.sqrt((obj1Velocity * obj1Velocity * object1.mass) / object2.mass) * ((obj1Velocity > 0) ? 1 : -1); - var average: number = (obj1NewVelocity + obj2NewVelocity) * 0.5; - obj1NewVelocity -= average; - obj2NewVelocity -= average; - object1.velocity.y = average + obj1NewVelocity * object1.elasticity; - object2.velocity.y = average + obj2NewVelocity * object2.elasticity; - } - else if (!object1.immovable) - { - object1.y = object1.y - overlap; - object1.velocity.y = obj2Velocity - obj1Velocity * object1.elasticity; - // This is special case code that handles things like horizontal moving platforms you can ride - if (object2.active && object2.moves && (object1.collisionMask.deltaY > object2.collisionMask.deltaY)) - { - object1.x += object2.x - object2.last.x; - } - } - else if (!object2.immovable) - { - object2.y += overlap; - object2.velocity.y = obj1Velocity - obj2Velocity * object2.elasticity; - // This is special case code that handles things like horizontal moving platforms you can ride - if (object1.active && object1.moves && (object1.collisionMask.deltaY < object2.collisionMask.deltaY)) - { - object2.x += object1.x - object1.last.x; - } - } - - return true; - } - else - { - return false; - } - } - - /** - * Returns the distance between the two given coordinates. - * @param x1 The X value of the first coordinate - * @param y1 The Y value of the first coordinate - * @param x2 The X value of the second coordinate - * @param y2 The Y value of the second coordinate - * @returns {number} The distance between the two coordinates - */ - public static distance(x1: number, y1: number, x2: number, y2: number) { - return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); - } - - /** - * Returns the distanced squared between the two given coordinates. - * @param x1 The X value of the first coordinate - * @param y1 The Y value of the first coordinate - * @param x2 The X value of the second coordinate - * @param y2 The Y value of the second coordinate - * @returns {number} The distance between the two coordinates - */ - public static distanceSquared(x1: number, y1: number, x2: number, y2: number) { - return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); - } - - - - // SAT - - /** - * Flattens the specified array of points onto a unit vector axis, - * resulting in a one dimensional range of the minimum and - * maximum value on that axis. - * - * @param {Array.} points The points to flatten. - * @param {Vector} normal The unit vector axis to flatten on. - * @param {Array.} result An array. After calling this function, - * result[0] will be the minimum value, - * result[1] will be the maximum value. - */ - public static flattenPointsOn(points, normal, result) { - - var min = Number.MAX_VALUE; - var max = -Number.MAX_VALUE; - var len = points.length; - - for (var i = 0; i < len; i++) - { - // Get the magnitude of the projection of the point onto the normal - var dot = points[i].dot(normal); - if (dot < min) { min = dot; } - if (dot > max) { max = dot; } - } - - result[0] = min; result[1] = max; - - } - - /** - * Pool of Vectors used in calculations. - * - * @type {Array.} - */ - public static T_VECTORS: Vec2[]; - - /** - * Pool of Arrays used in calculations. - * - * @type {Array.>} - */ - public static T_ARRAYS; - - /** - * Check whether two convex clockwise polygons are separated by the specified - * axis (must be a unit vector). - * - * @param {Vector} aPos The position of the first polygon. - * @param {Vector} bPos The position of the second polygon. - * @param {Array.} aPoints The points in the first polygon. - * @param {Array.} bPoints The points in the second polygon. - * @param {Vector} axis The axis (unit sized) to test against. The points of both polygons - * will be projected onto this axis. - * @param {Response=} response A Response object (optional) which will be populated - * if the axis is not a separating axis. - * @return {boolean} true if it is a separating axis, false otherwise. If false, - * and a response is passed in, information about how much overlap and - * the direction of the overlap will be populated. - */ - public static isSeparatingAxis(aPos, bPos, aPoints, bPoints, axis, response?:Response = null): bool { - - var rangeA = Collision.T_ARRAYS.pop(); - var rangeB = Collision.T_ARRAYS.pop(); - - // Get the magnitude of the offset between the two polygons - var offsetV = Collision.T_VECTORS.pop().copyFrom(bPos).sub(aPos); - var projectedOffset = offsetV.dot(axis); - - // Project the polygons onto the axis. - Collision.flattenPointsOn(aPoints, axis, rangeA); - Collision.flattenPointsOn(bPoints, axis, rangeB); - - // Move B's range to its position relative to A. - rangeB[0] += projectedOffset; - rangeB[1] += projectedOffset; - - // Check if there is a gap. If there is, this is a separating axis and we can stop - if (rangeA[0] > rangeB[1] || rangeB[0] > rangeA[1]) - { - Collision.T_VECTORS.push(offsetV); - Collision.T_ARRAYS.push(rangeA); - Collision.T_ARRAYS.push(rangeB); - return true; - } - - // If we're calculating a response, calculate the overlap. - if (response) - { - var overlap = 0; - - // A starts further left than B - if (rangeA[0] < rangeB[0]) - { - response.aInB = false; - - // A ends before B does. We have to pull A out of B - if (rangeA[1] < rangeB[1]) - { - overlap = rangeA[1] - rangeB[0]; - response.bInA = false; - // B is fully inside A. Pick the shortest way out. - } - else - { - var option1 = rangeA[1] - rangeB[0]; - var option2 = rangeB[1] - rangeA[0]; - overlap = option1 < option2 ? option1 : -option2; - } - // B starts further left than A - } - else - { - response.bInA = false; - - // B ends before A ends. We have to push A out of B - if (rangeA[1] > rangeB[1]) - { - overlap = rangeA[0] - rangeB[1]; - response.aInB = false; - // A is fully inside B. Pick the shortest way out. - } - else - { - var option1 = rangeA[1] - rangeB[0]; - var option2 = rangeB[1] - rangeA[0]; - overlap = option1 < option2 ? option1 : -option2; - } - } - - // If this is the smallest amount of overlap we've seen so far, set it as the minimum overlap. - var absOverlap = Math.abs(overlap); - - if (absOverlap < response.overlap) - { - response.overlap = absOverlap; - response.overlapN.copyFrom(axis); - - if (overlap < 0) - { - response.overlapN.reverse(); - } - } - } - - Collision.T_VECTORS.push(offsetV); - Collision.T_ARRAYS.push(rangeA); - Collision.T_ARRAYS.push(rangeB); - - return false; - - } - - public static LEFT_VORNOI_REGION:number = -1; - public static MIDDLE_VORNOI_REGION:number = 0; - public static RIGHT_VORNOI_REGION:number = 1; - - /** - * Calculates which Vornoi region a point is on a line segment. - * It is assumed that both the line and the point are relative to (0, 0) - * - * | (0) | - * (-1) [0]--------------[1] (1) - * | (0) | - * - * @param {Vector} line The line segment. - * @param {Vector} point The point. - * @return {number} LEFT_VORNOI_REGION (-1) if it is the left region, - * MIDDLE_VORNOI_REGION (0) if it is the middle region, - * RIGHT_VORNOI_REGION (1) if it is the right region. - */ - public static vornoiRegion(line: Vec2, point: Vec2): number { - - var len2 = line.length2(); - var dp = point.dot(line); - - if (dp < 0) { return Collision.LEFT_VORNOI_REGION; } - else if (dp > len2) { return Collision.RIGHT_VORNOI_REGION; } - else { return Collision.MIDDLE_VORNOI_REGION; } - - } - - /** - * Check if two circles intersect. - * - * @param {Circle} a The first circle. - * @param {Circle} b The second circle. - * @param {Response=} response Response object (optional) that will be populated if - * the circles intersect. - * @return {boolean} true if the circles intersect, false if they don't. - */ - public static testCircleCircle(a: Circle, b: Circle, response?: Response = null): bool { - - var differenceV = Collision.T_VECTORS.pop().copyFrom(b.pos).sub(a.pos); - var totalRadius = a.radius + b.radius; - var totalRadiusSq = totalRadius * totalRadius; - var distanceSq = differenceV.length2(); - - if (distanceSq > totalRadiusSq) - { - // They do not intersect - Collision.T_VECTORS.push(differenceV); - return false; - } - - // They intersect. If we're calculating a response, calculate the overlap. - if (response) - { - var dist = Math.sqrt(distanceSq); - response.a = a; - response.b = b; - response.overlap = totalRadius - dist; - response.overlapN.copyFrom(differenceV.normalize()); - response.overlapV.copyFrom(differenceV).scale(response.overlap); - response.aInB = a.radius <= b.radius && dist <= b.radius - a.radius; - response.bInA = b.radius <= a.radius && dist <= a.radius - b.radius; - } - - Collision.T_VECTORS.push(differenceV); - return true; - - } - - /** - * Check if a polygon and a circle intersect. - * - * @param {Polygon} polygon The polygon. - * @param {Circle} circle The circle. - * @param {Response=} response Response object (optional) that will be populated if - * they interset. - * @return {boolean} true if they intersect, false if they don't. - */ - public static testPolygonCircle(polygon: Polygon, circle: Circle, response?: Response = null): bool { - - var circlePos = Collision.T_VECTORS.pop().copyFrom(circle.pos).sub(polygon.pos); - var radius = circle.radius; - var radius2 = radius * radius; - var points = polygon.points; - var len = points.length; - var edge = T_VECTORS.pop(); - var point = T_VECTORS.pop(); - - // For each edge in the polygon - for (var i = 0; i < len; i++) - { - var next = i === len - 1 ? 0 : i + 1; - var prev = i === 0 ? len - 1 : i - 1; - var overlap = 0; - var overlapN = null; - - // Get the edge - edge.copyFrom(polygon.edges[i]); - // Calculate the center of the cirble relative to the starting point of the edge - point.copyFrom(circlePos).sub(points[i]); - - // If the distance between the center of the circle and the point - // is bigger than the radius, the polygon is definitely not fully in - // the circle. - if (response && point.length2() > radius2) - { - response.aInB = false; - } - - // Calculate which Vornoi region the center of the circle is in. - var region = vornoiRegion(edge, point); - - if (region === Collision.LEFT_VORNOI_REGION) - { - // Need to make sure we're in the RIGHT_VORNOI_REGION of the previous edge. - edge.copyFrom(polygon.edges[prev]); - - // Calculate the center of the circle relative the starting point of the previous edge - var point2 = Collision.T_VECTORS.pop().copyFrom(circlePos).sub(points[prev]); - region = vornoiRegion(edge, point2); - - if (region === Collision.RIGHT_VORNOI_REGION) - { - // It's in the region we want. Check if the circle intersects the point. - var dist = point.length2(); - - if (dist > radius) - { - // No intersection - Collision.T_VECTORS.push(circlePos); - Collision.T_VECTORS.push(edge); - Collision.T_VECTORS.push(point); - Collision.T_VECTORS.push(point2); - return false; - } - else if (response) - { - // It intersects, calculate the overlap - response.bInA = false; - overlapN = point.normalize(); - overlap = radius - dist; - } - } - - Collision.T_VECTORS.push(point2); - - } - else if (region === Collision.RIGHT_VORNOI_REGION) - { - // Need to make sure we're in the left region on the next edge - edge.copyFrom(polygon.edges[next]); - - // Calculate the center of the circle relative to the starting point of the next edge - point.copyFrom(circlePos).sub(points[next]); - region = vornoiRegion(edge, point); - - if (region === Collision.LEFT_VORNOI_REGION) - { - // It's in the region we want. Check if the circle intersects the point. - var dist = point.length2(); - - if (dist > radius) - { - // No intersection - Collision.T_VECTORS.push(circlePos); - Collision.T_VECTORS.push(edge); - Collision.T_VECTORS.push(point); - return false; - } - else if (response) - { - // It intersects, calculate the overlap - response.bInA = false; - overlapN = point.normalize(); - overlap = radius - dist; - } - } - // MIDDLE_VORNOI_REGION - } - else - { - // Need to check if the circle is intersecting the edge, - // Change the edge into its "edge normal". - var normal = edge.perp().normalize(); - - // Find the perpendicular distance between the center of the - // circle and the edge. - var dist = point.dot(normal); - var distAbs = Math.abs(dist); - - // If the circle is on the outside of the edge, there is no intersection - if (dist > 0 && distAbs > radius) - { - Collision.T_VECTORS.push(circlePos); - Collision.T_VECTORS.push(normal); - Collision.T_VECTORS.push(point); - return false; - } - else if (response) - { - // It intersects, calculate the overlap. - overlapN = normal; - overlap = radius - dist; - // If the center of the circle is on the outside of the edge, or part of the - // circle is on the outside, the circle is not fully inside the polygon. - if (dist >= 0 || overlap < 2 * radius) - { - response.bInA = false; - } - } - } - - // If this is the smallest overlap we've seen, keep it. - // (overlapN may be null if the circle was in the wrong Vornoi region) - if (overlapN && response && Math.abs(overlap) < Math.abs(response.overlap)) - { - response.overlap = overlap; - response.overlapN.copyFrom(overlapN); - } - } - - // Calculate the final overlap vector - based on the smallest overlap. - if (response) - { - response.a = polygon; - response.b = circle; - response.overlapV.copyFrom(response.overlapN).scale(response.overlap); - } - - Collision.T_VECTORS.push(circlePos); - Collision.T_VECTORS.push(edge); - Collision.T_VECTORS.push(point); - - return true; - } - - /** - * Check if a circle and a polygon intersect. - * - * NOTE: This runs slightly slower than polygonCircle as it just - * runs polygonCircle and reverses everything at the end. - * - * @param {Circle} circle The circle. - * @param {Polygon} polygon The polygon. - * @param {Response=} response Response object (optional) that will be populated if - * they interset. - * @return {boolean} true if they intersect, false if they don't. - */ - public static testCirclePolygon(circle: Circle, polygon: Polygon, response?: Response = null): bool { - - var result = Collision.testPolygonCircle(polygon, circle, response); - - if (result && response) - { - // Swap A and B in the response. - var a = response.a; - var aInB = response.aInB; - response.overlapN.reverse(); - response.overlapV.reverse(); - response.a = response.b; - response.b = a; - response.aInB = response.bInA; - response.bInA = aInB; - } - - return result; - } - - /** - * Checks whether two convex, clockwise polygons intersect. - * - * @param {Polygon} a The first polygon. - * @param {Polygon} b The second polygon. - * @param {Response=} response Response object (optional) that will be populated if - * they interset. - * @return {boolean} true if they intersect, false if they don't. - */ - public static testPolygonPolygon(a: Polygon, b: Polygon, response?: Response = null): bool { - - var aPoints = a.points; - var aLen = aPoints.length; - var bPoints = b.points; - var bLen = bPoints.length; - - // If any of the edge normals of A is a separating axis, no intersection. - for (var i = 0; i < aLen; i++) - { - if (Collision.isSeparatingAxis(a.pos, b.pos, aPoints, bPoints, a.normals[i], response)) - { - return false; - } - } - - // If any of the edge normals of B is a separating axis, no intersection. - for (var i = 0; i < bLen; i++) - { - if (Collision.isSeparatingAxis(a.pos, b.pos, aPoints, bPoints, b.normals[i], response)) - { - return false; - } - } - - // Since none of the edge normals of A or B are a separating axis, there is an intersection - // and we've already calculated the smallest overlap (in isSeparatingAxis). Calculate the - // final overlap vector. - if (response) - { - response.a = a; - response.b = b; - response.overlapV.copyFrom(response.overlapN).scale(response.overlap); - } - - return true; - } - - } - -} \ No newline at end of file diff --git a/wip/phaser clean up/CollisionMask.ts b/wip/phaser clean up/CollisionMask.ts deleted file mode 100644 index f0186ae0..00000000 --- a/wip/phaser clean up/CollisionMask.ts +++ /dev/null @@ -1,501 +0,0 @@ -/// - -/** -* Phaser - CollisionMask -*/ - -module Phaser { - - export class CollisionMask { - - /** - * CollisionMask constructor. Creates a new CollisionMask for the given GameObject. - * - * @param game {Phaser.Game} Current game instance. - * @param parent {Phaser.GameObject} The GameObject this CollisionMask belongs to. - * @param x {number} The initial x position of the CollisionMask. - * @param y {number} The initial y position of the CollisionMask. - * @param width {number} The width of the CollisionMask. - * @param height {number} The height of the CollisionMask. - */ - constructor(game: Game, parent: GameObject, x: number, y: number, width: number, height: number) { - - this._game = game; - this._parent = parent; - - // By default the CollisionMask is a quad - this.type = CollisionMask.QUAD; - - this.quad = new Phaser.Quad(this._parent.x, this._parent.y, this._parent.width, this._parent.height); - this.offset = new MicroPoint(0, 0); - this.last = new MicroPoint(0, 0); - - this._ref = this.quad; - - return this; - - } - - private _game; - private _parent; - - // An internal reference to the active collision shape - private _ref; - - /** - * Geom type of this sprite. (available: QUAD, POINT, CIRCLE, LINE, RECTANGLE, POLYGON) - * @type {number} - */ - public type: number = 0; - - /** - * Quad (a smaller version of Rectangle). - * @type {number} - */ - public static QUAD: number = 0; - - /** - * Point. - * @type {number} - */ - public static POINT: number = 1; - - /** - * Circle. - * @type {number} - */ - public static CIRCLE: number = 2; - - /** - * Line. - * @type {number} - */ - public static LINE: number = 3; - - /** - * Rectangle. - * @type {number} - */ - public static RECTANGLE: number = 4; - - /** - * Polygon. - * @type {number} - */ - public static POLYGON: number = 5; - - /** - * Rectangle shape container. A Rectangle instance. - * @type {Rectangle} - */ - public quad: Quad; - - /** - * Point shape container. A Point instance. - * @type {Point} - */ - public point: Point; - - /** - * Circle shape container. A Circle instance. - * @type {Circle} - */ - public circle: Circle; - - /** - * Line shape container. A Line instance. - * @type {Line} - */ - public line: Line; - - /** - * Rectangle shape container. A Rectangle instance. - * @type {Rectangle} - */ - public rect: Rectangle; - - /** - * A value from the top-left of the GameObject frame that this collisionMask is offset to. - * If the CollisionMask is a Quad/Rectangle the offset relates to the top-left of that Quad. - * If the CollisionMask is a Circle the offset relates to the center of the circle. - * @type {MicroPoint} - */ - public offset: MicroPoint; - - /** - * The previous x/y coordinates of the CollisionMask, used for hull calculations - * @type {MicroPoint} - */ - public last: MicroPoint; - - /** - * Create a circle shape with specific diameter. - * @param diameter {number} Diameter of the circle. - * @return {CollisionMask} This - */ - createCircle(diameter: number): CollisionMask { - - this.type = CollisionMask.CIRCLE; - this.circle = new Circle(this.last.x, this.last.y, diameter); - this._ref = this.circle; - - return this; - - } - - /** - * Pre-update is called right before update() on each object in the game loop. - */ - public preUpdate() { - - this.last.x = this.x; - this.last.y = this.y; - - } - - public update() { - - this._ref.x = this._parent.x + this.offset.x; - this._ref.y = this._parent.y + this.offset.y; - - } - - /** - * Renders the bounding box around this Sprite and the contact points. Useful for visually debugging. - * @param camera {Camera} Camera the bound will be rendered to. - * @param cameraOffsetX {number} X offset of bound to the camera. - * @param cameraOffsetY {number} Y offset of bound to the camera. - */ - public render(camera:Camera, cameraOffsetX:number, cameraOffsetY:number) { - - var _dx = cameraOffsetX + (this.x - camera.worldView.x); - var _dy = cameraOffsetY + (this.y - camera.worldView.y); - - this._parent.context.fillStyle = this._parent.renderDebugColor; - - if (this.type == CollisionMask.QUAD) - { - this._parent.context.fillRect(_dx, _dy, this.width, this.height); - } - else if (this.type == CollisionMask.CIRCLE) - { - this._parent.context.beginPath(); - this._parent.context.arc(_dx, _dy, this.circle.radius, 0, Math.PI * 2); - this._parent.context.fill(); - this._parent.context.closePath(); - } - - } - - /** - * Destroy all objects and references belonging to this CollisionMask - */ - public destroy() { - - this._game = null; - this._parent = null; - this._ref = null; - this.quad = null; - this.point = null; - this.circle = null; - this.rect = null; - this.line = null; - this.offset = null; - - } - - public intersectsRaw(left: number, right: number, top: number, bottom: number): bool { - -//if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height)) - - return true; - - } - - public intersectsVector(vector: Phaser.Vector2): bool { - - if (this.type == CollisionMask.QUAD) - { - return this.quad.contains(vector.x, vector.y); - } - - } - - /** - * Gives a basic boolean response to a geometric collision. - * If you need the details of the collision use the Collision functions instead and inspect the IntersectResult object. - * @param source {GeomSprite} Sprite you want to check. - * @return {boolean} Whether they overlaps or not. - */ - public intersects(source: CollisionMask): bool { - - // Quad vs. Quad - if (this.type == CollisionMask.QUAD && source.type == CollisionMask.QUAD) - { - return this.quad.intersects(source.quad); - } - - // Circle vs. Circle - if (this.type == CollisionMask.CIRCLE && source.type == CollisionMask.CIRCLE) - { - return Collision.circleToCircle(this.circle, source.circle).result; - } - - // Circle vs. Rect - if (this.type == CollisionMask.CIRCLE && source.type == CollisionMask.RECTANGLE) - { - return Collision.circleToRectangle(this.circle, source.rect).result; - } - - // Circle vs. Point - if (this.type == CollisionMask.CIRCLE && source.type == CollisionMask.POINT) - { - return Collision.circleContainsPoint(this.circle, source.point).result; - } - - // Circle vs. Line - if (this.type == CollisionMask.CIRCLE && source.type == CollisionMask.LINE) - { - return Collision.lineToCircle(source.line, this.circle).result; - } - - // Rect vs. Rect - if (this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.RECTANGLE) - { - return Collision.rectangleToRectangle(this.rect, source.rect).result; - } - - // Rect vs. Circle - if (this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.CIRCLE) - { - return Collision.circleToRectangle(source.circle, this.rect).result; - } - - // Rect vs. Point - if (this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.POINT) - { - return Collision.pointToRectangle(source.point, this.rect).result; - } - - // Rect vs. Line - if (this.type == CollisionMask.RECTANGLE && source.type == CollisionMask.LINE) - { - return Collision.lineToRectangle(source.line, this.rect).result; - } - - // Point vs. Point - if (this.type == CollisionMask.POINT && source.type == CollisionMask.POINT) - { - return this.point.equals(source.point); - } - - // Point vs. Circle - if (this.type == CollisionMask.POINT && source.type == CollisionMask.CIRCLE) - { - return Collision.circleContainsPoint(source.circle, this.point).result; - } - - // Point vs. Rect - if (this.type == CollisionMask.POINT && source.type == CollisionMask.RECTANGLE) - { - return Collision.pointToRectangle(this.point, source.rect).result; - } - - // Point vs. Line - if (this.type == CollisionMask.POINT && source.type == CollisionMask.LINE) - { - return source.line.isPointOnLine(this.point.x, this.point.y); - } - - // Line vs. Line - if (this.type == CollisionMask.LINE && source.type == CollisionMask.LINE) - { - return Collision.lineSegmentToLineSegment(this.line, source.line).result; - } - - // Line vs. Circle - if (this.type == CollisionMask.LINE && source.type == CollisionMask.CIRCLE) - { - return Collision.lineToCircle(this.line, source.circle).result; - } - - // Line vs. Rect - if (this.type == CollisionMask.LINE && source.type == CollisionMask.RECTANGLE) - { - return Collision.lineSegmentToRectangle(this.line, source.rect).result; - } - - // Line vs. Point - if (this.type == CollisionMask.LINE && source.type == CollisionMask.POINT) - { - return this.line.isPointOnLine(source.point.x, source.point.y); - } - - return false; - - } - - public checkHullIntersection(mask: CollisionMask): bool { - - if ((this.hullX + this.hullWidth > mask.hullX) && (this.hullX < mask.hullX + mask.width) && (this.hullY + this.hullHeight > mask.hullY) && (this.hullY < mask.hullY + mask.hullHeight)) - { - return true; - } - else - { - return false; - } - - } - - public get hullWidth(): number { - - if (this.deltaX > 0) - { - return this.width + this.deltaX; - } - else - { - return this.width - this.deltaX; - } - - } - - public get hullHeight(): number { - - if (this.deltaY > 0) - { - return this.height + this.deltaY; - } - else - { - return this.height - this.deltaY; - } - - } - - public get hullX(): number { - - if (this.x < this.last.x) - { - return this.x; - } - else - { - return this.last.x; - } - - } - - public get hullY(): number { - - if (this.y < this.last.y) - { - return this.y; - } - else - { - return this.last.y; - } - - } - - public get deltaXAbs(): number { - return (this.deltaX > 0 ? this.deltaX : -this.deltaX); - } - - public get deltaYAbs(): number { - return (this.deltaY > 0 ? this.deltaY : -this.deltaY); - } - - public get deltaX(): number { - return this.x - this.last.x; - } - - public get deltaY(): number { - return this.y - this.last.y; - } - - public get x(): number { - return this._ref.x; - //return this.quad.x; - } - - public set x(value: number) { - this._ref.x = value; - //this.quad.x = value; - } - - public get y(): number { - return this._ref.y; - //return this.quad.y; - } - - public set y(value: number) { - this._ref.y = value; - //this.quad.y = value; - } - - //public get rotation(): number { - // return this._angle; - //} - - //public set rotation(value: number) { - // this._angle = this._game.math.wrap(value, 360, 0); - //} - - //public get angle(): number { - // return this._angle; - //} - - //public set angle(value: number) { - // this._angle = this._game.math.wrap(value, 360, 0); - //} - - public set width(value:number) { - //this.quad.width = value; - this._ref.width = value; - } - - public set height(value:number) { - //this.quad.height = value; - this._ref.height = value; - } - - public get width(): number { - //return this.quad.width; - return this._ref.width; - } - - public get height(): number { - //return this.quad.height; - return this._ref.height; - } - - public get left(): number { - return this.x; - } - - public get right(): number { - return this.x + this.width; - } - - public get top(): number { - return this.y; - } - - public get bottom(): number { - return this.y + this.height; - } - - public get halfWidth(): number { - return this.width / 2; - } - - public get halfHeight(): number { - return this.height / 2; - } - - } - -} \ No newline at end of file diff --git a/wip/phaser clean up/Debug.ts b/wip/phaser clean up/Debug.ts deleted file mode 100644 index 5ffa22eb..00000000 --- a/wip/phaser clean up/Debug.ts +++ /dev/null @@ -1,90 +0,0 @@ -/** -* Phaser - Components - Debug -* -* -*/ - -module Phaser.Components { - - export class Debug { - - /** - * Render bound of this sprite for debugging? (default to false) - * @type {boolean} - */ - public renderDebug: bool = false; - - /** - * Color of the Sprite when no image is present. Format is a css color string. - * @type {string} - */ - public fillColor: string = 'rgb(255,255,255)'; - - /** - * Color of bound when render debug. (see renderDebug) Format is a css color string. - * @type {string} - */ - public renderDebugColor: string = 'rgba(0,255,0,0.5)'; - - /** - * Color of points when render debug. (see renderDebug) Format is a css color string. - * @type {string} - */ - public renderDebugPointColor: string = 'rgba(255,255,255,1)'; - - /** - * Renders the bounding box around this Sprite and the contact points. Useful for visually debugging. - * @param camera {Camera} Camera the bound will be rendered to. - * @param cameraOffsetX {number} X offset of bound to the camera. - * @param cameraOffsetY {number} Y offset of bound to the camera. - */ - /* - private renderBounds(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) { - - this._dx = cameraOffsetX + (this.frameBounds.topLeft.x - camera.worldView.x); - this._dy = cameraOffsetY + (this.frameBounds.topLeft.y - camera.worldView.y); - - this.context.fillStyle = this.renderDebugColor; - this.context.fillRect(this._dx, this._dy, this.frameBounds.width, this.frameBounds.height); - - //this.context.fillStyle = this.renderDebugPointColor; - - //var hw = this.frameBounds.halfWidth * this.scale.x; - //var hh = this.frameBounds.halfHeight * this.scale.y; - //var sw = (this.frameBounds.width * this.scale.x) - 1; - //var sh = (this.frameBounds.height * this.scale.y) - 1; - - //this.context.fillRect(this._dx, this._dy, 1, 1); // top left - //this.context.fillRect(this._dx + hw, this._dy, 1, 1); // top center - //this.context.fillRect(this._dx + sw, this._dy, 1, 1); // top right - //this.context.fillRect(this._dx, this._dy + hh, 1, 1); // left center - //this.context.fillRect(this._dx + hw, this._dy + hh, 1, 1); // center - //this.context.fillRect(this._dx + sw, this._dy + hh, 1, 1); // right center - //this.context.fillRect(this._dx, this._dy + sh, 1, 1); // bottom left - //this.context.fillRect(this._dx + hw, this._dy + sh, 1, 1); // bottom center - //this.context.fillRect(this._dx + sw, this._dy + sh, 1, 1); // bottom right - - } - */ - - /** - * Render debug infos. (including name, bounds info, position and some other properties) - * @param x {number} X position of the debug info to be rendered. - * @param y {number} Y position of the debug info to be rendered. - * @param [color] {number} color of the debug info to be rendered. (format is css color string) - */ - /* - public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') { - - this.context.fillStyle = color; - this.context.fillText('Sprite: ' + this.name + ' (' + this.frameBounds.width + ' x ' + this.frameBounds.height + ')', x, y); - this.context.fillText('x: ' + this.frameBounds.x.toFixed(1) + ' y: ' + this.frameBounds.y.toFixed(1) + ' rotation: ' + this.angle.toFixed(1), x, y + 14); - this.context.fillText('dx: ' + this._dx.toFixed(1) + ' dy: ' + this._dy.toFixed(1) + ' dw: ' + this._dw.toFixed(1) + ' dh: ' + this._dh.toFixed(1), x, y + 28); - this.context.fillText('sx: ' + this._sx.toFixed(1) + ' sy: ' + this._sy.toFixed(1) + ' sw: ' + this._sw.toFixed(1) + ' sh: ' + this._sh.toFixed(1), x, y + 42); - - } - */ - - } - -} \ No newline at end of file diff --git a/wip/phaser clean up/DebugPhysics.ts b/wip/phaser clean up/DebugPhysics.ts deleted file mode 100644 index 4dee9ba2..00000000 --- a/wip/phaser clean up/DebugPhysics.ts +++ /dev/null @@ -1,78 +0,0 @@ - static renderPhysicsBody(body: Phaser.Physics.Body, lineWidth: number = 1, fillStyle: string = 'rgba(0,255,0,0.2)', sleepStyle: string = 'rgba(100,100,100,0.2)') { - - for (var s = 0; s < body.shapesLength; s++) - { - DebugUtils.context.beginPath(); - - if (body.shapes[s].type == Phaser.Physics.AdvancedPhysics.SHAPE_TYPE_POLY) - { - var verts = body.shapes[s].tverts; - - // DebugUtils.context.moveTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y); - DebugUtils.context.moveTo(verts[0].x * 50, verts[0].y * 50); - - for (var i = 1; i < verts.length; i++) - { - // DebugUtils.context.lineTo(body.position.x * 50 + verts[i].x, body.position.y * 50 + verts[i].y); - DebugUtils.context.lineTo(verts[i].x * 50, verts[i].y * 50); - } - - // DebugUtils.context.lineTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y); - DebugUtils.context.lineTo(verts[0].x * 50, verts[0].y * 50); - } - else if (body.shapes[s].type == Phaser.Physics.AdvancedPhysics.SHAPE_TYPE_CIRCLE) - { - var circle = body.shapes[s]; - DebugUtils.context.arc(circle.tc.x * 50, circle.tc.y * 50, circle.radius * 50, 0, Math.PI * 2, false); - } - - DebugUtils.context.closePath(); - - if (body.isAwake) - { - DebugUtils.context.fillStyle = fillStyle; - } - else - { - DebugUtils.context.fillStyle = sleepStyle; - } - - DebugUtils.context.fill(); - - } - - } - - /** - * Render debug infos. (including name, bounds info, position and some other properties) - * @param x {number} X position of the debug info to be rendered. - * @param y {number} Y position of the debug info to be rendered. - * @param [color] {number} color of the debug info to be rendered. (format is css color string) - */ - /* - static renderPhysicsBodyInfo(body: Phaser.Physics.Body, x: number, y: number, color?: string = 'rgb(255,255,255)') { - - DebugUtils.context.fillStyle = color; - DebugUtils.context.fillText('Body ID: ' + body.name, x, y); - DebugUtils.context.fillText('Position x: ' + body.position.x.toFixed(1) + ' y: ' + body.position.y.toFixed(1) + ' rotation: ' + body.angle.toFixed(1), x, y + 14); - DebugUtils.context.fillText('World x: ' + (body.position.x * 50).toFixed(1) + ' y: ' + (body.position.y * 50).toFixed(1), x, y + 28); - DebugUtils.context.fillText('Velocity x: ' + body.velocity.x.toFixed(1) + ' y: ' + body.velocity.y.toFixed(1), x, y + 42); - - if (body.shapes[0].verts.length > 0) - { - DebugUtils.context.fillText('Vert 1 x: ' + (body.shapes[0].verts[0].x * 50) + ' y: ' + (body.shapes[0].verts[0].y * 50), x, y + 56); - DebugUtils.context.fillText('Vert 2 x: ' + (body.shapes[0].verts[1].x * 50) + ' y: ' + (body.shapes[0].verts[1].y * 50), x, y + 70); - DebugUtils.context.fillText('Vert 3 x: ' + (body.shapes[0].tverts[2].x * 50) + ' y: ' + (body.shapes[0].tverts[2].y * 50), x, y + 84); - DebugUtils.context.fillText('Vert 4 x: ' + (body.shapes[0].tverts[3].x * 50) + ' y: ' + (body.shapes[0].tverts[3].y * 50), x, y + 98); - - // - // DebugUtils.context.fillText('Vert 1 x: ' + body.shapes[0].verts[0].x.toFixed(1) + ' y: ' + body.shapes[0].verts[0].y.toFixed(1), x, y + 56); - // DebugUtils.context.fillText('Vert 2 x: ' + body.shapes[0].verts[1].x.toFixed(1) + ' y: ' + body.shapes[0].verts[1].y.toFixed(1), x, y + 70); - // DebugUtils.context.fillText('Vert 3 x: ' + body.shapes[0].verts[2].x.toFixed(1) + ' y: ' + body.shapes[0].verts[2].y.toFixed(1), x, y + 84); - // DebugUtils.context.fillText('Vert 4 x: ' + body.shapes[0].verts[3].x.toFixed(1) + ' y: ' + body.shapes[0].verts[3].y.toFixed(1), x, y + 98); - // - - } - - } - */ diff --git a/wip/phaser clean up/Emitter.ts b/wip/phaser clean up/Emitter.ts deleted file mode 100644 index 1aa5d2b1..00000000 --- a/wip/phaser clean up/Emitter.ts +++ /dev/null @@ -1,454 +0,0 @@ -/// -/// - -/** -* Phaser - Emitter -* -* Emitter is a lightweight particle emitter. It can be used for one-time explosions or for -* continuous effects like rain and fire. All it really does is launch Particle objects out -* at set intervals, and fixes their positions and velocities accorindgly. -*/ - -module Phaser { - - export class Emitter extends Group { - - /** - * Creates a new Emitter object at a specific position. - * Does NOT automatically generate or attach particles! - * - * @param x {number} The X position of the emitter. - * @param y {number} The Y position of the emitter. - * @param [size] {number} 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 MicroPoint(-100, -100); - this.maxParticleSpeed = new MicroPoint(100, 100); - this.minRotation = -360; - this.maxRotation = 360; - this.gravity = 0; - this.particleClass = null; - this.particleDrag = new MicroPoint(); - 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 MicroPoint(); - - } - - /** - * 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: MicroPoint; - - /** - * The maximum possible velocity of a particle. - * The default value is (100,100). - */ - public maxParticleSpeed: MicroPoint; - - /** - * The X and Y drag component of particles launched from the emitter. - */ - public particleDrag: MicroPoint; - - /** - * 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: MicroPoint; - - /** - * 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 Sprite objects, you can simply pass in a particle image or sprite sheet. - * @param quantity {number} The number of particles to generate when using the "create from image" option. - * @param multiple {boolean} 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 {number} 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 Emitter instance (nice for chaining stuff together, if you're into that). - */ - public makeParticles(graphics, quantity: number = 50, multiple: bool = false, collide: number = 0): 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.allowCollisions = Collision.ANY; - 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 {boolean} Whether the particles should all burst out at once. - * @param lifespan {number} How long each particle lives once emitted. 0 = forever. - * @param frequency {number} 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 {number} 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 && this.minRotation !== 0 && this.maxRotation !== 0) - { - 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 {number} The desired width of the emitter (particles are spawned randomly within these dimensions). - * @param height {number} 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 {number} The minimum value for this range. - * @param Max {number} 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 {number} The minimum value for this range. - * @param Max {number} 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 {number} The minimum value for this range. - * @param Max {number} 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 Object. - * - * @param Object {object} The Object 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/wip/phaser clean up/Input.ts b/wip/phaser clean up/Input.ts deleted file mode 100644 index 75a23b04..00000000 --- a/wip/phaser clean up/Input.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** -* Phaser - Components - Input -* -* -*/ - -module Phaser.Components { - - export class Input { - - // Input - //public inputEnabled: bool = false; - //private _inputOver: bool = false; - - //public onInputOver: Phaser.Signal; - //public onInputOut: Phaser.Signal; - //public onInputDown: Phaser.Signal; - //public onInputUp: Phaser.Signal; - - /** - * Update input. - */ - private updateInput() { - } - - - } - -} \ No newline at end of file diff --git a/wip/phaser clean up/Motion.ts b/wip/phaser clean up/Motion.ts deleted file mode 100644 index 6d91c688..00000000 --- a/wip/phaser clean up/Motion.ts +++ /dev/null @@ -1,409 +0,0 @@ -/// -/// - -/** -* Phaser - Motion -* -* The Motion class contains lots of useful functions for moving game objects around in world space. -*/ - -module Phaser { - - export class Motion { - - constructor(game: Game) { - - this._game = game; - - } - - private _game: Game; - - /** - * A tween-like function that takes a starting velocity and some other factors and returns an altered velocity. - * - * @param {number} Velocity Any component of velocity (e.g. 20). - * @param {number} Acceleration Rate at which the velocity is changing. - * @param {number} Drag Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set. - * @param {number} Max An absolute value cap for the velocity. - * - * @return {number} The altered Velocity value. - */ - public computeVelocity(Velocity: number, Acceleration: number = 0, Drag: number = 0, Max: number = 10000): number { - - if (Acceleration !== 0) - { - Velocity += Acceleration * this._game.time.elapsed; - } - else if (Drag !== 0) - { - var drag: number = Drag * this._game.time.elapsed; - - if (Velocity - drag > 0) - { - Velocity = Velocity - drag; - } - else if (Velocity + drag < 0) - { - Velocity += drag; - } - else - { - Velocity = 0; - } - } - - if ((Velocity != 0) && (Max != 10000)) - { - if (Velocity > Max) - { - Velocity = Max; - } - else if (Velocity < -Max) - { - Velocity = -Max; - } - } - - return Velocity; - - } - - /** - * Given the angle and speed calculate the velocity and return it as a Point - * - * @param {number} angle The angle (in degrees) calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) - * @param {number} speed The speed it will move, in pixels per second sq - * - * @return {Point} 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 { - - if (isNaN(speed)) - { - speed = 0; - } - - var a: number = this._game.math.degreesToRadians(angle); - - return new Point((Math.cos(a) * speed), (Math.sin(a) * speed)); - - } - - /** - * Sets the source Sprite x/y velocity so it will move directly towards the destination Sprite at the speed given (in pixels per second)
- * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.
- * Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms.
- * The source object doesn't stop moving automatically should it ever reach the destination coordinates.
- * If you need the object to accelerate, see accelerateTowardsObject() instead - * Note: Doesn't take into account acceleration, maxVelocity or drag (if you set drag or acceleration too high this object may not move at all) - * - * @param {GameObject} source The Sprite on which the velocity will be set - * @param {GameObject} dest The Sprite where the source object will move to - * @param {number} speed The speed it will move, in pixels per second (default is 60 pixels/sec) - * @param {number} maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms - */ - public moveTowardsObject(source:GameObject, dest:GameObject, speed:number= 60, maxTime:number = 0) - { - var a:number = this.angleBetween(source, dest); - - if (maxTime > 0) - { - var d:number = this.distanceBetween(source, dest); - - // We know how many pixels we need to move, but how fast? - speed = d / (maxTime / 1000); - } - - source.velocity.x = Math.cos(a) * speed; - source.velocity.y = Math.sin(a) * speed; - - } - - /** - * Sets the x/y acceleration on the source Sprite so it will move towards the destination Sprite at the speed given (in pixels per second)
- * You must give a maximum speed value, beyond which the Sprite won't go any faster.
- * If you don't need acceleration look at moveTowardsObject() instead. - * - * @param {GameObject} source The Sprite on which the acceleration will be set - * @param {GameObject} dest The Sprite where the source object will move towards - * @param {number} speed The speed it will accelerate in pixels per second - * @param {number} xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally - * @param {number} ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically - */ - public accelerateTowardsObject(source:GameObject, dest:GameObject, speed:number, xSpeedMax:number, ySpeedMax:number) - { - var a:number = this.angleBetween(source, dest); - - source.velocity.x = 0; - source.velocity.y = 0; - - source.acceleration.x = Math.cos(a) * speed; - source.acceleration.y = Math.sin(a) * speed; - - source.maxVelocity.x = xSpeedMax; - source.maxVelocity.y = ySpeedMax; - - } - - /** - * Move the given Sprite towards the mouse pointer coordinates at a steady velocity - * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.
- * Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms.
- * The source object doesn't stop moving automatically should it ever reach the destination coordinates.
- * - * @param {GameObject} source The Sprite to move - * @param {number} speed The speed it will move, in pixels per second (default is 60 pixels/sec) - * @param {number} maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms - */ - public moveTowardsMouse(source:GameObject, speed:number = 60, maxTime:number = 0) - { - var a:number = this.angleBetweenMouse(source); - - if (maxTime > 0) - { - var d:number = this.distanceToMouse(source); - - // We know how many pixels we need to move, but how fast? - speed = d / (maxTime / 1000); - } - - source.velocity.x = Math.cos(a) * speed; - source.velocity.y = Math.sin(a) * speed; - - } - - /** - * Sets the x/y acceleration on the source Sprite so it will move towards the mouse coordinates at the speed given (in pixels per second)
- * You must give a maximum speed value, beyond which the Sprite won't go any faster.
- * If you don't need acceleration look at moveTowardsMouse() instead. - * - * @param {GameObject} source The Sprite on which the acceleration will be set - * @param {number} speed The speed it will accelerate in pixels per second - * @param {number} xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally - * @param {number} ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically - */ - public accelerateTowardsMouse(source:GameObject, speed:number, xSpeedMax:number, ySpeedMax:number) - { - var a:number = this.angleBetweenMouse(source); - - source.velocity.x = 0; - source.velocity.y = 0; - - source.acceleration.x = Math.cos(a) * speed; - source.acceleration.y = Math.sin(a) * speed; - - source.maxVelocity.x = xSpeedMax; - source.maxVelocity.y = ySpeedMax; - } - - /** - * Sets the x/y velocity on the source Sprite so it will move towards the target coordinates at the speed given (in pixels per second)
- * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.
- * Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms.
- * The source object doesn't stop moving automatically should it ever reach the destination coordinates.
- * - * @param {GameObject} source The Sprite to move - * @param {Point} target The Point coordinates to move the source Sprite towards - * @param {number} speed The speed it will move, in pixels per second (default is 60 pixels/sec) - * @param {number} maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms - */ - public moveTowardsPoint(source:GameObject, target:Point, speed:number = 60, maxTime:number = 0) - { - var a:number = this.angleBetweenPoint(source, target); - - if (maxTime > 0) - { - var d:number = this.distanceToPoint(source, target); - - // We know how many pixels we need to move, but how fast? - speed = d / (maxTime / 1000); - } - - source.velocity.x = Math.cos(a) * speed; - source.velocity.y = Math.sin(a) * speed; - } - - /** - * Sets the x/y acceleration on the source Sprite so it will move towards the target coordinates at the speed given (in pixels per second)
- * You must give a maximum speed value, beyond which the Sprite won't go any faster.
- * If you don't need acceleration look at moveTowardsPoint() instead. - * - * @param {GameObject} source The Sprite on which the acceleration will be set - * @param {Point} target The Point coordinates to move the source Sprite towards - * @param {number} speed The speed it will accelerate in pixels per second - * @param {number} xSpeedMax The maximum speed in pixels per second in which the sprite can move horizontally - * @param {number} ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically - */ - public accelerateTowardsPoint(source:GameObject, target:Point, speed:number, xSpeedMax:number, ySpeedMax:number) - { - var a:number = this.angleBetweenPoint(source, target); - - source.velocity.x = 0; - source.velocity.y = 0; - - source.acceleration.x = Math.cos(a) * speed; - source.acceleration.y = Math.sin(a) * speed; - - source.maxVelocity.x = xSpeedMax; - source.maxVelocity.y = ySpeedMax; - } - - /** - * Find the distance (in pixels, rounded) between two Sprites, taking their origin into account - * - * @param {GameObject} a The first Sprite - * @param {GameObject} b The second Sprite - * @return {number} int Distance (in pixels) - */ - public distanceBetween(a:GameObject, b:GameObject):number - { - var dx:number = (a.x + a.origin.x) - (b.x + b.origin.x); - var dy:number = (a.y + a.origin.y) - (b.y + b.origin.y); - - return this._game.math.vectorLength(dx, dy); - - } - - /** - * Find the distance (in pixels, rounded) from an Sprite to the given Point, taking the source origin into account - * - * @param {GameObject} a The Sprite - * @param {Point} target The Point - * @return {number} Distance (in pixels) - */ - public distanceToPoint(a:GameObject, target:Point):number - { - var dx:number = (a.x + a.origin.x) - (target.x); - var dy:number = (a.y + a.origin.y) - (target.y); - - return this._game.math.vectorLength(dx, dy); - } - - /** - * Find the distance (in pixels, rounded) from the object x/y and the mouse x/y - * - * @param {GameObject} a Sprite to test against - * @return {number} The distance between the given sprite and the mouse coordinates - */ - public distanceToMouse(a:GameObject):number - { - var dx: number = (a.x + a.origin.x) - this._game.input.x; - var dy: number = (a.y + a.origin.y) - this._game.input.y; - - return this._game.math.vectorLength(dx, dy); - } - - /** - * Find the angle (in radians) between an Sprite and an Point. The source sprite takes its x/y and origin into account. - * The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) - * - * @param {GameObject} a The Sprite to test from - * @param {Point} target The Point to angle the Sprite towards - * @param {boolean} asDegrees If you need the value in degrees instead of radians, set to true - * - * @return {number} The angle (in radians unless asDegrees is true) - */ - public angleBetweenPoint(a:GameObject, target:Point, asDegrees:bool = false):number - { - var dx:number = (target.x) - (a.x + a.origin.x); - var dy:number = (target.y) - (a.y + a.origin.y); - - if (asDegrees) - { - return this._game.math.radiansToDegrees(Math.atan2(dy, dx)); - } - else - { - return Math.atan2(dy, dx); - } - } - - /** - * Find the angle (in radians) between the two Sprite, taking their x/y and origin into account. - * The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) - * - * @param {GameObject} a The Sprite to test from - * @param {GameObject} b The Sprite to test to - * @param {boolean} asDegrees If you need the value in degrees instead of radians, set to true - * - * @return {number} The angle (in radians unless asDegrees is true) - */ - public angleBetween(a:GameObject, b:GameObject, asDegrees:bool = false):number - { - var dx:number = (b.x + b.origin.x) - (a.x + a.origin.x); - var dy:number = (b.y + b.origin.y) - (a.y + a.origin.y); - - if (asDegrees) - { - return this._game.math.radiansToDegrees(Math.atan2(dy, dx)); - } - else - { - return Math.atan2(dy, dx); - } - } - - /** - * Given the GameObject and speed calculate the velocity and return it as an Point based on the direction the sprite is facing - * - * @param {GameObject} parent The Sprite to get the facing value from - * @param {number} speed The speed it will move, in pixels per second sq - * - * @return {Point} An Point where Point.x contains the velocity x value and Point.y contains the velocity y value - */ - public velocityFromFacing(parent:GameObject, speed:number):Point - { - var a:number; - - if (parent.facing == Collision.LEFT) - { - a = this._game.math.degreesToRadians(180); - } - else if (parent.facing == Collision.RIGHT) - { - a = this._game.math.degreesToRadians(0); - } - else if (parent.facing == Collision.UP) - { - a = this._game.math.degreesToRadians(-90); - } - else if (parent.facing == Collision.DOWN) - { - a = this._game.math.degreesToRadians(90); - } - - return new Point(Math.cos(a) * speed, Math.sin(a) * speed); - - } - - /** - * Find the angle (in radians) between an Sprite and the mouse, taking their x/y and origin into account. - * The angle is calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) - * - * @param {GameObject} a The Object to test from - * @param {boolean} asDegrees If you need the value in degrees instead of radians, set to true - * - * @return {number} The angle (in radians unless asDegrees is true) - */ - public angleBetweenMouse(a:GameObject, asDegrees:bool = false):number - { - // In order to get the angle between the object and mouse, we need the objects screen coordinates (rather than world coordinates) - var p:MicroPoint = a.getScreenXY(); - - var dx:number = a._game.input.x - p.x; - var dy:number = a._game.input.y - p.y; - - if (asDegrees) - { - return this._game.math.radiansToDegrees(Math.atan2(dy, dx)); - } - else - { - return Math.atan2(dy, dx); - } - } - - } - -} diff --git a/wip/phaser clean up/OldSprite.ts b/wip/phaser clean up/OldSprite.ts deleted file mode 100644 index 1e28f513..00000000 --- a/wip/phaser clean up/OldSprite.ts +++ /dev/null @@ -1,355 +0,0 @@ -/// -/// -/// -/// - -/** -* Phaser - Sprite -* -* The Sprite GameObject is an extension of the core GameObject that includes support for animation and dynamic textures. -* It's probably the most used GameObject of all. -*/ - -module Phaser { - - export class OldSprite { - - /** - * Sprite constructor - * Create a new Sprite. - * - * @param game {Phaser.Game} Current game instance. - * @param [x] {number} the initial x position of the sprite. - * @param [y] {number} the initial y position of the sprite. - * @param [key] {string} Key of the graphic you want to load for this sprite. - * @param [width] {number} The width of the object. - * @param [height] {number} The height of the object. - */ - constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, width?: number = 16, height?: number = 16) { - - this.canvas = game.stage.canvas; - this.context = game.stage.context; - - this.frameBounds = new Rectangle(x, y, width, height); - this.exists = true; - this.active = true; - this.visible = true; - this.alive = true; - this.isGroup = false; - this.alpha = 1; - this.scale = new MicroPoint(1, 1); - - this.last = new MicroPoint(x, y); - this.align = GameObject.ALIGN_TOP_LEFT; - this.mass = 1; - this.elasticity = 0; - this.health = 1; - this.immovable = false; - this.moves = true; - this.worldBounds = null; - - this.touching = Collision.NONE; - this.wasTouching = Collision.NONE; - this.allowCollisions = Collision.ANY; - - this.velocity = new MicroPoint(); - this.acceleration = new MicroPoint(); - this.drag = new MicroPoint(); - this.maxVelocity = new MicroPoint(10000, 10000); - - this.angle = 0; - this.angularVelocity = 0; - this.angularAcceleration = 0; - this.angularDrag = 0; - this.maxAngular = 10000; - - this.cameraBlacklist = []; - this.scrollFactor = new MicroPoint(1, 1); - this.collisionMask = new CollisionMask(game, this, x, y, width, height); - - - this._texture = null; - - this.animations = new AnimationManager(this._game, this); - - if (key !== null) - { - this.cacheKey = key; - this.loadGraphic(key); - } - else - { - this.frameBounds.width = 16; - this.frameBounds.height = 16; - } - - } - - /** - * The essential reference to the main game object - */ - public _game: Game; - - /** - * Controls whether update() is automatically called by State/Group. - */ - public active: bool; - - /** - * Controls whether draw() is automatically called by State/Group. - */ - public visible: bool; - - /** - * Setting this to true will prevent the object from being updated during the main game loop (you will have to call update on it yourself) - */ - public ignoreGlobalUpdate: bool; - - /** - * Setting this to true will prevent the object from being rendered during the main game loop (you will have to call render on it yourself) - */ - public ignoreGlobalRender: bool; - - /** - * An Array of Cameras to which this GameObject won't render - * @type {Array} - */ - public cameraBlacklist: number[]; - - /** - * Orientation of the object. - * @type {number} - */ - public facing: number; - - /** - * Set alpha to a number between 0 and 1 to change the opacity. - * @type {number} - */ - public alpha: number; - - /** - * Scale factor of the object. - * @type {MicroPoint} - */ - public scale: MicroPoint; - - /** - * Controls if the GameObject is rendered rotated or not. - * If renderRotation is false then the object can still rotate but it will never be rendered rotated. - * @type {boolean} - */ - public renderRotation: bool = true; - - /** - * A point that can store numbers from 0 to 1 (for X and Y independently) - * which governs how much this object is affected by the camera . - * @type {MicroPoint} - */ - public scrollFactor: MicroPoint; - - /** - * Rectangle container of this object. - * @type {Rectangle} - */ - public frameBounds: Rectangle; - - /** - * This objects CollisionMask - * @type {CollisionMask} - */ - public collisionMask: CollisionMask; - - /** - * A rectangular area which is object is allowed to exist within. If it travels outside of this area it will perform the outOfBoundsAction. - * @type {Quad} - */ - public worldBounds: Quad; - - /** - * A reference to the Canvas this GameObject will render to - * @type {HTMLCanvasElement} - */ - public canvas: HTMLCanvasElement; - - /** - * A reference to the Canvas Context2D this GameObject will render to - * @type {CanvasRenderingContext2D} - */ - public context: CanvasRenderingContext2D; - - /** - * Texture of this sprite to be rendered. - */ - private _texture; - - /** - * Texture of this sprite is DynamicTexture? (default to false) - * @type {boolean} - */ - private _dynamicTexture: bool = false; - - - /** - * This manages animations of the sprite. You can modify animations though it. (see AnimationManager) - * @type AnimationManager - */ - public animations: AnimationManager; - - /** - * The cache key that was used for this texture (if any) - */ - public cacheKey: string; - - - /** - * Flip the graphic horizontally? (defaults to false) - * @type {boolean} - */ - public flipped: bool = false; - - - - /** - * Pre-update is called right before update() on each object in the game loop. - */ - public preUpdate() { - - this.last.x = this.frameBounds.x; - this.last.y = this.frameBounds.y; - - this.collisionMask.preUpdate(); - - } - - /** - * Override this function to update your class's position and appearance. - */ - public update() { - } - - /** - * Automatically called after update() by the game loop. - */ - public postUpdate() { - - this.animations.update(); - - if (this.moves) - { - this.updateMotion(); - } - - if (this.worldBounds != null) - { - if (this.outOfBoundsAction == GameObject.OUT_OF_BOUNDS_KILL) - { - if (this.x < this.worldBounds.x || this.x > this.worldBounds.right || this.y < this.worldBounds.y || this.y > this.worldBounds.bottom) - { - this.kill(); - } - } - else - { - if (this.x < this.worldBounds.x) - { - this.x = this.worldBounds.x; - } - else if (this.x > this.worldBounds.right) - { - this.x = this.worldBounds.right; - } - - if (this.y < this.worldBounds.y) - { - this.y = this.worldBounds.y; - } - else if (this.y > this.worldBounds.bottom) - { - this.y = this.worldBounds.bottom; - } - } - } - - this.collisionMask.update(); - - if (this.inputEnabled) - { - this.updateInput(); - } - - this.wasTouching = this.touching; - this.touching = Collision.NONE; - - } - - /** - * Clean up memory. - */ - public destroy() { - } - - public set width(value:number) { - this.frameBounds.width = value; - } - - public set height(value:number) { - this.frameBounds.height = value; - } - - public get width(): number { - return this.frameBounds.width; - } - - public get height(): number { - return this.frameBounds.height; - } - - public set frame(value: number) { - this.animations.frame = value; - } - - public get frame(): number { - return this.animations.frame; - } - - public set frameName(value: string) { - this.animations.frameName = value; - } - - public get frameName(): string { - return this.animations.frameName; - } - - /** - * Handy for "killing" game objects. - * Default behavior is to flag them as nonexistent AND dead. - * However, if you want the "corpse" to remain in the game, - * like to animate an effect or whatever, you should override this, - * setting only alive to false, and leaving exists true. - */ - public kill() { - this.alive = false; - this.exists = false; - } - - /** - * Handy for bringing game objects "back to life". Just sets alive and exists back to true. - * In practice, this is most often called by Object.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 ""; - } - - - } - -} \ No newline at end of file diff --git a/wip/phaser clean up/PixelUtils.ts b/wip/phaser clean up/PixelUtils.ts deleted file mode 100644 index dfd1f8d3..00000000 --- a/wip/phaser clean up/PixelUtils.ts +++ /dev/null @@ -1,49 +0,0 @@ -/// -/// -/// -/// - -/** -* Phaser - PixelUtils -* -* A collection of methods useful for manipulating pixels. -*/ - -module Phaser { - - export class PixelUtils { - - static boot() { - - PixelUtils.pixelCanvas = document.createElement('canvas'); - PixelUtils.pixelCanvas.width = 1; - PixelUtils.pixelCanvas.height = 1; - PixelUtils.pixelContext = PixelUtils.pixelCanvas.getContext('2d'); - - } - - /** - * Canvas element used in 1x1 pixel checks. - * @type {HTMLCanvasElement} - */ - static pixelCanvas: HTMLCanvasElement; - - /** - * Render context of pixelCanvas - * @type {CanvasRenderingContext2D} - */ - static pixelContext: CanvasRenderingContext2D; - - static getPixel(key: string, x: number, y: number): number { - - // write out a single pixel (won't help with rotated sprites though.. hmm) - - var imageData = PixelUtils.pixelContext.getImageData(0, 0, 1, 1); - - return ColorUtils.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]); - - } - - } - -} \ No newline at end of file diff --git a/wip/phaser clean up/Properties.ts b/wip/phaser clean up/Properties.ts deleted file mode 100644 index 3171afe9..00000000 --- a/wip/phaser clean up/Properties.ts +++ /dev/null @@ -1,36 +0,0 @@ -/** -* Phaser - Components - Properties -* -* -*/ - -module Phaser.Components { - - export class Properties { - - /** - * Handy for storing health percentage or armor points or whatever. - * @type {number} - */ - public health: number; - - /** - * Reduces the "health" variable of this sprite by the amount specified in Damage. - * Calls kill() if health drops to or below zero. - * - * @param Damage {number} How much health to take away (use a negative number to give a health bonus). - */ - public hurt(damage: number) { - - this.health = this.health - damage; - - if (this.health <= 0) - { - //this.kill(); - } - - } - - } - -} \ No newline at end of file diff --git a/wip/phaser clean up/Tilemap.ts b/wip/phaser clean up/Tilemap.ts deleted file mode 100644 index 746d7df5..00000000 --- a/wip/phaser clean up/Tilemap.ts +++ /dev/null @@ -1,434 +0,0 @@ -/// -/// -/// - -/** -* Phaser - Tilemap -* -* This GameObject allows for the display of a tilemap within the game world. Tile maps consist of an image, tile data and a size. -* Internally it creates a TilemapLayer for each layer in the tilemap. -*/ - -module Phaser { - - export class Tilemap { - - /** - * Tilemap constructor - * Create a new Tilemap. - * - * @param game {Phaser.Game} Current game instance. - * @param key {string} Asset key for this map. - * @param mapData {string} Data of this map. (a big 2d array, normally in csv) - * @param format {number} Format of this map data, available: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON. - * @param resizeWorld {boolean} Resize the world bound automatically based on this tilemap? - * @param tileWidth {number} Width of tiles in this map. - * @param tileHeight {number} Height of tiles in this map. - */ - constructor(game: Game, key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0) { - - //super(game); - - this.isGroup = false; - - this.tiles = []; - this.layers = []; - - this.mapFormat = format; - - switch (format) - { - case Tilemap.FORMAT_CSV: - this.parseCSV(game.cache.getText(mapData), key, tileWidth, tileHeight); - break; - - case Tilemap.FORMAT_TILED_JSON: - this.parseTiledJSON(game.cache.getText(mapData), key); - break; - } - - if (this.currentLayer && resizeWorld) - { - this._game.world.setSize(this.currentLayer.widthInPixels, this.currentLayer.heightInPixels, true); - } - - } - - private _tempCollisionData; - - /** - * Tilemap data format enum: CSV. - * @type {number} - */ - public static FORMAT_CSV: number = 0; - /** - * Tilemap data format enum: Tiled JSON. - * @type {number} - */ - public static FORMAT_TILED_JSON: number = 1; - - /** - * Array contains tile objects of this map. - * @type {Tile[]} - */ - public tiles : Tile[]; - /** - * Array contains tilemap layer objects of this map. - * @type {TilemapLayer[]} - */ - public layers : TilemapLayer[]; - /** - * Current tilemap layer. - * @type {TilemapLayer} - */ - public currentLayer: TilemapLayer; - /** - * The tilemap layer for collision. - * @type {TilemapLayer} - */ - public collisionLayer: TilemapLayer; - /** - * Tilemap collision callback. - * @type {function} - */ - public collisionCallback = null; - /** - * Context for the collision callback called with. - */ - public collisionCallbackContext; - /** - * Format of this tilemap data. Available values: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON. - * @type {number} - */ - public mapFormat: number; - - /** - * Inherited update method. - */ - public update() { - } - - /** - * Render this tilemap to a specific camera with specific offset. - * @param camera {Camera} The camera this tilemap will be rendered to. - * @param cameraOffsetX {number} X offset of the camera. - * @param cameraOffsetY {number} Y offset of the camera. - */ - public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) { - - if (this.cameraBlacklist.indexOf(camera.ID) == -1) - { - // Loop through the layers - for (var i = 0; i < this.layers.length; i++) - { - this.layers[i].render(camera, cameraOffsetX, cameraOffsetY); - } - } - - } - - /** - * Parset csv map data and generate tiles. - * @param data {string} CSV map data. - * @param key {string} Asset key for tileset image. - * @param tileWidth {number} Width of its tile. - * @param tileHeight {number} Height of its tile. - */ - private parseCSV(data: string, key: string, tileWidth: number, tileHeight: number) { - - var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight); - - // Trim any rogue whitespace from the data - data = data.trim(); - - var rows = data.split("\n"); - - for (var i = 0; i < rows.length; i++) - { - var column = rows[i].split(","); - - if (column.length > 0) - { - layer.addColumn(column); - } - } - - layer.updateBounds(); - var tileQuantity = layer.parseTileOffsets(); - - this.currentLayer = layer; - this.collisionLayer = layer; - - this.layers.push(layer); - - this.generateTiles(tileQuantity); - - } - - /** - * Parset JSON map data and generate tiles. - * @param data {string} JSON map data. - * @param key {string} Asset key for tileset image. - */ - private parseTiledJSON(data: string, key: string) { - - // Trim any rogue whitespace from the data - data = data.trim(); - - var json = JSON.parse(data); - - for (var i = 0; i < json.layers.length; i++) - { - var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight); - - layer.alpha = json.layers[i].opacity; - layer.visible = json.layers[i].visible; - layer.tileMargin = json.tilesets[0].margin; - layer.tileSpacing = json.tilesets[0].spacing; - - var c = 0; - var row; - - for (var t = 0; t < json.layers[i].data.length; t++) - { - if (c == 0) - { - row = []; - } - - row.push(json.layers[i].data[t]); - - c++; - - if (c == json.layers[i].width) - { - layer.addColumn(row); - c = 0; - } - } - - layer.updateBounds(); - - var tileQuantity = layer.parseTileOffsets(); - - this.currentLayer = layer; - this.collisionLayer = layer; - - this.layers.push(layer); - - } - - this.generateTiles(tileQuantity); - - } - - /** - * Create tiles of given quantity. - * @param qty {number} Quentity of tiles to be generated. - */ - private generateTiles(qty:number) { - - for (var i = 0; i < qty; i++) - { - this.tiles.push(new Tile(this._game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight)); - } - - } - - public get widthInPixels(): number { - return this.currentLayer.widthInPixels; - } - - public get heightInPixels(): number { - return this.currentLayer.heightInPixels; - } - - // Tile Collision - - /** - * Set callback to be called when this tilemap collides. - * @param context {object} Callback will be called with this context. - * @param callback {function} Callback function. - */ - public setCollisionCallback(context, callback) { - - this.collisionCallbackContext = context; - this.collisionCallback = callback; - - } - - /** - * Set collision configs of tiles in a range index. - * @param start {number} First index of tiles. - * @param end {number} Last index of tiles. - * @param collision {number} Bit field of flags. (see Tile.allowCollision) - * @param resetCollisions {boolean} Reset collision flags before set. - * @param separateX {boolean} Enable seprate at x-axis. - * @param separateY {boolean} Enable seprate at y-axis. - */ - public setCollisionRange(start: number, end: number, collision?:number = Collision.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) { - - for (var i = start; i < end; i++) - { - this.tiles[i].setCollision(collision, resetCollisions, separateX, separateY); - } - - } - - /** - * Set collision configs of tiles with given index. - * @param values {number[]} Index array which contains all tile indexes. The tiles with those indexes will be setup with rest parameters. - * @param collision {number} Bit field of flags. (see Tile.allowCollision) - * @param resetCollisions {boolean} Reset collision flags before set. - * @param separateX {boolean} Enable seprate at x-axis. - * @param separateY {boolean} Enable seprate at y-axis. - */ - public setCollisionByIndex(values:number[], collision?:number = Collision.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) { - - for (var i = 0; i < values.length; i++) - { - this.tiles[values[i]].setCollision(collision, resetCollisions, separateX, separateY); - } - - } - - // Tile Management - - /** - * Get the tile by its index. - * @param value {number} Index of the tile you want to get. - * @return {Tile} The tile with given index. - */ - public getTileByIndex(value: number):Tile { - - if (this.tiles[value]) - { - return this.tiles[value]; - } - - return null; - - } - - /** - * Get the tile located at specific position and layer. - * @param x {number} X position of this tile located. - * @param y {number} Y position of this tile located. - * @param [layer] {number} layer of this tile located. - * @return {Tile} The tile with specific properties. - */ - public getTile(x: number, y: number, layer?: number = 0):Tile { - - return this.tiles[this.layers[layer].getTileIndex(x, y)]; - - } - - /** - * Get the tile located at specific position (in world coordinate) and layer. (thus you give a position of a point which is within the tile) - * @param x {number} X position of the point in target tile. - * @param x {number} Y position of the point in target tile. - * @param [layer] {number} layer of this tile located. - * @return {Tile} The tile with specific properties. - */ - public getTileFromWorldXY(x: number, y: number, layer?: number = 0):Tile { - - return this.tiles[this.layers[layer].getTileFromWorldXY(x, y)]; - - } - - public getTileFromInputXY(layer?: number = 0):Tile { - - return this.tiles[this.layers[layer].getTileFromWorldXY(this._game.input.getWorldX(), this._game.input.getWorldY())]; - - } - - /** - * Get tiles overlaps the given object. - * @param object {GameObject} Tiles you want to get that overlaps this. - * @return {array} Array with tiles informations. (Each contains x, y and the tile.) - */ - public getTileOverlaps(object: GameObject) { - - return this.currentLayer.getTileOverlaps(object); - - } - - // COLLIDE - /** - * Check whether this tilemap collides with the given game object or group of objects. - * @param objectOrGroup {function} Target object of group you want to check. - * @param callback {function} This is called if objectOrGroup collides the tilemap. - * @param context {object} Callback will be called with this context. - * @return {boolean} Return true if this collides with given object, otherwise return false. - */ - public collide(objectOrGroup = null, callback = null, context = null) { - - if (callback !== null && context !== null) - { - this.collisionCallback = callback; - this.collisionCallbackContext = context; - } - - if (objectOrGroup == null) - { - objectOrGroup = this._game.world.group; - } - - // Group? - if (objectOrGroup.isGroup == false) - { - this.collideGameObject(objectOrGroup); - } - else - { - objectOrGroup.forEachAlive(this, this.collideGameObject, true); - } - - } - - /** - * Check whether this tilemap collides with the given game object. - * @param object {GameObject} Target object you want to check. - * @return {boolean} Return true if this collides with given object, otherwise return false. - */ - public collideGameObject(object: GameObject): bool { - - if (object !== this && object.immovable == false && object.exists == true && object.allowCollisions != Collision.NONE) - { - this._tempCollisionData = this.collisionLayer.getTileOverlaps(object); - - if (this.collisionCallback !== null && this._tempCollisionData.length > 0) - { - this.collisionCallback.call(this.collisionCallbackContext, object, this._tempCollisionData); - } - - return true; - } - else - { - return false; - } - - } - - /** - * Set a tile to a specific layer. - * @param x {number} X position of this tile. - * @param y {number} Y position of this tile. - * @param index {number} The index of this tile type in the core map data. - * @param [layer] {number} which layer you want to set the tile to. - */ - public putTile(x: number, y: number, index: number, layer?: number = 0) { - - this.layers[layer].putTile(x, y, index); - - } - - // Set current layer - // Set layer order? - // Delete tiles of certain type - // Erase tiles - - } - -} \ No newline at end of file diff --git a/wip/phaser clean up/aabb 1.ts b/wip/phaser clean up/aabb 1.ts deleted file mode 100644 index df5ac64b..00000000 --- a/wip/phaser clean up/aabb 1.ts +++ /dev/null @@ -1,64 +0,0 @@ -/// - -(function () { - - var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render); - - function init() { - - // Using Phasers asset loader we load up a PNG from the assets folder - game.load.image('atari', 'assets/sprites/atari800xl.png'); - game.load.start(); - - } - - var atari: Phaser.Sprite; - - function create() { - - atari = game.add.sprite(200, 300, 'atari'); - atari.texture.alpha = 0.5; - //atari.scale.setTo(1.5, 1.5); - - //atari.physics.shape.setSize(150, 50); - //atari.physics.shape.offset.setTo(50, 25); - - //atari.physics.gravity.setTo(0, 2); - atari.body.bounce.setTo(0.7, 0.7); - atari.body.drag.setTo(10, 10); - - } - - function update() { - - atari.body.acceleration.x = 0; - atari.body.acceleration.y = 0; - - if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) - { - atari.body.acceleration.x = -150; - } - else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) - { - atari.body.acceleration.x = 150; - } - - if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) - { - atari.body.acceleration.y = -150; - } - else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) - { - atari.body.acceleration.y = 150; - } - - } - - function render() { - - atari.body.renderDebugInfo(16, 16); - Phaser.DebugUtils.renderSpritePhysicsBody(atari); - - } - -})(); diff --git a/wip/phaser clean up/aabb vs aabb 1.ts b/wip/phaser clean up/aabb vs aabb 1.ts deleted file mode 100644 index bbaf3f5e..00000000 --- a/wip/phaser clean up/aabb vs aabb 1.ts +++ /dev/null @@ -1,81 +0,0 @@ -/// - -(function () { - - var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render); - - function init() { - - // Using Phasers asset loader we load up a PNG from the assets folder - game.load.image('atari', 'assets/sprites/atari800xl.png'); - game.load.image('card', 'assets/sprites/mana_card.png'); - game.load.start(); - - } - - var atari: Phaser.Sprite; - var card: Phaser.Sprite; - - function create() { - - //atari = game.add.sprite(350, 100, 'atari'); - //atari = game.add.sprite(350, 500, 'atari'); - atari = game.add.sprite(0, 310, 'atari'); - card = game.add.sprite(400, 300, 'card'); - - //card.body.immovable = true; - - //atari.texture.alpha = 0.5; - //atari.scale.setTo(1.5, 1.5); - - //atari.body.shape.setSize(150, 50); - //atari.body.shape.offset.setTo(50, 25); - - //atari.body.gravity.setTo(0, 2); - atari.body.bounce.setTo(1, 1); - //atari.body.drag.setTo(10, 10); - - card.body.bounce.setTo(0.7, 0.7); - //card.body.velocity.x = -50; - - } - - function update() { - - atari.body.acceleration.x = 0; - atari.body.acceleration.y = 0; - - if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) - { - atari.body.acceleration.x = -150; - } - else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) - { - atari.body.acceleration.x = 150; - } - - if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) - { - atari.body.acceleration.y = -150; - } - else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) - { - atari.body.acceleration.y = 150; - } - - // collide? - game.collide(atari, card); - - } - - function render() { - - atari.body.renderDebugInfo(16, 16); - card.body.renderDebugInfo(200, 16); - - Phaser.DebugUtils.renderSpritePhysicsBody(atari); - Phaser.DebugUtils.renderSpritePhysicsBody(card); - - } - -})(); diff --git a/wip/phaser clean up/body1.ts b/wip/phaser clean up/body1.ts deleted file mode 100644 index 86cb69df..00000000 --- a/wip/phaser clean up/body1.ts +++ /dev/null @@ -1,206 +0,0 @@ -/// -/// -/// -/// - -(function () { - - var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render); - - function init() { - - game.load.image('xatari', 'assets/sprites/atari800xl.png'); - game.load.image('card', 'assets/sprites/mana_card.png'); - game.load.image('atari', 'assets/sprites/shinyball.png'); - game.load.start(); - - } - - var debug: HTMLTextAreaElement; - var atari: Phaser.Sprite; - var card: Phaser.Sprite; - var physics: Phaser.Physics.Advanced.Manager; - var circle: Phaser.Physics.Advanced.Body; - var walls: Phaser.Physics.Advanced.Body; - var t: Phaser.Physics.Advanced.Body; - - function create() { - - //atari = game.add.sprite(200, 100, 'atari'); - - // need to get the physics bounds around the sprite center, regardless of origin - //atari.transform.origin.setTo(0.5, 0.5); - //card = game.add.sprite(500, 300, 'card'); - - physics = new Phaser.Physics.Advanced.Manager(game); - //Phaser.Physics.Advanced.Manager.debug = debug; - - walls = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_STATIC, 0, 0); - walls.game = game; - - //walls.addBox(250, 200, 500, 20, 0, 1, 1); - - //staticBody.addShape(new ShapeBox(0, 0.2, 20.48, 0.4)); - - // * 0.02 p2m - // * 50 m2p - - walls.addBox(0, 500, 1024, 20, 0, 1, 1); - - //walls.transform.setRotation(game.math.degreesToRadians(4)); - //walls.fixedRotation = true; - - // position is in relation to the containing body! don't forget this - //ground = walls.addShape(new Phaser.Physics.Advanced.Shapes.Box(400, 500, 500, 20)); - - //walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 0.2, 20.48, 0.4)); - //walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 15.16, 20.48, 0.4)); - //walls.addShape(new Phaser.Physics.Advanced.ShapeBox(-10.04, 7.68, 0.4, 14.56)); - //walls.addShape(new Phaser.Physics.Advanced.ShapeBox(10.04, 7.68, 0.4, 14.56)); - //walls.resetMassData(); - - physics.space.addBody(walls); - - // Add a circle - //circle = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, 200, 100); - //circle.game = game; - //circle.addCircle(32, 0, 0, 0.5); - //physics.space.addBody(circle); - - t = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, 300, 100); - //t.fixedRotation = true; - t.game = game; - t.addBox(0, 0, 20, 20, 0.5, 1, 1); - //t.addCircle(32, 0, 0, 0.8); - //t.addTriangle(0, 0, 1, 1, 2, 2); - //t.addPoly([{ x: -0.8, y: 0.48 }, { x: -0.8, y: 0 }, { x: 0.8, y: 0 }, { x: 0.8, y: 0.32 }, { x: 0, y: 0.84 }, { x: -0.56, y: 0.84 }], 1, 1, 6); - //t.addPoly([{ x: -0.8, y: 0.48 }, { x: -0.8, y: 0 }, { x: 0.8, y: 0 }, { x: 0.8, y: 0.32 }, { x: 0, y: 0.84 }, { x: -0.56, y: 0.84 }], 0.5, 1, 1); - //t.transform.setRotation(game.math.degreesToRadians(45)); - //t.fixedRotation = true; - physics.space.addBody(t); - - game.input.onTap.add(step, this); - - } - - function step() { - - physics.update(); - } - - function update() { - - //if (physics.space.stepCount < 90) - //{ - physics.update(); - //} - - //atari.x = physics.metersToPixels(circle.position.x); - //atari.y = physics.metersToPixels(circle.position.y); - //atari.rotation = physics.metersToPixels(circle.angle); - - // force moves without rotating - - if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) - { - circle.applyAngularImpulse(-0.02); - } - else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) - { - circle.applyAngularImpulse(0.02); - } - - - /* - if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) - { - circle.applyForceToCenter(new Phaser.Vec2(-8, 0)); - } - else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) - { - circle.applyForceToCenter(new Phaser.Vec2(8, 0)); - } - */ - - if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) - { - circle.applyForceToCenter(new Phaser.Vec2(0, -10)); - } - else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) - { - circle.applyForceToCenter(new Phaser.Vec2(0, 5)); - } - - //console.log(circle.velocity.x, circle.velocity.y); - //console.log('p', circle.position.x, circle.position.y); - } - - function renderBounds(body: Phaser.Physics.Advanced.Body) { - - game.stage.context.fillStyle = 'rgba(0,255,200,0.2)'; - - game.stage.context.fillRect(body.bounds.x, body.bounds.y, body.bounds.width, body.bounds.height); - - } - - function renderCircle(shape) { - - game.stage.context.beginPath(); - game.stage.context.arc(shape.tc.x * 50, shape.tc.y * 50, shape.radius * 50, 0, Math.PI * 2, false); - - if (shape.body.isAwake) - { - game.stage.context.fillStyle = 'rgba(0,255,0, 0.3)'; - } - else - { - game.stage.context.fillStyle = 'rgba(100,100,100, 0.1)'; - } - - game.stage.context.fill(); - game.stage.context.closePath(); - - } - - function drawPolygon(ctx, shape, lineWidth, fillStyle) { - - var verts = shape.tverts; - var body = shape.body; - - ctx.beginPath(); - ctx.moveTo(body.position.x + verts[0].x * 50, body.position.y + verts[0].y * 50); - - for (var i = 0; i < verts.length; i++) { - ctx.lineTo(body.position.x + verts[i].x * 50, body.position.y + verts[i].y * 50); - } - - ctx.lineTo(body.position.x + verts[verts.length - 1].x * 50, body.position.y + verts[verts.length - 1].y * 50); - - ctx.closePath(); - - ctx.fillStyle = fillStyle; - ctx.fill(); - - } - - function render() { - - //game.stage.context.fillStyle = 'rgb(255,255,0)'; - //game.stage.context.fillText('x: ' + t.position.x + ' y: ' + t.position.y, 32, 32); - //game.stage.context.fillText('vx: ' + t.velocity.x + ' vy: ' + t.velocity.y, 32, 64); - //game.stage.context.fillText('x: ' + t.bounds.x + ' y: ' + t.bounds.y, 32, 32); - //game.stage.context.fillText('vx: ' + t.velocity.x + ' vy: ' + t.velocity.y, 32, 64); - - //renderCircle(circle.shapes[0]); - //renderBounds(circle); - - drawPolygon(game.stage.context, walls.shapes[0], 1, 'rgb(0,255,255)'); - //drawPolygon(game.stage.context, walls.shapes[1], 1, 'rgb(0,255,255)'); - - //renderCircle(t.shapes[0]); - drawPolygon(game.stage.context, t.shapes[0], 1, 'rgb(255,255,255)'); - //renderBounds(t); - - } - -})(); diff --git a/wip/phaser clean up/obb vs obb.ts b/wip/phaser clean up/obb vs obb.ts deleted file mode 100644 index 5b22bebf..00000000 --- a/wip/phaser clean up/obb vs obb.ts +++ /dev/null @@ -1,54 +0,0 @@ -/// - -(function () { - - var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render); - - function init() { - - // Using Phasers asset loader we load up a PNG from the assets folder - game.load.image('atari', 'assets/sprites/atari800xl.png'); - game.load.image('card', 'assets/sprites/mana_card.png'); - game.load.start(); - - } - - var atari: Phaser.Sprite; - var card: Phaser.Sprite; - - function create() { - - atari = game.add.sprite(200, 310, 'atari'); - - card = game.add.sprite(500, 300, 'card'); - - atari.input.start(0); - atari.input.enableDrag(); - - card.input.start(0); - card.events.onInputDown.add(rotateIt, this); - - } - - function rotateIt() { - card.rotation += 10; - } - - function update() { - } - - function render() { - - game.stage.context.save(); - - game.stage.context.strokeStyle = 'rgb(255,255,0)'; - game.stage.context.strokeRect(atari.cameraView.x, atari.cameraView.y, atari.cameraView.width, atari.cameraView.height); - - game.stage.context.strokeStyle = 'rgb(255,0,255)'; - game.stage.context.strokeRect(card.cameraView.x, card.cameraView.y, card.cameraView.width, card.cameraView.height); - - game.stage.context.restore(); - - } - -})();