mirror of
https://github.com/wassname/phaser.git
synced 2026-08-03 13:10:25 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86c872803a | ||
|
|
21120c8b62 | ||
|
|
a3b27fbf32 | ||
|
|
c09cff336d |
Binary file not shown.
|
After Width: | Height: | Size: 3.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 531 B |
Binary file not shown.
|
After Width: | Height: | Size: 106 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 120 KiB |
+37
-10
@@ -2,7 +2,7 @@ module.exports = function (grunt) {
|
|||||||
grunt.loadNpmTasks('grunt-typescript');
|
grunt.loadNpmTasks('grunt-typescript');
|
||||||
grunt.loadNpmTasks('grunt-contrib-watch');
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
||||||
grunt.loadNpmTasks('grunt-contrib-copy');
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
||||||
|
|
||||||
grunt.initConfig({
|
grunt.initConfig({
|
||||||
pkg: grunt.file.readJSON('package.json'),
|
pkg: grunt.file.readJSON('package.json'),
|
||||||
typescript: {
|
typescript: {
|
||||||
@@ -14,18 +14,45 @@ module.exports = function (grunt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
copy: {
|
copy: {
|
||||||
main: {
|
main: {
|
||||||
files: [
|
files: [{
|
||||||
{src: 'build/phaser.js', dest: 'Tests/phaser.js'}
|
src: 'build/phaser.js',
|
||||||
]}
|
dest: 'Tests/phaser.js'
|
||||||
},
|
}]
|
||||||
|
},
|
||||||
|
amd: {
|
||||||
|
files: [{
|
||||||
|
src: 'build/phaser.js',
|
||||||
|
dest: 'build/phaser.amd.js'
|
||||||
|
}],
|
||||||
|
options: {
|
||||||
|
processContent: function(content) {
|
||||||
|
var replacement = [
|
||||||
|
'(function (root, factory) {',
|
||||||
|
' if (typeof exports === \'object\') {',
|
||||||
|
' module.exports = factory();',
|
||||||
|
' } else if (typeof define === \'function\' && define.amd) {',
|
||||||
|
' define(factory);',
|
||||||
|
' } else {',
|
||||||
|
' root.Phaser = factory();',
|
||||||
|
' }',
|
||||||
|
'}(this, function () {',
|
||||||
|
content,
|
||||||
|
'return Phaser;',
|
||||||
|
'}));'
|
||||||
|
];
|
||||||
|
return replacement.join('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
watch: {
|
watch: {
|
||||||
files: '**/*.ts',
|
files: '**/*.ts',
|
||||||
tasks: ['typescript', 'copy']
|
tasks: ['typescript', 'copy']
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
grunt.registerTask('default', ['watch']);
|
grunt.registerTask('default', ['watch']);
|
||||||
|
|
||||||
}
|
}
|
||||||
+46
-85
@@ -92,6 +92,17 @@ module Phaser {
|
|||||||
*/
|
*/
|
||||||
public static OVERLAP_BIAS: number = 4;
|
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 Quad used in the separation process to help avoid gc spikes
|
||||||
|
* @type {Quad}
|
||||||
|
*/
|
||||||
|
public static _tempBounds: Quad;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for Line to Line intersection and returns an IntersectResult object containing the results of the intersection.
|
* Checks for Line to Line intersection and returns an IntersectResult object containing the results of the intersection.
|
||||||
@@ -634,10 +645,10 @@ module Phaser {
|
|||||||
* @param tile The Tile to separate
|
* @param tile The Tile to separate
|
||||||
* @returns {boolean} Whether the objects in fact touched and were separated
|
* @returns {boolean} Whether the objects in fact touched and were separated
|
||||||
*/
|
*/
|
||||||
public static separateTile(object:GameObject, tile): bool {
|
public static separateTile(object:GameObject, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool, collideUp: bool, collideDown: bool): bool {
|
||||||
|
|
||||||
var separatedX: bool = Collision.separateTileX(object, tile);
|
var separatedX: bool = Collision.separateTileX(object, x, y, width, height, mass, collideLeft, collideRight);
|
||||||
var separatedY: bool = Collision.separateTileY(object, tile);
|
var separatedY: bool = Collision.separateTileY(object, x, y, width, height, mass, collideUp, collideDown);
|
||||||
|
|
||||||
return separatedX || separatedY;
|
return separatedX || separatedY;
|
||||||
|
|
||||||
@@ -649,37 +660,34 @@ module Phaser {
|
|||||||
* @param tile The Tile to separate
|
* @param tile The Tile to separate
|
||||||
* @returns {boolean} Whether the objects in fact touched and were separated along the X axis.
|
* @returns {boolean} Whether the objects in fact touched and were separated along the X axis.
|
||||||
*/
|
*/
|
||||||
public static separateTileX(object, tile): bool {
|
public static separateTileX(object:GameObject, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool): bool {
|
||||||
|
|
||||||
// Can't separate two immovable objects
|
// Can't separate two immovable objects (tiles are always immovable)
|
||||||
if (object.immovable && tile.immovable)
|
if (object.immovable)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, get the two object deltas
|
// First, get the object delta
|
||||||
var overlap: number = 0;
|
var overlap: number = 0;
|
||||||
var objDelta: number = object.x - object.last.x;
|
var objDelta: number = object.x - object.last.x;
|
||||||
var tileDelta: number = 0;
|
|
||||||
|
|
||||||
if (objDelta != tileDelta)
|
if (objDelta != 0)
|
||||||
{
|
{
|
||||||
// Check if the X hulls actually overlap
|
// Check if the X hulls actually overlap
|
||||||
var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta;
|
var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta;
|
||||||
var tileDeltaAbs: number = (tileDelta > 0) ? tileDelta : -tileDelta;
|
|
||||||
var objBounds: Quad = new Quad(object.x - ((objDelta > 0) ? objDelta : 0), object.last.y, object.width + ((objDelta > 0) ? objDelta : -objDelta), object.height);
|
var objBounds: Quad = new Quad(object.x - ((objDelta > 0) ? objDelta : 0), object.last.y, object.width + ((objDelta > 0) ? objDelta : -objDelta), object.height);
|
||||||
var tileBounds: Quad = new Quad(tile.x - ((tileDelta > 0) ? tileDelta : 0), tile.y, tile.width + ((tileDelta > 0) ? tileDelta : -tileDelta), tile.height);
|
|
||||||
|
|
||||||
if ((objBounds.x + objBounds.width > tileBounds.x) && (objBounds.x < tileBounds.x + tileBounds.width) && (objBounds.y + objBounds.height > tileBounds.y) && (objBounds.y < tileBounds.y + tileBounds.height))
|
if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height))
|
||||||
{
|
{
|
||||||
var maxOverlap: number = objDeltaAbs + tileDeltaAbs + Collision.OVERLAP_BIAS;
|
var maxOverlap: number = objDeltaAbs + Collision.OVERLAP_BIAS;
|
||||||
|
|
||||||
// If they did overlap (and can), figure out by how much and flip the corresponding flags
|
// If they did overlap (and can), figure out by how much and flip the corresponding flags
|
||||||
if (objDelta > tileDelta)
|
if (objDelta > 0)
|
||||||
{
|
{
|
||||||
overlap = object.x + object.width - tile.x;
|
overlap = object.x + object.width - x;
|
||||||
|
|
||||||
if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.RIGHT) || !(tile.allowCollisions & Collision.LEFT))
|
if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.RIGHT) || collideLeft == false)
|
||||||
{
|
{
|
||||||
overlap = 0;
|
overlap = 0;
|
||||||
}
|
}
|
||||||
@@ -688,11 +696,11 @@ module Phaser {
|
|||||||
object.touching |= Collision.RIGHT;
|
object.touching |= Collision.RIGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (objDelta < tileDelta)
|
else if (objDelta < 0)
|
||||||
{
|
{
|
||||||
overlap = object.x - tile.width - tile.x;
|
overlap = object.x - width - x;
|
||||||
|
|
||||||
if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.LEFT) || !(tile.allowCollisions & Collision.RIGHT))
|
if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.LEFT) || collideRight == false)
|
||||||
{
|
{
|
||||||
overlap = 0;
|
overlap = 0;
|
||||||
}
|
}
|
||||||
@@ -709,26 +717,9 @@ module Phaser {
|
|||||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||||
if (overlap != 0)
|
if (overlap != 0)
|
||||||
{
|
{
|
||||||
var objVelocity: number = object.velocity.x;
|
object.x = object.x - overlap;
|
||||||
var tileVelocity: number = 0;
|
object.velocity.x = -(object.velocity.x * object.elasticity);
|
||||||
|
Collision.TILE_OVERLAP = true;
|
||||||
if (!object.immovable && !tile.immovable)
|
|
||||||
{
|
|
||||||
overlap *= 0.5;
|
|
||||||
object.x = object.x - overlap;
|
|
||||||
|
|
||||||
var objNewVelocity: number = Math.sqrt((tileVelocity * tileVelocity * tile.mass) / object.mass) * ((tileVelocity > 0) ? 1 : -1);
|
|
||||||
var tileNewVelocity: number = Math.sqrt((objVelocity * objVelocity * object.mass) / tile.mass) * ((objVelocity > 0) ? 1 : -1);
|
|
||||||
var average: number = (objNewVelocity + tileNewVelocity) * 0.5;
|
|
||||||
objNewVelocity -= average;
|
|
||||||
object.velocity.x = average + objNewVelocity * object.elasticity;
|
|
||||||
}
|
|
||||||
else if (!object.immovable)
|
|
||||||
{
|
|
||||||
object.x = object.x - overlap;
|
|
||||||
object.velocity.x = tileVelocity - objVelocity * object.elasticity;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -744,57 +735,53 @@ module Phaser {
|
|||||||
* @param tile The second 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.
|
* @returns {boolean} Whether the objects in fact touched and were separated along the Y axis.
|
||||||
*/
|
*/
|
||||||
public static separateTileY(object, tile): bool {
|
public static separateTileY(object: GameObject, x: number, y: number, width: number, height: number, mass: number, collideUp: bool, collideDown: bool): bool {
|
||||||
|
|
||||||
// Can't separate two immovable objects
|
// Can't separate two immovable objects (tiles are always immovable)
|
||||||
if (object.immovable && tile.immovable) {
|
if (object.immovable)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, get the two object deltas
|
// First, get the two object deltas
|
||||||
var overlap: number = 0;
|
var overlap: number = 0;
|
||||||
var objDelta: number = object.y - object.last.y;
|
var objDelta: number = object.y - object.last.y;
|
||||||
var tileDelta: number = 0;
|
|
||||||
|
|
||||||
if (objDelta != tileDelta)
|
if (objDelta != 0)
|
||||||
{
|
{
|
||||||
// Check if the Y hulls actually overlap
|
// Check if the Y hulls actually overlap
|
||||||
var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta;
|
var objDeltaAbs: number = (objDelta > 0) ? objDelta : -objDelta;
|
||||||
var tileDeltaAbs: number = (tileDelta > 0) ? tileDelta : -tileDelta;
|
|
||||||
var objBounds: Quad = new Quad(object.x, object.y - ((objDelta > 0) ? objDelta : 0), object.width, object.height + objDeltaAbs);
|
var objBounds: Quad = new Quad(object.x, object.y - ((objDelta > 0) ? objDelta : 0), object.width, object.height + objDeltaAbs);
|
||||||
var tileBounds: Quad = new Quad(tile.x, tile.y - ((tileDelta > 0) ? tileDelta : 0), tile.width, tile.height + tileDeltaAbs);
|
|
||||||
|
|
||||||
if ((objBounds.x + objBounds.width > tileBounds.x) && (objBounds.x < tileBounds.x + tileBounds.width) && (objBounds.y + objBounds.height > tileBounds.y) && (objBounds.y < tileBounds.y + tileBounds.height))
|
if ((objBounds.x + objBounds.width > x) && (objBounds.x < x + width) && (objBounds.y + objBounds.height > y) && (objBounds.y < y + height))
|
||||||
{
|
{
|
||||||
var maxOverlap: number = objDeltaAbs + tileDeltaAbs + Collision.OVERLAP_BIAS;
|
var maxOverlap: number = objDeltaAbs + Collision.OVERLAP_BIAS;
|
||||||
|
|
||||||
// If they did overlap (and can), figure out by how much and flip the corresponding flags
|
// If they did overlap (and can), figure out by how much and flip the corresponding flags
|
||||||
if (objDelta > tileDelta)
|
if (objDelta > 0)
|
||||||
{
|
{
|
||||||
overlap = object.y + object.height - tile.y;
|
overlap = object.y + object.height - y;
|
||||||
|
|
||||||
if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.DOWN) || !(tile.allowCollisions & Collision.UP))
|
if ((overlap > maxOverlap) || !(object.allowCollisions & Collision.DOWN) || collideUp == false)
|
||||||
{
|
{
|
||||||
overlap = 0;
|
overlap = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
object.touching |= Collision.DOWN;
|
object.touching |= Collision.DOWN;
|
||||||
//tile.touching |= Collision.UP;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (objDelta < tileDelta)
|
else if (objDelta < 0)
|
||||||
{
|
{
|
||||||
overlap = object.y - tile.height - tile.y;
|
overlap = object.y - height - y;
|
||||||
|
|
||||||
if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.UP) || !(tile.allowCollisions & Collision.DOWN))
|
if ((-overlap > maxOverlap) || !(object.allowCollisions & Collision.UP) || collideDown == false)
|
||||||
{
|
{
|
||||||
overlap = 0;
|
overlap = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
object.touching |= Collision.UP;
|
object.touching |= Collision.UP;
|
||||||
//tile.touching |= Collision.DOWN;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -805,35 +792,9 @@ module Phaser {
|
|||||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||||
if (overlap != 0)
|
if (overlap != 0)
|
||||||
{
|
{
|
||||||
var objVelocity: number = object.velocity.y;
|
object.y = object.y - overlap;
|
||||||
var tileVelocity: number = 0;
|
object.velocity.y = -(object.velocity.y * object.elasticity);
|
||||||
|
Collision.TILE_OVERLAP = true;
|
||||||
if (!object.immovable && !tile.immovable)
|
|
||||||
{
|
|
||||||
overlap *= 0.5;
|
|
||||||
object.y = object.y - overlap;
|
|
||||||
//tile.y += overlap;
|
|
||||||
|
|
||||||
var objNewVelocity: number = Math.sqrt((tileVelocity * tileVelocity * tile.mass) / object.mass) * ((tileVelocity > 0) ? 1 : -1);
|
|
||||||
var tileNewVelocity: number = Math.sqrt((objVelocity * objVelocity * object.mass) / tile.mass) * ((objVelocity > 0) ? 1 : -1);
|
|
||||||
var average: number = (objNewVelocity + tileNewVelocity) * 0.5;
|
|
||||||
objNewVelocity -= average;
|
|
||||||
//tileNewVelocity -= average;
|
|
||||||
object.velocity.y = average + objNewVelocity * object.elasticity;
|
|
||||||
//tile.velocity.y = average + tileNewVelocity * tile.elasticity;
|
|
||||||
}
|
|
||||||
else if (!object.immovable)
|
|
||||||
{
|
|
||||||
//console.log('y sep', overlap, object.y);
|
|
||||||
object.y = object.y - overlap;
|
|
||||||
object.velocity.y = tileVelocity - objVelocity * object.elasticity;
|
|
||||||
// This is special case code that handles things like horizontal moving platforms you can ride
|
|
||||||
if (tile.active && tile.moves && (objDelta > tileDelta))
|
|
||||||
{
|
|
||||||
//object.x += tile.x - tile.x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
+4
-2
@@ -80,7 +80,6 @@ module Phaser {
|
|||||||
public onRenderCallback = null;
|
public onRenderCallback = null;
|
||||||
public onPausedCallback = null;
|
public onPausedCallback = null;
|
||||||
|
|
||||||
public camera: Camera; // quick reference to the default created camera, access the rest via .world
|
|
||||||
public cache: Cache;
|
public cache: Cache;
|
||||||
public collision: Collision;
|
public collision: Collision;
|
||||||
public input: Input;
|
public input: Input;
|
||||||
@@ -330,7 +329,6 @@ module Phaser {
|
|||||||
this.onUpdateCallback = null;
|
this.onUpdateCallback = null;
|
||||||
this.onRenderCallback = null;
|
this.onRenderCallback = null;
|
||||||
this.onPausedCallback = null;
|
this.onPausedCallback = null;
|
||||||
this.camera = null;
|
|
||||||
this.cache = null;
|
this.cache = null;
|
||||||
this.input = null;
|
this.input = null;
|
||||||
this.loader = null;
|
this.loader = null;
|
||||||
@@ -422,6 +420,10 @@ module Phaser {
|
|||||||
return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate);
|
return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get camera(): Camera {
|
||||||
|
return this.world.cameras.current;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+3
-3
@@ -474,7 +474,7 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public forEachAlive(callback, recursive: bool = false) {
|
public forEachAlive(context, callback, recursive: bool = false) {
|
||||||
|
|
||||||
var basic;
|
var basic;
|
||||||
var i: number = 0;
|
var i: number = 0;
|
||||||
@@ -487,11 +487,11 @@ module Phaser {
|
|||||||
{
|
{
|
||||||
if (recursive && (basic.isGroup == true))
|
if (recursive && (basic.isGroup == true))
|
||||||
{
|
{
|
||||||
basic.forEachAlive(callback, true);
|
basic.forEachAlive(context, callback, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
callback.call(this, basic);
|
callback.call(context, basic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Phaser
|
* Phaser
|
||||||
*
|
*
|
||||||
* v0.9.4 - April 24th 2013
|
* v0.9.4 - April 28th 2013
|
||||||
*
|
*
|
||||||
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
||||||
*
|
*
|
||||||
|
|||||||
+9
-9
@@ -16,9 +16,9 @@ module Phaser {
|
|||||||
|
|
||||||
this._game = game;
|
this._game = game;
|
||||||
|
|
||||||
this._cameras = new CameraManager(this._game, 0, 0, width, height);
|
this.cameras = new CameraManager(this._game, 0, 0, width, height);
|
||||||
|
|
||||||
this._game.camera = this._cameras.current;
|
this._game.camera = this.cameras.current;
|
||||||
|
|
||||||
this.group = new Group(this._game, 0);
|
this.group = new Group(this._game, 0);
|
||||||
|
|
||||||
@@ -29,8 +29,8 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _game: Game;
|
private _game: Game;
|
||||||
private _cameras: CameraManager;
|
|
||||||
|
|
||||||
|
public cameras: CameraManager;
|
||||||
public group: Group;
|
public group: Group;
|
||||||
public bounds: Rectangle;
|
public bounds: Rectangle;
|
||||||
public worldDivisions: number;
|
public worldDivisions: number;
|
||||||
@@ -41,14 +41,14 @@ module Phaser {
|
|||||||
this.group.update();
|
this.group.update();
|
||||||
this.group.postUpdate();
|
this.group.postUpdate();
|
||||||
|
|
||||||
this._cameras.update();
|
this.cameras.update();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
|
|
||||||
// Unlike in flixel our render process is camera driven, not group driven
|
// Unlike in flixel our render process is camera driven, not group driven
|
||||||
this._cameras.render();
|
this.cameras.render();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ module Phaser {
|
|||||||
|
|
||||||
this.group.destroy();
|
this.group.destroy();
|
||||||
|
|
||||||
this._cameras.destroy();
|
this.cameras.destroy();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,15 +109,15 @@ module Phaser {
|
|||||||
// Cameras
|
// Cameras
|
||||||
|
|
||||||
public createCamera(x: number, y: number, width: number, height: number): Camera {
|
public createCamera(x: number, y: number, width: number, height: number): Camera {
|
||||||
return this._cameras.addCamera(x, y, width, height);
|
return this.cameras.addCamera(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeCamera(id: number): bool {
|
public removeCamera(id: number): bool {
|
||||||
return this._cameras.removeCamera(id);
|
return this.cameras.removeCamera(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAllCameras(): Camera[] {
|
public getAllCameras(): Camera[] {
|
||||||
return this._cameras.getAll();
|
return this.cameras.getAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Game Objects
|
// Game Objects
|
||||||
|
|||||||
@@ -27,13 +27,13 @@ module Phaser {
|
|||||||
this.y = Y;
|
this.y = Y;
|
||||||
this.width = 0;
|
this.width = 0;
|
||||||
this.height = 0;
|
this.height = 0;
|
||||||
this.minParticleSpeed = new Point(-100, -100);
|
this.minParticleSpeed = new MicroPoint(-100, -100);
|
||||||
this.maxParticleSpeed = new Point(100, 100);
|
this.maxParticleSpeed = new MicroPoint(100, 100);
|
||||||
this.minRotation = -360;
|
this.minRotation = -360;
|
||||||
this.maxRotation = 360;
|
this.maxRotation = 360;
|
||||||
this.gravity = 0;
|
this.gravity = 0;
|
||||||
this.particleClass = null;
|
this.particleClass = null;
|
||||||
this.particleDrag = new Point();
|
this.particleDrag = new MicroPoint();
|
||||||
this.frequency = 0.1;
|
this.frequency = 0.1;
|
||||||
this.lifespan = 3;
|
this.lifespan = 3;
|
||||||
this.bounce = 0;
|
this.bounce = 0;
|
||||||
@@ -41,7 +41,7 @@ module Phaser {
|
|||||||
this._counter = 0;
|
this._counter = 0;
|
||||||
this._explode = true;
|
this._explode = true;
|
||||||
this.on = false;
|
this.on = false;
|
||||||
this._point = new Point();
|
this._point = new MicroPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,18 +68,18 @@ module Phaser {
|
|||||||
* The minimum possible velocity of a particle.
|
* The minimum possible velocity of a particle.
|
||||||
* The default value is (-100,-100).
|
* The default value is (-100,-100).
|
||||||
*/
|
*/
|
||||||
public minParticleSpeed: Point;
|
public minParticleSpeed: MicroPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum possible velocity of a particle.
|
* The maximum possible velocity of a particle.
|
||||||
* The default value is (100,100).
|
* The default value is (100,100).
|
||||||
*/
|
*/
|
||||||
public maxParticleSpeed: Point;
|
public maxParticleSpeed: MicroPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The X and Y drag component of particles launched from the emitter.
|
* The X and Y drag component of particles launched from the emitter.
|
||||||
*/
|
*/
|
||||||
public particleDrag: Point;
|
public particleDrag: MicroPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The minimum possible angular velocity of a particle. The default value is -360.
|
* The minimum possible angular velocity of a particle. The default value is -360.
|
||||||
@@ -149,7 +149,7 @@ module Phaser {
|
|||||||
/**
|
/**
|
||||||
* Internal point object, handy for reusing for memory mgmt purposes.
|
* Internal point object, handy for reusing for memory mgmt purposes.
|
||||||
*/
|
*/
|
||||||
private _point: Point;
|
private _point: MicroPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean up memory.
|
* Clean up memory.
|
||||||
@@ -174,7 +174,7 @@ module Phaser {
|
|||||||
*
|
*
|
||||||
* @return This Emitter instance (nice for chaining stuff together, if you're into that).
|
* @return This Emitter instance (nice for chaining stuff together, if you're into that).
|
||||||
*/
|
*/
|
||||||
public makeParticles(Graphics, Quantity: number = 50, BakedRotations: number = 16, Multiple: bool = false, Collide: number = 0.8): Emitter {
|
public makeParticles(Graphics, Quantity: number = 50, BakedRotations: number = 16, Multiple: bool = false, Collide: number = 0): Emitter {
|
||||||
|
|
||||||
this.maxSize = Quantity;
|
this.maxSize = Quantity;
|
||||||
|
|
||||||
@@ -236,6 +236,7 @@ module Phaser {
|
|||||||
|
|
||||||
if (Collide > 0)
|
if (Collide > 0)
|
||||||
{
|
{
|
||||||
|
particle.allowCollisions = Collision.ANY;
|
||||||
particle.width *= Collide;
|
particle.width *= Collide;
|
||||||
particle.height *= Collide;
|
particle.height *= Collide;
|
||||||
//particle.centerOffsets();
|
//particle.centerOffsets();
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ module Phaser {
|
|||||||
this.last = new MicroPoint(x, y);
|
this.last = new MicroPoint(x, y);
|
||||||
this.origin = new MicroPoint(this.bounds.halfWidth, this.bounds.halfHeight);
|
this.origin = new MicroPoint(this.bounds.halfWidth, this.bounds.halfHeight);
|
||||||
this.align = GameObject.ALIGN_TOP_LEFT;
|
this.align = GameObject.ALIGN_TOP_LEFT;
|
||||||
this.mass = 1.0;
|
this.mass = 1;
|
||||||
this.elasticity = 0.0;
|
this.elasticity = 0;
|
||||||
this.health = 1;
|
this.health = 1;
|
||||||
this.immovable = false;
|
this.immovable = false;
|
||||||
this.moves = true;
|
this.moves = true;
|
||||||
@@ -52,7 +52,7 @@ module Phaser {
|
|||||||
this.maxAngular = 10000;
|
this.maxAngular = 10000;
|
||||||
|
|
||||||
this.cameraBlacklist = [];
|
this.cameraBlacklist = [];
|
||||||
this.scrollFactor = new MicroPoint(1.0, 1.0);
|
this.scrollFactor = new MicroPoint(1, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,17 +245,6 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if (typeof ObjectOrGroup === 'Tilemap')
|
|
||||||
{
|
|
||||||
//Since tilemap's have to be the caller, not the target, to do proper tile-based collisions,
|
|
||||||
// we redirect the call to the tilemap overlap here.
|
|
||||||
return ObjectOrGroup.overlaps(this, InScreenSpace, Camera);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//var object: GameObject = ObjectOrGroup;
|
|
||||||
|
|
||||||
if (!InScreenSpace)
|
if (!InScreenSpace)
|
||||||
{
|
{
|
||||||
return (ObjectOrGroup.x + ObjectOrGroup.width > this.x) && (ObjectOrGroup.x < this.x + this.width) &&
|
return (ObjectOrGroup.x + ObjectOrGroup.width > this.x) && (ObjectOrGroup.x < this.x + this.width) &&
|
||||||
@@ -308,20 +297,6 @@ module Phaser {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if (typeof ObjectOrGroup === 'Tilemap')
|
|
||||||
{
|
|
||||||
//Since tilemap's have to be the caller, not the target, to do proper tile-based collisions,
|
|
||||||
// we redirect the call to the tilemap overlap here.
|
|
||||||
//However, since this is overlapsAt(), we also have to invent the appropriate position for the tilemap.
|
|
||||||
//So we calculate the offset between the player and the requested position, and subtract that from the tilemap.
|
|
||||||
var tilemap: Tilemap = ObjectOrGroup;
|
|
||||||
return tilemap.overlapsAt(tilemap.x - (X - this.x), tilemap.y - (Y - this.y), this, InScreenSpace, Camera);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//var object: GameObject = ObjectOrGroup;
|
|
||||||
|
|
||||||
if (!InScreenSpace)
|
if (!InScreenSpace)
|
||||||
{
|
{
|
||||||
return (ObjectOrGroup.x + ObjectOrGroup.width > X) && (ObjectOrGroup.x < X + this.width) &&
|
return (ObjectOrGroup.x + ObjectOrGroup.width > X) && (ObjectOrGroup.x < X + this.width) &&
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ module Phaser {
|
|||||||
|
|
||||||
this.lifespan = 0;
|
this.lifespan = 0;
|
||||||
this.friction = 500;
|
this.friction = 500;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,6 +44,7 @@ module Phaser {
|
|||||||
* be dead yet, and then has some special bounce behavior if there is some gravity on it.
|
* be dead yet, and then has some special bounce behavior if there is some gravity on it.
|
||||||
*/
|
*/
|
||||||
public update() {
|
public update() {
|
||||||
|
|
||||||
//lifespan behavior
|
//lifespan behavior
|
||||||
if (this.lifespan <= 0)
|
if (this.lifespan <= 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ module Phaser {
|
|||||||
public tiles : Tile[];
|
public tiles : Tile[];
|
||||||
public layers : TilemapLayer[];
|
public layers : TilemapLayer[];
|
||||||
public currentLayer: TilemapLayer;
|
public currentLayer: TilemapLayer;
|
||||||
|
public collisionLayer: TilemapLayer;
|
||||||
public mapFormat: number;
|
public mapFormat: number;
|
||||||
|
|
||||||
public update() {
|
public update() {
|
||||||
@@ -90,6 +91,7 @@ module Phaser {
|
|||||||
var tileQuantity = layer.parseTileOffsets();
|
var tileQuantity = layer.parseTileOffsets();
|
||||||
|
|
||||||
this.currentLayer = layer;
|
this.currentLayer = layer;
|
||||||
|
this.collisionLayer = layer;
|
||||||
|
|
||||||
this.layers.push(layer);
|
this.layers.push(layer);
|
||||||
|
|
||||||
@@ -139,6 +141,7 @@ module Phaser {
|
|||||||
var tileQuantity = layer.parseTileOffsets();
|
var tileQuantity = layer.parseTileOffsets();
|
||||||
|
|
||||||
this.currentLayer = layer;
|
this.currentLayer = layer;
|
||||||
|
this.collisionLayer = layer;
|
||||||
|
|
||||||
this.layers.push(layer);
|
this.layers.push(layer);
|
||||||
|
|
||||||
@@ -167,20 +170,20 @@ module Phaser {
|
|||||||
|
|
||||||
// Tile Collision
|
// Tile Collision
|
||||||
|
|
||||||
public setCollisionRange(start: number, end: number, collision?:number = Collision.ANY) {
|
public setCollisionRange(start: number, end: number, collision?:number = Collision.ANY, resetCollisions: bool = false) {
|
||||||
|
|
||||||
for (var i = start; i < end; i++)
|
for (var i = start; i < end; i++)
|
||||||
{
|
{
|
||||||
this.tiles[i].allowCollisions = collision;
|
this.tiles[i].setCollision(collision, resetCollisions);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setCollisionByIndex(values:number[], collision?:number = Collision.ANY) {
|
public setCollisionByIndex(values:number[], collision?:number = Collision.ANY, resetCollisions: bool = false) {
|
||||||
|
|
||||||
for (var i = 0; i < values.length; i++)
|
for (var i = 0; i < values.length; i++)
|
||||||
{
|
{
|
||||||
this.tiles[values[i]].allowCollisions = collision;
|
this.tiles[values[i]].setCollision(collision, resetCollisions);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -222,21 +225,32 @@ module Phaser {
|
|||||||
// Group?
|
// Group?
|
||||||
if (objectOrGroup.isGroup == false)
|
if (objectOrGroup.isGroup == false)
|
||||||
{
|
{
|
||||||
if (objectOrGroup.exists && objectOrGroup.allowCollisions != Collision.NONE)
|
return this.collideGameObject(objectOrGroup);
|
||||||
{
|
|
||||||
this.currentLayer.getTileOverlaps(objectOrGroup);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// todo
|
objectOrGroup.forEachAlive(this, this.collideGameObject, true);
|
||||||
objectOrGroup.forEachAlive(this.currentLayer.getTileOverlaps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public collideGameObject(object: GameObject): bool {
|
||||||
|
|
||||||
|
if (object == this) { return false; }
|
||||||
|
|
||||||
|
if (object.immovable == false && object.exists == true && object.allowCollisions != Collision.NONE)
|
||||||
|
{
|
||||||
|
return this.collisionLayer.getTileOverlaps(object);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set current layer
|
// Set current layer
|
||||||
// Set layer order?
|
// Set layer order?
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ module Phaser {
|
|||||||
**/
|
**/
|
||||||
get isEmpty(): bool {
|
get isEmpty(): bool {
|
||||||
|
|
||||||
if (this._diameter < 1)
|
if (this._diameter <= 0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,14 @@ module Phaser {
|
|||||||
return this.y + this.height;
|
return this.y + this.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get halfWidth(): number {
|
||||||
|
return this.width / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get halfHeight(): number {
|
||||||
|
return this.height / 2;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether the object specified intersects (overlaps) with this Quad object.
|
* Determines whether the object specified intersects (overlaps) with this Quad object.
|
||||||
* This method checks the x, y, width, and height properties of the specified Quad object to see if it intersects with this Quad object.
|
* This method checks the x, y, width, and height properties of the specified Quad object to see if it intersects with this Quad object.
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Phaser
|
* Phaser
|
||||||
*
|
*
|
||||||
* v0.9.4 - April 24th 2013
|
* v0.9.4 - April 28th 2013
|
||||||
*
|
*
|
||||||
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
||||||
*
|
*
|
||||||
|
|||||||
+24
-10
@@ -60,7 +60,7 @@ module Phaser {
|
|||||||
private _fxShakeIntensity: number = 0;
|
private _fxShakeIntensity: number = 0;
|
||||||
private _fxShakeDuration: number = 0;
|
private _fxShakeDuration: number = 0;
|
||||||
private _fxShakeComplete = null;
|
private _fxShakeComplete = null;
|
||||||
private _fxShakeOffset: Point = new Point(0, 0);
|
private _fxShakeOffset: MicroPoint = new MicroPoint(0, 0);
|
||||||
private _fxShakeDirection: number = 0;
|
private _fxShakeDirection: number = 0;
|
||||||
private _fxShakePrevX: number = 0;
|
private _fxShakePrevX: number = 0;
|
||||||
private _fxShakePrevY: number = 0;
|
private _fxShakePrevY: number = 0;
|
||||||
@@ -77,8 +77,8 @@ module Phaser {
|
|||||||
public ID: number;
|
public ID: number;
|
||||||
public worldView: Rectangle;
|
public worldView: Rectangle;
|
||||||
public totalSpritesRendered: number;
|
public totalSpritesRendered: number;
|
||||||
public scale: Point = new Point(1, 1);
|
public scale: MicroPoint = new MicroPoint(1, 1);
|
||||||
public scroll: Point = new Point(0, 0);
|
public scroll: MicroPoint = new MicroPoint(0, 0);
|
||||||
public bounds: Rectangle = null;
|
public bounds: Rectangle = null;
|
||||||
public deadzone: Rectangle = null;
|
public deadzone: Rectangle = null;
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ module Phaser {
|
|||||||
public showShadow: bool = false;
|
public showShadow: bool = false;
|
||||||
public shadowColor: string = 'rgb(0,0,0)';
|
public shadowColor: string = 'rgb(0,0,0)';
|
||||||
public shadowBlur: number = 10;
|
public shadowBlur: number = 10;
|
||||||
public shadowOffset: Point = new Point(4, 4);
|
public shadowOffset: MicroPoint = new MicroPoint(4, 4);
|
||||||
|
|
||||||
public visible: bool = true;
|
public visible: bool = true;
|
||||||
public alpha: number = 1;
|
public alpha: number = 1;
|
||||||
@@ -221,6 +221,7 @@ module Phaser {
|
|||||||
public follow(target: Sprite, style?: number = Camera.STYLE_LOCKON) {
|
public follow(target: Sprite, style?: number = Camera.STYLE_LOCKON) {
|
||||||
|
|
||||||
this._target = target;
|
this._target = target;
|
||||||
|
|
||||||
var helper: number;
|
var helper: number;
|
||||||
|
|
||||||
switch (style)
|
switch (style)
|
||||||
@@ -256,7 +257,7 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public focusOn(point: Point) {
|
public focusOn(point) {
|
||||||
|
|
||||||
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
|
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
|
||||||
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
|
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
|
||||||
@@ -282,7 +283,7 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.bounds.setTo(x, y, width, height);
|
this.bounds.setTo(x, y, width, height);
|
||||||
this.worldView.setTo(x, y, width, height);
|
|
||||||
this.scroll.setTo(0, 0);
|
this.scroll.setTo(0, 0);
|
||||||
|
|
||||||
this.update();
|
this.update();
|
||||||
@@ -333,7 +334,7 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we didn't go outside the camera's bounds
|
// Make sure we didn't go outside the cameras bounds
|
||||||
if (this.bounds !== null)
|
if (this.bounds !== null)
|
||||||
{
|
{
|
||||||
if (this.scroll.x < this.bounds.left)
|
if (this.scroll.x < this.bounds.left)
|
||||||
@@ -360,6 +361,8 @@ module Phaser {
|
|||||||
this.worldView.x = this.scroll.x;
|
this.worldView.x = this.scroll.x;
|
||||||
this.worldView.y = this.scroll.y;
|
this.worldView.y = this.scroll.y;
|
||||||
|
|
||||||
|
//console.log(this.worldView.width, this.worldView.height);
|
||||||
|
|
||||||
// Input values
|
// Input values
|
||||||
this.inputX = this.worldView.x + this._game.input.x;
|
this.inputX = this.worldView.x + this._game.input.x;
|
||||||
this.inputY = this.worldView.y + this._game.input.y;
|
this.inputY = this.worldView.y + this._game.input.y;
|
||||||
@@ -494,7 +497,6 @@ module Phaser {
|
|||||||
this._game.stage.context.translate(-(this._sx + this.worldView.halfWidth), -(this._sy + this.worldView.halfHeight));
|
this._game.stage.context.translate(-(this._sx + this.worldView.halfWidth), -(this._sy + this.worldView.halfHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
if (this.opaque == true)
|
if (this.opaque == true)
|
||||||
{
|
{
|
||||||
@@ -560,7 +562,6 @@ module Phaser {
|
|||||||
if (this._rotation !== 0 || this._clip)
|
if (this._rotation !== 0 || this._clip)
|
||||||
{
|
{
|
||||||
this._game.stage.context.translate(0, 0);
|
this._game.stage.context.translate(0, 0);
|
||||||
//this._game.stage.context.restore();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// maybe just do this every frame regardless?
|
// maybe just do this every frame regardless?
|
||||||
@@ -603,9 +604,10 @@ module Phaser {
|
|||||||
|
|
||||||
this.worldView.width = width;
|
this.worldView.width = width;
|
||||||
this.worldView.height = height;
|
this.worldView.height = height;
|
||||||
|
|
||||||
this.checkClip();
|
this.checkClip();
|
||||||
|
|
||||||
|
//console.log('Camera setSize', width, height);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||||
@@ -645,6 +647,12 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public set width(value: number) {
|
public set width(value: number) {
|
||||||
|
|
||||||
|
if (value > this._game.stage.width)
|
||||||
|
{
|
||||||
|
value = this._game.stage.width;
|
||||||
|
}
|
||||||
|
|
||||||
this.worldView.width = value;
|
this.worldView.width = value;
|
||||||
this.checkClip();
|
this.checkClip();
|
||||||
}
|
}
|
||||||
@@ -654,6 +662,12 @@ module Phaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public set height(value: number) {
|
public set height(value: number) {
|
||||||
|
|
||||||
|
if (value > this._game.stage.height)
|
||||||
|
{
|
||||||
|
value = this._game.stage.height;
|
||||||
|
}
|
||||||
|
|
||||||
this.worldView.height = value;
|
this.worldView.height = value;
|
||||||
this.checkClip();
|
this.checkClip();
|
||||||
}
|
}
|
||||||
|
|||||||
+56
-1
@@ -27,12 +27,17 @@ module Phaser {
|
|||||||
// You can give this Tile a friendly name to help with debugging. Never used internally.
|
// You can give this Tile a friendly name to help with debugging. Never used internally.
|
||||||
public name: string;
|
public name: string;
|
||||||
|
|
||||||
|
public mass: number = 1.0;
|
||||||
public width: number;
|
public width: number;
|
||||||
|
|
||||||
public height: number;
|
public height: number;
|
||||||
|
|
||||||
public allowCollisions: number;
|
public allowCollisions: number;
|
||||||
|
|
||||||
|
public collideLeft: bool = false;
|
||||||
|
public collideRight: bool = false;
|
||||||
|
public collideUp: bool = false;
|
||||||
|
public collideDown: bool = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A reference to the tilemap this tile object belongs to.
|
* A reference to the tilemap this tile object belongs to.
|
||||||
*/
|
*/
|
||||||
@@ -54,6 +59,56 @@ module Phaser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setCollision(collision: number, resetCollisions: bool) {
|
||||||
|
|
||||||
|
if (resetCollisions)
|
||||||
|
{
|
||||||
|
this.resetCollision();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.allowCollisions = collision;
|
||||||
|
|
||||||
|
if (collision & Collision.ANY)
|
||||||
|
{
|
||||||
|
this.collideLeft = true;
|
||||||
|
this.collideRight = true;
|
||||||
|
this.collideUp = true;
|
||||||
|
this.collideDown = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (collision & Collision.LEFT || collision & Collision.WALL)
|
||||||
|
{
|
||||||
|
this.collideLeft = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (collision & Collision.RIGHT || collision & Collision.WALL)
|
||||||
|
{
|
||||||
|
this.collideRight = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (collision & Collision.UP || collision & Collision.CEILING)
|
||||||
|
{
|
||||||
|
this.collideUp = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (collision & Collision.DOWN || collision & Collision.CEILING)
|
||||||
|
{
|
||||||
|
this.collideDown = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public resetCollision() {
|
||||||
|
|
||||||
|
this.allowCollisions = Collision.NONE;
|
||||||
|
this.collideLeft = false;
|
||||||
|
this.collideRight = false;
|
||||||
|
this.collideUp = false;
|
||||||
|
this.collideDown = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a string representation of this object.
|
* Returns a string representation of this object.
|
||||||
* @method toString
|
* @method toString
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ module Phaser {
|
|||||||
private _oldCameraY: number = 0;
|
private _oldCameraY: number = 0;
|
||||||
private _columnData;
|
private _columnData;
|
||||||
|
|
||||||
|
private _tempTileX: number;
|
||||||
|
private _tempTileY: number;
|
||||||
|
private _tempTileW: number;
|
||||||
|
private _tempTileH: number;
|
||||||
|
|
||||||
public name: string;
|
public name: string;
|
||||||
public alpha: number = 1;
|
public alpha: number = 1;
|
||||||
public exists: bool = true;
|
public exists: bool = true;
|
||||||
@@ -78,84 +83,67 @@ module Phaser {
|
|||||||
|
|
||||||
public getTileOverlaps(object: GameObject) {
|
public getTileOverlaps(object: GameObject) {
|
||||||
|
|
||||||
//var result: bool = false;
|
// If the object is outside of the world coordinates then abort the check (tilemap has to exist within world bounds)
|
||||||
//var x: number = object.x;
|
if (object.bounds.x < 0 || object.bounds.x > this.widthInPixels || object.bounds.y < 0 || object.bounds.bottom > this.heightInPixels)
|
||||||
//var y: number = object.y;
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// What tiles do we need to check against?
|
// What tiles do we need to check against?
|
||||||
var mapX:number = this._game.math.snapToFloor(object.bounds.x, this.tileWidth);
|
this._tempTileX = this._game.math.snapToFloor(object.bounds.x, this.tileWidth) / this.tileWidth;
|
||||||
var mapY:number = this._game.math.snapToFloor(object.bounds.y, this.tileHeight);
|
this._tempTileY = this._game.math.snapToFloor(object.bounds.y, this.tileHeight) / this.tileHeight;
|
||||||
var mapW:number = this._game.math.snapToCeil(object.bounds.width, this.tileWidth) + this.tileWidth;
|
this._tempTileW = (this._game.math.snapToCeil(object.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth;
|
||||||
var mapH:number = this._game.math.snapToCeil(object.bounds.height, this.tileHeight) + this.tileHeight;
|
this._tempTileH = (this._game.math.snapToCeil(object.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight;
|
||||||
|
|
||||||
var tileX = mapX / this.tileWidth;
|
|
||||||
var tileY = mapY / this.tileHeight;
|
|
||||||
var tileW = mapW / this.tileWidth;
|
|
||||||
var tileH = mapH / this.tileHeight;
|
|
||||||
|
|
||||||
if (tileX < 0)
|
|
||||||
{
|
|
||||||
tileX = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tileY < 0)
|
|
||||||
{
|
|
||||||
tileY = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tileW > this.widthInTiles)
|
|
||||||
{
|
|
||||||
tileW = this.widthInTiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tileH > this.heightInTiles)
|
|
||||||
{
|
|
||||||
tileH = this.heightInTiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop through the tiles we've got and check overlaps accordingly
|
// Loop through the tiles we've got and check overlaps accordingly
|
||||||
var tiles = this.getTileBlock(tileX, tileY, tileW, tileH);
|
var tiles = this.getTileBlock(this._tempTileX, this._tempTileY, this._tempTileW, this._tempTileH);
|
||||||
|
|
||||||
var result = [];
|
Collision.TILE_OVERLAP = false;
|
||||||
var tempBounds = new Quad();
|
|
||||||
|
|
||||||
for (var r = 0; r < tiles.length; r++)
|
for (var r = 0; r < tiles.length; r++)
|
||||||
{
|
{
|
||||||
if (tiles[r].tile.allowCollisions != Collision.NONE)
|
if (tiles[r].tile.allowCollisions != Collision.NONE)
|
||||||
{
|
{
|
||||||
tempBounds.setTo(tiles[r].x * this.tileWidth, tiles[r].y * this.tileHeight, this.tileWidth, this.tileHeight);
|
Collision.separateTile(object, tiles[r].x * this.tileWidth, tiles[r].y * this.tileHeight, this.tileWidth, this.tileHeight, tiles[r].tile.mass, tiles[r].tile.collideLeft, tiles[r].tile.collideRight, tiles[r].tile.collideUp, tiles[r].tile.collideDown);
|
||||||
|
|
||||||
if (tempBounds.intersects(object.bounds))
|
|
||||||
{
|
|
||||||
result.push(Collision.separateTile(object, { x: tempBounds.x, y: tempBounds.y, width: tempBounds.width, height: tempBounds.height, mass: 1.0, immovable: true, allowCollisions: Collision.ANY }));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result.push(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result.push(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//return { x: mapX, y: mapY, w: mapW, h: mapH, collision: result };
|
return Collision.TILE_OVERLAP;
|
||||||
return { x: tileX, y: tileY, w: tileW, h: tileH, collision: result };
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//public checkTileOverlap(object:GameObject,
|
|
||||||
|
|
||||||
public getTileBlock(x: number, y: number, width: number, height: number) {
|
public getTileBlock(x: number, y: number, width: number, height: number) {
|
||||||
|
|
||||||
|
if (x < 0)
|
||||||
|
{
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y < 0)
|
||||||
|
{
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (width > this.widthInTiles)
|
||||||
|
{
|
||||||
|
width = this.widthInTiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (height > this.heightInTiles)
|
||||||
|
{
|
||||||
|
height = this.heightInTiles;
|
||||||
|
}
|
||||||
|
|
||||||
var output = [];
|
var output = [];
|
||||||
|
|
||||||
for (var ty = y; ty < y + height; ty++)
|
for (var ty = y; ty < y + height; ty++)
|
||||||
{
|
{
|
||||||
for (var tx = x; tx < x + width; tx++)
|
for (var tx = x; tx < x + width; tx++)
|
||||||
{
|
{
|
||||||
output.push({ x: tx, y: ty, tile: this._parent.tiles[this.mapData[ty][tx]] });
|
if (this.mapData[ty] && this.mapData[ty][tx])
|
||||||
|
{
|
||||||
|
output.push({ x: tx, y: ty, tile: this._parent.tiles[this.mapData[ty][tx]] });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +191,7 @@ module Phaser {
|
|||||||
|
|
||||||
this.boundsInTiles.setTo(0, 0, this.widthInTiles, this.heightInTiles);
|
this.boundsInTiles.setTo(0, 0, this.widthInTiles, this.heightInTiles);
|
||||||
|
|
||||||
console.log('layer bounds', this.boundsInTiles);
|
//console.log('layer bounds', this.boundsInTiles);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
Phaser
|
Phaser
|
||||||
======
|
======
|
||||||
|
|
||||||
Version: 0.9.4 Released: XX April 2013
|
Version: 0.9.4 Released: 28th April 2013
|
||||||
|
|
||||||
By Richard Davey, [Photon Storm](http://www.photonstorm.com)
|
By Richard Davey, [Photon Storm](http://www.photonstorm.com)
|
||||||
|
|
||||||
@@ -20,11 +20,15 @@ Latest Update
|
|||||||
|
|
||||||
V0.9.4
|
V0.9.4
|
||||||
|
|
||||||
* Fixed Tilemap bounds check if map was smaller than game dimensions
|
|
||||||
* Added Tilemap.getTile, getTileFromWorldXY, getTileFromInputXY
|
* Added Tilemap.getTile, getTileFromWorldXY, getTileFromInputXY
|
||||||
* Added Tilemap.setCollisionByIndex and setCollisionByRange
|
* Added Tilemap.setCollisionByIndex and setCollisionByRange
|
||||||
* Added GameObject.renderRotation boolean to control if the sprite will visually rotate or not (useful when angle needs to change but graphics don't)
|
* Added GameObject.renderRotation boolean to control if the sprite will visually rotate or not (useful when angle needs to change but graphics don't)
|
||||||
|
* Added additional check to Camera.width/height so you cannot set them larger than the Stage size
|
||||||
|
* Added Collision.separateTile and Tilemap.collide
|
||||||
|
* Fixed Tilemap bounds check if map was smaller than game dimensions
|
||||||
|
* Fixed: Made World._cameras public, World.cameras and turned Game.camera into a getter for it (thanks Hackmaniac)
|
||||||
|
* Fixed: Circle.isEmpty properly checks diameter (thanks bapuna)
|
||||||
|
* Updated Gruntfile to export new version of phaser.js wrapped in a UMD block for require.js/commonJS (thanks Hackmaniac)
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
|
|||||||
@@ -96,6 +96,10 @@
|
|||||||
<TypeScriptCompile Include="sprites\dynamic texture 1.ts" />
|
<TypeScriptCompile Include="sprites\dynamic texture 1.ts" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Content Include="tweens\properties.js">
|
||||||
|
<DependentUpon>properties.ts</DependentUpon>
|
||||||
|
</Content>
|
||||||
|
<TypeScriptCompile Include="tweens\properties.ts" />
|
||||||
<TypeScriptCompile Include="misc\screen grab.ts" />
|
<TypeScriptCompile Include="misc\screen grab.ts" />
|
||||||
<Content Include="misc\screen grab.js">
|
<Content Include="misc\screen grab.js">
|
||||||
<DependentUpon>screen grab.ts</DependentUpon>
|
<DependentUpon>screen grab.ts</DependentUpon>
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
for(var i = 0; i < 100; i++) {
|
for(var i = 0; i < 100; i++) {
|
||||||
myGame.createSprite(Math.random() * myGame.world.width, Math.random() * myGame.world.height, 'melon');
|
myGame.createSprite(Math.random() * myGame.world.width, Math.random() * myGame.world.height, 'melon');
|
||||||
}
|
}
|
||||||
|
myGame.onRenderCallback = render;
|
||||||
}
|
}
|
||||||
function update() {
|
function update() {
|
||||||
myGame.camera.renderDebugInfo(32, 32);
|
|
||||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||||
myGame.camera.scroll.x -= 4;
|
myGame.camera.scroll.x -= 4;
|
||||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||||
@@ -27,4 +27,7 @@
|
|||||||
myGame.camera.scroll.y += 4;
|
myGame.camera.scroll.y += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function render() {
|
||||||
|
myGame.camera.renderDebugInfo(32, 32);
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -25,12 +25,12 @@
|
|||||||
myGame.createSprite(Math.random() * myGame.world.width, Math.random() * myGame.world.height, 'melon');
|
myGame.createSprite(Math.random() * myGame.world.width, Math.random() * myGame.world.height, 'melon');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
myGame.onRenderCallback = render;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
|
|
||||||
myGame.camera.renderDebugInfo(32, 32);
|
|
||||||
|
|
||||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||||
{
|
{
|
||||||
myGame.camera.scroll.x -= 4;
|
myGame.camera.scroll.x -= 4;
|
||||||
@@ -51,4 +51,10 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
|
||||||
|
myGame.camera.renderDebugInfo(32, 32);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -12,22 +12,23 @@
|
|||||||
myGame.createSprite(0, 0, 'grid');
|
myGame.createSprite(0, 0, 'grid');
|
||||||
car = myGame.createSprite(400, 300, 'car');
|
car = myGame.createSprite(400, 300, 'car');
|
||||||
myGame.camera.follow(car);
|
myGame.camera.follow(car);
|
||||||
|
myGame.onRenderCallback = render;
|
||||||
}
|
}
|
||||||
function update() {
|
function update() {
|
||||||
myGame.camera.renderDebugInfo(32, 32);
|
|
||||||
car.renderDebugInfo(200, 32);
|
|
||||||
car.velocity.x = 0;
|
car.velocity.x = 0;
|
||||||
car.velocity.y = 0;
|
car.velocity.y = 0;
|
||||||
car.angularVelocity = 0;
|
car.angularVelocity = 0;
|
||||||
car.angularAcceleration = 0;
|
|
||||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||||
car.angularVelocity = -200;
|
car.angularVelocity = -200;
|
||||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||||
car.angularVelocity = 200;
|
car.angularVelocity = 200;
|
||||||
}
|
}
|
||||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||||
var motion = myGame.motion.velocityFromAngle(car.angle, 300);
|
car.velocity.copyFrom(myGame.motion.velocityFromAngle(car.angle, 300));
|
||||||
car.velocity.copyFrom(motion);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function render() {
|
||||||
|
myGame.camera.renderDebugInfo(32, 32);
|
||||||
|
car.renderDebugInfo(200, 32);
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -25,17 +25,16 @@
|
|||||||
|
|
||||||
myGame.camera.follow(car);
|
myGame.camera.follow(car);
|
||||||
|
|
||||||
|
myGame.onRenderCallback = render;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
|
|
||||||
myGame.camera.renderDebugInfo(32, 32);
|
|
||||||
car.renderDebugInfo(200, 32);
|
|
||||||
|
|
||||||
car.velocity.x = 0;
|
car.velocity.x = 0;
|
||||||
car.velocity.y = 0;
|
car.velocity.y = 0;
|
||||||
car.angularVelocity = 0;
|
car.angularVelocity = 0;
|
||||||
car.angularAcceleration = 0;
|
|
||||||
|
|
||||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||||
{
|
{
|
||||||
@@ -48,11 +47,16 @@
|
|||||||
|
|
||||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||||
{
|
{
|
||||||
var motion:Phaser.Point = myGame.motion.velocityFromAngle(car.angle, 300);
|
car.velocity.copyFrom(myGame.motion.velocityFromAngle(car.angle, 300));
|
||||||
|
|
||||||
car.velocity.copyFrom(motion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
|
||||||
|
myGame.camera.renderDebugInfo(32, 32);
|
||||||
|
car.renderDebugInfo(200, 32);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
/// <reference path="../../Phaser/Game.ts" />
|
|
||||||
(function () {
|
|
||||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
|
||||||
function init() {
|
|
||||||
myGame.loader.addTextFile('jsontest', 'assets/maps/test.json');
|
|
||||||
myGame.loader.addImageFile('jsontiles', 'assets/tiles/platformer_tiles.png');
|
|
||||||
myGame.loader.load();
|
|
||||||
}
|
|
||||||
var car;
|
|
||||||
var map;
|
|
||||||
var hasGrabbed = false;
|
|
||||||
function create() {
|
|
||||||
myGame.camera.deadzone = new Phaser.Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
|
||||||
map = myGame.createTilemap('jsontiles', 'jsontest', Phaser.Tilemap.FORMAT_TILED_JSON);
|
|
||||||
// for now like this, but change to auto soon
|
|
||||||
myGame.world.setSize(map.widthInPixels, map.heightInPixels);
|
|
||||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
|
||||||
car = myGame.createSprite(300, 100, 'car');
|
|
||||||
myGame.camera.follow(car);
|
|
||||||
}
|
|
||||||
function update() {
|
|
||||||
car.velocity.x = 0;
|
|
||||||
car.velocity.y = 0;
|
|
||||||
car.angularVelocity = 0;
|
|
||||||
car.angularAcceleration = 0;
|
|
||||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
|
||||||
car.angularVelocity = -200;
|
|
||||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
|
||||||
car.angularVelocity = 200;
|
|
||||||
}
|
|
||||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
|
||||||
var motion = myGame.motion.velocityFromAngle(car.angle, 300);
|
|
||||||
car.velocity.copyFrom(motion);
|
|
||||||
}
|
|
||||||
if(myGame.input.keyboard.justReleased(Phaser.Keyboard.SPACEBAR) && hasGrabbed == false) {
|
|
||||||
console.log('graboids');
|
|
||||||
hasGrabbed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
/// <reference path="../../Phaser/Game.ts" />
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
|
|
||||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
|
||||||
|
|
||||||
function init() {
|
|
||||||
|
|
||||||
myGame.loader.addTextFile('jsontest', 'assets/maps/test.json');
|
|
||||||
myGame.loader.addImageFile('jsontiles', 'assets/tiles/platformer_tiles.png');
|
|
||||||
|
|
||||||
myGame.loader.load();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var car: Phaser.Sprite;
|
|
||||||
var map: Phaser.Tilemap;
|
|
||||||
var hasGrabbed: bool = false;
|
|
||||||
|
|
||||||
function create() {
|
|
||||||
|
|
||||||
myGame.camera.deadzone = new Phaser.Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
|
|
||||||
|
|
||||||
map = myGame.createTilemap('jsontiles', 'jsontest', Phaser.Tilemap.FORMAT_TILED_JSON);
|
|
||||||
|
|
||||||
// for now like this, but change to auto soon
|
|
||||||
myGame.world.setSize(map.widthInPixels, map.heightInPixels);
|
|
||||||
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
|
|
||||||
|
|
||||||
car = myGame.createSprite(300, 100, 'car');
|
|
||||||
|
|
||||||
myGame.camera.follow(car);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function update() {
|
|
||||||
|
|
||||||
car.velocity.x = 0;
|
|
||||||
car.velocity.y = 0;
|
|
||||||
car.angularVelocity = 0;
|
|
||||||
car.angularAcceleration = 0;
|
|
||||||
|
|
||||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
|
||||||
{
|
|
||||||
car.angularVelocity = -200;
|
|
||||||
}
|
|
||||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
|
||||||
{
|
|
||||||
car.angularVelocity = 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
|
||||||
{
|
|
||||||
var motion:Phaser.Point = myGame.motion.velocityFromAngle(car.angle, 300);
|
|
||||||
|
|
||||||
car.velocity.copyFrom(motion);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myGame.input.keyboard.justReleased(Phaser.Keyboard.SPACEBAR) && hasGrabbed == false)
|
|
||||||
{
|
|
||||||
console.log('graboids');
|
|
||||||
hasGrabbed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
})();
|
|
||||||
+6082
-2215
File diff suppressed because it is too large
Load Diff
+16
-45
@@ -6,17 +6,15 @@
|
|||||||
myGame.loader.addTextFile('platform', 'assets/maps/platform-test-1.json');
|
myGame.loader.addTextFile('platform', 'assets/maps/platform-test-1.json');
|
||||||
myGame.loader.addImageFile('tiles', 'assets/tiles/platformer_tiles.png');
|
myGame.loader.addImageFile('tiles', 'assets/tiles/platformer_tiles.png');
|
||||||
myGame.loader.addImageFile('ufo', 'assets/sprites/ufo.png');
|
myGame.loader.addImageFile('ufo', 'assets/sprites/ufo.png');
|
||||||
myGame.loader.addImageFile('ilkke', 'assets/sprites/ilkke.png');
|
myGame.loader.addImageFile('melon', 'assets/sprites/melon.png');
|
||||||
myGame.loader.addImageFile('chunk', 'assets/sprites/chunk.png');
|
myGame.loader.addImageFile('chunk', 'assets/sprites/chunk.png');
|
||||||
myGame.loader.addImageFile('healthbar', 'assets/sprites/healthbar.png');
|
|
||||||
myGame.loader.load();
|
myGame.loader.load();
|
||||||
}
|
}
|
||||||
var map;
|
var map;
|
||||||
var car;
|
var car;
|
||||||
var marker;
|
|
||||||
var tile;
|
var tile;
|
||||||
var emitter;
|
var emitter;
|
||||||
var mo;
|
var test;
|
||||||
function create() {
|
function create() {
|
||||||
map = myGame.createTilemap('tiles', 'platform', Phaser.Tilemap.FORMAT_TILED_JSON);
|
map = myGame.createTilemap('tiles', 'platform', Phaser.Tilemap.FORMAT_TILED_JSON);
|
||||||
map.setCollisionRange(21, 53);
|
map.setCollisionRange(21, 53);
|
||||||
@@ -28,27 +26,21 @@
|
|||||||
Phaser.Keyboard.UP,
|
Phaser.Keyboard.UP,
|
||||||
Phaser.Keyboard.DOWN
|
Phaser.Keyboard.DOWN
|
||||||
]);
|
]);
|
||||||
emitter = myGame.createEmitter(32, 32);
|
emitter = myGame.createEmitter(32, 80);
|
||||||
emitter.width = 700;
|
emitter.width = 700;
|
||||||
emitter.makeParticles(null, 50, 0, false, 0);
|
emitter.makeParticles('chunk', 100, 0, false, 1);
|
||||||
emitter.gravity = 100;
|
emitter.gravity = 200;
|
||||||
emitter.setRotation(0, 0);
|
emitter.bounce = 0.8;
|
||||||
emitter.start(false);
|
emitter.start(false, 10, 0.05);
|
||||||
car = myGame.createSprite(250, 64, 'ufo');
|
car = myGame.createSprite(250, 64, 'ufo');
|
||||||
car.renderRotation = false;
|
car.renderRotation = false;
|
||||||
//car.renderDebug = true;
|
test = myGame.createSprite(200, 64, 'ufo');
|
||||||
|
test.elasticity = 1;
|
||||||
|
test.velocity.x = 50;
|
||||||
|
test.velocity.y = 100;
|
||||||
car.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
car.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
||||||
//car.velocity.y = 10;
|
}
|
||||||
marker = myGame.createGeomSprite(0, 0);
|
|
||||||
marker.createRectangle(16, 16);
|
|
||||||
marker.renderFill = false;
|
|
||||||
marker.visible = false;
|
|
||||||
//myGame.onRenderCallback = render;
|
|
||||||
}
|
|
||||||
function update() {
|
function update() {
|
||||||
marker.x = myGame.math.snapToFloor(myGame.input.worldX, 16);
|
|
||||||
marker.y = myGame.math.snapToFloor(myGame.input.worldY, 16);
|
|
||||||
//myGame.collide(car, map.currentLayer);
|
|
||||||
car.velocity.x = 0;
|
car.velocity.x = 0;
|
||||||
car.velocity.y = 0;
|
car.velocity.y = 0;
|
||||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||||
@@ -61,30 +53,9 @@
|
|||||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||||
car.velocity.y = 200;
|
car.velocity.y = 200;
|
||||||
}
|
}
|
||||||
mo = map.collide(car);
|
// Collide everything with the map
|
||||||
//map.getTileOverlaps()
|
map.collide();
|
||||||
}
|
// And collide everything in the game :)
|
||||||
function render() {
|
myGame.collide();
|
||||||
tile = map.getTileFromInputXY();
|
|
||||||
//var b = map.getTileOverlaps(car);
|
|
||||||
myGame.stage.context.font = '18px Arial';
|
|
||||||
myGame.stage.context.fillStyle = 'rgb(255,255,255)';
|
|
||||||
//myGame.stage.context.fillText(tile.toString(), 32, 32);
|
|
||||||
myGame.input.renderDebugInfo(32, 64, 'rgb(255,255,255)');
|
|
||||||
myGame.stage.context.fillStyle = 'rgb(255,255,255)';
|
|
||||||
myGame.stage.context.fillText(mo.x + ' ' + mo.y + ' ' + mo.w + ' ' + mo.h, 32, 200);
|
|
||||||
myGame.stage.context.fillText(car.bounds.x + ' ' + car.bounds.y + ' ' + car.bounds.width + ' ' + car.bounds.height, 32, 232);
|
|
||||||
var i = 0;
|
|
||||||
for(var y = mo.y; y < mo.y + mo.h; y++) {
|
|
||||||
for(var x = mo.x; x < mo.x + mo.w; x++) {
|
|
||||||
if(mo.collision[i] == true) {
|
|
||||||
myGame.stage.context.fillStyle = 'rgba(255,0,0,0.5)';
|
|
||||||
} else {
|
|
||||||
myGame.stage.context.fillStyle = 'rgba(0,255,0,0.5)';
|
|
||||||
}
|
|
||||||
myGame.stage.context.fillRect(x * 16, y * 16, 16, 16);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
+16
-64
@@ -10,9 +10,8 @@
|
|||||||
myGame.loader.addTextFile('platform', 'assets/maps/platform-test-1.json');
|
myGame.loader.addTextFile('platform', 'assets/maps/platform-test-1.json');
|
||||||
myGame.loader.addImageFile('tiles', 'assets/tiles/platformer_tiles.png');
|
myGame.loader.addImageFile('tiles', 'assets/tiles/platformer_tiles.png');
|
||||||
myGame.loader.addImageFile('ufo', 'assets/sprites/ufo.png');
|
myGame.loader.addImageFile('ufo', 'assets/sprites/ufo.png');
|
||||||
myGame.loader.addImageFile('ilkke', 'assets/sprites/ilkke.png');
|
myGame.loader.addImageFile('melon', 'assets/sprites/melon.png');
|
||||||
myGame.loader.addImageFile('chunk', 'assets/sprites/chunk.png');
|
myGame.loader.addImageFile('chunk', 'assets/sprites/chunk.png');
|
||||||
myGame.loader.addImageFile('healthbar', 'assets/sprites/healthbar.png');
|
|
||||||
|
|
||||||
myGame.loader.load();
|
myGame.loader.load();
|
||||||
|
|
||||||
@@ -20,11 +19,9 @@
|
|||||||
|
|
||||||
var map: Phaser.Tilemap;
|
var map: Phaser.Tilemap;
|
||||||
var car: Phaser.Sprite;
|
var car: Phaser.Sprite;
|
||||||
var marker: Phaser.GeomSprite;
|
|
||||||
var tile: Phaser.Tile;
|
var tile: Phaser.Tile;
|
||||||
var emitter: Phaser.Emitter;
|
var emitter: Phaser.Emitter;
|
||||||
|
var test: Phaser.Sprite;
|
||||||
var mo;
|
|
||||||
|
|
||||||
function create() {
|
function create() {
|
||||||
|
|
||||||
@@ -36,38 +33,27 @@
|
|||||||
|
|
||||||
myGame.input.keyboard.addKeyCapture([Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.UP, Phaser.Keyboard.DOWN]);
|
myGame.input.keyboard.addKeyCapture([Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.UP, Phaser.Keyboard.DOWN]);
|
||||||
|
|
||||||
emitter = myGame.createEmitter(32, 32);
|
emitter = myGame.createEmitter(32, 80);
|
||||||
emitter.width = 700;
|
emitter.width = 700;
|
||||||
emitter.makeParticles(null, 50, 0, false, 0);
|
emitter.makeParticles('chunk', 100, 0, false, 1);
|
||||||
emitter.gravity = 100;
|
emitter.gravity = 200;
|
||||||
emitter.setRotation(0,0);
|
emitter.bounce = 0.8;
|
||||||
emitter.start(false);
|
emitter.start(false, 10, 0.05);
|
||||||
|
|
||||||
car = myGame.createSprite(250, 64, 'ufo');
|
car = myGame.createSprite(250, 64, 'ufo');
|
||||||
car.renderRotation = false;
|
car.renderRotation = false;
|
||||||
//car.renderDebug = true;
|
|
||||||
|
test = myGame.createSprite(200, 64, 'ufo');
|
||||||
|
test.elasticity = 1;
|
||||||
|
test.velocity.x = 50;
|
||||||
|
test.velocity.y = 100;
|
||||||
|
|
||||||
car.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
car.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
||||||
//car.velocity.y = 10;
|
|
||||||
|
|
||||||
marker = myGame.createGeomSprite(0, 0);
|
|
||||||
marker.createRectangle(16, 16);
|
|
||||||
marker.renderFill = false;
|
|
||||||
marker.visible = false;
|
|
||||||
|
|
||||||
//myGame.onRenderCallback = render;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
|
|
||||||
marker.x = myGame.math.snapToFloor(myGame.input.worldX, 16);
|
|
||||||
marker.y = myGame.math.snapToFloor(myGame.input.worldY, 16);
|
|
||||||
|
|
||||||
//myGame.collide(car, map.currentLayer);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
car.velocity.x = 0;
|
car.velocity.x = 0;
|
||||||
car.velocity.y = 0;
|
car.velocity.y = 0;
|
||||||
|
|
||||||
@@ -89,45 +75,11 @@
|
|||||||
car.velocity.y = 200;
|
car.velocity.y = 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
mo = map.collide(car);
|
// Collide everything with the map
|
||||||
//map.getTileOverlaps()
|
map.collide();
|
||||||
|
|
||||||
}
|
// And collide everything in the game :)
|
||||||
|
myGame.collide();
|
||||||
function render() {
|
|
||||||
|
|
||||||
tile = map.getTileFromInputXY();
|
|
||||||
|
|
||||||
//var b = map.getTileOverlaps(car);
|
|
||||||
|
|
||||||
myGame.stage.context.font = '18px Arial';
|
|
||||||
myGame.stage.context.fillStyle = 'rgb(255,255,255)';
|
|
||||||
//myGame.stage.context.fillText(tile.toString(), 32, 32);
|
|
||||||
myGame.input.renderDebugInfo(32, 64, 'rgb(255,255,255)');
|
|
||||||
myGame.stage.context.fillStyle = 'rgb(255,255,255)';
|
|
||||||
myGame.stage.context.fillText(mo.x + ' ' + mo.y + ' ' + mo.w + ' ' + mo.h, 32, 200);
|
|
||||||
myGame.stage.context.fillText(car.bounds.x + ' ' + car.bounds.y + ' ' + car.bounds.width + ' ' + car.bounds.height, 32, 232);
|
|
||||||
|
|
||||||
|
|
||||||
var i = 0;
|
|
||||||
|
|
||||||
for (var y = mo.y; y < mo.y + mo.h; y++)
|
|
||||||
{
|
|
||||||
for (var x = mo.x; x < mo.x + mo.w; x++)
|
|
||||||
{
|
|
||||||
if (mo.collision[i] == true)
|
|
||||||
{
|
|
||||||
myGame.stage.context.fillStyle = 'rgba(255,0,0,0.5)';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
myGame.stage.context.fillStyle = 'rgba(0,255,0,0.5)';
|
|
||||||
}
|
|
||||||
|
|
||||||
myGame.stage.context.fillRect(x * 16, y * 16, 16, 16);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6082
-2215
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user