/*
 MinPubSub
 a micro publish/subscribe messaging framework
 @see https://github.com/daniellmb/MinPubSub 
 @author Daniel Lamb <daniellmb.com>

 Released under the MIT License
 MelonJS Game Engine
 Copyright (C) 2012, Olivier BIOT
 http://www.melonjs.org

 melonJS is licensed under the MIT License.
 http://www.opensource.org/licenses/mit-license.php

 Tween JS
 https://github.com/sole/Tween.js
*/
var me=me||{};
(function(a){function c(){if(!f){if(!d.body)return setTimeout(c,13);d.removeEventListener?d.removeEventListener("DOMContentLoaded",c,!1):a.removeEventListener("load",c,!1);f=!0;for(var b=0;b<i.length;b++)i[b].call(a,[]);i.length=0}}function b(){return{xmlDoc:null,parseFromString:function(d){a.DOMParser?this.xmlDoc=(new DOMParser).parseFromString(d,"text/xml"):(this.xmlDoc=new ActiveXObject("Microsoft.XMLDOM"),this.xmlDoc.async="false",this.xmlDoc.loadXML(d));null==this.xmlDoc&&console.log("xml "+this.xmlDoc+
" not found!")},getFirstElementByTagName:function(a){return this.xmlDoc?this.xmlDoc.getElementsByTagName(a)[0]:null},getAllTagElements:function(){return this.xmlDoc?this.xmlDoc.getElementsByTagName("*"):null},getStringAttribute:function(a,d,b){return(a=a.getAttribute(d))?a.trim():b},getIntAttribute:function(a,d,b){return(a=this.getStringAttribute(a,d,b))?parseInt(a):b},getFloatAttribute:function(a,d,b){return(a=this.getStringAttribute(a,d,b))?parseFloat(a):b},getBooleanAttribute:function(a,d,b){return(a=
this.getStringAttribute(a,d,b))?"true"==a:b},free:function(){this.xmlDoc=null}}}var d=a.document;me={mod:"melonJS",version:"0.9.5",nocache:"",audio:null,video:null,timer:null,input:null,state:null,game:null,entityPool:null,levelDirector:null,XMLParser:null,loadingScreen:null,TMXTileMap:null,debug:{displayFPS:!1,renderHitBox:!1,renderCollisionMap:!1,renderDirty:!1}};me.sys={ua:navigator.userAgent.toLowerCase(),sound:!1,localStorage:"object"==typeof a.localStorage,gyro:void 0!==a.DeviceMotionEvent,
nativeBase64:"function"==typeof a.atob,touch:!1,fps:60,interpolation:!1,scale:1,gravity:void 0,useNativeAnimFrame:!1,cacheImage:!1,dirtyRegion:!1,stopOnAudioError:!0,pauseOnBlur:!0,preRender:!1,checkVersion:function(a,d){for(var d=d||me.version,b=a.split("."),c=d.split("."),e=Math.min(b.length,c.length),f=0,g=0;g<e&&!(f=+b[g]-+c[g]);g++);return f?f:b.length-c.length}};var e=!1,g=!1,f=!1,i=[];a.onReady=function(b){g||(g=!0,"complete"===d.readyState?c():(d.addEventListener&&d.addEventListener("DOMContentLoaded",
c,!1),a.addEventListener("load",c,!1)));f?b.call(a,[]):i.push(function(){return b.call(a,[])});return this};a.onReady(function(){if(!e){var c=d.createElement("audio");me.utils.setNocache(d.location.href.match(/\?nocache/)||!1);c.canPlayType&&(me.audio.capabilities.mp3="no"!=c.canPlayType("audio/mpeg")&&""!=c.canPlayType("audio/mpeg"),me.audio.capabilities.ogg="no"!=c.canPlayType('audio/ogg; codecs="vorbis"')&&""!=c.canPlayType('audio/ogg; codecs="vorbis"'),me.audio.capabilities.wav="no"!=c.canPlayType('audio/wav; codecs="1"')&&
""!=c.canPlayType('audio/wav; codecs="1"'),me.sys.sound=me.audio.capabilities.mp3||me.audio.capabilities.ogg||me.audio.capabilities.wav);if(-1<me.sys.ua.search("iphone")||-1<me.sys.ua.search("ipod")||-1<me.sys.ua.search("ipad")||-1<me.sys.ua.search("android"))me.sys.sound=!1;me.sys.touch="createTouch"in d||"ontouchstart"in a;me.timer.init();me.XMLParser=new b;me.loadingScreen=new me.DefaultLoadingScreen;me.state.init();me.entityPool.init();me.levelDirector.reset();e=!0}});var l=!1,m=/xyz/.test(function(){})?
/\bparent\b/:/.*/;Object.extend=function(a){function d(){!l&&this.init&&this.init.apply(this,arguments)}var b=this.prototype;l=!0;var c=new this;l=!1;for(var e in a)c[e]="function"==typeof a[e]&&"function"==typeof b[e]&&m.test(a[e])?function(a,d){return function(){var c=this.parent;this.parent=b[a];var e=d.apply(this,arguments);this.parent=c;return e}}(e,a[e]):a[e];d.prototype=c;d.constructor=d;d.extend=Object.extend;return d};"function"!==typeof Object.create&&(Object.create=function(a){function d(){}
d.prototype=a;return new d});Function.bind||(Function.prototype.bind=function(){var a=this,d=Array.prototype.slice.call(arguments),b=d.shift();return function(){return a.apply(b,d.concat(Array.prototype.slice.call(arguments)))}});"undefined"===typeof Date.now&&(Date.now=function(){return(new Date).getTime()});"undefined"===typeof console&&(console={log:function(){},info:function(){},error:function(){alert(Array.prototype.slice.call(arguments).join(", "))}});Function.prototype.defer=function(){var a=
this,d=Array.prototype.slice.call(arguments);return window.setTimeout(function(){return a.apply(a,d)},0.01)};Object.defineProperty||(Object.defineProperty=function(a,d,b){if(a.__defineGetter__){b.get&&a.__defineGetter__(d,b.get);b.set&&a.__defineSetter__(d,b.set)}else throw"melonJS: Object.defineProperty not supported";});String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+/,"").replace(/\s+$/,"")});String.prototype.isNumeric=function(){return this!=null&&!isNaN(this)&&
this.trim()!=""};String.prototype.isBoolean=function(){return this!=null&&("true"==this.trim()||"false"==this.trim())};String.prototype.contains=function(a){return this.indexOf(a)>-1};String.prototype.toHex=function(){for(var a="",d=0;d<this.length;)a=a+this.charCodeAt(d++).toString(16);return a};Number.prototype.clamp=function(a,d){return this<a?a:this>d?d:+this};Number.prototype.random=function(a,d){return~~(Math.random()*(d-a+1))+a};Number.prototype.round=function(){var a=arguments.length<2?this:
arguments[0],d=Math.pow(10,arguments[1]||arguments[0]||0);return Math.round(a*d)/d};Number.prototype.toHex=function(){return"0123456789ABCDEF".charAt(this-this%16>>4)+"0123456789ABCDEF".charAt(this%16)};Number.prototype.sign=function(){return this<0?-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){a=Array.prototype.indexOf.call(this,a);a!==-1&&Array.prototype.splice.call(this,
a,1);return this};Object.defineProperty(me,"initialized",{get:function(){return e}});var k={},n=[],s,j=[];k.isDirty=!1;k.reset=function(){n.length=0;j.length=0;s=me.game.viewport.getRect();k.makeAllDirty()};k.makeDirty=function(a,d,b){if(d){k.isDirty=true;me.sys.dirtyRegion&&(b?n.push(b.union(a)):a.getRect&&n.push(a.getRect()))}a.visible&&j.unshift(a)};k.makeAllDirty=function(){n.length=0;n.push(s);k.isDirty=true};k.remove=function(a){var d=j.indexOf(a);if(d!=-1){j.splice(d,1);d=a.visible;a.visible=
false;k.makeDirty(a,true);a.visible=d}};k.draw=function(a){for(var d=n.length,b;d--,b=n[d];){for(var c=j.length,e;c--,e=j[c];)(!me.sys.dirtyRegion||!e.isEntity||e.overlaps(b))&&e.draw(a,b);me.debug.renderDirty&&b.draw(a,"white")}};k.flush=function(){if(me.sys.dirtyRegion)n.length=0;j.length=0;k.isDirty=false};var r=me,h={},u=null,q=[],x=!1,v=null;h.viewport=null;h.HUD=null;h.collisionMap=null;h.currentLevel=null;h.NO_OBJECT=0;h.ENEMY_OBJECT=1;h.COLLECTABLE_OBJECT=2;h.ACTION_OBJECT=3;h.onLevelLoaded=
null;h.init=function(a,d){if(!x){a=a||me.video.getWidth();d=d||me.video.getHeight();h.viewport=new me.Viewport(0,0,a,d);u=me.video.getScreenFrameBuffer();me.event.publish(me.event.GAME_INIT);x=true}};h.reset=function(){v&&clearTimeout(v);v=null;x||h.init();h.removeAll();h.viewport&&h.viewport.reset();k.reset();u.setTransform(1,0,0,1,0,0);h.currentLevel={pos:{x:0,y:0}}};h.loadTMXLevel=function(a){h.currentLevel=a;h.collisionMap=h.currentLevel.getLayerByName("collision");(!h.collisionMap||!h.collisionMap.isCollisionMap)&&
console.error("WARNING : no collision map detected");for(var d=h.currentLevel.getLayers(),b=d.length;b--;)d[b].visible&&h.add(d[b]);h.viewport.setBounds(Math.max(h.currentLevel.realwidth,h.viewport.width),Math.max(h.currentLevel.realheight,h.viewport.height));d=h.currentLevel.getObjectGroups();for(b=0;b<d.length;b++)if(d[b].visible)for(var c=0;c<d[b].objects.length;c++)h.addEntity(d[b].objects[c],d[b].z);h.currentLevel.pos.x!=h.currentLevel.pos.y&&u.translate(h.currentLevel.pos.x,h.currentLevel.pos.y);
h.sort();h.onLevelLoaded&&h.onLevelLoaded.call(h.onLevelLoaded,a.name);me.event.publish(me.event.LEVEL_LOADED,[a.name])};h.add=function(a,d){a.z=d?d:a.z;q.push(a)};h.addEntity=function(a,d){var b=me.entityPool.newInstanceOf(a);b&&h.add(b,d)};h.getEntityByName=function(a){for(var d=[],a=a.toLowerCase(),b=q.length,c;b--,c=q[b];)c.name==a&&d.push(c);return d};h.getEntityByGUID=function(a){for(var d=q.length,b;d--,b=q[d];)if(b.isEntity&&b.GUID==a)return b;return null};h.addHUD=function(a,d,b,c,e){if(h.HUD==
null){h.HUD=new me.HUD_Object(a,d,b,c,e);h.add(h.HUD)}};h.disableHUD=function(){if(h.HUD!=null){h.remove(h.HUD);h.HUD=null}};h.update=function(){for(var a=null,d=q.length,b;d--,b=q[d];){var a=me.sys.dirtyRegion&&b.isEntity?b.getRect():null,c=b.update();if(b.isEntity)b.visible=h.viewport.isVisible(b);k.makeDirty(b,c,c?a:null)}h.viewport.update(k.isDirty)&&k.makeAllDirty()};h.remove=function(a,d){a.destroy&&a.destroy();k.remove(a);if(d===true)q.remove(a);else{a.visible=false;if(a.isEntity)a.isEntity=
false;v=function(a){q.remove(a);v=null}.defer(a)}};h.removeAll=function(){for(var a=q.length;a--;)q[a].isPersistent||h.remove(q[a],true);k.flush()};h.sort=function(a){typeof a!=="function"?q.sort(function(a,d){return d.z-a.z}):q.sort(a);h.repaint()};h.collide=function(a){for(var d=null,b=q.length,c;b--,c=q[b];)if(c.visible&&(c.collidable&&c.isEntity&&c!=a)&&(d=c.checkCollision(a)))break;return d};h.repaint=function(){k.makeAllDirty()};h.draw=function(){if(k.isDirty){k.draw(u);h.viewport.draw(u)}k.flush()};
r.game=h;me.ScreenObject=Object.extend({visible:!1,addAsObject:!1,isPersistent:!1,z:999,rect:null,init:function(a,d){this.isPersistent=(this.addAsObject=this.visible=a===true||false)&&d===true||false;this.rect=new me.Rect(new me.Vector2d(0,0),0,0)},reset:function(){me.game.reset();this.onResetEvent.apply(this,arguments);if(this.addAsObject){this.visible=true;this.rect=me.game.viewport.getRect();me.game.add(this,this.z)}me.game.sort()},getRect:function(){return this.rect},destroy:function(){this.onDestroyEvent.apply(this,
arguments)},update:function(){return false},onUpdateFrame:function(){me.timer.update();me.game.update();me.game.draw();me.video.blitSurface()},draw:function(){},onResetEvent:function(){},onDestroyEvent:function(){}});for(var r=me,z=function(){if(A==-1&&y==-1){me.timer.reset();if(me.sys.useNativeAnimFrame){y=window.requestAnimationFrame(B);if(y!=-1)return;me.sys.useNativeAnimFrame=false}A=setInterval(F,J)}},B=function(){F();y=window.requestAnimationFrame(B)},K=function(){if(A!=-1){clearInterval(A);
A=-1}if(y!=-1){window.cancelAnimationFrame(y);y=-1}},L=function(a){K();if(t[w]){t[w].screen.visible&&me.game.remove.call(me.game,t[w].screen,true);t[w].screen.destroy()}if(t[a]){w=a;t[w].screen.reset.apply(t[w].screen,G);F=t[w].screen.onUpdateFrame.bind(t[w].screen);z();H&&H();me.game.repaint()}},D=["ms","moz","webkit","o"],C=0;C<D.length&&!window.requestAnimationFrame;++C)window.requestAnimationFrame=window[D[C]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[D[C]+"CancelAnimationFrame"]||
window[D[C]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(){return-1});window.cancelAnimationFrame||(window.cancelAnimationFrame=function(){return-1});var o={},w=-1,A=-1,y=-1,t={},I="",E=0,H=null,G=null,F=null,J=null;o.LOADING=0;o.MENU=1;o.READY=2;o.PLAY=3;o.GAMEOVER=4;o.GAME_END=5;o.SCORE=6;o.CREDITS=7;o.SETTINGS=8;o.USER=100;o.onPause=null;o.onResume=null;o.init=function(){o.set(o.LOADING,me.loadingScreen);a.addEventListener("blur",function(){me.sys.pauseOnBlur&&
w!=o.LOADING&&o.pause(true);if(o.onPause)o.onPause();me.event.publish(me.event.STATE_PAUSE)},false);a.addEventListener("focus",function(){if(me.sys.pauseOnBlur&&w!=o.LOADING){o.resume(true);me.game.repaint()}if(o.onResume)o.onResume();me.event.publish(me.event.STATE_RESUME)},false);J=~~(1E3/me.sys.fps)};o.pause=function(a){K();a&&me.audio.pauseTrack()};o.resume=function(a){z(w);a&&me.audio.resumeTrack()};o.isRunning=function(){return A!=-1||y!=-1};o.set=function(a,d){t[a]={};t[a].screen=d;t[a].transition=
true};o.current=function(){return t[w].screen};o.transition=function(a,d,b){if(a=="fade"){I=d;E=b}};o.setTransition=function(a,d){t[a].transition=d};o.change=function(a){G=null;arguments.length>1&&(G=Array.prototype.slice.call(arguments,1));if(E&&t[a].transition){H=function(){me.game.viewport.fadeOut(I,E)};me.game.viewport.fadeIn(I,E,function(){L(a)})}else L.defer(a)};o.isCurrent=function(a){return w==a};r.state=o})(window);
(function(a){me.DefaultLoadingScreen=me.ScreenObject.extend({init:function(){this.parent(!0);this.logo1=new me.Font("century gothic",32,"white","middle");this.logo2=new me.Font("century gothic",32,"ORANGE","middle");this.logo2.bold();this.invalidate=!1;this.handle=null;this.loadPercent=0},onResetEvent:function(){this.handle=me.event.subscribe(me.event.LOADER_PROGRESS,this.onProgressUpdate.bind(this))},onDestroyEvent:function(){this.logo1=this.logo2=null;this.handle&&(me.event.unsubscribe(this.handle),
this.handle=null)},onProgressUpdate:function(a){this.loadPercent=a;this.invalidate=!0},update:function(){return!0===this.invalidate?(this.invalidate=!1,!0):!1},draw:function(a){var d=this.logo1.measureText(a,"melon").width,b=(a.canvas.width-d-this.logo2.measureText(a,"JS").width)/2,c=a.canvas.height/2;me.video.clearSurface(a,"ORANGE");this.logo1.draw(a,"...",b,c);this.logo2.draw(a,"ASIKERSOFT",b+d,c);c+=this.logo1.measureText(a,"melon").height/2;d=Math.floor(this.loadPercent*a.canvas.width);a.strokeStyle=
"silver";a.strokeRect(0,c,a.canvas.width,6);a.fillStyle="#89b002";a.fillRect(2,c+2,d-4,2)}});var c=me,b=function(){if(l==i-k){for(var a in g)if(g[a].isTMX&&me.levelDirector.addTMXLevel(a))d.onResourceLoaded();d.onload?(clearTimeout(m),setTimeout(function(){d.onload();me.event.publish(me.event.LOADER_COMPLETE)},300),k=0):console.error("no load callback defined")}else m=setTimeout(b,100)},d={},e=[],g={},f={},i=0,l=0,m=0,k=0;d.onload=void 0;d.onProgress=void 0;d.onResourceLoaded=function(){l++;var a=
d.getLoadProgress();if(d.onProgress)d.onProgress(a);me.event.publish(me.event.LOADER_PROGRESS,[a])};d.onLoadingError=function(a){throw"melonJS: Failed loading resource "+a.src;};d.preload=function(a){for(var c=0;c<a.length;c++)i+=d.load(a[c],d.onResourceLoaded.bind(d),d.onLoadingError.bind(d,a[c]));b()};d.load=function(d,b,c){d.name=d.name.toLowerCase();switch(d.type){case "binary":var m=new XMLHttpRequest;m.open("GET",d.src+me.nocache,!1);m.responseType="arraybuffer";xmlhttp.onerror=c;m.onload=function(){var a=
m.response;if(a){var a=new Uint8Array(a),c=[];f[d.name]=new dataType;for(var e=0;e<a.byteLength;e++)c[e]=String.fromCharCode(a[e]);f[d.name].data=c.join("");b()}};m.send();return 1;case "image":return e.push(d.name),e[d.name]=new Image,e[d.name].onload=b,e[d.name].onerror=c,e[d.name].src=d.src+me.nocache,1;case "tmx":if(a.XMLHttpRequest){var h=new XMLHttpRequest;h.overrideMimeType&&h.overrideMimeType("text/xml")}else h=new ActiveXObject("Microsoft.XMLHTTP");h.open("GET",d.src+me.nocache,!1);h.onerror=
c;h.onload=function(){g[d.name]={};g[d.name].xml=h.responseText;g[d.name].isTMX=!0;b()};h.send();k+=1;return 2;case "audio":me.audio.setLoadCallback(b);if(me.audio.isAudioEnable())return me.audio.load(d),1;break;default:throw"melonJS: me.loader.load : unknow or invalide resource type : %s"+d.type;}return 0};d.getXML=function(a){a=a.toLowerCase();return null!=g?g[a].xml:null};d.getBinary=function(a){a=a.toLowerCase();return null!=f?f[a]:null};d.getImage=function(a){a=a.toLowerCase();if(null!=e[a]){if(!0===
me.sys.cacheImage){var d=me.video.createCanvasSurface(e[a].width,e[a].height);d.drawImage(e[a],0,0);return d.canvas}return e[a]}return null};d.getLoadProgress=function(){return l/i};c.loader=d})(window);
(function(){me.Vector2d=Object.extend({x:0,y:0,init:function(a,c){this.x=a||0;this.y=c||0},set:function(a,c){this.x=a;this.y=c},setZero:function(){this.set(0,0)},setV:function(a){this.x=a.x;this.y=a.y},add:function(a){this.x+=a.x;this.y+=a.y},sub:function(a){this.x-=a.x;this.y-=a.y},scale:function(a){this.x*=a.x;this.y*=a.y},div:function(a){this.x/=a;this.y/=a},abs:function(){0>this.x&&(this.x=-this.x);0>this.y&&(this.y=-this.y)},clamp:function(a,c){return new me.Vector2d(this.x.clamp(a,c),this.y.clamp(a,
c))},clampSelf:function(a,c){this.x=this.x.clamp(a,c);this.y=this.y.clamp(a,c);return this},minV:function(a){this.x=this.x<a.x?this.x:a.x;this.y=this.y<a.y?this.y:a.y},maxV:function(a){this.x=this.x>a.x?this.x:a.x;this.y=this.y>a.y?this.y:a.y},floor:function(){return new me.Vector2d(~~this.x,~~this.y)},floorSelf:function(){this.x=~~this.x;this.y=~~this.y;return this},ceil:function(){return new me.Vector2d(Math.ceil(this.x),Math.ceil(this.y))},ceilSelf:function(){this.x=Math.ceil(this.x);this.y=Math.ceil(this.y);
return this},negate:function(){return new me.Vector2d(-this.x,-this.y)},negateSelf:function(){this.x=-this.x;this.y=-this.y;return this},copy:function(a){this.x=a.x;this.y=a.y},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 c=1/a;this.x*=c;this.y*=c;return 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))},clone:function(){return new me.Vector2d(this.x,this.y)},toString:function(){return"x:"+this.x+"y:"+this.y}});me.Rect=Object.extend({pos:null,colPos:null,width:0,height:0,hWidth:0,hHeight:0,init:function(a,c,b){this.pos=a;this.colPos=new me.Vector2d;this.width=c;this.height=b;this.hWidth=~~(c/2);this.hHeight=~~(b/2);Object.defineProperty(this,"left",{get:function(){return this.pos.x},configurable:!0});Object.defineProperty(this,"right",{get:function(){return this.pos.x+
this.width},configurable:!0});Object.defineProperty(this,"top",{get:function(){return this.pos.y},configurable:!0});Object.defineProperty(this,"bottom",{get:function(){return this.pos.y+this.height},configurable:!0})},set:function(a,c,b){this.pos=a;this.width=c;this.height=b;this.hWidth=~~(c/2);this.hHeight=~~(b/2)},getRect:function(){return new me.Rect(this.pos.clone(),this.width,this.height)},union:function(a){var c=Math.min(this.pos.x,a.pos.x),b=Math.min(this.pos.y,a.pos.y);this.width=Math.ceil(Math.max(this.pos.x+
this.width,a.pos.x+a.width)-c);this.height=Math.ceil(Math.max(this.pos.y+this.height,a.pos.y+a.height)-b);this.pos.x=~~c;this.pos.y=~~b;return this},adjustSize:function(a,c,b,d){-1!=a&&(this.colPos.x=a,this.width=c,this.hWidth=~~(this.width/2),this.left!==this.pos.x+this.colPos.x&&Object.defineProperty(this,"left",{get:function(){return this.pos.x+this.colPos.x},configurable:!0}),this.right!==this.pos.x+this.colPos.x+this.width&&Object.defineProperty(this,"right",{get:function(){return this.pos.x+
this.colPos.x+this.width},configurable:!0}));-1!=b&&(this.colPos.y=b,this.height=d,this.hHeight=~~(this.height/2),this.top!==this.pos.y+this.colPos.y&&Object.defineProperty(this,"top",{get:function(){return this.pos.y+this.colPos.y},configurable:!0}),this.bottom!==this.pos.y+this.colPos.y+this.height&&Object.defineProperty(this,"bottom",{get:function(){return this.pos.y+this.colPos.y+this.height},configurable:!0}))},flipX:function(a){this.colPos.x=a-this.width-this.colPos.x;this.hWidth=~~(this.width/
2)},flipY:function(a){this.colPos.y=a-this.height-this.colPos.y;this.hHeight=~~(this.height/2)},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.left<=this.left&&a.right>=this.right&&a.top<=this.top&&a.bottom>=this.bottom},contains:function(a){return a.left>=this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},
collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,d=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>d?-d:d);c.x<c.y?(c.y=0,c.x=0>b?-c.x:c.x):(c.x=0,c.y=0>d?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle=c||"red";a.strokeRect(this.left-me.game.viewport.pos.x,this.top-me.game.viewport.pos.y,this.width,this.height)}})})(window);
(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,d,c,g,f,i){this.parent(new me.Vector2d(a,d),c-a,g-d);this.limits=new me.Vector2d(f||this.width,i||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH,onComplete:null};this._fadeOut=
{color:0,alpha:0,duration:0,tween:null};this._fadeIn={color:0,alpha:1,duration:0,tween:null};this.setDeadzone(this.width/6,this.height/6)},_followH:function(b){return b.x-this.pos.x>this._deadwidth?(this.pos.x=~~a(b.x-this._deadwidth,this._limitwidth),!0):b.x-this.pos.x<this.deadzone.x?(this.pos.x=~~c(b.x-this.deadzone.x,0),!0):!1},_followV:function(b){return b.y-this.pos.y>this._deadheight?(this.pos.y=~~a(b.y-this._deadheight,this._limitheight),!0):b.y-this.pos.y<this.deadzone.y?(this.pos.y=~~c(b.y-
this.deadzone.y,0),!0):!1},reset:function(a,d){this.pos.x=a||0;this.pos.y=d||0;this.follow_axis=this.target=null},setDeadzone:function(a,d){this.deadzone=new me.Vector2d(~~((this.width-a)/2),~~((this.height-d)/2-0.25*d));this._deadwidth=this.width-this.deadzone.x;this._deadheight=this.height-this.deadzone.y;this.update(!0)},setBounds:function(a,d){this.limits.set(a,d);this._limitwidth=this.limits.x-this.width;this._limitheight=this.limits.y-this.height},follow:function(a,d){if(a instanceof me.ObjectEntity)this.target=
a.pos;else if(a instanceof me.Vector2d)this.target=a;else throw"melonJS: invalid target for viewport.follow";this.follow_axis=d||this.AXIS.BOTH;this.update(!0)},move:function(a,d){var c=~~(this.pos.y+d);this.pos.x=(~~(this.pos.x+a)).clamp(0,this._limitwidth);this.pos.y=c.clamp(0,this._limitheight)},update:function(a){if(this.target&&a)switch(this.follow_axis){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}if(0<this._shake.duration)if(this._shake.duration-=me.timer.tick,0>this._shake.duration){if(this._shake.onComplete)this._shake.onComplete()}else{if(this._shake.axis==this.AXIS.BOTH||this._shake.axis==this.AXIS.HORIZONTAL)a=Math.random()*this._shake.intensity,this.pos.x=this.pos.x+this.width+a<this.limits.x?this.pos.x+~~a:this.pos.x-~~a;if(this._shake.axis==this.AXIS.BOTH||this._shake.axis==this.AXIS.VERTICAL)a=Math.random()*this._shake.intensity,
this.pos.y=this.pos.y+this.height+a<this.limits.y?this.pos.y+~~a:this.pos.y-~~a;a=!0}if(null!=this._fadeIn.tween||null!=this._fadeOut.tween)a=!0;return a},shake:function(a,d,c,g){c=c||this.AXIS.BOTH;c==this.AXIS.BOTH&&(this.width==this.limits.x?c=this.AXIS.VERTICAL:this.height==this.limits.y&&(c=this.AXIS.HORIZONTAL));!(c==this.AXIS.HORIZONTAL&&this.width==this.limits.x)&&!(c==this.AXIS.VERTICAL&&this.height==this.limits.y)&&(this._shake.intensity=a,this._shake.duration=d,this._shake.axis=c,this._shake.onComplete=
g||null)},fadeOut:function(a,d,c){this._fadeOut.color=a;this._fadeOut.duration=d||1E3;this._fadeOut.alpha=1;this._fadeOut.tween=(new me.Tween(this._fadeOut)).to({alpha:0},this._fadeOut.duration).onComplete(c||null);this._fadeOut.tween.start()},fadeIn:function(a,d,c){this._fadeIn.color=a;this._fadeIn.duration=d||1E3;this._fadeIn.alpha=0;this._fadeIn.tween=(new me.Tween(this._fadeIn)).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){this.pos.x=a.x-0.5*this.width;this.pos.y=a.y-0.5*this.height},isVisible:function(a){return a.overlaps(this)},draw:function(a){this._fadeIn.tween&&(a.globalAlpha=this._fadeIn.alpha,me.video.clearSurface(a,me.utils.HexToRGB(this._fadeIn.color)),a.globalAlpha=1,1==this._fadeIn.alpha&&(this._fadeIn.tween=null));this._fadeOut.tween&&(a.globalAlpha=this._fadeOut.alpha,me.video.clearSurface(a,me.utils.HexToRGB(this._fadeOut.color)),a.globalAlpha=
1,0==this._fadeOut.alpha&&(this._fadeOut.tween=null))}})})(window);
(function(){me.SpriteObject=me.Rect.extend({scale:null,scaleFlag:!1,lastflipX:!1,lastflipY:!1,z:0,offset:null,visible:!0,angle:0,anchorPoint:null,image:null,flickering:!1,flickerTimer:-1,flickercb:null,flickerState:!1,vp:null,init:function(a,c,b,d,e){this.parent(new me.Vector2d(a,c),d||b.width,e||b.height);this.image=b;this.scale=new me.Vector2d(1,1);this.vp=me.game.viewport;this.offset=new me.Vector2d(0,0);this.anchorPoint=new me.Vector2d(0.5,0.5);this.spritecount=new me.Vector2d(~~(this.image.width/
this.width),~~(this.image.height/this.height))},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,c){this.flickerTimer=a;0>this.flickerTimer?(this.flickering=!1,this.flickercb=null):this.flickering||(this.flickercb=c,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){0<a&&(this.scale.x=0>this.scale.x?-a:a,this.scale.y=0>this.scale.y?-a:a,this.scaleFlag=1!=this.scale.x||1!=this.scale.y)},update:function(){return this.flickering?(this.flickerTimer-=me.timer.tick,0>this.flickerTimer&&(this.flickercb&&this.flickercb(),this.flicker(-1)),!0):!1},draw:function(a){if(this.flickering&&
(this.flickerState=!this.flickerState,!this.flickerState))return;var c=~~(this.pos.x-this.vp.pos.x),b=~~(this.pos.y-this.vp.pos.y);if(this.scaleFlag||0!==this.angle){a.save();var d=this.width*this.anchorPoint.x,e=this.height*this.anchorPoint.y;a.translate(c+d,b+e);this.scaleFlag&&a.scale(this.scale.x,this.scale.y);0!==this.angle&&a.rotate(this.angle);c=-d;b=-e}a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,c,b,this.width,this.height);(this.scaleFlag||0!==this.angle)&&a.restore();
me.debug.renderHitBox&&this.parent(a,"blue")},destroy:function(){this.onDestroyEvent.apply(this,arguments)},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationpause:!1,animationspeed:0,init:function(a,c,b,d,e){this.anim=[];this.current=this.resetAnim=null;this.parent(a,c,b,d,e);1==this.spritecount.x*this.spritecount.y&&(this.setAnimationFrame=function(){});this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},
addAnimation:function(a,c){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==c)for(var c=[],b=0,d=this.spritecount.x*this.spritecount.y;b<d;b++)c[b]=b;b=0;for(d=c.length;b<d;b++)this.anim[a].frame[b]=new me.Vector2d(this.width*(c[b]%this.spritecount.x),this.height*~~(c[b]/this.spritecount.x));this.anim[a].length=this.anim[a].frame.length},setCurrentAnimation:function(a,c){this.current=this.anim[a];this.resetAnim=c||null;this.setAnimationFrame(this.current.idx)},isCurrentAnimation:function(a){return this.current.name==
a},setAnimationFrame:function(a){this.current.idx=(a||0)%this.current.length;this.offset=this.current.frame[this.current.idx]},update:function(){this.parent();return this.visible&&!this.animationpause&&this.fpscount++>this.animationspeed?(this.setAnimationFrame(++this.current.idx),this.fpscount=0,0==this.current.idx&&this.resetAnim&&("string"==typeof this.resetAnim?this.setCurrentAnimation(this.resetAnim):"function"==typeof this.resetAnim&&this.resetAnim()),!0):!1}})})(window);
(function(){me.ObjectSettings={name:null,image:null,transparent_color:null,spritewidth:null,spriteheight:null,type:0,collidable:!1};var a=me,c={},b={};c.init=function(){c.add("me.LevelEntity",me.LevelEntity);c.add("me.ObjectEntity",me.ObjectEntity);c.add("me.CollectableEntity",me.CollectableEntity);c.add("me.InvisibleEntity",me.InvisibleEntity)};c.add=function(a,c){b[a.toLowerCase()]=c};c.newInstanceOf=function(a){var c=a.name?a.name.toLowerCase():void 0;return!c?null:!b[c]?(console.error("cannot instance entity of type '"+
c+"': Class not found!"),null):new b[c](a.x,a.y,a)};a.entityPool=c;me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,collisionBox:null,init:function(a,b,c){this.parent(a,b,"string"==typeof c.image?me.loader.getImage(c.image):c.image,c.spritewidth,c.spriteheight);c.transparent_color&&this.setTransparency(c.transparent_color);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;
this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=void 0!=me.sys.gravity?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=c.collidable||!1;this.type=c.type||0;this.collisionMap=me.game.collisionMap;this.collisionBox=new me.Rect(this.pos,this.width,this.height);this.canBreakTile=!1;this.onTileBreak=null},updateColRect:function(a,b,c,f){this.collisionBox.adjustSize(a,b,c,f)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);
return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(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.parent(a),this.collisionBox.flipX(this.width))},
flipY:function(a){a!=this.lastflipY&&(this.parent(a),this.collisionBox.flipY(this.height))},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()},distanceTo:function(a){var b=
this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){this.gravity&&(a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0<a.y)?!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=this.collisionMap.checkCollision(this.collisionBox,this.vel);this.onslope=a.yprop.isSlope||a.xprop.isSlope;this.onladder=!1;if(a.y)if(this.onladder=a.yprop.isLadder,0<a.y)if(a.yprop.isSolid||a.yprop.isPlatform&&this.collisionBox.bottom-
1<=a.ytile.pos.y)this.pos.y=~~this.pos.y,this.vel.y=this.falling?a.ytile.pos.y-this.collisionBox.bottom:0,this.falling=!1;else if(a.yprop.isSlope&&!this.jumping)this.checkSlope(a.ytile,a.yprop.isLeftSlope),this.falling=!1;else{if(a.yprop.isBreakable)if(this.canBreakTile){if(me.game.currentLevel.clearTile(a.ytile.row,a.ytile.col),this.onTileBreak)this.onTileBreak()}else this.pos.y=~~this.pos.y,this.vel.y=this.falling?a.ytile.pos.y-this.collisionBox.bottom:0,this.falling=!1}else 0>a.y&&(!a.yprop.isPlatform&&
!a.yprop.isLadder)&&(this.falling=!0,this.vel.y=0);if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a},draw:function(a){this.parent(a);if(me.debug.renderHitBox){this.collisionBox.draw(a,
"red");var b=~~(this.pos.x+this.hWidth-this.vp.pos.x),c=~~(this.pos.y+this.hHeight-this.vp.pos.y);a.lineWidth=1;a.beginPath();a.moveTo(b,c);a.lineTo(b+~~(this.vel.x*this.hWidth),c+~~(this.vel.y*this.hHeight));a.stroke()}}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);
this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,f){this.collisionBox.adjustSize(a,b,c,f)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){},destroy:function(){this.onDestroyEvent.apply(this,arguments)},onDestroyEvent:function(){},
update:function(){return!1},draw:function(a){me.debug.renderHitBox&&(a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height),this.collisionBox.draw(a))}});me.LevelEntity=me.InvisibleEntity.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(){me.Font=Object.extend({ALIGN:{LEFT:"left",CENTER:"center",RIGHT:"right"},font:null,height:null,color:null,align:null,init:function(a,c,b,d){this.set(a,c,b,d)},bold:function(){this.font="bold "+this.font},italic:function(){this.font="italic "+this.font},set:function(a,c,b,d){this.font=""+c+"px "+a;this.height=c;this.color=b;this.align=d||"top"},getRect:function(){return new me.Rect(new Vector2d(0,0),0,0)},measureText:function(a,c){a.font=this.font;a.fillStyle=this.color;a.textBaseline=
this.align;var b=a.measureText(c);b.height=this.height;return b},draw:function(a,c,b,d){a.font=this.font;a.fillStyle=this.color;a.textBaseline=this.align;a.fillText(c,~~b,~~d)}});me.BitmapFont=me.Font.extend({size:null,sSize:null,firstChar:32,charCount:0,init:function(a,c,b,d){this.parent(a,null,null);this.size=new me.Vector2d;this.sSize=new me.Vector2d;this.firstChar=d||32;this.loadFontMetrics(a,c);this.align=this.ALIGN.RIGHT;b&&this.resize(b)},loadFontMetrics:function(a,c){this.font=me.loader.getImage(a);
this.size.x=c.x||c;this.size.y=c.y||this.font.height;this.sSize.copy(this.size);this.charCount=~~(this.font.width/this.size.x)},set:function(a,c){this.align=a;c&&this.resize(c)},resize:function(a){this.sSize.copy(this.size);this.sSize.x*=a;this.sSize.y*=a},measureText:function(a){return{width:a.length*this.sSize.x,height:this.sSize.y}},draw:function(a,c,b,d){c=new String(c);switch(this.align){case this.ALIGN.RIGHT:b-=this.measureText(c).width;break;case this.ALIGN.CENTER:b-=0.5*this.measureText(c).width}for(var e=
0,g=c.length;e<g;e++){var f=c.charCodeAt(e)-this.firstChar;a.drawImage(this.font,this.size.x*(f%this.charCount),this.size.y*~~(f/this.charCount),this.size.x,this.size.y,~~b,~~d,this.sSize.x,this.sSize.y);b+=this.sSize.x}}})})(window);
(function(){me.GUI_Object=me.SpriteObject.extend({isClickable:!0,updated:!1,init:function(a,c,b){this.parent(a,c,"string"==typeof b.image?me.loader.getImage(b.image):b.image,b.spritewidth,b.spriteheight);me.input.registerMouseEvent("mousedown",this,this.clicked.bind(this))},update:function(){return this.updated?(this.updated=!1,!0):!1},clicked:function(){if(this.isClickable)return this.updated=!0,this.onClicked()},onClicked:function(){return!0},onDestroyEvent:function(){me.input.releaseMouseEvent("mousedown",
this)}})})(window);
(function(){me.HUD_Item=Object.extend({init:function(a,c,b){this.pos=new me.Vector2d(a||0,c||0);this.visible=!0;this.defaultvalue=b||0;this.value=b||0;this.updated=!0},reset:function(){this.set(this.defaultvalue)},set:function(a){this.value=a;return this.updated=!0},update:function(a){return this.set(this.value+a)},draw:function(){}});me.HUD_Object=me.Rect.extend({init:function(a,c,b,d,e){this.parent(new me.Vector2d(a||0,c||0),b||me.video.getWidth(),d||me.video.getHeight());this.bgcolor=e;this.HUDItems=
{};this.HUDobj=[];this.objCount=0;this.HUD_invalidated=this.visible=!0;this.HUDCanvasSurface=me.video.createCanvasSurface(this.width,this.height);this.z=999;this.isPersistent=!0},addItem:function(a,c){this.HUDItems[a]=c;this.HUDobj.push(this.HUDItems[a]);this.objCount++;this.HUD_invalidated=!0},removeItem:function(a){this.HUDItems[a]&&(this.HUDobj.splice(this.HUDobj.indexOf(this.HUDItems[a]),1),this.HUDItems[a]=null,this.objCount--,this.HUD_invalidated=!0)},setItemValue:function(a,c){this.HUDItems[a]&&
!0==this.HUDItems[a].set(c)&&(this.HUD_invalidated=!0)},updateItemValue:function(a,c){this.HUDItems[a]&&!0==this.HUDItems[a].update(c)&&(this.HUD_invalidated=!0)},getItemValue:function(a){return this.HUDItems[a]?this.HUDItems[a].value:0},update:function(){return this.HUD_invalidated},reset:function(a){void 0!=a?(this.HUDItems[a]&&this.HUDItems[a].reset(),this.HUD_invalidated=!0):this.resetAll()},resetAll:function(){for(var a=this.objCount,c;a--,c=this.HUDobj[a];)c.reset();this.HUD_invalidated=!0},
getRect:function(){p=this.pos.clone();p.add(me.game.viewport.pos);return new me.Rect(p,this.width,this.height)},draw:function(a){if(this.HUD_invalidated){this.bgcolor?me.video.clearSurface(this.HUDCanvasSurface,this.bgcolor):this.HUDCanvasSurface.canvas.width=this.HUDCanvasSurface.canvas.width;for(var c=this.objCount,b;c--,b=this.HUDobj[c];)b.visible&&(b.draw(this.HUDCanvasSurface,0,0),b.updated&&(b.updated=!1))}c=me.game.currentLevel.pos;a.drawImage(this.HUDCanvasSurface.canvas,this.pos.x-c.x,this.pos.y-
c.y);this.HUD_invalidated=!1}})})(window);
(function(){var a=me,c=function(a){for(var a=g[a],b=0,d;d=a[b++];)if(d.ended||!d.currentTime)return d.currentTime=s,d;a[0].pause();a[0].currentTime=s;return a[0]},b=function(a,b,d){var e=c(a.toLowerCase());e.loop=b||!1;e.play();d&&!b&&e.addEventListener("ended",function(a){e.removeEventListener("ended",arguments.callee,!1);d()},!1)},d=function(a,b,d){d&&!b&&setTimeout(d,2E3)},e={},g=[],f=["mp3","ogg","wav"],i=null,l=-1,m=null,k=null,n=!0,s=0,j=0;e.capabilities={mp3:!1,ogg:!1,ma4:!1,wav:!1};e.init=
function(a){if(!me.initialized)return console.error("melonJS: me.audio.init() called before engine initialization."),!1;i=a?new String(a):new String("mp3");var c=a="",g=null,m=0,j=f.length;if(me.sys.sound)for(;m<j;m++)if(c=f[m],g=RegExp(c,"i"),-1!=i.search(g)&&e.capabilities[c]){a=c;break}""===a&&(n=!1);l=a;e.play=n?b:d;return n};e.setLoadCallback=function(a){m=a};e.isAudioEnable=function(){return n};e.enable=function(){n=me.sys.sound;e.play=n?b:d};e.disable=function(){n=!1;e.play=d};e.load=function(a){if(-1==
l)return 0;var b=new Audio(a.src+a.name+"."+l+me.nocache);b.preload="auto";b.addEventListener("canplaythrough",function(b){this.removeEventListener("canplaythrough",arguments.callee,!1);var d=a.name,c=a.channel;j=0;if(1<c)for(var e=g[d][0],f=1;f<c;f++){var B=e.cloneNode(!0);0==B.currentSrc.length&&(B.src=e.src);g[d][f]=B;g[d][f].load()}m&&m()},!1);b.addEventListener("error",function(){var b=a.name;if(3<j++)if(b="melonJS: failed loading "+b+"."+l,!1===me.sys.stopOnAudioError)me.audio.disable(),m&&
m(),console.log(b+", disabling audio");else throw b;else g[b][0].load()},!1);b.src=a.src+a.name+"."+l+me.nocache;b.load();g[a.name]=[b];return 1};e.stop=function(a){if(n)for(var a=g[a.toLowerCase()],b=a.length;b--;)a[b].pause(),a[b].currentTime=s};e.pause=function(a){if(n)for(var a=g[a.toLowerCase()],b=a.length;b--;)a[b].pause()};e.playTrack=function(a){if(n&&(null!=k&&e.stopTrack(),k=c(a.toLowerCase())))k.loop=!0,k.play()};e.stopTrack=function(){n&&k&&(k.pause(),k=null)};e.pauseTrack=function(){n&&
k&&k.pause()};e.resumeTrack=function(){n&&k&&k.play()};a.audio=e})(window);
(function(){var a=me,c={},b=null,d=!1,e=0,g=0,f=0,i=0,l=0,m=Math.ceil(1E3/me.sys.fps),k=1.25*(1E3/me.sys.fps);c.tick=1;c.init=function(){b=document.getElementById("framecounter");d=null!==b;c.reset()};c.reset=function(){i=f=Date.now();e=g=0};c.getTime=function(){return i};c.update=function(){f=i;i=Date.now();l=i-f;if(d&&(e++,g+=l,0==e%10)){var a=(~~(1E3*e/g)).clamp(0,me.sys.fps);b.replaceChild(document.createTextNode("("+a+"/"+me.sys.fps+" fps)"),b.firstChild);e=g=0}c.tick=l>k&&me.sys.interpolation?
l/m:1};a.timer=c;var a=me,n={},s=null,j=null,r=null,h=null,u=null,q=!1,x=0,v=0;n.init=function(a,b,d,c,e){if(!me.initialized)return console.error("melonJS: me.video.init() called before engine initialization."),!1;q=c||!1;me.sys.scale=!0===q?e||1:1;x=b*me.sys.scale;v=d*me.sys.scale;s=document.createElement("canvas");s.setAttribute("width",screen.width+"px");s.setAttribute("height",screen.height+"px");s.setAttribute("border","0px solid black");u=a?document.getElementById(a):document.body;u.appendChild(s);if(!s.getContext)return!1;
j=s.getContext("2d");q?(h=n.createCanvasSurface(b,d),r=h.canvas):(h=j,r=j.canvas);return!0};n.getWrapper=function(){return u};n.getWidth=function(){return r.width};n.getPos=function(a){for(var a=a||s,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};n.getHeight=function(){return r.height};n.createCanvasSurface=function(a,b){var d=document.createElement("canvas");d.width=a||r.width;d.height=b||r.height;return d.getContext("2d")};n.getScreenCanvas=
function(){return s};n.getScreenFrameBuffer=function(){return h};n.updateDisplaySize=function(a){q&&(me.sys.scale=a?a:document.getElementById("screen size").value,x=r.width*me.sys.scale,v=r.height*me.sys.scale,s.width=x,s.height=v)};n.clearSurface=function(a,b){a.save();a.setTransform(1,0,0,1,0,0);a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height);a.restore()};n.scale=function(a,b){a.translate(-(a.canvas.width*b-a.canvas.width>>1),-(a.canvas.height*b-a.canvas.height>>1));a.scale(b,b)};n.setAlpha=
function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};n.blitSurface=function(){n.blitSurface=q?function(){j.drawImage(r,0,0,r.width,r.height,0,0,x,v)}:function(){};n.blitSurface()};n.applyRGBFilter=function(a,b,d){var c=n.createCanvasSurface(a.width,a.height),a=me.utils.getPixels(a),e=a.data;switch(b){case "b&w":for(var b=0,f=e.length;b<f;b+=4)d=3*e[b]+4*e[b+1]+e[b+2]>>>3,e[b]=d,e[b+1]=d,e[b+2]=d;break;case "brightness":d=Math.abs(d).clamp(0,1);b=0;for(f=e.length;b<f;b+=4)e[b]*=d,e[b+1]*=
d,e[b+2]*=d;break;case "transparent":b=0;for(f=e.length;b<f;b+=4)me.utils.RGBToHex(e[b],e[b+1],e[b+2])===d&&(e[b+3]=0);break;default:return null}c.putImageData(a,0,0);return c};a.video=n})(window);
(function(a){var c=me,b=function(){v||(j.touches.push({x:0,y:0}),j.mouse.pos=new me.Vector2d(0,0),j.mouse.offset=me.video.getPos(),me.sys.touch?(me.video.getScreenCanvas().addEventListener("touchmove",m,!1),me.video.getScreenCanvas().addEventListener("touchstart",n,!1),me.video.getScreenCanvas().addEventListener("touchend",n,!1)):(a.addEventListener("mousewheel",l,!1),me.video.getScreenCanvas().addEventListener("mousemove",m,!1),me.video.getScreenCanvas().addEventListener("mousedown",k,!1),me.video.getScreenCanvas().addEventListener("mouseup",
k,!1)),v=!0)},d=function(a){a.stopPropagation?a.stopPropagation():a.cancelBubble=!0;a.preventDefault?a.preventDefault():a.returnValue=!1},e=function(a,b){var c=r[b||a.keyCode||a.which];return c?(q[c]||(h[c]=!0,q[c]=u[c]),d(a),!1):!0},g=function(a,b){var c=r[b||a.keyCode||a.which];return c?(h[c]=!1,q[c]=!1,d(a),!1):!0},f=function(a){var b=me.game.viewport.pos,d=me.game.currentLevel.pos,c=j.mouse.handlers[a.type];if(c)for(var e=0,f=j.touches.length;e<f;e++)for(var g=j.touches[e].x,m=j.touches[e].y,
h=c.length,k;h--,k=c[h];){var i=!1===k.floating?{x:g+b.x-d.x,y:m+b.y-d.y}:{x:g,y:m};if((null===k.rect||k.rect.containsPoint(i))&&!1===k.cb(a))break}},i=function(a){j.touches.length=0;if(a.touches)for(var b=j.mouse.offset,d=0,c=a.changedTouches.length;d<c;d++){var e=a.changedTouches[d],f=e.clientX-b.x,g=e.clientY-b.y;1!=me.sys.scale&&(f/=me.sys.scale,g/=me.sys.scale);j.touches.push({x:f,y:g,id:e.identifier})}else{var b=j.mouse.offset,f=a.pageX-b.x,g=a.pageY-b.y;1!=me.sys.scale&&(f/=me.sys.scale,g/=
me.sys.scale);j.touches.push({x:f,y:g,id:0})}j.mouse.pos.set(j.touches[0].x,j.touches[0].y)},l=function(a){f(a);d(a)},m=function(a){i(a);f(a);d(a)},k=function(a){var b=j.mouse.bind[a.button||0];f(a);b?"mousedown"===a.type||"touchstart"===a.type?e(a,b):g(a,b):d(a)},n=function(a){i(a);k(a)},s=function(a){j.accel=a.accelerationIncludingGravity},j={},r={},h={},u={},q={},x=!1,v=!1,z=!1;j.accel={x:0,y:0,z:0};j.mouse={pos:null,offset:null,LEFT:0,MIDDLE:1,RIGHT:2,bind:[3],handlers:{}};j.touches=[];j.KEY=
{LEFT:37,UP:38,RIGHT:39,DOWN:40,ENTER:13,SHIFT:16,CTRL:17,ALT:18,PAUSE:19,ESC:27,SPACE:32,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};j.isKeyPressed=function(a){return h[a]?(u[a]&&(q[a]=!0,h[a]=!1),!0):!1};j.keyStatus=function(a){return!0===q[a]?!0:h[a]};j.triggerKeyEvent=function(a,b){b?e({},a):g({},a)};j.bindKey=function(b,d,c){x||
(a.addEventListener("keydown",e,!1),a.addEventListener("keyup",g,!1),x=!0);r[b]=d;h[d]=!1;u[d]=c?c:!1;q[d]=!1};j.unbindKey=function(a){h[r[a]]=!1;u[r[a]]=!1;r[a]=null};j.bindMouse=function(a,d){b();if(!r[d])throw"melonJS : no action defined for keycode "+d;j.mouse.bind[a]=d};j.unbindMouse=function(a){j.mouse.bind[a]=null};j.bindTouch=function(a){j.bindMouse(me.input.mouse.LEFT,a)};j.unbindTouch=function(){j.unbindMouse(me.input.mouse.LEFT)};j.registerMouseEvent=function(a,d,c,e){b();switch(a){case "mousewheel":case "mousemove":case "mousedown":case "mouseup":case "touchmove":case "touchstart":case "touchend":me.sys.touch&&
("mousemove"==a?a="touchmove":"mousedown"==a?a="touchstart":"mouseup"==a&&(a="touchend"));j.mouse.handlers[a]||(j.mouse.handlers[a]=[]);j.mouse.handlers[a].push({rect:d||null,cb:c,floating:!0===e?!0:!1});break;default:throw"melonJS : invalid event type : "+a;}};j.releaseMouseEvent=function(a,b){switch(a){case "mousewheel":case "mousemove":case "mousedown":case "mouseup":case "touchmove":case "touchstart":case "touchend":me.sys.touch&&("mousemove"==a?a="touchmove":"mousedown"==a?a="touchstart":"mouseup"==
a&&(a="touchend"));var d=j.mouse.handlers[a];if(d)for(var c=d.length,e;c--,e=d[c];)e.rect===b&&(e.rect=e.cb=e.floating=null,j.mouse.handlers[a].splice(c,1));break;default:throw"melonJS : invalid event type : "+a;}};j.watchAccelerometer=function(){return a.sys.gyro?(z||(a.addEventListener("devicemotion",s,!1),z=!0),!0):!1};j.unwatchAccelerometer=function(){z&&(a.removeEventListener("devicemotion",s,!1),z=!1)};c.input=j})(window);
(function(a){var c={decode:function(b){b=b.replace(/[^A-Za-z0-9\+\/\=]/g,"");if(me.sys.nativeBase64)return a.atob(b);for(var d=[],c,e,f,g,h,i=0;i<b.length;)c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(i++)),e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(i++)),g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(i++)),h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(i++)),
c=c<<2|e>>4,e=(e&15)<<4|g>>2,f=(g&3)<<6|h,d.push(String.fromCharCode(c)),64!=g&&d.push(String.fromCharCode(e)),64!=h&&d.push(String.fromCharCode(f));return d=d.join("")}},b=me,d={},e={},g="",f=0,i=/^.*(\\|\/|\:)/,l=/\.[^\.]*$/;d.decodeBase64=function(a){return c.decode(a)};d.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),e=[],f,g,h;f=0;for(h=d.length/b;f<h;f++){e[f]=0;for(g=b-1;0<=g;--g)e[f]+=d.charCodeAt(f*b+g)<<(g<<3)}return e};d.decodeCSV=function(a,b){for(var a=a.trim().split("\n"),
d=[],c=0;c<a.length;c++){entries=a[c].split(",",b);for(var e=0;e<entries.length;e++)d.push(+entries[e])}return d};d.getBasename=function(a){return a.replace(i,"").replace(l,"")};d.setNocache=function(a){me.nocache=a?"?"+parseInt(1E7*Math.random()):""};d.HexToRGB=function(a,b){if("#"!==a.charAt(0))return a;a=a.substring(1,a.length);if(null==e[a]){if(6>a.length)var d=a.charAt(0)+a.charAt(0),c=a.charAt(1)+a.charAt(1),f=a.charAt(2)+a.charAt(2);else d=a.substring(0,2),c=a.substring(2,4),f=a.substring(4,
6);e[a]=parseInt(d,16)+","+parseInt(c,16)+","+parseInt(f,16)}return(b?"rgba(":"rgb(")+e[a]+(b?","+b+")":")")};d.RGBToHex=function(a,b,d){return a.toHex()+b.toHex()+d.toHex()};d.getPixels=function(a){if(a instanceof HTMLImageElement){var b=me.video.createCanvasSurface(a.width,a.height);b.drawImage(a,0,0);return b.getImageData(0,0,a.width,a.height)}return a.getContext("2d").getImageData(0,0,a.width,a.height)};d.resetGUID=function(a){g=a.toString().toUpperCase().toHex();f=0};d.createGUID=function(){return g+
"-"+f++};d.applyFriction=function(a,b){return 0>a+b?a+b*me.timer.tick:0<a-b?a-b*me.timer.tick:0};b.utils=d})(window);
(function(){function a(a){this.defaultvalue=a||0;this.value=a||0;this.updated=!0}a.prototype.reset=function(){this.set(this.defaultvalue)};a.prototype.update=function(a){return this.set(this.value+a)};a.prototype.set=function(a){this.value=a;return this.updated=!0};var c=me,b={},d={},e=[],g=0;b.add=function(b,c){if(b.constructor===Object)for(var l in b){var m=l;d[m]=new a(b[l]);e.push(d[m]);g++}else d[b]=new a(c),e.push(d[b]),g++};b.updateValue=function(a,b){if(a.constructor===Object)for(var c in a)d[c]&&
d[c].update(a[c]);else d[a]&&d[a].update(b)};b.setValue=function(a,b){if(a.constructor===Object)for(var c in a)d[c]&&d[c].set(a[c]);else d[a]&&d[a].set(b)};b.getItemValue=function(a){return d[a]?d[a].value:0};b.reset=function(a){void 0!=a?d[a]&&d[a].reset():b.resetAll()};b.resetAll=function(){for(var a=g,b;a--,b=e[a];)b.reset()};c.gamestat=b})(window);
(function(){me.LevelConstants={COLLISION_MAP:"collision",PARALLAX_MAP:"parallax"};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_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_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_POINTS="points";me.TMX_BACKGROUND_COLOR="backgroundcolor"})(window);
(function(){me.TMXUtils={setTMXProperties:function(a,c){var b=c.getElementsByTagName(me.TMX_TAG_PROPERTIES)[0];if(b)for(var b=b.getElementsByTagName(me.TMX_TAG_PROPERTY),d=0;d<b.length;d++){var e=me.XMLParser.getStringAttribute(b[d],me.TMX_TAG_NAME),g=me.XMLParser.getStringAttribute(b[d],me.TMX_TAG_VALUE);!g||g.isBoolean()?g=g?"true"==g:!0:g.isNumeric()&&(g=Number(g));a[e]=g}},mergeProperties:function(a,c,b){for(var d in c)if(b||void 0===a[d])a[d]=c[d];return a}}})(window);
(function(){me.TMXOBjectGroup=Object.extend({init:function(a,c,b,d){this.objects=[];this.name=a;this.width=me.XMLParser.getIntAttribute(c,me.TMX_TAG_WIDTH);this.height=me.XMLParser.getIntAttribute(c,me.TMX_TAG_HEIGHT);this.visible=1==me.XMLParser.getIntAttribute(c,me.TMX_TAG_VISIBLE,1);this.z=d;c.firstChild&&c.firstChild.nextSibling.nodeName===me.TMX_TAG_PROPERTIES&&me.TMXUtils.setTMXProperties(this,c);a=c.getElementsByTagName(me.TMX_TAG_OBJECT);for(c=0;c<a.length;c++)this.objects.push(new me.TMXOBject(a[c],
b,d))},reset:function(){this.objects=null},getObjectCount:function(){return this.objects.length},getObjectByIndex:function(a){return this.objects[a]}});me.TMXOBject=Object.extend({init:function(a,c,b){this.name=me.XMLParser.getStringAttribute(a,me.TMX_TAG_NAME);this.x=me.XMLParser.getIntAttribute(a,me.TMX_TAG_X);this.y=me.XMLParser.getIntAttribute(a,me.TMX_TAG_Y);this.z=b;this.width=me.XMLParser.getIntAttribute(a,me.TMX_TAG_WIDTH,0);this.height=me.XMLParser.getIntAttribute(a,me.TMX_TAG_HEIGHT,0);
if(this.gid=me.XMLParser.getIntAttribute(a,me.TMX_TAG_GID,null))c=c.getTilesetByGid(this.gid),this.width=c.tilewidth,this.height=c.tileheight,this.spritewidth=this.width,this.y-=this.height,b=new me.Tile(this.x,this.y,c.tilewidth,c.tileheight,this.gid),this.image=c.getTileImage(b);else if(c=a.getElementsByTagName(me.TMX_TAG_POLYGON),this.isPolygon=!0,c.length||(c=a.getElementsByTagName(me.TMX_TAG_POLYLINE),this.isPolygon=!1),c.length){this.points=[];for(var c=me.XMLParser.getStringAttribute(c[0],
me.TMX_TAG_POINTS).split(" "),b=0,d;b<c.length;b++)d=c[b].split(","),this.points[b]=new me.Vector2d(+d[0],+d[1])}me.TMXUtils.setTMXProperties(this,a)},getObjectPropertyByName:function(a){return this[a]}})})(window);
(function(){me.Tile=me.Rect.extend({tileId:null,init:function(a,c,b,d,e){this.parent(new me.Vector2d(a*b,c*d),b,d);this.row=a;this.col=c;this.tileId=e;this.flipX=0!==(this.tileId&2147483648);this.flipY=0!==(this.tileId&1073741824);this.flipAD=0!==(this.tileId&536870912);this.flipped=this.flipX||this.flipY||this.flipAD;this.tileId&=536870911}});me.Tileset=Object.extend({init:function(a,c,b,d,e,g){this.name=a;this.tilewidth=c;this.tileheight=b;this.spacing=d;this.margin=e;(this.image=g?me.loader.getImage(me.utils.getBasename(g)):
null)||console.log("melonJS: '"+g+"' file for tileset '"+this.name+"' not found!");this.type={SOLID:"solid",PLATFORM:"platform",L_SLOPE:"lslope",R_SLOPE:"rslope",LADDER:"ladder",BREAKABLE:"breakable"};this.TileProperties=[];this.tileXOffset=[];this.tileYOffset=[];this.image&&(this.hTileCount=~~((this.image.width-this.margin)/(this.tilewidth+this.spacing)),this.vTileCount=~~((this.image.height-this.margin)/(this.tileheight+this.spacing)))},getPropertyList:function(){return{isCollidable:!1,isSolid:!1,
isPlatform:!1,isSlope:!1,isLeftSlope:!1,isRightSlope:!1,isLadder:!1,isBreakable:!1}},getTileProperties:function(a){return this.TileProperties[a]},isTileCollidable:function(a){return this.TileProperties[a].isCollidable},getTileOffsetX:function(a){null==this.tileXOffset[a]&&(this.tileXOffset[a]=this.margin+(this.spacing+this.tilewidth)*(a%this.hTileCount));return this.tileXOffset[a]},getTileOffsetY:function(a){null==this.tileYOffset[a]&&(this.tileYOffset[a]=this.margin+(this.spacing+this.tileheight)*
~~(a/this.hTileCount));return this.tileYOffset[a]}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid=me.XMLParser.getIntAttribute(a,me.TMX_TAG_FIRSTGID);this.parent(me.XMLParser.getStringAttribute(a,me.TMX_TAG_NAME),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEWIDTH),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEHEIGHT),me.XMLParser.getIntAttribute(a,me.TMX_TAG_SPACING,0),me.XMLParser.getIntAttribute(a,me.TMX_TAG_MARGIN,0),a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE));
this.lastgid=this.firstgid+(this.hTileCount*this.vTileCount-1||0);this.trans=a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_TRANS);null!==this.trans&&this.image&&(this.image=me.video.applyRGBFilter(this.image,"transparent",this.trans.toUpperCase()).canvas);this.tileoffset=new me.Vector2d(0,0);var c=a.getElementsByTagName(me.TMX_TAG_TILEOFFSET);0<c.length&&(this.tileoffset.x=me.XMLParser.getIntAttribute(c[0],me.TMX_TAG_X),this.tileoffset.y=me.XMLParser.getIntAttribute(c[0],me.TMX_TAG_Y));
a=a.getElementsByTagName(me.TMX_TAG_TILE);for(c=0;c<a.length;c++){var b=me.XMLParser.getIntAttribute(a[c],me.TMX_TAG_ID)+this.firstgid;this.TileProperties[b]={};b=this.TileProperties[b];me.TMXUtils.setTMXProperties(b,a[c]);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.isSlope=b.isLeftSlope||b.isRightSlope;b.isCollidable=b.isSolid||b.isPlatform||b.isSlope||b.isLadder||b.isBreakable}},contains:function(a){return a>=this.firstgid&&a<=this.lastgid},getTileImage:function(a){var c=me.video.createCanvasSurface(this.tilewidth,this.tileheight);this.drawTile(c,0,0,a);return c.canvas},drawTile:function(a,c,b,d){if(d.flipped){var e=1,g=0,f=0,i=1,l=c,m=b,c=b=0;a.save();d.flipAD&&(e=0,f=g=
1,i=0,m+=this.tileheight-this.tilewidth);d.flipX&&(e=-e,f=-f,l+=d.flipAD?this.tileheight:this.tilewidth);d.flipY&&(g=-g,i=-i,m+=d.flipAD?this.tilewidth:this.tileheight);a.transform(e,g,f,i,l,m)}e=d.tileId-this.firstgid;a.drawImage(this.image,this.getTileOffsetX(e),this.getTileOffsetY(e),this.tilewidth,this.tileheight,c,b,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 c=-1,b=0,d=this.tilesets.length;b<d;b++){if(this.tilesets[b].contains(a))return this.tilesets[b];this.tilesets[b].firstgid==this.tilesets[b].lastgid&&a>=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}})})(window);
(function(){me.TMXOrthogonalRenderer=Object.extend({init:function(a,c,b,d){this.width=a;this.height=c;this.tilewidth=b;this.tileheight=d},pixelToTileCoords:function(a,c){return new me.Vector2d(a/this.tilewidth,c/this.tileheight)},tileToPixelCoords:function(a,c){return new me.Vector2d(a*this.tilewidth,c*this.tileheight)},drawTile:function(a,c,b,d,e){e.drawTile(a,e.tileoffset.x+c*this.tilewidth,e.tileoffset.y+(b+1)*this.tileheight-e.tileheight,d)},drawTileLayer:function(a,c,b,d){var e=this.pixelToTileCoords(b.x+
d.pos.x,b.y+d.pos.y).floorSelf(),b=this.pixelToTileCoords(b.x+d.pos.x+d.width+this.tilewidth,b.y+d.pos.y+d.height+this.tileheight).ceilSelf();b.x=b.x>this.width?this.width:b.x;b.y=b.y>this.height?this.height:b.y;for(d=e.y;d<b.y;d++)for(var g=e.x;g<b.x;g++){var f=c.layerData[g][d];f&&(c.tileset.contains(f.tileId)||(c.tileset=c.tilesets.getTilesetByGid(f.tileId)),this.drawTile(a,g,d,f,c.tileset))}}});me.TMXIsometricRenderer=Object.extend({init:function(a,c,b,d){this.width=a;this.height=c;this.tilewidth=
b;this.tileheight=d;this.hTilewidth=b/2;this.hTileheight=d/2;this.ratio=this.tilewidth/this.tileheight;this.originX=this.height*this.hTilewidth},pixelToTileCoords:function(a,c){a-=this.originX;return new me.Vector2d((c+a/this.ratio)/this.tileheight,(c-a/this.ratio)/this.tileheight)},tileToPixelCoords:function(a,c){return new me.Vector2d((a-c)*this.hTilewidth+this.originX,(a+c)*this.hTileheight)},drawTile:function(a,c,b,d,e){e.drawTile(a,(this.width-1)*e.tilewidth+(c-b)*e.tilewidth>>1,-e.tilewidth+
(c+b)*e.tileheight>>2,d)},drawTileLayer:function(a,c,b,d){var e=c.tileset,g=e.tileoffset,f=this.pixelToTileCoords(b.x+d.pos.x-e.tilewidth,b.y+d.pos.y-e.tileheight).floorSelf(),i=this.pixelToTileCoords(b.x+d.pos.x+d.width+e.tilewidth,b.y+d.pos.y+d.height+e.tileheight).ceilSelf(),i=this.tileToPixelCoords(i.x,i.y),l=this.tileToPixelCoords(f.x,f.y);l.x-=this.hTilewidth;l.y+=this.tileheight;var m=l.y-d.pos.y+b.y>this.hTileheight,b=d.pos.x+b.x-l.x<this.hTilewidth;m&&(b?(f.x--,l.x-=this.hTilewidth):(f.y--,
l.x+=this.hTilewidth),l.y-=this.hTileheight);b^=m;d=f.clone();for(m=l.y;m-this.tileheight<i.y;m+=this.hTileheight){d.setV(f);for(var k=l.x;k<i.x;k+=this.tilewidth){if(0<=d.x&&0<=d.y&&d.x<this.width&&d.y<this.height){var n=c.layerData[d.x][d.y];n&&(e.contains(n.tileId)||(e=c.tileset=c.tilesets.getTilesetByGid(n.tileId),g=e.tileoffset),e.drawTile(a,g.x+k,g.y+m-e.tileheight,n))}d.x++;d.y--}b?(f.y++,l.x-=this.hTilewidth,b=!1):(f.x++,l.x+=this.hTilewidth,b=!0)}}})})(window);
(function(a,c){me.ColorLayer=Object.extend({init:function(a,d,c){this.name=a;this.color=me.utils.HexToRGB(d);this.z=c;this.visible=!0;this.opacity=1},reset:function(){},update:function(){return!1},draw:function(a,d){a.fillStyle=this.color;var e=c.currentLevel.pos;a.fillRect(d.left-e.x,d.top-e.y,d.width,d.height)}});me.ImageLayer=Object.extend({init:function(a,d,e,g,f,i){this.name=a;(this.image=g?me.loader.getImage(me.utils.getBasename(g)):null)||console.log("melonJS: '"+g+"' file for Image Layer '"+
this.name+"' not found!");this.imagewidth=this.image.width;this.imageheight=this.image.height;this.z=f;this.ratio=i||0;this.lastpos=c.viewport.pos.clone();this.offset=new me.Vector2d(0,0);this.width=d?Math.min(c.viewport.width,d):c.viewport.width;this.height=e?Math.min(c.viewport.height,e):c.viewport.height;this.visible=!0;this.opacity=1},reset:function(){this.offset=this.viewport=this.lastpos=this.image=null},update:function(){if(0!==this.ratio){var a=c.viewport.pos;if(!this.lastpos.equals(a))return this.offset.x=
(this.imagewidth+this.offset.x+(a.x-this.lastpos.x)*this.ratio)%this.imagewidth,this.offset.y=(this.imageheight+this.offset.y+(a.y-this.lastpos.y)*this.ratio)%this.imageheight,this.lastpos.setV(a),!0}return!1},draw:function(a,d){1>this.opacity&&(a.globalAlpha=this.opacity);if(0===this.ratio)l=Math.min(d.width,this.imagewidth),m=Math.min(d.height,this.imageheight),a.drawImage(this.image,d.left,d.top,l,m,d.left,d.top,l,m);else{var c=~~this.offset.x,g=~~this.offset.y,f=0,i=0,l=Math.min(this.imagewidth-
~~this.offset.x,this.width),m=Math.min(this.imageheight-~~this.offset.y,this.height);do{do a.drawImage(this.image,c,g,l,m,f,i,l,m),g=0,i+=m,m=Math.min(this.imageheight,this.height-i);while(i<this.height);f+=l;if(f>=this.width)break;c=0;l=Math.min(this.imagewidth,this.width-f);g=~~this.offset.y;i=0;m=Math.min(this.imageheight-~~this.offset.y,this.height)}while(1)}a.globalAlpha=1}});CollisionTiledLayer=Object.extend({init:function(a,d){this.realwidth=a;this.realheight=d;this.isCollisionMap=!0},reset:function(){},
checkCollision:function(a,d){var c=0>d.x?a.left+d.x:a.right+d.x,g=0>d.y?a.top+d.y:a.bottom+d.y,f={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)f.x=d.x;if(0>=g||g>=this.realheight)f.y=d.y;return f}});me.TiledLayer=Object.extend({init:function(a,d,c,g,f,i){this.width=a;this.height=d;this.tilewidth=c;this.tileheight=g;this.realwidth=this.width*this.tilewidth;this.realheight=this.height*this.tileheight;this.z=i;this.name=null;this.visible=!1;this.layerData=null;this.tileset=(this.tilesets=f)?
this.tilesets.getTilesetByIndex(0):null},reset:function(){this.tilesets=this.tileset=this.layerData=null},initArray:function(){this.layerData=[];for(var a=0;a<this.width;a++){this.layerData[a]=[];for(var d=0;d<this.height;d++)this.layerData[a][d]=null}},getTileId:function(a,d){var c=this.getTile(a,d);return c?c.tileId:null},getTile:function(a,d){return this.layerData[~~(a/this.tilewidth)][~~(d/this.tileheight)]},setTile:function(a,d,c){this.layerData[a][d]=new me.Tile(a,d,this.tilewidth,this.tileheight,
c)},clearTile:function(a,d){this.layerData[a][d]=null},checkCollision:function(a,d){var c=0>d.x?~~(a.left+d.x):Math.ceil(a.right-1+d.x),g=0>d.y?~~(a.top+d.y):Math.ceil(a.bottom-1+d.y),f={x:0,xtile:void 0,xprop:{},y:0,ytile:void 0,yprop:{}};0>=c||c>=this.realwidth?f.x=d.x:0!=d.x&&(f.xtile=this.getTile(c,Math.ceil(a.bottom-1)),f.xtile&&this.tileset.isTileCollidable(f.xtile.tileId)?(f.x=d.x,f.xprop=this.tileset.getTileProperties(f.xtile.tileId)):(f.xtile=this.getTile(c,~~a.top),f.xtile&&this.tileset.isTileCollidable(f.xtile.tileId)&&
(f.x=d.x,f.xprop=this.tileset.getTileProperties(f.xtile.tileId))));0!=d.y&&(f.ytile=this.getTile(0>d.x?~~a.left:Math.ceil(a.right-1),g),f.ytile&&this.tileset.isTileCollidable(f.ytile.tileId)?(f.y=d.y||1,f.yprop=this.tileset.getTileProperties(f.ytile.tileId)):(f.ytile=this.getTile(0>d.x?Math.ceil(a.right-1):~~a.left,g),f.ytile&&this.tileset.isTileCollidable(f.ytile.tileId)&&(f.y=d.y||1,f.yprop=this.tileset.getTileProperties(f.ytile.tileId))));return f},update:function(){return!1}});me.TMXLayer=me.TiledLayer.extend({init:function(a,
d,c,g,f,i){this.parent(me.XMLParser.getIntAttribute(a,me.TMX_TAG_WIDTH),me.XMLParser.getIntAttribute(a,me.TMX_TAG_HEIGHT),d,c,f,i);this.orientation=g;this.name=me.XMLParser.getStringAttribute(a,me.TMX_TAG_NAME);this.visible=1==me.XMLParser.getIntAttribute(a,me.TMX_TAG_VISIBLE,1);this.opacity=me.XMLParser.getFloatAttribute(a,me.TMX_TAG_OPACITY,1).clamp(0,1);me.TMXUtils.setTMXProperties(this,a);void 0===this.preRender&&(this.preRender=me.sys.preRender);if((this.isCollisionMap=this.name.toLowerCase().contains(me.LevelConstants.COLLISION_MAP))&&
!me.debug.renderCollisionMap)this.visible=!1;a=a.getElementsByTagName(me.TMX_TAG_DATA)[0];d=me.XMLParser.getStringAttribute(a,me.TMX_TAG_ENCODING,null);c=me.XMLParser.getStringAttribute(a,me.TMX_TAG_COMPRESSION,null);""==d&&(d=null);""==c&&(c=null);if(this.visible){switch(this.orientation){case "orthogonal":this.renderer=new me.TMXOrthogonalRenderer(this.width,this.height,this.tilewidth,this.tileheight);break;case "isometric":this.renderer=new me.TMXIsometricRenderer(this.width,this.height,this.tilewidth,
this.tileheight);break;default:throw"melonJS: "+this.orientation+" type TMX Tile Map not supported!";}this.preRender&&(this.layerSurface=me.video.createCanvasSurface(this.width*this.tilewidth,this.height*this.tileheight),this.layerCanvas=this.layerSurface.canvas,this.layerSurface.globalAlpha=this.opacity)}if(this.visible||this.isCollisionMap)this.initArray(),this.fillArray(a,d,c)},reset:function(){this.preRender&&(this.layerSurface=this.layerCanvas=null);this.renderer=null;this.parent()},fillArray:function(a,
d,c){switch(c){case null:switch(d){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var c="",g=0,f=a.childNodes.length;g<f;g++)c+=a.childNodes[g].nodeValue;a=d==me.TMX_TAG_ATTR_BASE64?me.utils.decodeBase64AsArray(c,4):me.utils.decodeCSV(c,this.width);break;default:throw"melonJS: TMX Tile Map "+d+" encoding not supported!";}break;default:throw"melonJS: "+c+" compressed TMX Tile Map not supported!";}for(g=c=0;g<this.height;g++)for(f=0;f<this.width;f++){var i=
null==d?me.XMLParser.getIntAttribute(a[c++],me.TMX_TAG_GID):a[c++];0!==i&&(i=new me.Tile(f,g,this.tilewidth,this.tileheight,i),this.layerData[f][g]=i,this.tileset.contains(i.tileId)||(this.tileset=this.tilesets.getTilesetByGid(i.tileId)),this.visible&&this.preRender&&this.renderer.drawTile(this.layerSurface,f,g,i,this.tileset))}},clearTile:function(a,d){this.parent(a,d);this.visible&&this.preRender&&this.layerSurface.clearRect(a*this.tilewidth,d*this.tileheight,this.tilewidth,this.tileheight)},draw:function(a,
d){var e=c.viewport.pos;if(this.preRender){var g=Math.min(d.width,this.realwidth),f=Math.min(d.height,this.realheight);a.drawImage(this.layerCanvas,e.x+d.pos.x,e.y+d.pos.y,g,f,d.pos.x,d.pos.y,g,f)}else a.save(),1>this.opacity&&(a.globalAlpha=this.opacity),a.translate(-e.x,-e.y),this.renderer.drawTileLayer(a,this,e,d),a.restore()}})})(window,me.game);
(function(){me.TileMap=Object.extend({init:function(a,c){this.pos=new me.Vector2d(a,c);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null;this.mapLayers=[];this.objectGroups=[];this.initialized=!1},reset:function(){this.tilesets=null;this.mapLayers.length=0;this.objectGroups.length=0;this.pos.set(0,0);this.initialized=!1},getObjectGroupByName:function(a){return this.objectGroups[a]},getObjectGroups:function(){return this.objectGroups},
getLayers:function(){return this.mapLayers},getLayerByName:function(a){for(var c=null,a=a.trim().toLowerCase(),b=this.mapLayers.length;b--;)if(this.mapLayers[b].name.toLowerCase().contains(a)){c=this.mapLayers[b];break}a.toLowerCase().contains(me.LevelConstants.COLLISION_MAP)&&null==c&&(c=new CollisionTiledLayer(me.game.currentLevel.realwidth,me.game.currentLevel.realheight));return c},clearTile:function(a,c){for(var b=this.mapLayers.length;b--;)this.mapLayers[b].visible&&this.mapLayers[b]instanceof
me.TiledLayer&&this.mapLayers[b].clearTile(a,c)}});me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=null},reset:function(){if(!0===this.initialized){for(var a=this.mapLayers.length;a--;)this.mapLayers[a].reset(),this.mapLayers[a]=null;for(a=this.objectGroups.length;a--;)this.objectGroups[a].reset(),this.objectGroups[a]=null;this.parent();this.initialized=
!1}},load:function(){if(!this.initialized){var a=0,c=0.25;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),d=0;d<b.length;d++)switch(b.item(d).nodeName){case me.TMX_TAG_MAP:var e=b.item(d);this.version=me.XMLParser.getStringAttribute(e,me.TMX_TAG_VERSION);this.orientation=me.XMLParser.getStringAttribute(e,me.TMX_TAG_ORIENTATION);this.width=me.XMLParser.getIntAttribute(e,me.TMX_TAG_WIDTH);this.height=me.XMLParser.getIntAttribute(e,me.TMX_TAG_HEIGHT);this.tilewidth=
me.XMLParser.getIntAttribute(e,me.TMX_TAG_TILEWIDTH);this.tileheight=me.XMLParser.getIntAttribute(e,me.TMX_TAG_TILEHEIGHT);this.realwidth=this.width*this.tilewidth;this.realheight=this.height*this.tileheight;this.backgroundcolor=me.XMLParser.getStringAttribute(e,me.TMX_BACKGROUND_COLOR);this.z=a++;if(this.realwidth<me.game.viewport.width||this.realheight<me.game.viewport.height){var g=~~((me.game.viewport.width-this.realwidth)/2),f=~~((me.game.viewport.height-this.realheight)/2);this.pos.add({x:0<
g?g:0,y:0<f?f:0})}me.TMXUtils.setTMXProperties(this,e);(this.background_color=this.backgroundcolor?this.backgroundcolor:this.background_color)&&this.mapLayers.push(new me.ColorLayer("background_color",this.background_color,a++));this.background_image&&this.mapLayers.push(new me.ImageLayer("background_image",this.width,this.height,this.background_image,a++));break;case me.TMX_TAG_TILESET:this.tilesets||(this.tilesets=new me.TMXTilesetGroup);this.tilesets.add(new me.TMXTileset(b.item(d)));break;case me.TMX_TAG_IMAGE_LAYER:var f=
me.XMLParser.getStringAttribute(b.item(d),me.TMX_TAG_NAME),e=me.XMLParser.getIntAttribute(b.item(d),me.TMX_TAG_WIDTH),g=me.XMLParser.getIntAttribute(b.item(d),me.TMX_TAG_HEIGHT),i=b.item(d).getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE),e=new me.ImageLayer(f,e*this.tilewidth,g*this.tileheight,i,a++);e.visible=1==me.XMLParser.getIntAttribute(b.item(d),me.TMX_TAG_VISIBLE,1);e.opacity=me.XMLParser.getFloatAttribute(b.item(d),me.TMX_TAG_OPACITY,1);me.TMXUtils.setTMXProperties(e,
b.item(d));this.mapLayers.push(e);break;case me.TMX_TAG_LAYER:i=me.XMLParser.getStringAttribute(b.item(d),me.TMX_TAG_NAME);i.toLowerCase().contains(me.LevelConstants.PARALLAX_MAP)?(e=me.XMLParser.getIntAttribute(b.item(d),me.TMX_TAG_WIDTH),g=me.XMLParser.getIntAttribute(b.item(d),me.TMX_TAG_HEIGHT),f={},me.TMXUtils.setTMXProperties(f,b.item(d)),f.ratio&&(c=f.ratio),e=new me.ImageLayer(i,e*this.tilewidth,g*this.tileheight,f.imagesrc,a++,c),e.visible=1==me.XMLParser.getIntAttribute(b.item(d),me.TMX_TAG_VISIBLE,
1),e.opacity=me.XMLParser.getFloatAttribute(b.item(d),me.TMX_TAG_OPACITY,1),me.TMXUtils.mergeProperties(e,f,!1),c+=c*c,this.mapLayers.push(e)):this.mapLayers.push(new me.TMXLayer(b.item(d),this.tilewidth,this.tileheight,this.orientation,this.tilesets,a++));break;case me.TMX_TAG_OBJECTGROUP:e=me.XMLParser.getStringAttribute(b.item(d),me.TMX_TAG_NAME),this.objectGroups.push(new me.TMXOBjectGroup(e,b.item(d),this.tilesets,a++))}me.XMLParser.free();this.initialized=!0}}})})(window);
(function(){var a=me,c={},b={},d=[],e=0;c.reset=function(){};c.addLevel=function(){throw"melonJS: no level loader defined";};c.addTMXLevel=function(a,c){if(null==b[a])b[a]=new me.TMXTileMap(a,0,0),b[a].name=a,d[d.length]=a;else return!1;c&&c();return!0};c.loadLevel=function(a){a=a.toString().toLowerCase();if(void 0===b[a])throw"melonJS: level "+a+" not found";if(b[a]instanceof me.TMXTileMap){var f=me.state.isRunning();f&&me.state.pause();me.game.reset();me.utils.resetGUID(a);b[c.getCurrentLevelId()]&&
b[c.getCurrentLevelId()].reset();b[a].load();e=d.indexOf(a);me.game.loadTMXLevel(b[a]);f&&me.state.resume()}else throw"melonJS: no level loader defined";return!0};c.getCurrentLevelId=function(){return d[e]};c.reloadLevel=function(){return c.loadLevel(c.getCurrentLevelId())};c.nextLevel=function(){return e+1<d.length?c.loadLevel(d[e+1]):!1};c.previousLevel=function(){return 0<=e-1?c.loadLevel(d[e-1]):!1};a.levelDirector=c})(window);
(function(){me.Tween=function(a){var c={},b={},d={},e=1E3,g=0,f=null,i=0,l=me.Tween.Easing.Linear.EaseNone,m=null,k=null,n=null;this.to=function(b,c){null!==c&&(e=c);for(var f in b)null!==a[f]&&(d[f]=b[f]);return this};this.start=function(){me.game.add(this,999);f=me.timer.getTime()+g;i=0;for(var e in d)null!==a[e]&&(c[e]=a[e],b[e]=d[e]-a[e]);return this};this.stop=function(){me.game.remove(this);return this};this.delay=function(a){g=a;return this};me.event.subscribe(me.event.STATE_PAUSE,function(){f&&
(i=me.timer.getTime())});me.event.subscribe(me.event.STATE_RESUME,function(){f&&i&&(f+=me.timer.getTime()-i)});this.easing=function(a){l=a;return this};this.chain=function(a){m=a;return this};this.onUpdate=function(a){k=a;return this};this.onComplete=function(a){n=a;return this};this.update=function(){var d,g,i;g=me.timer.getTime();if(g<f)return!0;if(1<=(g=(g-f)/e))g=1;i=l(g);for(d in b)a[d]=c[d]+b[d]*i;null!==k&&k.call(a,i);return 1===g?(me.game.remove(this),null!==n&&n.call(a),null!==m&&m.start(),
!1):!0};this.destroy=function(){return!0}};me.Tween.Easing={Linear:{},Quadratic:{},Cubic:{},Quartic:{},Quintic:{},Sinusoidal:{},Exponential:{},Circular:{},Elastic:{},Back:{},Bounce:{}};me.Tween.Easing.Linear.EaseNone=function(a){return a};me.Tween.Easing.Quadratic.EaseIn=function(a){return a*a};me.Tween.Easing.Quadratic.EaseOut=function(a){return a*(2-a)};me.Tween.Easing.Quadratic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*
a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn=function(a){return a*a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return 1- --a*a*a*a};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return--a*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=
function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return 1-Math.cos(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseOut=function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return 0.5*(1-Math.cos(Math.PI*a))};me.Tween.Easing.Exponential.EaseIn=function(a){return 0===a?0:Math.pow(1024,a-1)};me.Tween.Easing.Exponential.EaseOut=function(a){return 1===a?1:1-Math.pow(2,-10*a)};me.Tween.Easing.Exponential.EaseInOut=
function(a){return 0===a?0:1===a?1:1>(a*=2)?0.5*Math.pow(1024,a-1):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return 1-Math.sqrt(1-a*a)};me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a*=2)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);
return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4):0.5*b*Math.pow(2,
-10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut=function(a){return--a*a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-me.Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=
1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5>a?0.5*me.Tween.Easing.Bounce.EaseIn(2*a):0.5*me.Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})();
(function(){var a=me,c={},b={};c.STATE_PAUSE="me.state.onPause";c.STATE_RESUME="me.state.onResume";c.GAME_INIT="me.game.onInit";c.LEVEL_LOADED="me.game.onLevelLoaded";c.LOADER_COMPLETE="me.loader.onload";c.LOADER_PROGRESS="me.loader.onProgress";c.publish=function(a,c){for(var g=b[a],f=g?g.length:0;f--;)g[f].apply(window,c||[])};c.subscribe=function(a,c){b[a]||(b[a]=[]);b[a].push(c);return[a,c]};c.unsubscribe=function(a,c){for(var g=b[c?a:a[0]],c=c||a[1],f=g?g.length:0;f--;)g[f]===c&&g.splice(f,1)};
a.event=c})();
