/**
 * @license MelonJS Game Engine
 * @copyright (C) 2011 - 2014 Olivier Biot, Jason Oster, Aaron McLeod
 * http://www.melonjs.org
 *
 * melonJS is licensed under the MIT License.
 * http://www.opensource.org/licenses/mit-license.php
 * Demo URL: http://www.w3cschool.cc/games/flappybird/
 *
 */
window.me=window.me||{},function(a){function b(){if(!h){if(!e.body)return setTimeout(b,13);e.removeEventListener?e.removeEventListener("DOMContentLoaded",b,!1):a.removeEventListener("load",b,!1),h=!0;for(var c=0;c<i.length;c++)i[c].call(a,[]);i.length=0}}function c(){return g?void 0:(g=!0,"complete"===e.readyState?b():(e.addEventListener&&e.addEventListener("DOMContentLoaded",b,!1),void a.addEventListener("load",b,!1)))}function d(){f||(me.device._check(),me.save._init(),me.loader.setNocache(e.location.href.match(/\?nocache/)||!1),me.timer.init(),me.mapReader=new me.TMXMapReader,me.state.init(),me.pool.init(),me.levelDirector.reset(),f=!0)}var e=a.document;me={mod:"melonJS",version:"1.0.0"},"function"==typeof define&&define.amd&&define("me",[],function(){return me}),me.sys={fps:60,interpolation:!1,scale:null,scalingInterpolation:!1,gravity:void 0,stopOnAudioError:!0,pauseOnBlur:!0,resumeOnFocus:!0,stopOnBlur:!1,preRender:!1,checkVersion:function(a,b){b=b||me.version;for(var c=a.split("."),d=b.split("."),e=Math.min(c.length,d.length),f=0,g=0;e>g&&!(f=+c[g]-+d[g]);g++);return f?f:c.length-d.length}};var f=!1,g=!1,h=!1,i=[];a.onReady=function(b){return c(),h?b.call(a,[]):i.push(function(){return b.call(a,[])}),this},a.onReady(function(){d()});var j=!1,k=/var xyz/.test(function(){})?/\bparent\b/:/[\D|\d]*/;Object.defineProperty||(Object.defineProperty=function(a,b,c){if(!a.__defineGetter__)throw"melonJS: Object.defineProperty not supported";c.get&&a.__defineGetter__(b,c.get),c.set&&a.__defineSetter__(b,c.set)}),Object.defineProperty(Object.prototype,"mixin",{value:function(a){var b,c=this;for(b in a)a.hasOwnProperty(b)&&(c[b]=a[b]);return c},enumerable:!1,configurable:!1});var l=function(a){if(null==a||"object"!=typeof a)return a;var b;if(a instanceof Array){b=[],Object.setPrototypeOf(b,Object.getPrototypeOf(a));for(var c=0,d=a.length;d>c;c++)b[c]=l(a[c]);return b}if(a instanceof Date)return b=new Date,b.setTime(a.getTime()),b;b={},Object.setPrototypeOf(b,Object.getPrototypeOf(a));for(var e in a)a.hasOwnProperty(e)&&(b[e]=l(a[e]));return b};if(Object.extend=function(a){function b(a,b){return function(){var c=this.parent;this.parent=d[a];var e=b.apply(this,arguments);return this.parent=c,e}}function c(){if(!j){for(var a in this)"object"==typeof this[a]&&(this[a]=l(this[a]));this.init&&this.init.apply(this,arguments)}return this}var d=this.prototype;j=!0;var e=new this;j=!1;for(var f in a)e[f]="function"==typeof a[f]&&"function"==typeof d[f]&&k.test(a[f])?b(f,a[f]):a[f];return c.prototype=e,c.constructor=c,c.extend=Object.extend,c},"function"!=typeof Object.create&&(Object.create=function(a){var b=function(){};return b.prototype=a,new b}),!Function.prototype.bind){var m=function(){};Function.prototype.bind=function(a){var b=this;if("function"!=typeof b)throw new TypeError("Function.prototype.bind called on incompatible "+b);var c=Array.prototype.slice.call(arguments,1),d=function(){if(this instanceof d){var e=b.apply(this,c.concat(Array.prototype.slice.call(arguments)));return Object(e)===e?e:this}return b.apply(a,c.concat(Array.prototype.slice.call(arguments)))};return b.prototype&&(m.prototype=b.prototype,d.prototype=new m,m.prototype=null),d}}if(window.throttle||(window.throttle=function(a,b,c){var d,e=window.performance.now();return"boolean"!=typeof b&&(b=!1),function(){var f=window.performance.now(),g=f-e,h=arguments;return a>g?void(b===!1&&(clearTimeout(d),d=setTimeout(function(){return e=f,c.apply(null,h)},g))):(e=f,c.apply(null,h))}}),"undefined"==typeof Date.now&&(Date.now=function(){return(new Date).getTime()}),"undefined"==typeof window.performance&&(window.performance={}),!window.performance.now){var n=Date.now();window.performance.timing&&window.performance.timing.navigationStart&&(n=window.performance.timing.navigationStart),window.performance.now=function(){return Date.now()-n}}"undefined"==typeof console&&(console={log:function(){},info:function(){},error:function(){alert(Array.prototype.slice.call(arguments).join(", "))}}),Function.prototype.defer=function(){return setTimeout(this.bind.apply(this,arguments),.01)},Object.getPrototypeOf=Object.getPrototypeOf||function(a){return a.__proto__},Object.setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/gm,"")}),String.prototype.trimLeft||(String.prototype.trimLeft=function(){return this.replace(/^\s+/,"")}),String.prototype.trimRight||(String.prototype.trimRight=function(){return this.replace(/\s+$/,"")}),String.prototype.isNumeric=function(){return null!==this&&!isNaN(this)&&""!==this.trim()},String.prototype.isBoolean=function(){return null!==this&&("true"===this.trim()||"false"===this.trim())},String.prototype.contains||(String.prototype.contains=function(a,b){return-1!==String.prototype.indexOf.call(this,a,b)}),String.prototype.toHex=function(){for(var a="",b=0;b<this.length;)a+=this.charCodeAt(b++).toString(16);return a},Number.prototype.clamp=function(a,b){return a>this?a:this>b?b:+this},Number.prototype.random=function(a,b){return~~(Math.random()*(b-a+1))+a},Number.prototype.round=function(){var a=arguments.length<2?this:arguments[0],b=Math.pow(10,arguments[1]||arguments[0]||0);return Math.round(a*b)/b},Number.prototype.toHex=function(){return"0123456789ABCDEF".charAt(this-this%16>>4)+"0123456789ABCDEF".charAt(this%16)},Number.prototype.sign=function(){return 0>this?-1:this>0?1:0},Number.prototype.degToRad=function(a){return(a||this)/180*Math.PI},Number.prototype.radToDeg=function(a){return(a||this)*(180/Math.PI)},Array.prototype.remove=function(a){var b=Array.prototype.indexOf.call(this,a);return-1!==b&&Array.prototype.splice.call(this,b,1),this},Array.prototype.forEach||(Array.prototype.forEach=function(a,b){for(var c=0,d=this.length;d--;c++)a.call(b||this,this[c],c,this)}),Object.defineProperty(me,"initialized",{get:function(){return f}}),me.game=function(){var a={},b=null,c=!1,d=!0,e=0,f=1;return a.viewport=null,a.collisionMap=null,a.currentLevel=null,a.world=null,a.mergeGroup=!0,a.sortOn="z",a.renderer=null,a.NO_OBJECT=0,a.ENEMY_OBJECT=1,a.COLLECTABLE_OBJECT=2,a.ACTION_OBJECT=3,a.onLevelLoaded=null,a.init=function(e,f){c||(e=e||me.video.getWidth(),f=f||me.video.getHeight(),a.viewport=new me.Viewport(0,0,e,f),a.world=new me.ObjectContainer(0,0,e,f),a.world.name="rootContainer",b=me.video.getSystemContext(),me.event.publish(me.event.GAME_INIT),me.input.translatePointerEvents(),d=!0,a.currentLevel={pos:{x:0,y:0}},c=!0)},a.reset=function(){a.world.destroy(),a.viewport&&a.viewport.reset(),a.currentLevel={pos:{x:0,y:0}},b.setTransform(1,0,0,1,0,0),e=0,f=Math.round(60/me.sys.fps)},a.getParentContainer=function(a){return a.ancestor},a.collide=function(b,c){return a.world.collide(b,c)},a.collideType=function(b,c,d){return a.world.collideType(b,c,d)},a.repaint=function(){d=!0},a.update=function(b){++e%f===0&&(e=0,me.timer.update(b),d=a.world.update(me.timer.getDelta())||d,d=a.viewport.update(me.timer.getDelta())||d)},a.draw=function(){if(d){var c=a.viewport.pos.x+~~a.viewport.offset.x,e=a.viewport.pos.y+~~a.viewport.offset.y;a.world.transform.translate(-c,-e),a.viewport.screenX=c-a.currentLevel.pos.x,a.viewport.screenY=e-a.currentLevel.pos.y,a.world.draw(b,a.viewport),a.world.transform.translate(c,e),a.viewport.draw(b)}d=!1,me.video.blitSurface()},a}()}(window),function(a){me.device=function(){function b(a){a.reading?(d.accelerationX=a.reading.accelerationX,d.accelerationY=a.reading.accelerationY,d.accelerationZ=a.reading.accelerationZ):(d.accelerationX=a.accelerationIncludingGravity.x,d.accelerationY=a.accelerationIncludingGravity.y,d.accelerationZ=a.accelerationIncludingGravity.z)}function c(a){d.gamma=a.gamma,d.beta=a.beta,d.alpha=a.alpha}var d={},e=!1,f=!1,g=null;return d._check=function(){me.device.pointerEnabled=navigator.pointerEnabled||navigator.msPointerEnabled,navigator.maxTouchPoints=navigator.maxTouchPoints||navigator.msMaxTouchPoints||0,a.gesture=a.gesture||a.MSGesture,me.device.touch="createTouch"in document||"ontouchstart"in a||navigator.isCocoonJS||navigator.maxTouchPoints>0,me.device.isMobile=me.device.ua.match(/Android|iPhone|iPad|iPod|BlackBerry|Windows Phone|Mobi/i)||!1,me.device.hasAccelerometer="undefined"!=typeof a.DeviceMotionEvent||"undefined"!=typeof a.Windows&&"function"==typeof Windows.Devices.Sensors.Accelerometer,this.hasPointerLockSupport="pointerLockElement"in document||"mozPointerLockElement"in document||"webkitPointerLockElement"in document,this.hasPointerLockSupport&&(document.exitPointerLock=document.exitPointerLock||document.mozExitPointerLock||document.webkitExitPointerLock),a.DeviceOrientationEvent&&(me.device.hasDeviceOrientation=!0),this.hasFullScreenSupport=document.fullscreenEnabled||document.webkitFullscreenEnabled||document.msFullscreenEnabled||document.mozFullScreenEnabled,document.exitFullscreen=document.cancelFullScreen||document.exitFullscreen||document.webkitCancelFullScreen||document.webkitExitFullscreen||document.mozCancelFullScreen||document.msExitFullscreen,navigator.vibrate=navigator.vibrate||navigator.webkitVibrate||navigator.mozVibrate||navigator.msVibrate;try{d.localStorage=!!a.localStorage}catch(b){d.localStorage=!1}me.device._detectAudio()},d._detectAudio=function(){if(me.device.sound=!Howler.noAudio,me.device.sound){var a=new Audio;me.device.audioCodecs={mp3:!!a.canPlayType("audio/mpeg;").replace(/^no$/,""),opus:!!a.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/,""),ogg:!!a.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),wav:!!a.canPlayType('audio/wav; codecs="1"').replace(/^no$/,""),m4a:!!(a.canPlayType("audio/x-m4a;")||a.canPlayType("audio/aac;")).replace(/^no$/,""),mp4:!!(a.canPlayType("audio/x-mp4;")||a.canPlayType("audio/aac;")).replace(/^no$/,""),weba:!!a.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,"")}}},d.ua=navigator.userAgent,d.audioCodecs={},d.sound=!1,d.localStorage=!1,d.hasAccelerometer=!1,d.hasDeviceOrientation=!1,d.hasFullScreenSupport=!1,d.hasPointerLockSupport=!1,d.nativeBase64="function"==typeof a.atob,d.touch=!1,d.isMobile=!1,d.orientation=0,d.accelerationX=0,d.accelerationY=0,d.accelerationZ=0,d.gamma=0,d.beta=0,d.alpha=0,d.requestFullscreen=function(a){this.hasFullScreenSupport&&(a=a||me.video.getWrapper(),a.requestFullscreen=a.requestFullscreen||a.webkitRequestFullscreen||a.mozRequestFullScreen||a.msRequestFullscreen,a.requestFullscreen())},d.exitFullscreen=function(){this.hasFullScreenSupport&&document.exitFullscreen()},d.getPixelRatio=function(){if(null===g){var b=me.video.getScreenContext(),c=a.devicePixelRatio||1,d=b.webkitBackingStorePixelRatio||b.mozBackingStorePixelRatio||b.msBackingStorePixelRatio||b.oBackingStorePixelRatio||b.backingStorePixelRatio||1;g=c/d}return g},d.getStorage=function(a){switch(a=a||"local"){case"local":return me.save}throw"melonJS : storage type "+a+" not supported"},d.turnOnPointerLock=function(){if(this.hasPointerLockSupport){var a=me.video.getWrapper();if(me.device.ua.match(/Firefox/i)){var b=function(){(document.fullscreenElement||document.webkitFullscreenElement||document.msFullscreenElement||document.mozFullScreenElement)===a&&(document.removeEventListener("fullscreenchange",b),document.removeEventListener("mozfullscreenchange",b),a.requestPointerLock=a.requestPointerLock||a.mozRequestPointerLock||a.webkitRequestPointerLock,a.requestPointerLock())};document.addEventListener("fullscreenchange",b,!1),document.addEventListener("mozfullscreenchange",b,!1),me.device.requestFullscreen()}else a.requestPointerLock()}},d.turnOffPointerLock=function(){this.hasPointerLockSupport&&document.exitPointerLock()},d.watchAccelerometer=function(){if(me.device.hasAccelerometer){if(!e){if("undefined"==typeof Windows)a.addEventListener("devicemotion",b,!1);else{var c=Windows.Devices.Sensors.Accelerometer.getDefault();if(c){var d=c.minimumReportInterval,f=d>=16?d:25;c.reportInterval=f,c.addEventListener("readingchanged",b,!1)}}e=!0}return!0}return!1},d.unwatchAccelerometer=function(){if(e){if("undefined"==typeof Windows)a.removeEventListener("devicemotion",b,!1);else{var c=Windows.Device.Sensors.Accelerometer.getDefault();c.removeEventListener("readingchanged",b,!1)}e=!1}},d.watchDeviceOrientation=function(){return me.device.hasDeviceOrientation&&!f&&(a.addEventListener("deviceorientation",c,!1),f=!0),!1},d.unwatchDeviceOrientation=function(){f&&(a.removeEventListener("deviceorientation",c,!1),f=!1)},d.vibrate=function(a){navigator.vibrate&&navigator.vibrate(a)},d}(),Object.defineProperty(me.device,"isFullscreen",{get:function(){return me.device.hasFullScreenSupport?(document.fullscreenElement||document.webkitFullscreenElement||document.msFullscreenElement||document.mozFullScreenElement)===me.video.getWrapper():!1}})}(window),function(a){me.timer=function(){var b={},c=0,d=0,e=0,f=0,g=0,h=Math.ceil(1e3/me.sys.fps),i=1e3/me.sys.fps*1.25,j=[],k=0,l=function(a){for(var b=0,c=j.length;c>b;b++)if(j[b].timerId===a){j.splice(b,1);break}},m=function(a){for(var b=0,c=j.length;c>b;b++){var d=j[b];d.pauseable&&me.state.isPaused()||(d.elapsed+=a),d.elapsed>=d.delay&&(d.func.apply(this),d.repeat===!0?d.elapsed-=d.delay:me.timer.clearTimeout(d.timerId))}};return b.tick=1,b.fps=0,b.init=function(){b.reset(),f=e=0},b.reset=function(){e=f=a.performance.now(),g=0,d=0,c=0},b.setTimeout=function(a,b,c){return j.push({func:a,delay:b,elapsed:0,repeat:!1,timerId:++k,pauseable:c===!0||!0}),k},b.setInterval=function(a,b,c){return j.push({func:a,delay:b,elapsed:0,repeat:!0,timerId:++k,pauseable:c===!0||!0}),k},b.clearTimeout=function(a){l.defer(this,a)},b.clearInterval=function(a){l.defer(this,a)},b.getTime=function(){return f},b.getDelta=function(){return g},b.countFPS=function(){c++,d+=g,c%10===0&&(this.fps=(~~(1e3*c/d)).clamp(0,me.sys.fps),d=0,c=0)},b.update=function(a){return e=f,f=a,g=f-e,b.tick=g>i&&me.sys.interpolation?g/h:1,m(g),g},b}()}(window),function(){me.pool=function(){var a={},b={};return a.init=function(){a.register("me.ObjectEntity",me.ObjectEntity),a.register("me.CollectableEntity",me.CollectableEntity),a.register("me.LevelEntity",me.LevelEntity),a.register("me.Tween",me.Tween,!0),a.register("me.Color",me.Color,!0),a.register("me.Particle",me.Particle,!0)},a.register=function(a,c,d){return d?void(b[a.toLowerCase()]={"class":c,pool:[]}):void(b[a.toLowerCase()]={"class":c,pool:void 0})},a.pull=function(a){var c="string"==typeof a?a.toLowerCase():void 0,d=Array.prototype.slice.call(arguments);if(c&&b[c]){var e;if(!b[c].pool)return e=b[c]["class"],d[0]=e,new(e.bind.apply(e,d));var f,g=b[c];return e=g["class"],g.pool.length>0?(f=g.pool.pop(),"function"==typeof f.init&&f.init.apply(f,d.slice(1)),"function"==typeof f.onResetEvent&&f.onResetEvent.apply(f,d.slice(1))):(d[0]=e,f=new(e.bind.apply(e,d)),f.className=c),f}var h=arguments[3];return h&&h.gid&&h.image?new me.SpriteObject(h.x,h.y,h.image):(c&&console.error("Cannot instantiate entity of type '"+a+"': Class not found!"),null)},a.purge=function(){for(var a in b)b[a].pool=[]},a.push=function(a){var c=a.className;"undefined"!=typeof c&&b[c]&&b[c].pool.push(a)},a}()}(window),function(){me.Vector2d=Object.extend({x:0,y:0,init:function(a,b){this.x=a||0,this.y=b||0},set:function(a,b){return this.x=a,this.y=b,this},setZero:function(){return this.set(0,0)},setV:function(a){return this.x=a.x,this.y=a.y,this},add:function(a){return this.x+=a.x,this.y+=a.y,this},sub:function(a){return this.x-=a.x,this.y-=a.y,this},scale:function(a){return this.x*=a.x,this.y*=a.y,this},div:function(a){return this.x/=a,this.y/=a,this},abs:function(){return this.x<0&&(this.x=-this.x),this.y<0&&(this.y=-this.y),this},clamp:function(a,b){return new me.Vector2d(this.x.clamp(a,b),this.y.clamp(a,b))},clampSelf:function(a,b){return this.x=this.x.clamp(a,b),this.y=this.y.clamp(a,b),this},minV:function(a){return this.x=this.x<a.x?this.x:a.x,this.y=this.y<a.y?this.y:a.y,this},maxV:function(a){return this.x=this.x>a.x?this.x:a.x,this.y=this.y>a.y?this.y:a.y,this},floor:function(){return new me.Vector2d(~~this.x,~~this.y)},floorSelf:function(){return this.x=~~this.x,this.y=~~this.y,this},ceil:function(){return new me.Vector2d(Math.ceil(this.x),Math.ceil(this.y))},ceilSelf:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},negate:function(){return new me.Vector2d(-this.x,-this.y)},negateSelf:function(){return this.x=-this.x,this.y=-this.y,this},copy:function(a){return this.x=a.x,this.y=a.y,this},equals:function(a){return this.x===a.x&&this.y===a.y},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},normalize:function(){var a=this.length();if(a<Number.MIN_VALUE)return 0;var b=1/a;return this.x*=b,this.y*=b,a},dotProduct:function(a){return this.x*a.x+this.y*a.y},distance:function(a){return Math.sqrt((this.x-a.x)*(this.x-a.x)+(this.y-a.y)*(this.y-a.y))},angle:function(a){return Math.atan2(a.y-this.y,a.x-this.x)},clone:function(){return new me.Vector2d(this.x,this.y)},toString:function(){return"x:"+this.x+",y:"+this.y}})}(window),function(){me.Rect=Object.extend({pos:new me.Vector2d,rangeV:new me.Vector2d,width:0,height:0,hWidth:0,hHeight:0,shapeType:"Rectangle",init:function(a,b,c){this.pos.setV(a),this.rangeV.set(0,0),this.width=b,this.height=c,this.hWidth=~~(b/2),this.hHeight=~~(c/2),Object.defineProperty(this,"left",{get:function(){var a=this.pos.x,b=a+this.rangeV.x;return b>a?a:b},configurable:!0}),Object.defineProperty(this,"right",{get:function(){var a=this.pos.x+this.width,b=a+this.rangeV.x;return a>b?a:b},configurable:!0}),Object.defineProperty(this,"top",{get:function(){var a=this.pos.y,b=a+this.rangeV.y;return b>a?a:b},configurable:!0}),Object.defineProperty(this,"bottom",{get:function(){var a=this.pos.y+this.height,b=a+this.rangeV.y;return a>b?a:b},configurable:!0})},setShape:function(a,b,c){return this.pos.setV(a),this.resize(b,c),this},resize:function(a,b){return this.width=a,this.height=b,this.hWidth=~~(a/2),this.hHeight=~~(b/2),this},getBounds:function(a){return"undefined"!=typeof a?a.setShape(this.pos,this.width,this.height):this.clone()},clone:function(){return new me.Rect(this.pos,this.width,this.height)},translate:function(a,b){return this.pos.x+=a,this.pos.y+=b,this},translateV:function(a){return this.translate(a.x,a.y)},addV:function(a){return this.rangeV.setV(a),this},union:function(a){var b=Math.min(this.left,a.left),c=Math.min(this.top,a.top);return this.resize(Math.max(this.right,a.right)-b,Math.max(this.bottom,a.bottom)-c),this.pos.set(b,c),this},flipX:function(a){return this.pos.x=a-this.width-this.pos.x,this},flipY:function(a){return this.pos.y=a-this.height-this.pos.y,this},equals:function(a){return this.left===a.left&&this.right===a.right&&this.top===a.top&&this.bottom===a.bottom},overlaps:function(a){return this.left<a.right&&a.left<this.right&&this.top<a.bottom&&a.top<this.bottom},within:function(a){return a.contains(this)},contains:function(a){return a.left>=this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPointV:function(a){return this.containsPoint(a.x,a.y)},containsPoint:function(a,b){return a>=this.left&&a<=this.right&&b>=this.top&&b<=this.bottom},collideWithRectangle:function(a){var b=new me.Vector2d(0,0);if(this.overlaps(a)){var c=this.left+this.hWidth-a.left-a.hWidth,d=this.top+this.hHeight-a.top-a.hHeight;b.x=a.hWidth+this.hWidth-(0>c?-c:c),b.y=a.hHeight+this.hHeight-(0>d?-d:d),b.x<b.y?(b.y=0,b.x=0>c?-b.x:b.x):(b.x=0,b.y=0>d?-b.y:b.y)}return b},draw:function(a,b){a.strokeStyle=b||"red",a.strokeRect(this.left,this.top,this.width,this.height)}})}(window),function(){me.Ellipse=Object.extend({pos:new me.Vector2d,radius:new me.Vector2d,shapeType:"Ellipse",init:function(a,b,c){this.setShape(a,b,c)},setShape:function(a,b,c){return this.radius.set(b/2,c/2),this.pos.setV(a).add(this.radius),this},translate:function(a,b){return this.pos.x+=a,this.pos.y+=b,this},translateV:function(a){return this.pos.add(a),this},containsPointV:function(a){return this.containsPoint(a.x,a.y)},containsPoint:function(a,b){return a-=this.pos.x,b-=this.pos.y,a*a/(this.radius.x*this.radius.x)+b*b/(this.radius.y*this.radius.y)<=1},getBounds:function(a){return"undefined"!=typeof a?a.setShape(this.pos.clone().sub(this.radius),2*this.radius.x,2*this.radius.y):new me.Rect(this.pos.clone().sub(this.radius),2*this.radius.x,2*this.radius.y)},clone:function(){return new me.Ellipse(this.pos,2*this.radius.x,2*this.radius.y)},draw:function(a,b){a.save(),a.beginPath(),a.translate(this.pos.x-this.radius.x,this.pos.y-this.radius.y),a.scale(this.radius.x,this.radius.y),a.arc(1,1,1,0,2*Math.PI,!1),a.restore(),a.strokeStyle=b||"red",a.stroke()}})}(window),function(){me.PolyShape=Object.extend({pos:new me.Vector2d,points:null,closed:!1,shapeType:"PolyShape",init:function(a,b,c){this.setShape(a,b,c)},setShape:function(a,b,c){return this.pos.setV(a),this.points=b,this.closed=c===!0,this.getBounds(),this},translate:function(a,b){return this.pos.x+=a,this.pos.y+=b,this},translateV:function(a){return this.pos.add(a),this},containsPointV:function(a){return this.containsPoint(a.x,a.y)},containsPoint:function(a,b){for(var c=!1,d=this.pos.x,e=this.pos.y,f=this.points,g=f.length,h=0,i=g-1;g>h;i=h++){var j=f[h].y+e,k=f[h].x+d,l=f[i].y+e,m=f[i].x+d;j>b!=l>b&&(m-k)*(b-j)/(l-j)+k>a&&(c=!c)}return c},getBounds:function(a){var b=this.pos.clone(),c=0,d=0;return this.points.forEach(function(a){b.x=Math.min(b.x,a.x),b.y=Math.min(b.y,a.y),c=Math.max(c,a.x),d=Math.max(d,a.y)}),"undefined"!=typeof a?a.setShape(b,c-b.x,d-b.y):new me.Rect(b,c-b.x,d-b.y)},clone:function(){var a=[];return this.points.forEach(function(b){a.push(new me.Vector2d(b.x,b.y))}),new me.PolyShape(this.pos.clone(),a,this.closed)},draw:function(a,b){a.save(),a.translate(-this.pos.x,-this.pos.y),a.strokeStyle=b||"red",a.beginPath(),a.moveTo(this.points[0].x,this.points[0].y),this.points.forEach(function(b){a.lineTo(b.x,b.y),a.moveTo(b.x,b.y)}),this.closed===!0&&a.lineTo(this.points[0].x,this.points[0].y),a.stroke(),a.restore()}})}(window),function(){me.Matrix2d=Object.extend({a:1,b:0,c:0,d:1,e:0,f:0,init:function(a,b,c,d,e,f){this.set(a||1,b||0,c||0,d||1,e||0,f||0)},identity:function(){return this.set(1,0,0,1,0,0),this},set:function(a,b,c,d,e,f){return this.a=a,this.b=b,this.c=c,this.d=d,this.e="undefined"!=typeof e?e:this.e,this.f="undefined"!=typeof f?f:this.f,this},multiply:function(a,b,c,d,e,f){var g=this.a,h=this.b,i=this.c,j=this.d;return this.a=a*g+b*i,this.b=a*h+b*j,this.c=c*g+d*i,this.d=c*h+d*j,this.e=e*g+f*i+this.e,this.f=e*h+f*j+this.f,this},scale:function(a,b){return this.a*=a,this.d*=b,this.e*=a,this.f*=b,this},rotate:function(a){if(0!==a){var b=Math.cos(a),c=Math.sin(a),d=this.a,e=this.b,f=this.c,g=this.d,h=this.e,i=this.f;this.a=d*b-e*c,this.b=d*c+e*b,this.c=f*b-g*c,this.d=f*c+g*b,this.e=h*b-i*c,this.f=h*c+i*b}return this},translate:function(a,b){return this.e+=a,this.f+=b,this},translateV:function(a){return this.translate(a.x,a.y)},isIdentity:function(){return 1===this.a&&0===this.b&&0===this.c&&1===this.d&&0===this.e&&0===this.f},clone:function(){return new me.Matrix2d(this.a,this.b,this.c,this.d,this.e,this.f)}})}(window),function(){me.debug={renderCollisionMap:!1}}(window),function(){me.Renderable=me.Rect.extend({isRenderable:!0,GUID:void 0,visible:!0,inViewport:!1,alwaysUpdate:!1,updateWhenPaused:!1,isPersistent:!1,floating:!1,z:0,anchorPoint:new me.Vector2d,alpha:1,init:function(a,b,c){this.parent(a,b,c),this.anchorPoint.set(.5,.5),this.setOpacity(1)},getOpacity:function(){return this.alpha},setOpacity:function(a){"number"==typeof a&&(this.alpha=a.clamp(0,1))},update:function(){return!1},draw:function(a,b){this.parent(a,b)}})}(window),function(){me.SpriteObject=me.Renderable.extend({scale:new me.Vector2d,scaleFlag:!1,lastflipX:!1,lastflipY:!1,z:0,offset:new me.Vector2d,angle:0,_sourceAngle:0,image:null,flickering:!1,flickerDuration:0,flickercb:null,flickerState:!1,init:function(a,b,c,d,e){this.isSprite=!0,this.parent(new me.Vector2d(a,b),d||c.width,e||c.height),this.image=c,this.scale.set(1,1),this.lastflipX=this.lastflipY=!1,this.scaleFlag=!1,this.offset.set(0,0),this.visible=!0,this.isPersistent=!1,this.flickering=!1},setTransparency:function(a){a="#"===a.charAt(0)?a.substring(1,7):a,this.image=me.video.applyRGBFilter(this.image,"transparent",a.toUpperCase()).canvas},isFlickering:function(){return this.flickering},flicker:function(a,b){this.flickerDuration=a,this.flickerDuration<=0?(this.flickering=!1,this.flickercb=null):this.flickering||(this.flickercb=b,this.flickering=!0)},flipX:function(a){a!==this.lastflipX&&(this.lastflipX=a,this.scale.x=-this.scale.x,this.scaleFlag=1!==this.scale.x||1!==this.scale.y)},flipY:function(a){a!==this.lastflipY&&(this.lastflipY=a,this.scale.y=-this.scale.y,this.scaleFlag=1!==this.scale.x||1!==this.scale.y)},resize:function(a){a>0&&(this.scale.x=this.scale.x<0?-a:a,this.scale.y=this.scale.y<0?-a:a,this.scaleFlag=1!==this.scale.x||1!==this.scale.y)},update:function(a){return this.flickering?(this.flickerDuration-=a,this.flickerDuration<0&&(this.flickercb&&this.flickercb(),this.flicker(-1)),!0):!1},draw:function(a){if(!this.flickering||(this.flickerState=!this.flickerState,this.flickerState)){a.save(),a.globalAlpha*=this.getOpacity();var b=~~this.pos.x,c=~~this.pos.y,d=this.width,e=this.height,f=this.angle+this._sourceAngle;if(this.scaleFlag||0!==f){var g=d*this.anchorPoint.x,h=e*this.anchorPoint.y;a.translate(b+g,c+h),this.scaleFlag&&a.scale(this.scale.x,this.scale.y),0!==f&&a.rotate(f),0!==this._sourceAngle?(d=this.height,e=this.width,b=-h,c=-g):(b=-g,c=-h)}a.drawImage(this.image,this.offset.x,this.offset.y,d,e,b,c,d,e),a.restore()}},destroy:function(){this.onDestroyEvent.apply(this,arguments)},onDestroyEvent:function(){}}),me.AnimationSheet=me.SpriteObject.extend({spacing:0,margin:0,animationpause:!1,animationspeed:100,init:function(a,b,c,d,e,f,g,h,i){this.anim={},this.resetAnim=null,this.current=null,this.animationspeed=100,this.spacing=f||0,this.margin=g||0,this.parent(a,b,c,d,e,f,g),this.textureAtlas=null,this.atlasIndices=null,this.buildLocalAtlas(h||void 0,i||void 0),this.addAnimation("default",null),this.setCurrentAnimation("default")},buildLocalAtlas:function(a,b){if(void 0!==a)this.textureAtlas=a,this.atlasIndices=b;else{this.textureAtlas=[];for(var c=new me.Vector2d(~~((this.image.width-this.margin)/(this.width+this.spacing)),~~((this.image.height-this.margin)/(this.height+this.spacing))),d=0,e=c.x*c.y;e>d;d++)this.textureAtlas[d]={name:""+d,offset:new me.Vector2d(this.margin+(this.spacing+this.width)*(d%c.x),this.margin+(this.spacing+this.height)*~~(d/c.x)),width:this.width,height:this.height,hWidth:this.width/2,hHeight:this.height/2,angle:0}}},addAnimation:function(a,b,c){if(this.anim[a]={name:a,frame:[],idx:0,length:0,animationspeed:c||this.animationspeed,nextFrame:0},null==b){b=[];var d=0;this.textureAtlas.forEach(function(){b[d]=d++})}for(var e=0,f=b.length;f>e;e++)if("number"==typeof b[e])this.anim[a].frame[e]=this.textureAtlas[b[e]];else{if(null===this.atlasIndices)throw"melonjs: string parameters for addAnimation are only allowed for TextureAtlas ";this.anim[a].frame[e]=this.textureAtlas[this.atlasIndices[b[e]]]}this.anim[a].length=this.anim[a].frame.length},setCurrentAnimation:function(a,b){if(!this.anim[a])throw"melonJS: animation id '"+a+"' not defined";this.current=this.anim[a],this.resetAnim=b||null,this.setAnimationFrame(this.current.idx),this.current.nextFrame=this.current.animationspeed},isCurrentAnimation:function(a){return this.current.name===a},setAnimationFrame:function(a){this.current.idx=(a||0)%this.current.length;var b=this.current.frame[this.current.idx];this.offset=b.offset,this.width=b.width,this.height=b.height,this.hWidth=b.hWidth,this.hHeight=b.hHeight,this._sourceAngle=b.angle},getCurrentAnimationFrame:function(){return this.current.idx},update:function(a){if(!this.animationpause&&(this.current.nextFrame-=a,this.current.nextFrame<=0)){if(this.setAnimationFrame(++this.current.idx),0===this.current.idx&&this.resetAnim)if("string"==typeof this.resetAnim)this.setCurrentAnimation(this.resetAnim);else if("function"==typeof this.resetAnim&&this.resetAnim()===!1)return this.current.idx=this.current.length-1,this.setAnimationFrame(this.current.idx),this.parent(a),!1;return this.current.nextFrame=this.current.animationspeed,this.parent(a)||!0}return this.parent(a)}})}(window),function(){var a=-(Math.PI/2);me.TextureAtlas=Object.extend({format:null,texture:null,atlas:null,init:function(a,b){if(a&&a.meta){if(a.meta.app.contains("texturepacker"))if(this.format="texturepacker",void 0===b){var c=me.utils.getBasename(a.meta.image);if(this.texture=me.loader.getImage(c),null===this.texture)throw"melonjs: Atlas texture '"+c+"' not found"}else this.texture=b;if(a.meta.app.contains("ShoeBox")){if(!a.meta.exporter||!a.meta.exporter.contains("melonJS"))throw"melonjs: ShoeBox requires the JSON exporter : https://github.com/melonjs/melonJS/tree/master/media/shoebox_JSON_export.sbx";this.format="ShoeBox",this.texture=b}this.atlas=this.initFromTexturePacker(a)}if(null===this.atlas)throw"melonjs: texture atlas format not supported"},initFromTexturePacker:function(a){var b={};return a.frames.forEach(function(a){a.hasOwnProperty("filename")&&(b[a.filename]={frame:new me.Rect(new me.Vector2d(a.frame.x,a.frame.y),a.frame.w,a.frame.h),source:new me.Rect(new me.Vector2d(a.spriteSourceSize.x,a.spriteSourceSize.y),a.spriteSourceSize.w,a.spriteSourceSize.h),rotated:a.rotated===!0,trimmed:a.trimmed===!0})}),b},getTexture:function(){return this.texture},getRegion:function(b){var c=this.atlas[b];return c?{name:b,pos:c.source.pos.clone(),offset:c.frame.pos.clone(),width:c.frame.width,height:c.frame.height,hWidth:c.frame.width/2,hHeight:c.frame.height/2,angle:c.rotated===!0?a:0}:null},createSpriteFromName:function(a){var b=this.getRegion(a);if(b){var c=new me.SpriteObject(0,0,this.getTexture(),b.width,b.height);return c.offset.setV(b.offset),c._sourceAngle=b.angle,c}throw"melonjs: TextureAtlas - region for "+a+" not found"},createAnimationFromName:function(a){for(var b=[],c={},d=0;d<a.length;++d)if(b[d]=this.getRegion(a[d]),c[a[d]]=d,null==b[d])throw"melonjs: TextureAtlas - region for "+a[d]+" not found";return new me.AnimationSheet(0,0,this.texture,0,0,0,0,b,c)}})}(window),function(){var a=Math.min,b=Math.max;me.Viewport=me.Renderable.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},bounds:null,deadzone:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,screenX:0,screenY:0,init:function(a,b,c,d){this.parent(new me.Vector2d(a,b),c-a,d-b),this.bounds=new me.Rect(new me.Vector2d(-1/0,-1/0),1/0,1/0),this.offset=new me.Vector2d,this.target=null,this.follow_axis=this.AXIS.NONE,this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH,onComplete:null},this._fadeOut={color:null,duration:0,tween:null},this._fadeIn={color:null,duration:0,tween:null},this.setDeadzone(this.width/6,this.height/6)},_followH:function(c){var d=this.pos.x;return c.x-this.pos.x>this.deadzone.right?this.pos.x=~~a(c.x-this.deadzone.right,this.bounds.width-this.width):c.x-this.pos.x<this.deadzone.pos.x&&(this.pos.x=~~b(c.x-this.deadzone.pos.x,this.bounds.pos.x)),d!==this.pos.x},_followV:function(c){var d=this.pos.y;return c.y-this.pos.y>this.deadzone.bottom?this.pos.y=~~a(c.y-this.deadzone.bottom,this.bounds.height-this.height):c.y-this.pos.y<this.deadzone.pos.y&&(this.pos.y=~~b(c.y-this.deadzone.pos.y,this.bounds.pos.y)),d!==this.pos.y},reset:function(a,b){this.pos.x=a||0,this.pos.y=b||0,this.target=null,this.follow_axis=null},setDeadzone:function(a,b){null===this.deadzone&&(this.deadzone=new me.Rect(new me.Vector2d,0,0)),this.deadzone.pos.set(~~((this.width-a)/2),~~((this.height-b)/2-.25*b)),this.deadzone.resize(a,b),this.updateTarget()},setBounds:function(a,b,c,d){this.bounds.pos.set(a,b),this.bounds.resize(c,d)},follow:function(a,b){if(a instanceof me.ObjectEntity)this.target=a.pos;else{if(!(a instanceof me.Vector2d))throw"melonJS: invalid target for viewport.follow";this.target=a}this.follow_axis="undefined"==typeof b?this.AXIS.BOTH:b,this.updateTarget()
},move:function(a,b){this.moveTo(~~(this.pos.x+a),~~(this.pos.y+b))},moveTo:function(a,b){this.pos.x=(~~a).clamp(this.bounds.pos.x,this.bounds.width-this.width),this.pos.y=(~~b).clamp(this.bounds.pos.y,this.bounds.height-this.height),me.event.publish(me.event.VIEWPORT_ONCHANGE,[this.pos])},updateTarget:function(){var a=!1;if(this.target)switch(this.follow_axis){case this.AXIS.NONE:break;case this.AXIS.HORIZONTAL:a=this._followH(this.target);break;case this.AXIS.VERTICAL:a=this._followV(this.target);break;case this.AXIS.BOTH:a=this._followH(this.target),a=this._followV(this.target)||a}return a},update:function(a){var b=this.updateTarget();return this._shake.duration>0&&(this._shake.duration-=a,this._shake.duration<=0?(this._shake.duration=0,this.offset.setZero(),"function"==typeof this._shake.onComplete&&this._shake.onComplete()):((this._shake.axis===this.AXIS.BOTH||this._shake.axis===this.AXIS.HORIZONTAL)&&(this.offset.x=(Math.random()-.5)*this._shake.intensity),(this._shake.axis===this.AXIS.BOTH||this._shake.axis===this.AXIS.VERTICAL)&&(this.offset.y=(Math.random()-.5)*this._shake.intensity)),b=!0),b===!0&&me.event.publish(me.event.VIEWPORT_ONCHANGE,[this.pos]),(null!=this._fadeIn.tween||null!=this._fadeOut.tween)&&(b=!0),b},shake:function(a,b,c,d){this._shake.duration>0||(this._shake={intensity:a,duration:b,axis:c||this.AXIS.BOTH,onComplete:d})},fadeOut:function(a,b,c){this._fadeOut.color=me.pool.pull("me.Color").parseHex(a),this._fadeOut.color.alpha=1,this._fadeOut.duration=b||1e3,this._fadeOut.tween=me.pool.pull("me.Tween",this._fadeOut.color).to({alpha:0},this._fadeOut.duration).onComplete(c||null),this._fadeOut.tween.start()},fadeIn:function(a,b,c){this._fadeIn.color=me.pool.pull("me.Color").parseHex(a),this._fadeIn.color.alpha=0,this._fadeIn.duration=b||1e3,this._fadeIn.tween=me.pool.pull("me.Tween",this._fadeIn.color).to({alpha:1},this._fadeIn.duration).onComplete(c||null),this._fadeIn.tween.start()},getWidth:function(){return this.width},getHeight:function(){return this.height},focusOn:function(a){var b=a.getBounds();this.moveTo(a.pos.x+b.pos.x+b.hWidth,a.pos.y+b.pos.y+b.hHeight)},isVisible:function(a){return a.overlaps(this)},localToWorld:function(a,b){return new me.Vector2d(a,b).add(this.pos).sub(me.game.currentLevel.pos)},worldToLocal:function(a,b){return new me.Vector2d(a,b).sub(this.pos).add(me.game.currentLevel.pos)},draw:function(a){this._fadeIn.tween&&(me.video.clearSurface(a,this._fadeIn.color.toRGBA()),1===this._fadeIn.color.alpha&&(this._fadeIn.tween=null,me.pool.push(this._fadeIn.color),this._fadeIn.color=null)),this._fadeOut.tween&&(me.video.clearSurface(a,this._fadeOut.color.toRGBA()),0===this._fadeOut.color.alpha&&(this._fadeOut.tween=null,me.pool.push(this._fadeOut.color),this._fadeOut.color=null))}})}(window),function(){me.GUI_Object=me.SpriteObject.extend({isClickable:!0,updated:!1,init:function(a,b,c){this.parent(a,b,"string"==typeof c.image?me.loader.getImage(c.image):c.image,c.spritewidth,c.spriteheight),this.floating=!0,me.input.registerPointerEvent("mousedown",this,this.clicked.bind(this))},update:function(){return this.updated?(this.updated=!1,!0):!1},clicked:function(a){return this.isClickable?(this.updated=!0,this.onClick(a)):void 0},onClick:function(){return!1},onDestroyEvent:function(){me.input.releasePointerEvent("mousedown",this)}})}(window),function(){var a=function(a,b){a.ancestor&&a.ancestor.removeChildNow(a,b)},b=new me.Rect(new me.Vector2d,0,0),c=0;me.ObjectContainer=me.Renderable.extend({sortOn:"z",autoSort:!0,pendingSort:null,children:null,bounds:null,collidable:!0,transform:new me.Matrix2d,init:function(a,b,c,d){this.parent(new me.Vector2d(a||0,b||0),c||1/0,d||1/0),this.bounds=new me.Rect(new me.Vector2d(0,0),0,0),this.children=[],this.sortOn=me.game.sortOn,this.autoSort=!0,this.transform.identity()},addChild:function(a,b){"undefined"!=typeof a.ancestor?a.ancestor.removeChildNow(a):a.isRenderable&&(a.GUID=me.utils.createGUID()),"number"==typeof b&&(a.z=b),"undefined"==typeof a.z&&(a.z=1/0),a.ancestor=this,this.children.push(a),this.autoSort===!0&&this.sort()},addChildAt:function(a,b){if(!(b>=0&&b<this.children.length))throw"melonJS (me.ObjectContainer): Index ("+b+") Out Of Bounds for addChildAt()";"undefined"!=typeof a.ancestor?a.ancestor.removeChildNow(a):a.isRenderable&&(a.GUID=me.utils.createGUID()),a.ancestor=this,this.children.splice(b,0,a)},swapChildren:function(a,b){var c=this.getChildIndex(a),d=this.getChildIndex(b);if(-1===c||-1===d)throw"melonJS (me.ObjectContainer): "+a+" Both the supplied childs must be a child of the caller "+this;var e=a.z;a.z=b.z,b.z=e,this.children[c]=b,this.children[d]=a},getChildAt:function(a){if(a>=0&&a<this.children.length)return this.children[a];throw"melonJS (me.ObjectContainer): Index ("+a+") Out Of Bounds for getChildAt()"},getChildIndex:function(a){return this.children.indexOf(a)},hasChild:function(a){return this===a.ancestor},getChildByProp:function(a,b){function c(a,c){"string"==typeof a[c]?a[c].match(f)&&e.push(a):a[c]===b&&e.push(a)}for(var d,e=[],f=new RegExp(b,"i"),g=this.children.length;g--,d=this.children[g];)d instanceof me.ObjectContainer?(c(d,a),e=e.concat(d.getChildByProp(a,b))):c(d,a);return e},getChildByName:function(a){return this.getChildByProp("name",a)},getChildByGUID:function(a){var b=this.getChildByProp("GUID",a);return b.length>0?b[0]:null},getBounds:function(a){var b="undefined"!=typeof a?a:this.bounds;b.pos.set(1/0,1/0),b.resize(-1/0,-1/0);for(var c,d,e=this.children.length;e--,d=this.children[e];)d.isRenderable&&d.visible&&(c=d.getBounds(),null!==c&&b.union(c));return b},removeChild:function(b,c){b.ancestor&&a.defer(this,b,c)},removeChildNow:function(a,b){if(!this.hasChild(a))throw"melonJS (me.ObjectContainer): "+a+" The supplied child must be a child of the caller "+this;a.ancestor=void 0,b||("function"==typeof a.destroy&&a.destroy(),me.pool.push(a)),this.children.splice(this.getChildIndex(a),1)},setChildsProperty:function(a,b,c){for(var d,e=this.children.length;e--,d=this.children[e];)c===!0&&d instanceof me.ObjectContainer&&d.setChildsProperty(a,b,c),d[a]=b},moveUp:function(a){var b=this.getChildIndex(a);b-1>=0&&this.swapChildren(a,this.getChildAt(b-1))},moveDown:function(a){var b=this.getChildIndex(a);b+1<this.children.length&&this.swapChildren(a,this.getChildAt(b+1))},moveToTop:function(a){var b=this.getChildIndex(a);b>0&&(this.splice(0,0,this.splice(b,1)[0]),a.z=this.children[1].z+1)},moveToBottom:function(a){var b=this.getChildIndex(a);b<this.children.length-1&&(this.splice(this.children.length-1,0,this.splice(b,1)[0]),a.z=this.children[this.children.length-2].z-1)},collide:function(a,b){return this.collideType(a,null,b)},collideType:function(a,b,c){var d,e;c=c===!0?!0:!1,c===!0&&(e=[]);for(var f,g=this.children.length;g--,f=this.children[g];)if((f.inViewport||f.alwaysUpdate)&&f.collidable)if(f instanceof me.ObjectContainer){if(d=f.collideType(a,b,c),c)e.concat(d);else if(d)return d}else if(f!==a&&(!b||f.type===b)&&(this._boundsA=f.getBounds(this._boundsA).translateV(f.pos),this._boundsB=a.getBounds(this._boundsB).translateV(a.pos),d=this._boundsA["collideWith"+this._boundsB.shapeType].call(this._boundsA,this._boundsB),0!==d.x||0!==d.y)){if(f.onCollision.call(f,d,a),d.type=f.type,d.obj=f,!c)return d;e.push(d)}return c?e:null},sort:function(a){if(null===this.pendingSort){if(a===!0)for(var b,c=this.children.length;c--,b=this.children[c];)b instanceof me.ObjectContainer&&b.sort(a);this.pendingSort=function(a){a.children.sort(a["_sort"+a.sortOn.toUpperCase()]),a.pendingSort=null,me.game.repaint()}.defer(this,this)}},_sortZ:function(a,b){return b.z-a.z},_sortX:function(a,b){var c=b.z-a.z;return c?c:(b.pos&&b.pos.x)-(a.pos&&a.pos.x)||0},_sortY:function(a,b){var c=b.z-a.z;return c?c:(b.pos&&b.pos.y)-(a.pos&&a.pos.y)||0},destroy:function(){this.pendingSort&&(clearTimeout(this.pendingSort),this.pendingSort=null);for(var a,b=this.children.length;b--,a=this.children[b];)a.isPersistent||this.removeChildNow(a);this.transform.identity()},update:function(a){for(var d,e,f,g,h=!1,i=!1,j=me.state.isPaused(),k=me.game.viewport,l=this.children.length;l--,g=this.children[l];)(!j||g.updateWhenPaused)&&(g.isRenderable?(i=c>0||g.floating,i&&c++,d=g.visible&&!i,d&&(e=g.pos.x,f=g.pos.y,b.translateV(g.pos),b.resize(g.width,g.height)),g.inViewport=g.visible&&(i||k.isVisible(b)),h|=(g.inViewport||g.alwaysUpdate)&&g.update(a),d&&b.translate(-e,-f),c>0&&c--):h|=g.update(a));return h},draw:function(a,b){var c=me.game.viewport,d=!1;this.drawCount=0,a.save(),a.transform(this.transform.a,this.transform.b,this.transform.c,this.transform.d,this.transform.e,this.transform.f),a.globalAlpha*=this.getOpacity(),a.translate(this.pos.x,this.pos.y);for(var e,f=this.children.length;f--,e=this.children[f];)d=e.floating,(e.inViewport||d&&e.visible)&&e.isRenderable&&(d===!0&&(a.save(),a.translate(c.screenX-this.pos.x,c.screenY-this.pos.y)),e.draw(a,b),d===!0&&a.restore(),this.drawCount++);a.restore()}})}(window),function(){me.ObjectSettings={name:null,image:null,transparent_color:null,spritewidth:null,spriteheight:null,type:0,collidable:!0},me.ObjectEntity=me.Renderable.extend({type:0,collidable:!0,shapes:[],shapeIndex:0,renderable:null,lastflipX:!1,lastflipY:!1,init:function(a,b,c){if(this.parent(this.pos.set(a,b),c.width,c.height),c.image){var d="string"==typeof c.image?me.loader.getImage(c.image):c.image;this.renderable=new me.AnimationSheet(0,0,d,~~c.spritewidth,~~c.spriteheight,~~c.spacing,~~c.margin),c.transparent_color&&this.renderable.setTransparency(c.transparent_color)}this.name=c.name?c.name.toLowerCase():"",void 0===this.vel&&(this.vel=new me.Vector2d),this.vel.set(0,0),void 0===this.accel&&(this.accel=new me.Vector2d),this.accel.set(0,0),void 0===this.friction&&(this.friction=new me.Vector2d),this.friction.set(0,0),void 0===this.maxVel&&(this.maxVel=new me.Vector2d),this.maxVel.set(1e3,1e3),this.gravity=void 0!==me.sys.gravity?me.sys.gravity:.98,this.alive=!0,this.falling=!1,this.jumping=!0,this.slopeY=0,this.onslope=!1,this.onladder=!1,this.disableTopLadderCollision=!1,this.collidable="undefined"!=typeof c.collidable?c.collidable:!0,this.type=c.type||0,this.lastflipX=this.lastflipY=!1,this.collisionMap=me.game.collisionMap,this.canBreakTile=!1,this.onTileBreak=null,"function"==typeof c.getShape&&(this.addShape(c.getShape()),"PolyShape"===this.getShape().shapeType&&(this._bounds=this.getBounds(),this.resize(this._bounds.width,this._bounds.height)))},addShape:function(a){this.shapes.push(a)},getShape:function(){return this.shapes[this.shapeIndex]},setShape:function(a){if("undefined"!=typeof this.shapes[a])return void(this.shapeIndex=a);throw"melonJS (me.Entity): Shape ("+a+") not defined"},onCollision:function(){this.collidable&&this.type===me.game.COLLECTABLE_OBJECT&&me.game.world.removeChild(this)},setVelocity:function(a,b){this.accel.x=0!==a?a:this.accel.x,this.accel.y=0!==b?b:this.accel.y,this.setMaxVelocity(a,b)},setMaxVelocity:function(a,b){this.maxVel.x=a,this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0,this.friction.y=b||0},flipX:function(a){a!==this.lastflipX&&(this.lastflipX=a,this.renderable&&this.renderable.flipX&&this.renderable.flipX(a),this.getShape().flipX&&this.getShape().flipX(this.width))},flipY:function(a){a!==this.lastflipY&&(this.lastflipY=a,this.renderable&&this.renderable.flipY&&this.renderable.flipY(a),this.getShape().flipY&&this.getShape().flipY(this.height))},distanceTo:function(a){var b=this.pos.x+this.hWidth-(a.pos.x+a.hWidth),c=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+c*c)},distanceToPoint:function(a){var b=this.pos.x+this.hWidth-a.x,c=this.pos.y+this.hHeight-a.y;return Math.sqrt(b*b+c*c)},angleTo:function(a){var b=a.pos.x+a.hWidth-(this.pos.x+this.hWidth),c=a.pos.y+a.hHeight-(this.pos.y+this.hHeight);return Math.atan2(c,b)},angleToPoint:function(a){var b=a.x-(this.pos.x+this.hWidth),c=a.y-(this.pos.y+this.hHeight);return Math.atan2(c,b)},checkSlope:function(a,b,c){a.pos.y=b.pos.y-a.height,this.slopeY=c?b.height-(a.right+this.vel.x-b.pos.x):a.left+this.vel.x-b.pos.x,this.vel.y=0,a.pos.y+=this.slopeY.clamp(0,b.height)},computeVelocity:function(a){this.gravity&&(a.y+=this.onladder?0:this.gravity*me.timer.tick,this.falling=a.y>0,this.jumping=this.falling?!1:this.jumping),this.friction.x&&(a.x=me.utils.applyFriction(a.x,this.friction.x)),this.friction.y&&(a.y=me.utils.applyFriction(a.y,this.friction.y)),0!==a.y&&(a.y=a.y.clamp(-this.maxVel.y,this.maxVel.y)),0!==a.x&&(a.x=a.x.clamp(-this.maxVel.x,this.maxVel.x))},updateMovement:function(){this.computeVelocity(this.vel);var a;return this.collidable&&(this._bounds=this.getBounds(this._bounds),this.__offsetX=this._bounds.pos.x,this.__offsetY=this._bounds.pos.y,this._bounds.translateV(this.pos),a=this.collisionMap.checkCollision(this._bounds,this.vel),this.onslope=a.yprop.isSlope||a.xprop.isSlope,this.onladder=!1,a.y&&(this.onladder=a.yprop.isLadder||a.yprop.isTopLadder,a.y>0?a.yprop.isSolid||a.yprop.isPlatform&&this._bounds.bottom-1<=a.ytile.pos.y||a.yprop.isTopLadder&&!this.disableTopLadderCollision?(this._bounds.pos.y=~~this._bounds.pos.y,this.vel.y=this.falling?a.ytile.pos.y-this._bounds.bottom:0,this.falling=!1):a.yprop.isSlope&&!this.jumping?(this.checkSlope(this._bounds,a.ytile,a.yprop.isLeftSlope),this.falling=!1):a.yprop.isBreakable&&(this.canBreakTile?(me.game.currentLevel.clearTile(a.ytile.col,a.ytile.row),this.onTileBreak&&this.onTileBreak()):(this.collision.pos.y=~~this.collision.pos.y,this.vel.y=this.falling?a.ytile.pos.y-this._bounds.bottom:0,this.falling=!1)):a.y<0&&(a.yprop.isPlatform||a.yprop.isLadder||a.yprop.isTopLadder||(this.falling=!0,this.vel.y=0))),a.x&&(this.onladder=a.xprop.isLadder||a.yprop.isTopLadder,a.xprop.isSlope&&!this.jumping?(this.checkSlope(this._bounds,a.xtile,a.xprop.isLeftSlope),this.falling=!1):a.xprop.isPlatform||a.xprop.isLadder||a.xprop.isTopLadder||(a.xprop.isBreakable&&this.canBreakTile?(me.game.currentLevel.clearTile(a.xtile.col,a.xtile.row),this.onTileBreak&&this.onTileBreak()):this.vel.x=0)),this.pos.set(this._bounds.pos.x-this.__offsetX,this._bounds.pos.y-this.__offsetY)),this.pos.add(this.vel),a},collide:function(a){return me.game.collide(this,a||!1)},collideType:function(a,b){return me.game.collideType(this,a,b||!1)},update:function(a){return this.renderable?this.renderable.update(a):!1},getBounds:function(a){return this.shapes.length?this.getShape().getBounds(a):this.parent(a).translate(-this.pos.x,-this.pos.y)},draw:function(a){if(this.renderable){var b=this;this.shapes.length&&"PolyShape"===this.getShape().shapeType&&(b=this.getBounds(this._bounds).translateV(this.pos));var c=~~(b.pos.x+this.anchorPoint.x*(b.width-this.renderable.width)),d=~~(b.pos.y+this.anchorPoint.y*(b.height-this.renderable.height));a.translate(c,d),this.renderable.draw(a),a.translate(-c,-d)}},destroy:function(){this.renderable&&(this.renderable.destroy.apply(this.renderable,arguments),this.renderable=null),this.onDestroyEvent.apply(this,arguments),this.shapes=[],this.shapeIndex=0},onDestroyEvent:function(){}}),me.CollectableEntity=me.ObjectEntity.extend({init:function(a,b,c){this.parent(a,b,c),this.type=me.game.COLLECTABLE_OBJECT}}),me.LevelEntity=me.ObjectEntity.extend({init:function(a,b,c){this.parent(a,b,c),this.nextlevel=c.to,this.fade=c.fade,this.duration=c.duration,this.fading=!1,this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel),me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel,this.fade&&this.duration?this.fading||(this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))):me.levelDirector.loadLevel(this.gotolevel)},onCollision:function(){this.goTo()}})}(window),function(a){me.ScreenObject=me.Renderable.extend({init:function(){this.parent(new me.Vector2d(0,0),0,0)},reset:function(){me.game.reset(),this.onResetEvent.apply(this,arguments)},destroy:function(){this.onDestroyEvent.apply(this,arguments)},onResetEvent:function(){},onDestroyEvent:function(){}}),function(){for(var a=0,b=["ms","moz","webkit","o"],c=window.requestAnimationFrame,d=window.cancelAnimationFrame,e=0;e<b.length&&(!c||!d);++e)c=window[b[e]+"RequestAnimationFrame"],d=window[b[e]+"CancelAnimationFrame"]||window[b[e]+"CancelRequestAnimationFrame"];c&&d||(c=function(b){var c=window.performance.now(),d=Math.max(0,16-(c-a)),e=window.setTimeout(function(){b(c+d)},d);return a=c+d,e},d=function(a){window.clearTimeout(a)}),window.requestAnimationFrame=c,window.cancelAnimationFrame=d}(),me.state=function(){function b(){-1===j&&-1!==i&&(me.timer.reset(),j=window.requestAnimationFrame(e))}function c(){k&&-1!==i&&(me.timer.reset(),k=!1)}function d(){k=!0}function e(a){me.game.update(a),me.game.draw(),-1!==j&&(j=window.requestAnimationFrame(e))}function f(){window.cancelAnimationFrame(j),j=-1}function g(a){f(),l[i]&&l[i].screen.destroy(),l[a]&&(i=a,l[i].screen.reset.apply(l[i].screen,o),b(),n&&n(),me.game.repaint())}var h={},i=-1,j=-1,k=!1,l={},m={color:"",duration:0},n=null,o=null,p=0;return h.LOADING=0,h.MENU=1,h.READY=2,h.PLAY=3,h.GAMEOVER=4,h.GAME_END=5,h.SCORE=6,h.CREDITS=7,h.SETTINGS=8,h.USER=100,h.onPause=null,h.onResume=null,h.onStop=null,h.onRestart=null,h.init=function(){h.set(h.LOADING,new me.DefaultLoadingScreen),a.addEventListener("blur",function(){i!==h.LOADING&&(me.sys.stopOnBlur&&(h.stop(!0),h.onStop&&h.onStop()),me.sys.pauseOnBlur&&(h.pause(!0),h.onPause&&h.onPause()))},!1),a.addEventListener("focus",function(){i!==h.LOADING&&(me.sys.resumeOnFocus&&(h.resume(!0),h.onResume&&h.onResume()),me.sys.stopOnBlur&&(h.restart(!0),me.game.repaint(),h.onRestart&&h.onRestart()))},!1)},h.stop=function(a){f(),a&&me.audio.pauseTrack(),p=window.performance.now(),me.event.publish(me.event.STATE_STOP)},h.pause=function(a){d(),a&&me.audio.pauseTrack(),p=window.performance.now(),me.event.publish(me.event.STATE_PAUSE)},h.restart=function(a){b(),a&&me.audio.resumeTrack(),p=window.performance.now()-p,me.event.publish(me.event.STATE_RESTART,[p])},h.resume=function(a){c(),a&&me.audio.resumeTrack(),p=window.performance.now()-p,me.event.publish(me.event.STATE_RESUME,[p])},h.isRunning=function(){return-1!==j},h.isPaused=function(){return k},h.set=function(a,b){l[a]={},l[a].screen=b,l[a].transition=!0},h.current=function(){return l[i].screen},h.transition=function(a,b,c){"fade"===a&&(m.color=b,m.duration=c)},h.setTransition=function(a,b){l[a].transition=b},h.change=function(a){if("undefined"==typeof l[a])throw"melonJS : Undefined ScreenObject for state '"+a+"'";o=null,arguments.length>1&&(o=Array.prototype.slice.call(arguments,1)),m.duration&&l[a].transition?(n=function(){me.game.viewport.fadeOut(m.color,m.duration)},me.game.viewport.fadeIn(m.color,m.duration,function(){g.defer(this,a)})):g.defer(this,a)},h.isCurrent=function(a){return i===a},h}()}(window),function(){var a=me.Renderable.extend({invalidate:!1,barHeight:4,progress:0,onProgressUpdate:function(a){this.progress=Math.floor(a*this.width),this.invalidate=!0},update:function(){return this.invalidate===!0?(this.invalidate=!1,!0):!1},draw:function(a){a.fillStyle="black",a.fillRect(0,this.height/2-this.barHeight/2,this.width,this.barHeight),a.fillStyle="#55aa00",a.fillRect(2,this.height/2-this.barHeight/2,this.progress,this.barHeight)}}),b=me.Renderable.extend({init:function(a,b){this.parent(new me.Vector2d(a,b),100,85)},draw:function(a){a.save(),a.translate(this.pos.x,this.pos.y),a.beginPath(),a.moveTo(.7,48.9),a.bezierCurveTo(10.8,68.9,38.4,75.8,62.2,64.5),a.bezierCurveTo(86.1,53.1,97.2,27.7,87,7.7),a.lineTo(87,7.7),a.bezierCurveTo(89.9,15.4,73.9,30.2,50.5,41.4),a.bezierCurveTo(27.1,52.5,5.2,55.8,.7,48.9),a.lineTo(.7,48.9),a.lineTo(.7,48.9),a.closePath(),a.fillStyle="rgb(255, 255, 255)",a.fill(),a.beginPath(),a.moveTo(84,7),a.bezierCurveTo(87.6,14.7,72.5,30.2,50.2,41.6),a.bezierCurveTo(27.9,53,6.9,55.9,3.2,48.2),a.bezierCurveTo(-.5,40.4,14.6,24.9,36.9,13.5),a.bezierCurveTo(59.2,2.2,80.3,-.8,84,7),a.lineTo(84,7),a.closePath(),a.lineWidth=5.3,a.strokeStyle="rgb(255, 255, 255)",a.lineJoin="miter",a.miterLimit=4,a.stroke(),a.restore()}}),c=me.Renderable.extend({init:function(a,b){this.parent(new me.Vector2d,a,b),this.logo1=new me.Font("century gothic",32,"white","middle"),this.logo2=new me.Font("century gothic",32,"#55aa00","middle"),this.logo2.bold(),this.logo1.textBaseline=this.logo2.textBaseline="alphabetic"},draw:function(a){var b=this.logo1.measureText(a,"w3cschool").width,c=(this.width-b-this.logo2.measureText(a,".cc").width)/2,d=this.height/2+this.logo2.measureText(a,"w3cschool").height;this.logo1.draw(a,"w3cschool",c,d),c+=b,this.logo2.draw(a,".cc",c,d)}});me.DefaultLoadingScreen=me.ScreenObject.extend({onResetEvent:function(){me.game.reset(),me.game.world.addChild(new me.ColorLayer("background","#202020",0));var d=new a(new me.Vector2d,me.video.getWidth(),me.video.getHeight());this.handle=me.event.subscribe(me.event.LOADER_PROGRESS,d.onProgressUpdate.bind(d)),me.game.world.addChild(d,1);var e=new b((me.video.getWidth()-100)/2,me.video.getHeight()/2-d.barHeight/2-90);me.game.world.addChild(e,1),me.game.world.addChild(new c(me.video.getWidth(),me.video.getHeight()),1)},onDestroyEvent:function(){this.handle&&(me.event.unsubscribe(this.handle),this.handle=null)}})}(window),function(){me.loader=function(){function a(){l===k?f.onload?(clearTimeout(m),setTimeout(function(){f.onload(),me.event.publish(me.event.LOADER_COMPLETE)},300)):console.error("no load callback defined"):m=setTimeout(a,100)}function b(a,b,c){g[a.name]=new Image,g[a.name].onload=b,g[a.name].onerror=c,g[a.name].src=a.src+f.nocache}function c(a,b,c){function d(b,c){h[a.name]={data:b,isTMX:"tmx"===a.type,format:c}}if("tmx"===a.type&&me.levelDirector.addTMXLevel(a.name),a.data)return d(a.data,a.format),void b();var e=new XMLHttpRequest,g=me.utils.getFileExtension(a.src).toLowerCase();e.overrideMimeType&&e.overrideMimeType("json"===g?"application/json":"text/xml"),e.open("GET",a.src+f.nocache,!0),e.ontimeout=c,e.onreadystatechange=function(){if(4===e.readyState)if(200===e.status||0===e.status&&e.responseText){var a=null;switch(g){case"xml":case"tmx":a=me.device.ua.match(/msie/i)||!e.responseXML?(new DOMParser).parseFromString(e.responseText,"text/xml"):e.responseXML,g="xml";break;case"json":a=JSON.parse(e.responseText);break;default:throw"melonJS: TMX file format "+g+"not supported !"}d(a,g),b()}else c()},e.send(null)}function d(a,b,c){var d=new XMLHttpRequest;d.overrideMimeType&&d.overrideMimeType("application/json"),d.open("GET",a.src+f.nocache,!0),d.ontimeout=c,d.onreadystatechange=function(){4===d.readyState&&(200===d.status||0===d.status&&d.responseText?(j[a.name]=JSON.parse(d.responseText),b()):c())},d.send(null)}function e(a,b,c){var d=new XMLHttpRequest;d.open("GET",a.src+f.nocache,!0),d.responseType="arraybuffer",d.onerror=c,d.onload=function(){var c=d.response;if(c){for(var e=new Uint8Array(c),f=[],g=0;g<e.byteLength;g++)f[g]=String.fromCharCode(e[g]);i[a.name]=f.join(""),b()}},d.send()}var f={},g={},h={},i={},j={},k=0,l=0,m=0;return f.nocache="",f.onload=void 0,f.onProgress=void 0,f.onResourceLoaded=function(a){l++;var b=f.getLoadProgress();f.onProgress&&f.onProgress(b,a),me.event.publish(me.event.LOADER_PROGRESS,[b,a])},f.onLoadingError=function(a){throw"melonJS: Failed loading resource "+a.src},f.setNocache=function(a){f.nocache=a?"?"+parseInt(1e7*Math.random(),10):""},f.preload=function(b){for(var c=0;c<b.length;c++)k+=f.load(b[c],f.onResourceLoaded.bind(f,b[c]),f.onLoadingError.bind(f,b[c]));a()},f.load=function(a,f,g){switch(a.name=a.name.toLowerCase(),a.type){case"binary":return e.call(this,a,f,g),1;case"image":return b.call(this,a,f,g),1;case"json":return d.call(this,a,f,g),1;case"tmx":case"tsx":return c.call(this,a,f,g),1;case"audio":return me.audio.load(a,f,g),1;default:throw"melonJS: me.loader.load : unknown or invalid resource type : "+a.type}return 0},f.unload=function(a){switch(a.name=a.name.toLowerCase(),a.type){case"binary":return a.name in i?(delete i[a.name],!0):!1;case"image":return a.name in g?("function"==typeof g[a.name].dispose&&g[a.name].dispose(),delete g[a.name],!0):!1;case"json":return a.name in j?(delete j[a.name],!0):!1;case"tmx":case"tsx":return a.name in h?(delete h[a.name],!0):!1;case"audio":return me.audio.unload(a.name);default:throw"melonJS: me.loader.unload : unknown or invalid resource type : "+a.type}},f.unloadAll=function(){var a;for(a in i)f.unload({name:a,type:"binary"});for(a in g)f.unload({name:a,type:"image"});for(a in h)f.unload({name:a,type:"tmx"});for(a in j)f.unload({name:a,type:"json"});me.audio.unloadAll()},f.getTMXFormat=function(a){return a=a.toLowerCase(),a in h?h[a].format:null},f.getTMX=function(a){return a=a.toLowerCase(),a in h?h[a].data:null},f.getBinary=function(a){return a=a.toLowerCase(),a in i?i[a]:null},f.getImage=function(a){return a=a.toLowerCase(),a in g?g[a]:null},f.getJSON=function(a){return a=a.toLowerCase(),a in j?j[a]:null},f.getLoadProgress=function(){return l/k},f}()}(window),function(){me.Font=me.Renderable.extend({font:new me.Vector2d,fontSize:new me.Vector2d,fillStyle:"#000000",strokeStyle:"#000000",lineWidth:1,textAlign:"left",textBaseline:"top",lineHeight:1,init:function(a,b,c,d){this.setFont(a,b,c,d),this.parent(this.pos,0,this.fontSize.y)},bold:function(){this.font="bold "+this.font},italic:function(){this.font="italic "+this.font},setFont:function(a,b,c,d){var e=a.split(",").map(function(a){return a=a.trim(),/(^".*"$)|(^'.*'$)/.test(a)?a:'"'+a+'"'});this.fontSize.y=parseInt(b,10),this.height=this.fontSize.y,"number"==typeof b&&(b+="px"),this.font=b+" "+e.join(","),this.fillStyle=c,d&&(this.textAlign=d)},measureText:function(a,b){a.font=this.font,a.fillStyle=this.fillStyle,a.textAlign=this.textAlign,a.textBaseline=this.textBaseline,this.height=this.width=0;for(var c=(""+b).split("\n"),d=0;d<c.length;d++)this.width=Math.max(a.measureText(c[d].trimRight()).width,this.width),this.height+=this.fontSize.y*this.lineHeight;return{width:this.width,height:this.height}},draw:function(a,b,c,d){this.pos.set(c,d),a.font=this.font,a.fillStyle=this.fillStyle,a.textAlign=this.textAlign,a.textBaseline=this.textBaseline;for(var e=(""+b).split("\n"),f=0;f<e.length;f++)a.fillText(e[f].trimRight(),~~c,~~d),d+=this.fontSize.y*this.lineHeight},drawStroke:function(a,b,c,d){this.pos.set(c,d),a.font=this.font,a.fillStyle=this.fillStyle,a.strokeStyle=this.strokeStyle,a.lineWidth=this.lineWidth,a.textAlign=this.textAlign,a.textBaseline=this.textBaseline;for(var e=(""+b).split("\n"),f=0;f<e.length;f++){var g=e[f].trimRight();a.strokeText(g,~~c,~~d),a.fillText(g,~~c,~~d),d+=this.fontSize.y*this.lineHeight}}}),me.BitmapFont=me.Font.extend({sSize:new me.Vector2d,firstChar:32,charCount:0,init:function(a,b,c,d){this.parent(a,null,null),this.firstChar=d||32,this.loadFontMetrics(a,b),this.textAlign="left",this.textBaseline="top",c&&this.resize(c)},loadFontMetrics:function(a,b){this.font=me.loader.getImage(a),this.fontSize.x=b.x||b,this.fontSize.y=b.y||this.font.height,this.sSize.copy(this.fontSize),this.height=this.sSize.y,this.charCount=~~(this.font.width/this.fontSize.x)},set:function(a,b){this.textAlign=a,b&&this.resize(b)},resize:function(a){this.sSize.setV(this.fontSize),this.sSize.x*=a,this.sSize.y*=a,this.height=this.sSize.y},measureText:function(a,b){var c=(""+b).split("\n");this.height=this.width=0;for(var d=0;d<c.length;d++)this.width=Math.max(c[d].trimRight().length*this.sSize.x,this.width),this.height+=this.sSize.y*this.lineHeight;return{width:this.width,height:this.height}},draw:function(a,b,c,d){var e=(""+b).split("\n"),f=c,g=this.sSize.y*this.lineHeight;this.pos.set(c,d);for(var h=0;h<e.length;h++){c=f;var i=e[h].trimRight(),j=i.length*this.sSize.x;switch(this.textAlign){case"right":c-=j;break;case"center":c-=.5*j}switch(this.textBaseline){case"middle":d-=.5*g;break;case"ideographic":case"alphabetic":case"bottom":d-=g}for(var k=0,l=i.length;l>k;k++){var m=i.charCodeAt(k)-this.firstChar;m>=0&&a.drawImage(this.font,this.fontSize.x*(m%this.charCount),this.fontSize.y*~~(m/this.charCount),this.fontSize.x,this.fontSize.y,~~c,~~d,this.sSize.x,this.sSize.y),c+=this.sSize.x}d+=g}}})}(window),function(){me.audio=function(){function a(a,b){if(g++>3){var d="melonJS: failed loading "+a;if(me.sys.stopOnAudioError!==!1)throw d;me.audio.disable(),b&&b(),console.log(d+", disabling audio")}else c[a].load()}var b={},c={},d={},e=null,f=null,g=0,h=!1,i=[];return b.init=function(a){if(!me.initialized)throw"melonJS: me.audio.init() called before engine initialization.";a="string"==typeof a?a:"mp3",this.audioFormats=a.split(",")},b.enable=function(){this.unmuteAll()},b.disable=function(){this.muteAll()},b.load=function(e,f,j){if(me.device.isMobile&&!navigator.isCocoonJS){if(h)return void i.push([e,f,j]);h=!0}for(var k=[],l=0;l<this.audioFormats.length;l++)k.push(e.src+e.name+"."+this.audioFormats[l]+me.loader.nocache);var m=new Howl({urls:k,volume:Howler.volume(),onend:function(a){d[a]&&(d[a](),d[a]=null)},onloaderror:function(){a.call(me.audio,e.name,j)},onload:function(){h=!1;var a=i.shift();a&&b.load.apply(b,a),g=0,f&&f()}});return c[e.name]=m,1},b.play=function(a,b,e,f){var g=c[a.toLowerCase()];return g&&"undefined"!=typeof g?(g.loop(b||!1),g.volume("number"==typeof f?f.clamp(0,1):Howler.volume()),"function"==typeof e?g.play(function(a){d[a]=e}):g.play(),g):void 0},b.stop=function(a){var b=c[a.toLowerCase()];b&&"undefined"!=typeof b&&b.stop()},b.pause=function(a){var b=c[a.toLowerCase()];b&&"undefined"!=typeof b&&b.pause()},b.playTrack=function(a,b){f=me.audio.play(a,!0,null,b),e=a.toLowerCase()},b.stopTrack=function(){f&&(f.pause(),e=null,f=null)},b.setVolume=function(a){Howler.volume(a)},b.getVolume=function(){return Howler.volume()},b.mute=function(a,b){b=void 0===b?!0:!!b;var d=c[a.toLowerCase()];d&&"undefined"!=typeof d&&d.mute(!0)},b.unmute=function(a){b.mute(a,!1)},b.muteAll=function(){Howler.mute()},b.unmuteAll=function(){Howler.unmute()},b.getCurrentTrack=function(){return e},b.pauseTrack=function(){f&&f.pause()},b.resumeTrack=function(){f&&f.play()},b.unload=function(a){return a=a.toLowerCase(),a in c?(e===a?b.stopTrack():b.stop(a),c[a].unload(),delete c[a],!0):!1},b.unloadAll=function(){for(var a in c)b.unload(a)},b}()}(window),function(){me.video=function(){var a={},b=null,c=null,d=null,e=null,f=null,g=-1,h=!1,i=0,j=0,k=!1,l=!0,m=1/0,n=1/0;return a.init=function(g,m,n,o,p,q){if(!me.initialized)throw"melonJS: me.video.init() called before engine initialization.";if(h=o||!1,k="auto"===p||!1,l=void 0!==q?q:!0,p="auto"!==p?parseFloat(p||1):1,me.sys.scale=new me.Vector2d(p,p),(k||1!==p)&&(h=!0),i=m*me.sys.scale.x,j=n*me.sys.scale.y,window.addEventListener("resize",throttle(100,!1,function(a){me.event.publish(me.event.WINDOW_ONRESIZE,[a])}),!1),window.addEventListener("orientationchange",function(a){me.event.publish(me.event.WINDOW_ONORIENTATION_CHANGE,[a])},!1),me.event.subscribe(me.event.WINDOW_ONRESIZE,me.video.onresize.bind(me.video)),me.event.subscribe(me.event.WINDOW_ONORIENTATION_CHANGE,me.video.onresize.bind(me.video)),b=a.createCanvas(i,j,!0),g&&(f=document.getElementById(g)),f||(f=document.body),f.appendChild(b),!b.getContext)return!1;if(c=a.getContext2d(b),me.device.getPixelRatio()>1&&(b.style.width=b.width/me.device.getPixelRatio()+"px",b.style.height=b.height/me.device.getPixelRatio()+"px"),h?(d=a.createCanvas(m,n,!1),e=a.getContext2d(d)):(d=b,e=c),window.getComputedStyle){var r=window.getComputedStyle(b,null);me.video.setMaxSize(parseInt(r.maxWidth,10),parseInt(r.maxHeight,10))}return me.video.onresize(null),me.game.init(),!0},a.getWrapper=function(){return f},a.getWidth=function(){return d.width},a.getPos=function(a){return a=a||b,a.getBoundingClientRect?a.getBoundingClientRect():{left:0,top:0}},a.getHeight=function(){return d.height},a.setMaxSize=function(a,b){m=a||1/0,n=b||1/0},a.createCanvas=function(a,b,c){if(0===a||0===b)throw new Error("melonJS: width or height was zero, Canvas could not be initialized !");var e=document.createElement("canvas");return c===!0&&navigator.isCocoonJS&&(e.screencanvas=!0),e.width=a||d.width,e.height=b||d.height,e
},a.getContext2d=function(a){var b;return b=navigator.isCocoonJS?a.getContext("2d",{antialias:me.sys.scalingInterpolation}):a.getContext("2d"),b.canvas||(b.canvas=a),me.video.setImageSmoothing(b,me.sys.scalingInterpolation),b},a.getScreenCanvas=function(){return b},a.getScreenContext=function(){return c},a.getSystemCanvas=function(){return d},a.getSystemContext=function(){return e},a.onresize=function(){var a=1,b=1;if(me.device.orientation="undefined"!=typeof window.orientation?window.orientation:window.outerWidth>window.outerHeight?90:0,k){var c=me.video.getScreenCanvas().parentNode,d=Math.min(m,c.width||window.innerWidth),e=Math.min(n,c.height||window.innerHeight);if(l){var f=me.video.getWidth()/me.video.getHeight(),h=d/e;a=b=f>h?d/me.video.getWidth():e/me.video.getHeight()}else a=d/me.video.getWidth(),b=e/me.video.getHeight();if(a*=me.device.getPixelRatio(),b*=me.device.getPixelRatio(),1!==a||1!==b)return g>=0&&clearTimeout(g),void(g=me.video.updateDisplaySize.defer(this,a,b))}me.input.offset=me.video.getPos()},a.updateDisplaySize=function(e,f){me.sys.scale.set(e,f),b.width=i=d.width*e,b.height=j=d.height*f,me.device.getPixelRatio()>1&&(b.style.width=b.width/me.device.getPixelRatio()+"px",b.style.height=b.height/me.device.getPixelRatio()+"px"),me.video.setImageSmoothing(c,me.sys.scalingInterpolation),me.input.offset=me.video.getPos(),a.blitSurface(),g=-1},a.clearSurface=function(a,b){var c=a.canvas;a.save(),a.setTransform(1,0,0,1,0,0),a.fillStyle=b,a.fillRect(0,0,c.width,c.height),a.restore()},a.setImageSmoothing=function(a,b){for(var c=["ms","moz","webkit","o"],d=0;d<c.length;++d)void 0!==a[c[d]+"ImageSmoothingEnabled"]&&(a[c[d]+"ImageSmoothingEnabled"]=b===!0);a.imageSmoothingEnabled=b===!0},a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"},a.blitSurface=function(){a.blitSurface=h?function(){c.drawImage(d,0,0,d.width,d.height,0,0,i,j)}:function(){},a.blitSurface()},a.applyRGBFilter=function(b,c,d){var e,f,g=a.getContext2d(a.createCanvas(b.width,b.height,!1)),h=me.utils.getPixels(b),i=h.data;switch(c){case"b&w":for(e=0,f=i.length;f>e;e+=4){var j=3*i[e]+4*i[e+1]+i[e+2]>>>3;i[e]=j,i[e+1]=j,i[e+2]=j}break;case"brightness":var k=Math.abs(d).clamp(0,1);for(e=0,f=i.length;f>e;e+=4)i[e]*=k,i[e+1]*=k,i[e+2]*=k;break;case"transparent":var l=me.pool.pull("me.Color").parseHex(d),m=me.pool.pull("me.Color");for(e=0,f=i.length;f>e;e+=4)m.setColor(i[e],i[e+1],i[e+2]),m.equals(l)&&(i[e+3]=0);me.pool.push(l),me.pool.push(m);break;default:return null}return g.putImageData(h,0,0),g},a}()}(window),function(a){me.input=function(){function b(){u||(a.addEventListener("keydown",f,!1),a.addEventListener("keyup",g,!1),u=!0)}function c(a,b){for(var c=2;c<a.length;++c)void 0!==a[c]&&me.video.getScreenCanvas().addEventListener(a[c],b,!1)}function d(){v||(m.changedTouches.push({x:0,y:0}),m.mouse.pos=new me.Vector2d(0,0),m.offset=me.video.getPos(),a.addEventListener("scroll",throttle(100,!1,function(a){m.offset=me.video.getPos(),me.event.publish(me.event.WINDOW_ONSCROLL,[a])}),!1),y=a.navigator.pointerEnabled?B:a.navigator.msPointerEnabled?C:me.device.touch?A:z,c(y,l),w="onwheel"in document.createElement("div")?"wheel":"mousewheel",a.addEventListener(w,j,!1),void 0===m.throttlingInterval&&(m.throttlingInterval=Math.floor(1e3/me.sys.fps)),m.throttlingInterval<17?me.video.getScreenCanvas().addEventListener(y[D],k,!1):me.video.getScreenCanvas().addEventListener(y[D],throttle(m.throttlingInterval,!1,function(a){k(a)}),!1),v=!0)}function e(a){return a.stopPropagation?a.stopPropagation():a.cancelBubble=!0,a.preventDefault?a.preventDefault():a.returnValue=!1,!1}function f(a,b,c){b=b||a.keyCode||a.which;var d=n[b];if(me.event.publish(me.event.KEYDOWN,[d,b,d?!q[d]:!0]),d){if(!q[d]){var f=c?c:b;r[d][f]||(o[d]++,r[d][f]=!0)}return s[b]?e(a):!0}return!0}function g(a,b,c){b=b||a.keyCode||a.which;var d=n[b];if(me.event.publish(me.event.KEYUP,[d,b]),d){var f=c?c:b;return r[d][f]=void 0,o[d]>0&&o[d]--,q[d]=!1,e(a)}return!0}function h(a){var b=!1,c=t[a.type];if(c||(c=y.indexOf(a.type)===G?t[y[F]]:t[a.type]),c)for(var d=me.game.viewport.localToWorld(0,0),e=0,f=m.changedTouches.length;f>e;e++){if("undefined"!=typeof a.timeStamp){if(a.timeStamp<x)continue;x=a.timeStamp}me.device.pointerEnabled||(a.pointerId=m.changedTouches[e].id),a.gameScreenX=m.changedTouches[e].x,a.gameScreenY=m.changedTouches[e].y,a.gameWorldX=a.gameScreenX+d.x,a.gameWorldY=a.gameScreenY+d.y;for(var g,h=c.length;h--,g=c[h];)if(g.floating===!0?(a.gameX=a.gameScreenX,a.gameY=a.gameScreenY):(a.gameX=a.gameWorldX,a.gameY=a.gameWorldY),g.bounds.containsPoint(a.gameX-g.rect.pos.x,a.gameY-g.rect.pos.y)&&g.cb(a)===!1){b=!0;break}}return b}function i(a){var b;if(m.changedTouches.length=0,a.touches)for(var c=0,d=a.changedTouches.length;d>c;c++){var e=a.changedTouches[c];b=m.globalToLocal(e.clientX,e.clientY),b.id=e.identifier,m.changedTouches.push(b)}else b=m.globalToLocal(a.clientX,a.clientY),b.id=a.pointerId||1,m.changedTouches.push(b);a.isPrimary!==!1&&m.mouse.pos.set(m.changedTouches[0].x,m.changedTouches[0].y)}function j(a){if(a.target===me.video.getScreenCanvas()){var b={deltaMode:1,type:"mousewheel",deltaX:a.deltaX,deltaY:a.deltaY,deltaZ:a.deltaZ};if("mousewheel"===w&&(b.deltaY=-1/40*a.wheelDelta,a.wheelDeltaX&&(b.deltaX=-1/40*a.wheelDeltaX)),h(b))return e(a)}return!0}function k(a){return i(a),h(a)?e(a):!0}function l(a){if(i(a),h(a))return e(a);var b=a.button||0,c=m.mouse.bind[b];return c?a.type===y[E]?f(a,c,b+1):g(a,c,b+1):!0}var m={},n={},o={},p={},q={},r={},s={},t={},u=!1,v=!1,w="mousewheel",x=0,y=null,z=["mousewheel","mousemove","mousedown","mouseup",void 0,"click","dblclick"],A=[void 0,"touchmove","touchstart","touchend","touchcancel","tap","dbltap"],B=["mousewheel","pointermove","pointerdown","pointerup","pointercancel",void 0,void 0],C=["mousewheel","MSPointerMove","MSPointerDown","MSPointerUp","MSPointerCancel",void 0,void 0],D=1,E=2,F=3,G=4;return m.mouse={pos:null,LEFT:0,MIDDLE:1,RIGHT:2,bind:[0,0,0]},m.offset=null,m.throttlingInterval=void 0,m.changedTouches=[],m.preventDefault=!0,m.KEY={TAB:9,ENTER:13,SHIFT:16,CTRL:17,ALT:18,PAUSE:19,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,NUM0:48,NUM1:49,NUM2:50,NUM3:51,NUM4:52,NUM5:53,NUM6:54,NUM7:55,NUM8:56,NUM9:57,A:65,B:66,C:67,D:68,E:69,F:70,G:71,H:72,I:73,J:74,K:75,L:76,M:77,N:78,O:79,P:80,Q:81,R:82,S:83,T:84,U:85,V:86,W:87,X:88,Y:89,Z:90,MULTIPLY:106,ADD:107,SUBSTRACT:109,DECIMAL:110,DIVIDE:111,PLUS:187,COMMA:188,MINUS:189,PERIOD:190},m.isKeyPressed=function(a){return o[a]&&!q[a]?(p[a]&&(q[a]=!0),!0):!1},m.keyStatus=function(a){return o[a]>0},m.triggerKeyEvent=function(a,b){b?f({},a):g({},a)},m.bindKey=function(a,c,d,e){b(),"boolean"!=typeof e&&(e=me.input.preventDefault),n[a]=c,s[a]=e,o[c]=0,p[c]=d?d:!1,q[c]=!1,r[c]={}},m.unlockKey=function(a){q[a]=!1},m.unbindKey=function(a){o[n[a]]=0,p[n[a]]=!1,r[n[a]]={},n[a]=null,s[a]=null},m.globalToLocal=function(a,b){var c=m.offset,d=me.device.getPixelRatio();a-=c.left,b-=c.top;var e=me.sys.scale;return(1!==e.x||1!==e.y)&&(a/=e.x,b/=e.y),new me.Vector2d(a*d,b*d)},m.bindMouse=function(a,b){if(d(),!n[b])throw"melonJS : no action defined for keycode "+b;m.mouse.bind[a]=b},m.unbindMouse=function(a){m.mouse.bind[a]=null},m.bindTouch=function(a){m.bindMouse(me.input.mouse.LEFT,a)},m.unbindTouch=function(){m.unbindMouse(me.input.mouse.LEFT)},m.registerPointerEvent=function(a,b,c,e){if(d(),-1!==z.indexOf(a)&&(me.device.touch||me.device.pointerEnabled)&&(a=y[z.indexOf(a)]),a&&-1!==y.indexOf(a)){t[a]||(t[a]=[]);var f=b.floating===!0?!0:!1;e&&(f=e===!0?!0:!1);var g=b.getBounds();return"undefined"==typeof b.getShape&&g.translate(-b.pos.x,-b.pos.y),void t[a].push({rect:b,bounds:g,cb:c,floating:f})}throw"melonJS : invalid event type : "+a},m.releasePointerEvent=function(a,b){-1!==z.indexOf(a)&&(me.device.touch||me.device.pointerEnabled)&&(a=y[z.indexOf(a)]);{if(!a||-1===y.indexOf(a))throw"melonJS : invalid event type : "+a;t[a]||(t[a]=[]);var c=t[a];if(c)for(var d,e=c.length;e--,d=c[e];)d.rect===b&&(d.rect=d.bounds=d.cb=d.floating=null,t[a].splice(e,1))}},m.translatePointerEvents=function(){m.registerPointerEvent("mousemove",me.game.viewport,function(a){return me.event.publish(me.event.MOUSEMOVE,[a]),!1})},m}()}(window),function(a){var b=function(){var b={},c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";return b.decode=function(b){if(b=b.replace(/[^A-Za-z0-9\+\/\=]/g,""),me.device.nativeBase64)return a.atob(b);for(var d,e,f,g,h,i,j,k=[],l=0;l<b.length;)g=c.indexOf(b.charAt(l++)),h=c.indexOf(b.charAt(l++)),i=c.indexOf(b.charAt(l++)),j=c.indexOf(b.charAt(l++)),d=g<<2|h>>4,e=(15&h)<<4|i>>2,f=(3&i)<<6|j,k.push(String.fromCharCode(d)),64!==i&&k.push(String.fromCharCode(e)),64!==j&&k.push(String.fromCharCode(f));return k=k.join("")},b}();me.utils=function(){var a={},c="",d=0,e=/^.*(\\|\/|\:)/,f=/\.[^\.]*$/;return a.decodeBase64=function(a){return b.decode(a)},a.decodeBase64AsArray=function(a,c){c=c||1;var d,e,f,g,h=b.decode(a);for(g="function"==typeof window.Uint32Array?new Uint32Array(h.length/c):[],d=0,f=h.length/c;f>d;d++)for(g[d]=0,e=c-1;e>=0;--e)g[d]+=h.charCodeAt(d*c+e)<<(e<<3);return g},a.decompress=function(){throw"melonJS: GZIP/ZLIB compressed TMX Tile Map not supported!"},a.decodeCSV=function(a,b){a=a.trim().split("\n");for(var c=[],d=0;d<a.length;d++)for(var e=a[d].split(",",b),f=0;f<e.length;f++)c.push(+e[f]);return c},a.getBasename=function(a){return a.replace(e,"").replace(f,"")},a.getFileExtension=function(a){return a.substring(a.lastIndexOf(".")+1,a.length)},a.getPixels=function(a){if(a instanceof HTMLImageElement){var b=me.video.getContext2d(me.video.createCanvas(a.width,a.height));return b.drawImage(a,0,0),b.getImageData(0,0,a.width,a.height)}return a.getContext("2d").getImageData(0,0,a.width,a.height)},a.resetGUID=function(a){c=a.toString().toUpperCase().toHex(),d=0},a.createGUID=function(){return c+"-"+d++},a.applyFriction=function(a,b){return 0>a+b?a+b*me.timer.tick:a-b>0?a-b*me.timer.tick:0},a}()}(window),function(){var a={black:[0,0,0],silver:[192,192,129],gray:[128,128,128],white:[255,255,255],maroon:[128,0,0],red:[255,0,0],purple:[128,0,128],fuchsia:[255,0,255],green:[0,128,0],lime:[0,255,0],olive:[128,128,0],yellow:[255,255,0],navy:[0,0,128],blue:[0,0,255],teal:[0,128,128],aqua:[0,255,255],orange:[255,165,0],aliceblue:[240,248,245],antiquewhite:[250,235,215],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],blanchedalmond:[255,235,205],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,35],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],"darkgray[*]":[169,169,169],darkgreen:[0,100,0],"darkgrey[*]":[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],limegreen:[50,205,50],linen:[250,240,230],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],oldlace:[253,245,230],olivedrab:[107,142,35],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],whitesmoke:[245,245,245],yellowgreen:[154,205,50]};me.Color=Object.extend({r:0,g:0,b:0,alpha:1,init:function(a,b,c,d){return this.setColor(a,b,c,d),this},onResetEvent:function(){this.setColor(0,0,0,1)},add:function(a){return this.r=Math.min(this.r+a.r,255),this.g=Math.min(this.g+a.g,255),this.b=Math.min(this.b+a.b,255),this},setColor:function(a,b,c,d){return this.r=a||0,this.g=b||0,this.b=c||0,this.alpha=d||1,this},darken:function(a){return this.r=Math.min(this.r*a,255),this.g=Math.min(this.g*a,255),this.b=Math.min(this.b*a,255),this},equals:function(a){return this.r===a.r&&this.g===a.g&&this.b===a.b&&this.alpha===a.alpha},parseCSS:function(b){var c=a[b]||c;return this.setColor(c[0],c[1],c[2],1),this},parseHex:function(a){return"#"===a.charAt(0)&&(a=a.substring(1,a.length)),a.length<6?(this.r=parseInt(a.charAt(0)+a.charAt(0),16),this.g=parseInt(a.charAt(1)+a.charAt(1),16),this.b=parseInt(a.charAt(2)+a.charAt(2),16)):(this.r=parseInt(a.substring(0,2),16),this.g=parseInt(a.substring(2,4),16),this.b=parseInt(a.substring(4,6),16)),this.alpha=1,this},random:function(){return this.setColor(Math.floor(256*Math.random()),Math.floor(256*Math.random()),Math.floor(256*Math.random()),this.alpha),this},toHex:function(){return"#"+this.r.toHex()+this.g.toHex()+this.b.toHex()},toRGB:function(){return"rgb("+this.r+","+this.g+","+this.b+")"},toRGBA:function(){return"rgba("+this.r+","+this.g+","+this.b+","+this.alpha+")"}})}(window),function(){me.save=function(){function a(a){return"add"===a||"remove"===a}var b={},c={_init:function(){if(me.device.localStorage===!0){var a=JSON.parse(localStorage.getItem("me.save"))||[];a.forEach(function(a){b[a]=JSON.parse(localStorage.getItem("me.save."+a))})}},add:function(d){Object.keys(d).forEach(function(e){a(e)||(!function(a){Object.defineProperty(c,a,{configurable:!0,enumerable:!0,get:function(){return b[a]},set:function(c){b[a]=c,me.device.localStorage===!0&&localStorage.setItem("me.save."+a,JSON.stringify(c))}})}(e),e in b||(c[e]=d[e]))}),me.device.localStorage===!0&&localStorage.setItem("me.save",JSON.stringify(Object.keys(b)))},remove:function(c){a(c)||"undefined"!=typeof b[c]&&(delete b[c],me.device.localStorage===!0&&(localStorage.removeItem("me.save."+c),localStorage.setItem("me.save",JSON.stringify(Object.keys(b)))))}};return c}()}(window),function(){me.COLLISION_LAYER="collision",me.TMX_TAG_MAP="map",me.TMX_TAG_NAME="name",me.TMX_TAG_VALUE="value",me.TMX_TAG_VERSION="version",me.TMX_TAG_ORIENTATION="orientation",me.TMX_TAG_WIDTH="width",me.TMX_TAG_HEIGHT="height",me.TMX_TAG_OPACITY="opacity",me.TMX_TAG_TRANS="trans",me.TMX_TAG_TILEWIDTH="tilewidth",me.TMX_TAG_TILEHEIGHT="tileheight",me.TMX_TAG_TILEOFFSET="tileoffset",me.TMX_TAG_FIRSTGID="firstgid",me.TMX_TAG_GID="gid",me.TMX_TAG_TILE="tile",me.TMX_TAG_ID="id",me.TMX_TAG_DATA="data",me.TMX_TAG_COMPRESSION="compression",me.TMX_TAG_GZIP="gzip",me.TMX_TAG_ZLIB="zlib",me.TMX_TAG_ENCODING="encoding",me.TMX_TAG_ATTR_BASE64="base64",me.TMX_TAG_CSV="csv",me.TMX_TAG_SPACING="spacing",me.TMX_TAG_MARGIN="margin",me.TMX_TAG_PROPERTIES="properties",me.TMX_TAG_PROPERTY="property",me.TMX_TAG_IMAGE="image",me.TMX_TAG_SOURCE="source",me.TMX_TAG_VISIBLE="visible",me.TMX_TAG_TILESET="tileset",me.TMX_TAG_LAYER="layer",me.TMX_TAG_TILE_LAYER="tilelayer",me.TMX_TAG_IMAGE_LAYER="imagelayer",me.TMX_TAG_OBJECTGROUP="objectgroup",me.TMX_TAG_OBJECT="object",me.TMX_TAG_X="x",me.TMX_TAG_Y="y",me.TMX_TAG_WIDTH="width",me.TMX_TAG_HEIGHT="height",me.TMX_TAG_POLYGON="polygon",me.TMX_TAG_POLYLINE="polyline",me.TMX_TAG_ELLIPSE="ellipse",me.TMX_TAG_POINTS="points",me.TMX_BACKGROUND_COLOR="backgroundcolor"}(window),function(){me.TMXUtils=function(){function a(a){if(!a||a.isBoolean())a=a?"true"===a:!0;else if(a.isNumeric())a=Number(a);else if(a.match(/^json:/i)){var b=a.split(/^json:/i)[1];try{a=JSON.parse(b)}catch(c){throw"Unable to parse JSON: "+b}}return a}var b={};return b.applyTMXPropertiesFromXML=function(b,c){var d=c.getElementsByTagName(me.TMX_TAG_PROPERTIES)[0];if(d)for(var e=d.getElementsByTagName(me.TMX_TAG_PROPERTY),f=0;f<e.length;f++){var g=me.mapReader.TMXParser.getStringAttribute(e[f],me.TMX_TAG_NAME),h=me.mapReader.TMXParser.getStringAttribute(e[f],me.TMX_TAG_VALUE);b[g]=a(h)}},b.applyTMXPropertiesFromJSON=function(b,c){var d=c[me.TMX_TAG_PROPERTIES];if(d)for(var e in d)d.hasOwnProperty(e)&&(b[e]=a(d[e]))},b}()}(window),function(){me.TMXObjectGroup=Object.extend({name:null,width:0,height:0,visible:!1,z:0,objects:[],initFromXML:function(a,b,c,d){this.name=a,this.width=me.mapReader.TMXParser.getIntAttribute(b,me.TMX_TAG_WIDTH),this.height=me.mapReader.TMXParser.getIntAttribute(b,me.TMX_TAG_HEIGHT),this.visible=1===me.mapReader.TMXParser.getIntAttribute(b,me.TMX_TAG_VISIBLE,1),this.opacity=me.mapReader.TMXParser.getFloatAttribute(b,me.TMX_TAG_OPACITY,1).clamp(0,1),this.z=d,this.objects=[],b.firstChild&&b.firstChild.nextSibling.nodeName===me.TMX_TAG_PROPERTIES&&me.TMXUtils.applyTMXPropertiesFromXML(this,b);for(var e=b.getElementsByTagName(me.TMX_TAG_OBJECT),f=0;f<e.length;f++){var g=new me.TMXObject;g.initFromXML(e[f],c,d),this.objects.push(g)}},initFromJSON:function(a,b,c,d){var e=this;this.name=a,this.width=b[me.TMX_TAG_WIDTH],this.height=b[me.TMX_TAG_HEIGHT],this.visible=b[me.TMX_TAG_VISIBLE],this.opacity=parseFloat(b[me.TMX_TAG_OPACITY]||1).clamp(0,1),this.z=d,this.objects=[],me.TMXUtils.applyTMXPropertiesFromJSON(this,b),b.objects.forEach(function(a){var b=new me.TMXObject;b.initFromJSON(a,c,d),e.objects.push(b)})},destroy:function(){this.objects=null},getObjectCount:function(){return this.objects.length},getObjectByIndex:function(a){return this.objects[a]}}),me.TMXObject=Object.extend({name:null,x:0,y:0,width:0,height:0,z:0,gid:void 0,isPolygon:!1,isPolyline:!1,points:void 0,initFromXML:function(a,b,c){if(this.name=me.mapReader.TMXParser.getStringAttribute(a,me.TMX_TAG_NAME),this.x=me.mapReader.TMXParser.getIntAttribute(a,me.TMX_TAG_X),this.y=me.mapReader.TMXParser.getIntAttribute(a,me.TMX_TAG_Y),this.z=c,this.width=me.mapReader.TMXParser.getIntAttribute(a,me.TMX_TAG_WIDTH,0),this.height=me.mapReader.TMXParser.getIntAttribute(a,me.TMX_TAG_HEIGHT,0),this.gid=me.mapReader.TMXParser.getIntAttribute(a,me.TMX_TAG_GID,null),this.isEllipse=!1,this.isPolygon=!1,this.isPolyline=!1,this.gid)this.setImage(this.gid,b);else if(a.getElementsByTagName(me.TMX_TAG_ELLIPSE).length)this.isEllipse=!0;else{var d=a.getElementsByTagName(me.TMX_TAG_POLYGON);if(d.length?this.isPolygon=!0:(d=a.getElementsByTagName(me.TMX_TAG_POLYLINE),d.length&&(this.isPolyline=!0)),d.length){this.points=[];for(var e,f=me.mapReader.TMXParser.getStringAttribute(d[0],me.TMX_TAG_POINTS).split(" "),g=0;g<f.length;g++)e=f[g].split(","),this.points.push(new me.Vector2d(+e[0],+e[1]))}}me.game.renderer.adjustPosition(this),me.TMXUtils.applyTMXPropertiesFromXML(this,a)},initFromJSON:function(a,b,c){if(this.name=a[me.TMX_TAG_NAME],this.x=parseInt(a[me.TMX_TAG_X],10),this.y=parseInt(a[me.TMX_TAG_Y],10),this.z=parseInt(c,10),this.width=parseInt(a[me.TMX_TAG_WIDTH]||0,10),this.height=parseInt(a[me.TMX_TAG_HEIGHT]||0,10),this.gid=parseInt(a[me.TMX_TAG_GID],10)||null,this.isEllipse=!1,this.isPolygon=!1,this.isPolyline=!1,this.gid)this.setImage(this.gid,b);else if(void 0!==a[me.TMX_TAG_ELLIPSE])this.isEllipse=!0;else{var d=a[me.TMX_TAG_POLYGON];if(void 0!==d?this.isPolygon=!0:(d=a[me.TMX_TAG_POLYLINE],void 0!==d&&(this.isPolyline=!0)),void 0!==d){this.points=[];var e=this;d.forEach(function(a){e.points.push(new me.Vector2d(parseInt(a.x,10),parseInt(a.y,10)))})}}me.game.renderer.adjustPosition(this),me.TMXUtils.applyTMXPropertiesFromJSON(this,a)},setImage:function(a,b){var c=b.getTilesetByGid(this.gid);this.width=c.tilewidth,this.height=c.tileheight,this.spritewidth=this.width;var d=new me.Tile(this.x,this.y,c.tilewidth,c.tileheight,this.gid);this.image=c.getTileImage(d)},getShape:function(){return this.isEllipse===!0?new me.Ellipse(new me.Vector2d(0,0),this.width,this.height):this.isPolygon===!0||this.isPolyline===!0?new me.PolyShape(new me.Vector2d(0,0),this.points,this.isPolygon):new me.Rect(new me.Vector2d(0,0),this.width,this.height)},getObjectPropertyByName:function(a){return this[a]}})}(window),function(){var a=2147483648,b=1073741824,c=536870912;me.Tile=me.Rect.extend({tileId:null,tileset:null,transform:null,init:function(d,e,f,g,h){this.parent(new me.Vector2d(d*f,e*g),f,g),this.col=d,this.row=e,this.tileId=h,this.flipX=0!==(this.tileId&a),this.flipY=0!==(this.tileId&b),this.flipAD=0!==(this.tileId&c),this.flipped=this.flipX||this.flipY||this.flipAD,this.flipped===!0&&this.createTransform(),this.tileId&=~(a|b|c)},createTransform:function(){null===this.transform&&(this.transform=new me.Matrix2d),this.transform.identity(),this.flipAD&&(this.transform.set(0,1,1,0),this.transform.translate(0,this.height-this.width)),this.flipX&&(this.transform.a*=-1,this.transform.c*=-1,this.transform.translate(this.flipAD?this.height:this.width,0)),this.flipY&&(this.transform.b*=-1,this.transform.d*=-1,this.transform.translate(0,this.flipAD?this.width:this.height))}}),me.TMXTileset=Object.extend({type:{SOLID:"solid",PLATFORM:"platform",L_SLOPE:"lslope",R_SLOPE:"rslope",LADDER:"ladder",TOPLADDER:"topladder",BREAKABLE:"breakable"},init:function(){this.TileProperties=[],this.tileXOffset=[],this.tileYOffset=[]},initFromXML:function(a){this.firstgid=me.mapReader.TMXParser.getIntAttribute(a,me.TMX_TAG_FIRSTGID);var b=me.mapReader.TMXParser.getStringAttribute(a,me.TMX_TAG_SOURCE);if(b){if(b=me.utils.getBasename(b),a=me.loader.getTMX(b),!a)throw"melonJS:"+b+" TSX tileset not found";me.mapReader.TMXParser.parseFromString(a),a=me.mapReader.TMXParser.getFirstElementByTagName("tileset")}this.name=me.mapReader.TMXParser.getStringAttribute(a,me.TMX_TAG_NAME),this.tilewidth=me.mapReader.TMXParser.getIntAttribute(a,me.TMX_TAG_TILEWIDTH),this.tileheight=me.mapReader.TMXParser.getIntAttribute(a,me.TMX_TAG_TILEHEIGHT),this.spacing=me.mapReader.TMXParser.getIntAttribute(a,me.TMX_TAG_SPACING,0),this.margin=me.mapReader.TMXParser.getIntAttribute(a,me.TMX_TAG_MARGIN,0),this.tileoffset=new me.Vector2d(0,0);var c=a.getElementsByTagName(me.TMX_TAG_TILEOFFSET);c.length>0&&(this.tileoffset.x=me.mapReader.TMXParser.getIntAttribute(c[0],me.TMX_TAG_X),this.tileoffset.y=me.mapReader.TMXParser.getIntAttribute(c[0],me.TMX_TAG_Y));for(var d=a.getElementsByTagName(me.TMX_TAG_TILE),e=0;e<d.length;e++){var f=me.mapReader.TMXParser.getIntAttribute(d[e],me.TMX_TAG_ID)+this.firstgid,g={};me.TMXUtils.applyTMXPropertiesFromXML(g,d[e]),this.setTileProperty(f,g)}var h=a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE),i=h?me.loader.getImage(me.utils.getBasename(h)):null;i||console.log("melonJS: '"+h+"' file for tileset '"+this.name+"' not found!");var j=a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_TRANS);this.initFromImage(i,j)},initFromJSON:function(a){this.firstgid=a[me.TMX_TAG_FIRSTGID];var b=a[me.TMX_TAG_SOURCE];if(b&&(b=me.utils.getBasename(b),a=me.loader.getTMX(b),!a))throw"melonJS:"+b+" TSX tileset not found";this.name=a[me.TMX_TAG_NAME],this.tilewidth=parseInt(a[me.TMX_TAG_TILEWIDTH],10),this.tileheight=parseInt(a[me.TMX_TAG_TILEHEIGHT],10),this.spacing=parseInt(a[me.TMX_TAG_SPACING]||0,10),this.margin=parseInt(a[me.TMX_TAG_MARGIN]||0,10),this.tileoffset=new me.Vector2d(0,0);var c=a[me.TMX_TAG_TILEOFFSET];c&&(this.tileoffset.x=parseInt(c[me.TMX_TAG_X],10),this.tileoffset.y=parseInt(c[me.TMX_TAG_Y],10));var d=a.tileproperties;for(var e in d){var f={};f.mixin(d[e]),this.setTileProperty(parseInt(e,10)+this.firstgid,f)}var g=me.utils.getBasename(a[me.TMX_TAG_IMAGE]),h=g?me.loader.getImage(g):null;h||console.log("melonJS: '"+g+"' file for tileset '"+this.name+"' not found!");var i=a[me.TMX_TAG_TRANS]||null;this.initFromImage(h,i)},initFromImage:function(a,b){a&&(this.image=a,this.hTileCount=~~((this.image.width-this.margin)/(this.tilewidth+this.spacing)),this.vTileCount=~~((this.image.height-this.margin)/(this.tileheight+this.spacing))),this.lastgid=this.firstgid+(this.hTileCount*this.vTileCount-1||0),null!==b&&this.image&&(this.image=me.video.applyRGBFilter(this.image,"transparent",b.toUpperCase()).canvas)},setTileProperty:function(a,b){b.isSolid=b.type?b.type.toLowerCase()===this.type.SOLID:!1,b.isPlatform=b.type?b.type.toLowerCase()===this.type.PLATFORM:!1,b.isLeftSlope=b.type?b.type.toLowerCase()===this.type.L_SLOPE:!1,b.isRightSlope=b.type?b.type.toLowerCase()===this.type.R_SLOPE:!1,b.isBreakable=b.type?b.type.toLowerCase()===this.type.BREAKABLE:!1,b.isLadder=b.type?b.type.toLowerCase()===this.type.LADDER:!1,b.isTopLadder=b.type?b.type.toLowerCase()===this.type.TOPLADDER:!1,b.isSlope=b.isLeftSlope||b.isRightSlope,b.isCollidable=!!b.type,this.TileProperties[a]=b},contains:function(a){return a>=this.firstgid&&a<=this.lastgid},getTileImage:function(a){var b=me.video.getContext2d(me.video.createCanvas(this.tilewidth,this.tileheight));return this.drawTile(b,0,0,a),b.canvas},getTileProperties:function(a){return this.TileProperties[a]},isTileCollidable:function(a){return this.TileProperties[a].isCollidable},getTileOffsetX:function(a){var b=this.tileXOffset[a];return"undefined"==typeof b&&(b=this.tileXOffset[a]=this.margin+(this.spacing+this.tilewidth)*(a%this.hTileCount)),b},getTileOffsetY:function(a){var b=this.tileYOffset[a];return"undefined"==typeof b&&(b=this.tileYOffset[a]=this.margin+(this.spacing+this.tileheight)*~~(a/this.hTileCount)),b},drawTile:function(a,b,c,d){if(d.flipped){a.save();var e=d.transform;a.transform(e.a,e.b,e.c,e.d,e.e+b,e.f+c),b=c=0}var f=d.tileId-this.firstgid;a.drawImage(this.image,this.getTileOffsetX(f),this.getTileOffsetY(f),this.tilewidth,this.tileheight,b,c,this.tilewidth,this.tileheight),d.flipped&&a.restore()}}),me.TMXTilesetGroup=Object.extend({init:function(){this.tilesets=[]},add:function(a){this.tilesets.push(a)},getTilesetByIndex:function(a){return this.tilesets[a]},getTilesetByGid:function(a){for(var b=-1,c=0,d=this.tilesets.length;d>c;c++){if(this.tilesets[c].contains(a))return this.tilesets[c];this.tilesets[c].firstgid===this.tilesets[c].lastgid&&a>=this.tilesets[c].firstgid&&(b=c)}if(-1!==b)return this.tilesets[b];throw"no matching tileset found for gid "+a}})}(window),function(){me.TMXOrthogonalRenderer=Object.extend({init:function(a,b,c,d){this.cols=a,this.rows=b,this.tilewidth=c,this.tileheight=d},canRender:function(a){return"orthogonal"===a.orientation&&this.cols===a.cols&&this.rows===a.rows&&this.tilewidth===a.tilewidth&&this.tileheight===a.tileheight},pixelToTileCoords:function(a,b){return new me.Vector2d(a/this.tilewidth,b/this.tileheight)},tileToPixelCoords:function(a,b){return new me.Vector2d(a*this.tilewidth,b*this.tileheight)},adjustPosition:function(a){"number"==typeof a.gid&&(a.y-=a.height)},drawTile:function(a,b,c,d,e){e.drawTile(a,e.tileoffset.x+b*this.tilewidth,e.tileoffset.y+(c+1)*this.tileheight-e.tileheight,d)},drawTileLayer:function(a,b,c){var d=this.pixelToTileCoords(c.pos.x,c.pos.y).floorSelf(),e=this.pixelToTileCoords(c.pos.x+c.width+this.tilewidth,c.pos.y+c.height+this.tileheight).ceilSelf();e.x=e.x>this.cols?this.cols:e.x,e.y=e.y>this.rows?this.rows:e.y;for(var f=d.y;f<e.y;f++)for(var g=d.x;g<e.x;g++){var h=b.layerData[g][f];h&&this.drawTile(a,g,f,h,h.tileset)}}}),me.TMXIsometricRenderer=Object.extend({init:function(a,b,c,d){this.cols=a,this.rows=b,this.tilewidth=c,this.tileheight=d,this.hTilewidth=c/2,this.hTileheight=d/2,this.originX=this.rows*this.hTilewidth},canRender:function(a){return"isometric"===a.orientation&&this.cols===a.cols&&this.rows===a.rows&&this.tilewidth===a.tilewidth&&this.tileheight===a.tileheight},pixelToTileCoords:function(a,b){a-=this.originX;var c=b/this.tileheight,d=a/this.tilewidth;return new me.Vector2d(c+d,c-d)},tileToPixelCoords:function(a,b){return new me.Vector2d((a-b)*this.hTilewidth+this.originX,(a+b)*this.hTileheight)},adjustPosition:function(a){var b=a.x/this.hTilewidth,c=a.y/this.tileheight,d=this.tileToPixelCoords(b,c);d.x-=a.width/2,d.y-=a.height,a.x=d.x,a.y=d.y},drawTile:function(a,b,c,d,e){e.drawTile(a,(this.cols-1)*e.tilewidth+(b-c)*e.tilewidth>>1,-e.tilewidth+(b+c)*e.tileheight>>2,d)},drawTileLayer:function(a,b,c){var d=b.tileset,e=d.tileoffset,f=this.pixelToTileCoords(c.pos.x-d.tilewidth,c.pos.y-d.tileheight).floorSelf(),g=this.pixelToTileCoords(c.pos.x+c.width+d.tilewidth,c.pos.y+c.height+d.tileheight).ceilSelf(),h=this.tileToPixelCoords(g.x,g.y),i=this.tileToPixelCoords(f.x,f.y);i.x-=this.hTilewidth,i.y+=this.tileheight;var j=i.y-c.pos.y>this.hTileheight,k=c.pos.x-i.x<this.hTilewidth;j&&(k?(f.x--,i.x-=this.hTilewidth):(f.y--,i.x+=this.hTilewidth),i.y-=this.hTileheight);for(var l=j^k,m=f.clone(),n=i.y;n-this.tileheight<h.y;n+=this.hTileheight){m.setV(f);for(var o=i.x;o<h.x;o+=this.tilewidth){if(m.x>=0&&m.y>=0&&m.x<this.cols&&m.y<this.rows){var p=b.layerData[m.x][m.y];p&&(d=p.tileset,e=d.tileoffset,d.drawTile(a,e.x+o,e.y+n-d.tileheight,p))}m.x++,m.y--}l?(f.y++,i.x-=this.hTilewidth,l=!1):(f.x++,i.x+=this.hTilewidth,l=!0)}}})}(window),function(){me.ColorLayer=me.Renderable.extend({init:function(a,b,c){this.parent(new me.Vector2d(0,0),1/0,1/0),this.name=a,this.color=(new me.Color).parseHex(b),this.z=c},draw:function(a,b){var c=a.globalAlpha;a.globalAlpha*=this.getOpacity(),a.fillStyle=this.color.toRGB(),a.fillRect(b.left,b.top,b.width,b.height),a.globalAlpha=c}}),me.ImageLayer=me.Renderable.extend({init:function(a,b,c,d,e,f){if(this.name=a,this.image=d?me.loader.getImage(me.utils.getBasename(d)):null,!this.image)throw"melonJS: '"+d+"' file for Image Layer '"+this.name+"' not found!";this.imagewidth=this.image.width,this.imageheight=this.image.height;var g=me.game.viewport;b=b?Math.min(g.width,b):g.width,c=c?Math.min(g.height,c):g.height,this.parent(new me.Vector2d(0,0),b,c),this.z=e,this.ratio=new me.Vector2d(1,1),f&&("number"==typeof f?this.ratio.set(f,f):this.ratio.setV(f)),this.lastpos=g.pos.clone(),this.floating=!0,this._repeat="repeat",this.repeatX=!0,this.repeatY=!0,Object.defineProperty(this,"repeat",{get:function(){return this._repeat},set:function(a){switch(this._repeat=a,this._repeat){case"no-repeat":this.repeatX=!1,this.repeatY=!1;break;case"repeat-x":this.repeatX=!0,this.repeatY=!1;break;case"repeat-y":this.repeatX=!1,this.repeatY=!0;break;default:this.repeatX=!0,this.repeatY=!0}}}),this.anchorPoint.set(0,0),this.handle=me.event.subscribe(me.event.VIEWPORT_ONCHANGE,this.updateLayer.bind(this))},updateLayer:function(a){(0!==this.ratio.x||0!==this.ratio.y)&&(this.repeatX||this.repeatY?(this.pos.x+=(a.x-this.lastpos.x)*this.ratio.x%this.imagewidth,this.pos.x=(this.imagewidth+this.pos.x)%this.imagewidth,this.pos.y+=(a.y-this.lastpos.y)*this.ratio.y%this.imageheight,this.pos.y=(this.imageheight+this.pos.y)%this.imageheight):(this.pos.x+=(a.x-this.lastpos.x)*this.ratio.x,this.pos.y+=(a.y-this.lastpos.y)*this.ratio.y),this.lastpos.setV(a))
},draw:function(a,b){var c=me.game.viewport,d=0!==this.anchorPoint.y||0!==this.anchorPoint.x,e=~~(this.anchorPoint.x*(c.width-this.imagewidth)),f=~~(this.anchorPoint.y*(c.height-this.imageheight));d&&a.translate(e,f),a.globalAlpha*=this.getOpacity();var g,h;if(0===this.ratio.x&&0===this.ratio.y)g=Math.min(b.width,this.imagewidth),h=Math.min(b.height,this.imageheight),a.drawImage(this.image,b.left,b.top,g,h,b.left,b.top,g,h);else{var i=~~this.pos.x,j=~~this.pos.y,k=0,l=0;for(g=Math.min(this.imagewidth-i,this.width),h=Math.min(this.imageheight-j,this.height);;){do a.drawImage(this.image,i,j,g,h,k,l,g,h),j=0,l+=h,h=Math.min(this.imageheight,this.height-l);while(this.repeatY&&l<this.height);if(k+=g,!this.repeatX||k>=this.width)break;i=0,g=Math.min(this.imagewidth,this.width-k),j=~~this.pos.y,l=0,h=Math.min(this.imageheight-~~this.pos.y,this.height)}}d&&a.translate(-e,-f)},destroy:function(){this.handle&&(me.event.unsubscribe(this.handle),this.handle=null),this.image=null,this.lastpos=null}}),me.CollisionTiledLayer=me.Renderable.extend({init:function(a,b){this.parent(new me.Vector2d(0,0),a,b),this.isCollisionMap=!0},checkCollision:function(a,b){var c=b.x<0?a.left+b.x:a.right+b.x,d=b.y<0?a.top+b.y:a.bottom+b.y,e={x:0,y:0,xprop:{},yprop:{}};return(0>=c||c>=this.width)&&(e.x=b.x),(0>=d||d>=this.height)&&(e.y=b.y),e}}),me.TMXLayer=me.Renderable.extend({layerData:null,init:function(a,b,c,d,e){this.parent(new me.Vector2d(0,0),0,0),this.tilewidth=a,this.tileheight=b,this.orientation=c,this.tilesets=d,this.tileset=this.tilesets?this.tilesets.getTilesetByIndex(0):null,this.z=e},initFromXML:function(a){this.name=me.mapReader.TMXParser.getStringAttribute(a,me.TMX_TAG_NAME),this.visible=1===me.mapReader.TMXParser.getIntAttribute(a,me.TMX_TAG_VISIBLE,1),this.cols=me.mapReader.TMXParser.getIntAttribute(a,me.TMX_TAG_WIDTH),this.rows=me.mapReader.TMXParser.getIntAttribute(a,me.TMX_TAG_HEIGHT),this.setOpacity(me.mapReader.TMXParser.getFloatAttribute(a,me.TMX_TAG_OPACITY,1)),this.width=this.cols*this.tilewidth,this.height=this.rows*this.tileheight,me.TMXUtils.applyTMXPropertiesFromXML(this,a),"undefined"==typeof this.preRender&&(this.preRender=me.sys.preRender),this.isCollisionMap=this.name.toLowerCase().contains(me.COLLISION_LAYER),this.isCollisionMap&&!me.debug.renderCollisionMap&&(this.visible=!1),this.preRender===!0&&(this.layerCanvas=me.video.createCanvas(this.cols*this.tilewidth,this.rows*this.tileheight),this.layerSurface=me.video.getContext2d(this.layerCanvas))},initFromJSON:function(a){this.name=a[me.TMX_TAG_NAME],this.visible=a[me.TMX_TAG_VISIBLE],this.cols=parseInt(a[me.TMX_TAG_WIDTH],10),this.rows=parseInt(a[me.TMX_TAG_HEIGHT],10),this.setOpacity(parseFloat(a[me.TMX_TAG_OPACITY])),this.width=this.cols*this.tilewidth,this.height=this.rows*this.tileheight,me.TMXUtils.applyTMXPropertiesFromJSON(this,a),"undefined"==typeof this.preRender&&(this.preRender=me.sys.preRender),this.isCollisionMap=this.name.toLowerCase().contains(me.COLLISION_LAYER),this.isCollisionMap&&!me.debug.renderCollisionMap&&(this.visible=!1),this.preRender===!0&&(this.layerCanvas=me.video.createCanvas(this.cols*this.tilewidth,this.rows*this.tileheight),this.layerSurface=me.video.getContext2d(this.layerCanvas))},destroy:function(){this.preRender&&(this.layerCanvas=null,this.layerSurface=null),this.renderer=null,this.layerData=null,this.tileset=null,this.tilesets=null},setRenderer:function(a){this.renderer=a},initArray:function(a,b){this.layerData=[];for(var c=0;a>c;c++){this.layerData[c]=[];for(var d=0;b>d;d++)this.layerData[c][d]=null}},getTileId:function(a,b){var c=this.getTile(a,b);return c?c.tileId:null},getTile:function(a,b){return this.layerData[~~(a/this.tilewidth)][~~(b/this.tileheight)]},setTile:function(a,b,c){var d=new me.Tile(a,b,this.tilewidth,this.tileheight,c);return d.tileset=this.tileset.contains(d.tileId)?this.tileset:this.tileset=this.tilesets.getTilesetByGid(d.tileId),this.layerData[a][b]=d,d},clearTile:function(a,b){this.layerData[a][b]=null,this.visible&&this.preRender&&this.layerSurface.clearRect(a*this.tilewidth,b*this.tileheight,this.tilewidth,this.tileheight)},checkCollision:function(a,b){var c=b.x<0?~~(a.left+b.x):Math.ceil(a.right-1+b.x),d=b.y<0?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),e={x:0,xtile:void 0,xprop:{},y:0,ytile:void 0,yprop:{}};return 0>=c||c>=this.width?e.x=b.x:0!==b.x&&(e.xtile=this.getTile(c,Math.ceil(a.bottom-1)),e.xtile&&this.tileset.isTileCollidable(e.xtile.tileId)?(e.x=b.x,e.xprop=this.tileset.getTileProperties(e.xtile.tileId)):(e.xtile=this.getTile(c,~~a.top),e.xtile&&this.tileset.isTileCollidable(e.xtile.tileId)&&(e.x=b.x,e.xprop=this.tileset.getTileProperties(e.xtile.tileId)))),e.ytile=this.getTile(b.x<0?~~a.left:Math.ceil(a.right-1),d),e.ytile&&this.tileset.isTileCollidable(e.ytile.tileId)?(e.y=b.y||1,e.yprop=this.tileset.getTileProperties(e.ytile.tileId)):(e.ytile=this.getTile(b.x<0?Math.ceil(a.right-1):~~a.left,d),e.ytile&&this.tileset.isTileCollidable(e.ytile.tileId)&&(e.y=b.y||1,e.yprop=this.tileset.getTileProperties(e.ytile.tileId))),e},draw:function(a,b){if(this.preRender){var c=Math.min(b.width,this.width),d=Math.min(b.height,this.height);this.layerSurface.globalAlpha=a.globalAlpha*this.getOpacity(),a.drawImage(this.layerCanvas,b.pos.x,b.pos.y,c,d,b.pos.x,b.pos.y,c,d)}else{var e=a.globalAlpha;a.globalAlpha*=this.getOpacity(),this.renderer.drawTileLayer(a,this,b),a.globalAlpha=e}}})}(window),function(){me.TMXTileMap=me.Renderable.extend({init:function(a){this.levelId=a,this.z=0,this.name=null,this.cols=0,this.rows=0,this.tilewidth=0,this.tileheight=0,this.tilesets=null,this.mapLayers=[],this.objectGroups=[],this.version="",this.orientation="",this.tilesets=null,this.initialized=!1,this.parent(new me.Vector2d,0,0)},getObjectGroupByName:function(a){var b=null;a=a.trim().toLowerCase();for(var c=this.objectGroups.length;c--;)if(this.objectGroups[c].name.toLowerCase().contains(a)){b=this.objectGroups[c];break}return b},getObjectGroups:function(){return this.objectGroups},getLayers:function(){return this.mapLayers},getLayerByName:function(a){var b=null;a=a.trim().toLowerCase();for(var c=this.mapLayers.length;c--;)if(this.mapLayers[c].name.toLowerCase().contains(a)){b=this.mapLayers[c];break}return a.toLowerCase().contains(me.COLLISION_LAYER)&&null==b&&(b=new me.CollisionTiledLayer(me.game.currentLevel.width,me.game.currentLevel.height)),b},clearTile:function(a,b){for(var c=this.mapLayers.length;c--;)this.mapLayers[c]instanceof me.TMXLayer&&this.mapLayers[c].clearTile(a,b)},destroy:function(){var a;if(this.initialized===!0){for(a=this.mapLayers.length;a--;)this.mapLayers[a]=null;for(a=this.objectGroups.length;a--;)this.objectGroups[a].destroy(),this.objectGroups[a]=null;this.tilesets=null,this.mapLayers.length=0,this.objectGroups.length=0,this.pos.set(0,0),this.initialized=!1}}})}(window),function(){function a(){var a={tmxDoc:null,setData:function(a){this.tmxDoc=a},getFirstElementByTagName:function(a){return this.tmxDoc?this.tmxDoc.getElementsByTagName(a)[0]:null},getAllTagElements:function(){return this.tmxDoc?this.tmxDoc.getElementsByTagName("*"):null},getStringAttribute:function(a,b,c){var d=a.getAttribute(b);return d?d.trim():c},getIntAttribute:function(a,b,c){var d=this.getStringAttribute(a,b,c);return d?parseInt(d,10):c},getFloatAttribute:function(a,b,c){var d=this.getStringAttribute(a,b,c);return d?parseFloat(d):c},getBooleanAttribute:function(a,b,c){var d=this.getStringAttribute(a,b,c);return d?"true"===d:c},free:function(){this.tmxDoc=null}};return a}me.TMXMapReader=Object.extend({XMLReader:null,JSONReader:null,TMXParser:null,readMap:function(a){if(!a.initialized){if("xml"===me.loader.getTMXFormat(a.levelId)?(null===this.XMLReader&&(this.XMLReader=new b),this.TMXParser=this.XMLReader.TMXParser,this.XMLReader.readXMLMap(a,me.loader.getTMX(a.levelId))):(null===this.JSONReader&&(this.JSONReader=new c),this.JSONReader.readJSONMap(a,me.loader.getTMX(a.levelId))),a.width<me.game.viewport.width||a.height<me.game.viewport.height){var d=~~((me.game.viewport.width-a.width)/2),e=~~((me.game.viewport.height-a.height)/2);a.pos.add({x:d>0?d:0,y:e>0?e:0})}a.initialized=!0}},getNewDefaultRenderer:function(a){switch(a.orientation){case"orthogonal":return new me.TMXOrthogonalRenderer(a.cols,a.rows,a.tilewidth,a.tileheight);case"isometric":return new me.TMXIsometricRenderer(a.cols,a.rows,a.tilewidth,a.tileheight);default:throw"melonJS: "+a.orientation+" type TMX Tile Map not supported!"}},setLayerData:function(a,b,c,d){switch(a.initArray(a.cols,a.rows),c){case null:b=b.getElementsByTagName(me.TMX_TAG_TILE);break;case"json":break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var e="",f=0,g=b.childNodes.length;g>f;f++)e+=b.childNodes[f].nodeValue;c===me.TMX_TAG_CSV?b=me.utils.decodeCSV(e,a.cols):(b=me.utils.decodeBase64AsArray(e,4),null!==d&&(b=me.utils.decompress(b,d))),e=null;break;default:throw"melonJS: TMX Tile Map "+c+" encoding not supported!"}for(var h=0,i=0;i<a.rows;i++)for(var j=0;j<a.cols;j++){var k=null==c?this.TMXParser.getIntAttribute(b[h++],me.TMX_TAG_GID):b[h++];if(0!==k){var l=a.setTile(j,i,k);a.visible&&a.preRender&&a.renderer.drawTile(a.layerSurface,j,i,l,l.tileset)}}}});var b=me.TMXMapReader.extend({TMXParser:null,init:function(){this.TMXParser||(this.TMXParser=new a)},readXMLMap:function(a,b){if(!b)throw"melonJS:"+a.levelId+" TMX map not found";var c=0;this.TMXParser.setData(b);for(var d=this.TMXParser.getAllTagElements(),e=0;e<d.length;e++)switch(d.item(e).nodeName){case me.TMX_TAG_MAP:var f=d.item(e);a.version=this.TMXParser.getStringAttribute(f,me.TMX_TAG_VERSION),a.orientation=this.TMXParser.getStringAttribute(f,me.TMX_TAG_ORIENTATION),a.cols=this.TMXParser.getIntAttribute(f,me.TMX_TAG_WIDTH),a.rows=this.TMXParser.getIntAttribute(f,me.TMX_TAG_HEIGHT),a.tilewidth=this.TMXParser.getIntAttribute(f,me.TMX_TAG_TILEWIDTH),a.tileheight=this.TMXParser.getIntAttribute(f,me.TMX_TAG_TILEHEIGHT),a.width=a.cols*a.tilewidth,a.height=a.rows*a.tileheight,a.backgroundcolor=this.TMXParser.getStringAttribute(f,me.TMX_BACKGROUND_COLOR),a.z=c++,me.TMXUtils.applyTMXPropertiesFromXML(a,f),a.backgroundcolor&&a.mapLayers.push(new me.ColorLayer("background_color",a.backgroundcolor,c++)),a.background_image&&a.mapLayers.push(new me.ImageLayer("background_image",a.width,a.height,a.background_image,c++)),null!==me.game.renderer&&me.game.renderer.canRender(a)||(me.game.renderer=this.getNewDefaultRenderer(a));break;case me.TMX_TAG_TILESET:a.tilesets||(a.tilesets=new me.TMXTilesetGroup),a.tilesets.add(this.readTileset(d.item(e)));break;case me.TMX_TAG_IMAGE_LAYER:a.mapLayers.push(this.readImageLayer(a,d.item(e),c++));break;case me.TMX_TAG_LAYER:a.mapLayers.push(this.readLayer(a,d.item(e),c++));break;case me.TMX_TAG_OBJECTGROUP:a.objectGroups.push(this.readObjectGroup(a,d.item(e),c++))}this.TMXParser.free()},readLayer:function(a,b,c){var d=new me.TMXLayer(a.tilewidth,a.tileheight,a.orientation,a.tilesets,c);d.initFromXML(b);var e=b.getElementsByTagName(me.TMX_TAG_DATA)[0],f=this.TMXParser.getStringAttribute(e,me.TMX_TAG_ENCODING,null),g=this.TMXParser.getStringAttribute(e,me.TMX_TAG_COMPRESSION,null);return""===f&&(f=null),""===g&&(g=null),(!d.isCollisionMap||me.debug.renderCollisionMap)&&d.setRenderer(me.game.renderer.canRender(d)?me.game.renderer:me.mapReader.getNewDefaultRenderer(d)),this.setLayerData(d,e,f,g),e=null,d},readImageLayer:function(a,b,c){var d=this.TMXParser.getStringAttribute(b,me.TMX_TAG_NAME),e=this.TMXParser.getIntAttribute(b,me.TMX_TAG_WIDTH),f=this.TMXParser.getIntAttribute(b,me.TMX_TAG_HEIGHT),g=b.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE),h=new me.ImageLayer(d,e*a.tilewidth,f*a.tileheight,g,c);return h.visible=1===this.TMXParser.getIntAttribute(b,me.TMX_TAG_VISIBLE,1),h.setOpacity(this.TMXParser.getFloatAttribute(b,me.TMX_TAG_OPACITY,1)),me.TMXUtils.applyTMXPropertiesFromXML(h,b),"number"==typeof h.ratio&&(h.ratio=new me.Vector2d(parseFloat(h.ratio),parseFloat(h.ratio))),h},readTileset:function(a){var b=new me.TMXTileset;return b.initFromXML(a),b},readObjectGroup:function(a,b,c){var d=this.TMXParser.getStringAttribute(b,me.TMX_TAG_NAME),e=new me.TMXObjectGroup;return e.initFromXML(d,b,a.tilesets,c),e}}),c=me.TMXMapReader.extend({readJSONMap:function(a,b){if(!b)throw"melonJS:"+a.levelId+" TMX map not found";var c=0,d=this;a.version=b[me.TMX_TAG_VERSION],a.orientation=b[me.TMX_TAG_ORIENTATION],a.cols=parseInt(b[me.TMX_TAG_WIDTH],10),a.rows=parseInt(b[me.TMX_TAG_HEIGHT],10),a.tilewidth=parseInt(b[me.TMX_TAG_TILEWIDTH],10),a.tileheight=parseInt(b[me.TMX_TAG_TILEHEIGHT],10),a.width=a.cols*a.tilewidth,a.height=a.rows*a.tileheight,a.backgroundcolor=b[me.TMX_BACKGROUND_COLOR],a.z=c++,me.TMXUtils.applyTMXPropertiesFromJSON(a,b),a.backgroundcolor&&a.mapLayers.push(new me.ColorLayer("background_color",a.backgroundcolor,c++)),a.background_image&&a.mapLayers.push(new me.ImageLayer("background_image",a.width,a.height,a.background_image,c++)),null!==me.game.renderer&&me.game.renderer.canRender(a)||(me.game.renderer=this.getNewDefaultRenderer(a)),a.tilesets||(a.tilesets=new me.TMXTilesetGroup),b.tilesets.forEach(function(b){a.tilesets.add(d.readTileset(b))}),b.layers.forEach(function(b){switch(b.type){case me.TMX_TAG_IMAGE_LAYER:a.mapLayers.push(d.readImageLayer(a,b,c++));break;case me.TMX_TAG_TILE_LAYER:a.mapLayers.push(d.readLayer(a,b,c++));break;case me.TMX_TAG_OBJECTGROUP:a.objectGroups.push(d.readObjectGroup(a,b,c++))}})},readLayer:function(a,b,c){var d=new me.TMXLayer(a.tilewidth,a.tileheight,a.orientation,a.tilesets,c);return d.initFromJSON(b),d.isCollisionMap||d.setRenderer(me.game.renderer.canRender(d)?me.game.renderer:me.mapReader.getNewDefaultRenderer(d)),this.setLayerData(d,b[me.TMX_TAG_DATA],"json",null),d},readImageLayer:function(a,b,c){var d=b[me.TMX_TAG_NAME],e=parseInt(b[me.TMX_TAG_WIDTH],10),f=parseInt(b[me.TMX_TAG_HEIGHT],10),g=b[me.TMX_TAG_IMAGE],h=new me.ImageLayer(d,e*a.tilewidth,f*a.tileheight,g,c);return h.visible=b[me.TMX_TAG_VISIBLE],h.setOpacity(parseFloat(b[me.TMX_TAG_OPACITY])),me.TMXUtils.applyTMXPropertiesFromJSON(h,b),"number"==typeof h.ratio&&(h.ratio=new me.Vector2d(parseFloat(h.ratio),parseFloat(h.ratio))),h},readTileset:function(a){var b=new me.TMXTileset;return b.initFromJSON(a),b},readObjectGroup:function(a,b,c){var d=new me.TMXObjectGroup;return d.initFromJSON(b[me.TMX_TAG_NAME],b,a.tilesets,c),d}})}(window),function(){me.levelDirector=function(){var a={},b={},c=[],d=0,e=function(a,b){b.autoSort=!1,me.game.currentLevel=a,me.game.collisionMap=me.game.currentLevel.getLayerByName("collision"),me.game.collisionMap&&me.game.collisionMap.isCollisionMap||console.error("WARNING : no collision map detected");for(var c=a.getLayers(),d=c.length;d--;)c[d].visible&&b.addChild(c[d]);me.game.viewport.setBounds(0,0,Math.max(a.width,me.game.viewport.width),Math.max(a.height,me.game.viewport.height));for(var e=b,f=a.getObjectGroups(),g=0;g<f.length;g++){var h=f[g];me.game.mergeGroup===!1&&(e=new me.ObjectContainer,e.name=h.name,e.visible=h.visible,e.z=h.z,e.setOpacity(h.opacity),e.autoSort=!1);for(var i=0;i<h.objects.length;i++){var j=h.objects[i],k=me.pool.pull(j.name,j.x,j.y,j);k&&(k.z=h.z,me.game.mergeGroup===!0&&k.isRenderable===!0&&(k.setOpacity(k.getOpacity()*h.opacity),null!==k.renderable&&k.renderable.setOpacity(k.renderable.getOpacity()*h.opacity)),e.addChild(k))}me.game.mergeGroup===!1&&(b.addChild(e),e.autoSort=!0)}b.sort(!0),b.autoSort=!0,me.game.world.transform.translateV(me.game.currentLevel.pos),me.game.onLevelLoaded&&me.game.onLevelLoaded.call(me.game.onLevelLoaded,a.name),me.event.publish(me.event.LEVEL_LOADED,[a.name])};return a.reset=function(){},a.addLevel=function(){throw"melonJS: no level loader defined"},a.addTMXLevel=function(a,d){return null!=b[a]?!1:(b[a]=new me.TMXTileMap(a),b[a].name=a,c.push(a),d&&d(),!0)},a.loadLevel=function(f){if(f=f.toString().toLowerCase(),void 0===b[f])throw"melonJS: level "+f+" not found";if(!(b[f]instanceof me.TMXTileMap))throw"melonJS: no level loader defined";var g=me.state.isRunning();return g&&me.state.stop(),me.game.reset(),me.utils.resetGUID(f),b[a.getCurrentLevelId()]&&b[a.getCurrentLevelId()].destroy(),me.mapReader.readMap(b[f]),d=c.indexOf(f),e(b[f],me.game.world),g&&me.state.restart.defer(this),!0},a.getCurrentLevelId=function(){return c[d]},a.reloadLevel=function(){return a.loadLevel(a.getCurrentLevelId())},a.nextLevel=function(){return d+1<c.length?a.loadLevel(c[d+1]):!1},a.previousLevel=function(){return d-1>=0?a.loadLevel(c[d-1]):!1},a.levelCount=function(){return c.length},a}()}(window),/**
 * @preserve Tween JS
 * https://github.com/sole/Tween.js
 */
