var GameMath=(function(){function GameMath(game){this.globalSeed=Math.random();this._game=game}GameMath.PI=3.141592653589793;GameMath.PI_2=1.5707963267948966;GameMath.PI_4=0.7853981633974483;GameMath.PI_8=0.39269908169872414;GameMath.PI_16=0.19634954084936207;GameMath.TWO_PI=6.283185307179586;GameMath.THREE_PI_2=4.71238898038469;GameMath.E=2.71828182845905;GameMath.LN10=2.302585092994046;GameMath.LN2=0.6931471805599453;GameMath.LOG10E=0.4342944819032518;GameMath.LOG2E=1.4426950408889634;GameMath.SQRT1_2=0.7071067811865476;GameMath.SQRT2=1.4142135623730951;GameMath.DEG_TO_RAD=0.017453292519943295;GameMath.RAD_TO_DEG=57.29577951308232;GameMath.B_16=65536;GameMath.B_31=2147483648;GameMath.B_32=4294967296;GameMath.B_48=281474976710656;GameMath.B_53=9007199254740992;GameMath.B_64=18446744073709552000;GameMath.ONE_THIRD=0.3333333333333333;GameMath.TWO_THIRDS=0.6666666666666666;GameMath.ONE_SIXTH=0.16666666666666666;GameMath.COS_PI_3=0.8660254037844386;GameMath.SIN_2PI_3=0.03654595;GameMath.CIRCLE_ALPHA=0.5522847498307935;GameMath.ON=true;GameMath.OFF=false;GameMath.SHORT_EPSILON=0.1;GameMath.PERC_EPSILON=0.001;GameMath.EPSILON=0.0001;GameMath.LONG_EPSILON=1e-8;GameMath.prototype.computeMachineEpsilon=function(){var fourThirds=4/3;var third=fourThirds-1;var one=third+third+third;return Math.abs(1-one)};GameMath.prototype.fuzzyEqual=function(a,b,epsilon){if(typeof epsilon==="undefined"){epsilon=0.0001}return Math.abs(a-b)b-epsilon};GameMath.prototype.fuzzyCeil=function(val,epsilon){if(typeof epsilon==="undefined"){epsilon=0.0001}return Math.ceil(val-epsilon)};GameMath.prototype.fuzzyFloor=function(val,epsilon){if(typeof epsilon==="undefined"){epsilon=0.0001}return Math.floor(val+epsilon)};GameMath.prototype.average=function(){var args=[];for(var _i=0;_i<(arguments.length-0);_i++){args[_i]=arguments[_i+0]}var avg=0;for(var i=0;i0)?Math.floor(n):Math.ceil(n)};GameMath.prototype.shear=function(n){return n%1};GameMath.prototype.wrap=function(val,max,min){if(typeof min==="undefined"){min=0}val-=min;max-=min;if(max==0){return min}val%=max;val+=min;while(valrd/2){a1+=rd*2}if(a2<-rd/2&&a1>rd/2){a2+=rd*2}return a2-a1};GameMath.prototype.normalizeAngleToAnother=function(dep,ind,radians){if(typeof radians==="undefined"){radians=true}return ind+this.nearestAngleBetween(ind,dep,radians)};GameMath.prototype.normalizeAngleAfterAnother=function(dep,ind,radians){if(typeof radians==="undefined"){radians=true}dep=this.normalizeAngle(dep-ind,radians);return ind+dep};GameMath.prototype.normalizeAngleBeforeAnother=function(dep,ind,radians){if(typeof radians==="undefined"){radians=true}dep=this.normalizeAngle(ind-dep,radians);return ind-dep};GameMath.prototype.interpolateAngles=function(a1,a2,weight,radians,ease){if(typeof radians==="undefined"){radians=true}if(typeof ease==="undefined"){ease=null}a1=this.normalizeAngle(a1,radians);a2=this.normalizeAngleToAnother(a2,a1,radians);return(typeof ease==="function")?ease(weight,a1,a2-a1,1):this.interpolateFloat(a1,a2,weight)};GameMath.prototype.logBaseOf=function(value,base){return Math.log(value)/Math.log(base)};GameMath.prototype.GCD=function(m,n){var r;m=Math.abs(m);n=Math.abs(n);if(m=100){return true}else{if(Math.random()*100>=chance){return false}else{return true}}}};GameMath.prototype.maxAdd=function(value,amount,max){value+=amount;if(value>max){value=max}return value};GameMath.prototype.minSub=function(value,amount,min){value-=amount;if(value0.5)?1:-1};GameMath.prototype.isOdd=function(n){if(n&1){return true}else{return false}};GameMath.prototype.isEven=function(n){if(n&1){return false}else{return true}};GameMath.prototype.wrapAngle=function(angle){var result=angle;if(angle>=-180&&angle<=180){return angle}result=(angle+180)%360;if(result<0){result+=360}return result-180};GameMath.prototype.angleLimit=function(angle,min,max){var result=angle;if(angle>max){result=max}else{if(angle1){return this.linear(v[m],v[m-1],m-f)}return this.linear(v[i],v[i+1>m?m:i+1],f-i)};GameMath.prototype.bezierInterpolation=function(v,k){var b=0;var n=v.length-1;for(var i=0;i<=n;i++){b+=Math.pow(1-k,n-i)*Math.pow(k,i)*v[i]*this.bernstein(n,i)}return b};GameMath.prototype.catmullRomInterpolation=function(v,k){var m=v.length-1;var f=m*k;var i=Math.floor(f);if(v[0]===v[m]){if(k<0){i=Math.floor(f=m*(1+k))}return this.catmullRom(v[(i-1+m)%m],v[i],v[(i+1)%m],v[(i+2)%m],f-i)}else{if(k<0){return v[0]-(this.catmullRom(v[0],v[0],v[1],v[1],-f)-v[0])}if(k>1){return v[m]-(this.catmullRom(v[m],v[m],v[m-1],v[m-1],f-m)-v[m])}return this.catmullRom(v[i?i-1:0],v[i],v[m0){Velocity=Velocity-drag}else{if(Velocity+drag<0){Velocity+=drag}else{Velocity=0}}}}if((Velocity!=0)&&(Max!=10000)){if(Velocity>Max){Velocity=Max}else{if(Velocity<-Max){Velocity=-Max}}}return Velocity};GameMath.prototype.velocityFromAngle=function(angle,speed){var a=this.degreesToRadians(angle);return new Point((Math.cos(a)*speed),(Math.sin(a)*speed))};GameMath.prototype.random=function(){return this.globalSeed=this.srand(this.globalSeed)};GameMath.prototype.srand=function(Seed){return((69621*(Seed*2147483647))%2147483647)/2147483647};GameMath.prototype.getRandom=function(Objects,StartIndex,Length){if(typeof StartIndex==="undefined"){StartIndex=0}if(typeof Length==="undefined"){Length=0}if(Objects!=null){var l=Length;if((l==0)||(l>Objects.length-StartIndex)){l=Objects.length-StartIndex}if(l>0){return Objects[StartIndex+Math.floor(Math.random()*l)]}}return null};GameMath.prototype.floor=function(Value){var n=Value|0;return(Value>0)?(n):((n!=Value)?(n-1):(n))};GameMath.prototype.ceil=function(Value){var n=Value|0;return(Value>0)?((n!=Value)?(n+1):(n)):(n)};return GameMath})();var Point=(function(){function Point(x,y){if(typeof x==="undefined"){x=0}if(typeof y==="undefined"){y=0}this.setTo(x,y)}Point.prototype.add=function(toAdd,output){if(typeof output==="undefined"){output=new Point()}return output.setTo(this.x+toAdd.x,this.y+toAdd.y)};Point.prototype.addTo=function(x,y){if(typeof x==="undefined"){x=0}if(typeof y==="undefined"){y=0}return this.setTo(this.x+x,this.y+y)};Point.prototype.subtractFrom=function(x,y){if(typeof x==="undefined"){x=0}if(typeof y==="undefined"){y=0}return this.setTo(this.x-x,this.y-y)};Point.prototype.invert=function(){return this.setTo(this.y,this.x)};Point.prototype.clamp=function(min,max){this.clampX(min,max);this.clampY(min,max);return this};Point.prototype.clampX=function(min,max){this.x=Math.max(Math.min(this.x,max),min);return this};Point.prototype.clampY=function(min,max){this.x=Math.max(Math.min(this.x,max),min);this.y=Math.max(Math.min(this.y,max),min);return this};Point.prototype.clone=function(output){if(typeof output==="undefined"){output=new Point()}return output.setTo(this.x,this.y)};Point.prototype.copyFrom=function(source){return this.setTo(source.x,source.y)};Point.prototype.copyTo=function(target){return target.setTo(this.x,this.y)};Point.prototype.distanceTo=function(target,round){if(typeof round==="undefined"){round=false}var dx=this.x-target.x;var dy=this.y-target.y;if(round===true){return Math.round(Math.sqrt(dx*dx+dy*dy))}else{return Math.sqrt(dx*dx+dy*dy)}};Point.distanceBetween=function distanceBetween(pointA,pointB,round){if(typeof round==="undefined"){round=false}var dx=pointA.x-pointB.x;var dy=pointA.y-pointB.y;if(round===true){return Math.round(Math.sqrt(dx*dx+dy*dy))}else{return Math.sqrt(dx*dx+dy*dy)}};Point.prototype.distanceCompare=function(target,distance){if(this.distanceTo(target)>=distance){return true}else{return false}};Point.prototype.equals=function(toCompare){if(this.x===toCompare.x&&this.y===toCompare.y){return true}else{return false}};Point.prototype.interpolate=function(pointA,pointB,f){};Point.prototype.offset=function(dx,dy){this.x+=dx;this.y+=dy;return this};Point.prototype.polar=function(length,angle){};Point.prototype.setTo=function(x,y){this.x=x;this.y=y;return this};Point.prototype.subtract=function(point,output){if(typeof output==="undefined"){output=new Point()}return output.setTo(this.x-point.x,this.y-point.y)};Point.prototype.toString=function(){return"[{Point (x="+this.x+" y="+this.y+")}]"};return Point})();var Rectangle=(function(){function Rectangle(x,y,width,height){if(typeof x==="undefined"){x=0}if(typeof y==="undefined"){y=0}if(typeof width==="undefined"){width=0}if(typeof height==="undefined"){height=0}this.x=0;this.y=0;this.width=0;this.height=0;this.setTo(x,y,width,height)}Object.defineProperty(Rectangle.prototype,"halfWidth",{get:function(){return Math.round(this.width/2)},enumerable:true,configurable:true});Object.defineProperty(Rectangle.prototype,"halfHeight",{get:function(){return Math.round(this.height/2)},enumerable:true,configurable:true});Object.defineProperty(Rectangle.prototype,"bottom",{get:function(){return this.y+this.height},set:function(value){if(value=this.x&&x<=this.right&&y>=this.y&&y<=this.bottom){return true}return false};Rectangle.prototype.containsPoint=function(point){return this.contains(point.x,point.y)};Rectangle.prototype.containsRect=function(rect){if(rect.volume>this.volume){return false}if(rect.x>=this.x&&rect.y>=this.y&&rect.right<=this.right&&rect.bottom<=this.bottom){return true}return false};Rectangle.prototype.copyFrom=function(source){return this.setTo(source.x,source.y,source.width,source.height)};Rectangle.prototype.copyTo=function(target){return target.copyFrom(this)};Rectangle.prototype.equals=function(toCompare){if(this.x===toCompare.x&&this.y===toCompare.y&&this.width===toCompare.width&&this.height===toCompare.height){return true}return false};Rectangle.prototype.inflate=function(dx,dy){if(!isNaN(dx)&&!isNaN(dy)){this.x-=dx;this.width+=2*dx;this.y-=dy;this.height+=2*dy}return this};Rectangle.prototype.inflatePoint=function(point){return this.inflate(point.x,point.y)};Rectangle.prototype.intersection=function(toIntersect,output){if(typeof output==="undefined"){output=new Rectangle()}if(this.intersects(toIntersect)===true){output.x=Math.max(toIntersect.x,this.x);output.y=Math.max(toIntersect.y,this.y);output.width=Math.min(toIntersect.right,this.right)-output.x;output.height=Math.min(toIntersect.bottom,this.bottom)-output.y}return output};Rectangle.prototype.intersects=function(toIntersect){if(toIntersect.x>=this.right){return false}if(toIntersect.right<=this.x){return false}if(toIntersect.bottom<=this.y){return false}if(toIntersect.y>=this.bottom){return false}return true};Rectangle.prototype.overlap=function(rect){return(rect.x+rect.width>this.x)&&(rect.xthis.y)&&(rect.y0){this.width=width}if(height>0){this.height=height}}return this};Rectangle.prototype.union=function(toUnion,output){if(typeof output==="undefined"){output=new Rectangle()}return output.setTo(Math.min(toUnion.x,this.x),Math.min(toUnion.y,this.y),Math.max(toUnion.right,this.right),Math.max(toUnion.bottom,this.bottom))};Rectangle.prototype.toString=function(){return"[{Rectangle (x="+this.x+" y="+this.y+" width="+this.width+" height="+this.height+" empty="+this.isEmpty+")}]"};return Rectangle})();var Camera=(function(){function Camera(game,id,x,y,width,height){this._clip=false;this._rotation=0;this._target=null;this._sx=0;this._sy=0;this._fxFlashComplete=null;this._fxFlashDuration=0;this._fxFlashAlpha=0;this._fxFadeComplete=null;this._fxFadeDuration=0;this._fxFadeAlpha=0;this._fxShakeIntensity=0;this._fxShakeDuration=0;this._fxShakeComplete=null;this._fxShakeOffset=new Point(0,0);this._fxShakeDirection=0;this._fxShakePrevX=0;this._fxShakePrevY=0;this.scale=new Point(1,1);this.scroll=new Point(0,0);this.bounds=null;this.deadzone=null;this.showBorder=false;this.borderColor="rgb(255,255,255)";this.opaque=true;this._bgColor="rgb(0,0,0)";this._bgTextureRepeat="repeat";this.showShadow=false;this.shadowColor="rgb(0,0,0)";this.shadowBlur=10;this.shadowOffset=new Point(4,4);this.visible=true;this.alpha=1;this.inputX=0;this.inputY=0;this._game=game;this.ID=id;this._stageX=x;this._stageY=y;this.worldView=new Rectangle(0,0,width,height);this.checkClip()}Camera.STYLE_LOCKON=0;Camera.STYLE_PLATFORMER=1;Camera.STYLE_TOPDOWN=2;Camera.STYLE_TOPDOWN_TIGHT=3;Camera.SHAKE_BOTH_AXES=0;Camera.SHAKE_HORIZONTAL_ONLY=1;Camera.SHAKE_VERTICAL_ONLY=2;Camera.prototype.flash=function(color,duration,onComplete,force){if(typeof color==="undefined"){color=16777215}if(typeof duration==="undefined"){duration=1}if(typeof onComplete==="undefined"){onComplete=null}if(typeof force==="undefined"){force=false}if(force===false&&this._fxFlashAlpha>0){return}if(duration<=0){duration=1}var red=color>>16&255;var green=color>>8&255;var blue=color&255;this._fxFlashColor="rgba("+red+","+green+","+blue+",";this._fxFlashDuration=duration;this._fxFlashAlpha=1;this._fxFlashComplete=onComplete};Camera.prototype.fade=function(color,duration,onComplete,force){if(typeof color==="undefined"){color=0}if(typeof duration==="undefined"){duration=1}if(typeof onComplete==="undefined"){onComplete=null}if(typeof force==="undefined"){force=false}if(force===false&&this._fxFadeAlpha>0){return}if(duration<=0){duration=1}var red=color>>16&255;var green=color>>8&255;var blue=color&255;this._fxFadeColor="rgba("+red+","+green+","+blue+",";this._fxFadeDuration=duration;this._fxFadeAlpha=0.01;this._fxFadeComplete=onComplete};Camera.prototype.shake=function(intensity,duration,onComplete,force,direction){if(typeof intensity==="undefined"){intensity=0.05}if(typeof duration==="undefined"){duration=0.5}if(typeof onComplete==="undefined"){onComplete=null}if(typeof force==="undefined"){force=true}if(typeof direction==="undefined"){direction=Camera.SHAKE_BOTH_AXES}if(!force&&((this._fxShakeOffset.x!=0)||(this._fxShakeOffset.y!=0))){return}if(this._fxShakeOffset.x==0&&this._fxShakeOffset.y==0){this._fxShakePrevX=this._stageX;this._fxShakePrevY=this._stageY}this._fxShakeIntensity=intensity;this._fxShakeDuration=duration;this._fxShakeComplete=onComplete;this._fxShakeDirection=direction;this._fxShakeOffset.setTo(0,0)};Camera.prototype.stopFX=function(){this._fxFlashAlpha=0;this._fxFadeAlpha=0;if(this._fxShakeDuration!==0){this._fxShakeDuration=0;this._fxShakeOffset.setTo(0,0);this._stageX=this._fxShakePrevX;this._stageY=this._fxShakePrevY}};Camera.prototype.follow=function(target,style){if(typeof style==="undefined"){style=Camera.STYLE_LOCKON}this._target=target;var helper;switch(style){case Camera.STYLE_PLATFORMER:var w=this.width/8;var h=this.height/3;this.deadzone=new Rectangle((this.width-w)/2,(this.height-h)/2-h*0.25,w,h);break;case Camera.STYLE_TOPDOWN:helper=Math.max(this.width,this.height)/4;this.deadzone=new Rectangle((this.width-helper)/2,(this.height-helper)/2,helper,helper);break;case Camera.STYLE_TOPDOWN_TIGHT:helper=Math.max(this.width,this.height)/8;this.deadzone=new Rectangle((this.width-helper)/2,(this.height-helper)/2,helper,helper);break;case Camera.STYLE_LOCKON:default:this.deadzone=null;break}};Camera.prototype.focusOnXY=function(x,y){x+=(x>0)?1e-7:-1e-7;y+=(y>0)?1e-7:-1e-7;this.scroll.x=Math.round(x-this.worldView.halfWidth);this.scroll.y=Math.round(y-this.worldView.halfHeight)};Camera.prototype.focusOn=function(point){point.x+=(point.x>0)?1e-7:-1e-7;point.y+=(point.y>0)?1e-7:-1e-7;this.scroll.x=Math.round(point.x-this.worldView.halfWidth);this.scroll.y=Math.round(point.y-this.worldView.halfHeight)};Camera.prototype.setBounds=function(X,Y,Width,Height,UpdateWorld){if(typeof X==="undefined"){X=0}if(typeof Y==="undefined"){Y=0}if(typeof Width==="undefined"){Width=0}if(typeof Height==="undefined"){Height=0}if(typeof UpdateWorld==="undefined"){UpdateWorld=false}if(this.bounds==null){this.bounds=new Rectangle()}this.bounds.setTo(X,Y,Width,Height);this.update()};Camera.prototype.update=function(){if(this._target!==null){if(this.deadzone==null){this.focusOnXY(this._target.x+this._target.origin.x,this._target.y+this._target.origin.y)}else{var edge;var targetX=this._target.x+((this._target.x>0)?1e-7:-1e-7);var targetY=this._target.y+((this._target.y>0)?1e-7:-1e-7);edge=targetX-this.deadzone.x;if(this.scroll.x>edge){this.scroll.x=edge}edge=targetX+this._target.width-this.deadzone.x-this.deadzone.width;if(this.scroll.xedge){this.scroll.y=edge}edge=targetY+this._target.height-this.deadzone.y-this.deadzone.height;if(this.scroll.ythis.bounds.right-this.width){this.scroll.x=this.bounds.right-this.width}if(this.scroll.ythis.bounds.bottom-this.height){this.scroll.y=this.bounds.bottom-this.height}}this.worldView.x=this.scroll.x;this.worldView.y=this.scroll.y;this.inputX=this.worldView.x+this._game.input.x;this.inputY=this.worldView.y+this._game.input.y;if(this._fxFlashAlpha>0){this._fxFlashAlpha-=this._game.time.elapsed/this._fxFlashDuration;this._fxFlashAlpha=this._game.math.roundTo(this._fxFlashAlpha,-2);if(this._fxFlashAlpha<=0){this._fxFlashAlpha=0;if(this._fxFlashComplete!==null){this._fxFlashComplete()}}}if(this._fxFadeAlpha>0){this._fxFadeAlpha+=this._game.time.elapsed/this._fxFadeDuration;this._fxFadeAlpha=this._game.math.roundTo(this._fxFadeAlpha,-2);if(this._fxFadeAlpha>=1){this._fxFadeAlpha=1;if(this._fxFadeComplete!==null){this._fxFadeComplete()}}}if(this._fxShakeDuration>0){this._fxShakeDuration-=this._game.time.elapsed;this._fxShakeDuration=this._game.math.roundTo(this._fxShakeDuration,-2);if(this._fxShakeDuration<=0){this._fxShakeDuration=0;this._fxShakeOffset.setTo(0,0);this._stageX=this._fxShakePrevX;this._stageY=this._fxShakePrevY;if(this._fxShakeComplete!=null){this._fxShakeComplete()}}else{if((this._fxShakeDirection==Camera.SHAKE_BOTH_AXES)||(this._fxShakeDirection==Camera.SHAKE_HORIZONTAL_ONLY)){this._fxShakeOffset.x=(this._game.math.random()*this._fxShakeIntensity*this.worldView.width*2-this._fxShakeIntensity*this.worldView.width)}if((this._fxShakeDirection==Camera.SHAKE_BOTH_AXES)||(this._fxShakeDirection==Camera.SHAKE_VERTICAL_ONLY)){this._fxShakeOffset.y=(this._game.math.random()*this._fxShakeIntensity*this.worldView.height*2-this._fxShakeIntensity*this.worldView.height)}}}};Camera.prototype.render=function(){if(this.visible===false&&this.alpha<0.1){return}if((this._fxShakeOffset.x!=0)||(this._fxShakeOffset.y!=0)){this._stageX=this._fxShakePrevX+(this.worldView.halfWidth)+this._fxShakeOffset.x;this._stageY=this._fxShakePrevY+(this.worldView.halfHeight)+this._fxShakeOffset.y}this._game.stage.context.save();if(this.alpha!==1){this._game.stage.context.globalAlpha=this.alpha}this._sx=this._stageX;this._sy=this._stageY;if(this.showShadow){this._game.stage.context.shadowColor=this.shadowColor;this._game.stage.context.shadowBlur=this.shadowBlur;this._game.stage.context.shadowOffsetX=this.shadowOffset.x;this._game.stage.context.shadowOffsetY=this.shadowOffset.y}if(this.scale.x!==1||this.scale.y!==1){this._game.stage.context.scale(this.scale.x,this.scale.y);this._sx=this._sx/this.scale.x;this._sy=this._sy/this.scale.y}if(this._rotation!==0){this._game.stage.context.translate(this._sx+this.worldView.halfWidth,this._sy+this.worldView.halfHeight);this._game.stage.context.rotate(this._rotation*(Math.PI/180));this._game.stage.context.translate(-(this._sx+this.worldView.halfWidth),-(this._sy+this.worldView.halfHeight))}if(this.opaque==true){if(this._bgTexture){this._game.stage.context.fillStyle=this._bgTexture;this._game.stage.context.fillRect(this._sx,this._sy,this.worldView.width,this.worldView.height)}else{this._game.stage.context.fillStyle=this._bgColor;this._game.stage.context.fillRect(this._sx,this._sy,this.worldView.width,this.worldView.height)}}if(this.showShadow){this._game.stage.context.shadowBlur=0;this._game.stage.context.shadowOffsetX=0;this._game.stage.context.shadowOffsetY=0}if(this._clip){this._game.stage.context.beginPath();this._game.stage.context.rect(this._sx,this._sy,this.worldView.width,this.worldView.height);this._game.stage.context.closePath();this._game.stage.context.clip()}this._game.world.group.render(this,this._sx,this._sy);if(this.showBorder){this._game.stage.context.strokeStyle=this.borderColor;this._game.stage.context.lineWidth=1;this._game.stage.context.rect(this._sx,this._sy,this.worldView.width,this.worldView.height);this._game.stage.context.stroke()}if(this._fxFlashAlpha>0){this._game.stage.context.fillStyle=this._fxFlashColor+this._fxFlashAlpha+")";this._game.stage.context.fillRect(this._sx,this._sy,this.worldView.width,this.worldView.height)}if(this._fxFadeAlpha>0){this._game.stage.context.fillStyle=this._fxFadeColor+this._fxFadeAlpha+")";this._game.stage.context.fillRect(this._sx,this._sy,this.worldView.width,this.worldView.height)}if(this.scale.x!==1||this.scale.y!==1){this._game.stage.context.scale(1,1)}if(this._rotation!==0||this._clip){this._game.stage.context.translate(0,0)}this._game.stage.context.restore();if(this.alpha!==1){this._game.stage.context.globalAlpha=1}};Object.defineProperty(Camera.prototype,"backgroundColor",{get:function(){return this._bgColor},set:function(color){this._bgColor=color},enumerable:true,configurable:true});Camera.prototype.setTexture=function(key,repeat){if(typeof repeat==="undefined"){repeat="repeat"}this._bgTexture=this._game.stage.context.createPattern(this._game.cache.getImage(key),repeat);this._bgTextureRepeat=repeat};Camera.prototype.setPosition=function(x,y){this._stageX=x;this._stageY=y;this.checkClip()};Camera.prototype.setSize=function(width,height){this.worldView.width=width;this.worldView.height=height;this.checkClip()};Camera.prototype.renderDebugInfo=function(x,y,color){if(typeof color==="undefined"){color="rgb(255,255,255)"}this._game.stage.context.fillStyle=color;this._game.stage.context.fillText("Camera ID: "+this.ID+" ("+this.worldView.width+" x "+this.worldView.height+")",x,y);this._game.stage.context.fillText("X: "+this._stageX+" Y: "+this._stageY+" Rotation: "+this._rotation,x,y+14);this._game.stage.context.fillText("World X: "+this.scroll.x.toFixed(1)+" World Y: "+this.scroll.y.toFixed(1),x,y+28);if(this.bounds){this._game.stage.context.fillText("Bounds: "+this.bounds.width+" x "+this.bounds.height,x,y+56)}};Object.defineProperty(Camera.prototype,"x",{get:function(){return this._stageX},set:function(value){this._stageX=value;this.checkClip()},enumerable:true,configurable:true});Object.defineProperty(Camera.prototype,"y",{get:function(){return this._stageY},set:function(value){this._stageY=value;this.checkClip()},enumerable:true,configurable:true});Object.defineProperty(Camera.prototype,"width",{get:function(){return this.worldView.width},set:function(value){this.worldView.width=value;this.checkClip()},enumerable:true,configurable:true});Object.defineProperty(Camera.prototype,"height",{get:function(){return this.worldView.height},set:function(value){this.worldView.height=value;this.checkClip()},enumerable:true,configurable:true});Object.defineProperty(Camera.prototype,"rotation",{get:function(){return this._rotation},set:function(value){this._rotation=this._game.math.wrap(value,360,0)},enumerable:true,configurable:true});Camera.prototype.checkClip=function(){if(this._stageX!==0||this._stageY!==0||this.worldView.widththis.x)&&(ObjectOrGroup.xthis.y)&&(ObjectOrGroup.ythis._point.x)&&(objectScreenPos.xthis._point.y)&&(objectScreenPos.yX)&&(ObjectOrGroup.xY)&&(ObjectOrGroup.y0)?1e-7:-1e-7;this._point.y+=(this._point.y>0)?1e-7:-1e-7;return(objectScreenPos.x+ObjectOrGroup.width>this._point.x)&&(objectScreenPos.xthis._point.y)&&(objectScreenPos.ythis.x)&&(point.xthis.y)&&(point.ythis._point.x)&&(Xthis._point.y)&&(Y0)&&(this._point.x0)&&(this._point.y0)?1e-7:-1e-7;point.y+=(point.y>0)?1e-7:-1e-7;return point};Object.defineProperty(GameObject.prototype,"solid",{get:function(){return(this.allowCollisions&GameObject.ANY)>GameObject.NONE},set:function(Solid){if(Solid){this.allowCollisions=GameObject.ANY}else{this.allowCollisions=GameObject.NONE}},enumerable:true,configurable:true});GameObject.prototype.getMidpoint=function(point){if(typeof point==="undefined"){point=null}if(point==null){point=new Point()}point.x=this.x+this.width*0.5;point.y=this.y+this.height*0.5;return point};GameObject.prototype.reset=function(X,Y){this.revive();this.touching=GameObject.NONE;this.wasTouching=GameObject.NONE;this.x=X;this.y=Y;this.last.x=X;this.last.y=Y;this.velocity.x=0;this.velocity.y=0};GameObject.prototype.isTouching=function(Direction){return(this.touching&Direction)>GameObject.NONE};GameObject.prototype.justTouched=function(Direction){return((this.touching&Direction)>GameObject.NONE)&&((this.wasTouching&Direction)<=GameObject.NONE)};GameObject.prototype.hurt=function(Damage){this.health=this.health-Damage;if(this.health<=0){this.kill()}};GameObject.prototype.destroy=function(){};Object.defineProperty(GameObject.prototype,"x",{get:function(){return this.bounds.x},set:function(value){this.bounds.x=value},enumerable:true,configurable:true});Object.defineProperty(GameObject.prototype,"y",{get:function(){return this.bounds.y},set:function(value){this.bounds.y=value},enumerable:true,configurable:true});Object.defineProperty(GameObject.prototype,"rotation",{get:function(){return this._angle},set:function(value){this._angle=this._game.math.wrap(value,360,0)},enumerable:true,configurable:true});Object.defineProperty(GameObject.prototype,"angle",{get:function(){return this._angle},set:function(value){this._angle=this._game.math.wrap(value,360,0)},enumerable:true,configurable:true});Object.defineProperty(GameObject.prototype,"width",{get:function(){return this.bounds.width},enumerable:true,configurable:true});Object.defineProperty(GameObject.prototype,"height",{get:function(){return this.bounds.height},enumerable:true,configurable:true});return GameObject})(Basic);var Sprite=(function(_super){__extends(Sprite,_super);function Sprite(game,x,y,key){if(typeof x==="undefined"){x=0}if(typeof y==="undefined"){y=0}if(typeof key==="undefined"){key=null}_super.call(this,game,x,y);this._sx=0;this._sy=0;this._sw=0;this._sh=0;this._dx=0;this._dy=0;this._dw=0;this._dh=0;this._texture=null;this.animations=new Animations(this._game,this);if(key!==null){this.loadGraphic(key)}else{this.bounds.width=16;this.bounds.height=16}}Sprite.prototype.loadGraphic=function(key){if(this._game.cache.isSpriteSheet(key)==false){this._texture=this._game.cache.getImage(key);this.bounds.width=this._texture.width;this.bounds.height=this._texture.height}else{this._texture=this._game.cache.getImage(key);this.animations.loadFrameData(this._game.cache.getFrameData(key))}return this};Sprite.prototype.makeGraphic=function(width,height,color){if(typeof color==="undefined"){color=4294967295}this._texture=null;this.width=width;this.height=height;return this};Sprite.prototype.inCamera=function(camera){if(this.scrollFactor.x!==1||this.scrollFactor.y!==1){this._dx=this.bounds.x-(camera.x*this.scrollFactor.x);this._dy=this.bounds.y-(camera.y*this.scrollFactor.x);this._dw=this.bounds.width*this.scale.x;this._dh=this.bounds.height*this.scale.y;return(camera.right>this._dx)&&(camera.xthis._dy)&&(camera.y-1){this._game.stage.context.globalAlpha=globalAlpha}return true};Sprite.prototype.renderDebugInfo=function(x,y,color){if(typeof color==="undefined"){color="rgb(255,255,255)"}this._game.stage.context.fillStyle=color;this._game.stage.context.fillText("Sprite: "+this.name+" ("+this.bounds.width+" x "+this.bounds.height+")",x,y);this._game.stage.context.fillText("x: "+this.bounds.x.toFixed(1)+" y: "+this.bounds.y.toFixed(1)+" rotation: "+this.angle.toFixed(1),x,y+14);this._game.stage.context.fillText("dx: "+this._dx.toFixed(1)+" dy: "+this._dy.toFixed(1)+" dw: "+this._dw.toFixed(1)+" dh: "+this._dh.toFixed(1),x,y+28);this._game.stage.context.fillText("sx: "+this._sx.toFixed(1)+" sy: "+this._sy.toFixed(1)+" sw: "+this._sw.toFixed(1)+" sh: "+this._sh.toFixed(1),x,y+42)};return Sprite})(GameObject);var Group=(function(_super){__extends(Group,_super);function Group(game,MaxSize){if(typeof MaxSize==="undefined"){MaxSize=0}_super.call(this,game);this.isGroup=true;this.members=[];this.length=0;this._maxSize=MaxSize;this._marker=0;this._sortIndex=null}Group.ASCENDING=-1;Group.DESCENDING=1;Group.prototype.destroy=function(){if(this.members!=null){var basic;var i=0;while(i=this._maxSize){this._marker=0}if((this._maxSize==0)||(this.members==null)||(this._maxSize>=this.members.length)){return}var basic;var i=this._maxSize;var l=this.members.length;while(i=0){return Object}var i=0;var l=this.members.length;while(i=this.length){this.length=i+1}return Object}i++}if(this._maxSize>0){if(this.members.length>=this._maxSize){return Object}else{if(this.members.length*2<=this._maxSize){this.members.length*=2}else{this.members.length=this._maxSize}}}else{this.members.length*=2}this.members[i]=Object;this.length=i+1;return Object};Group.prototype.recycle=function(ObjectClass){if(typeof ObjectClass==="undefined"){ObjectClass=null}var basic;if(this._maxSize>0){if(this.length=this._maxSize){this._marker=0}return basic}}else{basic=this.getFirstAvailable(ObjectClass);if(basic!=null){return basic}if(ObjectClass==null){return null}return this.add(new ObjectClass())}};Group.prototype.remove=function(Object,Splice){if(typeof Splice==="undefined"){Splice=false}var index=this.members.indexOf(Object);if((index<0)||(index>=this.members.length)){return null}if(Splice){this.members.splice(index,1);this.length--}else{this.members[index]=null}return Object};Group.prototype.replace=function(OldObject,NewObject){var index=this.members.indexOf(OldObject);if((index<0)||(index>=this.members.length)){return null}this.members[index]=NewObject;return NewObject};Group.prototype.sort=function(Index,Order){if(typeof Index==="undefined"){Index="y"}if(typeof Order==="undefined"){Order=Group.ASCENDING}this._sortIndex=Index;this._sortOrder=Order;this.members.sort(this.sortHandler)};Group.prototype.setAll=function(VariableName,Value,Recurse){if(typeof Recurse==="undefined"){Recurse=true}var basic;var i=0;while(iObj2[this._sortIndex]){return -this._sortOrder}}return 0};return Group})(Basic);var Particle=(function(_super){__extends(Particle,_super);function Particle(game){_super.call(this,game);this.lifespan=0;this.friction=500}Particle.prototype.update=function(){if(this.lifespan<=0){return}this.lifespan-=this._game.time.elapsed;if(this.lifespan<=0){this.kill()}if(this.touching){if(this.angularVelocity!=0){this.angularVelocity=-this.angularVelocity}}if(this.acceleration.y>0){if(this.touching&GameObject.FLOOR){this.drag.x=this.friction;if(!(this.wasTouching&GameObject.FLOOR)){if(this.velocity.y<-this.elasticity*10){if(this.angularVelocity!=0){this.angularVelocity*=-this.elasticity}}else{this.velocity.y=0;this.angularVelocity=0}}}else{this.drag.x=0}}};Particle.prototype.onEmit=function(){};return Particle})(Sprite);var Emitter=(function(_super){__extends(Emitter,_super);function Emitter(game,X,Y,Size){if(typeof X==="undefined"){X=0}if(typeof Y==="undefined"){Y=0}if(typeof Size==="undefined"){Size=0}_super.call(this,game,Size);this.x=X;this.y=Y;this.width=0;this.height=0;this.minParticleSpeed=new Point(-100,-100);this.maxParticleSpeed=new Point(100,100);this.minRotation=-360;this.maxRotation=360;this.gravity=0;this.particleClass=null;this.particleDrag=new Point();this.frequency=0.1;this.lifespan=3;this.bounce=0;this._quantity=0;this._counter=0;this._explode=true;this.on=false;this._point=new Point()}Emitter.prototype.destroy=function(){this.minParticleSpeed=null;this.maxParticleSpeed=null;this.particleDrag=null;this.particleClass=null;this._point=null;_super.prototype.destroy.call(this)};Emitter.prototype.makeParticles=function(Graphics,Quantity,BakedRotations,Multiple,Collide){if(typeof Quantity==="undefined"){Quantity=50}if(typeof BakedRotations==="undefined"){BakedRotations=16}if(typeof Multiple==="undefined"){Multiple=false}if(typeof Collide==="undefined"){Collide=0.8}this.maxSize=Quantity;var totalFrames=1;var randomFrame;var particle;var i=0;while(i0){particle.width*=Collide;particle.height*=Collide}else{particle.allowCollisions=GameObject.NONE}particle.exists=false;this.add(particle);i++}return this};Emitter.prototype.update=function(){if(this.on){if(this._explode){this.on=false;var i=0;var l=this._quantity;if((l<=0)||(l>this.length)){l=this.length}while(i0)&&(this._timer>this.frequency)&&this.on){this._timer-=this.frequency;this.emitParticle();if((this._quantity>0)&&(++this._counter>=this._quantity)){this.on=false;this._quantity=0}}}}_super.prototype.update.call(this)};Emitter.prototype.kill=function(){this.on=false;_super.prototype.kill.call(this)};Emitter.prototype.start=function(Explode,Lifespan,Frequency,Quantity){if(typeof Explode==="undefined"){Explode=true}if(typeof Lifespan==="undefined"){Lifespan=0}if(typeof Frequency==="undefined"){Frequency=0.1}if(typeof Quantity==="undefined"){Quantity=0}this.revive();this.visible=true;this.on=true;this._explode=Explode;this.lifespan=Lifespan;this.frequency=Frequency;this._quantity+=Quantity;this._counter=0;this._timer=0};Emitter.prototype.emitParticle=function(){var particle=this.recycle(Particle);particle.lifespan=this.lifespan;particle.elasticity=this.bounce;particle.reset(this.x-(particle.width>>1)+this._game.math.random()*this.width,this.y-(particle.height>>1)+this._game.math.random()*this.height);particle.visible=true;if(this.minParticleSpeed.x!=this.maxParticleSpeed.x){particle.velocity.x=this.minParticleSpeed.x+this._game.math.random()*(this.maxParticleSpeed.x-this.minParticleSpeed.x)}else{particle.velocity.x=this.minParticleSpeed.x}if(this.minParticleSpeed.y!=this.maxParticleSpeed.y){particle.velocity.y=this.minParticleSpeed.y+this._game.math.random()*(this.maxParticleSpeed.y-this.minParticleSpeed.y)}else{particle.velocity.y=this.minParticleSpeed.y}particle.acceleration.y=this.gravity;if(this.minRotation!=this.maxRotation){particle.angularVelocity=this.minRotation+this._game.math.random()*(this.maxRotation-this.minRotation)}else{particle.angularVelocity=this.minRotation}if(particle.angularVelocity!=0){particle.angle=this._game.math.random()*360-180}particle.drag.x=this.particleDrag.x;particle.drag.y=this.particleDrag.y;particle.onEmit()};Emitter.prototype.setSize=function(Width,Height){this.width=Width;this.height=Height};Emitter.prototype.setXSpeed=function(Min,Max){if(typeof Min==="undefined"){Min=0}if(typeof Max==="undefined"){Max=0}this.minParticleSpeed.x=Min;this.maxParticleSpeed.x=Max};Emitter.prototype.setYSpeed=function(Min,Max){if(typeof Min==="undefined"){Min=0}if(typeof Max==="undefined"){Max=0}this.minParticleSpeed.y=Min;this.maxParticleSpeed.y=Max};Emitter.prototype.setRotation=function(Min,Max){if(typeof Min==="undefined"){Min=0}if(typeof Max==="undefined"){Max=0}this.minRotation=Min;this.maxRotation=Max};Emitter.prototype.at=function(Object){Object.getMidpoint(this._point);this.x=this._point.x-(this.width>>1);this.y=this._point.y-(this.height>>1)};return Emitter})(Group);var Loader=(function(){function Loader(game,callback){this._game=game;this._gameCreateComplete=callback;this._keys=[];this._fileList={};this._xhr=new XMLHttpRequest()}Loader.prototype.checkKeyExists=function(key){if(this._fileList[key]){return true}else{return false}};Loader.prototype.addImageFile=function(key,url){if(this.checkKeyExists(key)===false){this._fileList[key]={type:"image",key:key,url:url,data:null,error:false,loaded:false};this._keys.push(key)}};Loader.prototype.addSpriteSheet=function(key,url,frameWidth,frameHeight,frameMax){if(typeof frameMax==="undefined"){frameMax=-1}if(this.checkKeyExists(key)===false){this._fileList[key]={type:"spritesheet",key:key,url:url,data:null,frameWidth:frameWidth,frameHeight:frameHeight,frameMax:frameMax,error:false,loaded:false};this._keys.push(key)}};Loader.prototype.addTextureAtlas=function(key,url,jsonURL,jsonData){if(typeof jsonURL==="undefined"){jsonURL=null}if(typeof jsonData==="undefined"){jsonData=null}if(this.checkKeyExists(key)===false){if(jsonURL!==null){this._fileList[key]={type:"textureatlas",key:key,url:url,data:null,jsonURL:jsonURL,jsonData:null,error:false,loaded:false};this._keys.push(key)}else{if(typeof jsonData==="string"){var data=JSON.parse(jsonData);if(data.frames){this._fileList[key]={type:"textureatlas",key:key,url:url,data:null,jsonURL:null,jsonData:data.frames,error:false,loaded:false};this._keys.push(key)}}else{if(jsonData.frames){this._fileList[key]={type:"textureatlas",key:key,url:url,data:null,jsonURL:null,jsonData:jsonData.frames,error:false,loaded:false};this._keys.push(key)}}}}};Loader.prototype.addAudioFile=function(key,url){if(this.checkKeyExists(key)===false){this._fileList[key]={type:"audio",key:key,url:url,data:null,buffer:null,error:false,loaded:false};this._keys.push(key)}};Loader.prototype.addTextFile=function(key,url){if(this.checkKeyExists(key)===false){this._fileList[key]={type:"text",key:key,url:url,data:null,error:false,loaded:false};this._keys.push(key)}};Loader.prototype.removeFile=function(key){delete this._fileList[key]};Loader.prototype.removeAll=function(){this._fileList={}};Loader.prototype.load=function(onFileLoadCallback,onCompleteCallback){if(typeof onFileLoadCallback==="undefined"){onFileLoadCallback=null}if(typeof onCompleteCallback==="undefined"){onCompleteCallback=null}this.progress=0;this.hasLoaded=false;this._onComplete=onCompleteCallback;if(onCompleteCallback==null){this._onComplete=this._game.onCreateCallback}this._onFileLoad=onFileLoadCallback;if(this._keys.length>0){this._progressChunk=100/this._keys.length;this.loadFile()}else{this.progress=1;this.hasLoaded=true;this._gameCreateComplete.call(this._game);if(this._onComplete!==null){this._onComplete.call(this._game.callbackContext)}}};Loader.prototype.loadFile=function(){var _this=this;var file=this._fileList[this._keys.pop()];switch(file.type){case"image":case"spritesheet":case"textureatlas":file.data=new Image();file.data.name=file.key;file.data.onload=function(){return _this.fileComplete(file.key)};file.data.onerror=function(){return _this.fileError(file.key)};file.data.src=file.url;break;case"audio":this._xhr.open("GET",file.url,true);this._xhr.responseType="arraybuffer";this._xhr.onload=function(){return _this.fileComplete(file.key)};this._xhr.onerror=function(){return _this.fileError(file.key)};this._xhr.send();break;case"text":this._xhr.open("GET",file.url,true);this._xhr.responseType="text";this._xhr.onload=function(){return _this.fileComplete(file.key)};this._xhr.onerror=function(){return _this.fileError(file.key)};this._xhr.send();break}};Loader.prototype.fileError=function(key){this._fileList[key].loaded=true;this._fileList[key].error=true;this.nextFile(key,false)};Loader.prototype.fileComplete=function(key){var _this=this;this._fileList[key].loaded=true;var file=this._fileList[key];var loadNext=true;switch(file.type){case"image":this._game.cache.addImage(file.key,file.url,file.data);break;case"spritesheet":this._game.cache.addSpriteSheet(file.key,file.url,file.data,file.frameWidth,file.frameHeight,file.frameMax);break;case"textureatlas":if(file.jsonURL==null){this._game.cache.addTextureAtlas(file.key,file.url,file.data,file.jsonData)}else{loadNext=false;this._xhr.open("GET",file.jsonURL,true);this._xhr.responseType="text";this._xhr.onload=function(){return _this.jsonLoadComplete(file.key)};this._xhr.onerror=function(){return _this.jsonLoadError(file.key)};this._xhr.send()}break;case"audio":file.data=this._xhr.response;this._game.cache.addSound(file.key,file.url,file.data);break;case"text":file.data=this._xhr.response;this._game.cache.addText(file.key,file.url,file.data);break}if(loadNext){this.nextFile(key,true)}};Loader.prototype.jsonLoadComplete=function(key){var data=JSON.parse(this._xhr.response);if(data.frames){var file=this._fileList[key];this._game.cache.addTextureAtlas(file.key,file.url,file.data,data.frames)}this.nextFile(key,true)};Loader.prototype.jsonLoadError=function(key){var file=this._fileList[key];file.error=true;this.nextFile(key,true)};Loader.prototype.nextFile=function(previousKey,success){this.progress=Math.round(this.progress+this._progressChunk);if(this._onFileLoad){this._onFileLoad.call(this._game.callbackContext,this.progress,previousKey,success)}if(this._keys.length>0){this.loadFile()}else{this.hasLoaded=true;this.removeAll();this._gameCreateComplete.call(this._game);if(this._onComplete!==null){this._onComplete.call(this._game.callbackContext)}}};return Loader})();var SoundManager=(function(){function SoundManager(game){this._context=null;this._game=game;if(game.device.webaudio==true){if(!!window.AudioContext){this._context=new window.AudioContext()}else{if(!!window.webkitAudioContext){this._context=new window.webkitAudioContext()}}if(this._context!==null){this._gainNode=this._context.createGainNode();this._gainNode.connect(this._context.destination);this._volume=1}}}SoundManager.prototype.mute=function(){this._gainNode.gain.value=0};SoundManager.prototype.unmute=function(){this._gainNode.gain.value=this._volume};Object.defineProperty(SoundManager.prototype,"volume",{get:function(){return this._volume},set:function(value){this._volume=value;this._gainNode.gain.value=this._volume},enumerable:true,configurable:true});SoundManager.prototype.decode=function(key,callback,sound){if(typeof callback==="undefined"){callback=null}if(typeof sound==="undefined"){sound=null}var soundData=this._game.cache.getSound(key);if(soundData){if(this._game.cache.isSoundDecoded(key)===false){var that=this;this._context.decodeAudioData(soundData,function(buffer){that._game.cache.decodedSound(key,buffer);if(sound){sound.setDecodedBuffer(buffer)}callback()})}}};SoundManager.prototype.play=function(key,volume,loop){if(typeof volume==="undefined"){volume=1}if(typeof loop==="undefined"){loop=false}var _this=this;if(this._context===null){return}var soundData=this._game.cache.getSound(key);if(soundData){if(this._game.cache.isSoundDecoded(key)===true){return new Sound(this._context,this._gainNode,soundData,volume,loop)}else{var tempSound=new Sound(this._context,this._gainNode,null,volume,loop);this.decode(key,function(){return _this.play(key)},tempSound);return tempSound}}};return SoundManager})();var Sound=(function(){function Sound(context,gainNode,data,volume,loop){if(typeof volume==="undefined"){volume=1}if(typeof loop==="undefined"){loop=false}this.loop=false;this.isPlaying=false;this.isDecoding=false;this._context=context;this._gainNode=gainNode;this._buffer=data;this._volume=volume;this.loop=loop;if(this._context!==null){this._localGainNode=this._context.createGainNode();this._localGainNode.connect(this._gainNode);this._localGainNode.gain.value=this._volume}if(this._buffer===null){this.isDecoding=true}else{this.play()}}Sound.prototype.setDecodedBuffer=function(data){this._buffer=data;this.isDecoding=false;this.play()};Sound.prototype.play=function(){if(this._buffer===null||this.isDecoding===true){return}this._sound=this._context.createBufferSource();this._sound.buffer=this._buffer;this._sound.connect(this._localGainNode);if(this.loop){this._sound.loop=true}this._sound.noteOn(0);this.duration=this._sound.buffer.duration;this.isPlaying=true};Sound.prototype.stop=function(){if(this.isPlaying===true){this.isPlaying=false;this._sound.noteOff(0)}};Sound.prototype.mute=function(){this._localGainNode.gain.value=0};Sound.prototype.unmute=function(){this._localGainNode.gain.value=this._volume};Object.defineProperty(Sound.prototype,"volume",{get:function(){return this._volume},set:function(value){this._volume=value;this._localGainNode.gain.value=this._volume},enumerable:true,configurable:true});return Sound})();var StageScaleMode=(function(){function StageScaleMode(game){var _this=this;this._startHeight=0;this.width=0;this.height=0;this._game=game;this.orientation=window.orientation;window.addEventListener("orientationchange",function(event){return _this.checkOrientation(event)},false)}StageScaleMode.EXACT_FIT=0;StageScaleMode.NO_SCALE=1;StageScaleMode.SHOW_ALL=2;StageScaleMode.prototype.update=function(){if(this._game.stage.scaleMode!==StageScaleMode.NO_SCALE&&(window.innerWidth!==this.width||window.innerHeight!==this.height)){this.refresh()}};Object.defineProperty(StageScaleMode.prototype,"isLandscape",{get:function(){return window.orientation===90||window.orientation===-90},enumerable:true,configurable:true});StageScaleMode.prototype.checkOrientation=function(event){if(window.orientation!==this.orientation){this.refresh();this.orientation=window.orientation}};StageScaleMode.prototype.refresh=function(){var _this=this;if(this._game.device.iPad==false&&this._game.device.webApp==false&&this._game.device.desktop==false){document.documentElement.style.minHeight="5000px";this._startHeight=window.innerHeight;if(this._game.device.android&&this._game.device.chrome==false){window.scrollTo(0,1)}else{window.scrollTo(0,0)}}if(this._check==null){this._iterations=40;this._check=window.setInterval(function(){return _this.setScreenSize()},10)}};StageScaleMode.prototype.setScreenSize=function(){if(this._game.device.iPad==false&&this._game.device.webApp==false&&this._game.device.desktop==false){if(this._game.device.android&&this._game.device.chrome==false){window.scrollTo(0,1)}else{window.scrollTo(0,0)}}this._iterations--;if(window.innerHeight>this._startHeight||this._iterations<0){document.documentElement.style.minHeight=window.innerHeight+"px";if(this._game.stage.scaleMode==StageScaleMode.EXACT_FIT){if(this._game.stage.maxScaleX&&window.innerWidth>this._game.stage.maxScaleX){this.width=this._game.stage.maxScaleX}else{this.width=window.innerWidth}if(this._game.stage.maxScaleY&&window.innerHeight>this._game.stage.maxScaleY){this.height=this._game.stage.maxScaleY}else{this.height=window.innerHeight}}else{if(this._game.stage.scaleMode==StageScaleMode.SHOW_ALL){var multiplier=Math.min((window.innerHeight/this._game.stage.height),(window.innerWidth/this._game.stage.width));this.width=Math.round(this._game.stage.width*multiplier);this.height=Math.round(this._game.stage.height*multiplier);if(this._game.stage.maxScaleX&&this.width>this._game.stage.maxScaleX){this.width=this._game.stage.maxScaleX}if(this._game.stage.maxScaleY&&this.height>this._game.stage.maxScaleY){this.height=this._game.stage.maxScaleY}}}this._game.stage.canvas.style.width=this.width+"px";this._game.stage.canvas.style.height=this.height+"px";this._game.input.scaleX=this._game.stage.width/this.width;this._game.input.scaleY=this._game.stage.height/this.height;clearInterval(this._check);this._check=null}};return StageScaleMode})();var Stage=(function(){function Stage(game,parent,width,height){var _this=this;this.clear=true;this.minScaleX=null;this.maxScaleX=null;this.minScaleY=null;this.maxScaleY=null;this._logo="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAO1JREFUeNpi/P//PwM6YGRkxBQEAqBaRnQxFmwa10d6MAjrMqMofHv5L1we2SBGmAtAktg0ogOQQYHLd8ANYYFpPtTmzUAMAFmwnsEDrAdkCAvMZlIAsiFMMAEYsKvaSrQhIMCELkGsV2AAbIC8gCQYgwKIUABiNYBf9yoYH7n7n6CzN274g2IYEyFbsNmKLIaSkHpP7WSwUfbA0ASzFQRslBlxp0RcAF0TRhggA3zhAJIDpUKU5A9KyshpHDkjFZu5g2nJMFcwXVJSgqIGnBKx5bKenh4w/XzVbgbPtlIUcVgSxuoCUgHIIIAAAwArtXwJBABO6QAAAABJRU5ErkJggg==";this._game=game;this.canvas=document.createElement("canvas");this.canvas.width=width;this.canvas.height=height;if(document.getElementById(parent)){document.getElementById(parent).appendChild(this.canvas);document.getElementById(parent).style.overflow="hidden"}else{document.body.appendChild(this.canvas)}this.context=this.canvas.getContext("2d");this.offset=this.getOffset(this.canvas);this.bounds=new Rectangle(this.offset.x,this.offset.y,width,height);this.aspectRatio=width/height;this.scaleMode=StageScaleMode.NO_SCALE;this.scale=new StageScaleMode(this._game);window.onblur=function(event){return _this.visibilityChange(event)};window.onfocus=function(event){return _this.visibilityChange(event)}}Stage.ORIENTATION_LANDSCAPE=0;Stage.ORIENTATION_PORTRAIT=1;Stage.prototype.update=function(){this.scale.update();if(this.clear){this.context.clearRect(0,0,this.width,this.height)}};Stage.prototype.renderDebugInfo=function(){this.context.fillStyle="rgb(255,255,255)";this.context.fillText(Game.VERSION,10,20);this.context.fillText("Game Size: "+this.width+" x "+this.height,10,40);this.context.fillText("x: "+this.x+" y: "+this.y,10,60)};Stage.prototype.visibilityChange=function(event){if(event.type=="blur"&&this._game.pause==false&&this._game.isBooted==true){this._game.pause=true;this.drawPauseScreen()}else{if(event.type=="focus"){this._game.pause=false}}};Stage.prototype.drawInitScreen=function(){this.context.fillStyle="rgb(40, 40, 40)";this.context.fillRect(0,0,this.width,this.height);this.context.fillStyle="rgb(255,255,255)";this.context.font="bold 18px Arial";this.context.textBaseline="top";this.context.fillText(Game.VERSION,54,32);this.context.fillText("Game Size: "+this.width+" x "+this.height,32,64);this.context.fillText("www.photonstorm.com",32,96);this.context.font="16px Arial";this.context.fillText("You are seeing this screen because you didn't specify any default",32,160);this.context.fillText("functions in the Game constructor, or use Game.loadState()",32,184);var image=new Image();var that=this;image.onload=function(){that.context.drawImage(image,32,32)};image.src=this._logo};Stage.prototype.drawPauseScreen=function(){this.context.fillStyle="rgba(0, 0, 0, 0.4)";this.context.fillRect(0,0,this.width,this.height);var arrowWidth=Math.round(this.width/2);var arrowHeight=Math.round(this.height/2);var sx=this.centerX-arrowWidth/2;var sy=this.centerY-arrowHeight/2;this.context.beginPath();this.context.moveTo(sx,sy);this.context.lineTo(sx,sy+arrowHeight);this.context.lineTo(sx+arrowWidth,this.centerY);this.context.closePath();this.context.fillStyle="rgba(255, 255, 255, 0.8)";this.context.fill()};Stage.prototype.getOffset=function(element){var box=element.getBoundingClientRect();var clientTop=element.clientTop||document.body.clientTop||0;var clientLeft=element.clientLeft||document.body.clientLeft||0;var scrollTop=window.pageYOffset||element.scrollTop||document.body.scrollTop;var scrollLeft=window.pageXOffset||element.scrollLeft||document.body.scrollLeft;return new Point(box.left+scrollLeft-clientLeft,box.top+scrollTop-clientTop)};Object.defineProperty(Stage.prototype,"backgroundColor",{get:function(){return this._bgColor},set:function(color){this.canvas.style.backgroundColor=color},enumerable:true,configurable:true});Object.defineProperty(Stage.prototype,"x",{get:function(){return this.bounds.x},enumerable:true,configurable:true});Object.defineProperty(Stage.prototype,"y",{get:function(){return this.bounds.y},enumerable:true,configurable:true});Object.defineProperty(Stage.prototype,"width",{get:function(){return this.bounds.width},enumerable:true,configurable:true});Object.defineProperty(Stage.prototype,"height",{get:function(){return this.bounds.height},enumerable:true,configurable:true});Object.defineProperty(Stage.prototype,"centerX",{get:function(){return this.bounds.halfWidth},enumerable:true,configurable:true});Object.defineProperty(Stage.prototype,"centerY",{get:function(){return this.bounds.halfHeight},enumerable:true,configurable:true});Object.defineProperty(Stage.prototype,"randomX",{get:function(){return Math.round(Math.random()*this.bounds.width)},enumerable:true,configurable:true});Object.defineProperty(Stage.prototype,"randomY",{get:function(){return Math.round(Math.random()*this.bounds.height)},enumerable:true,configurable:true});return Stage})();var Time=(function(){function Time(game){this.timeScale=1;this.elapsed=0;this.time=0;this.now=0;this.delta=0;this.fps=0;this.fpsMin=1000;this.fpsMax=0;this.msMin=1000;this.msMax=0;this.frames=0;this._timeLastSecond=0;this._started=Date.now();this._timeLastSecond=this._started;this.time=this._started}Object.defineProperty(Time.prototype,"totalElapsedSeconds",{get:function(){return(this.now-this._started)*0.001},enumerable:true,configurable:true});Time.prototype.update=function(){this.now=Date.now();this.delta=this.now-this.time;this.msMin=Math.min(this.msMin,this.delta);this.msMax=Math.max(this.msMax,this.delta);this.frames++;if(this.now>this._timeLastSecond+1000){this.fps=Math.round((this.frames*1000)/(this.now-this._timeLastSecond));this.fpsMin=Math.min(this.fpsMin,this.fps);this.fpsMax=Math.max(this.fpsMax,this.fps);this._timeLastSecond=this.now;this.frames=0}this.time=this.now};Time.prototype.elapsedSince=function(since){return this.now-since};Time.prototype.elapsedSecondsSince=function(since){return(this.now-since)*0.001};Time.prototype.reset=function(){this._started=this.now};return Time})();var TilemapBuffer=(function(){function TilemapBuffer(game,camera,tilemap,texture,tileOffsets){this._startX=0;this._maxX=0;this._startY=0;this._maxY=0;this._tx=0;this._ty=0;this._dx=0;this._dy=0;this._oldCameraX=0;this._oldCameraY=0;this._dirty=true;this._game=game;this.camera=camera;this._tilemap=tilemap;this._texture=texture;this._tileOffsets=tileOffsets}TilemapBuffer.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this._game.stage.width;this.canvas.height=this._game.stage.height;this.context=this.canvas.getContext("2d")};TilemapBuffer.prototype.update=function(){};TilemapBuffer.prototype.renderDebugInfo=function(x,y,color){if(typeof color==="undefined"){color="rgb(255,255,255)"}this._game.stage.context.fillStyle=color;this._game.stage.context.fillText("TilemapBuffer",x,y);this._game.stage.context.fillText("startX: "+this._startX+" endX: "+this._maxX,x,y+14);this._game.stage.context.fillText("startY: "+this._startY+" endY: "+this._maxY,x,y+28);this._game.stage.context.fillText("dx: "+this._dx+" dy: "+this._dy,x,y+42);this._game.stage.context.fillText("Dirty: "+this._dirty,x,y+56)};TilemapBuffer.prototype.render=function(dx,dy){this._maxX=this._game.math.ceil(this.camera.width/this._tilemap.tileWidth)+1;this._maxY=this._game.math.ceil(this.camera.height/this._tilemap.tileHeight)+1;this._startX=this._game.math.floor(this.camera.worldView.x/this._tilemap.tileWidth);this._startY=this._game.math.floor(this.camera.worldView.y/this._tilemap.tileHeight);if(this._startX<0){this._startX=0}if(this._startY<0){this._startY=0}if(this._startX+this._maxX>this._tilemap.widthInTiles){this._startX=this._tilemap.widthInTiles-this._maxX}if(this._startY+this._maxY>this._tilemap.heightInTiles){this._startY=this._tilemap.heightInTiles-this._maxY}this._dx=dx;this._dy=dy;this._dx+=-(this.camera.worldView.x-(this._startX*this._tilemap.tileWidth));this._dy+=-(this.camera.worldView.y-(this._startY*this._tilemap.tileHeight));this._tx=this._dx;this._ty=this._dy;for(var row=this._startY;row0){if(this.widthInTiles==0){this.widthInTiles=column.length}this.heightInTiles++;for(var c=0;c0){this.widthInPixels=this.tileWidth*this.widthInTiles}if(this.heightInTiles>0){this.heightInPixels=this.tileHeight*this.heightInTiles}this.boundsInTiles.setTo(0,0,this.widthInTiles,this.heightInTiles)};Tilemap.prototype.parseTiledJSON=function(data){console.log("parseTiledJSON");this.mapData=[];data=data.trim();var json=JSON.parse(data);this.tileWidth=json.tilewidth;this.tileHeight=json.tileheight;this.widthInTiles=json.layers[0].width;this.heightInTiles=json.layers[0].height;this.widthInPixels=this.widthInTiles*this.tileWidth;this.heightInPixels=this.heightInTiles*this.tileHeight;this.boundsInTiles.setTo(0,0,this.widthInTiles,this.heightInTiles);console.log("width in tiles",this.widthInTiles);console.log("height in tiles",this.heightInTiles);console.log("width in px",this.widthInPixels);console.log("height in px",this.heightInPixels);var c=0;var row;for(var i=0;iQuadTree._min)||(this.height>QuadTree._min);this._northWestTree=null;this._northEastTree=null;this._southEastTree=null;this._southWestTree=null;this._leftEdge=this.x;this._rightEdge=this.x+this.width;this._halfWidth=this.width/2;this._midpointX=this._leftEdge+this._halfWidth;this._topEdge=this.y;this._bottomEdge=this.y+this.height;this._halfHeight=this.height/2;this._midpointY=this._topEdge+this._halfHeight}QuadTree.A_LIST=0;QuadTree.B_LIST=1;QuadTree.prototype.destroy=function(){this._tailA.destroy();this._tailB.destroy();this._headA.destroy();this._headB.destroy();this._tailA=null;this._tailB=null;this._headA=null;this._headB=null;if(this._northWestTree!=null){this._northWestTree.destroy()}if(this._northEastTree!=null){this._northEastTree.destroy()}if(this._southEastTree!=null){this._southEastTree.destroy()}if(this._southWestTree!=null){this._southWestTree.destroy()}this._northWestTree=null;this._northEastTree=null;this._southEastTree=null;this._southWestTree=null;QuadTree._object=null;QuadTree._processingCallback=null;QuadTree._notifyCallback=null};QuadTree.prototype.load=function(ObjectOrGroup1,ObjectOrGroup2,NotifyCallback,ProcessCallback){if(typeof ObjectOrGroup2==="undefined"){ObjectOrGroup2=null}if(typeof NotifyCallback==="undefined"){NotifyCallback=null}if(typeof ProcessCallback==="undefined"){ProcessCallback=null}this.add(ObjectOrGroup1,QuadTree.A_LIST);if(ObjectOrGroup2!=null){this.add(ObjectOrGroup2,QuadTree.B_LIST);QuadTree._useBothLists=true}else{QuadTree._useBothLists=false}QuadTree._notifyCallback=NotifyCallback;QuadTree._processingCallback=ProcessCallback};QuadTree.prototype.add=function(ObjectOrGroup,List){QuadTree._list=List;if(ObjectOrGroup.isGroup==true){var i=0;var basic;var members=ObjectOrGroup.members;var l=ObjectOrGroup.length;while(i=QuadTree._objectLeftEdge)&&(this._rightEdge<=QuadTree._objectRightEdge)&&(this._topEdge>=QuadTree._objectTopEdge)&&(this._bottomEdge<=QuadTree._objectBottomEdge))){this.addToList();return}if((QuadTree._objectLeftEdge>this._leftEdge)&&(QuadTree._objectRightEdgethis._topEdge)&&(QuadTree._objectBottomEdgethis._midpointY)&&(QuadTree._objectBottomEdgethis._midpointX)&&(QuadTree._objectRightEdgethis._topEdge)&&(QuadTree._objectBottomEdgethis._midpointY)&&(QuadTree._objectBottomEdgethis._leftEdge)&&(QuadTree._objectLeftEdgethis._topEdge)&&(QuadTree._objectTopEdgethis._midpointX)&&(QuadTree._objectLeftEdgethis._topEdge)&&(QuadTree._objectTopEdgethis._midpointX)&&(QuadTree._objectLeftEdgethis._midpointY)&&(QuadTree._objectTopEdgethis._leftEdge)&&(QuadTree._objectLeftEdgethis._midpointY)&&(QuadTree._objectTopEdge0)&&(QuadTree._iterator!=null)&&(QuadTree._iterator.object!=null)&&QuadTree._iterator.object.exists&&this.overlapNode()){overlapProcessed=true}iterator=iterator.next}}if((this._northWestTree!=null)&&this._northWestTree.execute()){overlapProcessed=true}if((this._northEastTree!=null)&&this._northEastTree.execute()){overlapProcessed=true}if((this._southEastTree!=null)&&this._southEastTree.execute()){overlapProcessed=true}if((this._southWestTree!=null)&&this._southWestTree.execute()){overlapProcessed=true}return overlapProcessed};QuadTree.prototype.overlapNode=function(){var overlapProcessed=false;var checkObject;while(QuadTree._iterator!=null){if(!QuadTree._object.exists||(QuadTree._object.allowCollisions<=0)){break}checkObject=QuadTree._iterator.object;if((QuadTree._object===checkObject)||!checkObject.exists||(checkObject.allowCollisions<=0)){QuadTree._iterator=QuadTree._iterator.next;continue}QuadTree._objectHullX=(QuadTree._object.x0)?QuadTree._objectHullWidth:-QuadTree._objectHullWidth);QuadTree._objectHullHeight=QuadTree._object.y-QuadTree._object.last.y;QuadTree._objectHullHeight=QuadTree._object.height+((QuadTree._objectHullHeight>0)?QuadTree._objectHullHeight:-QuadTree._objectHullHeight);QuadTree._checkObjectHullX=(checkObject.x0)?QuadTree._checkObjectHullWidth:-QuadTree._checkObjectHullWidth);QuadTree._checkObjectHullHeight=checkObject.y-checkObject.last.y;QuadTree._checkObjectHullHeight=checkObject.height+((QuadTree._checkObjectHullHeight>0)?QuadTree._checkObjectHullHeight:-QuadTree._checkObjectHullHeight);if((QuadTree._objectHullX+QuadTree._objectHullWidth>QuadTree._checkObjectHullX)&&(QuadTree._objectHullXQuadTree._checkObjectHullY)&&(QuadTree._objectHullY0)?obj1delta:-obj1delta;var obj2deltaAbs=(obj2delta>0)?obj2delta:-obj2delta;var obj1rect=new Rectangle(Object1.x-((obj1delta>0)?obj1delta:0),Object1.last.y,Object1.width+((obj1delta>0)?obj1delta:-obj1delta),Object1.height);var obj2rect=new Rectangle(Object2.x-((obj2delta>0)?obj2delta:0),Object2.last.y,Object2.width+((obj2delta>0)?obj2delta:-obj2delta),Object2.height);if((obj1rect.x+obj1rect.width>obj2rect.x)&&(obj1rect.xobj2rect.y)&&(obj1rect.yobj2delta){overlap=Object1.x+Object1.width-Object2.x;if((overlap>maxOverlap)||!(Object1.allowCollisions&GameObject.RIGHT)||!(Object2.allowCollisions&GameObject.LEFT)){overlap=0}else{Object1.touching|=GameObject.RIGHT;Object2.touching|=GameObject.LEFT}}else{if(obj1deltamaxOverlap)||!(Object1.allowCollisions&GameObject.LEFT)||!(Object2.allowCollisions&GameObject.RIGHT)){overlap=0}else{Object1.touching|=GameObject.LEFT;Object2.touching|=GameObject.RIGHT}}}}}if(overlap!=0){var obj1v=Object1.velocity.x;var obj2v=Object2.velocity.x;if(!obj1immovable&&!obj2immovable){overlap*=0.5;Object1.x=Object1.x-overlap;Object2.x+=overlap;var obj1velocity=Math.sqrt((obj2v*obj2v*Object2.mass)/Object1.mass)*((obj2v>0)?1:-1);var obj2velocity=Math.sqrt((obj1v*obj1v*Object1.mass)/Object2.mass)*((obj1v>0)?1:-1);var average=(obj1velocity+obj2velocity)*0.5;obj1velocity-=average;obj2velocity-=average;Object1.velocity.x=average+obj1velocity*Object1.elasticity;Object2.velocity.x=average+obj2velocity*Object2.elasticity}else{if(!obj1immovable){Object1.x=Object1.x-overlap;Object1.velocity.x=obj2v-obj1v*Object1.elasticity}else{if(!obj2immovable){Object2.x+=overlap;Object2.velocity.x=obj1v-obj2v*Object2.elasticity}}}return true}else{return false}};World.separateY=function separateY(Object1,Object2){var obj1immovable=Object1.immovable;var obj2immovable=Object2.immovable;if(obj1immovable&&obj2immovable){return false}var overlap=0;var obj1delta=Object1.y-Object1.last.y;var obj2delta=Object2.y-Object2.last.y;if(obj1delta!=obj2delta){var obj1deltaAbs=(obj1delta>0)?obj1delta:-obj1delta;var obj2deltaAbs=(obj2delta>0)?obj2delta:-obj2delta;var obj1rect=new Rectangle(Object1.x,Object1.y-((obj1delta>0)?obj1delta:0),Object1.width,Object1.height+obj1deltaAbs);var obj2rect=new Rectangle(Object2.x,Object2.y-((obj2delta>0)?obj2delta:0),Object2.width,Object2.height+obj2deltaAbs);if((obj1rect.x+obj1rect.width>obj2rect.x)&&(obj1rect.xobj2rect.y)&&(obj1rect.yobj2delta){overlap=Object1.y+Object1.height-Object2.y;if((overlap>maxOverlap)||!(Object1.allowCollisions&GameObject.DOWN)||!(Object2.allowCollisions&GameObject.UP)){overlap=0}else{Object1.touching|=GameObject.DOWN;Object2.touching|=GameObject.UP}}else{if(obj1deltamaxOverlap)||!(Object1.allowCollisions&GameObject.UP)||!(Object2.allowCollisions&GameObject.DOWN)){overlap=0}else{Object1.touching|=GameObject.UP;Object2.touching|=GameObject.DOWN}}}}}if(overlap!=0){var obj1v=Object1.velocity.y;var obj2v=Object2.velocity.y;if(!obj1immovable&&!obj2immovable){overlap*=0.5;Object1.y=Object1.y-overlap;Object2.y+=overlap;var obj1velocity=Math.sqrt((obj2v*obj2v*Object2.mass)/Object1.mass)*((obj2v>0)?1:-1);var obj2velocity=Math.sqrt((obj1v*obj1v*Object1.mass)/Object2.mass)*((obj1v>0)?1:-1);var average=(obj1velocity+obj2velocity)*0.5;obj1velocity-=average;obj2velocity-=average;Object1.velocity.y=average+obj1velocity*Object1.elasticity;Object2.velocity.y=average+obj2velocity*Object2.elasticity}else{if(!obj1immovable){Object1.y=Object1.y-overlap;Object1.velocity.y=obj2v-obj1v*Object1.elasticity;if(Object2.active&&Object2.moves&&(obj1delta>obj2delta)){Object1.x+=Object2.x-Object2.last.x}}else{if(!obj2immovable){Object2.y+=overlap;Object2.velocity.y=obj1v-obj2v*Object2.elasticity;if(Object1.active&&Object1.moves&&(obj1delta0){this._diameter=value;this._radius=value*0.5}return this._diameter};Circle.prototype.radius=function(value){if(value&&value>0){this._radius=value;this._diameter=value*2}return this._radius};Circle.prototype.circumference=function(){return 2*(Math.PI*this._radius)};Circle.prototype.bottom=function(value){if(value&&!isNaN(value)){if(valuethis.x){this.radius(value-this.x)}else{this._radius=0;this._diameter=0}}return this.x+this._radius};Circle.prototype.top=function(value){if(value&&!isNaN(value)){if(value>this.y){this._radius=0;this._diameter=0}else{this.radius(this.y-value)}}return this.y-this._radius};Circle.prototype.area=function(){if(this._radius>0){return Math.PI*this._radius*this._radius}else{return 0}};Circle.prototype.isEmpty=function(){if(this._diameter<1){return true}return false};Circle.prototype.clone=function(output){if(typeof output==="undefined"){output=new Circle()}return output.setTo(this.x,this.y,this._diameter)};Circle.prototype.copyFrom=function(source){return this.setTo(source.x,source.y,source.diameter())};Circle.prototype.copyTo=function(target){return target.copyFrom(this)};Circle.prototype.distanceTo=function(target,round){if(typeof round==="undefined"){round=false}var dx=this.x-target.x;var dy=this.y-target.y;if(round===true){return Math.round(Math.sqrt(dx*dx+dy*dy))}else{return Math.sqrt(dx*dx+dy*dy)}};Circle.prototype.equals=function(toCompare){if(this.x===toCompare.x&&this.y===toCompare.y&&this.diameter()===toCompare.diameter()){return true}return false};Circle.prototype.intersects=function(toIntersect){if(this.distanceTo(toIntersect,false)<(this._radius+toIntersect._radius)){return true}return false};Circle.prototype.circumferencePoint=function(angle,asDegrees,output){if(typeof asDegrees==="undefined"){asDegrees=false}if(typeof output==="undefined"){output=new Point()}if(asDegrees===true){angle=angle*(180/Math.PI)}output.x=this.x+this._radius*Math.cos(angle);output.y=this.y+this._radius*Math.sin(angle);return output};Circle.prototype.offset=function(dx,dy){if(!isNaN(dx)&&!isNaN(dy)){this.x+=dx;this.y+=dy}return this};Circle.prototype.offsetPoint=function(point){return this.offset(point.x,point.y)};Circle.prototype.setTo=function(x,y,diameter){this.x=x;this.y=y;this._diameter=diameter;this._radius=diameter*0.5;return this};Circle.prototype.toString=function(){return"[{Circle (x="+this.x+" y="+this.y+" diameter="+this.diameter()+" radius="+this.radius()+")}]"};return Circle})();var Finger=(function(){function Finger(game){this.point=null;this.circle=null;this.withinGame=false;this.clientX=-1;this.clientY=-1;this.pageX=-1;this.pageY=-1;this.screenX=-1;this.screenY=-1;this.x=-1;this.y=-1;this.isDown=false;this.isUp=false;this.timeDown=0;this.duration=0;this.timeUp=0;this.justPressedRate=200;this.justReleasedRate=200;this._game=game;this.active=false}Finger.prototype.start=function(event){this.identifier=event.identifier;this.target=event.target;if(this.point===null){this.point=new Point()}if(this.circle===null){this.circle=new Circle(0,0,44)}this.move(event);this.active=true;this.withinGame=true;this.isDown=true;this.isUp=false;this.timeDown=this._game.time.now};Finger.prototype.move=function(event){this.clientX=event.clientX;this.clientY=event.clientY;this.pageX=event.pageX;this.pageY=event.pageY;this.screenX=event.screenX;this.screenY=event.screenY;this.x=this.pageX-this._game.stage.offset.x;this.y=this.pageY-this._game.stage.offset.y;this.point.setTo(this.x,this.y);this.circle.setTo(this.x,this.y,44);this.duration=this._game.time.now-this.timeDown};Finger.prototype.leave=function(event){this.withinGame=false;this.move(event)};Finger.prototype.stop=function(event){this.active=false;this.withinGame=false;this.isDown=false;this.isUp=true;this.timeUp=this._game.time.now;this.duration=this.timeUp-this.timeDown};Finger.prototype.justPressed=function(duration){if(typeof duration==="undefined"){duration=this.justPressedRate}if(this.isDown===true&&(this.timeDown+duration)>this._game.time.now){return true}else{return false}};Finger.prototype.justReleased=function(duration){if(typeof duration==="undefined"){duration=this.justReleasedRate}if(this.isUp===true&&(this.timeUp+duration)>this._game.time.now){return true}else{return false}};Finger.prototype.toString=function(){return"[{Finger (identifer="+this.identifier+" active="+this.active+" duration="+this.duration+" withinGame="+this.withinGame+" x="+this.x+" y="+this.y+" clientX="+this.clientX+" clientY="+this.clientY+" screenX="+this.screenX+" screenY="+this.screenY+" pageX="+this.pageX+" pageY="+this.pageY+")}]"};return Finger})();var Touch=(function(){function Touch(game){this.x=0;this.y=0;this.isDown=false;this.isUp=true;this._game=game;this.finger1=new Finger(this._game);this.finger2=new Finger(this._game);this.finger3=new Finger(this._game);this.finger4=new Finger(this._game);this.finger5=new Finger(this._game);this.finger6=new Finger(this._game);this.finger7=new Finger(this._game);this.finger8=new Finger(this._game);this.finger9=new Finger(this._game);this.finger10=new Finger(this._game);this._fingers=[this.finger1,this.finger2,this.finger3,this.finger4,this.finger5,this.finger6,this.finger7,this.finger8,this.finger9,this.finger10];this.touchDown=new Signal();this.touchUp=new Signal();this.start()}Touch.prototype.start=function(){var _this=this;this._game.stage.canvas.addEventListener("touchstart",function(event){return _this.onTouchStart(event)},false);this._game.stage.canvas.addEventListener("touchmove",function(event){return _this.onTouchMove(event)},false);this._game.stage.canvas.addEventListener("touchend",function(event){return _this.onTouchEnd(event)},false);this._game.stage.canvas.addEventListener("touchenter",function(event){return _this.onTouchEnter(event)},false);this._game.stage.canvas.addEventListener("touchleave",function(event){return _this.onTouchLeave(event)},false);this._game.stage.canvas.addEventListener("touchcancel",function(event){return _this.onTouchCancel(event)},false);document.addEventListener("touchmove",function(event){return _this.consumeTouchMove(event)},false)};Touch.prototype.consumeTouchMove=function(event){event.preventDefault()};Touch.prototype.onTouchStart=function(event){event.preventDefault();for(var i=0;i>>0;h-=n;h*=n;n=h>>>0;h-=n;n+=h*4294967296}return(n>>>0)*2.3283064365386963e-10};RandomDataGenerator.prototype.sow=function(seeds){if(typeof seeds==="undefined"){seeds=[]}this.s0=this.hash(" ");this.s1=this.hash(this.s0);this.s2=this.hash(this.s1);var seed;for(var i=0;seed=seeds[i++];){this.s0-=this.hash(seed);this.s0+=~~(this.s0<0);this.s1-=this.hash(seed);this.s1+=~~(this.s1<0);this.s2-=this.hash(seed);this.s2+=~~(this.s2<0)}};Object.defineProperty(RandomDataGenerator.prototype,"integer",{get:function(){return this.uint32()},enumerable:true,configurable:true});Object.defineProperty(RandomDataGenerator.prototype,"frac",{get:function(){return this.fract32()},enumerable:true,configurable:true});Object.defineProperty(RandomDataGenerator.prototype,"real",{get:function(){return this.uint32()+this.fract32()},enumerable:true,configurable:true});RandomDataGenerator.prototype.integerInRange=function(min,max){return Math.floor(this.realInRange(min,max))};RandomDataGenerator.prototype.realInRange=function(min,max){min=min||0;max=max||0;return this.frac*(max-min)+min};Object.defineProperty(RandomDataGenerator.prototype,"normal",{get:function(){return 1-2*this.frac},enumerable:true,configurable:true});Object.defineProperty(RandomDataGenerator.prototype,"uuid",{get:function(){var a,b;for(b=a="";a++<36;b+=~a%5|a*3&4?(a^15?8^this.frac*(a^20?16:4):4).toString(16):"-"){}return b},enumerable:true,configurable:true});RandomDataGenerator.prototype.pick=function(array){return array[this.integerInRange(0,array.length)]};RandomDataGenerator.prototype.weightedPick=function(array){return array[~~(Math.pow(this.frac,2)*array.length)]};RandomDataGenerator.prototype.timestamp=function(min,max){if(typeof min==="undefined"){min=946684800000}if(typeof max==="undefined"){max=1577862000000}return this.realInRange(min,max)};Object.defineProperty(RandomDataGenerator.prototype,"angle",{get:function(){return this.integerInRange(-180,180)},enumerable:true,configurable:true});return RandomDataGenerator})();var Device=(function(){function Device(){this.desktop=false;this.iOS=false;this.android=false;this.chromeOS=false;this.linux=false;this.macOS=false;this.windows=false;this.canvas=false;this.file=false;this.fileSystem=false;this.localStorage=false;this.webGL=false;this.worker=false;this.touch=false;this.css3D=false;this.arora=false;this.chrome=false;this.epiphany=false;this.firefox=false;this.ie=false;this.ieVersion=0;this.mobileSafari=false;this.midori=false;this.opera=false;this.safari=false;this.webApp=false;this.audioData=false;this.webaudio=false;this.ogg=false;this.mp3=false;this.wav=false;this.m4a=false;this.iPhone=false;this.iPhone4=false;this.iPad=false;this.pixelRatio=0;this._checkAudio();this._checkBrowser();this._checkCSS3D();this._checkDevice();this._checkFeatures();this._checkOS()}Device.prototype._checkOS=function(){var ua=navigator.userAgent;if(/Android/.test(ua)){this.android=true}else{if(/CrOS/.test(ua)){this.chromeOS=true}else{if(/iP[ao]d|iPhone/i.test(ua)){this.iOS=true}else{if(/Linux/.test(ua)){this.linux=true}else{if(/Mac OS/.test(ua)){this.macOS=true}else{if(/Windows/.test(ua)){this.windows=true}}}}}}if(this.windows||this.macOS||this.linux){this.desktop=true}};Device.prototype._checkFeatures=function(){this.canvas=!!window.CanvasRenderingContext2D;try{this.localStorage=!!localStorage.getItem}catch(error){this.localStorage=false}this.file=!!window.File&&!!window.FileReader&&!!window.FileList&&!!window.Blob;this.fileSystem=!!window.requestFileSystem;this.webGL=!!window.WebGLRenderingContext;this.worker=!!window.Worker;if("ontouchstart" in document.documentElement||window.navigator.msPointerEnabled){this.touch=true}};Device.prototype._checkBrowser=function(){var ua=navigator.userAgent;if(/Arora/.test(ua)){this.arora=true}else{if(/Chrome/.test(ua)){this.chrome=true}else{if(/Epiphany/.test(ua)){this.epiphany=true}else{if(/Firefox/.test(ua)){this.firefox=true}else{if(/Mobile Safari/.test(ua)){this.mobileSafari=true}else{if(/MSIE (\d+\.\d+);/.test(ua)){this.ie=true;this.ieVersion=parseInt(RegExp.$1)}else{if(/Midori/.test(ua)){this.midori=true}else{if(/Opera/.test(ua)){this.opera=true}else{if(/Safari/.test(ua)){this.safari=true}}}}}}}}}if(navigator.standalone){this.webApp=true}};Device.prototype._checkAudio=function(){this.audioData=!!(window.Audio);this.webaudio=!!(window.webkitAudioContext||window.AudioContext);var audioElement=document.createElement("audio");var result=false;try{if(result=!!audioElement.canPlayType){if(audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,"")){this.ogg=true}if(audioElement.canPlayType("audio/mpeg;").replace(/^no$/,"")){this.mp3=true}if(audioElement.canPlayType('audio/wav; codecs="1"').replace(/^no$/,"")){this.wav=true}if(audioElement.canPlayType("audio/x-m4a;")||audioElement.canPlayType("audio/aac;").replace(/^no$/,"")){this.m4a=true}}}catch(e){}};Device.prototype._checkDevice=function(){this.pixelRatio=window.devicePixelRatio||1;this.iPhone=navigator.userAgent.toLowerCase().indexOf("iphone")!=-1;this.iPhone4=(this.pixelRatio==2&&this.iPhone);this.iPad=navigator.userAgent.toLowerCase().indexOf("ipad")!=-1};Device.prototype._checkCSS3D=function(){var el=document.createElement("p");var has3d;var transforms={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};document.body.insertBefore(el,null);for(var t in transforms){if(el.style[t]!==undefined){el.style[t]="translate3d(1px,1px,1px)";has3d=window.getComputedStyle(el).getPropertyValue(transforms[t])}}document.body.removeChild(el);this.css3D=(has3d!==undefined&&has3d.length>0&&has3d!=="none")};Device.prototype.getAll=function(){var output="";output=output.concat("Device\n");output=output.concat("iPhone : "+this.iPhone+"\n");output=output.concat("iPhone4 : "+this.iPhone4+"\n");output=output.concat("iPad : "+this.iPad+"\n");output=output.concat("\n");output=output.concat("Operating System\n");output=output.concat("iOS: "+this.iOS+"\n");output=output.concat("Android: "+this.android+"\n");output=output.concat("ChromeOS: "+this.chromeOS+"\n");output=output.concat("Linux: "+this.linux+"\n");output=output.concat("MacOS: "+this.macOS+"\n");output=output.concat("Windows: "+this.windows+"\n");output=output.concat("\n");output=output.concat("Browser\n");output=output.concat("Arora: "+this.arora+"\n");output=output.concat("Chrome: "+this.chrome+"\n");output=output.concat("Epiphany: "+this.epiphany+"\n");output=output.concat("Firefox: "+this.firefox+"\n");output=output.concat("Internet Explorer: "+this.ie+" ("+this.ieVersion+")\n");output=output.concat("Mobile Safari: "+this.mobileSafari+"\n");output=output.concat("Midori: "+this.midori+"\n");output=output.concat("Opera: "+this.opera+"\n");output=output.concat("Safari: "+this.safari+"\n");output=output.concat("\n");output=output.concat("Features\n");output=output.concat("Canvas: "+this.canvas+"\n");output=output.concat("File: "+this.file+"\n");output=output.concat("FileSystem: "+this.fileSystem+"\n");output=output.concat("LocalStorage: "+this.localStorage+"\n");output=output.concat("WebGL: "+this.webGL+"\n");output=output.concat("Worker: "+this.worker+"\n");output=output.concat("Touch: "+this.touch+"\n");output=output.concat("CSS 3D: "+this.css3D+"\n");output=output.concat("\n");output=output.concat("Audio\n");output=output.concat("Audio Data: "+this.canvas+"\n");output=output.concat("Web Audio: "+this.canvas+"\n");output=output.concat("Can play OGG: "+this.canvas+"\n");output=output.concat("Can play MP3: "+this.canvas+"\n");output=output.concat("Can play M4A: "+this.canvas+"\n");output=output.concat("Can play WAV: "+this.canvas+"\n");return output};return Device})();var Game=(function(){function Game(callbackContext,parent,width,height,initCallback,createCallback,updateCallback,renderCallback){if(typeof parent==="undefined"){parent=""}if(typeof width==="undefined"){width=800}if(typeof height==="undefined"){height=600}if(typeof initCallback==="undefined"){initCallback=null}if(typeof createCallback==="undefined"){createCallback=null}if(typeof updateCallback==="undefined"){updateCallback=null}if(typeof renderCallback==="undefined"){renderCallback=null}var _this=this;this._maxAccumulation=32;this._accumulator=0;this._step=0;this._loadComplete=false;this._paused=false;this._pendingState=null;this.onInitCallback=null;this.onCreateCallback=null;this.onUpdateCallback=null;this.onRenderCallback=null;this.onPausedCallback=null;this.isBooted=false;this.callbackContext=callbackContext;this.onInitCallback=initCallback;this.onCreateCallback=createCallback;this.onUpdateCallback=updateCallback;this.onRenderCallback=renderCallback;if(document.readyState==="complete"||document.readyState==="interactive"){this.boot(parent,width,height)}else{document.addEventListener("DOMContentLoaded",function(){return _this.boot(parent,width,height)},false)}}Game.VERSION="Phaser version 0.7";Game.prototype.boot=function(parent,width,height){var _this=this;if(!document.body){window.setTimeout(function(){return _this.boot(parent,width,height)},13)}else{this.device=new Device();this.stage=new Stage(this,parent,width,height);this.world=new World(this,width,height);this.sound=new SoundManager(this);this.cache=new Cache(this);this.loader=new Loader(this,this.loadComplete);this.time=new Time(this);this.input=new Input(this);this.math=new GameMath(this);this.rnd=new RandomDataGenerator([(Date.now()*Math.random()).toString()]);this.framerate=60;if(this.onInitCallback==null&&this.onCreateCallback==null&&this.onUpdateCallback==null&&this.onRenderCallback==null&&this._pendingState==null){this.isBooted=false;this.stage.drawInitScreen()}else{this.isBooted=true;this._loadComplete=false;this._raf=new RequestAnimationFrame(this.loop,this);if(this._pendingState){this.switchState(this._pendingState,false,false)}else{this.startState()}}}};Game.prototype.loadComplete=function(){this._loadComplete=true};Game.prototype.loop=function(){if(this._paused==true){if(this.onPausedCallback!==null){this.onPausedCallback.call(this.callbackContext)}return}this.time.update();this.input.update();this.stage.update();this._accumulator+=this.time.delta;if(this._accumulator>this._maxAccumulation){this._accumulator=this._maxAccumulation}while(this._accumulator>=this._step){this.time.elapsed=this.time.timeScale*(this._step/1000);this.world.update();this._accumulator=this._accumulator-this._step}if(this._loadComplete&&this.onUpdateCallback){this.onUpdateCallback.call(this.callbackContext)}this.world.render();if(this._loadComplete&&this.onRenderCallback){this.onRenderCallback.call(this.callbackContext)}};Game.prototype.startState=function(){if(this.onInitCallback!==null){this.onInitCallback.call(this.callbackContext)}else{if(this.onCreateCallback!==null){this.onCreateCallback.call(this.callbackContext)}this._loadComplete=true}};Game.prototype.setCallbacks=function(initCallback,createCallback,updateCallback,renderCallback){if(typeof initCallback==="undefined"){initCallback=null}if(typeof createCallback==="undefined"){createCallback=null}if(typeof updateCallback==="undefined"){updateCallback=null}if(typeof renderCallback==="undefined"){renderCallback=null}this.onInitCallback=initCallback;this.onCreateCallback=createCallback;this.onUpdateCallback=updateCallback;this.onRenderCallback=renderCallback};Game.prototype.switchState=function(state,clearWorld,clearCache){if(typeof clearWorld==="undefined"){clearWorld=true}if(typeof clearCache==="undefined"){clearCache=false}if(this.isBooted==false){this._pendingState=state;return}if(typeof state==="function"){state=new state(this)}if(state.create||state.update){this.callbackContext=state;this.onInitCallback=null;this.onCreateCallback=null;this.onUpdateCallback=null;this.onRenderCallback=null;this.onPausedCallback=null;if(state.init){this.onInitCallback=state.init}if(state.create){this.onCreateCallback=state.create}if(state.update){this.onUpdateCallback=state.update}if(state.render){this.onRenderCallback=state.render}if(state.paused){this.onPausedCallback=state.paused}if(clearWorld){this.world.destroy();if(clearCache==true){this.cache.destroy()}}this._loadComplete=false;this.startState()}else{throw Error("Invalid State object given. Must contain at least a create or update function.");return}};Game.prototype.destroy=function(){this.callbackContext=null;this.onInitCallback=null;this.onCreateCallback=null;this.onUpdateCallback=null;this.onRenderCallback=null;this.onPausedCallback=null;this.camera=null;this.cache=null;this.input=null;this.loader=null;this.sound=null;this.stage=null;this.time=null;this.math=null;this.world=null;this.isBooted=false};Object.defineProperty(Game.prototype,"pause",{get:function(){return this._paused},set:function(value){if(value==true&&this._paused==false){this._paused=true}else{if(value==false&&this._paused==true){this._paused=false;this.time.time=Date.now();this.input.reset()}}},enumerable:true,configurable:true});Object.defineProperty(Game.prototype,"framerate",{get:function(){return 1000/this._step},set:function(value){this._step=1000/value;if(this._maxAccumulation=this._timeNextFrame){this._frameIndex++;if(this._frameIndex==this._frames.length){if(this.looped){this._frameIndex=0;this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex])}else{this.onComplete()}}else{this.currentFrame=this._frameData.getFrame(this._frames[this._frameIndex])}this._timeLastFrame=this._game.time.now;this._timeNextFrame=this._game.time.now+this.delay;return true}return false};Animation.prototype.destroy=function(){this._game=null;this._parent=null;this._frames=null;this._frameData=null;this.currentFrame=null;this.isPlaying=false};return Animation})();var AnimationLoader=(function(){function AnimationLoader(){}AnimationLoader.parseSpriteSheet=function parseSpriteSheet(game,key,frameWidth,frameHeight,frameMax){var img=game.cache.getImage(key);if(img==null){return null}var width=img.width;var height=img.height;var row=Math.round(width/frameWidth);var column=Math.round(height/frameHeight);var total=row*column;if(frameMax!==-1){total=frameMax}if(width==0||height==0||widththis._frameData.total){return false}}};Animations.prototype.play=function(name,frameRate,loop){if(typeof frameRate==="undefined"){frameRate=null}if(this._anims[name]){this.currentAnim=this._anims[name];this.currentAnim.play(frameRate,loop)}};Animations.prototype.stop=function(name){if(this._anims[name]){this.currentAnim=this._anims[name];this.currentAnim.stop()}};Animations.prototype.update=function(){if(this.currentAnim&&this.currentAnim.update()==true){this.currentFrame=this.currentAnim.currentFrame;this._parent.bounds.width=this.currentFrame.width;this._parent.bounds.height=this.currentFrame.height}};Object.defineProperty(Animations.prototype,"frameTotal",{get:function(){return this._frameData.total},enumerable:true,configurable:true});Object.defineProperty(Animations.prototype,"frame",{get:function(){return this._frameIndex},set:function(value){this.currentFrame=this._frameData.getFrame(value);if(this.currentFrame!==null){this._parent.bounds.width=this.currentFrame.width;this._parent.bounds.height=this.currentFrame.height;this._frameIndex=value}},enumerable:true,configurable:true});return Animations})();var State=(function(){function State(game){this.game=game;this.camera=game.camera;this.cache=game.cache;this.input=game.input;this.loader=game.loader;this.sound=game.sound;this.stage=game.stage;this.time=game.time;this.math=game.math;this.world=game.world}State.prototype.init=function(){};State.prototype.create=function(){};State.prototype.update=function(){};State.prototype.render=function(){};State.prototype.paused=function(){};State.prototype.createCamera=function(x,y,width,height){return this.game.world.createCamera(x,y,width,height)};State.prototype.createSprite=function(x,y,key){if(typeof key==="undefined"){key=""}return this.game.world.createSprite(x,y,key)};State.prototype.createGroup=function(MaxSize){if(typeof MaxSize==="undefined"){MaxSize=0}return this.game.world.createGroup(MaxSize)};State.prototype.createParticle=function(){return this.game.world.createParticle()};State.prototype.createEmitter=function(x,y,size){if(typeof x==="undefined"){x=0}if(typeof y==="undefined"){y=0}if(typeof size==="undefined"){size=0}return this.game.world.createEmitter(x,y,size)};State.prototype.createTilemap=function(key,mapData,format,tileWidth,tileHeight){return this.game.world.createTilemap(key,mapData,format,tileWidth,tileHeight)};State.prototype.collide=function(ObjectOrGroup1,ObjectOrGroup2,NotifyCallback){if(typeof ObjectOrGroup1==="undefined"){ObjectOrGroup1=null}if(typeof ObjectOrGroup2==="undefined"){ObjectOrGroup2=null}if(typeof NotifyCallback==="undefined"){NotifyCallback=null}return this.game.world.overlap(ObjectOrGroup1,ObjectOrGroup2,NotifyCallback,World.separate)};return State})();var Tile=(function(_super){__extends(Tile,_super);function Tile(game,Tilemap,Index,Width,Height,Visible,AllowCollisions){_super.call(this,game,0,0,Width,Height);this.immovable=true;this.moves=false;this.callback=null;this.filter=null;this.tilemap=Tilemap;this.index=Index;this.visible=Visible;this.allowCollisions=AllowCollisions;this.mapIndex=0}Tile.prototype.destroy=function(){_super.prototype.destroy.call(this);this.callback=null;this.tilemap=null};return Tile})(GameObject);