Integrated SAT. Fixed lots of examples. Fixed documentation. Added new examples and built new phaser.js file for testing.

This commit is contained in:
photonstorm committed 2014-01-27 06:29:26 +00:00
1 parent 45518b3ecd
commit 4505aa50f6
35 files changed
+4065 -2261

No files matched your search

+1
View File
@@ -112,6 +112,7 @@ module.exports = function (grunt) {
'src/sound/SoundManager.js',
'src/utils/Debug.js',
'src/utils/Color.js',
'src/physics/arcade/SAT.js',
'src/physics/arcade/ArcadePhysics.js',
'src/physics/arcade/Body.js',
'src/particles/Particles.js',
+2
View File
@@ -67,6 +67,7 @@ Significant API changes:
* Body.customSeparateCallback allows you to set your own callback when two Bodies need to separate rather than using the built-in method.
* Body.collideCallback allows you to set a callback that is fired whenever the Body is hit on any of its active faces.
* Body.allowCollision has been renamed to Body.checkCollision.
* Body.rebound is a boolean that controls if a body will exchange velocity on collision. Set to false to allow it to be 'pushed' (see new examples).
New features:
@@ -167,6 +168,7 @@ Updates:
* Removed ArcadePhysics binding to the QuadTree, so it can now be used independantly of the physics system.
* Removed ArcadePhysics.preUpdate and postUpdate as neither are needed any more.
* Body.bottom and Body.right are no longer rounded, so will give accurate sub-pixel values.
* Fixed lots of documentation in the Emitter class.
Bug Fixes:
+1
View File
@@ -131,6 +131,7 @@
<script src="$path/src/utils/Debug.js"></script>
<script src="$path/src/utils/Color.js"></script>
<script src="$path/src/physics/arcade/SAT.js"></script>
<script src="$path/src/physics/arcade/ArcadePhysics.js"></script>
<script src="$path/src/physics/arcade/Body.js"></script>
+2517 -883
View File
File diff suppressed because it is too large. Load diff
+11 -11
View File
@@ -1,13 +1,13 @@
/*! Phaser v1.1.4 | (c) 2013 Photon Storm Ltd. */
!function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof exports?module.exports=b():a.Phaser=b()}(this,function(){function a(){return b.Matrix="undefined"!=typeof Float32Array?Float32Array:Array,b.Matrix}var b=b||{},c=c||{VERSION:"1.1.4",DEV_VERSION:"1.1.4",GAMES:[],AUTO:0,CANVAS:1,WEBGL:2,HEADLESS:3,SPRITE:0,BUTTON:1,BULLET:2,GRAPHICS:3,TEXT:4,TILESPRITE:5,BITMAPTEXT:6,GROUP:7,RENDERTEXTURE:8,TILEMAP:9,TILEMAPLAYER:10,EMITTER:11,POLYGON:12,BITMAPDATA:13,CANVAS_FILTER:14,WEBGL_FILTER:15,NONE:0,LEFT:1,RIGHT:2,UP:3,DOWN:4};b.InteractionManager=function(){},c.Utils={shuffle:function(a){for(var b=a.length-1;b>0;b--){var c=Math.floor(Math.random()*(b+1)),d=a[b];a[b]=a[c],a[c]=d}return a},pad:function(a,b,c,d){if("undefined"==typeof b)var b=0;if("undefined"==typeof c)var c=" ";if("undefined"==typeof d)var d=3;var e=0;if(b+1>=a.length)switch(d){case 1:a=Array(b+1-a.length).join(c)+a;break;case 3:var f=Math.ceil((e=b-a.length)/2),g=e-f;a=Array(g+1).join(c)+a+Array(f+1).join(c);break;default:a+=Array(b+1-a.length).join(c)}return a},isPlainObject:function(a){if("object"!=typeof a||a.nodeType||a===a.window)return!1;try{if(a.constructor&&!hasOwn.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(b){return!1}return!0},extend:function(){var a,b,d,e,f,g,h=arguments[0]||{},i=1,j=arguments.length,k=!1;for("boolean"==typeof h&&(k=h,h=arguments[1]||{},i=2),j===i&&(h=this,--i);j>i;i++)if(null!=(a=arguments[i]))for(b in a)d=h[b],e=a[b],h!==e&&(k&&e&&(c.Utils.isPlainObject(e)||(f=Array.isArray(e)))?(f?(f=!1,g=d&&Array.isArray(d)?d:[]):g=d&&c.Utils.isPlainObject(d)?d:{},h[b]=c.Utils.extend(k,g,e)):void 0!==e&&(h[b]=e));return h}},b.hex2rgb=function(a){return[(255&a>>16)/255,(255&a>>8)/255,(255&a)/255]},"function"!=typeof Function.prototype.bind&&(Function.prototype.bind=function(){var a=Array.prototype.slice;return function(b){function c(){var f=e.concat(a.call(arguments));d.apply(this instanceof c?this:b,f)}var d=this,e=a.call(arguments,1);if("function"!=typeof d)throw new TypeError;return c.prototype=function f(a){return a&&(f.prototype=a),this instanceof f?void 0:new f}(d.prototype),c}}()),a(),b.mat3={},b.mat3.create=function(){var a=new b.Matrix(9);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,a[6]=0,a[7]=0,a[8]=1,a},b.mat3.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,a[6]=0,a[7]=0,a[8]=1,a},b.mat4={},b.mat4.create=function(){var a=new b.Matrix(16);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},b.mat3.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],f=a[2],g=a[3],h=a[4],i=a[5],j=a[6],k=a[7],l=a[8],m=b[0],n=b[1],o=b[2],p=b[3],q=b[4],r=b[5],s=b[6],t=b[7],u=b[8];return c[0]=m*d+n*g+o*j,c[1]=m*e+n*h+o*k,c[2]=m*f+n*i+o*l,c[3]=p*d+q*g+r*j,c[4]=p*e+q*h+r*k,c[5]=p*f+q*i+r*l,c[6]=s*d+t*g+u*j,c[7]=s*e+t*h+u*k,c[8]=s*f+t*i+u*l,c},b.mat3.clone=function(a){var c=new b.Matrix(9);return c[0]=a[0],c[1]=a[1],c[2]=a[2],c[3]=a[3],c[4]=a[4],c[5]=a[5],c[6]=a[6],c[7]=a[7],c[8]=a[8],c},b.mat3.transpose=function(a,b){if(!b||a===b){var c=a[1],d=a[2],e=a[5];return a[1]=a[3],a[2]=a[6],a[3]=c,a[5]=a[7],a[6]=d,a[7]=e,a}return b[0]=a[0],b[1]=a[3],b[2]=a[6],b[3]=a[1],b[4]=a[4],b[5]=a[7],b[6]=a[2],b[7]=a[5],b[8]=a[8],b},b.mat3.toMat4=function(a,c){return c||(c=b.mat4.create()),c[15]=1,c[14]=0,c[13]=0,c[12]=0,c[11]=0,c[10]=a[8],c[9]=a[7],c[8]=a[6],c[7]=0,c[6]=a[5],c[5]=a[4],c[4]=a[3],c[3]=0,c[2]=a[2],c[1]=a[1],c[0]=a[0],c},b.mat4.create=function(){var a=new b.Matrix(16);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},b.mat4.transpose=function(a,b){if(!b||a===b){var c=a[1],d=a[2],e=a[3],f=a[6],g=a[7],h=a[11];return a[1]=a[4],a[2]=a[8],a[3]=a[12],a[4]=c,a[6]=a[9],a[7]=a[13],a[8]=d,a[9]=f,a[11]=a[14],a[12]=e,a[13]=g,a[14]=h,a}return b[0]=a[0],b[1]=a[4],b[2]=a[8],b[3]=a[12],b[4]=a[1],b[5]=a[5],b[6]=a[9],b[7]=a[13],b[8]=a[2],b[9]=a[6],b[10]=a[10],b[11]=a[14],b[12]=a[3],b[13]=a[7],b[14]=a[11],b[15]=a[15],b},b.mat4.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],f=a[2],g=a[3],h=a[4],i=a[5],j=a[6],k=a[7],l=a[8],m=a[9],n=a[10],o=a[11],p=a[12],q=a[13],r=a[14],s=a[15],t=b[0],u=b[1],v=b[2],w=b[3];return c[0]=t*d+u*h+v*l+w*p,c[1]=t*e+u*i+v*m+w*q,c[2]=t*f+u*j+v*n+w*r,c[3]=t*g+u*k+v*o+w*s,t=b[4],u=b[5],v=b[6],w=b[7],c[4]=t*d+u*h+v*l+w*p,c[5]=t*e+u*i+v*m+w*q,c[6]=t*f+u*j+v*n+w*r,c[7]=t*g+u*k+v*o+w*s,t=b[8],u=b[9],v=b[10],w=b[11],c[8]=t*d+u*h+v*l+w*p,c[9]=t*e+u*i+v*m+w*q,c[10]=t*f+u*j+v*n+w*r,c[11]=t*g+u*k+v*o+w*s,t=b[12],u=b[13],v=b[14],w=b[15],c[12]=t*d+u*h+v*l+w*p,c[13]=t*e+u*i+v*m+w*q,c[14]=t*f+u*j+v*n+w*r,c[15]=t*g+u*k+v*o+w*s,c},b.Point=function(a,b){this.x=a||0,this.y=b||0},b.Point.prototype.clone=function(){return new b.Point(this.x,this.y)},b.Point.prototype.constructor=b.Point,b.Rectangle=function(a,b,c,d){this.x=a||0,this.y=b||0,this.width=c||0,this.height=d||0},b.Rectangle.prototype.clone=function(){return new b.Rectangle(this.x,this.y,tLine truncated
},b.PrimitiveShader.prototype.init=function(){var a=b.compileProgram(this.vertexSrc,this.fragmentSrc),c=b.gl;c.useProgram(a),this.projectionVector=c.getUniformLocation(a,"projectionVector"),this.offsetVector=c.getUniformLocation(a,"offsetVector"),this.aVertexPosition=c.getAttribLocation(a,"aVertexPosition"),this.colorAttribute=c.getAttribLocation(a,"aColor"),this.translationMatrix=c.getUniformLocation(a,"translationMatrix"),this.alpha=c.getUniformLocation(a,"alpha"),this.program=a},b.StripShader=function(){this.program=null,this.fragmentSrc=["precision mediump float;","varying vec2 vTextureCoord;","varying float vColor;","uniform float alpha;","uniform sampler2D uSampler;","void main(void) {"," gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));"," gl_FragColor = gl_FragColor * alpha;","}"],this.vertexSrc=["attribute vec2 aVertexPosition;","attribute vec2 aTextureCoord;","attribute float aColor;","uniform mat3 translationMatrix;","uniform vec2 projectionVector;","uniform vec2 offsetVector;","varying vec2 vTextureCoord;","varying float vColor;","void main(void) {"," vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);"," v -= offsetVector.xyx;"," gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / projectionVector.y + 1.0 , 0.0, 1.0);"," vTextureCoord = aTextureCoord;"," vColor = aColor;","}"]},b.StripShader.prototype.init=function(){var a=b.compileProgram(this.vertexSrc,this.fragmentSrc),c=b.gl;c.useProgram(a),this.uSampler=c.getUniformLocation(a,"uSampler"),this.projectionVector=c.getUniformLocation(a,"projectionVector"),this.offsetVector=c.getUniformLocation(a,"offsetVector"),this.colorAttribute=c.getAttribLocation(a,"aColor"),this.aVertexPosition=c.getAttribLocation(a,"aVertexPosition"),this.aTextureCoord=c.getAttribLocation(a,"aTextureCoord"),this.translationMatrix=c.getUniformLocation(a,"translationMatrix"),this.alpha=c.getUniformLocation(a,"alpha"),this.program=a},b._batchs=[],b._getBatch=function(a){return 0===b._batchs.length?new b.WebGLBatch(a):b._batchs.pop()},b._returnBatch=function(a){a.clean(),b._batchs.push(a)},b._restoreBatchs=function(a){for(var c=0;c<b._batchs.length;c++)b._batchs[c].restoreLostContext(a)},b.WebGLBatch=function(a){this.gl=a,this.size=0,this.vertexBuffer=a.createBuffer(),this.indexBuffer=a.createBuffer(),this.uvBuffer=a.createBuffer(),this.colorBuffer=a.createBuffer(),this.blendMode=b.blendModes.NORMAL,this.dynamicSize=1},b.WebGLBatch.prototype.constructor=b.WebGLBatch,b.WebGLBatch.prototype.clean=function(){this.verticies=[],this.uvs=[],this.indices=[],this.colors=[],this.dynamicSize=1,this.texture=null,this.last=null,this.size=0,this.head=null,this.tail=null},b.WebGLBatch.prototype.restoreLostContext=function(a){this.gl=a,this.vertexBuffer=a.createBuffer(),this.indexBuffer=a.createBuffer(),this.uvBuffer=a.createBuffer(),this.colorBuffer=a.createBuffer()},b.WebGLBatch.prototype.init=function(a){a.batch=this,this.dirty=!0,this.blendMode=a.blendMode,this.texture=a.texture.baseTexture,this.head=a,this.tail=a,this.size=1,this.growBatch()},b.WebGLBatch.prototype.insertBefore=function(a,b){this.size++,a.batch=this,this.dirty=!0;var c=b.__prev;b.__prev=a,a.__next=b,c?(a.__prev=c,c.__next=a):this.head=a},b.WebGLBatch.prototype.insertAfter=function(a,b){this.size++,a.batch=this,this.dirty=!0;var c=b.__next;b.__next=a,a.__prev=b,c?(a.__next=c,c.__prev=a):this.tail=a},b.WebGLBatch.prototype.remove=function(a){return this.size--,0===this.size?(a.batch=null,a.__prev=null,a.__next=null,void 0):(a.__prev?a.__prev.__next=a.__next:(this.head=a.__next,this.head.__prev=null),a.__next?a.__next.__prev=a.__prev:(this.tail=a.__prev,this.tail.__next=null),a.batch=null,a.__next=null,a.__prev=null,this.dirty=!0,void 0)},b.WebGLBatch.prototype.split=function(a){this.dirty=!0;var c=new b.WebGLBatch(this.gl);c.init(a),c.texture=this.texture,c.tail=this.tail,this.tail=a.__prev,this.tail.__next=null,a.__prev=null;for(var d=0;a;)d++,a.batch=c,a=a.__next;return c.size=d,this.size-=d,c},b.WebGLBatch.prototype.merge=function(a){this.dirty=!0,this.tail.__next=a.head,a.head.__prev=this.tail,this.size+=a.size,this.tail=a.tail;for(var b=a.head;b;)b.batch=this,b=b.__next},b.WebGLBatch.prototype.growBatch=function(){var a=this.gl;this.dynamicSize=1===this.size?1:1.5*this.size,this.verticies=new Float32Array(8*this.dynamicSize),a.bindBuffer(a.ARRAY_BUFFER,this.vertexBuffer),a.bufferData(a.ARRAY_BUFFER,this.verticies,a.DYNAMIC_DRAW),this.uvs=new Float32Array(8*this.dynamicSize),a.bindBuffer(a.ARRAY_BUFFER,this.uvBuffer),a.bufferData(a.ARRAY_BUFFER,this.uvs,a.DYNAMIC_DRAW),this.dirtyUVS=!0,this.colors=new Float32Array(4*this.dynamicSize),a.bindBuffer(a.ARRAY_BUFFER,this.colorBuffer),a.bufferData(a.ARRAY_BUFFER,this.colors,a.DYNAMIC_DRAW),this.dirtyColors=!0,this.indices=new Uint16Array(6*this.dynamicSize);for(var b=this.indices.length/6,c=0;b>c;c++){var d=6*c,e=4*c;this.indices[d+0]=e+0,this.indices[d+1]=e+1,this.indices[d+2]=e+2,this.indices[d+3]=e+0,this.indices[d+4]=Line truncated
!function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof exports?module.exports=b():a.Phaser=b()}(this,function(){function a(){return b.Matrix="undefined"!=typeof Float32Array?Float32Array:Array,b.Matrix}var b=b||{},c=c||{VERSION:"1.1.4",DEV_VERSION:"1.1.4",GAMES:[],AUTO:0,CANVAS:1,WEBGL:2,HEADLESS:3,SPRITE:0,BUTTON:1,BULLET:2,GRAPHICS:3,TEXT:4,TILESPRITE:5,BITMAPTEXT:6,GROUP:7,RENDERTEXTURE:8,TILEMAP:9,TILEMAPLAYER:10,EMITTER:11,POLYGON:12,BITMAPDATA:13,CANVAS_FILTER:14,WEBGL_FILTER:15,NONE:0,LEFT:1,RIGHT:2,UP:3,DOWN:4};b.InteractionManager=function(){},c.Utils={shuffle:function(a){for(var b=a.length-1;b>0;b--){var c=Math.floor(Math.random()*(b+1)),d=a[b];a[b]=a[c],a[c]=d}return a},pad:function(a,b,c,d){if("undefined"==typeof b)var b=0;if("undefined"==typeof c)var c=" ";if("undefined"==typeof d)var d=3;var e=0;if(b+1>=a.length)switch(d){case 1:a=Array(b+1-a.length).join(c)+a;break;case 3:var f=Math.ceil((e=b-a.length)/2),g=e-f;a=Array(g+1).join(c)+a+Array(f+1).join(c);break;default:a+=Array(b+1-a.length).join(c)}return a},isArray:function(a){return"[object Array]"===toString.call(a)},isPlainObject:function(a){if("object"!=typeof a||a.nodeType||a===a.window)return!1;try{if(a.constructor&&!hasOwn.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(b){return!1}return!0},extend:function(){var a,b,d,e,f,g,h=arguments[0]||{},i=1,j=arguments.length,k=!1;for("boolean"==typeof h&&(k=h,h=arguments[1]||{},i=2),j===i&&(h=this,--i);j>i;i++)if(null!=(a=arguments[i]))for(b in a)d=h[b],e=a[b],h!==e&&(k&&e&&(c.Utils.isPlainObject(e)||(f=Array.isArray(e)))?(f?(f=!1,g=d&&Array.isArray(d)?d:[]):g=d&&c.Utils.isPlainObject(d)?d:{},h[b]=c.Utils.extend(k,g,e)):void 0!==e&&(h[b]=e));return h}},b.hex2rgb=function(a){return[(255&a>>16)/255,(255&a>>8)/255,(255&a)/255]},"function"!=typeof Function.prototype.bind&&(Function.prototype.bind=function(){var a=Array.prototype.slice;return function(b){function c(){var f=e.concat(a.call(arguments));d.apply(this instanceof c?this:b,f)}var d=this,e=a.call(arguments,1);if("function"!=typeof d)throw new TypeError;return c.prototype=function f(a){return a&&(f.prototype=a),this instanceof f?void 0:new f}(d.prototype),c}}()),a(),b.mat3={},b.mat3.create=function(){var a=new b.Matrix(9);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,a[6]=0,a[7]=0,a[8]=1,a},b.mat3.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,a[6]=0,a[7]=0,a[8]=1,a},b.mat4={},b.mat4.create=function(){var a=new b.Matrix(16);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},b.mat3.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],f=a[2],g=a[3],h=a[4],i=a[5],j=a[6],k=a[7],l=a[8],m=b[0],n=b[1],o=b[2],p=b[3],q=b[4],r=b[5],s=b[6],t=b[7],u=b[8];return c[0]=m*d+n*g+o*j,c[1]=m*e+n*h+o*k,c[2]=m*f+n*i+o*l,c[3]=p*d+q*g+r*j,c[4]=p*e+q*h+r*k,c[5]=p*f+q*i+r*l,c[6]=s*d+t*g+u*j,c[7]=s*e+t*h+u*k,c[8]=s*f+t*i+u*l,c},b.mat3.clone=function(a){var c=new b.Matrix(9);return c[0]=a[0],c[1]=a[1],c[2]=a[2],c[3]=a[3],c[4]=a[4],c[5]=a[5],c[6]=a[6],c[7]=a[7],c[8]=a[8],c},b.mat3.transpose=function(a,b){if(!b||a===b){var c=a[1],d=a[2],e=a[5];return a[1]=a[3],a[2]=a[6],a[3]=c,a[5]=a[7],a[6]=d,a[7]=e,a}return b[0]=a[0],b[1]=a[3],b[2]=a[6],b[3]=a[1],b[4]=a[4],b[5]=a[7],b[6]=a[2],b[7]=a[5],b[8]=a[8],b},b.mat3.toMat4=function(a,c){return c||(c=b.mat4.create()),c[15]=1,c[14]=0,c[13]=0,c[12]=0,c[11]=0,c[10]=a[8],c[9]=a[7],c[8]=a[6],c[7]=0,c[6]=a[5],c[5]=a[4],c[4]=a[3],c[3]=0,c[2]=a[2],c[1]=a[1],c[0]=a[0],c},b.mat4.create=function(){var a=new b.Matrix(16);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},b.mat4.transpose=function(a,b){if(!b||a===b){var c=a[1],d=a[2],e=a[3],f=a[6],g=a[7],h=a[11];return a[1]=a[4],a[2]=a[8],a[3]=a[12],a[4]=c,a[6]=a[9],a[7]=a[13],a[8]=d,a[9]=f,a[11]=a[14],a[12]=e,a[13]=g,a[14]=h,a}return b[0]=a[0],b[1]=a[4],b[2]=a[8],b[3]=a[12],b[4]=a[1],b[5]=a[5],b[6]=a[9],b[7]=a[13],b[8]=a[2],b[9]=a[6],b[10]=a[10],b[11]=a[14],b[12]=a[3],b[13]=a[7],b[14]=a[11],b[15]=a[15],b},b.mat4.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],f=a[2],g=a[3],h=a[4],i=a[5],j=a[6],k=a[7],l=a[8],m=a[9],n=a[10],o=a[11],p=a[12],q=a[13],r=a[14],s=a[15],t=b[0],u=b[1],v=b[2],w=b[3];return c[0]=t*d+u*h+v*l+w*p,c[1]=t*e+u*i+v*m+w*q,c[2]=t*f+u*j+v*n+w*r,c[3]=t*g+u*k+v*o+w*s,t=b[4],u=b[5],v=b[6],w=b[7],c[4]=t*d+u*h+v*l+w*p,c[5]=t*e+u*i+v*m+w*q,c[6]=t*f+u*j+v*n+w*r,c[7]=t*g+u*k+v*o+w*s,t=b[8],u=b[9],v=b[10],w=b[11],c[8]=t*d+u*h+v*l+w*p,c[9]=t*e+u*i+v*m+w*q,c[10]=t*f+u*j+v*n+w*r,c[11]=t*g+u*k+v*o+w*s,t=b[12],u=b[13],v=b[14],w=b[15],c[12]=t*d+u*h+v*l+w*p,c[13]=t*e+u*i+v*m+w*q,c[14]=t*f+u*j+v*n+w*r,c[15]=t*g+u*k+v*o+w*s,c},b.Point=function(a,b){this.x=a||0,this.y=b||0},b.Point.prototype.clone=function(){return new b.Point(this.x,this.y)},b.Point.prototype.constructor=b.Point,b.Rectangle=function(a,b,c,d){this.x=a||0,this.y=b||0,this.width=c||0,this.height=d||0},b.Rectangle.prLine truncated
},b.PrimitiveShader.prototype.init=function(){var a=b.compileProgram(this.vertexSrc,this.fragmentSrc),c=b.gl;c.useProgram(a),this.projectionVector=c.getUniformLocation(a,"projectionVector"),this.offsetVector=c.getUniformLocation(a,"offsetVector"),this.aVertexPosition=c.getAttribLocation(a,"aVertexPosition"),this.colorAttribute=c.getAttribLocation(a,"aColor"),this.translationMatrix=c.getUniformLocation(a,"translationMatrix"),this.alpha=c.getUniformLocation(a,"alpha"),this.program=a},b.StripShader=function(){this.program=null,this.fragmentSrc=["precision mediump float;","varying vec2 vTextureCoord;","varying float vColor;","uniform float alpha;","uniform sampler2D uSampler;","void main(void) {"," gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));"," gl_FragColor = gl_FragColor * alpha;","}"],this.vertexSrc=["attribute vec2 aVertexPosition;","attribute vec2 aTextureCoord;","attribute float aColor;","uniform mat3 translationMatrix;","uniform vec2 projectionVector;","uniform vec2 offsetVector;","varying vec2 vTextureCoord;","varying float vColor;","void main(void) {"," vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);"," v -= offsetVector.xyx;"," gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / projectionVector.y + 1.0 , 0.0, 1.0);"," vTextureCoord = aTextureCoord;"," vColor = aColor;","}"]},b.StripShader.prototype.init=function(){var a=b.compileProgram(this.vertexSrc,this.fragmentSrc),c=b.gl;c.useProgram(a),this.uSampler=c.getUniformLocation(a,"uSampler"),this.projectionVector=c.getUniformLocation(a,"projectionVector"),this.offsetVector=c.getUniformLocation(a,"offsetVector"),this.colorAttribute=c.getAttribLocation(a,"aColor"),this.aVertexPosition=c.getAttribLocation(a,"aVertexPosition"),this.aTextureCoord=c.getAttribLocation(a,"aTextureCoord"),this.translationMatrix=c.getUniformLocation(a,"translationMatrix"),this.alpha=c.getUniformLocation(a,"alpha"),this.program=a},b._batchs=[],b._getBatch=function(a){return 0===b._batchs.length?new b.WebGLBatch(a):b._batchs.pop()},b._returnBatch=function(a){a.clean(),b._batchs.push(a)},b._restoreBatchs=function(a){for(var c=0;c<b._batchs.length;c++)b._batchs[c].restoreLostContext(a)},b.WebGLBatch=function(a){this.gl=a,this.size=0,this.vertexBuffer=a.createBuffer(),this.indexBuffer=a.createBuffer(),this.uvBuffer=a.createBuffer(),this.colorBuffer=a.createBuffer(),this.blendMode=b.blendModes.NORMAL,this.dynamicSize=1},b.WebGLBatch.prototype.constructor=b.WebGLBatch,b.WebGLBatch.prototype.clean=function(){this.verticies=[],this.uvs=[],this.indices=[],this.colors=[],this.dynamicSize=1,this.texture=null,this.last=null,this.size=0,this.head=null,this.tail=null},b.WebGLBatch.prototype.restoreLostContext=function(a){this.gl=a,this.vertexBuffer=a.createBuffer(),this.indexBuffer=a.createBuffer(),this.uvBuffer=a.createBuffer(),this.colorBuffer=a.createBuffer()},b.WebGLBatch.prototype.init=function(a){a.batch=this,this.dirty=!0,this.blendMode=a.blendMode,this.texture=a.texture.baseTexture,this.head=a,this.tail=a,this.size=1,this.growBatch()},b.WebGLBatch.prototype.insertBefore=function(a,b){this.size++,a.batch=this,this.dirty=!0;var c=b.__prev;b.__prev=a,a.__next=b,c?(a.__prev=c,c.__next=a):this.head=a},b.WebGLBatch.prototype.insertAfter=function(a,b){this.size++,a.batch=this,this.dirty=!0;var c=b.__next;b.__next=a,a.__prev=b,c?(a.__next=c,c.__prev=a):this.tail=a},b.WebGLBatch.prototype.remove=function(a){return this.size--,0===this.size?(a.batch=null,a.__prev=null,a.__next=null,void 0):(a.__prev?a.__prev.__next=a.__next:(this.head=a.__next,this.head.__prev=null),a.__next?a.__next.__prev=a.__prev:(this.tail=a.__prev,this.tail.__next=null),a.batch=null,a.__next=null,a.__prev=null,this.dirty=!0,void 0)},b.WebGLBatch.prototype.split=function(a){this.dirty=!0;var c=new b.WebGLBatch(this.gl);c.init(a),c.texture=this.texture,c.tail=this.tail,this.tail=a.__prev,this.tail.__next=null,a.__prev=null;for(var d=0;a;)d++,a.batch=c,a=a.__next;return c.size=d,this.size-=d,c},b.WebGLBatch.prototype.merge=function(a){this.dirty=!0,this.tail.__next=a.head,a.head.__prev=this.tail,this.size+=a.size,this.tail=a.tail;for(var b=a.head;b;)b.batch=this,b=b.__next},b.WebGLBatch.prototype.growBatch=function(){var a=this.gl;this.dynamicSize=1===this.size?1:1.5*this.size,this.verticies=new Float32Array(8*this.dynamicSize),a.bindBuffer(a.ARRAY_BUFFER,this.vertexBuffer),a.bufferData(a.ARRAY_BUFFER,this.verticies,a.DYNAMIC_DRAW),this.uvs=new Float32Array(8*this.dynamicSize),a.bindBuffer(a.ARRAY_BUFFER,this.uvBuffer),a.bufferData(a.ARRAY_BUFFER,this.uvs,a.DYNAMIC_DRAW),this.dirtyUVS=!0,this.colors=new Float32Array(4*this.dynamicSize),a.bindBuffer(a.ARRAY_BUFFER,this.colorBuffer),a.bufferData(a.ARRAY_BUFFER,this.colors,a.DYNAMIC_DRAW),this.dirtyColors=!0,this.indices=new Uint16Array(6*this.dynamicSize);for(var b=this.indices.length/6,c=0;b>c;c++){var d=6*c,e=4*c;this.indices[d+0]=e+0,this.indices[d+1]=e+1,this.indices[d+2]=e+2,this.indices[d+3]=e+0,this.indices[d+4]=Line truncated
},b.WebGLRenderGroup.prototype.renderTilingSprite=function(a,c){var d=this.gl;b.shaderProgram;var e=a.tilePosition,f=a.tileScale,g=e.x/a.texture.baseTexture.width,h=e.y/a.texture.baseTexture.height,i=a.width/a.texture.baseTexture.width/f.x,j=a.height/a.texture.baseTexture.height/f.y;a.uvs[0]=0-g,a.uvs[1]=0-h,a.uvs[2]=1*i-g,a.uvs[3]=0-h,a.uvs[4]=1*i-g,a.uvs[5]=1*j-h,a.uvs[6]=0-g,a.uvs[7]=1*j-h,d.bindBuffer(d.ARRAY_BUFFER,a._uvBuffer),d.bufferSubData(d.ARRAY_BUFFER,0,a.uvs),this.renderStrip(a,c)},b.WebGLRenderGroup.prototype.initStrip=function(a){var b=this.gl;this.shaderProgram,a._vertexBuffer=b.createBuffer(),a._indexBuffer=b.createBuffer(),a._uvBuffer=b.createBuffer(),a._colorBuffer=b.createBuffer(),b.bindBuffer(b.ARRAY_BUFFER,a._vertexBuffer),b.bufferData(b.ARRAY_BUFFER,a.verticies,b.DYNAMIC_DRAW),b.bindBuffer(b.ARRAY_BUFFER,a._uvBuffer),b.bufferData(b.ARRAY_BUFFER,a.uvs,b.STATIC_DRAW),b.bindBuffer(b.ARRAY_BUFFER,a._colorBuffer),b.bufferData(b.ARRAY_BUFFER,a.colors,b.STATIC_DRAW),b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,a._indexBuffer),b.bufferData(b.ELEMENT_ARRAY_BUFFER,a.indices,b.STATIC_DRAW)},b.initDefaultShaders=function(){b.primitiveShader=new b.PrimitiveShader,b.primitiveShader.init(),b.stripShader=new b.StripShader,b.stripShader.init(),b.defaultShader=new b.PixiShader,b.defaultShader.init();var a=b.gl,c=b.defaultShader.program;a.useProgram(c),a.enableVertexAttribArray(b.defaultShader.aVertexPosition),a.enableVertexAttribArray(b.defaultShader.colorAttribute),a.enableVertexAttribArray(b.defaultShader.aTextureCoord)},b.activatePrimitiveShader=function(){var a=b.gl;a.useProgram(b.primitiveShader.program),a.disableVertexAttribArray(b.defaultShader.aVertexPosition),a.disableVertexAttribArray(b.defaultShader.colorAttribute),a.disableVertexAttribArray(b.defaultShader.aTextureCoord),a.enableVertexAttribArray(b.primitiveShader.aVertexPosition),a.enableVertexAttribArray(b.primitiveShader.colorAttribute)},b.deactivatePrimitiveShader=function(){var a=b.gl;a.useProgram(b.defaultShader.program),a.disableVertexAttribArray(b.primitiveShader.aVertexPosition),a.disableVertexAttribArray(b.primitiveShader.colorAttribute),a.enableVertexAttribArray(b.defaultShader.aVertexPosition),a.enableVertexAttribArray(b.defaultShader.colorAttribute),a.enableVertexAttribArray(b.defaultShader.aTextureCoord)},b.activateStripShader=function(){var a=b.gl;a.useProgram(b.stripShader.program)},b.deactivateStripShader=function(){var a=b.gl;a.useProgram(b.defaultShader.program)},b.CompileVertexShader=function(a,c){return b._CompileShader(a,c,a.VERTEX_SHADER)},b.CompileFragmentShader=function(a,c){return b._CompileShader(a,c,a.FRAGMENT_SHADER)},b._CompileShader=function(a,b,c){var d=b.join("\n"),e=a.createShader(c);return a.shaderSource(e,d),a.compileShader(e),a.getShaderParameter(e,a.COMPILE_STATUS)?e:(window.console.log(a.getShaderInfoLog(e)),null)},b.compileProgram=function(a,c){var d=b.gl,e=b.CompileFragmentShader(d,c),f=b.CompileVertexShader(d,a),g=d.createProgram();return d.attachShader(g,f),d.attachShader(g,e),d.linkProgram(g),d.getProgramParameter(g,d.LINK_STATUS)||window.console.log("Could not initialise shaders"),g},b.BitmapText=function(a,c){b.DisplayObjectContainer.call(this),this.setText(a),this.setStyle(c),this.updateText(),this.dirty=!1},b.BitmapText.prototype=Object.create(b.DisplayObjectContainer.prototype),b.BitmapText.prototype.constructor=b.BitmapText,b.BitmapText.prototype.setText=function(a){this.text=a||" ",this.dirty=!0},b.BitmapText.prototype.setStyle=function(a){a=a||{},a.align=a.align||"left",this.style=a;var c=a.font.split(" ");this.fontName=c[c.length-1],this.fontSize=c.length>=2?parseInt(c[c.length-2],10):b.BitmapText.fonts[this.fontName].size,this.dirty=!0},b.BitmapText.prototype.updateText=function(){for(var a=b.BitmapText.fonts[this.fontName],c=new b.Point,d=null,e=[],f=0,g=[],h=0,i=this.fontSize/a.size,j=0;j<this.text.length;j++){var k=this.text.charCodeAt(j);if(/(?:\r\n|\r|\n)/.test(this.text.charAt(j)))g.push(c.x),f=Math.max(f,c.x),h++,c.x=0,c.y+=a.lineHeight,d=null;else{var l=a.chars[k];l&&(d&&l[d]&&(c.x+=l.kerning[d]),e.push({texture:l.texture,line:h,charCode:k,position:new b.Point(c.x+l.xOffset,c.y+l.yOffset)}),c.x+=l.xAdvance,d=k)}}g.push(c.x),f=Math.max(f,c.x);var m=[];for(j=0;h>=j;j++){var n=0;"right"===this.style.align?n=f-g[j]:"center"===this.style.align&&(n=(f-g[j])/2),m.push(n)}for(j=0;j<e.length;j++){var o=new b.Sprite(e[j].texture);o.position.x=(e[j].position.x+m[e[j].line])*i,o.position.y=e[j].position.y*i,o.scale.x=o.scale.y=i,this.addChild(o)}this.width=f*i,this.height=(c.y+a.lineHeight)*i},b.BitmapText.prototype.updateTransform=function(){if(this.dirty){for(;this.children.length>0;)this.removeChild(this.getChildAt(0));this.updateText(),this.dirty=!1}b.DisplayObjectContainer.prototype.updateTransform.call(this)},b.BitmapText.fonts={},b.Text=function(a,c){this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),b.Sprite.call(this,b.Texture.fromCanvas(this.canvas)),thiLine truncated
},destroy:function(){this.plugins.length=0,this._pluginsLength=0,this.game=null,this._parent=null}},c.PluginManager.prototype.constructor=c.PluginManager,c.Stage=function(a,d,e){this.game=a,this._backgroundColor="rgb(0,0,0)",this.offset=new c.Point,this.canvas=null,this._stage=new b.Stage(0,!1),this._stage.name="_stage_root",this._stage.interactive=!1,this.display=this._stage,this.scaleMode=c.StageScaleMode.NO_SCALE,this.fullScreenScaleMode=c.StageScaleMode.NO_SCALE,this.scale=new c.StageScaleMode(this.game,d,e),this.aspectRatio=d/e,this.disableVisibilityChange=!1,this._nextOffsetCheck=0,this.checkOffsetInterval=2500,a.config?this.parseConfig(a.config):(this.canvas=c.Canvas.create(d,e),this.canvas.style["-webkit-full-screen"]="width: 100%; height: 100%")},c.Stage.prototype={parseConfig:function(a){this.canvas=a.canvasID?c.Canvas.create(this.game.width,this.game.height,a.canvasID):c.Canvas.create(this.game.width,this.game.height),a.canvasStyle?this.canvas.stlye=a.canvasStyle:this.canvas.style["-webkit-full-screen"]="width: 100%; height: 100%",a.checkOffsetInterval&&(this.checkOffsetInterval=a.checkOffsetInterval),a.disableVisibilityChange&&(this.disableVisibilityChange=a.disableVisibilityChange),a.fullScreenScaleMode&&(this.fullScreenScaleMode=a.fullScreenScaleMode),a.scaleMode&&(this.scaleMode=a.scaleMode),a.backgroundColor&&(this.backgroundColor=a.backgroundColor)},boot:function(){c.Canvas.getOffset(this.canvas,this.offset),this.bounds=new c.Rectangle(this.offset.x,this.offset.y,this.game.width,this.game.height);var a=this;this._onChange=function(b){return a.visibilityChange(b)},c.Canvas.setUserSelect(this.canvas,"none"),c.Canvas.setTouchAction(this.canvas,"none"),this.backgroundColor="#000",document.addEventListener("visibilitychange",this._onChange,!1),document.addEventListener("webkitvisibilitychange",this._onChange,!1),document.addEventListener("pagehide",this._onChange,!1),document.addEventListener("pageshow",this._onChange,!1),window.onblur=this._onChange,window.onfocus=this._onChange},update:function(){this.checkOffsetInterval!==!1&&this.game.time.now>this._nextOffsetCheck&&(c.Canvas.getOffset(this.canvas,this.offset),this._nextOffsetCheck=this.game.time.now+this.checkOffsetInterval)},visibilityChange:function(a){this.disableVisibilityChange||(this.game.paused="pagehide"==a.type||"blur"==a.type||document.hidden===!0||document.webkitHidden===!0?!0:!1)}},c.Stage.prototype.constructor=c.Stage,Object.defineProperty(c.Stage.prototype,"backgroundColor",{get:function(){return this._backgroundColor},set:function(a){this._backgroundColor=a,this.game.transparent===!1&&(this.game.renderType==c.CANVAS?this.game.canvas.style.backgroundColor=a:("string"==typeof a&&(a=c.Color.hexToRGB(a)),this._stage.setBackgroundColor(a)))}}),c.Group=function(a,d,e,f){this.game=a,"undefined"==typeof d&&(d=a.world),this.name=e||"group","undefined"==typeof f&&(f=!1),f?this._container=this.game.stage._stage:(this._container=new b.DisplayObjectContainer,this._container.name=this.name,d?d instanceof c.Group?(d._container.addChild(this._container),d._container.updateTransform()):(d.addChild(this._container),d.updateTransform()):(this.game.stage._stage.addChild(this._container),this.game.stage._stage.updateTransform())),this.type=c.GROUP,this.alive=!0,this.exists=!0,this.group=null,this._container.scale=new c.Point(1,1),this.scale=this._container.scale,this.cursor=null},c.Group.RETURN_NONE=0,c.Group.RETURN_TOTAL=1,c.Group.RETURN_CHILD=2,c.Group.SORT_ASCENDING=-1,c.Group.SORT_DESCENDING=1,c.Group.prototype={add:function(a){return a.group!==this&&(a.type&&a.type===c.GROUP?(a.group=this,this._container.addChild(a._container),a._container.updateTransform()):(a.group=this,a.events&&a.events.onAddedToGroup.dispatch(a,this),this._container.addChild(a),a.updateTransform()),null===this.cursor&&(this.cursor=a)),a},addAt:function(a,b){return a.group!==this&&(a.type&&a.type===c.GROUP?(a.group=this,this._container.addChildAt(a._container,b),a._container.updateTransform()):(a.group=this,a.events&&a.events.onAddedToGroup.dispatch(a,this),this._container.addChildAt(a,b),a.updateTransform()),null===this.cursor&&(this.cursor=a)),a},getAt:function(a){return this._container.getChildAt(a)},create:function(a,b,d,e,f){"undefined"==typeof f&&(f=!0);var g=new c.Sprite(this.game,a,b,d,e);return g.group=this,g.exists=f,g.visible=f,g.alive=f,g.events&&g.events.onAddedToGroup.dispatch(g,this),this._container.addChild(g),g.updateTransform(),null===this.cursor&&(this.cursor=g),g},createMultiple:function(a,b,d,e){"undefined"==typeof e&&(e=!1);for(var f=0;a>f;f++){var g=new c.Sprite(this.game,0,0,b,d);g.group=this,g.exists=e,g.visible=e,g.alive=e,g.events&&g.events.onAddedToGroup.dispatch(g,this),this._container.addChild(g),g.updateTransform(),null===this.cursor&&(this.cursor=g)}},next:function(){this.cursor&&(this.cursor=this.cursor==this._container.last?this._container._iNext:this.cursor._iNext)},previous:function(){this.cursor&&(this.cursor=this.cursor==this._contaLine truncated
},reset:function(){for(var a in this._keys)this._keys[a].isDown=!1},justPressed:function(a,b){return"undefined"==typeof b&&(b=250),this._keys[a]&&this._keys[a].isDown&&this._keys[a].duration<b?!0:!1},justReleased:function(a,b){return"undefined"==typeof b&&(b=250),this._keys[a]&&this._keys[a].isDown===!1&&this.game.time.now-this._keys[a].timeUp<b?!0:!1},isDown:function(a){return this._keys[a]?this._keys[a].isDown:!1}},c.Keyboard.prototype.constructor=c.Keyboard,c.Keyboard.A="A".charCodeAt(0),c.Keyboard.B="B".charCodeAt(0),c.Keyboard.C="C".charCodeAt(0),c.Keyboard.D="D".charCodeAt(0),c.Keyboard.E="E".charCodeAt(0),c.Keyboard.F="F".charCodeAt(0),c.Keyboard.G="G".charCodeAt(0),c.Keyboard.H="H".charCodeAt(0),c.Keyboard.I="I".charCodeAt(0),c.Keyboard.J="J".charCodeAt(0),c.Keyboard.K="K".charCodeAt(0),c.Keyboard.L="L".charCodeAt(0),c.Keyboard.M="M".charCodeAt(0),c.Keyboard.N="N".charCodeAt(0),c.Keyboard.O="O".charCodeAt(0),c.Keyboard.P="P".charCodeAt(0),c.Keyboard.Q="Q".charCodeAt(0),c.Keyboard.R="R".charCodeAt(0),c.Keyboard.S="S".charCodeAt(0),c.Keyboard.T="T".charCodeAt(0),c.Keyboard.U="U".charCodeAt(0),c.Keyboard.V="V".charCodeAt(0),c.Keyboard.W="W".charCodeAt(0),c.Keyboard.X="X".charCodeAt(0),c.Keyboard.Y="Y".charCodeAt(0),c.Keyboard.Z="Z".charCodeAt(0),c.Keyboard.ZERO="0".charCodeAt(0),c.Keyboard.ONE="1".charCodeAt(0),c.Keyboard.TWO="2".charCodeAt(0),c.Keyboard.THREE="3".charCodeAt(0),c.Keyboard.FOUR="4".charCodeAt(0),c.Keyboard.FIVE="5".charCodeAt(0),c.Keyboard.SIX="6".charCodeAt(0),c.Keyboard.SEVEN="7".charCodeAt(0),c.Keyboard.EIGHT="8".charCodeAt(0),c.Keyboard.NINE="9".charCodeAt(0),c.Keyboard.NUMPAD_0=96,c.Keyboard.NUMPAD_1=97,c.Keyboard.NUMPAD_2=98,c.Keyboard.NUMPAD_3=99,c.Keyboard.NUMPAD_4=100,c.Keyboard.NUMPAD_5=101,c.Keyboard.NUMPAD_6=102,c.Keyboard.NUMPAD_7=103,c.Keyboard.NUMPAD_8=104,c.Keyboard.NUMPAD_9=105,c.Keyboard.NUMPAD_MULTIPLY=106,c.Keyboard.NUMPAD_ADD=107,c.Keyboard.NUMPAD_ENTER=108,c.Keyboard.NUMPAD_SUBTRACT=109,c.Keyboard.NUMPAD_DECIMAL=110,c.Keyboard.NUMPAD_DIVIDE=111,c.Keyboard.F1=112,c.Keyboard.F2=113,c.Keyboard.F3=114,c.Keyboard.F4=115,c.Keyboard.F5=116,c.Keyboard.F6=117,c.Keyboard.F7=118,c.Keyboard.F8=119,c.Keyboard.F9=120,c.Keyboard.F10=121,c.Keyboard.F11=122,c.Keyboard.F12=123,c.Keyboard.F13=124,c.Keyboard.F14=125,c.Keyboard.F15=126,c.Keyboard.COLON=186,c.Keyboard.EQUALS=187,c.Keyboard.UNDERSCORE=189,c.Keyboard.QUESTION_MARK=191,c.Keyboard.TILDE=192,c.Keyboard.OPEN_BRACKET=219,c.Keyboard.BACKWARD_SLASH=220,c.Keyboard.CLOSED_BRACKET=221,c.Keyboard.QUOTES=222,c.Keyboard.BACKSPACE=8,c.Keyboard.TAB=9,c.Keyboard.CLEAR=12,c.Keyboard.ENTER=13,c.Keyboard.SHIFT=16,c.Keyboard.CONTROL=17,c.Keyboard.ALT=18,c.Keyboard.CAPS_LOCK=20,c.Keyboard.ESC=27,c.Keyboard.SPACEBAR=32,c.Keyboard.PAGE_UP=33,c.Keyboard.PAGE_DOWN=34,c.Keyboard.END=35,c.Keyboard.HOME=36,c.Keyboard.LEFT=37,c.Keyboard.UP=38,c.Keyboard.RIGHT=39,c.Keyboard.DOWN=40,c.Keyboard.INSERT=45,c.Keyboard.DELETE=46,c.Keyboard.HELP=47,c.Keyboard.NUM_LOCK=144,c.Mouse=function(a){this.game=a,this.callbackContext=this.game,this.mouseDownCallback=null,this.mouseMoveCallback=null,this.mouseUpCallback=null,this.capture=!1,this.button=-1,this.disabled=!1,this.locked=!1,this.pointerLock=new c.Signal,this.event=null,this._onMouseDown=null,this._onMouseMove=null,this._onMouseUp=null},c.Mouse.NO_BUTTON=-1,c.Mouse.LEFT_BUTTON=0,c.Mouse.MIDDLE_BUTTON=1,c.Mouse.RIGHT_BUTTON=2,c.Mouse.prototype={start:function(){var a=this;this.game.device.android&&this.game.device.chrome===!1||(this._onMouseDown=function(b){return a.onMouseDown(b)},this._onMouseMove=function(b){return a.onMouseMove(b)},this._onMouseUp=function(b){return a.onMouseUp(b)},document.addEventListener("mousedown",this._onMouseDown,!0),document.addEventListener("mousemove",this._onMouseMove,!0),document.addEventListener("mouseup",this._onMouseUp,!0))},onMouseDown:function(a){this.event=a,this.capture&&a.preventDefault(),this.button=a.which,this.mouseDownCallback&&this.mouseDownCallback.call(this.callbackContext,a),this.game.input.disabled||this.disabled||(a.identifier=0,this.game.input.mousePointer.start(a))},onMouseMove:function(a){this.event=a,this.capture&&a.preventDefault(),this.mouseMoveCallback&&this.mouseMoveCallback.call(this.callbackContext,a),this.game.input.disabled||this.disabled||(a.identifier=0,this.game.input.mousePointer.move(a))},onMouseUp:function(a){this.event=a,this.capture&&a.preventDefault(),this.button=c.Mouse.NO_BUTTON,this.mouseUpCallback&&this.mouseUpCallback.call(this.callbackContext,a),this.game.input.disabled||this.disabled||(a.identifier=0,this.game.input.mousePointer.stop(a))},requestPointerLock:function(){if(this.game.device.pointerLock){var a=this.game.stage.canvas;a.requestPointerLock=a.requestPointerLock||a.mozRequestPointerLock||a.webkitRequestPointerLock,a.requestPointerLock();var b=this;this._pointerLockChange=function(a){return b.pointerLockChange(a)},document.addEventListener("pointerlockchange",this._pointerLockChange,!0),document.addEventListener("mozpointeLine truncated
},_pollGamepads:function(){var a=navigator.webkitGetGamepads&&navigator.webkitGetGamepads()||navigator.webkitGamepads;if(a){this._rawPads=[];for(var b=!1,c=0;c<a.length&&(typeof a[c]!==this._prevRawGamepadTypes[c]&&(b=!0,this._prevRawGamepadTypes[c]=typeof a[c]),a[c]&&this._rawPads.push(a[c]),3!==c);c++);if(b){for(var d,e={rawIndices:{},padIndices:{}},f=0;f<this._gamepads.length;f++)if(d=this._gamepads[f],d.connected)for(var g=0;g<this._rawPads.length;g++)this._rawPads[g].index===d.index&&(e.rawIndices[d.index]=!0,e.padIndices[f]=!0);for(var h=0;h<this._gamepads.length;h++)if(d=this._gamepads[h],!e.padIndices[h]){this._rawPads.length<1&&d.disconnect();for(var i=0;i<this._rawPads.length&&!e.padIndices[h];i++){var j=this._rawPads[i];if(j){if(e.rawIndices[j.index]){d.disconnect();continue}d.connect(j),e.rawIndices[j.index]=!0,e.padIndices[h]=!0}else d.disconnect()}}}}},setDeadZones:function(a){for(var b=0;b<this._gamepads.length;b++)this._gamepads[b].deadZone=a},stop:function(){this._active=!1,window.removeEventListener("gamepadconnected",this._ongamepadconnected),window.removeEventListener("gamepaddisconnected",this._ongamepaddisconnected)},reset:function(){this.update();for(var a=0;a<this._gamepads.length;a++)this._gamepads[a].reset()},justPressed:function(a,b){for(var c=0;c<this._gamepads.length;c++)if(this._gamepads[c].justPressed(a,b)===!0)return!0;return!1},justReleased:function(a,b){for(var c=0;c<this._gamepads.length;c++)if(this._gamepads[c].justReleased(a,b)===!0)return!0;return!1},isDown:function(a){for(var b=0;b<this._gamepads.length;b++)if(this._gamepads[b].isDown(a)===!0)return!0;return!1}},c.Gamepad.prototype.constructor=c.Gamepad,Object.defineProperty(c.Gamepad.prototype,"active",{get:function(){return this._active}}),Object.defineProperty(c.Gamepad.prototype,"supported",{get:function(){return this._gamepadSupportAvailable}}),Object.defineProperty(c.Gamepad.prototype,"padsConnected",{get:function(){return this._rawPads.length}}),Object.defineProperty(c.Gamepad.prototype,"pad1",{get:function(){return this._gamepads[0]}}),Object.defineProperty(c.Gamepad.prototype,"pad2",{get:function(){return this._gamepads[1]}}),Object.defineProperty(c.Gamepad.prototype,"pad3",{get:function(){return this._gamepads[2]}}),Object.defineProperty(c.Gamepad.prototype,"pad4",{get:function(){return this._gamepads[3]}}),c.Gamepad.BUTTON_0=0,c.Gamepad.BUTTON_1=1,c.Gamepad.BUTTON_2=2,c.Gamepad.BUTTON_3=3,c.Gamepad.BUTTON_4=4,c.Gamepad.BUTTON_5=5,c.Gamepad.BUTTON_6=6,c.Gamepad.BUTTON_7=7,c.Gamepad.BUTTON_8=8,c.Gamepad.BUTTON_9=9,c.Gamepad.BUTTON_10=10,c.Gamepad.BUTTON_11=11,c.Gamepad.BUTTON_12=12,c.Gamepad.BUTTON_13=13,c.Gamepad.BUTTON_14=14,c.Gamepad.BUTTON_15=15,c.Gamepad.AXIS_0=0,c.Gamepad.AXIS_1=1,c.Gamepad.AXIS_2=2,c.Gamepad.AXIS_3=3,c.Gamepad.AXIS_4=4,c.Gamepad.AXIS_5=5,c.Gamepad.AXIS_6=6,c.Gamepad.AXIS_7=7,c.Gamepad.AXIS_8=8,c.Gamepad.AXIS_9=9,c.Gamepad.XBOX360_A=0,c.Gamepad.XBOX360_B=1,c.Gamepad.XBOX360_X=2,c.Gamepad.XBOX360_Y=3,c.Gamepad.XBOX360_LEFT_BUMPER=4,c.Gamepad.XBOX360_RIGHT_BUMPER=5,c.Gamepad.XBOX360_LEFT_TRIGGER=6,c.Gamepad.XBOX360_RIGHT_TRIGGER=7,c.Gamepad.XBOX360_BACK=8,c.Gamepad.XBOX360_START=9,c.Gamepad.XBOX360_STICK_LEFT_BUTTON=10,c.Gamepad.XBOX360_STICK_RIGHT_BUTTON=11,c.Gamepad.XBOX360_DPAD_LEFT=14,c.Gamepad.XBOX360_DPAD_RIGHT=15,c.Gamepad.XBOX360_DPAD_UP=12,c.Gamepad.XBOX360_DPAD_DOWN=13,c.Gamepad.XBOX360_STICK_LEFT_X=0,c.Gamepad.XBOX360_STICK_LEFT_Y=1,c.Gamepad.XBOX360_STICK_RIGHT_X=2,c.Gamepad.XBOX360_STICK_RIGHT_Y=3,c.SinglePad=function(a,b){this.game=a,this._padParent=b,this._index=null,this._rawPad=null,this._connected=!1,this._prevTimestamp=null,this._rawButtons=[],this._buttons=[],this._axes=[],this._hotkeys=[],this.callbackContext=this,this.onConnectCallback=null,this.onDisconnectCallback=null,this.onDownCallback=null,this.onUpCallback=null,this.onAxisCallback=null,this.onFloatCallback=null,this.deadZone=.26},c.SinglePad.prototype={addCallbacks:function(a,b){"undefined"!=typeof b&&(this.onConnectCallback="function"==typeof b.onConnect?b.onConnect:this.onConnectCallback,this.onDisconnectCallback="function"==typeof b.onDisconnect?b.onDisconnect:this.onDisconnectCallback,this.onDownCallback="function"==typeof b.onDown?b.onDown:this.onDownCallback,this.onUpCallback="function"==typeof b.onUp?b.onUp:this.onUpCallback,this.onAxisCallback="function"==typeof b.onAxis?b.onAxis:this.onAxisCallback,this.onFloatCallback="function"==typeof b.onFloat?b.onFloat:this.onFloatCallback)},addButton:function(a){return this._hotkeys[a]=new c.GamepadButton(this.game,a),this._hotkeys[a]},pollStatus:function(){if(!this._rawPad.timestamp||this._rawPad.timestamp!=this._prevTimestamp){for(var a=0;a<this._rawPad.buttons.length;a+=1){var b=this._rawPad.buttons[a];this._rawButtons[a]!==b&&(1===b?this.processButtonDown(a,b):0===b?this.processButtonUp(a,b):this.processButtonFloat(a,b),this._rawButtons[a]=b)}for(var c=this._rawPad.axes,d=0;d<c.length;d+=1){var e=c[d];e>0&&e>this.deadZone||0>e&&e<-this.deadZone?this.processALine truncated
}}),c.Text=function(a,d,e,f,g){d=d||0,e=e||0,f=f||"",g=g||"",this.game=a,this.exists=!0,this.alive=!0,this.group=null,this.name="",this.type=c.TEXT,this._text=f,this._style=g,b.Text.call(this,f,g),this.position.x=this.x=d,this.position.y=this.y=e,this.anchor=new c.Point,this.scale=new c.Point(1,1),this.fixedToCamera=!1,this.cameraOffset=new c.Point,this._cache={dirty:!1,a00:1,a01:0,a02:d,a10:0,a11:1,a12:e,id:1,x:-1,y:-1,scaleX:1,scaleY:1},this._cache.x=this.x,this._cache.y=this.y,this.renderable=!0},c.Text.prototype=Object.create(b.Text.prototype),c.Text.prototype.constructor=c.Text,c.Text.prototype.update=function(){this.exists&&(this.fixedToCamera&&(this.x=this.game.camera.view.x+this.cameraOffset.x,this.y=this.game.camera.view.y+this.cameraOffset.y),this._cache.dirty=!1,this._cache.x=this.x,this._cache.y=this.y,(this.position.x!=this._cache.x||this.position.y!=this._cache.y)&&(this.position.x=this._cache.x,this.position.y=this._cache.y,this._cache.dirty=!0))},c.Text.prototype.destroy=function(){this.group&&this.group.remove(this),this.canvas.parentNode?this.canvas.parentNode.removeChild(this.canvas):(this.canvas=null,this.context=null),this.exists=!1,this.group=null},Object.defineProperty(c.Text.prototype,"angle",{get:function(){return c.Math.radToDeg(this.rotation)},set:function(a){this.rotation=c.Math.degToRad(a)}}),Object.defineProperty(c.Text.prototype,"x",{get:function(){return this.position.x},set:function(a){this.position.x=a}}),Object.defineProperty(c.Text.prototype,"y",{get:function(){return this.position.y},set:function(a){this.position.y=a}}),Object.defineProperty(c.Text.prototype,"content",{get:function(){return this._text},set:function(a){a!==this._text&&(this._text=a,this.setText(a))}}),Object.defineProperty(c.Text.prototype,"font",{get:function(){return this._style},set:function(a){a!==this._style&&(this._style=a,this.setStyle(a))}}),c.BitmapText=function(a,d,e,f,g){d=d||0,e=e||0,f=f||"",g=g||"",this.game=a,this.exists=!0,this.alive=!0,this.group=null,this.name="",this.type=c.BITMAPTEXT,b.BitmapText.call(this,f,g),this.position.x=d,this.position.y=e,this.anchor=new c.Point,this.scale=new c.Point(1,1),this._cache={dirty:!1,a00:1,a01:0,a02:d,a10:0,a11:1,a12:e,id:1,x:-1,y:-1,scaleX:1,scaleY:1},this._cache.x=this.x,this._cache.y=this.y},c.BitmapText.prototype=Object.create(b.BitmapText.prototype),c.BitmapText.prototype.constructor=c.BitmapText,c.BitmapText.prototype.update=function(){this.exists&&(this._cache.dirty=!1,this._cache.x=this.x,this._cache.y=this.y,(this.position.x!=this._cache.x||this.position.y!=this._cache.y)&&(this.position.x=this._cache.x,this.position.y=this._cache.y,this._cache.dirty=!0),this.pivot.x=this.anchor.x*this.width,this.pivot.y=this.anchor.y*this.height)},c.BitmapText.prototype.destroy=function(){this.group&&this.group.remove(this),this.canvas&&this.canvas.parentNode?this.canvas.parentNode.removeChild(this.canvas):(this.canvas=null,this.context=null),this.exists=!1,this.group=null},Object.defineProperty(c.BitmapText.prototype,"angle",{get:function(){return c.Math.radToDeg(this.rotation)},set:function(a){this.rotation=c.Math.degToRad(a)}}),Object.defineProperty(c.BitmapText.prototype,"x",{get:function(){return this.position.x},set:function(a){this.position.x=a}}),Object.defineProperty(c.BitmapText.prototype,"y",{get:function(){return this.position.y},set:function(a){this.position.y=a}}),c.Button=function(a,b,d,e,f,g,h,i,j,k){b=b||0,d=d||0,e=e||null,f=f||null,g=g||this,c.Sprite.call(this,a,b,d,e,i),this.type=c.BUTTON,this._onOverFrameName=null,this._onOutFrameName=null,this._onDownFrameName=null,this._onUpFrameName=null,this._onOverFrameID=null,this._onOutFrameID=null,this._onDownFrameID=null,this._onUpFrameID=null,this.onOverSound=null,this.onOutSound=null,this.onDownSound=null,this.onUpSound=null,this.onOverSoundMarker="",this.onOutSoundMarker="",this.onDownSoundMarker="",this.onUpSoundMarker="",this.onInputOver=new c.Signal,this.onInputOut=new c.Signal,this.onInputDown=new c.Signal,this.onInputUp=new c.Signal,this.freezeFrames=!1,this.forceOut=!1,this.setFrames(h,i,j,k),null!==f&&this.onInputUp.add(f,g),this.input.start(0,!0),this.events.onInputOver.add(this.onInputOverHandler,this),this.events.onInputOut.add(this.onInputOutHandler,this),this.events.onInputDown.add(this.onInputDownHandler,this),this.events.onInputUp.add(this.onInputUpHandler,this)},c.Button.prototype=Object.create(c.Sprite.prototype),c.Button.prototype=c.Utils.extend(!0,c.Button.prototype,c.Sprite.prototype,b.Sprite.prototype),c.Button.prototype.constructor=c.Button,c.Button.prototype.clearFrames=function(){this._onOverFrameName=null,this._onOverFrameID=null,this._onOutFrameName=null,this._onOutFrameID=null,this._onDownFrameName=null,this._onDownFrameID=null,this._onUpFrameName=null,this._onUpFrameID=null},c.Button.prototype.setFrames=function(a,b,c,d){this.clearFrames(),null!==a&&("string"==typeof a?(this._onOverFrameName=a,this.input.pointerOver()&&(this.frameName=a)):(this._onOverFrameID=a,thisLine truncated
for(var d=1;b[d]<a;)d++;var e=b[d-1],f=d<b.length?b[d]:Number.POSITIVE_INFINITY;return a-e>=f-a?f:e},roundTo:function(a,b,c){"undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=10);var d=Math.pow(c,-b);return Math.round(a*d)/d},floorTo:function(a,b,c){"undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=10);var d=Math.pow(c,-b);return Math.floor(a*d)/d},ceilTo:function(a,b,c){"undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=10);var d=Math.pow(c,-b);return Math.ceil(a*d)/d},interpolateFloat:function(a,b,c){return(b-a)*c+a},angleBetween:function(a,b,c,d){return Math.atan2(d-b,c-a)},normalizeAngle:function(a,b){"undefined"==typeof b&&(b=!0);var c=b?Math.PI:180;return this.wrap(a,-c,c)},nearestAngleBetween:function(a,b,c){"undefined"==typeof c&&(c=!0);var d=c?Math.PI:180;return a=this.normalizeAngle(a,c),b=this.normalizeAngle(b,c),-d/2>a&&b>d/2&&(a+=2*d),-d/2>b&&a>d/2&&(b+=2*d),b-a},interpolateAngles:function(a,b,c,d,e){return"undefined"==typeof d&&(d=!0),"undefined"==typeof e&&(e=null),a=this.normalizeAngle(a,d),b=this.normalizeAngleToAnother(b,a,d),"function"==typeof e?e(c,a,b-a,1):this.interpolateFloat(a,b,c)},chanceRoll:function(a){return"undefined"==typeof a&&(a=50),0>=a?!1:a>=100?!0:100*Math.random()>=a?!1:!0},numberArray:function(a,b){for(var c=[],d=a;b>=d;d++)c.push(d);return c},maxAdd:function(a,b,c){return a+=b,a>c&&(a=c),a},minSub:function(a,b,c){return a-=b,c>a&&(a=c),a},wrap:function(a,b,c){var d=c-b;if(0>=d)return 0;var e=(a-b)%d;return 0>e&&(e+=d),e+b},wrapValue:function(a,b,c){var d;return a=Math.abs(a),b=Math.abs(b),c=Math.abs(c),d=(a+b)%c},randomSign:function(){return Math.random()>.5?1:-1},isOdd:function(a){return 1&a},isEven:function(a){return 1&a?!1:!0},max:function(){for(var a=1,b=0,c=arguments.length;c>a;a++)arguments[b]<arguments[a]&&(b=a);return arguments[b]},min:function(){for(var a=1,b=0,c=arguments.length;c>a;a++)arguments[a]<arguments[b]&&(b=a);return arguments[b]},wrapAngle:function(a){return this.wrap(a,-180,180)},angleLimit:function(a,b,c){var d=a;return a>c?d=c:b>a&&(d=b),d},linearInterpolation:function(a,b){var c=a.length-1,d=c*b,e=Math.floor(d);return 0>b?this.linear(a[0],a[1],d):b>1?this.linear(a[c],a[c-1],c-d):this.linear(a[e],a[e+1>c?c:e+1],d-e)},bezierInterpolation:function(a,b){for(var c=0,d=a.length-1,e=0;d>=e;e++)c+=Math.pow(1-b,d-e)*Math.pow(b,e)*a[e]*this.bernstein(d,e);return c},catmullRomInterpolation:function(a,b){var c=a.length-1,d=c*b,e=Math.floor(d);return a[0]===a[c]?(0>b&&(e=Math.floor(d=c*(1+b))),this.catmullRom(a[(e-1+c)%c],a[e],a[(e+1)%c],a[(e+2)%c],d-e)):0>b?a[0]-(this.catmullRom(a[0],a[0],a[1],a[1],-d)-a[0]):b>1?a[c]-(this.catmullRom(a[c],a[c],a[c-1],a[c-1],d-c)-a[c]):this.catmullRom(a[e?e-1:0],a[e],a[e+1>c?c:e+1],a[e+2>c?c:e+2],d-e)},linear:function(a,b,c){return(b-a)*c+a},bernstein:function(a,b){return this.factorial(a)/this.factorial(b)/this.factorial(a-b)},catmullRom:function(a,b,c,d,e){var f=.5*(c-a),g=.5*(d-b),h=e*e,i=e*h;return(2*b-2*c+f+g)*i+(-3*b+3*c-2*f-g)*h+f*e+b},difference:function(a,b){return Math.abs(a-b)},getRandom:function(a,b,c){if("undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=0),null!=a){var d=c;if((0===d||d>a.length-b)&&(d=a.length-b),d>0)return a[b+Math.floor(Math.random()*d)]}return null},floor:function(a){var b=0|a;return a>0?b:b!=a?b-1:b},ceil:function(a){var b=0|a;return a>0?b!=a?b+1:b:b},sinCosGenerator:function(a,b,c,d){"undefined"==typeof b&&(b=1),"undefined"==typeof c&&(c=1),"undefined"==typeof d&&(d=1);for(var e=b,f=c,g=d*Math.PI/a,h=[],i=[],j=0;a>j;j++)f-=e*g,e+=f*g,h[j]=f,i[j]=e;return{sin:i,cos:h,length:a}},shift:function(a){var b=a.shift();return a.push(b),b},shuffleArray:function(a){for(var b=a.length-1;b>0;b--){var c=Math.floor(Math.random()*(b+1)),d=a[b];a[b]=a[c],a[c]=d}return a},distance:function(a,b,c,d){var e=a-c,f=b-d;return Math.sqrt(e*e+f*f)},distanceRounded:function(a,b,d,e){return Math.round(c.Math.distance(a,b,d,e))},clamp:function(a,b,c){return b>a?b:a>c?c:a},clampBottom:function(a,b){return b>a?b:a},within:function(a,b,c){return Math.abs(a-b)<=c},mapLinear:function(a,b,c,d,e){return d+(a-b)*(e-d)/(c-b)},smoothstep:function(a,b,c){return b>=a?0:a>=c?1:(a=(a-b)/(c-b),a*a*(3-2*a))},smootherstep:function(a,b,c){return b>=a?0:a>=c?1:(a=(a-b)/(c-b),a*a*a*(a*(6*a-15)+10))},sign:function(a){return 0>a?-1:a>0?1:0},degToRad:function(){var a=Math.PI/180;return function(b){return b*a}}(),radToDeg:function(){var a=180/Math.PI;return function(b){return b*a}}()},c.QuadTree=function(a,b,c,d,e,f,g){this.maxObjects=e||10,this.maxLevels=f||4,this.level=g||0,this.bounds={x:Math.round(a),y:Math.round(b),width:c,height:d,subWidth:Math.floor(c/2),subHeight:Math.floor(d/2),right:Math.round(a)+Math.floor(c/2),bottom:Math.round(b)+Math.floor(d/2)},this.objects=[],this.nodes=[]},c.QuadTree.prototype={populate:function(a){a.forEach(this.populateHandler,this,!0)},populateHandler:function(a){a.body&&a.body.allowCollision.none===!1&&a.alive&&this.insert(a.body)},split:function(){this.level++,this.nodes[0]=new c.QuadTLine truncated
if(this.currentAnim.isPlaying===!1)return this.currentAnim.paused=!1,this.currentAnim.play(b,c,d)}},stop:function(a,b){"undefined"==typeof b&&(b=!1),"string"==typeof a?this._anims[a]&&(this.currentAnim=this._anims[a],this.currentAnim.stop(b)):this.currentAnim&&this.currentAnim.stop(b)},update:function(){return this.updateIfVisible&&this.sprite.visible===!1?!1:this.currentAnim&&this.currentAnim.update()===!0?(this.currentFrame=this.currentAnim.currentFrame,this.sprite.currentFrame=this.currentFrame,!0):!1},getAnimation:function(a){return"string"==typeof a&&this._anims[a]?this._anims[a]:!1},refreshFrame:function(){this.sprite.currentFrame=this.currentFrame,this.sprite.setTexture(b.TextureCache[this.currentFrame.uuid])},destroy:function(){this._anims={},this._frameData=null,this._frameIndex=0,this.currentAnim=null,this.currentFrame=null}},c.AnimationManager.prototype.constructor=c.AnimationManager,Object.defineProperty(c.AnimationManager.prototype,"frameData",{get:function(){return this._frameData}}),Object.defineProperty(c.AnimationManager.prototype,"frameTotal",{get:function(){return this._frameData?this._frameData.total:-1}}),Object.defineProperty(c.AnimationManager.prototype,"paused",{get:function(){return this.currentAnim.isPaused},set:function(a){this.currentAnim.paused=a}}),Object.defineProperty(c.AnimationManager.prototype,"frame",{get:function(){return this.currentFrame?this._frameIndex:void 0},set:function(a){"number"==typeof a&&this._frameData&&null!==this._frameData.getFrame(a)&&(this.currentFrame=this._frameData.getFrame(a),this._frameIndex=a,this.sprite.currentFrame=this.currentFrame,this.sprite.setTexture(b.TextureCache[this.currentFrame.uuid]))}}),Object.defineProperty(c.AnimationManager.prototype,"frameName",{get:function(){return this.currentFrame?this.currentFrame.name:void 0},set:function(a){"string"==typeof a&&this._frameData&&null!==this._frameData.getFrameByName(a)?(this.currentFrame=this._frameData.getFrameByName(a),this._frameIndex=this.currentFrame.index,this.sprite.currentFrame=this.currentFrame,this.sprite.setTexture(b.TextureCache[this.currentFrame.uuid])):console.warn("Cannot set frameName: "+a)}}),c.Animation=function(a,b,c,d,e,f,g){this.game=a,this._parent=b,this._frameData=d,this.name=c,this._frames=[],this._frames=this._frames.concat(e),this.delay=1e3/f,this.looped=g,this.killOnComplete=!1,this.isFinished=!1,this.isPlaying=!1,this.isPaused=!1,this._pauseStartTime=0,this._frameIndex=0,this._frameDiff=0,this._frameSkip=1,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex])},c.Animation.prototype={play:function(a,c,d){return"number"==typeof a&&(this.delay=1e3/a),"boolean"==typeof c&&(this.looped=c),"undefined"!=typeof d&&(this.killOnComplete=d),this.isPlaying=!0,this.isFinished=!1,this.paused=!1,this._timeLastFrame=this.game.time.now,this._timeNextFrame=this.game.time.now+this.delay,this._frameIndex=0,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex]),this._parent.setTexture(b.TextureCache[this.currentFrame.uuid]),this._parent.events&&this._parent.events.onAnimationStart.dispatch(this._parent,this),this},restart:function(){this.isPlaying=!0,this.isFinished=!1,this.paused=!1,this._timeLastFrame=this.game.time.now,this._timeNextFrame=this.game.time.now+this.delay,this._frameIndex=0,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex])},stop:function(a){"undefined"==typeof a&&(a=!1),this.isPlaying=!1,this.isFinished=!0,this.paused=!1,a&&(this.currentFrame=this._frameData.getFrame(this._frames[0]))},update:function(){return this.isPaused?!1:this.isPlaying===!0&&this.game.time.now>=this._timeNextFrame?(this._frameSkip=1,this._frameDiff=this.game.time.now-this._timeNextFrame,this._timeLastFrame=this.game.time.now,this._frameDiff>this.delay&&(this._frameSkip=Math.floor(this._frameDiff/this.delay),this._frameDiff-=this._frameSkip*this.delay),this._timeNextFrame=this.game.time.now+(this.delay-this._frameDiff),this._frameIndex+=this._frameSkip,this._frameIndex>=this._frames.length?this.looped?(this._frameIndex%=this._frames.length,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex]),this.currentFrame&&this._parent.setTexture(b.TextureCache[this.currentFrame.uuid]),this._parent.events.onAnimationLoop.dispatch(this._parent,this)):this.onComplete():(this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex]),this.currentFrame&&this._parent.setTexture(b.TextureCache[this.currentFrame.uuid])),!0):!1},destroy:function(){this.game=null,this._parent=null,this._frames=null,this._frameData=null,this.currentFrame=null,this.isPlaying=!1},onComplete:function(){this.isPlaying=!1,this.isFinished=!0,this.paused=!1,this._parent.events&&this._parent.events.onAnimationComplete.dispatch(this._parent,this),this.killOnComplete&&this._parent.kill()}},c.Animation.prototype.constructor=c.Animation,Object.defineProperty(c.Animation.prototype,"paused",{get:function(){return this.isPaused},set:function(a){this.isPLine truncated
},c.Sound.prototype={soundHasUnlocked:function(a){a==this.key&&(this._sound=this.game.cache.getSoundData(this.key),this.totalDuration=this._sound.duration)},addMarker:function(a,b,c,d,e){d=d||1,"undefined"==typeof e&&(e=!1),this.markers[a]={name:a,start:b,stop:b+c,volume:d,duration:c,durationMS:1e3*c,loop:e}},removeMarker:function(a){delete this.markers[a]},update:function(){this.pendingPlayback&&this.game.cache.isSoundReady(this.key)&&(this.pendingPlayback=!1,this.play(this._tempMarker,this._tempPosition,this._tempVolume,this._tempLoop)),this.isPlaying&&(this.currentTime=this.game.time.now-this.startTime,this.currentTime>=this.durationMS&&(this.usingWebAudio?this.loop?(this.onLoop.dispatch(this),""===this.currentMarker?(this.currentTime=0,this.startTime=this.game.time.now):this.play(this.currentMarker,0,this.volume,!0,!0)):this.stop():this.loop?(this.onLoop.dispatch(this),this.play(this.currentMarker,0,this.volume,!0,!0)):this.stop()))},play:function(a,b,c,d,e){if(a=a||"",b=b||0,"undefined"==typeof c&&(c=this._volume),"undefined"==typeof d&&(d=!1),"undefined"==typeof e&&(e=!0),this.isPlaying!==!0||e!==!1||this.override!==!1){if(this.isPlaying&&this.override&&(this.usingWebAudio?"undefined"==typeof this._sound.stop?this._sound.noteOff(0):this._sound.stop(0):this.usingAudioTag&&(this._sound.pause(),this._sound.currentTime=0)),this.currentMarker=a,""!==a){if(!this.markers[a])return console.warn("Phaser.Sound.play: audio marker "+a+" doesn't exist"),void 0;this.position=this.markers[a].start,this.volume=this.markers[a].volume,this.loop=this.markers[a].loop,this.duration=this.markers[a].duration,this.durationMS=this.markers[a].durationMS,this._tempMarker=a,this._tempPosition=this.position,this._tempVolume=this.volume,this._tempLoop=this.loop}else this.position=b,this.volume=c,this.loop=d,this.duration=0,this.durationMS=0,this._tempMarker=a,this._tempPosition=b,this._tempVolume=c,this._tempLoop=d;this.usingWebAudio?this.game.cache.isSoundDecoded(this.key)?(null==this._buffer&&(this._buffer=this.game.cache.getSoundData(this.key)),this._sound=this.context.createBufferSource(),this._sound.buffer=this._buffer,this.externalNode?this._sound.connect(this.externalNode.input):this._sound.connect(this.gainNode),this.totalDuration=this._sound.buffer.duration,0===this.duration&&(this.duration=this.totalDuration,this.durationMS=1e3*this.totalDuration),this.loop&&""===a&&(this._sound.loop=!0),"undefined"==typeof this._sound.start?this._sound.noteGrainOn(0,this.position,this.duration):this._sound.start(0,this.position,this.duration),this.isPlaying=!0,this.startTime=this.game.time.now,this.currentTime=0,this.stopTime=this.startTime+this.durationMS,this.onPlay.dispatch(this)):(this.pendingPlayback=!0,this.game.cache.getSound(this.key)&&this.game.cache.getSound(this.key).isDecoding===!1&&this.game.sound.decode(this.key,this)):this.game.cache.getSound(this.key)&&this.game.cache.getSound(this.key).locked?(this.game.cache.reloadSound(this.key),this.pendingPlayback=!0):this._sound&&(this.game.device.cocoonJS||4===this._sound.readyState)?(this._sound.play(),this.totalDuration=this._sound.duration,0===this.duration&&(this.duration=this.totalDuration,this.durationMS=1e3*this.totalDuration),this._sound.currentTime=this.position,this._sound.muted=this._muted,this._sound.volume=this._muted?0:this._volume,this.isPlaying=!0,this.startTime=this.game.time.now,this.currentTime=0,this.stopTime=this.startTime+this.durationMS,this.onPlay.dispatch(this)):this.pendingPlayback=!0}},restart:function(a,b,c,d){a=a||"",b=b||0,c=c||1,"undefined"==typeof d&&(d=!1),this.play(a,b,c,d,!0)},pause:function(){this.isPlaying&&this._sound&&(this.stop(),this.isPlaying=!1,this.paused=!0,this.pausedPosition=this.currentTime,this.pausedTime=this.game.time.now,this.onPause.dispatch(this))},resume:function(){if(this.paused&&this._sound){if(this.usingWebAudio){var a=this.position+this.pausedPosition/1e3;this._sound=this.context.createBufferSource(),this._sound.buffer=this._buffer,this.externalNode?this._sound.connect(this.externalNode.input):this._sound.connect(this.gainNode),this.loop&&(this._sound.loop=!0),"undefined"==typeof this._sound.start?this._sound.noteGrainOn(0,a,this.duration):this._sound.start(0,a,this.duration)}else this._sound.play();this.isPlaying=!0,this.paused=!1,this.startTime+=this.game.time.now-this.pausedTime,this.onResume.dispatch(this)}},stop:function(){this.isPlaying&&this._sound&&(this.usingWebAudio?"undefined"==typeof this._sound.stop?this._sound.noteOff(0):this._sound.stop(0):this.usingAudioTag&&(this._sound.pause(),this._sound.currentTime=0)),this.isPlaying=!1;var a=this.currentMarker;this.currentMarker="",this.onStop.dispatch(this,a)}},c.Sound.prototype.constructor=c.Sound,Object.defineProperty(c.Sound.prototype,"isDecoding",{get:function(){return this.game.cache.getSound(this.key).isDecoding}}),Object.defineProperty(c.Sound.prototype,"isDecoded",{get:function(){return this.game.cache.isSoundDecoded(this.key)}}),Object.defineProperty(c.SoundLine truncated
},separateTiles:function(a,b){if(a.immovable)return!1;a.overlapX=0,a.overlapY=0;for(var d,e=0,f=0,g=0;g<b.length;g++)d=b[g],c.Rectangle.intersects(a,d)&&(a.deltaX()<0&&a.allowCollision.left&&d.tile.faceRight?(e=a.x-d.right,e>=a.deltaX()&&(a.blocked.left=!0,a.touching.left=!0,a.touching.none=!1)):a.deltaX()>0&&a.allowCollision.right&&d.tile.faceLeft&&(e=a.right-d.x,e<=a.deltaX()&&(a.blocked.right=!0,a.touching.right=!0,a.touching.none=!1)),a.deltaY()<0&&a.allowCollision.up&&d.tile.faceBottom?(f=a.y-d.bottom,f>=a.deltaY()&&(a.blocked.up=!0,a.touching.up=!0,a.touching.none=!1)):a.deltaY()>0&&a.allowCollision.down&&d.tile.faceTop&&(f=a.bottom-d.y,f<=a.deltaY()&&(a.blocked.down=!0,a.touching.down=!0,a.touching.none=!1)));return 0!==e&&(a.overlapX=e),0!==f&&(a.overlapY=f),a.touching.none?!1:((a.touching.left||a.touching.right)&&(a.x-=a.overlapX,a.preX-=a.overlapX,a.velocity.x=0===a.bounce.x?0:-a.velocity.x*a.bounce.x),(a.touching.up||a.touching.down)&&(a.y-=a.overlapY,a.preY-=a.overlapY,a.velocity.y=0===a.bounce.y?0:-a.velocity.y*a.bounce.y),!0)},separateTile:function(a,b){return a.immovable||c.Rectangle.intersects(a,b)===!1?!1:(a.overlapX=0,a.overlapY=0,a.deltaX()<0&&a.allowCollision.left&&b.tile.faceRight?(a.overlapX=a.x-b.right,a.overlapX>=a.deltaX()&&(a.blocked.left=!0,a.touching.left=!0,a.touching.none=!1)):a.deltaX()>0&&a.allowCollision.right&&b.tile.faceLeft&&(a.overlapX=a.right-b.x,a.overlapX<=a.deltaX()&&(a.blocked.right=!0,a.touching.right=!0,a.touching.none=!1)),a.deltaY()<0&&a.allowCollision.up&&b.tile.faceBottom?(a.overlapY=a.y-b.bottom,a.overlapY>=a.deltaY()&&(a.blocked.up=!0,a.touching.up=!0,a.touching.none=!1)):a.deltaY()>0&&a.allowCollision.down&&b.tile.faceTop&&(a.overlapY=a.bottom-b.y,a.overlapY<=a.deltaY()&&(a.blocked.down=!0,a.touching.down=!0,a.touching.none=!1)),a.touching.none?!1:((a.touching.left||a.touching.right)&&(a.x-=a.overlapX,a.preX-=a.overlapX,a.velocity.x=0===a.bounce.x?0:-a.velocity.x*a.bounce.x),(a.touching.up||a.touching.down)&&(a.y-=a.overlapY,a.preY-=a.overlapY,a.velocity.y=0===a.bounce.y?0:-a.velocity.y*a.bounce.y),!0))},moveToObject:function(a,b,c,d){return"undefined"==typeof c&&(c=60),"undefined"==typeof d&&(d=0),this._angle=Math.atan2(b.y-a.y,b.x-a.x),d>0&&(c=this.distanceBetween(a,b)/(d/1e3)),a.body.velocity.x=Math.cos(this._angle)*c,a.body.velocity.y=Math.sin(this._angle)*c,this._angle},moveToPointer:function(a,b,c,d){return"undefined"==typeof b&&(b=60),c=c||this.game.input.activePointer,"undefined"==typeof d&&(d=0),this._angle=this.angleToPointer(a,c),d>0&&(b=this.distanceToPointer(a,c)/(d/1e3)),a.body.velocity.x=Math.cos(this._angle)*b,a.body.velocity.y=Math.sin(this._angle)*b,this._angle},moveToXY:function(a,b,c,d,e){return"undefined"==typeof d&&(d=60),"undefined"==typeof e&&(e=0),this._angle=Math.atan2(c-a.y,b-a.x),e>0&&(d=this.distanceToXY(a,b,c)/(e/1e3)),a.body.velocity.x=Math.cos(this._angle)*d,a.body.velocity.y=Math.sin(this._angle)*d,this._angle},velocityFromAngle:function(a,b,d){return"undefined"==typeof b&&(b=60),d=d||new c.Point,d.setTo(Math.cos(this.game.math.degToRad(a))*b,Math.sin(this.game.math.degToRad(a))*b)},velocityFromRotation:function(a,b,d){return"undefined"==typeof b&&(b=60),d=d||new c.Point,d.setTo(Math.cos(a)*b,Math.sin(a)*b)},accelerationFromRotation:function(a,b,d){return"undefined"==typeof b&&(b=60),d=d||new c.Point,d.setTo(Math.cos(a)*b,Math.sin(a)*b)},accelerateToObject:function(a,b,c,d,e){return"undefined"==typeof c&&(c=60),"undefined"==typeof d&&(d=1e3),"undefined"==typeof e&&(e=1e3),this._angle=this.angleBetween(a,b),a.body.acceleration.setTo(Math.cos(this._angle)*c,Math.sin(this._angle)*c),a.body.maxVelocity.setTo(d,e),this._angle},accelerateToPointer:function(a,b,c,d,e){return"undefined"==typeof c&&(c=60),"undefined"==typeof b&&(b=this.game.input.activePointer),"undefined"==typeof d&&(d=1e3),"undefined"==typeof e&&(e=1e3),this._angle=this.angleToPointer(a,b),a.body.acceleration.setTo(Math.cos(this._angle)*c,Math.sin(this._angle)*c),a.body.maxVelocity.setTo(d,e),this._angle},accelerateToXY:function(a,b,c,d,e,f){return"undefined"==typeof d&&(d=60),"undefined"==typeof e&&(e=1e3),"undefined"==typeof f&&(f=1e3),this._angle=this.angleToXY(a,b,c),a.body.acceleration.setTo(Math.cos(this._angle)*d,Math.sin(this._angle)*d),a.body.maxVelocity.setTo(e,f),this._angle},distanceBetween:function(a,b){return this._dx=a.x-b.x,this._dy=a.y-b.y,Math.sqrt(this._dx*this._dx+this._dy*this._dy)},distanceToXY:function(a,b,c){return this._dx=a.x-b,this._dy=a.y-c,Math.sqrt(this._dx*this._dx+this._dy*this._dy)},distanceToPointer:function(a,b){return b=b||this.game.input.activePointer,this._dx=a.x-b.x,this._dy=a.y-b.y,Math.sqrt(this._dx*this._dx+this._dy*this._dy)},angleBetween:function(a,b){return this._dx=b.x-a.x,this._dy=b.y-a.y,Math.atan2(this._dy,this._dx)},angleToXY:function(a,b,c){return this._dx=b-a.x,this._dy=c-a.y,Math.atan2(this._dy,this._dx)},angleToPointer:function(a,b){return b=b||this.game.input.activePointer,this._dx=b.worldX-a.x,this._dy=b.worlLine truncated
this._tx=this._dx,this._ty+=this.map.tileHeight}return this.debug&&(this.context.globalAlpha=1,this.renderDebug()),this.game.renderType===c.WEBGL&&b.texturesToUpdate.push(this.baseTexture),this.dirty=!1,this.layer.dirty=!1,!0}},c.TilemapLayer.prototype.renderDebug=function(){this._tx=this._dx,this._ty=this._dy,this.context.strokeStyle=this.debugColor,this.context.fillStyle=this.debugFillColor;for(var a=this._startY,b=this._startY+this._maxY;b>a;a++){this._column=this.layer.data[a];for(var c=this._startX,d=this._startX+this._maxX;d>c;c++){var e=this._column[c];e&&(e.faceTop||e.faceBottom||e.faceLeft||e.faceRight)&&(this._tx=Math.floor(this._tx),this.debugFill&&this.context.fillRect(this._tx,this._ty,this._cw,this._ch),this.context.beginPath(),e.faceTop&&(this.context.moveTo(this._tx,this._ty),this.context.lineTo(this._tx+this._cw,this._ty)),e.faceBottom&&(this.context.moveTo(this._tx,this._ty+this._ch),this.context.lineTo(this._tx+this._cw,this._ty+this._ch)),e.faceLeft&&(this.context.moveTo(this._tx,this._ty),this.context.lineTo(this._tx,this._ty+this._ch)),e.faceRight&&(this.context.moveTo(this._tx+this._cw,this._ty),this.context.lineTo(this._tx+this._cw,this._ty+this._ch)),this.context.stroke()),this._tx+=this.map.tileWidth}this._tx=this._dx,this._ty+=this.map.tileHeight}},Object.defineProperty(c.TilemapLayer.prototype,"scrollX",{get:function(){return this._x},set:function(a){a!==this._x&&a>=0&&this.layer.widthInPixels>this.width&&(this._x=a,this._x>this.layer.widthInPixels-this.width&&(this._x=this.layer.widthInPixels-this.width),this._startX=this.game.math.floor(this._x/this.map.tileWidth),this._startX<0&&(this._startX=0),this._startX+this._maxX>this.layer.width&&(this._startX=this.layer.width-this._maxX),this.dirty=!0)}}),Object.defineProperty(c.TilemapLayer.prototype,"scrollY",{get:function(){return this._y},set:function(a){a!==this._y&&a>=0&&this.layer.heightInPixels>this.height&&(this._y=a,this._y>this.layer.heightInPixels-this.height&&(this._y=this.layer.heightInPixels-this.height),this._startY=this.game.math.floor(this._y/this.map.tileHeight),this._startY<0&&(this._startY=0),this._startY+this._maxY>this.layer.height&&(this._startY=this.layer.height-this._maxY),this.dirty=!0)}}),Object.defineProperty(c.TilemapLayer.prototype,"collisionWidth",{get:function(){return this._cw},set:function(a){this._cw=a,this.dirty=!0}}),Object.defineProperty(c.TilemapLayer.prototype,"collisionHeight",{get:function(){return this._ch},set:function(a){this._ch=a,this.dirty=!0}}),c.TilemapParser={tileset:function(a,b,d,e,f,g,h,i,j){var k=a.cache.getTilesetImage(b);if(null===k)return console.warn("Phaser.TilemapParser.tileSet: Invalid image key given"),null;var l=k.width,m=k.height;return-1===h&&(h=Math.round(l/d)),-1===i&&(i=Math.round(m/e)),-1===j&&(j=h*i),0===l||0===m||d>l||e>m||0===j?(console.warn("Phaser.TilemapParser.tileSet: width/height zero or width/height < given tileWidth/tileHeight"),null):new c.Tileset(k,b,d,e,f,g,h,i,j)},parse:function(a,b){var d=a.cache.getTilemapData(b);return d?d.format===c.Tilemap.CSV?this.parseCSV(d.data):d.format===c.Tilemap.TILED_JSON?this.parseTiledJSON(d.data):void 0:{layers:[],objects:[],images:[],tilesets:[]}},parseCSV:function(a){a=a.trim();for(var b=[],c=a.split("\n"),d=c.length,e=0,f=0;f<c.length;f++){b[f]=[];for(var g=c[f].split(","),h=0;h<g.length;h++)b[f][h]=parseInt(g[h],10);0===e&&(e=g.length)}return[{name:"csv",width:e,height:d,alpha:1,visible:!0,indexes:[],tileMargin:0,tileSpacing:0,data:b}]},parseTiledJSON:function(a){if("orthogonal"!==a.orientation)return console.warn("TilemapParser.parseTiledJSON: Only orthogonal map types are supported in this version of Phaser"),null;var b={};b.width=a.width,b.height=a.height,b.tileWidth=a.tilewidth,b.tileHeight=a.tileheight,b.orientation=a.orientation,b.version=a.version,b.properties=a.properties,b.widthInPixels=b.width*b.tileWidth,b.heightInPixels=b.height*b.tileHeight;for(var d=[],e=0;e<a.layers.length;e++)if("tilelayer"===a.layers[e].type){var f={name:a.layers[e].name,x:a.layers[e].x,y:a.layers[e].y,width:a.layers[e].width,height:a.layers[e].height,widthInPixels:a.layers[e].width*a.tilewidth,heightInPixels:a.layers[e].height*a.tileheight,alpha:a.layers[e].opacity,visible:a.layers[e].visible,properties:{},indexes:[]};a.layers[e].properties&&(f.properties=a.layers[e].properties);for(var g=0,h=[],i=[],j=0,k=a.layers[e].data.length;k>j;j++)a.layers[e].data[j]>0?h.push(new c.Tile(a.layers[e].data[j],g,i.length,a.tilewidth,a.tileheight)):h.push(null),g++,g===a.layers[e].width&&(i.push(h),g=0,h=[]);f.data=i,d.push(f)}b.layers=d;for(var l=[],e=0;e<a.layers.length;e++)if("imagelayer"===a.layers[e].type){var m={name:a.layers[e].name,image:a.layers[e].image,x:a.layers[e].x,y:a.layers[e].y,alpha:a.layers[e].opacity,visible:a.layers[e].visible,properties:{}};a.layers[e].properties&&(m.properties=a.layers[e].properties),l.push(m)}b.images=l;for(var n={},e=0;e<a.layers.length;e++)if("objectgroup"===a.layers[e].type){n[a.layers[e].name]=[];for(Line truncated
},destroy:function(){this.plugins.length=0,this._pluginsLength=0,this.game=null,this._parent=null}},c.PluginManager.prototype.constructor=c.PluginManager,c.Stage=function(a,d,e){this.game=a,this._backgroundColor="rgb(0,0,0)",this.offset=new c.Point,this.canvas=null,this._stage=new b.Stage(0,!1),this._stage.name="_stage_root",this._stage.interactive=!1,this.display=this._stage,this.scaleMode=c.StageScaleMode.NO_SCALE,this.fullScreenScaleMode=c.StageScaleMode.NO_SCALE,this.scale=new c.StageScaleMode(this.game,d,e),this.aspectRatio=d/e,this.disableVisibilityChange=!1,this._nextOffsetCheck=0,this.checkOffsetInterval=2500,a.config?this.parseConfig(a.config):(this.canvas=c.Canvas.create(d,e),this.canvas.style["-webkit-full-screen"]="width: 100%; height: 100%")},c.Stage.prototype={parseConfig:function(a){this.canvas=a.canvasID?c.Canvas.create(this.game.width,this.game.height,a.canvasID):c.Canvas.create(this.game.width,this.game.height),a.canvasStyle?this.canvas.stlye=a.canvasStyle:this.canvas.style["-webkit-full-screen"]="width: 100%; height: 100%",a.checkOffsetInterval&&(this.checkOffsetInterval=a.checkOffsetInterval),a.disableVisibilityChange&&(this.disableVisibilityChange=a.disableVisibilityChange),a.fullScreenScaleMode&&(this.fullScreenScaleMode=a.fullScreenScaleMode),a.scaleMode&&(this.scaleMode=a.scaleMode),a.backgroundColor&&(this.backgroundColor=a.backgroundColor)},boot:function(){c.Canvas.getOffset(this.canvas,this.offset),this.bounds=new c.Rectangle(this.offset.x,this.offset.y,this.game.width,this.game.height);var a=this;this._onChange=function(b){return a.visibilityChange(b)},c.Canvas.setUserSelect(this.canvas,"none"),c.Canvas.setTouchAction(this.canvas,"none"),this.backgroundColor="#000",document.addEventListener("visibilitychange",this._onChange,!1),document.addEventListener("webkitvisibilitychange",this._onChange,!1),document.addEventListener("pagehide",this._onChange,!1),document.addEventListener("pageshow",this._onChange,!1),window.onblur=this._onChange,window.onfocus=this._onChange},update:function(){this.checkOffsetInterval!==!1&&this.game.time.now>this._nextOffsetCheck&&(c.Canvas.getOffset(this.canvas,this.offset),this._nextOffsetCheck=this.game.time.now+this.checkOffsetInterval)},visibilityChange:function(a){this.disableVisibilityChange||(this.game.paused=this.game.paused!==!1||"pagehide"!=a.type&&"blur"!=a.type&&document.hidden!==!0&&document.webkitHidden!==!0?!1:!0)}},c.Stage.prototype.constructor=c.Stage,Object.defineProperty(c.Stage.prototype,"backgroundColor",{get:function(){return this._backgroundColor},set:function(a){this._backgroundColor=a,this.game.transparent===!1&&(this.game.renderType==c.CANVAS?this.game.canvas.style.backgroundColor=a:("string"==typeof a&&(a=c.Color.hexToRGB(a)),this._stage.setBackgroundColor(a)))}}),c.Group=function(a,d,e,f){this.game=a,"undefined"==typeof d&&(d=a.world),this.name=e||"group","undefined"==typeof f&&(f=!1),f?this._container=this.game.stage._stage:(this._container=new b.DisplayObjectContainer,this._container.name=this.name,d?d instanceof c.Group?(d._container.addChild(this._container),d._container.updateTransform()):(d.addChild(this._container),d.updateTransform()):(this.game.stage._stage.addChild(this._container),this.game.stage._stage.updateTransform())),this.type=c.GROUP,this.alive=!0,this.exists=!0,this.group=null,this._container.scale=new c.Point(1,1),this.scale=this._container.scale,this.cursor=null},c.Group.RETURN_NONE=0,c.Group.RETURN_TOTAL=1,c.Group.RETURN_CHILD=2,c.Group.SORT_ASCENDING=-1,c.Group.SORT_DESCENDING=1,c.Group.prototype={add:function(a){return a.group!==this&&(a.type&&a.type===c.GROUP?(a.group=this,this._container.addChild(a._container),a._container.updateTransform()):(a.group=this,a.events&&a.events.onAddedToGroup.dispatch(a,this),this._container.addChild(a),a.updateTransform()),null===this.cursor&&(this.cursor=a)),a},addAt:function(a,b){return a.group!==this&&(a.type&&a.type===c.GROUP?(a.group=this,this._container.addChildAt(a._container,b),a._container.updateTransform()):(a.group=this,a.events&&a.events.onAddedToGroup.dispatch(a,this),this._container.addChildAt(a,b),a.updateTransform()),null===this.cursor&&(this.cursor=a)),a},getAt:function(a){return this._container.getChildAt(a)},create:function(a,b,d,e,f){"undefined"==typeof f&&(f=!0);var g=new c.Sprite(this.game,a,b,d,e);return g.group=this,g.exists=f,g.visible=f,g.alive=f,g.events&&g.events.onAddedToGroup.dispatch(g,this),this._container.addChild(g),g.updateTransform(),null===this.cursor&&(this.cursor=g),g},createMultiple:function(a,b,d,e){"undefined"==typeof e&&(e=!1);for(var f=0;a>f;f++){var g=new c.Sprite(this.game,0,0,b,d);g.group=this,g.exists=e,g.visible=e,g.alive=e,g.events&&g.events.onAddedToGroup.dispatch(g,this),this._container.addChild(g),g.updateTransform(),null===this.cursor&&(this.cursor=g)}},next:function(){this.cursor&&(this.cursor=this.cursor==this._container.last?this._container._iNext:this.cursor._iNext)},previous:function(){this.cursor&&(this.cursor=tLine truncated
},processKeyUp:function(a){this.game.input.disabled||this.disabled||(this._capture[a.keyCode]&&a.preventDefault(),this.onUpCallback&&this.onUpCallback.call(this.callbackContext,a),this._hotkeys[a.keyCode]&&this._hotkeys[a.keyCode].processKeyUp(a),this._keys[a.keyCode]?(this._keys[a.keyCode].isDown=!1,this._keys[a.keyCode].timeUp=this.game.time.now):this._keys[a.keyCode]={isDown:!1,timeDown:this.game.time.now,timeUp:this.game.time.now,duration:0})},reset:function(){for(var a in this._keys)this._keys[a].isDown=!1},justPressed:function(a,b){return"undefined"==typeof b&&(b=250),this._keys[a]&&this._keys[a].isDown&&this._keys[a].duration<b?!0:!1},justReleased:function(a,b){return"undefined"==typeof b&&(b=250),this._keys[a]&&this._keys[a].isDown===!1&&this.game.time.now-this._keys[a].timeUp<b?!0:!1},isDown:function(a){return this._keys[a]?this._keys[a].isDown:!1}},c.Keyboard.prototype.constructor=c.Keyboard,c.Keyboard.A="A".charCodeAt(0),c.Keyboard.B="B".charCodeAt(0),c.Keyboard.C="C".charCodeAt(0),c.Keyboard.D="D".charCodeAt(0),c.Keyboard.E="E".charCodeAt(0),c.Keyboard.F="F".charCodeAt(0),c.Keyboard.G="G".charCodeAt(0),c.Keyboard.H="H".charCodeAt(0),c.Keyboard.I="I".charCodeAt(0),c.Keyboard.J="J".charCodeAt(0),c.Keyboard.K="K".charCodeAt(0),c.Keyboard.L="L".charCodeAt(0),c.Keyboard.M="M".charCodeAt(0),c.Keyboard.N="N".charCodeAt(0),c.Keyboard.O="O".charCodeAt(0),c.Keyboard.P="P".charCodeAt(0),c.Keyboard.Q="Q".charCodeAt(0),c.Keyboard.R="R".charCodeAt(0),c.Keyboard.S="S".charCodeAt(0),c.Keyboard.T="T".charCodeAt(0),c.Keyboard.U="U".charCodeAt(0),c.Keyboard.V="V".charCodeAt(0),c.Keyboard.W="W".charCodeAt(0),c.Keyboard.X="X".charCodeAt(0),c.Keyboard.Y="Y".charCodeAt(0),c.Keyboard.Z="Z".charCodeAt(0),c.Keyboard.ZERO="0".charCodeAt(0),c.Keyboard.ONE="1".charCodeAt(0),c.Keyboard.TWO="2".charCodeAt(0),c.Keyboard.THREE="3".charCodeAt(0),c.Keyboard.FOUR="4".charCodeAt(0),c.Keyboard.FIVE="5".charCodeAt(0),c.Keyboard.SIX="6".charCodeAt(0),c.Keyboard.SEVEN="7".charCodeAt(0),c.Keyboard.EIGHT="8".charCodeAt(0),c.Keyboard.NINE="9".charCodeAt(0),c.Keyboard.NUMPAD_0=96,c.Keyboard.NUMPAD_1=97,c.Keyboard.NUMPAD_2=98,c.Keyboard.NUMPAD_3=99,c.Keyboard.NUMPAD_4=100,c.Keyboard.NUMPAD_5=101,c.Keyboard.NUMPAD_6=102,c.Keyboard.NUMPAD_7=103,c.Keyboard.NUMPAD_8=104,c.Keyboard.NUMPAD_9=105,c.Keyboard.NUMPAD_MULTIPLY=106,c.Keyboard.NUMPAD_ADD=107,c.Keyboard.NUMPAD_ENTER=108,c.Keyboard.NUMPAD_SUBTRACT=109,c.Keyboard.NUMPAD_DECIMAL=110,c.Keyboard.NUMPAD_DIVIDE=111,c.Keyboard.F1=112,c.Keyboard.F2=113,c.Keyboard.F3=114,c.Keyboard.F4=115,c.Keyboard.F5=116,c.Keyboard.F6=117,c.Keyboard.F7=118,c.Keyboard.F8=119,c.Keyboard.F9=120,c.Keyboard.F10=121,c.Keyboard.F11=122,c.Keyboard.F12=123,c.Keyboard.F13=124,c.Keyboard.F14=125,c.Keyboard.F15=126,c.Keyboard.COLON=186,c.Keyboard.EQUALS=187,c.Keyboard.UNDERSCORE=189,c.Keyboard.QUESTION_MARK=191,c.Keyboard.TILDE=192,c.Keyboard.OPEN_BRACKET=219,c.Keyboard.BACKWARD_SLASH=220,c.Keyboard.CLOSED_BRACKET=221,c.Keyboard.QUOTES=222,c.Keyboard.BACKSPACE=8,c.Keyboard.TAB=9,c.Keyboard.CLEAR=12,c.Keyboard.ENTER=13,c.Keyboard.SHIFT=16,c.Keyboard.CONTROL=17,c.Keyboard.ALT=18,c.Keyboard.CAPS_LOCK=20,c.Keyboard.ESC=27,c.Keyboard.SPACEBAR=32,c.Keyboard.PAGE_UP=33,c.Keyboard.PAGE_DOWN=34,c.Keyboard.END=35,c.Keyboard.HOME=36,c.Keyboard.LEFT=37,c.Keyboard.UP=38,c.Keyboard.RIGHT=39,c.Keyboard.DOWN=40,c.Keyboard.INSERT=45,c.Keyboard.DELETE=46,c.Keyboard.HELP=47,c.Keyboard.NUM_LOCK=144,c.Mouse=function(a){this.game=a,this.callbackContext=this.game,this.mouseDownCallback=null,this.mouseMoveCallback=null,this.mouseUpCallback=null,this.capture=!1,this.button=-1,this.disabled=!1,this.locked=!1,this.pointerLock=new c.Signal,this.event=null,this._onMouseDown=null,this._onMouseMove=null,this._onMouseUp=null},c.Mouse.NO_BUTTON=-1,c.Mouse.LEFT_BUTTON=0,c.Mouse.MIDDLE_BUTTON=1,c.Mouse.RIGHT_BUTTON=2,c.Mouse.prototype={start:function(){var a=this;this.game.device.android&&this.game.device.chrome===!1||(this._onMouseDown=function(b){return a.onMouseDown(b)},this._onMouseMove=function(b){return a.onMouseMove(b)},this._onMouseUp=function(b){return a.onMouseUp(b)},document.addEventListener("mousedown",this._onMouseDown,!0),document.addEventListener("mousemove",this._onMouseMove,!0),document.addEventListener("mouseup",this._onMouseUp,!0))},onMouseDown:function(a){this.event=a,this.capture&&a.preventDefault(),this.button=a.which,this.mouseDownCallback&&this.mouseDownCallback.call(this.callbackContext,a),this.game.input.disabled||this.disabled||(a.identifier=0,this.game.input.mousePointer.start(a))},onMouseMove:function(a){this.event=a,this.capture&&a.preventDefault(),this.mouseMoveCallback&&this.mouseMoveCallback.call(this.callbackContext,a),this.game.input.disabled||this.disabled||(a.identifier=0,this.game.input.mousePointer.move(a))},onMouseUp:function(a){this.event=a,this.capture&&a.preventDefault(),this.button=c.Mouse.NO_BUTTON,this.mouseUpCallback&&this.mouseUpCallback.call(this.callbackContext,a),this.game.input.disabled||this.disabled||(a.Line truncated
},start:function(){this._active=!0;var a=this;this._ongamepadconnected=function(b){var c=b.gamepad;a._rawPads.push(c),a._gamepads[c.index].connect(c)},window.addEventListener("gamepadconnected",this._ongamepadconnected,!1),this._ongamepaddisconnected=function(b){var c=b.gamepad;for(var d in a._rawPads)a._rawPads[d].index===c.index&&a._rawPads.splice(d,1);a._gamepads[c.index].disconnect()},window.addEventListener("gamepaddisconnected",this._ongamepaddisconnected,!1)},update:function(){this._pollGamepads();for(var a=0;a<this._gamepads.length;a++)this._gamepads[a]._connected&&this._gamepads[a].pollStatus()},_pollGamepads:function(){var a=navigator.webkitGetGamepads&&navigator.webkitGetGamepads()||navigator.webkitGamepads;if(a){this._rawPads=[];for(var b=!1,c=0;c<a.length&&(typeof a[c]!==this._prevRawGamepadTypes[c]&&(b=!0,this._prevRawGamepadTypes[c]=typeof a[c]),a[c]&&this._rawPads.push(a[c]),3!==c);c++);if(b){for(var d,e={rawIndices:{},padIndices:{}},f=0;f<this._gamepads.length;f++)if(d=this._gamepads[f],d.connected)for(var g=0;g<this._rawPads.length;g++)this._rawPads[g].index===d.index&&(e.rawIndices[d.index]=!0,e.padIndices[f]=!0);for(var h=0;h<this._gamepads.length;h++)if(d=this._gamepads[h],!e.padIndices[h]){this._rawPads.length<1&&d.disconnect();for(var i=0;i<this._rawPads.length&&!e.padIndices[h];i++){var j=this._rawPads[i];if(j){if(e.rawIndices[j.index]){d.disconnect();continue}d.connect(j),e.rawIndices[j.index]=!0,e.padIndices[h]=!0}else d.disconnect()}}}}},setDeadZones:function(a){for(var b=0;b<this._gamepads.length;b++)this._gamepads[b].deadZone=a},stop:function(){this._active=!1,window.removeEventListener("gamepadconnected",this._ongamepadconnected),window.removeEventListener("gamepaddisconnected",this._ongamepaddisconnected)},reset:function(){this.update();for(var a=0;a<this._gamepads.length;a++)this._gamepads[a].reset()},justPressed:function(a,b){for(var c=0;c<this._gamepads.length;c++)if(this._gamepads[c].justPressed(a,b)===!0)return!0;return!1},justReleased:function(a,b){for(var c=0;c<this._gamepads.length;c++)if(this._gamepads[c].justReleased(a,b)===!0)return!0;return!1},isDown:function(a){for(var b=0;b<this._gamepads.length;b++)if(this._gamepads[b].isDown(a)===!0)return!0;return!1}},c.Gamepad.prototype.constructor=c.Gamepad,Object.defineProperty(c.Gamepad.prototype,"active",{get:function(){return this._active}}),Object.defineProperty(c.Gamepad.prototype,"supported",{get:function(){return this._gamepadSupportAvailable}}),Object.defineProperty(c.Gamepad.prototype,"padsConnected",{get:function(){return this._rawPads.length}}),Object.defineProperty(c.Gamepad.prototype,"pad1",{get:function(){return this._gamepads[0]}}),Object.defineProperty(c.Gamepad.prototype,"pad2",{get:function(){return this._gamepads[1]}}),Object.defineProperty(c.Gamepad.prototype,"pad3",{get:function(){return this._gamepads[2]}}),Object.defineProperty(c.Gamepad.prototype,"pad4",{get:function(){return this._gamepads[3]}}),c.Gamepad.BUTTON_0=0,c.Gamepad.BUTTON_1=1,c.Gamepad.BUTTON_2=2,c.Gamepad.BUTTON_3=3,c.Gamepad.BUTTON_4=4,c.Gamepad.BUTTON_5=5,c.Gamepad.BUTTON_6=6,c.Gamepad.BUTTON_7=7,c.Gamepad.BUTTON_8=8,c.Gamepad.BUTTON_9=9,c.Gamepad.BUTTON_10=10,c.Gamepad.BUTTON_11=11,c.Gamepad.BUTTON_12=12,c.Gamepad.BUTTON_13=13,c.Gamepad.BUTTON_14=14,c.Gamepad.BUTTON_15=15,c.Gamepad.AXIS_0=0,c.Gamepad.AXIS_1=1,c.Gamepad.AXIS_2=2,c.Gamepad.AXIS_3=3,c.Gamepad.AXIS_4=4,c.Gamepad.AXIS_5=5,c.Gamepad.AXIS_6=6,c.Gamepad.AXIS_7=7,c.Gamepad.AXIS_8=8,c.Gamepad.AXIS_9=9,c.Gamepad.XBOX360_A=0,c.Gamepad.XBOX360_B=1,c.Gamepad.XBOX360_X=2,c.Gamepad.XBOX360_Y=3,c.Gamepad.XBOX360_LEFT_BUMPER=4,c.Gamepad.XBOX360_RIGHT_BUMPER=5,c.Gamepad.XBOX360_LEFT_TRIGGER=6,c.Gamepad.XBOX360_RIGHT_TRIGGER=7,c.Gamepad.XBOX360_BACK=8,c.Gamepad.XBOX360_START=9,c.Gamepad.XBOX360_STICK_LEFT_BUTTON=10,c.Gamepad.XBOX360_STICK_RIGHT_BUTTON=11,c.Gamepad.XBOX360_DPAD_LEFT=14,c.Gamepad.XBOX360_DPAD_RIGHT=15,c.Gamepad.XBOX360_DPAD_UP=12,c.Gamepad.XBOX360_DPAD_DOWN=13,c.Gamepad.XBOX360_STICK_LEFT_X=0,c.Gamepad.XBOX360_STICK_LEFT_Y=1,c.Gamepad.XBOX360_STICK_RIGHT_X=2,c.Gamepad.XBOX360_STICK_RIGHT_Y=3,c.SinglePad=function(a,b){this.game=a,this._padParent=b,this._index=null,this._rawPad=null,this._connected=!1,this._prevTimestamp=null,this._rawButtons=[],this._buttons=[],this._axes=[],this._hotkeys=[],this.callbackContext=this,this.onConnectCallback=null,this.onDisconnectCallback=null,this.onDownCallback=null,this.onUpCallback=null,this.onAxisCallback=null,this.onFloatCallback=null,this.deadZone=.26},c.SinglePad.prototype={addCallbacks:function(a,b){"undefined"!=typeof b&&(this.onConnectCallback="function"==typeof b.onConnect?b.onConnect:this.onConnectCallback,this.onDisconnectCallback="function"==typeof b.onDisconnect?b.onDisconnect:this.onDisconnectCallback,this.onDownCallback="function"==typeof b.onDown?b.onDown:this.onDownCallback,this.onUpCallback="function"==typeof b.onUp?b.onUp:this.onUpCallback,this.onAxisCallback="function"==typeof b.onAxis?b.onAxis:this.onAxisCallback,thisLine truncated
}}),Object.defineProperty(c.TileSprite.prototype,"frame",{get:function(){return this.animations.frame},set:function(a){this.animations.frame=a}}),Object.defineProperty(c.TileSprite.prototype,"frameName",{get:function(){return this.animations.frameName},set:function(a){this.animations.frameName=a}}),Object.defineProperty(c.TileSprite.prototype,"inCamera",{get:function(){return this._cache.cameraVisible}}),Object.defineProperty(c.TileSprite.prototype,"inputEnabled",{get:function(){return this.input.enabled},set:function(a){a?this.input.enabled===!1&&this.input.start():this.input.enabled&&this.input.stop()}}),c.Text=function(a,d,e,f,g){d=d||0,e=e||0,f=f||"",g=g||"",this.game=a,this.exists=!0,this.alive=!0,this.group=null,this.name="",this.type=c.TEXT,this._text=f,this._style=g,b.Text.call(this,f,g),this.position.x=this.x=d,this.position.y=this.y=e,this.anchor=new c.Point,this.scale=new c.Point(1,1),this.fixedToCamera=!1,this.cameraOffset=new c.Point(d,e),this._cache={dirty:!1,a00:1,a01:0,a02:d,a10:0,a11:1,a12:e,id:1,x:-1,y:-1,scaleX:1,scaleY:1},this._cache.x=this.x,this._cache.y=this.y,this.renderable=!0},c.Text.prototype=Object.create(b.Text.prototype),c.Text.prototype.constructor=c.Text,c.Text.prototype.update=function(){this.exists&&(this.fixedToCamera&&(this.x=this.game.camera.view.x+this.cameraOffset.x,this.y=this.game.camera.view.y+this.cameraOffset.y),this._cache.dirty=!1,this._cache.x=this.x,this._cache.y=this.y,(this.position.x!=this._cache.x||this.position.y!=this._cache.y)&&(this.position.x=this._cache.x,this.position.y=this._cache.y,this._cache.dirty=!0))},c.Text.prototype.destroy=function(){this.group&&this.group.remove(this),this.canvas.parentNode?this.canvas.parentNode.removeChild(this.canvas):(this.canvas=null,this.context=null),this.exists=!1,this.group=null},Object.defineProperty(c.Text.prototype,"angle",{get:function(){return c.Math.radToDeg(this.rotation)},set:function(a){this.rotation=c.Math.degToRad(a)}}),Object.defineProperty(c.Text.prototype,"x",{get:function(){return this.position.x},set:function(a){this.position.x=a}}),Object.defineProperty(c.Text.prototype,"y",{get:function(){return this.position.y},set:function(a){this.position.y=a}}),Object.defineProperty(c.Text.prototype,"content",{get:function(){return this._text},set:function(a){a!==this._text&&(this._text=a,this.setText(a))}}),Object.defineProperty(c.Text.prototype,"font",{get:function(){return this._style},set:function(a){a!==this._style&&(this._style=a,this.setStyle(a))}}),c.BitmapText=function(a,d,e,f,g){d=d||0,e=e||0,f=f||"",g=g||"",this.game=a,this.exists=!0,this.alive=!0,this.group=null,this.name="",this.type=c.BITMAPTEXT,b.BitmapText.call(this,f,g),this.position.x=d,this.position.y=e,this.anchor=new c.Point,this.scale=new c.Point(1,1),this._cache={dirty:!1,a00:1,a01:0,a02:d,a10:0,a11:1,a12:e,id:1,x:-1,y:-1,scaleX:1,scaleY:1},this._cache.x=this.x,this._cache.y=this.y},c.BitmapText.prototype=Object.create(b.BitmapText.prototype),c.BitmapText.prototype.constructor=c.BitmapText,c.BitmapText.prototype.update=function(){this.exists&&(this._cache.dirty=!1,this._cache.x=this.x,this._cache.y=this.y,(this.position.x!=this._cache.x||this.position.y!=this._cache.y)&&(this.position.x=this._cache.x,this.position.y=this._cache.y,this._cache.dirty=!0),this.pivot.x=this.anchor.x*this.width,this.pivot.y=this.anchor.y*this.height)},c.BitmapText.prototype.destroy=function(){this.group&&this.group.remove(this),this.canvas&&this.canvas.parentNode?this.canvas.parentNode.removeChild(this.canvas):(this.canvas=null,this.context=null),this.exists=!1,this.group=null},Object.defineProperty(c.BitmapText.prototype,"angle",{get:function(){return c.Math.radToDeg(this.rotation)},set:function(a){this.rotation=c.Math.degToRad(a)}}),Object.defineProperty(c.BitmapText.prototype,"x",{get:function(){return this.position.x},set:function(a){this.position.x=a}}),Object.defineProperty(c.BitmapText.prototype,"y",{get:function(){return this.position.y},set:function(a){this.position.y=a}}),c.Button=function(a,b,d,e,f,g,h,i,j,k){b=b||0,d=d||0,e=e||null,f=f||null,g=g||this,c.Sprite.call(this,a,b,d,e,i),this.type=c.BUTTON,this._onOverFrameName=null,this._onOutFrameName=null,this._onDownFrameName=null,this._onUpFrameName=null,this._onOverFrameID=null,this._onOutFrameID=null,this._onDownFrameID=null,this._onUpFrameID=null,this.onOverSound=null,this.onOutSound=null,this.onDownSound=null,this.onUpSound=null,this.onOverSoundMarker="",this.onOutSoundMarker="",this.onDownSoundMarker="",this.onUpSoundMarker="",this.onInputOver=new c.Signal,this.onInputOut=new c.Signal,this.onInputDown=new c.Signal,this.onInputUp=new c.Signal,this.freezeFrames=!1,this.forceOut=!1,this.setFrames(h,i,j,k),null!==f&&this.onInputUp.add(f,g),this.input.start(0,!0),this.events.onInputOver.add(this.onInputOverHandler,this),this.events.onInputOut.add(this.onInputOutHandler,this),this.events.onInputDown.add(this.onInputDownHandler,this),this.events.onInputUp.add(this.onInputUpHandler,this)},c.Button.proLine truncated
},average:function(){for(var a=[],b=0;b<arguments.length-0;b++)a[b]=arguments[b+0];for(var c=0,d=0;d<a.length;d++)c+=a[d];return c/a.length},truncate:function(a){return a>0?Math.floor(a):Math.ceil(a)},shear:function(a){return a%1},snapTo:function(a,b,c){return"undefined"==typeof c&&(c=0),0===b?a:(a-=c,a=b*Math.round(a/b),c+a)},snapToFloor:function(a,b,c){return"undefined"==typeof c&&(c=0),0===b?a:(a-=c,a=b*Math.floor(a/b),c+a)},snapToCeil:function(a,b,c){return"undefined"==typeof c&&(c=0),0===b?a:(a-=c,a=b*Math.ceil(a/b),c+a)},snapToInArray:function(a,b,c){if("undefined"==typeof c&&(c=!0),c&&b.sort(),a<b[0])return b[0];for(var d=1;b[d]<a;)d++;var e=b[d-1],f=d<b.length?b[d]:Number.POSITIVE_INFINITY;return a-e>=f-a?f:e},roundTo:function(a,b,c){"undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=10);var d=Math.pow(c,-b);return Math.round(a*d)/d},floorTo:function(a,b,c){"undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=10);var d=Math.pow(c,-b);return Math.floor(a*d)/d},ceilTo:function(a,b,c){"undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=10);var d=Math.pow(c,-b);return Math.ceil(a*d)/d},interpolateFloat:function(a,b,c){return(b-a)*c+a},angleBetween:function(a,b,c,d){return Math.atan2(d-b,c-a)},reverseAngle:function(a){return this.normalizeAngle(a+Math.PI,!0)},normalizeAngle:function(a){return a%=2*Math.PI,a>=0?a:a+2*Math.PI},normalizeLatitude:function(a){return Math.max(-90,Math.min(90,a))},normalizeLongitude:function(a){return 180==a%360?180:(a%=360,-180>a?a+360:a>180?a-360:a)},nearestAngleBetween:function(a,b,c){"undefined"==typeof c&&(c=!0);var d=c?Math.PI:180;return a=this.normalizeAngle(a,c),b=this.normalizeAngle(b,c),-d/2>a&&b>d/2&&(a+=2*d),-d/2>b&&a>d/2&&(b+=2*d),b-a},interpolateAngles:function(a,b,c,d,e){return"undefined"==typeof d&&(d=!0),"undefined"==typeof e&&(e=null),a=this.normalizeAngle(a,d),b=this.normalizeAngleToAnother(b,a,d),"function"==typeof e?e(c,a,b-a,1):this.interpolateFloat(a,b,c)},chanceRoll:function(a){return"undefined"==typeof a&&(a=50),0>=a?!1:a>=100?!0:100*Math.random()>=a?!1:!0},numberArray:function(a,b){for(var c=[],d=a;b>=d;d++)c.push(d);return c},maxAdd:function(a,b,c){return a+=b,a>c&&(a=c),a},minSub:function(a,b,c){return a-=b,c>a&&(a=c),a},wrap:function(a,b,c){var d=c-b;if(0>=d)return 0;var e=(a-b)%d;return 0>e&&(e+=d),e+b},wrapValue:function(a,b,c){var d;return a=Math.abs(a),b=Math.abs(b),c=Math.abs(c),d=(a+b)%c},randomSign:function(){return Math.random()>.5?1:-1},isOdd:function(a){return 1&a},isEven:function(a){return 1&a?!1:!0},max:function(){for(var a=1,b=0,c=arguments.length;c>a;a++)arguments[b]<arguments[a]&&(b=a);return arguments[b]},min:function(){for(var a=1,b=0,c=arguments.length;c>a;a++)arguments[a]<arguments[b]&&(b=a);return arguments[b]},wrapAngle:function(a){return this.wrap(a,-180,180)},angleLimit:function(a,b,c){var d=a;return a>c?d=c:b>a&&(d=b),d},linearInterpolation:function(a,b){var c=a.length-1,d=c*b,e=Math.floor(d);return 0>b?this.linear(a[0],a[1],d):b>1?this.linear(a[c],a[c-1],c-d):this.linear(a[e],a[e+1>c?c:e+1],d-e)},bezierInterpolation:function(a,b){for(var c=0,d=a.length-1,e=0;d>=e;e++)c+=Math.pow(1-b,d-e)*Math.pow(b,e)*a[e]*this.bernstein(d,e);return c},catmullRomInterpolation:function(a,b){var c=a.length-1,d=c*b,e=Math.floor(d);return a[0]===a[c]?(0>b&&(e=Math.floor(d=c*(1+b))),this.catmullRom(a[(e-1+c)%c],a[e],a[(e+1)%c],a[(e+2)%c],d-e)):0>b?a[0]-(this.catmullRom(a[0],a[0],a[1],a[1],-d)-a[0]):b>1?a[c]-(this.catmullRom(a[c],a[c],a[c-1],a[c-1],d-c)-a[c]):this.catmullRom(a[e?e-1:0],a[e],a[e+1>c?c:e+1],a[e+2>c?c:e+2],d-e)},linear:function(a,b,c){return(b-a)*c+a},bernstein:function(a,b){return this.factorial(a)/this.factorial(b)/this.factorial(a-b)},catmullRom:function(a,b,c,d,e){var f=.5*(c-a),g=.5*(d-b),h=e*e,i=e*h;return(2*b-2*c+f+g)*i+(-3*b+3*c-2*f-g)*h+f*e+b},difference:function(a,b){return Math.abs(a-b)},getRandom:function(a,b,c){if("undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=0),null!=a){var d=c;if((0===d||d>a.length-b)&&(d=a.length-b),d>0)return a[b+Math.floor(Math.random()*d)]}return null},floor:function(a){var b=0|a;return a>0?b:b!=a?b-1:b},ceil:function(a){var b=0|a;return a>0?b!=a?b+1:b:b},sinCosGenerator:function(a,b,c,d){"undefined"==typeof b&&(b=1),"undefined"==typeof c&&(c=1),"undefined"==typeof d&&(d=1);for(var e=b,f=c,g=d*Math.PI/a,h=[],i=[],j=0;a>j;j++)f-=e*g,e+=f*g,h[j]=f,i[j]=e;return{sin:i,cos:h,length:a}},shift:function(a){var b=a.shift();return a.push(b),b},shuffleArray:function(a){for(var b=a.length-1;b>0;b--){var c=Math.floor(Math.random()*(b+1)),d=a[b];a[b]=a[c],a[c]=d}return a},distance:function(a,b,c,d){var e=a-c,f=b-d;return Math.sqrt(e*e+f*f)},distancePow:function(a,b,c,d,e){return"undefined"==typeof e&&(e=2),Math.sqrt(Math.pow(c-a,e)+Math.pow(d-b,e))},distanceRounded:function(a,b,d,e){return Math.round(c.Math.distance(a,b,d,e))},clamp:function(a,b,c){return b>a?b:a>c?c:a},clampBottom:function(a,b){return b>a?b:a},within:function(a,b,c){return Math.abs(a-b)<=c},mapLinear:function(a,b,c,d,e){retuLine truncated
},validateFrames:function(a,b){"undefined"==typeof b&&(b=!0);for(var c=0;c<a.length;c++)if(b===!0){if(a[c]>this._frameData.total)return!1}else if(this._frameData.checkFrameName(a[c])===!1)return!1;return!0},play:function(a,b,c,d){if(this._anims[a]){if(this.currentAnim!=this._anims[a])return this.currentAnim=this._anims[a],this.currentAnim.paused=!1,this.currentAnim.play(b,c,d);if(this.currentAnim.isPlaying===!1)return this.currentAnim.paused=!1,this.currentAnim.play(b,c,d)}},stop:function(a,b){"undefined"==typeof b&&(b=!1),"string"==typeof a?this._anims[a]&&(this.currentAnim=this._anims[a],this.currentAnim.stop(b)):this.currentAnim&&this.currentAnim.stop(b)},update:function(){return this.updateIfVisible&&this.sprite.visible===!1?!1:this.currentAnim&&this.currentAnim.update()===!0?(this.currentFrame=this.currentAnim.currentFrame,this.sprite.currentFrame=this.currentFrame,!0):!1},getAnimation:function(a){return"string"==typeof a&&this._anims[a]?this._anims[a]:!1},refreshFrame:function(){this.sprite.currentFrame=this.currentFrame,this.sprite.setTexture(b.TextureCache[this.currentFrame.uuid])},destroy:function(){this._anims={},this._frameData=null,this._frameIndex=0,this.currentAnim=null,this.currentFrame=null}},c.AnimationManager.prototype.constructor=c.AnimationManager,Object.defineProperty(c.AnimationManager.prototype,"frameData",{get:function(){return this._frameData}}),Object.defineProperty(c.AnimationManager.prototype,"frameTotal",{get:function(){return this._frameData?this._frameData.total:-1}}),Object.defineProperty(c.AnimationManager.prototype,"paused",{get:function(){return this.currentAnim.isPaused},set:function(a){this.currentAnim.paused=a}}),Object.defineProperty(c.AnimationManager.prototype,"frame",{get:function(){return this.currentFrame?this._frameIndex:void 0},set:function(a){"number"==typeof a&&this._frameData&&null!==this._frameData.getFrame(a)&&(this.currentFrame=this._frameData.getFrame(a),this._frameIndex=a,this.sprite.currentFrame=this.currentFrame,this.sprite.setTexture(b.TextureCache[this.currentFrame.uuid]))}}),Object.defineProperty(c.AnimationManager.prototype,"frameName",{get:function(){return this.currentFrame?this.currentFrame.name:void 0},set:function(a){"string"==typeof a&&this._frameData&&null!==this._frameData.getFrameByName(a)?(this.currentFrame=this._frameData.getFrameByName(a),this._frameIndex=this.currentFrame.index,this.sprite.currentFrame=this.currentFrame,this.sprite.setTexture(b.TextureCache[this.currentFrame.uuid])):console.warn("Cannot set frameName: "+a)}}),c.Animation=function(a,b,c,d,e,f,g){this.game=a,this._parent=b,this._frameData=d,this.name=c,this._frames=[],this._frames=this._frames.concat(e),this.delay=1e3/f,this.looped=g,this.killOnComplete=!1,this.isFinished=!1,this.isPlaying=!1,this.isPaused=!1,this._pauseStartTime=0,this._frameIndex=0,this._frameDiff=0,this._frameSkip=1,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex])},c.Animation.prototype={play:function(a,c,d){return"number"==typeof a&&(this.delay=1e3/a),"boolean"==typeof c&&(this.looped=c),"undefined"!=typeof d&&(this.killOnComplete=d),this.isPlaying=!0,this.isFinished=!1,this.paused=!1,this._timeLastFrame=this.game.time.now,this._timeNextFrame=this.game.time.now+this.delay,this._frameIndex=0,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex]),this._parent.setTexture(b.TextureCache[this.currentFrame.uuid]),this._parent.events&&this._parent.events.onAnimationStart.dispatch(this._parent,this),this},restart:function(){this.isPlaying=!0,this.isFinished=!1,this.paused=!1,this._timeLastFrame=this.game.time.now,this._timeNextFrame=this.game.time.now+this.delay,this._frameIndex=0,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex])},stop:function(a){"undefined"==typeof a&&(a=!1),this.isPlaying=!1,this.isFinished=!0,this.paused=!1,a&&(this.currentFrame=this._frameData.getFrame(this._frames[0]))},update:function(){return this.isPaused?!1:this.isPlaying===!0&&this.game.time.now>=this._timeNextFrame?(this._frameSkip=1,this._frameDiff=this.game.time.now-this._timeNextFrame,this._timeLastFrame=this.game.time.now,this._frameDiff>this.delay&&(this._frameSkip=Math.floor(this._frameDiff/this.delay),this._frameDiff-=this._frameSkip*this.delay),this._timeNextFrame=this.game.time.now+(this.delay-this._frameDiff),this._frameIndex+=this._frameSkip,this._frameIndex>=this._frames.length?this.looped?(this._frameIndex%=this._frames.length,this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex]),this.currentFrame&&this._parent.setTexture(b.TextureCache[this.currentFrame.uuid]),this._parent.events.onAnimationLoop.dispatch(this._parent,this)):this.onComplete():(this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex]),this.currentFrame&&this._parent.setTexture(b.TextureCache[this.currentFrame.uuid])),!0):!1},destroy:function(){this.game=null,this._parent=null,this._frames=null,this._frameData=null,this.currentFrame=null,this.iLine truncated
}b.BitmapText.fonts[f.font]=f}},c.Sound=function(a,b,d,e,f){"undefined"==typeof d&&(d=1),"undefined"==typeof e&&(e=!1),"undefined"==typeof f&&(f=a.sound.connectToMaster),this.game=a,this.name=b,this.key=b,this.loop=e,this._volume=d,this.markers={},this.context=null,this._buffer=null,this._muted=!1,this.autoplay=!1,this.totalDuration=0,this.startTime=0,this.currentTime=0,this.duration=0,this.stopTime=0,this.paused=!1,this.pausedPosition=0,this.pausedTime=0,this.isPlaying=!1,this.currentMarker="",this.pendingPlayback=!1,this.override=!1,this.usingWebAudio=this.game.sound.usingWebAudio,this.usingAudioTag=this.game.sound.usingAudioTag,this.externalNode=null,this.usingWebAudio?(this.context=this.game.sound.context,this.masterGainNode=this.game.sound.masterGain,this.gainNode="undefined"==typeof this.context.createGain?this.context.createGainNode():this.context.createGain(),this.gainNode.gain.value=d*this.game.sound.volume,f&&this.gainNode.connect(this.masterGainNode)):this.game.cache.getSound(b)&&this.game.cache.isSoundReady(b)?(this._sound=this.game.cache.getSoundData(b),this.totalDuration=0,this._sound.duration&&(this.totalDuration=this._sound.duration)):this.game.cache.onSoundUnlock.add(this.soundHasUnlocked,this),this.onDecoded=new c.Signal,this.onPlay=new c.Signal,this.onPause=new c.Signal,this.onResume=new c.Signal,this.onLoop=new c.Signal,this.onStop=new c.Signal,this.onMute=new c.Signal,this.onMarkerComplete=new c.Signal},c.Sound.prototype={soundHasUnlocked:function(a){a==this.key&&(this._sound=this.game.cache.getSoundData(this.key),this.totalDuration=this._sound.duration)},addMarker:function(a,b,c,d,e){d=d||1,"undefined"==typeof e&&(e=!1),this.markers[a]={name:a,start:b,stop:b+c,volume:d,duration:c,durationMS:1e3*c,loop:e}},removeMarker:function(a){delete this.markers[a]},update:function(){this.pendingPlayback&&this.game.cache.isSoundReady(this.key)&&(this.pendingPlayback=!1,this.play(this._tempMarker,this._tempPosition,this._tempVolume,this._tempLoop)),this.isPlaying&&(this.currentTime=this.game.time.now-this.startTime,this.currentTime>=this.durationMS&&(this.usingWebAudio?this.loop?(this.onLoop.dispatch(this),""===this.currentMarker?(this.currentTime=0,this.startTime=this.game.time.now):this.play(this.currentMarker,0,this.volume,!0,!0)):this.stop():this.loop?(this.onLoop.dispatch(this),this.play(this.currentMarker,0,this.volume,!0,!0)):this.stop()))},play:function(a,b,c,d,e){if(a=a||"",b=b||0,"undefined"==typeof c&&(c=this._volume),"undefined"==typeof d&&(d=!1),"undefined"==typeof e&&(e=!0),this.isPlaying!==!0||e!==!1||this.override!==!1){if(this.isPlaying&&this.override&&(this.usingWebAudio?"undefined"==typeof this._sound.stop?this._sound.noteOff(0):this._sound.stop(0):this.usingAudioTag&&(this._sound.pause(),this._sound.currentTime=0)),this.currentMarker=a,""!==a){if(!this.markers[a])return console.warn("Phaser.Sound.play: audio marker "+a+" doesn't exist"),void 0;this.position=this.markers[a].start,this.volume=this.markers[a].volume,this.loop=this.markers[a].loop,this.duration=this.markers[a].duration,this.durationMS=this.markers[a].durationMS,this._tempMarker=a,this._tempPosition=this.position,this._tempVolume=this.volume,this._tempLoop=this.loop}else this.position=b,this.volume=c,this.loop=d,this.duration=0,this.durationMS=0,this._tempMarker=a,this._tempPosition=b,this._tempVolume=c,this._tempLoop=d;this.usingWebAudio?this.game.cache.isSoundDecoded(this.key)?(null==this._buffer&&(this._buffer=this.game.cache.getSoundData(this.key)),this._sound=this.context.createBufferSource(),this._sound.buffer=this._buffer,this.externalNode?this._sound.connect(this.externalNode.input):this._sound.connect(this.gainNode),this.totalDuration=this._sound.buffer.duration,0===this.duration&&(this.duration=this.totalDuration,this.durationMS=1e3*this.totalDuration),this.loop&&""===a&&(this._sound.loop=!0),"undefined"==typeof this._sound.start?this._sound.noteGrainOn(0,this.position,this.duration):this._sound.start(0,this.position,this.duration),this.isPlaying=!0,this.startTime=this.game.time.now,this.currentTime=0,this.stopTime=this.startTime+this.durationMS,this.onPlay.dispatch(this)):(this.pendingPlayback=!0,this.game.cache.getSound(this.key)&&this.game.cache.getSound(this.key).isDecoding===!1&&this.game.sound.decode(this.key,this)):this.game.cache.getSound(this.key)&&this.game.cache.getSound(this.key).locked?(this.game.cache.reloadSound(this.key),this.pendingPlayback=!0):this._sound&&(this.game.device.cocoonJS||4===this._sound.readyState)?(this._sound.play(),this.totalDuration=this._sound.duration,0===this.duration&&(this.duration=this.totalDuration,this.durationMS=1e3*this.totalDuration),this._sound.currentTime=this.position,this._sound.muted=this._muted,this._sound.volume=this._muted?0:this._volume,this.isPlaying=!0,this.startTime=this.game.time.now,this.currentTime=0,this.stopTime=this.startTime+this.durationMS,this.onPlay.dispatch(this)):this.pendingPlayback=!0}},restart:function(a,b,c,d){a=a||"",b=b||0,c=c||1,"uLine truncated
},m.Circle=b,m.Polygon=c,c.prototype.recalc=c.prototype.recalc=function(){this.edges=[],this.normals=[];for(var b=this.points,c=b.length,d=0;c>d;d++){var e=b[d],f=c-1>d?b[d+1]:b[0],g=(new a).copy(f).sub(e),h=(new a).copy(g).perp().normalize();this.edges.push(g),this.normals.push(h)}return this},c.prototype.rotate=c.prototype.rotate=function(a){var b,c=this.points,d=this.edges,e=this.normals,f=c.length,g=Math.cos(a),h=Math.sin(a);for(b=0;f>b;b++)c[b].rotatePrecalc(h,g),d[b].rotatePrecalc(h,g),e[b].rotatePrecalc(h,g);return this},c.prototype.scale=c.prototype.scale=function(a,b){var c,d=this.points,e=this.edges,f=this.normals,g=d.length;for(c=0;g>c;c++)d[c].scale(a,b),e[c].scale(a,b),f[c].scale(a,b);return this},c.prototype.translate=c.prototype.translate=function(a,b){var c,d=this.points,e=d.length;for(c=0;e>c;c++)d[c].x+=a,d[c].y+=b;return this},m.Box=d,d.prototype.toPolygon=d.prototype.toPolygon=function(){var b=this.pos,d=this.w,e=this.h;return new c(new a(b.x,b.y),[new a,new a(d,0),new a(d,e),new a(0,e)])},m.Response=e,e.prototype.clear=e.prototype.clear=function(){return this.aInB=!0,this.bInA=!0,this.overlap=Number.MAX_VALUE,this};for(var n=[],o=0;10>o;o++)n.push(new a);for(var p=[],o=0;5>o;o++)p.push([]);var q=-1,r=0,s=1;return m.testCircleCircle=i,m.testPolygonCircle=j,m.testCirclePolygon=k,m.testPolygonPolygon=l,m}),c.Physics={},c.Physics.Arcade=function(a){this.game=a,this.gravity=new c.Point,this.quadTree=new c.QuadTree(this.game.world.bounds.x,this.game.world.bounds.y,this.game.world.bounds.width,this.game.world.bounds.height,this.maxObjects,this.maxLevels),this.maxObjects=10,this.maxLevels=4,this._mapData=[],this._mapTiles=0,this._result=!1,this._total=0,this._angle=0,this._dx=0,this._dy=0,this._gravityX=0,this._gravityY=0,this._response=new SAT.Response},c.Physics.Arcade.RECT=0,c.Physics.Arcade.CIRCLE=1,c.Physics.Arcade.prototype={updateMotion:function(a){a.allowGravity?(this._gravityX=this.gravity.x+a.gravity.x,this._gravityY=this.gravity.y+a.gravity.y):(this._gravityX=a.gravity.x,this._gravityY=a.gravity.y),(this._gravityX<0&&a.blocked.left||this._gravityX>0&&a.blocked.right)&&(this._gravityX=0),(this._gravityY<0&&a.blocked.up||this._gravityY>0&&a.blocked.down)&&(this._gravityY=0),a.allowRotation&&(this._velocityDelta=a.angularAcceleration*this.game.time.physicsElapsed,0!==a.angularDrag&&0===a.angularAcceleration&&(this._drag=a.angularDrag*this.game.time.physicsElapsed,a.angularVelocity>0?a.angularVelocity-=this._drag:a.angularVelocity<0&&(a.angularVelocity+=this._drag)),a.rotation+=this.game.time.physicsElapsed*(a.angularVelocity+this._velocityDelta/2),a.angularVelocity+=this._velocityDelta,a.angularVelocity>a.maxAngular?a.angularVelocity=a.maxAngular:a.angularVelocity<-a.maxAngular&&(a.angularVelocity=-a.maxAngular)),a.motionVelocity.x=(a.acceleration.x+this._gravityX)*this.game.time.physicsElapsed,a.motionVelocity.y=(a.acceleration.y+this._gravityY)*this.game.time.physicsElapsed},overlap:function(a,b,c,d,e){return c=c||null,d=d||null,e=e||c,this._result=!1,this._total=0,this.collideHandler(a,b,c,d,e,!0),this._total>0},overlapArray:function(a,b,c,d,e){c=c||null,d=d||null,e=e||c,this._result=!1,this._total=0;for(var f=0,g=b.length;g>f;f++)this.collideHandler(a,b[f],c,d,e,!0);return this._total>0},collide:function(a,b,c,d,e){return c=c||null,d=d||null,e=e||c,this._result=!1,this._total=0,this.collideHandler(a,b,c,d,e,!1),this._total>0},collideArray:function(a,b,c,d,e){c=c||null,d=d||null,e=e||c,this._result=!1,this._total=0;for(var f=0,g=b.length;g>f;f++)this.collideHandler(a,b[f],c,d,e,!1);return this._total>0},collideHandler:function(a,b,d,e,f,g){return"undefined"!=typeof b||a.type!==c.GROUP&&a.type!==c.EMITTER?(a&&b&&a.exists&&b.exists&&(a.type==c.SPRITE||a.type==c.TILESPRITE?b.type==c.SPRITE||b.type==c.TILESPRITE?this.collideSpriteVsSprite(a,b,d,e,f,g):b.type==c.GROUP||b.type==c.EMITTER?this.collideSpriteVsGroup(a,b,d,e,f,g):b.type==c.TILEMAPLAYER&&this.collideSpriteVsTilemapLayer(a,b,d,e,f):a.type==c.GROUP?b.type==c.SPRITE||b.type==c.TILESPRITE?this.collideSpriteVsGroup(b,a,d,e,f,g):b.type==c.GROUP||b.type==c.EMITTER?this.collideGroupVsGroup(a,b,d,e,f,g):b.type==c.TILEMAPLAYER&&this.collideGroupVsTilemapLayer(a,b,d,e,f):a.type==c.TILEMAPLAYER?b.type==c.SPRITE||b.type==c.TILESPRITE?this.collideSpriteVsTilemapLayer(b,a,d,e,f):(b.type==c.GROUP||b.type==c.EMITTER)&&this.collideGroupVsTilemapLayer(b,a,d,e,f):a.type==c.EMITTER&&(b.type==c.SPRITE||b.type==c.TILESPRITE?this.collideSpriteVsGroup(b,a,d,e,f,g):b.type==c.GROUP||b.type==c.EMITTER?this.collideGroupVsGroup(a,b,d,e,f,g):b.type==c.TILEMAPLAYER&&this.collideGroupVsTilemapLayer(a,b,d,e,f))),void 0):(this.collideGroupVsSelf(a,d,e,f,g),void 0)},collideSpriteVsSprite:function(a,b,c,d,e,f){this.separate(a.body,b.body,d,e,f)&&(c&&c.call(e,a,b),this._total++)},collideSpriteVsGroup:function(a,b,d,e,f,g){if(0!==b.length){this.quadTree.clear(),this.quadTree=new c.QuadTree(this.game.world.bounds.x,this.game.world.bounds.y,this.game.world.bounds.widLine truncated
}},c.Tile.prototype.constructor=c.Tile,Object.defineProperty(c.Tile.prototype,"canCollide",{get:function(){return this.collides||this.collisionCallback||this.layer.callbacks[this.index]}}),Object.defineProperty(c.Tile.prototype,"bottom",{get:function(){return this.y+this.height}}),Object.defineProperty(c.Tile.prototype,"right",{get:function(){return this.x+this.width}}),c.Tilemap=function(a,b){this.game=a,this.key=b;var d=c.TilemapParser.parse(this.game,b);null!==d&&(this.width=d.width,this.height=d.height,this.tileWidth=d.tileWidth,this.tileHeight=d.tileHeight,this.orientation=d.orientation,this.version=d.version,this.properties=d.properties,this.widthInPixels=d.widthInPixels,this.heightInPixels=d.heightInPixels,this.layers=d.layers,this.tilesets=d.tilesets,this.tiles=d.tiles,this.objects=d.objects,this.images=d.images,this.currentLayer=0,this.debugMap=[],this._results=[],this._tempA=0,this._tempB=0)},c.Tilemap.CSV=0,c.Tilemap.TILED_JSON=1,c.Tilemap.prototype={create:function(a,b,d){for(var e=[],f=0;d>f;f++){e[f]=[];for(var g=0;b>g;g++)e[f][g]=0}this.layers.push({name:a,width:b,height:d,alpha:1,visible:!0,tileMargin:0,tileSpacing:0,format:c.Tilemap.CSV,data:e,indexes:[],dirty:!0}),this.currentLayer=this.layers.length-1},addTilesetImage:function(a,b){if("undefined"==typeof b){if("string"!=typeof a)return!1;b=a}return"string"==typeof a&&(a=this.getTilesetIndex(a)),this.tilesets[a]?(this.tilesets[a].image=this.game.cache.getImage(b),!0):!1},createFromTiles:function(a,b,c,d,e){"undefined"==typeof e&&(e=this.game.world)},createFromObjects:function(a,b,c,d,e,f,g){if("undefined"==typeof e&&(e=!0),"undefined"==typeof f&&(f=!0),"undefined"==typeof g&&(g=this.game.world),!this.objects[a])return console.warn("Tilemap.createFromObjects: Invalid objectgroup name given: "+a),void 0;for(var h,i=0,j=this.objects[a].length;j>i;i++)if(this.objects[a][i].gid===b){h=g.create(this.objects[a][i].x,this.objects[a][i].y,c,d,e),h.anchor.setTo(0,1),h.name=this.objects[a][i].name,h.visible=this.objects[a][i].visible,h.autoCull=f;for(property in this.objects[a][i].properties)g.set(h,property,this.objects[a][i].properties[property],!1,!1,0)}},createLayer:function(a,b,d,e){"undefined"==typeof b&&(b=this.game.width),"undefined"==typeof d&&(d=this.game.height),"undefined"==typeof e&&(e=this.game.world);var f=a;return"string"==typeof a&&(f=this.getLayerIndex(a)),null===f||f>this.layers.length?(console.warn("Tilemap.createLayer: Invalid layer ID given: "+f),void 0):e.add(new c.TilemapLayer(this.game,this,f,b,d))},getIndex:function(a,b){for(var c=0;c<a.length;c++)if(a[c].name===b)return c;return null},getLayerIndex:function(a){return this.getIndex(this.layers,a)},getTilesetIndex:function(a){return this.getIndex(this.tilesets,a)},getImageIndex:function(a){return this.getIndex(this.images,a)},getObjectIndex:function(a){return this.getIndex(this.objects,a)},setTileIndexCallback:function(a,b,c,d){if(d=this.getLayer(d),"number"==typeof a)this.layers[d].callbacks[a]={callback:b,callbackContext:c};else for(var e=0,f=a.length;f>e;e++)this.layers[d].callbacks[a[e]]={callback:b,callbackContext:c}},setTileLocationCallback:function(a,b,c,d,e,f,g){if(g=this.getLayer(g),this.copy(a,b,c,d,g),!(this._results.length<2))for(var h=1;h<this._results.length;h++)this._results[h].setCollisionCallback(e,f)},setCollision:function(a,b,c){if("undefined"==typeof b&&(b=!0),c=this.getLayer(c),"number"==typeof a)return this.setCollisionByIndex(a,b,c,!0);for(var d=0,e=a.length;e>d;d++)this.setCollisionByIndex(a[d],b,c,!1);this.calculateFaces(c)},setCollisionBetween:function(a,b,c,d){if("undefined"==typeof c&&(c=!0),d=this.getLayer(d),!(a>b)){for(var e=a;b>=e;e++)this.setCollisionByIndex(e,c,d,!1);this.calculateFaces(d)}},setCollisionByExclusion:function(a,b,c){"undefined"==typeof b&&(b=!0),c=this.getLayer(c);for(var d=0,e=this.tiles.length;e>d;d++)-1===a.indexOf(d)&&this.setCollisionByIndex(d,b,c,!1);this.calculateFaces(c)},setCollisionByIndex:function(a,b,c,d){"undefined"==typeof b&&(b=!0),"undefined"==typeof c&&(c=this.currentLayer),"undefined"==typeof d&&(d=!0);for(var e=0;e<this.layers[c].height;e++)for(var f=0;f<this.layers[c].width;f++){var g=this.layers[c].data[e][f];g&&g.index===a&&(g.collides=b,g.faceTop=b,g.faceBottom=b,g.faceLeft=b,g.faceRight=b)}return d&&this.calculateFaces(c),c},getLayer:function(a){return"undefined"==typeof a?a=this.currentLayer:"string"==typeof a?a=this.getLayerIndex(a):a instanceof c.TilemapLayer&&(a=a.index),a},calculateFaces:function(a){for(var b=null,c=null,d=null,e=null,f=0,g=this.layers[a].height;g>f;f++)for(var h=0,i=this.layers[a].width;i>h;h++){var j=this.layers[a].data[f][h];j&&(b=this.getTileAbove(a,h,f),c=this.getTileBelow(a,h,f),d=this.getTileLeft(a,h,f),e=this.getTileRight(a,h,f),b&&b.collides&&(j.faceTop=!1),c&&c.collides&&(j.faceBottom=!1),d&&d.collides&&(j.faceLeft=!1),e&&e.collides&&(j.faceRight=!1))}},getTileAbove:function(a,b,c){return c>0?this.layers[a].data[c-1][b]:null},getTileBelow:function(a,b,c){return c<this.layLine truncated
+8 -8
View File
@@ -110,6 +110,10 @@
}
],
"collision": [
{
"file": "body+scale.js",
"title": "body scale"
},
{
"file": "bounding+box.js",
"title": "bounding box"
@@ -118,6 +122,10 @@
"file": "group+vs+group.js",
"title": "group vs group"
},
{
"file": "group+vs+self.js",
"title": "group vs self"
},
{
"file": "larger+bounding+box.js",
"title": "larger bounding box"
@@ -130,10 +138,6 @@
"file": "process+callback.js",
"title": "process callback"
},
{
"file": "sprite+tiles.js",
"title": "sprite tiles"
},
{
"file": "sprite+vs+group.js",
"title": "sprite vs group"
@@ -142,10 +146,6 @@
"file": "sprite+vs+sprite.js",
"title": "sprite vs sprite"
},
{
"file": "transform.js",
"title": "transform"
},
{
"file": "vertical+collision.js",
"title": "vertical collision"
+1
View File
@@ -136,6 +136,7 @@
<script src="../src/utils/Debug.js"></script>
<script src="../src/utils/Color.js"></script>
<script src="../src/physics/arcade/SAT.js"></script>
<script src="../src/physics/arcade/ArcadePhysics.js"></script>
<script src="../src/physics/arcade/Body.js"></script>
+1
View File
@@ -136,6 +136,7 @@
<script src="../src/utils/Debug.js"></script>
<script src="../src/utils/Color.js"></script>
<script src="../src/physics/arcade/SAT.js"></script>
<script src="../src/physics/arcade/ArcadePhysics.js"></script>
<script src="../src/physics/arcade/Body.js"></script>
Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B

+46
View File
@@ -0,0 +1,46 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.spritesheet('gameboy', 'assets/sprites/gameboy_seize_color_40x60.png', 40, 60);
}
var sprite;
var sprite2;
function create() {
game.stage.backgroundColor = '#124184';
// Here we're tweening the scale of the sprite, which translates to the scale of the Body as well
// The collision will carry on working even against the scaled body.
sprite = game.add.sprite(200, 300, 'gameboy', 2);
sprite.name = 'green';
sprite.anchor.setTo(0.5, 0.5);
sprite.body.immovable = true;
sprite2 = game.add.sprite(600, 270, 'gameboy', 3);
sprite2.name = 'yellow';
sprite2.body.rebound = false;
sprite2.body.velocity.x = -200;
game.add.tween(sprite.scale).to( { x: 3, y: 3 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
}
function update() {
game.physics.collide(sprite, sprite2);
}
function render() {
game.debug.renderPolygon(sprite.body.polygons, 'rgb(255,0,0)');
game.debug.renderPolygon(sprite2.body.polygons, 'rgb(255,0,0)');
}
+8 -12
View File
@@ -14,16 +14,15 @@ function create() {
game.stage.backgroundColor = '#2d2d2d';
sprite1 = game.add.sprite(50, 200, 'atari');
sprite1 = game.add.sprite(150, 300, 'atari');
sprite1.name = 'atari';
sprite1.body.velocity.x = 100;
// This adjusts the collision body size.
// 100x100 is the new width/height.
// This adjusts the collision body size to be 104 x 104.
// See the offset bounding box for another example.
sprite1.body.setSize(100, 100, 0, 0);
sprite1.body.setSize(104, 104, 0, 0);
sprite1.body.immovable = true;
sprite2 = game.add.sprite(700, 220, 'mushroom');
sprite2 = game.add.sprite(700, 320, 'mushroom');
sprite2.name = 'mushroom';
sprite2.body.velocity.x = -100;
@@ -40,16 +39,13 @@ function collisionHandler (obj1, obj2) {
game.stage.backgroundColor = '#992d2d';
console.log(obj1.name + ' collided with ' + obj2.name);
}
function render() {
game.debug.renderSpriteInfo(sprite1, 32, 32);
game.debug.renderSpriteCollision(sprite1, 32, 400);
game.debug.renderBodyInfo(sprite1, 32, 32);
game.debug.renderSpriteBody(sprite1);
game.debug.renderSpriteBody(sprite2);
game.debug.renderPolygon(sprite1.body.polygons, 'rgb(255,0,0)');
game.debug.renderPolygon(sprite2.body.polygons, 'rgb(255,0,0)');
}
+15 -11
View File
@@ -12,8 +12,9 @@ function preload() {
var sprite;
var bullets;
var veggies;
var bulletTime = 0;
var cursors;
var bulletTime = 0;
var bullet;
function create() {
@@ -44,23 +45,26 @@ function create() {
sprite = game.add.sprite(400, 550, 'phaser');
// Stop the following keys from propagating up to the browser
game.input.keyboard.addKeyCapture([ Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.SPACEBAR ]);
cursors = game.input.keyboard.createCursorKeys();
game.input.keyboard.addKeyCapture([ Phaser.Keyboard.SPACEBAR ]);
}
function update() {
// As we don't need to exchange any velocities or motion we can the 'overlap' check instead of 'collide'
game.physics.overlap(bullets, veggies, collisionHandler, null, this);
sprite.body.velocity.x = 0;
sprite.body.velocity.y = 0;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
if (cursors.left.isDown)
{
sprite.body.velocity.x = -200;
sprite.body.velocity.x = -300;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
else if (cursors.right.isDown)
{
sprite.body.velocity.x = 200;
sprite.body.velocity.x = 300;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
@@ -68,9 +72,6 @@ function update() {
fireBullet();
}
// As we don't need to exchange any velocities or motion we can use the faster 'overlap' check instead of 'collide':
game.physics.overlap(bullets, veggies, collisionHandler, null, this);
}
function fireBullet () {
@@ -83,7 +84,7 @@ function fireBullet () {
{
bullet.reset(sprite.x + 6, sprite.y - 8);
bullet.body.velocity.y = -300;
bulletTime = game.time.now + 250;
bulletTime = game.time.now + 150;
}
}
@@ -91,9 +92,12 @@ function fireBullet () {
// Called if the bullet goes out of the screen
function resetBullet (bullet) {
bullet.kill();
}
// Called if the bullet hits one of the veg sprites
function collisionHandler (bullet, veg) {
bullet.kill();
+40
View File
@@ -0,0 +1,40 @@
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
function preload() {
game.load.spritesheet('spinner', 'assets/sprites/bluemetal_32x32x4.png', 32, 32);
}
var sprites;
function create() {
// Here we create a group, populate it with sprites, give them all a random velocity
// and then check the group against itself for collision
sprites = game.add.group();
for (var i = 0; i < 30; i++)
{
var s = sprites.create(game.rnd.integerInRange(100, 700), game.rnd.integerInRange(32, 200), 'spinner');
s.animations.add('spin', [0,1,2,3]);
s.play('spin', 20, true);
s.body.velocity.x = game.rnd.integerInRange(-200, 200);
s.body.velocity.y = game.rnd.integerInRange(-200, 200);
}
sprites.setAll('body.collideWorldBounds', true);
sprites.setAll('body.bounce.x', 1);
sprites.setAll('body.bounce.y', 1);
sprites.setAll('body.friction', 0);
sprites.setAll('body.minBounceVelocity', 0);
}
function update() {
game.physics.collide(sprites);
}
+7 -7
View File
@@ -15,14 +15,14 @@ function create() {
game.stage.backgroundColor = '#2d2d2d';
sprite1 = game.add.sprite(50, 200, 'atari');
sprite1 = game.add.sprite(130, 200, 'atari');
sprite1.name = 'atari';
sprite1.body.velocity.x = 100;
// In this example the new collision box is much larger than the original sprite
sprite1.body.setSize(400, 50, -100, 20);
sprite1.body.immovable = true;
sprite2 = game.add.sprite(700, 220, 'mushroom');
sprite2 = game.add.sprite(700, 210, 'mushroom');
sprite2.name = 'mushroom';
sprite2.body.velocity.x = -100;
@@ -39,13 +39,13 @@ function collisionHandler (obj1, obj2) {
game.stage.backgroundColor = '#992d2d';
console.log(obj1.name + ' collided with ' + obj2.name);
}
function render() {
game.debug.renderRectangle(sprite1.body);
game.debug.renderRectangle(sprite2.body);
game.debug.renderBodyInfo(sprite1, 32, 32);
game.debug.renderPolygon(sprite1.body.polygons, 'rgb(255,0,0)');
game.debug.renderPolygon(sprite2.body.polygons, 'rgb(255,0,0)');
}
+7 -9
View File
@@ -15,15 +15,13 @@ function create() {
game.stage.backgroundColor = '#2d2d2d';
sprite1 = game.add.sprite(50, 200, 'atari');
sprite1 = game.add.sprite(150, 200, 'atari');
sprite1.name = 'atari';
sprite1.body.velocity.x = 100;
// This adjusts the collision body size.
// 100x50 is the new width/height.
// This adjusts the collision body size to be a 100x50 box.
// 50, 25 is the X and Y offset of the newly sized box.
// In this case the box is 50px in and 25px down.
sprite1.body.setSize(100, 50, 50, 25);
sprite1.body.immovable = true;
sprite2 = game.add.sprite(700, 220, 'mushroom');
sprite2.name = 'mushroom';
@@ -42,13 +40,13 @@ function collisionHandler (obj1, obj2) {
game.stage.backgroundColor = '#992d2d';
console.log(obj1.name + ' collided with ' + obj2.name);
}
function render() {
game.debug.renderRectangle(sprite1.body);
game.debug.renderRectangle(sprite2.body);
game.debug.renderBodyInfo(sprite1, 32, 32);
game.debug.renderPolygon(sprite1.body.polygons, 'rgb(255,0,0)');
game.debug.renderPolygon(sprite2.body.polygons, 'rgb(255,0,0)');
}
-69
View File
@@ -1,69 +0,0 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.spritesheet('tiles', 'assets/tiles/platformer_tiles.png', 16, 16);
game.load.image('carrot', 'assets/sprites/carrot.png');
}
var tiles;
var sprite;
function create() {
game.stage.backgroundColor = '#2d2d2d';
tiles = game.add.group();
for (var x = 0; x < 40; x++)
{
var tile = tiles.create(100 + (x * 16), 300, 'tiles', 4);
tile.body.immovable = true;
}
sprite = game.add.sprite(300, 150, 'carrot');
sprite.name = 'mushroom';
sprite.body.collideWorldBounds = true;
sprite.body.velocity.x = 40;
sprite.body.velocity.y = 120;
sprite.body.bounce.setTo(1, 1);
game.input.onDown.add(carryOn, this);
}
function carryOn() {
game.paused = false;
}
function update() {
// object1, object2, collideCallback, processCallback, callbackContext
game.physics.collide(sprite, tiles, collisionHandler, null, this);
}
function collisionHandler (s, t) {
t.alpha = 0.5;
console.log('---------------------------------------------');
console.log(t.body);
game.paused = true;
}
function render() {
// game.debug.renderSpriteInfo(sprite1, 32, 32);
// game.debug.renderSpriteCollision(sprite1, 32, 400);
game.debug.renderSpriteBody(sprite);
// game.debug.renderSpriteBody(sprite2);
}
+16 -22
View File
@@ -1,5 +1,5 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
function preload() {
@@ -10,12 +10,13 @@ function preload() {
var sprite;
var group;
var cursors;
function create() {
game.stage.backgroundColor = '#2d2d2d';
// This will check Sprite vs. Group collision
// This example will check Sprite vs. Group collision
sprite = game.add.sprite(32, 200, 'phaser');
sprite.name = 'phaser-dude';
@@ -24,7 +25,7 @@ function create() {
for (var i = 0; i < 50; i++)
{
var c = group.create(100 + Math.random() * 700, game.world.randomY, 'veggies', game.rnd.integerInRange(0, 36));
var c = group.create(game.rnd.integerInRange(100, 770), game.rnd.integerInRange(0, 570), 'veggies', game.rnd.integerInRange(0, 36));
c.name = 'veg' + i;
c.body.immovable = true;
}
@@ -32,58 +33,51 @@ function create() {
for (var i = 0; i < 20; i++)
{
// Here we'll create some chillis which the player can pick-up. They are still part of the same Group.
var c = group.create(100 + Math.random() * 700, game.world.randomY, 'veggies', 17);
var c = group.create(game.rnd.integerInRange(100, 770), game.rnd.integerInRange(0, 570), 'veggies', 17);
c.name = 'chilli' + i;
c.body.immovable = true;
}
game.input.keyboard.addKeyCapture([ Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.UP, Phaser.Keyboard.DOWN ]);
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
game.physics.collide(sprite, group, collisionHandler, null, this);
game.physics.collide(group, group);
sprite.body.velocity.x = 0;
sprite.body.velocity.y = 0;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
if (cursors.left.isDown)
{
sprite.body.velocity.x = -200;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
else if (cursors.right.isDown)
{
sprite.body.velocity.x = 200;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
if (cursors.up.isDown)
{
sprite.body.velocity.y = -200;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
else if (cursors.down.isDown)
{
sprite.body.velocity.y = 200;
}
game.physics.collide(sprite, group, collisionHandler, null, this);
}
function collisionHandler (obj1, obj2) {
function collisionHandler (player, veg) {
// If the player collides with the chillis then they get eaten :)
// The chilli frame ID is 17
console.log('Hit', obj2.name);
if (obj2.frame == 17)
if (veg.frame == 17)
{
obj2.kill();
veg.kill();
}
}
function render () {
// game.debug.renderQuadTree(game.physics.quadTree);
}
-117
View File
@@ -1,117 +0,0 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('atari', 'assets/sprites/atari130xe.png');
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
game.load.image('flectrum', 'assets/sprites/flectrum.png');
}
var testGroup;
var sprite1;
var sprite2;
var sprite3;
function create() {
game.stage.backgroundColor = '#2d2d2d';
game.world.setBounds(-1000, -1000, 2000, 2000);
testGroup = game.add.group();
test2();
}
function test1 () {
// Test 1 - 2 sprites in world space (seems to work fine with local transform?)
sprite1 = game.add.sprite(-600, 200, 'atari');
sprite1.name = 'atari';
// sprite1.body.setSize(100, 100, 0, 0);
sprite2 = game.add.sprite(-100, 220, 'mushroom');
sprite2.name = 'mushroom';
game.camera.focusOn(sprite1);
game.camera.x += 300;
game.input.onDown.add(go1, this);
}
function test2 () {
// 1 sprite in world space (seems to work fine with local transform?) and 1 in a group
sprite1 = testGroup.create(0, -150, 'atari');
sprite1.name = 'atari';
sprite1.body.immovable = true;
// sprite1.body.setSize(100, 100, 0, 0);
sprite2 = game.add.sprite(-100, 140, 'mushroom');
sprite2.name = 'mushroom';
sprite3 = game.add.sprite(-200, 150, 'flectrum');
sprite3.name = 'tall';
testGroup.x = -600;
testGroup.y = 200;
game.camera.focusOn(sprite2);
game.camera.x -= 300;
game.input.onDown.add(go2, this);
}
function go1 () {
sprite1.body.velocity.x = 100;
sprite2.body.velocity.x = -100;
}
function go2 () {
sprite2.body.velocity.x = -100;
}
function update () {
game.physics.collide(sprite1, sprite2, collisionHandler, null, this);
// sprite3.angle += 0.5;
}
function collisionHandler (obj1, obj2) {
game.stage.backgroundColor = '#992d2d';
console.log(obj1.name + ' collided with ' + obj2.name);
}
function render() {
// game.debug.renderSpriteInfo(sprite1, 32, 32);
// game.debug.renderSpriteCollision(sprite1, 32, 400);
game.debug.renderSpriteCoords(sprite1, 32, 32);
game.debug.renderSpriteCoords(sprite2, 300, 32);
game.debug.renderCameraInfo(game.camera, 32, 500);
game.debug.renderSpriteBody(sprite1);
game.debug.renderSpriteBody(sprite2);
game.debug.renderSpriteBody(sprite3);
game.debug.renderGroupInfo(testGroup, 500, 500);
game.debug.renderPixel(testGroup.x, testGroup.y, 'rgb(255,255,0)');
}
+1 -1
View File
@@ -16,7 +16,7 @@ function create() {
emitter = game.add.emitter(0, 0, 200);
emitter.makeParticles('diamond');
emitter.gravity = 10;
emitter.gravity = 200;
game.input.onDown.add(particleBurst, this);
+2 -3
View File
@@ -17,9 +17,8 @@ function create() {
emitter.minParticleSpeed.setTo(-200, -300);
emitter.maxParticleSpeed.setTo(200, -400);
emitter.gravity = 8;
emitter.gravity = 150;
emitter.bounce.setTo(0.5, 0.5);
emitter.particleDrag.x = 10;
emitter.angularDrag = 30;
emitter.start(false, 8000, 400);
@@ -28,6 +27,6 @@ function create() {
function update() {
game.physics.collide(emitter, emitter);
game.physics.collide(emitter);
}
+2 -2
View File
@@ -31,8 +31,8 @@ function create() {
flyer.body.bounce.setTo(0.8, 0.8);
// This sets the gravity the sprite responds to in the world, as a point
// Leave x=0 and set y=8 to simulate falling
flyer.body.gravity.setTo(0, 8);
// Leave x=0 and set y=80 to simulate falling
flyer.body.gravity.setTo(0, 80);
}
+11 -9
View File
@@ -20,7 +20,9 @@ function create() {
// displays it on-screen
// and assign it to a variable
ball = game.add.sprite(400, 200, 'ball');
knocker = game.add.sprite(400, 200, 'dude');
knocker.body.immovable = true;
// This gets it moving
ball.body.velocity.setTo(200, 200);
@@ -33,37 +35,37 @@ function create() {
ball.body.bounce.setTo(1, 1);
// This sets the gravity the sprite responds to in the world, as a point
// Here we leave x=0 and set y=8 to simulate falling
ball.body.gravity.setTo(0, 8);
// Here we leave x=0 and set y=80 to simulate falling
ball.body.gravity.setTo(0, 80);
}
// Move the knocker with the arrow keys
function update () {
// Enable physics between the knocker and the ball
game.physics.collide(knocker, ball);
if (cursors.up.isDown)
{
knocker.body.velocity.y = -400;
knocker.body.velocity.y = -300;
}
else if (cursors.down.isDown)
{
knocker.body.velocity.y = 400;
knocker.body.velocity.y = 300;
}
else if (cursors.left.isDown)
{
knocker.body.velocity.x = -400;
knocker.body.velocity.x = -300;
}
else if (cursors.right.isDown)
{
knocker.body.velocity.x = 400;
knocker.body.velocity.x = 300;
}
else
{
knocker.body.velocity.setTo(0, 0);
}
// Enable physics between the knocker and the ball
game.physics.collide(knocker, ball);
}
+2 -2
View File
@@ -31,8 +31,8 @@ function create() {
image.body.bounce.setTo(0.8, 0.8);
// This sets the gravity the sprite responds to in the world, as a point
// Leave x=0 and set y=8 to simulate falling
image.body.gravity.setTo(0, 8);
// Leave x=0 and set y=180 to simulate falling
image.body.gravity.setTo(0, 180);
}
+1 -1
View File
@@ -19,7 +19,7 @@ var launchVelocity = 0;
function create() {
// set global gravity
game.physics.gravity.y = 100;
game.physics.gravity.y = 200;
game.stage.backgroundColor = '#0072bc';
var graphics = game.add.graphics(0,0);
+55 -1
View File
@@ -28,7 +28,61 @@ function create() {
var bg = game.add.sprite(0, 0, bmd);
bg.body.moves = false;
test10();
test12();
}
function test12() {
// game.physics.gravity.y = 150;
sprite = game.add.sprite(200, 300, 'gameboy', 0);
sprite.name = 'red';
sprite.body.collideWorldBounds = true;
sprite.body.checkCollision.right = false;
// sprite.body.checkCollision.up = false;
// sprite.body.immovable = true;
sprite2 = game.add.sprite(400, 358, 'gameboy', 2);
sprite2.name = 'green';
sprite2.body.collideWorldBounds = true;
sprite2.body.bounce.setTo(0.9, 0.9);
game.input.onDown.add(launch12, this);
}
function launch12() {
sprite2.body.velocity.x = -200;
// sprite2.body.velocity.y = -60;
}
function test11() {
// game.physics.gravity.y = 150;
sprite = game.add.sprite(300, 200, 'gameboy', 0);
sprite.name = 'red';
sprite.body.collideWorldBounds = true;
// sprite.body.checkCollision.down = false;
// sprite.body.checkCollision.up = false;
sprite.body.checkCollision.right = false;
// sprite.body.immovable = true;
sprite2 = game.add.sprite(290, 400, 'gameboy', 2);
sprite2.name = 'green';
sprite2.body.collideWorldBounds = true;
sprite2.body.bounce.setTo(0.9, 0.9);
game.input.onDown.add(launch11, this);
}
function launch11() {
sprite2.body.velocity.y = -200;
}
+50
View File
@@ -0,0 +1,50 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('arrow', 'assets/sprites/longarrow.png');
}
var sprite;
var cursors;
function create() {
game.stage.backgroundColor = '#124184';
sprite = game.add.sprite(400, 300, 'arrow');
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
sprite.body.velocity.x = 0;
sprite.body.velocity.y = 0;
sprite.body.angularVelocity = 0;
if (cursors.left.isDown)
{
sprite.body.angularVelocity = -100;
}
else if (cursors.right.isDown)
{
sprite.body.angularVelocity = 100;
}
if (cursors.up.isDown)
{
game.physics.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
}
}
function render() {
game.debug.renderBodyInfo(sprite, 16, 24);
}
+48
View File
@@ -0,0 +1,48 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.spritesheet('gameboy', 'assets/sprites/gameboy_seize_color_40x60.png', 40, 60);
}
var sprite;
var sprite2;
function create() {
game.stage.backgroundColor = '#124184';
// Here we're tweening the scale of the sprite, which translates to the scale of the Body as well
// The collision will carry on working even against the scaled body.
sprite = game.add.sprite(200, 300, 'gameboy', 2);
sprite.name = 'green';
// sprite.anchor.setTo(0.5, 0.5);
sprite.body.immovable = true;
sprite2 = game.add.sprite(600, 300, 'gameboy', 3);
sprite2.name = 'yellow';
sprite2.body.rebound = false;
// sprite2.body.velocity.x = -200;
game.add.tween(sprite2).to( { x: 0 }, 3000, Phaser.Easing.Linear.None, true);
// game.add.tween(sprite.scale).to( { x: 3, y: 3 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
}
function update() {
game.physics.collide(sprite, sprite2);
}
function render() {
game.debug.renderPolygon(sprite.body.polygons, 'rgb(255,0,0)');
game.debug.renderPolygon(sprite2.body.polygons, 'rgb(255,0,0)');
}
+10 -15
View File
@@ -15,7 +15,7 @@ var platform;
function create() {
// Our ball sprite
ball = game.add.sprite(420, 100, 'wizball');
ball = game.add.sprite(440, 100, 'wizball');
ball.anchor.setTo(0.5, 0.5);
ball.body.customSeparateX = true;
@@ -42,25 +42,20 @@ function update() {
circle.y = ball.y;
// This is a rect vs. rect collision. The callback will check the circle.
game.physics.overlap(ball, platform, null, processCallback, this);
game.physics.overlap(ball, platform, collisionCallback, processCallback, this);
}
function collisionCallback(a, b) {
ball.body.y -= 10;
ball.body.velocity.y *= -1 * ball.body.bounce.y;
}
function processCallback(a, b) {
// console.log('p', a.y, b.y);
if (Phaser.Circle.intersectsRectangle(circle, platform.body))
{
console.log('boom', ball.body.overlapX, ball.body.overlapY);
// ball.body.x = ball.body.x - ball.body.overlapX;
// ball.body.velocity.x = platform.body.velocity.x - ball.body.velocity.x * ball.body.bounce.x;
ball.body.y -= 10;
ball.body.velocity.y *= -1 * ball.body.bounce.y;
}
return true;
return (Phaser.Circle.intersectsRectangle(circle, platform.body));
}
-1
View File
@@ -77,7 +77,6 @@
<meta charset="UTF-8" />
<title>phaser</title>
<base href="../"></base>
<script src="wip/SAT.js" type="text/javascript"></script>
<?php
require('../../build/config.php');
+13 -49
View File
@@ -1,76 +1,40 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
function preload() {
game.load.image('arrow', 'assets/sprites/asteroids_ship.png');
game.load.image('ball', 'assets/sprites/shinyball.png');
game.load.spritesheet('gameboy', 'assets/sprites/gameboy_seize_color_40x60.png', 40, 60);
game.load.spritesheet('spinner', 'assets/sprites/bluemetal_32x32x4.png', 32, 32);
}
var gameboy;
var sprites;
var bmd;
function create() {
game.stage.backgroundColor = '#124184';
bmd = game.add.bitmapData(800, 600);
bmd.fillStyle('#ffffff');
var bg = game.add.sprite(0, 0, bmd);
bg.body.moves = false;
game.physics.gravity.y = 250;
// game.physics.gravity.x = 250;
// Here we create a group, populate it with sprites, give them all a random velocity
// and then check the group against itself for collision
sprites = game.add.group();
for (var i = 0; i < 20; i++)
for (var i = 0; i < 30; i++)
{
var s = sprites.create(game.rnd.integerInRange(100, 700), game.rnd.integerInRange(32, 200), 'ball');
s.body.velocity.x = game.rnd.integerInRange(-400, 400);
var s = sprites.create(game.rnd.integerInRange(100, 700), game.rnd.integerInRange(32, 200), 'spinner');
s.animations.add('spin', [0,1,2,3]);
s.play('spin', 20, true);
s.body.velocity.x = game.rnd.integerInRange(-200, 200);
s.body.velocity.y = game.rnd.integerInRange(-200, 200);
s.name = 'ball' + i;
}
sprites.setAll('body.collideWorldBounds', true);
sprites.setAll('body.bounce.x', 0.9);
sprites.setAll('body.bounce.y', 0.9);
sprites.setAll('body.minBounceVelocity', 0.8);
gameboy = game.add.sprite(300, 50, 'gameboy', 0);
gameboy.name = 'gameboy';
gameboy.body.collideWorldBounds = true;
gameboy.body.bounce.setTo(0.9, 0.9);
gameboy.body.velocity.x = game.rnd.integerInRange(-400, 400);
gameboy.body.velocity.y = game.rnd.integerInRange(-200, 200);
sprites.setAll('body.bounce.x', 1);
sprites.setAll('body.bounce.y', 1);
sprites.setAll('body.friction', 0);
sprites.setAll('body.minBounceVelocity', 0);
}
function update() {
game.physics.collide(gameboy, sprites);
game.physics.collide(sprites);
// sprite.rotation = sprite.body.angle;
// if (sprite)
// {
// bmd.fillStyle('#ffff00');
// bmd.fillRect(sprite.body.center.x, sprite.body.center.y, 2, 2);
// }
// if (sprite2)
// {
// bmd.fillStyle('#ff00ff');
// bmd.fillRect(sprite2.body.center.x, sprite2.body.center.y, 2, 2);
// }
}
function render() {
}
+74 -114
View File
@@ -22,7 +22,6 @@
Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
/**
* The total number of particles in this emitter.
* @property {number} maxParticles - The total number of particles in this emitter..
* @default
*/
@@ -36,7 +35,8 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
this.name = 'emitter' + this.game.particles.ID++;
/**
* @property {Description} type - Description.
* @property {number} type - Internal Phaser Type value.
* @protected
*/
this.type = Phaser.EMITTER;
@@ -65,140 +65,114 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
this.height = 1;
/**
* The minimum possible velocity of a particle.
* The default value is (-100,-100).
* @property {Phaser.Point} minParticleSpeed
* @property {Phaser.Point} minParticleSpeed - The minimum possible velocity of a particle.
* @default
*/
this.minParticleSpeed = new Phaser.Point(-100, -100);
/**
* The maximum possible velocity of a particle.
* The default value is (100,100).
* @property {Phaser.Point} maxParticleSpeed
* @property {Phaser.Point} maxParticleSpeed - The maximum possible velocity of a particle.
* @default
*/
this.maxParticleSpeed = new Phaser.Point(100, 100);
/**
* The minimum possible scale of a particle.
* The default value is 1.
* @property {number} minParticleScale
* @property {number} minParticleScale - The minimum possible scale of a particle.
* @default
*/
this.minParticleScale = 1;
/**
* The maximum possible scale of a particle.
* The default value is 1.
* @property {number} maxParticleScale
* @property {number} maxParticleScale - The maximum possible scale of a particle.
* @default
*/
this.maxParticleScale = 1;
/**
* The minimum possible angular velocity of a particle. The default value is -360.
* @property {number} minRotation
* @property {number} minRotation - The minimum possible angular velocity of a particle.
* @default
*/
this.minRotation = -360;
/**
* The maximum possible angular velocity of a particle. The default value is 360.
* @property {number} maxRotation
* @property {number} maxRotation - The maximum possible angular velocity of a particle.
* @default
*/
this.maxRotation = 360;
/**
* Sets the <code>gravity.y</code> of each particle to this value on launch.
* @property {number} gravity
* @property {number} gravity - Sets the `body.gravity.y` of each particle sprite to this value on launch.
* @default
*/
this.gravity = 2;
this.gravity = 100;
/**
* Set your own particle class type here.
* @property {Description} particleClass
* @property {any} particleClass - For emitting your own particle class types.
* @default
*/
this.particleClass = null;
/**
* The friction component of particles launched from the emitter.
* @property {number} particleFriction
* @property {number} particleFriction - The friction component of particles launched from the emitter.
* @default
*/
this.particleFriction = 0;
/**
* The angular drag component of particles launched from the emitter if they are rotating.
* @property {number} angularDrag
* @property {number} angularDrag - The angular drag component of particles launched from the emitter if they are rotating.
* @default
*/
this.angularDrag = 0;
/**
* How often a particle is emitted in ms (if emitter is started with Explode === false).
* @property {boolean} frequency
* @property {boolean} frequency - How often a particle is emitted in ms (if emitter is started with Explode === false).
* @default
*/
this.frequency = 100;
/**
* How long each particle lives once it is emitted in ms. Default is 2 seconds.
* Set lifespan to 'zero' for particles to live forever.
* @property {number} lifespan
* @property {number} lifespan - How long each particle lives once it is emitted in ms. Default is 2 seconds. Set lifespan to 'zero' for particles to live forever.
* @default
*/
this.lifespan = 2000;
/**
* How much each particle should bounce on each axis. 1 = full bounce, 0 = no bounce.
* @property {Phaser.Point} bounce
* @property {Phaser.Point} bounce - How much each particle should bounce on each axis. 1 = full bounce, 0 = no bounce.
*/
this.bounce = new Phaser.Point();
/**
* Internal helper for deciding how many particles to launch.
* @property {number} _quantity
* @property {number} _quantity - Internal helper for deciding how many particles to launch.
* @private
* @default
*/
this._quantity = 0;
/**
* Internal helper for deciding when to launch particles or kill them.
* @property {number} _timer
* @property {number} _timer - Internal helper for deciding when to launch particles or kill them.
* @private
* @default
*/
this._timer = 0;
/**
* Internal counter for figuring out how many particles to launch.
* @property {number} _counter
* @property {number} _counter - Internal counter for figuring out how many particles to launch.
* @private
* @default
*/
this._counter = 0;
/**
* Internal helper for the style of particle emission (all at once, or one at a time).
* @property {boolean} _explode
* @property {boolean} _explode - Internal helper for the style of particle emission (all at once, or one at a time).
* @private
* @default
*/
this._explode = true;
/**
* Determines whether the emitter is currently emitting particles.
* It is totally safe to directly toggle this.
* @property {boolean} on
* @property {boolean} on - Determines whether the emitter is currently emitting particles. It is totally safe to directly toggle this.
* @default
*/
this.on = false;
/**
* Determines whether the emitter is being updated by the core game loop.
* @property {boolean} exists
* @property {boolean} exists - Determines whether the emitter is being updated by the core game loop.
* @default
*/
this.exists = true;
@@ -272,27 +246,19 @@ Phaser.Particles.Arcade.Emitter.prototype.update = function () {
* This function generates a new array of particle sprites to attach to the emitter.
*
* @method Phaser.Particles.Arcade.Emitter#makeParticles
* @param {Description} keys - Description.
* @param {number} frames - Description.
* @param {number} quantity - The number of particles to generate when using the "create from image" option.
* @param {number} collide - Description.
* @param {boolean} collideWorldBounds - Description.
* @return This Emitter instance (nice for chaining stuff together, if you're into that).
* @param {array|string} keys - A string or an array of strings that the particle sprites will use as their texture. If an array one is picked at random.
* @param {array|number} frames - A frame number, or array of frames that the sprite will use. If an array one is picked at random.
* @param {number} quantity - The number of particles to generate.
* @param {boolean} [collide=false] - Sets the checkCollision.none flag on the particle sprites body.
* @param {boolean} [collideWorldBounds=false] - A particle can be set to collide against the World bounds automatically and rebound back into the World if this is set to true. Otherwise it will leave the World.
* @return {Phaser.Particles.Arcade.Emitter} This Emitter instance.
*/
Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames, quantity, collide, collideWorldBounds) {
if (typeof frames == 'undefined')
{
frames = 0;
}
quantity = quantity || this.maxParticles;
collide = collide || 0;
if (typeof collideWorldBounds == 'undefined')
{
collideWorldBounds = false;
}
if (typeof frames === 'undefined') { frames = 0; }
if (typeof quantity === 'undefined') { quantity = this.maxParticles; }
if (typeof collide === 'undefined') { collide = false; }
if (typeof collideWorldBounds === 'undefined') { collideWorldBounds = false; }
var particle;
var i = 0;
@@ -301,14 +267,14 @@ Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames
while (i < quantity)
{
if (this.particleClass == null)
if (this.particleClass === null)
{
if (typeof keys == 'object')
if (typeof keys === 'object')
{
rndKey = this.game.rnd.pick(keys);
}
if (typeof frames == 'object')
if (typeof frames === 'object')
{
rndFrame = this.game.rnd.pick(frames);
}
@@ -320,7 +286,7 @@ Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames
// particle = new this.particleClass(this.game);
// }
if (collide > 0)
if (collide)
{
particle.body.checkCollision.any = true;
particle.body.checkCollision.none = false;
@@ -347,9 +313,9 @@ Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames
}
/**
* Call this function to turn off all the particles and the emitter.
* @method Phaser.Particles.Arcade.Emitter#kill
*/
* Call this function to turn off all the particles and the emitter.
* @method Phaser.Particles.Arcade.Emitter#kill
*/
Phaser.Particles.Arcade.Emitter.prototype.kill = function () {
this.on = false;
@@ -359,10 +325,9 @@ Phaser.Particles.Arcade.Emitter.prototype.kill = function () {
}
/**
* Handy for bringing game objects "back to life". Just sets alive and exists back to true.
* In practice, this is most often called by <code>Object.reset()</code>.
* @method Phaser.Particles.Arcade.Emitter#revive
*/
* Handy for bringing game objects "back to life". Just sets alive and exists back to true.
* @method Phaser.Particles.Arcade.Emitter#revive
*/
Phaser.Particles.Arcade.Emitter.prototype.revive = function () {
this.alive = true;
@@ -371,27 +336,19 @@ Phaser.Particles.Arcade.Emitter.prototype.revive = function () {
}
/**
* Call this function to start emitting particles.
* @method Phaser.Particles.Arcade.Emitter#start
* @param {boolean} explode - Whether the particles should all burst out at once.
* @param {number} lifespan - How long each particle lives once emitted. 0 = forever.
* @param {number} frequency - Ignored if Explode is set to true. Frequency is how often to emit a particle in ms.
* @param {number} quantity - How many particles to launch. 0 = "all of the particles".
*/
* Call this function to start emitting particles.
* @method Phaser.Particles.Arcade.Emitter#start
* @param {boolean} [explode=true] - Whether the particles should all burst out at once.
* @param {number} [lifespan=0] - How long each particle lives once emitted. 0 = forever.
* @param {number} [frequency=250] - Ignored if Explode is set to true. Frequency is how often to emit a particle in ms.
* @param {number} [quantity=0] - How many particles to launch. 0 = "all of the particles".
*/
Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, frequency, quantity) {
if (typeof explode !== 'boolean')
{
explode = true;
}
lifespan = lifespan || 0;
// How many ms between emissions?
frequency = frequency || 250;
// Total number of particles to emit
quantity = quantity || 0;
if (typeof explode === 'undefined') { explode = true; }
if (typeof lifespan === 'undefined') { lifespan = 0; }
if (typeof frequency === 'undefined') { frequency = 250; }
if (typeof quantity === 'undefined') { quantity = 0; }
this.revive();
@@ -417,9 +374,9 @@ Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, f
}
/**
* This function can be used both internally and externally to emit the next particle.
* @method Phaser.Particles.Arcade.Emitter#emitParticle
*/
* This function can be used both internally and externally to emit the next particle.
* @method Phaser.Particles.Arcade.Emitter#emitParticle
*/
Phaser.Particles.Arcade.Emitter.prototype.emitParticle = function () {
var particle = this.getFirstExists(false);
@@ -485,8 +442,8 @@ Phaser.Particles.Arcade.Emitter.prototype.emitParticle = function () {
/**
* A more compact way of setting the width and height of the emitter.
* @method Phaser.Particles.Arcade.Emitter#setSize
* @param {number} width - The desired width of the emitter (particles are spawned randomly within these dimensions).
* @param {number} height - The desired height of the emitter.
* @param {number} width - The desired width of the emitter (particles are spawned randomly within these dimensions).
* @param {number} height - The desired height of the emitter.
*/
Phaser.Particles.Arcade.Emitter.prototype.setSize = function (width, height) {
@@ -498,8 +455,8 @@ Phaser.Particles.Arcade.Emitter.prototype.setSize = function (width, height) {
/**
* A more compact way of setting the X velocity range of the emitter.
* @method Phaser.Particles.Arcade.Emitter#setXSpeed
* @param {number} min - The minimum value for this range.
* @param {number} max - The maximum value for this range.
* @param {number} [min=0] - The minimum value for this range.
* @param {number} [max=0] - The maximum value for this range.
*/
Phaser.Particles.Arcade.Emitter.prototype.setXSpeed = function (min, max) {
@@ -514,8 +471,8 @@ Phaser.Particles.Arcade.Emitter.prototype.setXSpeed = function (min, max) {
/**
* A more compact way of setting the Y velocity range of the emitter.
* @method Phaser.Particles.Arcade.Emitter#setYSpeed
* @param {number} min - The minimum value for this range.
* @param {number} max - The maximum value for this range.
* @param {number} [min=0] - The minimum value for this range.
* @param {number} [max=0] - The maximum value for this range.
*/
Phaser.Particles.Arcade.Emitter.prototype.setYSpeed = function (min, max) {
@@ -530,8 +487,8 @@ Phaser.Particles.Arcade.Emitter.prototype.setYSpeed = function (min, max) {
/**
* A more compact way of setting the angular velocity constraints of the emitter.
* @method Phaser.Particles.Arcade.Emitter#setRotation
* @param {number} min - The minimum value for this range.
* @param {number} max - The maximum value for this range.
* @param {number} [min=0] - The minimum value for this range.
* @param {number} [max=0] - The maximum value for this range.
*/
Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) {
@@ -544,14 +501,17 @@ Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) {
}
/**
* Change the emitter's midpoint to match the midpoint of a <code>Object</code>.
* Change the emitters center to match the center of any object with a `center` property, such as a Sprite.
* @method Phaser.Particles.Arcade.Emitter#at
* @param {object} object - The <code>Object</code> that you want to sync up with.
* @param {object|Phaser.Sprite} object - The object that you wish to match the center with.
*/
Phaser.Particles.Arcade.Emitter.prototype.at = function (object) {
this.emitX = object.center.x;
this.emitY = object.center.y;
if (object.center)
{
this.emitX = object.center.x;
this.emitY = object.center.y;
}
}
+13 -1
View File
@@ -111,6 +111,18 @@ Phaser.Physics.Arcade = function (game) {
};
/**
* @constant
* @type {number}
*/
Phaser.Physics.Arcade.RECT = 0;
/**
* @constant
* @type {number}
*/
Phaser.Physics.Arcade.CIRCLE = 1;
Phaser.Physics.Arcade.prototype = {
/**
@@ -327,7 +339,7 @@ Phaser.Physics.Arcade.prototype = {
collideHandler: function (object1, object2, collideCallback, processCallback, callbackContext, overlapOnly) {
// Only collide valid objects
if (typeof object2 === 'undefined' && object1.type === Phaser.GROUP)
if (typeof object2 === 'undefined' && (object1.type === Phaser.GROUP || object1.type === Phaser.EMITTER))
{
this.collideGroupVsSelf(object1, collideCallback, processCallback, callbackContext, overlapOnly);
return;
+240 -159
View File
@@ -211,6 +211,12 @@ Phaser.Physics.Arcade.Body = function (sprite) {
*/
this.facing = Phaser.NONE;
/**
* @property {boolean} rebound - A Body set to rebound will exchange velocity with another Body during collision. Set to false to allow this body to be 'pushed' rather than exchange velocity.
* @default
*/
this.rebound = true;
/**
* @property {boolean} immovable - An immovable Body will not receive any impacts or exchanges of velocity from other bodies.
* @default
@@ -289,6 +295,22 @@ Phaser.Physics.Arcade.Body = function (sprite) {
*/
this.blockedPoint = new Phaser.Point(0, 0);
/**
* @property {Phaser.Physics.Arcade.RECT|Phaser.Physics.Arcade.CIRCLE} type - The type of SAT Shape.
*/
this.type = Phaser.Physics.Arcade.RECT;
/**
* @property {SAT.Box|SAT.Circle|SAT.Polygon} shape - The SAT Collision shape.
*/
this.shape = new SAT.Box(new SAT.Vector(this.x, this.y), this.width, this.height);
/**
* @property {SAT.Polygon} polygons - The SAT Polygons, as derived from the Shape.
* @private
*/
this.polygons = this.shape.toPolygon();
/**
* @property {number} _dx - Internal cache var.
* @private
@@ -314,10 +336,10 @@ Phaser.Physics.Arcade.Body = function (sprite) {
this._sy = sprite.scale.y;
/**
* @property {number} _average - Internal cache var.
* @property {array} _distances - Internal cache var.
* @private
*/
this.polygons = new SAT.Box(new SAT.Vector(this.x, this.y), this.width, this.height).toPolygon();
this._distances = [0, 0, 0, 0];
this._debug = 0;
@@ -325,6 +347,22 @@ Phaser.Physics.Arcade.Body = function (sprite) {
Phaser.Physics.Arcade.Body.prototype = {
setCircle: function (radius) {
this.shape = new SAT.Circle(new SAT.Vector(this.x, this.y), radius);
this.polygons = null;
this.type = Phaser.Physics.Arcade.CIRCLE;
},
setBox: function () {
this.shape = new SAT.Box(new SAT.Vector(this.x, this.y), this.width, this.height);
this.polygons = this.shape.toPolygon();
this.type = Phaser.Physics.Arcade.RECT;
},
/**
* Internal method.
*
@@ -340,8 +378,10 @@ Phaser.Physics.Arcade.Body.prototype = {
this.halfWidth = Math.floor(this.width / 2);
this.halfHeight = Math.floor(this.height / 2);
// Scale by the difference between this and what it was previously
this.polygons.scale(scaleX / this._sx, scaleY / this._sy);
if (this.polygons)
{
this.polygons.scale(scaleX / this._sx, scaleY / this._sy);
}
this._sx = scaleX;
this._sy = scaleY;
@@ -395,8 +435,7 @@ Phaser.Physics.Arcade.Body.prototype = {
this.applyMotion();
}
this.polygons.pos.x = this.x;
this.polygons.pos.y = this.y;
this.syncPosition();
},
@@ -573,22 +612,7 @@ Phaser.Physics.Arcade.Body.prototype = {
this.velocity.y = -this.maxVelocity.y;
}
this.polygons.pos.x = this.x;
this.polygons.pos.y = this.y;
},
/**
* Checks for an overlap between this Body and the given Body.
*
* @method Phaser.Physics.Arcade#overlap
* @param {Phaser.Physics.Arcade.Body} body - The Body that collided.
* @param {SAT.Response} response - SAT Response handler.
* @return {boolean} True if the two bodies overlap, otherwise false.
*/
overlap: function (body, response) {
return SAT.testPolygonPolygon(this.polygons, body.polygons, response);
this.syncPosition();
},
@@ -664,6 +688,34 @@ Phaser.Physics.Arcade.Body.prototype = {
},
/**
* Subtracts the given Vector from this Body.
*
* @method Phaser.Physics.Arcade#sub
* @protected
* @param {SAT.Vector} v - The vector to substract from this Body.
*/
sub: function (v) {
this.x -= v.x;
this.y -= v.y;
},
/**
* Adds the given Vector from this Body.
*
* @method Phaser.Physics.Arcade#add
* @protected
* @param {SAT.Vector} v - The vector to add to this Body.
*/
add: function (v) {
this.x += v.x;
this.y += v.y;
},
/**
* Separation response handler.
*
@@ -675,7 +727,11 @@ Phaser.Physics.Arcade.Body.prototype = {
give: function (body, response) {
this.add(response.overlapV);
this.rebound(body);
if (this.rebound)
{
this.processRebound(body);
}
},
@@ -690,7 +746,11 @@ Phaser.Physics.Arcade.Body.prototype = {
take: function (body, response) {
this.sub(response.overlapV);
this.rebound(body);
if (this.rebound)
{
this.processRebound(body);
}
},
@@ -708,7 +768,10 @@ Phaser.Physics.Arcade.Body.prototype = {
this.sub(response.overlapV);
body.add(response.overlapV);
this.exchange(body);
if (this.rebound)
{
this.exchange(body);
}
},
@@ -721,9 +784,9 @@ Phaser.Physics.Arcade.Body.prototype = {
*/
exchange: function (body) {
if (this.mass === body.mass)
if (this.mass === body.mass && this.speed > 0 && body.speed > 0)
{
// A direct velocity exchange
// A direct velocity exchange (as they are both moving and have the same mass)
this._dx = body.velocity.x;
this._dy = body.velocity.y;
@@ -762,11 +825,11 @@ Phaser.Physics.Arcade.Body.prototype = {
/**
* Rebound the velocity of this Body.
*
* @method Phaser.Physics.Arcade#rebound
* @method Phaser.Physics.Arcade#processRebound
* @protected
* @param {Phaser.Physics.Arcade.Body} body - The Body that collided.
*/
rebound: function (body) {
processRebound: function (body) {
this.velocity.x = body.velocity.x - this.velocity.x * this.bounce.x;
this.velocity.y = body.velocity.y - this.velocity.y * this.bounce.y;
@@ -774,8 +837,99 @@ Phaser.Physics.Arcade.Body.prototype = {
},
/**
* Checks for an overlap between this Body and the given Body.
*
* @method Phaser.Physics.Arcade#overlap
* @param {Phaser.Physics.Arcade.Body} body - The Body that is being checked against this Body.
* @param {SAT.Response} response - SAT Response handler.
* @return {boolean} True if the two bodies overlap, otherwise false.
*/
overlap: function (body, response) {
if (this.type === Phaser.Physics.Arcade.RECT && body.type === Phaser.Physics.Arcade.RECT)
{
return SAT.testPolygonPolygon(this.polygons, body.polygons, response);
}
else if (this.type === Phaser.Physics.Arcade.CIRCLE && body.type === Phaser.Physics.Arcade.CIRCLE)
{
return SAT.testCircleCircle(this.shape, body.shape, response);
}
else if (this.type === Phaser.Physics.Arcade.RECT && body.type === Phaser.Physics.Arcade.CIRCLE)
{
return SAT.testPolygonCircle(this.polygons, body.shape, response);
}
else if (this.type === Phaser.Physics.Arcade.CIRCLE && body.type === Phaser.Physics.Arcade.RECT)
{
return SAT.testCirclePolygon(this.shape, body.polygons, response);
}
},
/**
* This separates this Body from the given Body unless a customSeparateCallback is set.
* It assumes they have already been overlap checked and the resulting overlap is stored in overlapX and overlapY.
*
* @method Phaser.Physics.Arcade#separate
* @protected
* @param {Phaser.Physics.Arcade.Body} body - The Body to be separated from this one.
* @param {SAT.Response} response - SAT Response handler.
* @return {boolean}
*/
separate: function (body, response) {
if (this.customSeparateCallback)
{
return this.customSeparateCallback.call(this.customSeparateContext, this, response);
}
this._distances[0] = body.right - this.x; // Distance of B to face on left side of A
this._distances[1] = this.right - body.x; // Distance of B to face on right side of A
this._distances[2] = body.bottom - this.y; // Distance of B to face on bottom side of A
this._distances[3] = this.bottom - body.y; // Distance of B to face on top side of A
if (response.overlapN.x)
{
// Which is smaller? Left or Right?
if (this._distances[0] < this._distances[1])
{
// console.log(this.sprite.name, 'collided on the LEFT with', body.sprite.name, response);
this.hitLeft(body, response);
}
else if (this._distances[1] < this._distances[0])
{
// console.log(this.sprite.name, 'collided on the RIGHT with', body.sprite.name, response);
this.hitRight(body, response);
}
}
else if (response.overlapN.y)
{
// Which is smaller? Top or Bottom?
if (this._distances[2] < this._distances[3])
{
// console.log(this.sprite.name, 'collided on the TOP with', body.sprite.name, response);
this.hitTop(body, response);
}
else if (this._distances[3] < this._distances[2])
{
// console.log(this.sprite.name, 'collided on the BOTTOM with', body.sprite.name, response);
this.hitBottom(body, response);
}
}
this.syncPosition();
body.syncPosition();
return true;
},
/**
* Process a collision with the left face of this Body.
* Collision and separation can be further checked by setting a collideCallback.
* This callback will be sent 4 parameters: The face of collision, this Body, the colliding Body and the SAT Response.
* If the callback returns true then separation, rebounds and the touching flags will all be set.
* If it returns false this will be skipped and must be handled manually.
*
* @method Phaser.Physics.Arcade#hitLeft
* @protected
@@ -784,13 +938,13 @@ Phaser.Physics.Arcade.Body.prototype = {
*/
hitLeft: function (body, response) {
// We know that Body is overlapping with This on the left-hand side
if ((body.deltaX() < 0 && !this.checkCollision.right) || (body.deltaX() > 0 && !this.checkCollision.left))
// We know that Body is overlapping with This on the left hand side (deltaX < 0 = moving left, > 0 = moving right)
if (body.speed > 0 && (body.deltaX() <= 0 || (body.deltaX() > 0 && !this.checkCollision.left)))
{
return;
}
if ((body.deltaY() < 0 && !this.checkCollision.down) || (body.deltaY() > 0 && !this.checkCollision.up) || (body.deltaY() > 0 && !this.checkCollision.up) || (body.deltaY() > 0 && !this.checkCollision.down))
if (this.collideCallback && !this.collideCallback.call(this.collideCallbackContext, Phaser.LEFT, this, body, response))
{
return;
}
@@ -823,15 +977,14 @@ Phaser.Physics.Arcade.Body.prototype = {
this.x -= this.right - this.game.world.bounds.right;
}
if (this.collideCallback)
{
this.collideCallback.call(this.collideCallbackContext, Phaser.LEFT, this, body);
}
},
/**
* Process a collision with the right face of this Body.
* Collision and separation can be further checked by setting a collideCallback.
* This callback will be sent 4 parameters: The face of collision, this Body, the colliding Body and the SAT Response.
* If the callback returns true then separation, rebounds and the touching flags will all be set.
* If it returns false this will be skipped and must be handled manually.
*
* @method Phaser.Physics.Arcade#hitRight
* @protected
@@ -840,13 +993,13 @@ Phaser.Physics.Arcade.Body.prototype = {
*/
hitRight: function (body, response) {
// We know that Body is overlapping with This on the right-hand side
if ((body.deltaX() < 0 && !this.checkCollision.right) || (body.deltaX() > 0 && !this.checkCollision.left))
// We know that Body is overlapping with This on the right hand side (deltaX < 0 = moving left, > 0 = moving right)
if (body.speed > 0 && (body.deltaX() >= 0 || (body.deltaX() < 0 && !this.checkCollision.right)))
{
return;
}
if ((body.deltaY() < 0 && !this.checkCollision.down) || (body.deltaY() > 0 && !this.checkCollision.up) || (body.deltaY() > 0 && !this.checkCollision.up) || (body.deltaY() > 0 && !this.checkCollision.down))
if (this.collideCallback && !this.collideCallback.call(this.collideCallbackContext, Phaser.RIGHT, this, body))
{
return;
}
@@ -879,15 +1032,14 @@ Phaser.Physics.Arcade.Body.prototype = {
this.x += this.game.world.bounds.x - this.x;
}
if (this.collideCallback)
{
this.collideCallback.call(this.collideCallbackContext, Phaser.RIGHT, this, body);
}
},
/**
* Process a collision with the top face of this Body.
* Collision and separation can be further checked by setting a collideCallback.
* This callback will be sent 4 parameters: The face of collision, this Body, the colliding Body and the SAT Response.
* If the callback returns true then separation, rebounds and the touching flags will all be set.
* If it returns false this will be skipped and must be handled manually.
*
* @method Phaser.Physics.Arcade#hitTop
* @protected
@@ -896,8 +1048,13 @@ Phaser.Physics.Arcade.Body.prototype = {
*/
hitTop: function (body, response) {
// We know that Body is overlapping with This on the top side (deltaY > 0 = moving down < 0 = moving up)
if ((body.deltaY() > 0 && (!this.checkCollision.up || !this.checkCollision.down)) || (body.deltaY() < 0 && (!this.checkCollision.down || !this.checkCollision.up)))
// We know that Body is overlapping with This on the bottom side (deltaY < 0 = moving up, > 0 = moving down)
if (body.speed > 0 && (body.deltaY() <= 0 || (body.deltaY() > 0 && !this.checkCollision.up)))
{
return;
}
if (this.collideCallback && !this.collideCallback.call(this.collideCallbackContext, Phaser.UP, this, body))
{
return;
}
@@ -930,15 +1087,14 @@ Phaser.Physics.Arcade.Body.prototype = {
this.y -= this.bottom - this.game.world.bounds.bottom;
}
if (this.collideCallback)
{
this.collideCallback.call(this.collideCallbackContext, Phaser.UP, this, body);
}
},
/**
* Process a collision with the bottom face of this Body.
* Collision and separation can be further checked by setting a collideCallback.
* This callback will be sent 4 parameters: The face of collision, this Body, the colliding Body and the SAT Response.
* If the callback returns true then separation, rebounds and the touching flags will all be set.
* If it returns false this will be skipped and must be handled manually.
*
* @method Phaser.Physics.Arcade#hitBottom
* @protected
@@ -947,8 +1103,13 @@ Phaser.Physics.Arcade.Body.prototype = {
*/
hitBottom: function (body, response) {
// We know that Body is overlapping with This on the bottom side (deltaY > 0 = moving down < 0 = moving up)
if ((body.deltaY() < 0 && (!this.checkCollision.down || !this.checkCollision.up)) || (body.deltaY() < 0 && (!this.checkCollision.down || !this.checkCollision.up)))
// We know that Body is overlapping with This on the bottom side (deltaY < 0 = moving up, > 0 = moving down)
if (body.speed > 0 && (body.deltaY() >= 0 || (body.deltaY() < 0 && !this.checkCollision.down)))
{
return;
}
if (this.collideCallback && !this.collideCallback.call(this.collideCallbackContext, Phaser.DOWN, this, body))
{
return;
}
@@ -981,102 +1142,25 @@ Phaser.Physics.Arcade.Body.prototype = {
this.y += this.game.world.bounds.y - this.y;
}
if (this.collideCallback)
{
this.collideCallback.call(this.collideCallbackContext, Phaser.DOWN, this, body);
}
},
/**
* Subtracts the given Vector from this Body.
* Internal method that syncs the Body coordinates with the SAT shape and polygon positions.
*
* @method Phaser.Physics.Arcade#sub
* @method Phaser.Physics.Arcade#syncPosition
* @protected
* @param {SAT.Vector} v - The vector to substract from this Body.
*/
sub: function (v) {
syncPosition: function () {
this.x -= v.x;
this.y -= v.y;
this.shape.pos.x = this.x;
this.shape.pos.y = this.y;
},
/**
* Adds the given Vector from this Body.
*
* @method Phaser.Physics.Arcade#add
* @protected
* @param {SAT.Vector} v - The vector to add to this Body.
*/
add: function (v) {
this.x += v.x;
this.y += v.y;
},
/**
* This separates this Body from the given Body unless a customSeparateCallback is set.
* It assumes they have already been overlap checked and the resulting overlap is stored in overlapX and overlapY.
*
* @method Phaser.Physics.Arcade#separate
* @protected
* @param {Phaser.Physics.Arcade.Body} body - The Body to be separated from this one.
* @param {SAT.Response} response - SAT Response handler.
* @return {boolean}
*/
separate: function (body, response) {
if (this.customSeparateCallback)
if (this.polygons)
{
return this.customSeparateCallback.call(this.customSeparateContext, this, response);
this.polygons.pos.x = this.x;
this.polygons.pos.y = this.y;
}
var distances = [
(body.right - this.x), // distance of box 'b' to face on 'left' side of 'a'.
(this.right - body.x), // distance of box 'b' to face on 'right' side of 'a'.
(body.bottom - this.y), // distance of box 'b' to face on 'bottom' side of 'a'.
(this.bottom - body.y) // distance of box 'b' to face on 'top' side of 'a'.
];
if (response.overlapN.x)
{
// Which is smaller? Left or Right?
if (distances[0] < distances[1])
{
console.log(this.sprite.name, 'collided on the LEFT with', body.sprite.name, response);
this.hitLeft(body, response);
}
else if (distances[1] < distances[0])
{
console.log(this.sprite.name, 'collided on the RIGHT with', body.sprite.name, response);
this.hitRight(body, response);
}
}
else if (response.overlapN.y)
{
// Which is smaller? Top or Bottom?
if (distances[2] < distances[3])
{
console.log(this.sprite.name, 'collided on the TOP with', body.sprite.name, response);
this.hitTop(body, response);
}
else if (distances[3] < distances[2])
{
console.log(this.sprite.name, 'collided on the BOTTOM with', body.sprite.name, response);
this.hitBottom(body, response);
}
}
this.polygons.pos.x = this.x;
this.polygons.pos.y = this.y;
body.polygons.pos.x = body.x;
body.polygons.pos.y = body.y;
return true;
},
/**
@@ -1152,9 +1236,17 @@ Phaser.Physics.Arcade.Body.prototype = {
this.halfWidth = Math.floor(this.width / 2);
this.halfHeight = Math.floor(this.height / 2);
this.offset.setTo(offsetX, offsetY);
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
if (this.type === Phaser.Physics.Arcade.RECT)
{
this.setBox();
}
else
{
this.setCircle();
}
},
/**
@@ -1177,8 +1269,14 @@ Phaser.Physics.Arcade.Body.prototype = {
this.y = this.preY;
this.rotation = this.preRotation;
this.polygons.pos.x = this.x;
this.polygons.pos.y = this.y;
this.shape.pos.x = this.x;
this.shape.pos.y = this.y;
if (this.polygons)
{
this.polygons.pos.x = this.x;
this.polygons.pos.y = this.y;
}
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
@@ -1303,20 +1401,3 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", {
}
});
/**
* @name Phaser.Physics.Arcade.Body#movingLeft
* @property {boolean} movingLeft - True if this Body is moving left, based on its angle and speed.
*/
Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "movingLeft", {
/**
* True if this Body is moving left, based on its angle and speed.
* @method movingLeft
* @return {boolean}
*/
get: function () {
return (this.speed > 0 && this.angle >= 0 && this.angle <= 0);
},
});
+862
View File
@@ -0,0 +1,862 @@
// Version 0.2 - Copyright 2013 - Jim Riecken <jimr@jimr.ca>
//
// Released under the MIT License - https://github.com/jriecken/sat-js
//
// A simple library for determining intersections of circles and
// polygons using the Separating Axis Theorem.
/** @preserve SAT.js - Version 0.2 - Copyright 2013 - Jim Riecken <jimr@jimr.ca> - released under the MIT License. https://github.com/jriecken/sat-js */
/*global define: false, module: false*/
/*jshint shadow:true, sub:true, forin:true, noarg:true, noempty:true,
eqeqeq:true, bitwise:true, strict:true, undef:true,
curly:true, browser:true */
// Create a UMD wrapper for SAT. Works in:
//
// - Plain browser via global SAT variable
// - AMD loader (like require.js)
// - Node.js
//
// The quoted properties all over the place are used so that the Closure Compiler
// does not mangle the exposed API in advanced mode.
/**
* @param {*} root - The global scope
* @param {Function} factory - Factory that creates SAT module
*/
(function (root, factory) {
"use strict";
if (typeof define === 'function' && define['amd']) {
define(factory);
} else if (typeof exports === 'object') {
module['exports'] = factory();
} else {
root['SAT'] = factory();
}
}(this, function () {
"use strict";
var SAT = {};
//
// ## Vector
//
// Represents a vector in two dimensions with `x` and `y` properties.
// Create a new Vector, optionally passing in the `x` and `y` coordinates. If
// a coordinate is not specified, it will be set to `0`
/**
* @param {?number=} x The x position.
* @param {?number=} y The y position.
* @constructor
*/
function Vector(x, y) {
this['x'] = x || 0;
this['y'] = y || 0;
}
SAT['Vector'] = Vector;
// Alias `Vector` as `V`
SAT['V'] = Vector;
// Copy the values of another Vector into this one.
/**
* @param {Vector} other The other Vector.
* @return {Vector} This for chaining.
*/
Vector.prototype['copy'] = Vector.prototype.copy = function(other) {
this['x'] = other['x'];
this['y'] = other['y'];
return this;
};
// Change this vector to be perpendicular to what it was before. (Effectively
// roatates it 90 degrees in a clockwise direction)
/**
* @return {Vector} This for chaining.
*/
Vector.prototype['perp'] = Vector.prototype.perp = function() {
var x = this['x'];
this['x'] = this['y'];
this['y'] = -x;
return this;
};
// Rotate this vector (counter-clockwise) by the specified angle (in radians).
/**
* @param {number} angle The angle to rotate (in radians)
* @return {Vector} This for chaining.
*/
Vector.prototype['rotate'] = Vector.prototype.rotate = function (angle) {
var x = this['x'];
var y = this['y'];
this['x'] = x * Math.cos(angle) - y * Math.sin(angle);
this['y'] = x * Math.sin(angle) + y * Math.cos(angle);
return this;
};
// Rotate this vector (counter-clockwise) by the specified angle (in radians) which has already been calculated into sin and cos.
/**
* @param {number} sin - The Math.sin(angle)
* @param {number} cos - The Math.cos(angle)
* @return {Vector} This for chaining.
*/
Vector.prototype['rotatePrecalc'] = Vector.prototype.rotatePrecalc = function (sin, cos) {
var x = this['x'];
var y = this['y'];
this['x'] = x * cos - y * sin;
this['y'] = x * sin + y * cos;
return this;
};
// Reverse this vector.
/**
* @return {Vector} This for chaining.
*/
Vector.prototype['reverse'] = Vector.prototype.reverse = function() {
this['x'] = -this['x'];
this['y'] = -this['y'];
return this;
};
// Normalize this vector. (make it have length of `1`)
/**
* @return {Vector} This for chaining.
*/
Vector.prototype['normalize'] = Vector.prototype.normalize = function() {
var d = this.len();
if(d > 0) {
this['x'] = this['x'] / d;
this['y'] = this['y'] / d;
}
return this;
};
// Add another vector to this one.
/**
* @param {Vector} other The other Vector.
* @return {Vector} This for chaining.
*/
Vector.prototype['add'] = Vector.prototype.add = function(other) {
this['x'] += other['x'];
this['y'] += other['y'];
return this;
};
// Subtract another vector from this one.
/**
* @param {Vector} other The other Vector.
* @return {Vector} This for chaiing.
*/
Vector.prototype['sub'] = Vector.prototype.sub = function(other) {
this['x'] -= other['x'];
this['y'] -= other['y'];
return this;
};
// Scale this vector. An independant scaling factor can be provided
// for each axis, or a single scaling factor that will scale both `x` and `y`.
/**
* @param {number} x The scaling factor in the x direction.
* @param {?number=} y The scaling factor in the y direction. If this
* is not specified, the x scaling factor will be used.
* @return {Vector} This for chaining.
*/
Vector.prototype['scale'] = Vector.prototype.scale = function(x,y) {
this['x'] *= x;
this['y'] *= y || x;
return this;
};
// Project this vector on to another vector.
/**
* @param {Vector} other The vector to project onto.
* @return {Vector} This for chaining.
*/
Vector.prototype['project'] = Vector.prototype.project = function(other) {
var amt = this.dot(other) / other.len2();
this['x'] = amt * other['x'];
this['y'] = amt * other['y'];
return this;
};
// Project this vector onto a vector of unit length. This is slightly more efficient
// than `project` when dealing with unit vectors.
/**
* @param {Vector} other The unit vector to project onto.
* @return {Vector} This for chaining.
*/
Vector.prototype['projectN'] = Vector.prototype.projectN = function(other) {
var amt = this.dot(other);
this['x'] = amt * other['x'];
this['y'] = amt * other['y'];
return this;
};
// Reflect this vector on an arbitrary axis.
/**
* @param {Vector} axis The vector representing the axis.
* @return {Vector} This for chaining.
*/
Vector.prototype['reflect'] = Vector.prototype.reflect = function(axis) {
var x = this['x'];
var y = this['y'];
this.project(axis).scale(2);
this['x'] -= x;
this['y'] -= y;
return this;
};
// Reflect this vector on an arbitrary axis (represented by a unit vector). This is
// slightly more efficient than `reflect` when dealing with an axis that is a unit vector.
/**
* @param {Vector} axis The unit vector representing the axis.
* @return {Vector} This for chaining.
*/
Vector.prototype['reflectN'] = Vector.prototype.reflectN = function(axis) {
var x = this['x'];
var y = this['y'];
this.projectN(axis).scale(2);
this['x'] -= x;
this['y'] -= y;
return this;
};
// Get the dot product of this vector and another.
/**
* @param {Vector} other The vector to dot this one against.
* @return {number} The dot product.
*/
Vector.prototype['dot'] = Vector.prototype.dot = function(other) {
return this['x'] * other['x'] + this['y'] * other['y'];
};
// Get the squared length of this vector.
/**
* @return {number} The length^2 of this vector.
*/
Vector.prototype['len2'] = Vector.prototype.len2 = function() {
return this.dot(this);
};
// Get the length of this vector.
/**
* @return {number} The length of this vector.
*/
Vector.prototype['len'] = Vector.prototype.len = function() {
return Math.sqrt(this.len2());
};
// ## Circle
//
// Represents a circle with a position and a radius.
// Create a new circle, optionally passing in a position and/or radius. If no position
// is given, the circle will be at `(0,0)`. If no radius is provided, the circle will
// have a radius of `0`.
/**
* @param {Vector=} pos A vector representing the position of the center of the circle
* @param {?number=} r The radius of the circle
* @constructor
*/
function Circle(pos, r) {
this['pos'] = pos || new Vector();
this['r'] = r || 0;
}
SAT['Circle'] = Circle;
// ## Polygon
//
// Represents a *convex* polygon with any number of points (specified in counter-clockwise order)
//
// The edges/normals of the polygon will be calculated on creation and stored in the
// `edges` and `normals` properties. If you change the polygon's points, you will need
// to call `recalc` to recalculate the edges/normals.
// Create a new polygon, passing in a position vector, and an array of points (represented
// by vectors relative to the position vector). If no position is passed in, the position
// of the polygon will be `(0,0)`.
/**
* @param {Vector=} pos A vector representing the origin of the polygon. (all other
* points are relative to this one)
* @param {Array.<Vector>=} points An array of vectors representing the points in the polygon,
* in counter-clockwise order.
* @constructor
*/
function Polygon(pos, points) {
this['pos'] = pos || new Vector();
this['points'] = points || [];
this.recalc();
}
SAT['Polygon'] = Polygon;
// Recalculates the edges and normals of the polygon. This **must** be called
// if the `points` array is modified at all and the edges or normals are to be
// accessed.
/**
* @return {Polygon} This for chaining.
*/
Polygon.prototype['recalc'] = Polygon.prototype.recalc = function() {
// The edges here are the direction of the `n`th edge of the polygon, relative to
// the `n`th point. If you want to draw a given edge from the edge value, you must
// first translate to the position of the starting point.
this['edges'] = [];
// The normals here are the direction of the normal for the `n`th edge of the polygon, relative
// to the position of the `n`th point. If you want to draw an edge normal, you must first
// translate to the position of the starting point.
this['normals'] = [];
var points = this['points'];
var len = points.length;
for (var i = 0; i < len; i++) {
var p1 = points[i];
var p2 = i < len - 1 ? points[i + 1] : points[0];
var e = new Vector().copy(p2).sub(p1);
var n = new Vector().copy(e).perp().normalize();
this['edges'].push(e);
this['normals'].push(n);
}
return this;
};
// Rotates this polygon counter-clockwise around the origin of *its local coordinate system* (i.e. `pos`).
//
// Note: You do **not** need to call `recalc` after rotation.
/**
* @param {number} angle The angle to rotate (in radians)
* @return {Polygon} This for chaining.
*/
Polygon.prototype['rotate'] = Polygon.prototype.rotate = function(angle) {
var i;
var points = this['points'];
var edges = this['edges'];
var normals = this['normals'];
var len = points.length;
// Calc it just the once, rather than 4 times per array element
var cos = Math.cos(angle);
var sin = Math.sin(angle);
for (i = 0; i < len; i++) {
points[i].rotatePrecalc(sin, cos);
edges[i].rotatePrecalc(sin, cos);
normals[i].rotatePrecalc(sin, cos);
}
return this;
};
// Rotates this polygon counter-clockwise around the origin of *its local coordinate system* (i.e. `pos`).
//
// Note: You do **not** need to call `recalc` after rotation.
/**
* @param {number} angle The angle to rotate (in radians)
* @return {Polygon} This for chaining.
*/
Polygon.prototype['scale'] = Polygon.prototype.scale = function(x, y) {
var i;
var points = this['points'];
var edges = this['edges'];
var normals = this['normals'];
var len = points.length;
for (i = 0; i < len; i++) {
points[i].scale(x,y);
edges[i].scale(x,y);
normals[i].scale(x,y);
}
return this;
};
// Translates the points of this polygon by a specified amount relative to the origin of *its own coordinate
// system* (i.e. `pos`).
//
// This is most useful to change the "center point" of a polygon.
//
// Note: You do **not** need to call `recalc` after translation.
/**
* @param {number} x The horizontal amount to translate.
* @param {number} y The vertical amount to translate.
* @return {Polygon} This for chaining.
*/
Polygon.prototype['translate'] = Polygon.prototype.translate = function (x, y) {
var i;
var points = this['points'];
var len = points.length;
for (i = 0; i < len; i++) {
points[i].x += x;
points[i].y += y;
}
return this;
};
// ## Box
//
// Represents an axis-aligned box, with a width and height.
// Create a new box, with the specified position, width, and height. If no position
// is given, the position will be `(0,0)`. If no width or height are given, they will
// be set to `0`.
/**
* @param {Vector=} pos A vector representing the top-left of the box.
* @param {?number=} w The width of the box.
* @param {?number=} h The height of the box.
* @constructor
*/
function Box(pos, w, h) {
this['pos'] = pos || new Vector();
this['w'] = w || 0;
this['h'] = h || 0;
}
SAT['Box'] = Box;
// Returns a polygon whose edges are the same as this box.
/**
* @return {Polygon} A new Polygon that represents this box.
*/
Box.prototype['toPolygon'] = Box.prototype.toPolygon = function() {
var pos = this['pos'];
var w = this['w'];
var h = this['h'];
return new Polygon(new Vector(pos['x'], pos['y']), [
new Vector(), new Vector(w, 0),
new Vector(w,h), new Vector(0,h)
]);
};
// ## Response
//
// An object representing the result of an intersection. Contains:
// - The two objects participating in the intersection
// - The vector representing the minimum change necessary to extract the first object
// from the second one (as well as a unit vector in that direction and the magnitude
// of the overlap)
// - Whether the first object is entirely inside the second, and vice versa.
/**
* @constructor
*/
function Response() {
this['a'] = null;
this['b'] = null;
this['overlapN'] = new Vector();
this['overlapV'] = new Vector();
this.clear();
}
SAT['Response'] = Response;
// Set some values of the response back to their defaults. Call this between tests if
// you are going to reuse a single Response object for multiple intersection tests (recommented
// as it will avoid allcating extra memory)
/**
* @return {Response} This for chaining
*/
Response.prototype['clear'] = Response.prototype.clear = function() {
this['aInB'] = true;
this['bInA'] = true;
this['overlap'] = Number.MAX_VALUE;
return this;
};
// ## Object Pools
// A pool of `Vector` objects that are used in calculations to avoid
// allocating memory.
/**
* @type {Array.<Vector>}
*/
var T_VECTORS = [];
for (var i = 0; i < 10; i++) { T_VECTORS.push(new Vector()); }
// A pool of arrays of numbers used in calculations to avoid allocating
// memory.
/**
* @type {Array.<Array.<number>>}
*/
var T_ARRAYS = [];
for (var i = 0; i < 5; i++) { T_ARRAYS.push([]); }
// ## Helper Functions
// 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.<Vector>} points The points to flatten.
* @param {Vector} normal The unit vector axis to flatten on.
* @param {Array.<number>} result An array. After calling this function,
* result[0] will be the minimum value,
* result[1] will be the maximum value.
*/
function 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++ ) {
// 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;
}
// Check whether two convex 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.<Vector>} aPoints The points in the first polygon.
* @param {Array.<Vector>} 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.
*/
function isSeparatingAxis(aPos, bPos, aPoints, bPoints, axis, response) {
var rangeA = T_ARRAYS.pop();
var rangeB = T_ARRAYS.pop();
// The magnitude of the offset between the two polygons
var offsetV = T_VECTORS.pop().copy(bPos).sub(aPos);
var projectedOffset = offsetV.dot(axis);
// Project the polygons onto the axis.
flattenPointsOn(aPoints, axis, rangeA);
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]) {
T_VECTORS.push(offsetV);
T_ARRAYS.push(rangeA);
T_ARRAYS.push(rangeB);
return true;
}
// This is not a separating axis. 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'].copy(axis);
if (overlap < 0) {
response['overlapN'].reverse();
}
}
}
T_VECTORS.push(offsetV);
T_ARRAYS.push(rangeA);
T_ARRAYS.push(rangeB);
return false;
}
// 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) [S]--------------[E] (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.
*/
function vornoiRegion(line, point) {
var len2 = line.len2();
var dp = point.dot(line);
// If the point is beyond the start of the line, it is in the
// left vornoi region.
if (dp < 0) { return LEFT_VORNOI_REGION; }
// If the point is beyond the end of the line, it is in the
// right vornoi region.
else if (dp > len2) { return RIGHT_VORNOI_REGION; }
// Otherwise, it's in the middle one.
else { return MIDDLE_VORNOI_REGION; }
}
// Constants for Vornoi regions
/**
* @const
*/
var LEFT_VORNOI_REGION = -1;
/**
* @const
*/
var MIDDLE_VORNOI_REGION = 0;
/**
* @const
*/
var RIGHT_VORNOI_REGION = 1;
// ## Collision Tests
// Check if two circles collide.
/**
* @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.
*/
function testCircleCircle(a, b, response) {
// Check if the distance between the centers of the two
// circles is greater than their combined radius.
var differenceV = T_VECTORS.pop().copy(b['pos']).sub(a['pos']);
var totalRadius = a['r'] + b['r'];
var totalRadiusSq = totalRadius * totalRadius;
var distanceSq = differenceV.len2();
// If the distance is bigger than the combined radius, they don't intersect.
if (distanceSq > totalRadiusSq) {
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'].copy(differenceV.normalize());
response['overlapV'].copy(differenceV).scale(response['overlap']);
response['aInB']= a['r'] <= b['r'] && dist <= b['r'] - a['r'];
response['bInA'] = b['r'] <= a['r'] && dist <= a['r'] - b['r'];
}
T_VECTORS.push(differenceV);
return true;
}
SAT['testCircleCircle'] = testCircleCircle;
// Check if a polygon and a circle collide.
/**
* @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.
*/
function testPolygonCircle(polygon, circle, response) {
// Get the position of the circle relative to the polygon.
var circlePos = T_VECTORS.pop().copy(circle['pos']).sub(polygon['pos']);
var radius = circle['r'];
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.copy(polygon['edges'][i]);
// Calculate the center of the circle relative to the starting point of the edge.
point.copy(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.len2() > radius2) {
response['aInB'] = false;
}
// Calculate which Vornoi region the center of the circle is in.
var region = vornoiRegion(edge, point);
// If it's the left region:
if (region === LEFT_VORNOI_REGION) {
// We need to make sure we're in the RIGHT_VORNOI_REGION of the previous edge.
edge.copy(polygon['edges'][prev]);
// Calculate the center of the circle relative the starting point of the previous edge
var point2 = T_VECTORS.pop().copy(circlePos).sub(points[prev]);
region = vornoiRegion(edge, point2);
if (region === RIGHT_VORNOI_REGION) {
// It's in the region we want. Check if the circle intersects the point.
var dist = point.len();
if (dist > radius) {
// No intersection
T_VECTORS.push(circlePos);
T_VECTORS.push(edge);
T_VECTORS.push(point);
T_VECTORS.push(point2);
return false;
} else if (response) {
// It intersects, calculate the overlap.
response['bInA'] = false;
overlapN = point.normalize();
overlap = radius - dist;
}
}
T_VECTORS.push(point2);
// If it's the right region:
} else if (region === RIGHT_VORNOI_REGION) {
// We need to make sure we're in the left region on the next edge
edge.copy(polygon['edges'][next]);
// Calculate the center of the circle relative to the starting point of the next edge.
point.copy(circlePos).sub(points[next]);
region = vornoiRegion(edge, point);
if (region === LEFT_VORNOI_REGION) {
// It's in the region we want. Check if the circle intersects the point.
var dist = point.len();
if (dist > radius) {
// No intersection
T_VECTORS.push(circlePos);
T_VECTORS.push(edge);
T_VECTORS.push(point);
return false;
} else if (response) {
// It intersects, calculate the overlap.
response['bInA'] = false;
overlapN = point.normalize();
overlap = radius - dist;
}
}
// Otherwise, it's the middle 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) {
// No intersection
T_VECTORS.push(circlePos);
T_VECTORS.push(normal);
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'].copy(overlapN);
}
}
// Calculate the final overlap vector - based on the smallest overlap.
if (response) {
response['a'] = polygon;
response['b'] = circle;
response['overlapV'].copy(response['overlapN']).scale(response['overlap']);
}
T_VECTORS.push(circlePos);
T_VECTORS.push(edge);
T_VECTORS.push(point);
return true;
}
SAT['testPolygonCircle'] = testPolygonCircle;
// Check if a circle and a polygon collide.
//
// **NOTE:** This is slightly less efficient 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.
*/
function testCirclePolygon(circle, polygon, response) {
// Test the polygon against the circle.
var result = 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;
}
SAT['testCirclePolygon'] = testCirclePolygon;
// Checks whether polygons collide.
/**
* @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.
*/
function testPolygonPolygon(a, b, response) {
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 (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 (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'].copy(response['overlapN']).scale(response['overlap']);
}
return true;
}
SAT['testPolygonPolygon'] = testPolygonPolygon;
return SAT;
}));
-754
View File
@@ -1,754 +0,0 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Physics Body is linked to a single Sprite. All physics operations should be performed against the body rather than
* the Sprite itself. For example you can set the velocity, acceleration, bounce values etc all on the Body.
*
* @class Phaser.Physics.Arcade.Body
* @classdesc Arcade Physics Body Constructor
* @constructor
* @param {Phaser.Sprite} sprite - The Sprite object this physics body belongs to.
*/
Phaser.Physics.Arcade.Body = function (sprite) {
/**
* @property {Phaser.Sprite} sprite - Reference to the parent Sprite.
*/
this.sprite = sprite;
/**
* @property {Phaser.Game} game - Local reference to game.
*/
this.game = sprite.game;
/**
* @property {Phaser.Point} offset - The offset of the Physics Body from the Sprite x/y position.
*/
this.offset = new Phaser.Point();
/**
* @property {number} x - The x position of the physics body.
* @readonly
*/
this.x = sprite.x;
/**
* @property {number} y - The y position of the physics body.
* @readonly
*/
this.y = sprite.y;
/**
* @property {number} preX - The previous x position of the physics body.
* @readonly
*/
this.preX = sprite.x;
/**
* @property {number} preY - The previous y position of the physics body.
* @readonly
*/
this.preY = sprite.y;
/**
* @property {number} preRotation - The previous rotation of the physics body.
* @readonly
*/
this.preRotation = sprite.angle;
/**
* @property {number} width - The calculated width of the physics body.
*/
this.width = sprite.currentFrame.sourceSizeW;
/**
* @property {number} height - The calculated height of the physics body.
*/
this.height = sprite.currentFrame.sourceSizeH;
/**
* @property {Phaser.Point} center - The center coordinate of the Physics Body.
*/
this.center = new Phaser.Point(this.x + this.halfWidth, this.y + this.halfHeight);
/**
* @property {Phaser.Point} motionVelocity - The data from the updateMotion function.
*/
this.motionVelocity = new Phaser.Point();
/**
* @property {Phaser.Point} velocity - The velocity in pixels per second sq. of the Body.
*/
this.velocity = new Phaser.Point();
/**
* @property {Phaser.Point} acceleration - The velocity in pixels per second sq. of the Body.
*/
this.acceleration = new Phaser.Point();
/**
* @property {number} speed - The speed in pixels per second sq. of the Body.
*/
this.speed = 0;
/**
* @property {number} angle - The angle of the Body in radians.
*/
this.angle = 0;
/**
* @property {number} minBounceVelocity - The minimum bounce velocity (could just be the bounce value?).
*/
// this.minBounceVelocity = 0.5;
this._debug = 0;
/**
* @property {Phaser.Point} gravity - The gravity applied to the motion of the Body.
*/
this.gravity = new Phaser.Point();
/**
* @property {Phaser.Point} bounce - The elasticitiy of the Body when colliding. bounce.x/y = 1 means full rebound, bounce.x/y = 0.5 means 50% rebound velocity.
*/
this.bounce = new Phaser.Point();
/**
* @property {Phaser.Point} minVelocity - When a body rebounds off another the minVelocity is checked, if the new velocity is lower than the minVelocity the body is stopped.
* @default
*/
this.minVelocity = new Phaser.Point(20, 20);
/**
* @property {Phaser.Point} maxVelocity - The maximum velocity in pixels per second sq. that the Body can reach.
* @default
*/
this.maxVelocity = new Phaser.Point(10000, 10000);
/**
* @property {number} angularVelocity - The angular velocity in pixels per second sq. of the Body.
* @default
*/
this.angularVelocity = 0;
/**
* @property {number} angularAcceleration - The angular acceleration in pixels per second sq. of the Body.
* @default
*/
this.angularAcceleration = 0;
/**
* @property {number} angularDrag - The angular drag applied to the rotation of the Body.
* @default
*/
this.angularDrag = 0;
/**
* @property {number} maxAngular - The maximum angular velocity in pixels per second sq. that the Body can reach.
* @default
*/
this.maxAngular = 1000;
/**
* @property {number} mass - The mass of the Body.
* @default
*/
this.mass = 1;
/**
* Set the allowCollision properties to control which directions collision is processed for this Body.
* For example allowCollision.up = false means it won't collide when the collision happened while moving up.
* @property {object} allowCollision - An object containing allowed collision.
*/
this.allowCollision = { none: false, any: true, up: true, down: true, left: true, right: true };
/**
* This object is populated with boolean values when the Body collides with another.
* touching.up = true means the collision happened to the top of this Body for example.
* @property {object} touching - An object containing touching results.
*/
this.touching = { none: true, up: false, down: false, left: false, right: false };
/**
* @property {boolean} immovable - An immovable Body will not receive any impacts or exchanges of velocity from other bodies.
* @default
*/
this.immovable = false;
/**
* @property {boolean} moves - Set to true to allow the Physics system to move this Body, other false to move it manually.
* @default
*/
this.moves = true;
/**
* @property {number} rotation - The amount the parent Sprite is rotated. Note: You cannot rotate an AABB.
* @default
*/
this.rotation = 0;
/**
* @property {boolean} allowRotation - Allow angular rotation? This will cause the Sprite to be rotated via angularVelocity, etc. Note that the AABB remains un-rotated.
* @default
*/
this.allowRotation = true;
/**
* @property {boolean} allowGravity - Allow this Body to be influenced by the global Gravity value? Note: It will always be influenced by the local gravity value.
* @default
*/
this.allowGravity = true;
/**
* This flag allows you to disable the custom x separation that takes place by Physics.Arcade.separate.
* Used in combination with your own collision processHandler you can create whatever type of collision response you need.
* @property {boolean} customSeparateX - Use a custom separation system or the built-in one?
* @default
*/
this.customSeparateX = false;
/**
* This flag allows you to disable the custom y separation that takes place by Physics.Arcade.separate.
* Used in combination with your own collision processHandler you can create whatever type of collision response you need.
* @property {boolean} customSeparateY - Use a custom separation system or the built-in one?
* @default
*/
this.customSeparateY = false;
/**
* When this body collides with another, the amount of overlap is stored here.
* @property {number} overlapX - The amount of horizontal overlap during the collision.
*/
this.overlapX = 0;
/**
* When this body collides with another, the amount of overlap is stored here.
* @property {number} overlapY - The amount of vertical overlap during the collision.
*/
this.overlapY = 0;
/**
* @property {number} friction - The amount of friction this body experiences during motion.
* @default
*/
this.friction = 0;
/**
* A Body can be set to collide against the World bounds automatically and rebound back into the World if this is set to true. Otherwise it will leave the World.
* @property {boolean} collideWorldBounds - Should the Body collide with the World bounds?
*/
this.collideWorldBounds = false;
/**
* This object is populated with boolean values when the Body collides with the World bounds or a Tile.
* For example if blocked.up is true then the Body cannot move up.
* @property {object} blocked - An object containing on which faces this Body is blocked from moving, if any.
*/
this.blocked = { up: false, down: false, left: false, right: false };
/**
* @property {number} _dx - Internal cache var.
* @private
*/
this._dx = 0;
/**
* @property {number} _dy - Internal cache var.
* @private
*/
this._dy = 0;
/**
* @property {number} _sx - Internal cache var.
* @private
*/
this._sx = sprite.scale.x;
/**
* @property {number} _sy - Internal cache var.
* @private
*/
this._sy = sprite.scale.y;
this.shape = new SAT.Box(new SAT.Vector(this.x, this.y), this.width, this.height);
this.polygon = this.shape.toPolygon();
this.response = new SAT.Response();
};
Phaser.Physics.Arcade.Body.prototype = {
/**
* Internal method.
*
* @method Phaser.Physics.Arcade#updateBounds
* @protected
*/
updateBounds: function (centerX, centerY, scaleX, scaleY) {
// if (scaleX != this._sx || scaleY != this._sy)
// {
// this.width = this.sourceWidth * scaleX;
// this.height = this.sourceHeight * scaleY;
// this.halfWidth = Math.floor(this.width / 2);
// this.halfHeight = Math.floor(this.height / 2);
// this._sx = scaleX;
// this._sy = scaleY;
// this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
// }
},
/**
* Internal method.
*
* @method Phaser.Physics.Arcade#preUpdate
* @protected
*/
preUpdate: function () {
// this.screenX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
// this.screenY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
this.preX = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.preY = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
// this.preRotation = this.sprite.angle;
this.preRotation = this.sprite.rotation;
// This all needs to move - because a body may start the preUpdate already touching something
this.blocked.up = false;
this.blocked.down = false;
this.blocked.left = false;
this.blocked.right = false;
this.x = this.preX;
this.y = this.preY;
// this.rotation = this.preRotation;
this.speed = Math.sqrt(this.velocity.x * this.velocity.x + this.velocity.y * this.velocity.y);
this.angle = Math.atan2(this.velocity.y, this.velocity.x);
this._debug++;
if (this.moves)
{
if (this.collideWorldBounds)
{
this.checkWorldBounds();
}
this.game.physics.updateMotion(this);
this.applyMotion();
}
this.polygon.pos.x = this.x;
this.polygon.pos.y = this.y;
if (this.deltaZ() !== 0)
{
// this.polygon.rotate(this.sprite.rotation);
// console.log(this.sprite.rotation);
}
// this.polygon.rotate(this.game.math.degToRad(this.rotation));
},
/**
* Internal method used to check the Body against the World Bounds.
*
* @method Phaser.Physics.Arcade#checkWorldBounds
* @protected
*/
checkWorldBounds: function () {
if (this.x <= this.game.world.bounds.x)
{
this.overlapX = this.game.world.bounds.x - this.x;
this.blocked.left = true;
// console.log(this._debug, 'cwl', this.overlapX, this.x, this.game.world.bounds.x);
}
else if (this.right >= this.game.world.bounds.right)
{
this.overlapX = this.right - this.game.world.bounds.right;
this.blocked.right = true;
// console.log(this._debug, 'cwr', this.overlapX, this.x, this.game.world.bounds.x);
}
if (this.y <= this.game.world.bounds.y)
{
this.overlapY = this.game.world.bounds.y - this.y;
this.blocked.up = true;
// console.log(this._debug, 'cwu', this.overlapY, this.y, this.height, this.bottom, this.game.world.bounds.bottom);
}
else if (this.bottom >= this.game.world.bounds.bottom)
{
this.overlapY = this.bottom - this.game.world.bounds.bottom;
this.blocked.down = true;
// console.log(this._debug, 'cwd', this.overlapY, this.y, this.height, this.bottom, this.game.world.bounds.bottom);
}
this.blockedPoint.setTo(this.x, this.y);
},
/**
* Internal method.
*
* @method Phaser.Physics.Arcade#applyMotion
* @protected
*/
applyMotion: function () {
if (this.friction > 0 && this.acceleration.isZero())
{
if (this.speed > this.friction)
{
this.speed -= this.friction;
}
else
{
this.speed = 0;
}
this.velocity.x = Math.cos(this.angle) * this.speed;
this.velocity.y = Math.sin(this.angle) * this.speed;
}
// overlapX/Y values at this point will be penetration into the bounds and DELTA WILL BE ZERO
if (this.blocked.left)
{
// Separate
this.x += this.overlapX;
// console.log(this._debug, 'blocked left', this.x, this.overlapX);
this.velocity.x *= -this.bounce.x;
this._dx = this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
// if (this._dx > this.minBounceVelocity)
if (Math.abs(this.velocity.x) > this.minVelocity.x)
{
this.x += this._dx;
this.velocity.x += this.motionVelocity.x;
// console.log(this._debug, 'blocked left', this._dx, 'overlap', this.overlapX, 'delta', this.deltaX(), 'newy', this.x);
}
else
{
// Kill it dead :)
this.preX = this.x; // because we don't want any delta from a separation
this.velocity.x = 0;
this.motionVelocity.x = 0;
// console.log(this._debug, 'blocked left KILL', this._dx, 'overlap', this.overlapX, 'delta', this.deltaX(), 'newy', this.x);
}
}
else if (this.blocked.right)
{
// Separate
this.x -= this.overlapX;
this.velocity.x *= -this.bounce.x;
this._dx = this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
if (this._dx < -this.minBounceVelocity)
{
this.x += this._dx;
this.velocity.x += this.motionVelocity.x;
// console.log(this._debug, 'blocked right', this._dx, 'overlap', this.overlapX, 'delta', this.deltaX(), 'newy', this.x);
}
else
{
// Kill it dead :)
this.preX = this.x; // because we don't want any delta from a separation
this.velocity.x = 0;
this.motionVelocity.x = 0;
// console.log(this._debug, 'blocked right KILL', this._dx, 'overlap', this.overlapX, 'delta', this.deltaX(), 'newy', this.x);
}
}
else
{
this.x += this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
this.velocity.x += this.motionVelocity.x;
}
// overlapX/Y values at this point will be penetration into the bounds and DELTA WILL BE ZERO
if (this.blocked.up)
{
// Separate
this.y += this.overlapY;
this.velocity.y *= -this.bounce.y;
this._dy = this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
// if (this._dy > this.minBounceVelocity)
if (Math.abs(this.velocity.y) > this.minVelocity.y)
{
this.y += this._dy;
this.velocity.y += this.motionVelocity.y;
}
else
{
// Kill it dead :)
this.preY = this.y; // because we don't want any delta from a separation
this.velocity.y = 0;
this.motionVelocity.y = 0;
// console.log(this._debug, 'void1', this.velocity.y, 'delta', this.deltaY());
}
}
else if (this.blocked.down)
{
// Separate
this.y -= this.overlapY;
this.velocity.y *= -this.bounce.y;
this._dy = this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
// if (this._dy < -this.minBounceVelocity)
if (Math.abs(this.velocity.y) > this.minVelocity.y)
{
this.y += this._dy;
this.velocity.y += this.motionVelocity.y;
// console.log(this._debug, 'rb', this._dy, 'delta', this.deltaY(), 'newy', this.y);
}
else
{
// Kill it dead :)
this.preY = this.y; // because we don't want any delta from a separation
this.velocity.y = 0;
this.motionVelocity.y = 0;
// console.log(this._debug, 'void1', this.velocity.y, 'delta', this.deltaY());
}
}
else
{
this.y += this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
this.velocity.y += this.motionVelocity.y;
}
if (this.velocity.x > this.maxVelocity.x)
{
this.velocity.x = this.maxVelocity.x;
}
else if (this.velocity.x < -this.maxVelocity.x)
{
this.velocity.x = -this.maxVelocity.x;
}
if (this.velocity.y > this.maxVelocity.y)
{
this.velocity.y = this.maxVelocity.y;
}
else if (this.velocity.y < -this.maxVelocity.y)
{
this.velocity.y = -this.maxVelocity.y;
}
},
collide: function (body) {
this.response.clear();
// if (this._debug === 100)
// {
// console.log(this.sprite.name, this.polygon);
// }
if (SAT.testPolygonPolygon(this.polygon, body.polygon, this.response))
{
// b1.pos.sub(r.overlapV);
// sprite.body.velocity.x *= -sprite.body.bounce.x;
this.velocity.x = 0;
// separate
this.x += Math.ceil(Math.abs(this.response.overlapV.x));
this.y += Math.ceil(Math.abs(this.response.overlapV.y));
console.log(this.response, this.deltaX());
console.log('sprite moved to', this.x, this.deltaX());
}
},
/**
* Internal method. This is called directly before the sprites are sent to the renderer.
*
* @method Phaser.Physics.Arcade#postUpdate
* @protected
*/
postUpdate: function () {
if (this.moves)
{
this.sprite.x += this.deltaX();
this.sprite.y += this.deltaY();
this.sprite.worldTransform[2] += this.deltaX();
this.sprite.worldTransform[5] += this.deltaY();
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
this.rotation = this.preRotation;
if (this.allowRotation)
{
// this.sprite.angle += this.deltaZ();
}
}
},
/**
* Resets all Body values (velocity, acceleration, rotation, etc)
*
* @method Phaser.Physics.Arcade#reset
*/
reset: function () {
this.velocity.setTo(0, 0);
this.acceleration.setTo(0, 0);
this.angularVelocity = 0;
this.angularAcceleration = 0;
this.preX = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.preY = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
this.preRotation = this.sprite.angle;
this.x = this.preX;
this.y = this.preY;
this.rotation = this.preRotation;
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
},
/**
* Returns the absolute delta x value.
*
* @method Phaser.Physics.Arcade.Body#deltaAbsX
* @return {number} The absolute delta value.
*/
deltaAbsX: function () {
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
},
/**
* Returns the absolute delta y value.
*
* @method Phaser.Physics.Arcade.Body#deltaAbsY
* @return {number} The absolute delta value.
*/
deltaAbsY: function () {
return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY());
},
/**
* Returns the delta x value. The difference between Body.x now and in the previous step.
*
* @method Phaser.Physics.Arcade.Body#deltaX
* @return {number} The delta value. Positive if the motion was to the right, negative if to the left.
*/
deltaX: function () {
return this.x - this.preX;
},
/**
* Returns the delta y value. The difference between Body.y now and in the previous step.
*
* @method Phaser.Physics.Arcade.Body#deltaY
* @return {number} The delta value. Positive if the motion was downwards, negative if upwards.
*/
deltaY: function () {
return this.y - this.preY;
},
deltaZ: function () {
return this.rotation - this.preRotation;
}
};
Phaser.Physics.Arcade.Body.prototype.constructor = Phaser.Physics.Arcade.Body;
/**
* @name Phaser.Physics.Arcade.Body#bottom
* @property {number} bottom - The bottom value of this Body (same as Body.y + Body.height)
*/
Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "bottom", {
/**
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
* @method bottom
* @return {number}
*/
get: function () {
return this.y + this.height;
},
/**
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
* @method bottom
* @param {number} value
*/
set: function (value) {
if (value <= this.y)
{
this.height = 0;
}
else
{
this.height = (this.y - value);
}
}
});
/**
* @name Phaser.Physics.Arcade.Body#right
* @property {number} right - The right value of this Body (same as Body.x + Body.width)
*/
Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", {
/**
* The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
* However it does affect the width property.
* @method right
* @return {number}
*/
get: function () {
return this.x + this.width;
},
/**
* The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
* However it does affect the width property.
* @method right
* @param {number} value
*/
set: function (value) {
if (value <= this.x)
{
this.width = 0;
}
else
{
this.width = this.x + value;
}
}
});