function(){me.Tween=function(a){var b=a,c={},d={},e={},f=1e3,g=0,h=!1,i=!1,j=0,k=null,l=me.Tween.Easing.Linear.None,m=me.Tween.Interpolation.Linear,n=[],o=null,p=!1,q=null,r=null;for(var s in a)c[s]=parseFloat(a[s],10);this.onResetEvent=function(a){b=a,c={},d={},e={},l=me.Tween.Easing.Linear.None,m=me.Tween.Interpolation.Linear,h=!1,i=!1,f=1e3,j=0,o=null,p=!1,q=null,r=null},this.to=function(a,b){return void 0!==b&&(f=b),d=a,this},this.start=function(a){p=!1,me.game.world.addChild(this),k=("undefined"==typeof a?me.timer.getTime():a)+j;for(var f in d){if(d[f]instanceof Array){if(0===d[f].length)continue;d[f]=[b[f]].concat(d[f])}c[f]=b[f],c[f]instanceof Array==!1&&(c[f]*=1),e[f]=c[f]||0}return this},this.stop=function(){return me.game.world.hasChild(this)&&me.game.world.removeChildNow(this),this},this.delay=function(a){return j=a,this},me.event.subscribe(me.event.STATE_RESUME,function(a){k&&(k+=a)}),this.repeat=function(a){return g=a,this},this.yoyo=function(a){return h=a,this},this.easing=function(a){if("function"!=typeof a)throw"melonJS: invalid easing function for me.Tween.easing()";return l=a,this},this.interpolation=function(a){return m=a,this},this.chain=function(){return n=arguments,this},this.onStart=function(a){return o=a,this},this.onUpdate=function(a){return q=a,this},this.onComplete=function(a){return r=a,this},this.update=function(){var a,s=me.timer.getTime();if(k>s)return!0;p===!1&&(null!==o&&o.call(b),p=!0);var t=(s-k)/f;t=t>1?1:t;var u=l(t);for(a in d){var v=c[a]||0,w=d[a];w instanceof Array?b[a]=m(w,u):("string"==typeof w&&(w=v+parseFloat(w,10)),"number"==typeof w&&(b[a]=v+(w-v)*u))}if(null!==q&&q.call(b,u),1===t){if(g>0){isFinite(g)&&g--;for(a in e){if("string"==typeof d[a]&&(e[a]=e[a]+parseFloat(d[a],10)),h){var x=e[a];e[a]=d[a],d[a]=x,i=!i}c[a]=e[a]}return k=s+j,!0}me.game.world.removeChildNow(this),null!==r&&r.call(b);for(var y=0,z=n.length;z>y;y++)n[y].start(s);return!1}return!0}},me.Tween.Easing={Linear:{None:function(a){return a}},Quadratic:{In:function(a){return a*a},Out:function(a){return a*(2-a)},InOut:function(a){return(a*=2)<1?.5*a*a:-.5*(--a*(a-2)-1)}},Cubic:{In:function(a){return a*a*a},Out:function(a){return--a*a*a+1},InOut:function(a){return(a*=2)<1?.5*a*a*a:.5*((a-=2)*a*a+2)}},Quartic:{In:function(a){return a*a*a*a},Out:function(a){return 1- --a*a*a*a},InOut:function(a){return(a*=2)<1?.5*a*a*a*a:-.5*((a-=2)*a*a*a-2)}},Quintic:{In:function(a){return a*a*a*a*a},Out:function(a){return--a*a*a*a*a+1},InOut:function(a){return(a*=2)<1?.5*a*a*a*a*a:.5*((a-=2)*a*a*a*a+2)}},Sinusoidal:{In:function(a){return 1-Math.cos(a*Math.PI/2)},Out:function(a){return Math.sin(a*Math.PI/2)},InOut:function(a){return.5*(1-Math.cos(Math.PI*a))}},Exponential:{In:function(a){return 0===a?0:Math.pow(1024,a-1)},Out:function(a){return 1===a?1:1-Math.pow(2,-10*a)},InOut:function(a){return 0===a?0:1===a?1:(a*=2)<1?.5*Math.pow(1024,a-1):.5*(-Math.pow(2,-10*(a-1))+2)}},Circular:{In:function(a){return 1-Math.sqrt(1-a*a)},Out:function(a){return Math.sqrt(1- --a*a)},InOut:function(a){return(a*=2)<1?-.5*(Math.sqrt(1-a*a)-1):.5*(Math.sqrt(1-(a-=2)*a)+1)}},Elastic:{In:function(a){var b,c=.1,d=.4;return 0===a?0:1===a?1:(!c||1>c?(c=1,b=d/4):b=d*Math.asin(1/c)/(2*Math.PI),-(c*Math.pow(2,10*(a-=1))*Math.sin(2*(a-b)*Math.PI/d)))},Out:function(a){var b,c=.1,d=.4;return 0===a?0:1===a?1:(!c||1>c?(c=1,b=d/4):b=d*Math.asin(1/c)/(2*Math.PI),c*Math.pow(2,-10*a)*Math.sin(2*(a-b)*Math.PI/d)+1)},InOut:function(a){var b,c=.1,d=.4;return 0===a?0:1===a?1:(!c||1>c?(c=1,b=d/4):b=d*Math.asin(1/c)/(2*Math.PI),(a*=2)<1?-.5*c*Math.pow(2,10*(a-=1))*Math.sin(2*(a-b)*Math.PI/d):c*Math.pow(2,-10*(a-=1))*Math.sin(2*(a-b)*Math.PI/d)*.5+1)}},Back:{In:function(a){var b=1.70158;return a*a*((b+1)*a-b)},Out:function(a){var b=1.70158;return--a*a*((b+1)*a+b)+1},InOut:function(a){var b=2.5949095;return(a*=2)<1?.5*a*a*((b+1)*a-b):.5*((a-=2)*a*((b+1)*a+b)+2)}},Bounce:{In:function(a){return 1-me.Tween.Easing.Bounce.Out(1-a)},Out:function(a){return 1/2.75>a?7.5625*a*a:2/2.75>a?7.5625*(a-=1.5/2.75)*a+.75:2.5/2.75>a?7.5625*(a-=2.25/2.75)*a+.9375:7.5625*(a-=2.625/2.75)*a+.984375},InOut:function(a){return.5>a?.5*me.Tween.Easing.Bounce.In(2*a):.5*me.Tween.Easing.Bounce.Out(2*a-1)+.5}}},me.Tween.Interpolation={Linear:function(a,b){var c=a.length-1,d=c*b,e=Math.floor(d),f=me.Tween.Interpolation.Utils.Linear;return 0>b?f(a[0],a[1],d):b>1?f(a[c],a[c-1],c-d):f(a[e],a[e+1>c?c:e+1],d-e)},Bezier:function(a,b){var c,d=0,e=a.length-1,f=Math.pow,g=me.Tween.Interpolation.Utils.Bernstein;for(c=0;e>=c;c++)d+=f(1-b,e-c)*f(b,c)*a[c]*g(e,c);return d},CatmullRom:function(a,b){var c=a.length-1,d=c*b,e=Math.floor(d),f=me.Tween.Interpolation.Utils.CatmullRom;return a[0]===a[c]?(0>b&&(e=Math.floor(d=c*(1+b))),f(a[(e-1+c)%c],a[e],a[(e+1)%c],a[(e+2)%c],d-e)):0>b?a[0]-(f(a[0],a[0],a[1],a[1],-d)-a[0]):b>1?a[c]-(f(a[c],a[c],a[c-1],a[c-1],d-c)-a[c]):f(a[e?e-1:0],a[e],a[e+1>c?c:e+1],a[e+2>c?c:e+2],d-e)},Utils:{Linear:function(a,b,c){return(b-a)*c+a},Bernstein:function(a,b){var c=me.Tween.Interpolation.Utils.Factorial;return c(a)/c(b)/c(a-b)},Factorial:function(){var a=[1];return function(b){var c,d=1;if(a[b])return a[b];for(c=b;c>1;c--)d*=c;return a[b]=d}}(),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}}}}(),/**
 * @preserve MinPubSub
 * a micro publish/subscribe messaging framework
 * @see https://github.com/daniellmb/MinPubSub 
 * @author Daniel Lamb <daniellmb.com>
 *
 * Released under the MIT License
 */
function(){me.event=function(){var a={},b={};return a.STATE_PAUSE="me.state.onPause",a.STATE_RESUME="me.state.onResume",a.STATE_STOP="me.state.onStop",a.STATE_RESTART="me.state.onRestart",a.GAME_INIT="me.game.onInit",a.LEVEL_LOADED="me.game.onLevelLoaded",a.LOADER_COMPLETE="me.loader.onload",a.LOADER_PROGRESS="me.loader.onProgress",a.KEYDOWN="me.input.keydown",a.KEYUP="me.input.keyup",a.MOUSEMOVE="me.game.mousemove",a.DRAGSTART="me.game.dragstart",a.DRAGEND="me.game.dragend",a.WINDOW_ONRESIZE="window.onresize",a.WINDOW_ONORIENTATION_CHANGE="window.orientationchange",a.WINDOW_ONSCROLL="window.onscroll",a.VIEWPORT_ONCHANGE="viewport.onchange",a.publish=function(a,c){for(var d=b[a],e=d?d.length:0;e--;)d[e].apply(window,c||[])},a.subscribe=function(a,c){return b[a]||(b[a]=[]),b[a].push(c),[a,c]},a.unsubscribe=function(a,c){var d=b[c?a:a[0]],e=d?d.length:0;for(c=c||a[1];e--;)d[e]===c&&d.splice(e,1)},a}()}(),/*!
 *  howler.js v1.1.17
 *  howlerjs.com
 *
 *  (c) 2013-2014, James Simpson of GoldFire Studios
 *  goldfirestudios.com
 *
 *  MIT License
 */
function(){var a={},b=null,c=!0,d=!1;if("undefined"!=typeof AudioContext)b=new AudioContext;else if("undefined"!=typeof webkitAudioContext)b=new webkitAudioContext;else if("undefined"!=typeof Audio){c=!1;try{new Audio}catch(e){d=!0}}else c=!1,d=!0;if(c){var f="undefined"==typeof b.createGain?b.createGainNode():b.createGain();f.gain.value=1,f.connect(b.destination)}var g=function(){this._volume=1,this._muted=!1,this.usingWebAudio=c,this.noAudio=d,this._howls=[]};g.prototype={volume:function(a){var b=this;if(a=parseFloat(a),a>=0&&1>=a){b._volume=a,c&&(f.gain.value=a);for(var d in b._howls)if(b._howls.hasOwnProperty(d)&&b._howls[d]._webAudio===!1)for(var e=0;e<b._howls[d]._audioNode.length;e++)b._howls[d]._audioNode[e].volume=b._howls[d]._volume*b._volume;return b}return c?f.gain.value:b._volume},mute:function(){return this._setMuted(!0),this},unmute:function(){return this._setMuted(!1),this},_setMuted:function(a){var b=this;b._muted=a,c&&(f.gain.value=a?0:b._volume);for(var d in b._howls)if(b._howls.hasOwnProperty(d)&&b._howls[d]._webAudio===!1)for(var e=0;e<b._howls[d]._audioNode.length;e++)b._howls[d]._audioNode[e].muted=a}};var h=new g,i=null;if(!d){i=new Audio;var j={mp3:!!i.canPlayType("audio/mpeg;").replace(/^no$/,""),opus:!!i.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/,""),ogg:!!i.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),wav:!!i.canPlayType('audio/wav; codecs="1"').replace(/^no$/,""),m4a:!!(i.canPlayType("audio/x-m4a;")||i.canPlayType("audio/aac;")).replace(/^no$/,""),mp4:!!(i.canPlayType("audio/x-mp4;")||i.canPlayType("audio/aac;")).replace(/^no$/,""),weba:!!i.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,"")}}var k=function(a){var b=this;b._autoplay=a.autoplay||!1,b._buffer=a.buffer||!1,b._duration=a.duration||0,b._format=a.format||null,b._loop=a.loop||!1,b._loaded=!1,b._sprite=a.sprite||{},b._src=a.src||"",b._pos3d=a.pos3d||[0,0,-.5],b._volume=void 0!==a.volume?a.volume:1,b._urls=a.urls||[],b._rate=a.rate||1,b._onload=[a.onload||function(){}],b._onloaderror=[a.onloaderror||function(){}],b._onend=[a.onend||function(){}],b._onpause=[a.onpause||function(){}],b._onplay=[a.onplay||function(){}],b._onendTimer=[],b._webAudio=c&&!b._buffer,b._audioNode=[],b._webAudio&&b._setupAudioNode(),h._howls.push(b),b.load()};if(k.prototype={load:function(){var b=this,c=null;if(d)return void b.on("loaderror");for(var e=0;e<b._urls.length;e++){var f,g;if(b._format)f=b._format;else{if(g=b._urls[e].toLowerCase().split("?")[0],f=g.match(/.+\.([^?]+)(\?|$)/),f=f&&f.length>=2?f:g.match(/data\:audio\/([^?]+);/),!f)return void b.on("loaderror");f=f[1]}if(j[f]){c=b._urls[e];break}}if(!c)return void b.on("loaderror");if(b._src=c,b._webAudio)l(b,c);else{var i=new Audio;b._audioNode.push(i),i.src=c,i._pos=0,i.preload="auto",i.volume=h._muted?0:b._volume*h.volume(),a[c]=b;var k=function(){b._duration=Math.ceil(10*i.duration)/10,0===Object.getOwnPropertyNames(b._sprite).length&&(b._sprite={_default:[0,1e3*b._duration]}),b._loaded||(b._loaded=!0,b.on("load")),b._autoplay&&b.play(),i.removeEventListener("canplaythrough",k,!1)};i.addEventListener("canplaythrough",k,!1),i.load()}return b},urls:function(a){var b=this;return a?(b.stop(),b._urls="string"==typeof a?[a]:a,b._loaded=!1,b.load(),b):b._urls},play:function(a,c){var d=this;return"function"==typeof a&&(c=a),a&&"function"!=typeof a||(a="_default"),d._loaded?d._sprite[a]?(d._inactiveNode(function(e){e._sprite=a;var f,g=e._pos>0?e._pos:d._sprite[a][0]/1e3,i=d._sprite[a][1]/1e3-e._pos,j=!(!d._loop&&!d._sprite[a][2]),k="string"==typeof c?c:Math.round(Date.now()*Math.random())+"";if(function(){var b={id:k,sprite:a,loop:j};f=setTimeout(function(){!d._webAudio&&j&&d.stop(b.id,b.timer).play(a,b.id),d._webAudio&&!j&&(d._nodeById(b.id).paused=!0,d._nodeById(b.id)._pos=0),d._webAudio||j||d.stop(b.id,b.timer),d.on("end",k)},1e3*i),d._onendTimer.push(f),b.timer=d._onendTimer[d._onendTimer.length-1]}(),d._webAudio){var l=d._sprite[a][0]/1e3,m=d._sprite[a][1]/1e3;e.id=k,e.paused=!1,n(d,[j,l,m],k),d._playStart=b.currentTime,e.gain.value=d._volume,"undefined"==typeof e.bufferSource.start?e.bufferSource.noteGrainOn(0,g,i):e.bufferSource.start(0,g,i)}else{if(4!==e.readyState)return d._clearEndTimer(f),function(){var b=d,f=a,g=c,h=e,i=function(){b.play(f,g),h.removeEventListener("canplaythrough",i,!1)};h.addEventListener("canplaythrough",i,!1)}(),d;e.id=k,e.currentTime=g,e.muted=h._muted,e.volume=d._volume*h.volume(),setTimeout(function(){e.play()},0)}return d.on("play"),"function"==typeof c&&c(k),d}),d):("function"==typeof c&&c(),d):(d.on("load",function(){d.play(a,c)}),d)},pause:function(a,b){var c=this;if(!c._loaded)return c.on("play",function(){c.pause(a)}),c;c._clearEndTimer(b||0);var d=a?c._nodeById(a):c._activeNode();if(d)if(d._pos=c.pos(null,a),c._webAudio){if(!d.bufferSource||d.paused)return c;d.paused=!0,"undefined"==typeof d.bufferSource.stop?d.bufferSource.noteOff(0):d.bufferSource.stop(0)}else d.pause();return c.on("pause"),c},stop:function(a,b){var c=this;if(!c._loaded)return c.on("play",function(){c.stop(a)}),c;c._clearEndTimer(b||0);var d=a?c._nodeById(a):c._activeNode();if(d)if(d._pos=0,c._webAudio){if(!d.bufferSource||d.paused)return c;d.paused=!0,"undefined"==typeof d.bufferSource.stop?d.bufferSource.noteOff(0):d.bufferSource.stop(0)}else d.pause(),d.currentTime=0;return c},mute:function(a){var b=this;if(!b._loaded)return b.on("play",function(){b.mute(a)}),b;var c=a?b._nodeById(a):b._activeNode();return c&&(b._webAudio?c.gain.value=0:c.volume=0),b},unmute:function(a){var b=this;if(!b._loaded)return b.on("play",function(){b.unmute(a)}),b;var c=a?b._nodeById(a):b._activeNode();return c&&(b._webAudio?c.gain.value=b._volume:c.volume=b._volume),b},volume:function(a,b){var c=this;if(a=parseFloat(a),a>=0&&1>=a){if(c._volume=a,!c._loaded)return c.on("play",function(){c.volume(a,b)}),c;var d=b?c._nodeById(b):c._activeNode();return d&&(c._webAudio?d.gain.value=a:d.volume=a*h.volume()),c}return c._volume},loop:function(a){var b=this;return"boolean"==typeof a?(b._loop=a,b):b._loop},sprite:function(a){var b=this;return"object"==typeof a?(b._sprite=a,b):b._sprite},pos:function(a,c){var d=this;if(!d._loaded)return d.on("load",function(){d.pos(a)}),"number"==typeof a?d:d._pos||0;a=parseFloat(a);var e=c?d._nodeById(c):d._activeNode();if(e)return a>=0?(d.pause(c),e._pos=a,d.play(e._sprite,c),d):d._webAudio?e._pos+(b.currentTime-d._playStart):e.currentTime;if(a>=0)return d;for(var f=0;f<d._audioNode.length;f++)if(d._audioNode[f].paused&&4===d._audioNode[f].readyState)return d._webAudio?d._audioNode[f]._pos:d._audioNode[f].currentTime},pos3d:function(a,b,c,d){var e=this;if(b="undefined"!=typeof b&&b?b:0,c="undefined"!=typeof c&&c?c:-.5,!e._loaded)return e.on("play",function(){e.pos3d(a,b,c,d)}),e;if(!(a>=0||0>a))return e._pos3d;if(e._webAudio){var f=d?e._nodeById(d):e._activeNode();f&&(e._pos3d=[a,b,c],f.panner.setPosition(a,b,c))}return e},fade:function(a,b,c,d,e){var f=this,g=Math.abs(a-b),h=a>b?"down":"up",i=g/.01,j=c/i;if(!f._loaded)return f.on("load",function(){f.fade(a,b,c,d,e)}),f;f.volume(a,e);for(var k=1;i>=k;k++)!function(){var a=f._volume+("up"===h?.01:-.01)*k,c=Math.round(1e3*a)/1e3,g=b;setTimeout(function(){f.volume(c,e),c===g&&d&&d()},j*k)}()},fadeIn:function(a,b,c){return this.volume(0).play().fade(0,a,b,c)},fadeOut:function(a,b,c,d){var e=this;return e.fade(e._volume,a,b,function(){c&&c(),e.pause(d),e.on("end")},d)},_nodeById:function(a){for(var b=this,c=b._audioNode[0],d=0;d<b._audioNode.length;d++)if(b._audioNode[d].id===a){c=b._audioNode[d];break}return c},_activeNode:function(){for(var a=this,b=null,c=0;c<a._audioNode.length;c++)if(!a._audioNode[c].paused){b=a._audioNode[c];break}return a._drainPool(),b},_inactiveNode:function(a){for(var b=this,c=null,d=0;d<b._audioNode.length;d++)if(b._audioNode[d].paused&&4===b._audioNode[d].readyState){a(b._audioNode[d]),c=!0;break}if(b._drainPool(),!c){var e;b._webAudio?(e=b._setupAudioNode(),a(e)):(b.load(),e=b._audioNode[b._audioNode.length-1],e.addEventListener("loadedmetadata",function(){a(e)}))}},_drainPool:function(){var a,b=this,c=0;for(a=0;a<b._audioNode.length;a++)b._audioNode[a].paused&&c++;for(a=b._audioNode.length-1;a>=0&&!(5>=c);a--)b._audioNode[a].paused&&(b._webAudio&&b._audioNode[a].disconnect(0),c--,b._audioNode.splice(a,1))},_clearEndTimer:function(a){var b=this,c=b._onendTimer.indexOf(a);c=c>=0?c:0,b._onendTimer[c]&&(clearTimeout(b._onendTimer[c]),b._onendTimer.splice(c,1))},_setupAudioNode:function(){var a=this,c=a._audioNode,d=a._audioNode.length;return c[d]="undefined"==typeof b.createGain?b.createGainNode():b.createGain(),c[d].gain.value=a._volume,c[d].paused=!0,c[d]._pos=0,c[d].readyState=4,c[d].connect(f),c[d].panner=b.createPanner(),c[d].panner.setPosition(a._pos3d[0],a._pos3d[1],a._pos3d[2]),c[d].panner.connect(c[d]),c[d]},on:function(a,b){var c=this,d=c["_on"+a];if("function"==typeof b)d.push(b);else for(var e=0;e<d.length;e++)b?d[e].call(c,b):d[e].call(c);return c},off:function(a,b){for(var c=this,d=c["_on"+a],e=b.toString(),f=0;f<d.length;f++)if(e===d[f].toString()){d.splice(f,1);break}return c},unload:function(){for(var b=this,c=b._audioNode,d=0;d<b._audioNode.length;d++)c[d].paused||b.stop(c[d].id),b._webAudio?c[d].disconnect(0):c[d].src="";var e=h._howls.indexOf(b);null!==e&&e>=0&&h._howls.splice(e,1),delete a[b._src],b=null}},c)var l=function(c,d){if(d in a)c._duration=a[d].duration,m(c);else{var e=new XMLHttpRequest;e.open("GET",d,!0),e.responseType="arraybuffer",e.onload=function(){b.decodeAudioData(e.response,function(b){b&&(a[d]=b,m(c,b))},function(){c.on("loaderror")})},e.onerror=function(){c._webAudio&&(c._buffer=!0,c._webAudio=!1,c._audioNode=[],delete c._gainNode,c.load())};try{e.send()}catch(f){e.onerror()}}},m=function(a,b){a._duration=b?b.duration:a._duration,0===Object.getOwnPropertyNames(a._sprite).length&&(a._sprite={_default:[0,1e3*a._duration]}),a._loaded||(a._loaded=!0,a.on("load")),a._autoplay&&a.play()},n=function(c,d,e){var f=c._nodeById(e);f.bufferSource=b.createBufferSource(),f.bufferSource.buffer=a[c._src],f.bufferSource.connect(f.panner),f.bufferSource.loop=d[0],d[0]&&(f.bufferSource.loopStart=d[1],f.bufferSource.loopEnd=d[1]+d[2]),f.bufferSource.playbackRate.value=c._rate};"function"==typeof define&&define.amd&&define(function(){return{Howler:h,Howl:k}}),"undefined"!=typeof exports&&(exports.Howler=h,exports.Howl=k),window.Howler=h,window.Howl=k}(),function(){me.plugin=function(){var a={};return a.Base=Object.extend({version:void 0,init:function(){}}),a.patch=function(a,b,c){if(void 0!==a.prototype&&(a=a.prototype),"function"==typeof a[b]){var d=a[b];a[b]=function(a,b){return function(){var a=this.parent;this.parent=d;var c=b.apply(this,arguments);return this.parent=a,c}}(b,c)}else console.error(b+" is not an existing function")},a.register=function(a,b){if(me.plugin[b]&&console.error("plugin "+b+" already registered"),void 0===a.prototype.version)throw"melonJS: Plugin version not defined !";if(me.sys.checkVersion(a.prototype.version)>0)throw"melonJS: Plugin version mismatch, expected: "+a.prototype.version+", got: "+me.version;var c=[];if(arguments.length>2&&(c=Array.prototype.slice.call(arguments,1)),c[0]=a,me.plugin[b]=new(a.bind.apply(a,c)),!(me.plugin[b]instanceof me.plugin.Base))throw"melonJS: Plugin should extend the me.plugin.Base Class !"},a}()}(),me.DraggableEntity=function(a,b,c,d){"use strict";return a.extend({init:function(a,c,e){this.parent(a,c,e),this.dragging=!1,this.dragId=null,this.grabOffset=new d(0,0),this.onPointerEvent=b.registerPointerEvent,this.removePointerEvent=b.releasePointerEvent,this.initEvents()},initEvents:function(){var a=this;this.mouseDown=function(a){this.translatePointerEvent(a,c.DRAGSTART)},this.mouseUp=function(a){this.translatePointerEvent(a,c.DRAGEND)},this.onPointerEvent("mousedown",this,this.mouseDown.bind(this)),this.onPointerEvent("mouseup",this,this.mouseUp.bind(this)),c.subscribe(c.MOUSEMOVE,this.dragMove.bind(this)),c.subscribe(c.DRAGSTART,function(b,c){c===a&&a.dragStart(b)}),c.subscribe(c.DRAGEND,function(b,c){c===a&&a.dragEnd(b)})},translatePointerEvent:function(a,b){c.publish(b,[a,this])},dragStart:function(a){return this.dragging===!1?(this.dragging=!0,this.dragId=a.pointerId,this.grabOffset.set(a.gameX,a.gameY),this.grabOffset.sub(this.pos),!1):void 0},dragMove:function(a){this.dragging===!0&&this.dragId===a.pointerId&&(this.pos.set(a.gameX,a.gameY),this.pos.sub(this.grabOffset))},dragEnd:function(){return this.dragging===!0?(this.pointerId=void 0,this.dragging=!1,!1):void 0},destroy:function(){c.unsubscribe(c.MOUSEMOVE,this.dragMove),c.unsubscribe(c.DRAGSTART,this.dragStart),c.unsubscribe(c.DRAGEND,this.dragEnd),this.removePointerEvent("mousedown",this),this.removePointerEvent("mouseup",this)}})}(me.ObjectEntity,me.input,me.event,me.Vector2d),me.DroptargetEntity=function(a,b){"use strict";return a.extend({CHECKMETHOD_OVERLAP:"overlaps",CHECKMETHOD_CONTAINS:"contains",checkMethod:null,init:function(a,c,d){this.parent(a,c,d),b.subscribe(b.DRAGEND,this.checkOnMe.bind(this)),this.checkMethod=this[this.CHECKMETHOD_OVERLAP]},setCheckMethod:function(a){void 0!==this[a]&&(this.checkMethod=this[a])},checkOnMe:function(a,b){b&&this.checkMethod(b.getBounds().translateV(b.pos))&&this.drop(b)},drop:function(){},destroy:function(){b.unsubscribe(b.DRAGEND,this.checkOnMe)}})}(me.ObjectEntity,me.event,me.Rect),function(){var a=function(){var a=me.video.createCanvas(1,1),b=me.video.getContext2d(a);return b.fillStyle="#fff",b.fillRect(0,0,1,1),a}();me.ParticleEmitterSettings={width:0,height:0,image:a,totalParticles:50,angle:Math.PI/2,angleVariation:0,minLife:1e3,maxLife:3e3,speed:2,speedVariation:1,minRotation:0,maxRotation:0,minStartScale:1,maxStartScale:1,minEndScale:0,maxEndScale:0,gravity:0,wind:0,followTrajectory:!1,textureAdditive:!1,onlyInViewport:!0,floating:!1,maxParticles:10,frequency:100,duration:1/0,framesToSkip:0},me.ParticleEmitter=me.Rect.extend({_stream:!1,_frequencyTimer:0,_durationTimer:0,_enabled:!1,isRenderable:!1,init:function(a,b,c){this.parent(new me.Vector2d(a,b),1/0,1/0),this.autoSort=!1,this.container=new me.ParticleContainer(this),Object.defineProperty(this,"z",{get:function(){return this.container.z},set:function(a){this.container.z=a},enumerable:!0,configurable:!0}),Object.defineProperty(this,"floating",{get:function(){return this.container.floating},set:function(a){this.container.floating=a},enumerable:!0,configurable:!0}),this.reset(c)},destroy:function(){this.reset()},getRandomPoint:function(){var a=this.pos.clone();return a.x+=Number.prototype.random(-this.hWidth,this.hWidth),a.y+=Number.prototype.random(-this.hHeight,this.hHeight),a},reset:function(a){a=a||{};var b=me.ParticleEmitterSettings,c="number"==typeof a.width?a.width:b.width,d="number"==typeof a.height?a.height:b.height;this.resize(c,d),this.image=a.image||b.image,this.totalParticles="number"==typeof a.totalParticles?a.totalParticles:b.totalParticles,this.angle="number"==typeof a.angle?a.angle:b.angle,this.angleVariation="number"==typeof a.angleVariation?a.angleVariation:b.angleVariation,this.minLife="number"==typeof a.minLife?a.minLife:b.minLife,this.maxLife="number"==typeof a.maxLife?a.maxLife:b.maxLife,this.speed="number"==typeof a.speed?a.speed:b.speed,this.speedVariation="number"==typeof a.speedVariation?a.speedVariation:b.speedVariation,this.minRotation="number"==typeof a.minRotation?a.minRotation:b.minRotation,this.maxRotation="number"==typeof a.maxRotation?a.maxRotation:b.maxRotation,this.minStartScale="number"==typeof a.minStartScale?a.minStartScale:b.minStartScale,this.maxStartScale="number"==typeof a.maxStartScale?a.maxStartScale:b.maxStartScale,this.minEndScale="number"==typeof a.minEndScale?a.minEndScale:b.minEndScale,this.maxEndScale="number"==typeof a.maxEndScale?a.maxEndScale:b.maxEndScale,this.gravity="number"==typeof a.gravity?a.gravity:b.gravity,this.wind="number"==typeof a.wind?a.wind:b.wind,this.followTrajectory="boolean"==typeof a.followTrajectory?a.followTrajectory:b.followTrajectory,this.textureAdditive="boolean"==typeof a.textureAdditive?a.textureAdditive:b.textureAdditive,this.onlyInViewport="boolean"==typeof a.onlyInViewport?a.onlyInViewport:b.onlyInViewport,this.floating="boolean"==typeof a.floating?a.floating:b.floating,this.maxParticles="number"==typeof a.maxParticles?a.maxParticles:b.maxParticles,this.frequency="number"==typeof a.frequency?a.frequency:b.frequency,this.duration="number"==typeof a.duration?a.duration:b.duration,this.framesToSkip="number"==typeof a.framesToSkip?a.framesToSkip:b.framesToSkip,this.container.destroy()},addParticles:function(a){for(var b=0;~~a>b;b++){var c=me.pool.pull("me.Particle",this);c.isRenderable=!1,this.container.addChild(c)}},isRunning:function(){return this._enabled&&this._stream},streamParticles:function(a){this._enabled=!0,this._stream=!0,this.frequency=Math.max(this.frequency,1),this._durationTimer="number"==typeof a?a:this.duration},stopStream:function(){this._enabled=!1},burstParticles:function(a){this._enabled=!0,this._stream=!1,this.addParticles("number"==typeof a?a:this.totalParticles),this._enabled=!1},update:function(a){if(this._enabled&&this._stream){if(1/0!==this._durationTimer&&(this._durationTimer-=a,this._durationTimer<=0))return this.stopStream(),!1;this._frequencyTimer+=a;var b=this.container.children.length;b<this.totalParticles&&this._frequencyTimer>=this.frequency&&(this.addParticles(b+this.maxParticles<=this.totalParticles?this.maxParticles:this.totalParticles-b),this._frequencyTimer=0)}return!0}})}(window),function(){me.ParticleContainer=me.ObjectContainer.extend({init:function(a){this.parent(),this.autoSort=!1,this._updateCount=0,this._dt=0,this._emitter=a},update:function(a){if(++this._updateCount>this._emitter.framesToSkip&&(this._updateCount=0),this._updateCount>0)return this._dt+=a,!1;a+=this._dt,this._dt=0;for(var b=me.game.viewport,c=this.children.length-1;c>=0;--c){var d=this.children[c];d.isRenderable=!0,d.inViewport=this.floating||d.pos.x<b.pos.x+b.width&&b.pos.x<d.pos.x+d.width&&d.pos.y<b.pos.y+b.height&&b.pos.y<d.pos.y+d.height,d.update(a)||this.removeChildNow(d)}return!0},draw:function(a,b){if(this.children.length>0){var c;this._emitter.textureAdditive&&(c=a.globalCompositeOperation,a.globalCompositeOperation="lighter"),this.parent(a,b),this._emitter.textureAdditive&&(a.globalCompositeOperation=c)}}})}(window),function(){me.Particle=me.Renderable.extend({init:function(a){this.parent(a.getRandomPoint(),a.image.width,a.image.height),this.alwaysUpdate=!0,this.image=a.image;var b=a.angle+(a.angleVariation>0?(2*Math.random()-1)*a.angleVariation:0),c=a.speed+(a.speedVariation>0?(2*Math.random()-1)*a.speedVariation:0);this.vel=new me.Vector2d(c*Math.cos(b),-c*Math.sin(b)),this.life=Number.prototype.random(a.minLife,a.maxLife),this.startLife=this.life,this.startScale=Number.prototype.random(a.minStartScale,a.maxStartScale).clamp(a.minStartScale,a.maxStartScale),this.endScale=Number.prototype.random(a.minEndScale,a.maxEndScale).clamp(a.minEndScale,a.maxEndScale),this.gravity=a.gravity,this.wind=a.wind,this.followTrajectory=a.followTrajectory,this.onlyInViewport=a.onlyInViewport,this.z=a.z,this._deltaInv=me.sys.fps/1e3,this.transform=new me.Matrix2d,a.followTrajectory||(this.angle=Number.prototype.random(a.minRotation,a.maxRotation))},update:function(a){var b=a*this._deltaInv;this.life=this.life>a?this.life-a:0;var c=this.life/this.startLife,d=this.startScale;this.startScale>this.endScale?(d*=c,d=d<this.endScale?this.endScale:d):this.startScale<this.endScale&&(d/=c,d=d>this.endScale?this.endScale:d),this.alpha=c,this.vel.x+=this.wind*b,this.vel.y+=this.gravity*b;var e=this.followTrajectory?Math.atan2(this.vel.y,this.vel.x):this.angle;return this.transform.set(d,0,0,d,0,0).rotate(e),this.pos.x+=this.vel.x*b,this.pos.y+=this.vel.y*b,(this.inViewport||!this.onlyInViewport)&&this.life>0},draw:function(a){a.save(),a.globalAlpha*=this.alpha;var b=this.transform;a.transform(b.a,b.b,b.c,b.d,~~this.pos.x,~~this.pos.y);var c=this.width,d=this.height;a.drawImage(this.image,0,0,c,d,-c/2,-d/2,c,d),a.restore()}})}(window);