/*
 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
 
 
 MinPubSub
 a micro publish/subscribe messaging framework
 @see https://github.com/daniellmb/MinPubSub 
 @author Daniel Lamb <daniellmb.com>
 Released under the MIT License
 
 Tween JS
 https://github.com/sole/Tween.js
*/
var me=me||{};
(function(a){function b(){if(!e){if(!d.body)return setTimeout(b,13);d.removeEventListener?d.removeEventListener("DOMContentLoaded",b,!1):a.removeEventListener("load",b,!1);e=!0;for(var c=0;c<k.length;c++)k[c].call(a,[]);k.length=0}}function c(){return{tmxDoc:null,isJSON:!1,parseFromString:function(d,c){(this.isJSON=c||!1)?this.tmxDoc=JSON.parse(d):(a.DOMParser?this.tmxDoc=(new DOMParser).parseFromString(d,"text/xml"):(this.tmxDoc=new ActiveXObject("Microsoft.XMLDOM"),this.tmxDoc.async="false",this.tmxDoc.loadXML(d)),
null==this.tmxDoc&&console.log("tmx/tsx "+this.tmxDoc+" not found!"))},getFirstElementByTagName:function(a){return this.tmxDoc?this.tmxDoc.getElementsByTagName(a)[0]:null},getAllTagElements:function(){return this.tmxDoc?this.tmxDoc.getElementsByTagName("*"):null},getStringAttribute:function(a,d,c){return(a=a.getAttribute(d))?a.trim():c},getIntAttribute:function(a,d,c){return(a=this.getStringAttribute(a,d,c))?parseInt(a):c},getFloatAttribute:function(a,d,c){return(a=this.getStringAttribute(a,d,c))?
parseFloat(a):c},getBooleanAttribute:function(a,d,c){return(a=this.getStringAttribute(a,d,c))?"true"==a:c},free:function(){this.tmxDoc=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,TMXParser:null,loadingScreen:null,TMXTileMap:null};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:null,gravity:void 0,useNativeAnimFrame:!1,cacheImage:!1,dirtyRegion:!1,stopOnAudioError:!0,pauseOnBlur:!0,preRender:!1,checkVersion:function(a,d){d=d||me.version;for(var c=a.split("."),b=d.split("."),f=Math.min(c.length,b.length),e=0,g=0;g<f&&!(e=+c[g]-+b[g]);g++);return e?e:c.length-b.length}};var f=!1,g=!1,e=!1,k=[];a.onReady=function(c){g||(g=!0,"complete"===d.readyState?b():(d.addEventListener&&d.addEventListener("DOMContentLoaded",b,!1),a.addEventListener("load",
b,!1)));e?c.call(a,[]):k.push(function(){return c.call(a,[])});return this};a.onReady(function(){f||(me.utils.setNocache(d.location.href.match(/\?nocache/)||!1),me.audio.detectCapabilities(),me.sys.touch="createTouch"in d||"ontouchstart"in a||navigator.isCocoonJS,me.timer.init(),me.TMXParser=new c,me.loadingScreen=new me.DefaultLoadingScreen,me.state.init(),me.entityPool.init(),me.levelDirector.reset(),f=!0)});var m=!1,n=/xyz/.test(function(){})?/\bparent\b/:/.*/;Object.extend=function(a){function d(){!m&&
this.init&&this.init.apply(this,arguments)}var c=this.prototype;m=!0;var b=new this;m=!1;for(var f in a)b[f]="function"==typeof a[f]&&"function"==typeof c[f]&&n.test(a[f])?function(a,d){return function(){var b=this.parent;this.parent=c[a];var f=d.apply(this,arguments);this.parent=b;return f}}(f,a[f]):a[f];d.prototype=b;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),c=d.shift();return function(){return a.apply(c,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,c){if(a.__defineGetter__)c.get&&a.__defineGetter__(d,c.get),c.set&&a.__defineSetter__(d,c.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 null!=this&&!isNaN(this)&&""!=this.trim()};String.prototype.isBoolean=function(){return null!=this&&("true"==this.trim()||
"false"==this.trim())};String.prototype.contains=function(a){return-1<this.indexOf(a)};String.prototype.toHex=function(){for(var a="",d=0;d<this.length;)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=2>arguments.length?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 0>this?-1:0<this?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);-1!==a&&Array.prototype.splice.call(this,a,1);return this};Array.prototype.forEach||(Array.prototype.forEach=function(a,d){for(var c=
0,b=this.length;b--;c++)a.call(d||this,this[c],c,this)});Object.defineProperty(me,"initialized",{get:function(){return f}});var h={},q=[],s,l=[],u=0;h.isDirty=!1;h.reset=function(){q.length=0;l.length=0;s=me.game.viewport.getRect();h.makeAllDirty()};h.makeDirty=function(a,d,c){d&&(h.isDirty=!0,me.sys.dirtyRegion&&(c?q.push(c.union(a)):a.getRect&&q.push(a.getRect())));a.inViewport&&l.unshift(a)};h.makeAllDirty=function(){q.length=0;q.push(s);h.isDirty=!0};h.remove=function(a){var d=l.indexOf(a);-1!=
d&&(l.splice(d,1),a.inViewport=!1,h.makeDirty(a,!0))};h.getDrawCount=function(){return u};h.draw=function(a){var d=me.game.viewport.pos.x,c=me.game.viewport.pos.y;a.save();a.translate(-d,-c);for(var d=d-me.game.currentLevel.pos.x,c=c-me.game.currentLevel.pos.y,b=q.length,f;b--,f=q[b];){for(var e=l.length,g;e--,g=l[e];)if(!me.sys.dirtyRegion||!g.isSprite||g.overlaps(f))!0===g.floating&&(a.save(),a.translate(d,c)),g.draw(a,f),!0===g.floating&&a.restore(),u++;me.debug.renderDirty&&f.draw(a,"white")}a.restore()};
h.flush=function(){me.sys.dirtyRegion&&(q.length=0);l.length=0;h.isDirty=!1;u=0};var w=me,j={},x=null,t=[],C=!1,y=null,v=null,D=function(a,d){return d.z-a.z};j.viewport=null;j.HUD=null;j.collisionMap=null;j.currentLevel=null;j.NO_OBJECT=0;j.ENEMY_OBJECT=1;j.COLLECTABLE_OBJECT=2;j.ACTION_OBJECT=3;j.onLevelLoaded=null;j.init=function(a,d){C||(a=a||me.video.getWidth(),d=d||me.video.getHeight(),j.viewport=new me.Viewport(0,0,a,d),x=me.video.getSystemContext(),me.event.publish(me.event.GAME_INIT),C=!0)};
j.reset=function(){C||j.init();j.removeAll();j.viewport&&j.viewport.reset();h.reset();x.setTransform(1,0,0,1,0,0);j.currentLevel={pos:{x:0,y:0}}};j.loadTMXLevel=function(a){j.currentLevel=a;j.collisionMap=j.currentLevel.getLayerByName("collision");(!j.collisionMap||!j.collisionMap.isCollisionMap)&&console.error("WARNING : no collision map detected");for(var d=j.currentLevel.getLayers(),c=d.length;c--;)d[c].visible&&j.add(d[c]);j.viewport.setBounds(Math.max(j.currentLevel.realwidth,j.viewport.width),
Math.max(j.currentLevel.realheight,j.viewport.height));d=j.currentLevel.getObjectGroups();for(c=0;c<d.length;c++)if(d[c].visible)for(var b=0;b<d[c].objects.length;b++)j.addEntity(d[c].objects[b],d[c].z);j.currentLevel.pos.x!=j.currentLevel.pos.y&&x.translate(j.currentLevel.pos.x,j.currentLevel.pos.y);j.sort();j.onLevelLoaded&&j.onLevelLoaded.call(j.onLevelLoaded,a.name);me.event.publish(me.event.LEVEL_LOADED,[a.name])};j.add=function(a,d){a.z=d?d:a.z;t.push(a)};j.addEntity=function(a,d){var c=me.entityPool.newInstanceOf(a.name,
a.x,a.y,a);c&&j.add(c,d)};j.getEntityByName=function(a){var d=[];a=a.toLowerCase();for(var c=t.length,b;c--,b=t[c];)b.name&&b.name.toLowerCase()===a&&d.push(b);return d};j.getObjectCount=function(){return t.length};j.getDrawCount=function(){return h.getDrawCount()};j.getEntityByGUID=function(a){for(var d=t.length,c;d--,c=t[d];)if(c.isEntity&&c.GUID==a)return c;return null};j.addHUD=function(a,d,c,b,f){null==j.HUD&&(j.HUD=new me.HUD_Object(a,d,c,b,f),j.add(j.HUD))};j.disableHUD=function(){null!=j.HUD&&
(j.remove(j.HUD),j.HUD=null)};j.update=function(){for(var a=null,d=t.length,c;d--,c=t[d];){var a=me.sys.dirtyRegion&&c.isSprite?c.getRect():null,b=c.update();c.inViewport=c.visible?!c.isSprite||c.floating?!0:j.viewport.isVisible(c):!1;h.makeDirty(c,b,b?a:null)}j.viewport.update(h.isDirty)&&h.makeAllDirty()};j.remove=function(a,d){a.destroy&&a.destroy();h.remove(a);!0===d?(t.remove(a),me.entityPool.freeInstance(a)):(a.visible=!1,y=function(a){t.remove(a);me.entityPool.freeInstance(a);y=null}.defer(a))};
j.removeAll=function(){y&&(clearTimeout(y),y=null);v&&(clearTimeout(v),v=null);for(var a=t.length;a--;)t[a].isPersistent||j.remove(t[a],!0);h.flush()};j.sort=function(a){null===v&&("function"!==typeof a&&(a=D),v=function(a){t.sort(a);v=null;me.game.repaint()}.defer(a))};j.collide=function(a,d){var c;d=!0===d?!0:!1;if(!0===d)var b=[],f=0;for(var e=t.length,g;e--,g=t[e];)if(g.inViewport&&(g.visible&&g.collidable&&g!=a)&&(c=g.collisionBox.collideVsAABB.call(g.collisionBox,a.collisionBox),0!=c.x||0!=
c.y)){g.onCollision.call(g,c,a);c.type=g.type;c.obj=g;if(!d)return c;b[f++]=c}return d?b:null};j.collideType=function(a,d,c){var b;c=!0===c?!0:!1;if(!0===c)var f=[],e=0;for(var g=t.length,z;g--,z=t[g];)if(z.inViewport&&(z.visible&&z.collidable&&z.type===d&&z!=a)&&(b=z.collisionBox.collideVsAABB.call(z.collisionBox,a.collisionBox),0!=b.x||0!=b.y)){z.onCollision.call(z,b,a);b.type=z.type;b.obj=z;if(!c)return b;f[e++]=b}return c?f:null};j.repaint=function(){h.makeAllDirty()};j.draw=function(){h.isDirty&&
(h.draw(x),j.viewport.draw(x));h.flush()};w.game=j;me.ScreenObject=Object.extend({inViewport:!1,visible:!1,addAsObject:!1,isPersistent:!1,z:999,rect:null,init:function(a,d){this.isPersistent=(this.addAsObject=this.visible=!0===a||!1)&&!0===d||!1;this.rect=new me.Rect(new me.Vector2d(0,0),0,0)},reset:function(){me.game.reset();this.onResetEvent.apply(this,arguments);this.addAsObject&&(this.visible=!0,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!1},onUpdateFrame:function(){me.timer.update();me.game.update();me.game.draw();me.video.blitSurface()},draw:function(){},onResetEvent:function(){},onDestroyEvent:function(){}});for(var w=me,z=function(){if(-1==F&&-1==E){me.timer.reset();if(me.sys.useNativeAnimFrame){E=window.requestAnimationFrame(N);if(-1!=E)return;me.sys.useNativeAnimFrame=!1}F=setInterval(J,~~(1E3/me.sys.fps))}},N=function(){J();E=window.requestAnimationFrame(N)},
O=function(){-1!=F&&(clearInterval(F),F=-1);-1!=E&&(window.cancelAnimationFrame(E),E=-1)},P=function(a){O();A[B]&&(A[B].screen.visible&&me.game.remove.call(me.game,A[B].screen,!0),A[B].screen.destroy());A[a]&&(B=a,A[B].screen.reset.apply(A[B].screen,K),J=A[B].screen.onUpdateFrame.bind(A[B].screen),z(),L&&L(),me.game.repaint())},H=["ms","moz","webkit","o"],G=0;G<H.length&&!window.requestAnimationFrame;++G)window.requestAnimationFrame=window[H[G]+"RequestAnimationFrame"],window.cancelAnimationFrame=
window[H[G]+"CancelAnimationFrame"]||window[H[G]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(){return-1});window.cancelAnimationFrame||(window.cancelAnimationFrame=function(){return-1});var r={},B=-1,F=-1,E=-1,A={},M="",I=0,L=null,K=null,J=null;r.LOADING=0;r.MENU=1;r.READY=2;r.PLAY=3;r.GAMEOVER=4;r.GAME_END=5;r.SCORE=6;r.CREDITS=7;r.SETTINGS=8;r.USER=100;r.onPause=null;r.onResume=null;r.init=function(){r.set(r.LOADING,me.loadingScreen);a.addEventListener("blur",
function(){me.sys.pauseOnBlur&&B!=r.LOADING&&r.pause(!0);if(r.onPause)r.onPause();me.event.publish(me.event.STATE_PAUSE)},!1);a.addEventListener("focus",function(){me.sys.pauseOnBlur&&B!=r.LOADING&&(r.resume(!0),me.game.repaint());if(r.onResume)r.onResume();me.event.publish(me.event.STATE_RESUME)},!1)};r.pause=function(a){O();a&&me.audio.pauseTrack()};r.resume=function(a){z();a&&me.audio.resumeTrack()};r.isRunning=function(){return-1!=F||-1!=E};r.set=function(a,d){A[a]={};A[a].screen=d;A[a].transition=
!0};r.current=function(){return A[B].screen};r.transition=function(a,d,c){"fade"==a&&(M=d,I=c)};r.setTransition=function(a,d){A[a].transition=d};r.change=function(a){K=null;1<arguments.length&&(K=Array.prototype.slice.call(arguments,1));I&&A[a].transition?(L=function(){me.game.viewport.fadeOut(M,I)},me.game.viewport.fadeIn(M,I,function(){P.defer(a)})):P.defer(a)};r.isCurrent=function(a){return B==a};w.state=r})(window);
(function(){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,"#89b002","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,c=(me.video.getWidth()-d-this.logo2.measureText(a,"JS").width)/2,b=me.video.getHeight()/2;me.video.clearSurface(a,"black");this.logo1.draw(a,"melon",c,b);this.logo2.draw(a,"JS",c+d,b);b+=this.logo1.measureText(a,"melon").height/2;d=Math.floor(this.loadPercent*me.video.getWidth());
a.strokeStyle="silver";a.strokeRect(0,b,me.video.getWidth(),6);a.fillStyle="#89b002";a.fillRect(2,b+2,d-4,2)}});var a=me,b=function(){if(m==k-h){for(var a in g)if(g[a].isTMX&&me.levelDirector.addTMXLevel(a))d.onResourceLoaded();d.onload?(clearTimeout(n),setTimeout(function(){d.onload();me.event.publish(me.event.LOADER_COMPLETE)},300),h=0):console.error("no load callback defined")}else n=setTimeout(b,100)},c=function(a,d,c){var b=new XMLHttpRequest;"json"!==me.utils.getFileExtension(a.src).toLowerCase()&&
b.overrideMimeType&&b.overrideMimeType("text/xml");b.open("GET",a.src+me.nocache,!0);b.ontimeout=c;b.onreadystatechange=function(){4==b.readyState&&(200==b.status||0==b.status&&b.responseText?(g[a.name]={data:b.responseText,isTMX:"tmx"===a.type,type:me.utils.getFileExtension(a.src).toLowerCase()},d()):c())};b.send(null)},d={},f={},g={},e={},k=0,m=0,n=0,h=0;d.onload=void 0;d.onProgress=void 0;d.onResourceLoaded=function(){m++;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++)k+=d.load(a[c],d.onResourceLoaded.bind(d),d.onLoadingError.bind(d,a[c]));b()};d.load=function(a,d,b){a.name=a.name.toLowerCase();switch(a.type){case "binary":var g=new XMLHttpRequest;g.open("GET",a.src+me.nocache,!1);g.responseType="arraybuffer";g.onerror=b;g.onload=function(){var c=g.response;if(c){var c=new Uint8Array(c),b=[];e[a.name]=new dataType;for(var f=0;f<c.byteLength;f++)b[f]=
String.fromCharCode(c[f]);e[a.name].data=b.join("");d()}};g.send();return 1;case "image":return f[a.name]=new Image,f[a.name].onload=d,f[a.name].onerror=b,f[a.name].src=a.src+me.nocache,1;case "tmx":return c.call(this,a,d,b),h+=1,2;case "tsx":return c.call(this,a,d,b),1;case "audio":me.audio.setLoadCallback(d);if(me.audio.isAudioEnable())return me.audio.load(a),1;break;default:throw"melonJS: me.loader.load : unknown or invalid resource type : "+a.type;}return 0};d.unload=function(a){a.name=a.name.toLowerCase();
switch(a.type){case "binary":if(!(a.name in e))return!1;delete e[a.name];return!0;case "image":if(!(a.name in f))return!1;delete f[a.name];return!0;case "tmx":case "tsx":if(!(a.name in g))return!1;delete g[a.name];return!0;case "audio":return me.audio.unload(a.name);default:throw"melonJS: me.loader.unload : unknown or invalid resource type : "+a.type;}};d.unloadAll=function(){for(var a in e)d.unload(a);for(a in f)d.unload(a);for(a in g)d.unload(a);me.audio.unloadAll()};d.getTMXFormat=function(a){a=
a.toLowerCase();return a in g?g[a].type:null};d.getTMX=function(a){a=a.toLowerCase();return a in g?g[a].data:null};d.getBinary=function(a){a=a.toLowerCase();return a in e?e[a]:null};d.getImage=function(a){a=a.toLowerCase();if(a in f){if(!0===me.sys.cacheImage){var d=me.video.createCanvasSurface(f[a].width,f[a].height);d.drawImage(f[a],0,0);return d.canvas}return f[a]}return null};d.getLoadProgress=function(){return m/k};a.loader=d})(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){this.x=a;this.y=b},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,b){return new me.Vector2d(this.x.clamp(a,b),this.y.clamp(a,
b))},clampSelf:function(a,b){this.x=this.x.clamp(a,b);this.y=this.y.clamp(a,b);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 b=1/a;this.x*=b;this.y*=b;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))},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}});me.Rect=Object.extend({pos:null,colPos:null,width:0,height:0,hWidth:0,hHeight:0,init:function(a,b,c){this.pos=a;this.colPos=new me.Vector2d;this.width=b;this.height=c;this.hWidth=~~(b/2);this.hHeight=~~(c/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,b,c){this.pos=a;this.width=b;this.height=c;this.hWidth=~~(b/2);this.hHeight=~~(c/2)},getRect:function(){return new me.Rect(this.pos.clone(),this.width,this.height)},union:function(a){var b=Math.min(this.pos.x,
a.pos.x),c=Math.min(this.pos.y,a.pos.y);this.width=Math.ceil(Math.max(this.pos.x+this.width,a.pos.x+a.width)-b);this.height=Math.ceil(Math.max(this.pos.y+this.height,a.pos.y+a.height)-c);this.pos.x=~~b;this.pos.y=~~c;return this},adjustSize:function(a,b,c,d){-1!=a&&(this.colPos.x=a,this.width=b,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!=c&&(this.colPos.y=c,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)},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.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 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.debug={displayFPS:!1,renderHitBox:!1,renderCollisionMap:!1,renderDirty:!1,renderVelocity:!1}})(window);
(function(){var a=Math.min,b=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,b,g,e,k){this.parent(new me.Vector2d(a,d),b-a,g-d);this.limits=new me.Vector2d(e||this.width,k||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(c){return c.x-this.pos.x>this._deadwidth?(this.pos.x=~~a(c.x-this._deadwidth,this._limitwidth),!0):c.x-this.pos.x<this.deadzone.x?(this.pos.x=~~b(c.x-this.deadzone.x,0),!0):!1},_followV:function(c){return c.y-this.pos.y>this._deadheight?(this.pos.y=~~a(c.y-this._deadheight,this._limitheight),!0):c.y-this.pos.y<this.deadzone.y?(this.pos.y=~~b(c.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 b=~~(this.pos.y+d);this.pos.x=(~~(this.pos.x+a)).clamp(0,this._limitwidth);this.pos.y=b.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,b,g){b=b||this.AXIS.BOTH;b==this.AXIS.BOTH&&(this.width==this.limits.x?b=this.AXIS.VERTICAL:this.height==this.limits.y&&(b=this.AXIS.HORIZONTAL));!(b==this.AXIS.HORIZONTAL&&this.width==this.limits.x)&&!(b==this.AXIS.VERTICAL&&this.height==this.limits.y)&&(this._shake.intensity=a,this._shake.duration=d,this._shake.axis=b,this._shake.onComplete=
g||null)},fadeOut:function(a,d,b){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(b||null);this._fadeOut.tween.start()},fadeIn:function(a,d,b){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(b||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,inViewport:!1,angle:0,anchorPoint:null,alpha:1,floating:!1,image:null,flickering:!1,flickerTimer:-1,flickercb:null,flickerState:!1,init:function(a,b,c,d,f){this.isSprite=!0;this.parent(new me.Vector2d(a,b),d||c.width,f||c.height);this.image=c;this.scale=new me.Vector2d(1,1);this.scaleFlag=this.lastflipX=this.lastflipY=!1;this.offset=new me.Vector2d(0,0);this.anchorPoint=new me.Vector2d(0.5,
0.5);this.alpha=1;this.visible=!0;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.flickerTimer=a;0>this.flickerTimer?(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){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)},getOpacity:function(){return this.alpha},setOpacity:function(a){a&&(this.alpha=a.clamp(0,1))},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;a.save();a.globalAlpha=this.alpha;var b=~~this.pos.x,c=~~this.pos.y;if(this.scaleFlag||0!==this.angle){var d=this.width*this.anchorPoint.x,f=this.height*this.anchorPoint.y;a.translate(b+d,c+f);this.scaleFlag&&a.scale(this.scale.x,this.scale.y);0!==this.angle&&a.rotate(this.angle);b=-d;c=-f}a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,
b,c,this.width,this.height);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,spacing:0,margin:0,animationpause:!1,animationspeed:0,init:function(a,b,c,d,f,g,e){this.anim=[];this.current=this.resetAnim=null;this.spacing=g||0;this.margin=e||0;this.parent(a,b,c,d,f,g,e);this.spritecount=new me.Vector2d(~~((this.image.width-this.margin)/(this.width+
this.spacing)),~~((this.image.height-this.margin)/(this.height+this.spacing)));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,b,c){this.anim[a]={name:a,frame:[],idx:0,length:0,animationspeed:c||this.animationspeed};if(null==b){b=[];c=0;for(var d=this.spritecount.x*this.spritecount.y;c<d;c++)b[c]=c}c=0;for(d=b.length;c<d;c++)this.anim[a].frame[c]=
new me.Vector2d(this.margin+(this.spacing+this.width)*(b[c]%this.spritecount.x),this.margin+(this.spacing+this.height)*~~(b[c]/this.spritecount.x));this.anim[a].length=this.anim[a].frame.length},setCurrentAnimation:function(a,b){if(this.anim[a])this.current=this.anim[a],this.resetAnim=b||null,this.setAnimationFrame(this.current.idx);else throw"melonJS: animation id '"+a+"' not defined";},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]},getCurrentAnimationFrame:function(){return this.current.idx},update:function(){this.parent();return this.visible&&!this.animationpause&&this.fpscount++>this.current.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,b={},c={};b.init=function(){b.add("me.LevelEntity",me.LevelEntity);b.add("me.ObjectEntity",me.ObjectEntity);b.add("me.CollectableEntity",me.CollectableEntity);b.add("me.InvisibleEntity",me.InvisibleEntity)};b.add=function(a,b,g){g?c[a.toLowerCase()]={"class":b,pool:[],active:[]}:c[a.toLowerCase()]=b};b.newInstanceOf=function(a){var b="string"===typeof a?a.toLowerCase():
void 0;if(b&&c[b]){if(!c[b].pool){var g=c[b];arguments[0]=g;return new (g.bind.apply(g,arguments))}var e=c[b],g=e["class"];0<e.pool.length?(g=e.pool.pop(),g.init.apply(g,Array.prototype.slice.call(arguments,1))):(arguments[0]=g,g=new (g.bind.apply(g,arguments)),g.className=b);e.active.push(g);return g}if((e=arguments[3])&&e.image)return new me.SpriteObject(e.x,e.y,e.image);b&&console.error("Cannot instantiate entity of type '"+b+"': Class not found!");return null};b.purge=function(){for(className in c)c[className].pool=
[]};b.freeInstance=function(a){var b=a.className;if(b&&c[b]){for(var g=!0,e=0,k=c[b].active.length;e<k;e++)if(c[b].active[e]===a){g=!1;c[b].active.splice(e,1);break}g||c[b].pool.push(a)}};a.entityPool=b;me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,collisionBox:null,init:function(a,c,b){this.parent(a,c,"string"==typeof b.image?me.loader.getImage(b.image):b.image,b.spritewidth,b.spriteheight,b.spacing,b.margin);b.transparent_color&&this.setTransparency(b.transparent_color);
this.GUID=me.utils.createGUID();this.name=b.name?b.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=b.collidable||!1;this.type=b.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,c,b,e){this.collisionBox.adjustSize(a,c,b,e)},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,c){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=c?c:this.accel.y;this.setMaxVelocity(a,c)},setMaxVelocity:function(a,c){this.maxVel.x=a;this.maxVel.y=c},setFriction:function(a,c){this.friction.x=a||0;this.friction.y=c||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 c=this.pos.x+this.hWidth-(a.pos.x+a.hWidth);a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(c*c+a*a)},distanceToPoint:function(a){var c=this.pos.x+this.hWidth-a.x;a=this.pos.y+this.hHeight-a.y;return Math.sqrt(c*c+a*a)},angleTo:function(a){return Math.atan2(a.pos.y+a.hHeight-(this.pos.y+this.hHeight),a.pos.x+a.hWidth-(this.pos.x+this.hWidth))},angleToPoint:function(a){return Math.atan2(a.y-(this.pos.y+this.hHeight),a.x-(this.pos.x+
this.hWidth))},checkSlope:function(a,c){this.pos.y=a.pos.y-this.height;this.slopeY=c?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.col,a.ytile.row),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.col,a.xtile.row),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a},collide:function(a){return me.game.collide(this,a||!1)},collideType:function(a,c){return me.game.collideType(this,a,c||!1)},draw:function(a){this.parent(a);if(me.debug.renderHitBox){this.collisionBox.draw(a,
"red");var c=~~(this.pos.x+this.hWidth),b=~~(this.pos.y+this.hHeight);a.lineWidth=1;a.beginPath();a.moveTo(c,b);a.lineTo(c+~~(this.vel.x*this.hWidth),b+~~(this.vel.y*this.hHeight));a.stroke()}}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a,c,b){this.parent(a,c,b);this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,c,b){this.parent(new me.Vector2d(a,c),b.width,b.height);this.collisionBox=new me.Rect(this.pos,
b.width,b.height);this.GUID=me.utils.createGUID();this.name=b.name?b.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,c,b,e){this.collisionBox.adjustSize(a,c,b,e)},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,this.pos.y,this.width,this.height),this.collisionBox.draw(a))}});
me.LevelEntity=me.InvisibleEntity.extend({init:function(a,c,b){this.parent(a,c,b);this.nextlevel=b.to;this.fade=b.fade;this.duration=b.duration;this.fading=!1;this.gotolevel=b.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,b,c,d){this.set(a,b,c,d)},bold:function(){this.font="bold "+this.font},italic:function(){this.font="italic "+this.font},set:function(a,b,c,d){a=a.split(",");for(var f=0;f<a.length;f++)a[f]="'"+a[f]+"'";this.height=parseInt(b);"number"===typeof b&&(b=""+b+"px");this.font=b+" "+a.join(",");this.color=c;this.align=d||"left"},getRect:function(){return new me.Rect(new Vector2d(0,
0),0,0)},measureText:function(a,b){a.font=this.font;a.fillStyle=this.color;a.textAlign=this.align;var c=a.measureText(b);c.height=this.height;return c},draw:function(a,b,c,d){a.font=this.font;a.fillStyle=this.color;a.textAlign=this.align;a.fillText(b,~~c,~~d)}});me.BitmapFont=me.Font.extend({size:null,sSize:null,firstChar:32,charCount:0,init:function(a,b,c,d){this.parent(a,null,null);this.size=new me.Vector2d;this.sSize=new me.Vector2d;this.firstChar=d||32;this.loadFontMetrics(a,b);this.align=this.ALIGN.RIGHT;
c&&this.resize(c)},loadFontMetrics:function(a,b){this.font=me.loader.getImage(a);this.size.x=b.x||b;this.size.y=b.y||this.font.height;this.sSize.copy(this.size);this.charCount=~~(this.font.width/this.size.x)},set:function(a,b){this.align=a;b&&this.resize(b)},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,b,c,d){b=new String(b);switch(this.align){case this.ALIGN.RIGHT:c-=
this.measureText(b).width;break;case this.ALIGN.CENTER:c-=0.5*this.measureText(b).width}for(var f=0,g=b.length;f<g;f++){var e=b.charCodeAt(f)-this.firstChar;a.drawImage(this.font,this.size.x*(e%this.charCount),this.size.y*~~(e/this.charCount),this.size.x,this.size.y,~~c,~~d,this.sSize.x,this.sSize.y);c+=this.sSize.x}}})})(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.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.onClick()},onClick:function(){return!0},onDestroyEvent:function(){me.input.releaseMouseEvent("mousedown",
this)}})})(window);
(function(){me.HUD_Item=Object.extend({init:function(a,b,c){this.pos=new me.Vector2d(a||0,b||0);this.visible=!0;this.defaultvalue=c||0;this.value=c||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,b,c,d,f){this.parent(new me.Vector2d(a||0,b||0),c||me.video.getWidth(),d||me.video.getHeight());this.bgcolor=f;this.HUDItems=
{};this.HUDobj=[];this.objCount=0;this.HUD_invalidated=this.floating=this.visible=!0;this.HUDCanvas=me.video.createCanvas(this.width,this.height);this.HUDCanvasSurface=this.HUDCanvas.getContext("2d");this.z=999;this.isPersistent=!0},addItem:function(a,b){this.HUDItems[a]=b;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,b){this.HUDItems[a]&&!0==this.HUDItems[a].set(b)&&(this.HUD_invalidated=!0)},updateItemValue:function(a,b){this.HUDItems[a]&&!0==this.HUDItems[a].update(b)&&(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,b;a--,b=
this.HUDobj[a];)b.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.HUDCanvas.width=this.HUDCanvas.width;for(var b=this.objCount,c;b--,c=this.HUDobj[b];)c.visible&&(c.draw(this.HUDCanvasSurface,0,0),c.updated&&(c.updated=!1))}a.drawImage(this.HUDCanvas,this.pos.x,this.pos.y);this.HUD_invalidated=
!1}})})(window);
(function(){var a=me,b=function(a){a=k[a];for(var c=0,b;b=a[c++];)if(b.ended||!b.currentTime)return b.currentTime=l,b;a[0].pause();a[0].currentTime=l;return a[0]},c=function(a){if(3<u++)if(a="melonJS: failed loading "+a+"."+m,!1===me.sys.stopOnAudioError)me.audio.disable(),n&&n(),console.log(a+", disabling audio");else throw a;else k[a][0].load()},d=function(a,c){u=0;if(1<c)for(var b=k[a][0],d=1;d<c;d++)k[a][d]=new Audio(b.src),k[a][d].preload="auto",k[a][d].load();n&&n.call()},f=function(a,c,d,e){var f=
b(a.toLowerCase());f.loop=c||!1;f.volume=e?parseFloat(e):1;f.play();d&&!c&&f.addEventListener("ended",function(a){f.removeEventListener("ended",arguments.callee,!1);d()},!1)},g=function(a,c,b){b&&!c&&setTimeout(b,2E3)},e={},k={},m=-1,n=null,h=null,q=null,s=!0,l=0,u=0;e.capabilities={mp3:{codec:"audio/mpeg",canPlay:!1,canPlayType:"no"},ogg:{codec:'audio/ogg; codecs="vorbis"',canPlay:!1,canPlayType:"no"},m4a:{codec:'audio/mp4; codecs="mp4a.40.2"',canPlay:!1,canPlayType:"no"},wav:{codec:'audio/wav; codecs="1"',
canPlay:!1,canPlayType:"no"}};e.detectCapabilities=function(){var a=document.createElement("audio");if(a.canPlayType)for(var c in e.capabilities){var b=a.canPlayType(e.capabilities[c].codec);""!==b&&"no"!==b&&(e.capabilities[c].canPlay=!0,e.capabilities[c].canPlayType=b);me.sys.sound|=e.capabilities[c].canPlay}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"))&&!navigator.isCocoonJS)me.sys.sound=!1};e.init=function(a){if(!me.initialized)throw"melonJS: me.audio.init() called before engine initialization.";
a=new String(a?a:"mp3");a=a.split(",");var c="",b=a.length;if(me.sys.sound){for(var d="",h=0;h<b;h++)if(d=a[h].toLowerCase().trim(),e.capabilities[d]&&e.capabilities[d].canPlay&&"probably"===e.capabilities[d].canPlayType){c=d;break}for(h=0;h<b;h++)if(d=a[h].toLowerCase().trim(),e.capabilities[d]&&e.capabilities[d].canPlay){c=d;break}}""===c&&(s=!1);m=c;e.play=e.isAudioEnable()?f:g;return e.isAudioEnable()};e.setLoadCallback=function(a){n=a};e.isAudioEnable=function(){return s};e.enable=function(){s=
me.sys.sound;e.play=s?f:g};e.disable=function(){s=!1;e.play=g};e.load=function(a){if(-1==m)return 0;var b=new Audio(a.src+a.name+"."+m+me.nocache);b.preload="auto";b.addEventListener("canplaythrough",function(c){this.removeEventListener("canplaythrough",arguments.callee,!1);d.apply(me.audio,[a.name,a.channel])},!1);b.addEventListener("error",function(){c.apply(me.audio,[a.name])},!1);b.load();k[a.name]=[b];return 1};e.stop=function(a){if(s){a=k[a.toLowerCase()];for(var c=a.length;c--;)a[c].pause(),
a[c].currentTime=l}};e.pause=function(a){if(s){a=k[a.toLowerCase()];for(var c=a.length;c--;)a[c].pause()}};e.playTrack=function(a){if(s&&(null!=q&&e.stopTrack(),a=a.toLowerCase(),q=b(a)))h=a,q.loop=!0,q.play()};e.stopTrack=function(){s&&q&&(q.pause(),q=h=null)};e.pauseTrack=function(){s&&q&&q.pause()};e.resumeTrack=function(){s&&q&&q.play()};e.unload=function(a){a=a.toLowerCase();if(!(a in k))return!1;h===a?e.stopTrack():e.stop(a);delete k[a];return!0};e.unloadAll=function(){for(var a in k)e.unload(a)};
a.audio=e})(window);
(function(){var a=me,b={},c=null,d=0,f=0,g=0,e=0,k=0,m=Math.ceil(1E3/me.sys.fps),n=1.25*(1E3/me.sys.fps);b.tick=1;b.fps=0;b.init=function(){c=document.getElementById("framecounter");null!==c&&(me.debug.displayFPS=!0);b.reset()};b.reset=function(){e=g=Date.now();d=f=0};b.getTime=function(){return e};b.update=function(){g=e;e=Date.now();k=e-g;me.debug.displayFPS&&(d++,f+=k,0==d%10&&(this.fps=(~~(1E3*d/f)).clamp(0,me.sys.fps),d=f=0),null!==c&&c.replaceChild(document.createTextNode("("+this.fps+"/"+me.sys.fps+
" fps)"),c.firstChild));b.tick=k>n&&me.sys.interpolation?k/m:1};a.timer=b;var a=me,h={},q=null,s=null,l=null,u=null,w=null,j=-1,x=!1,t=0,C=0,y=!1,v=!0;h.init=function(a,c,b,d,e,f){if(!me.initialized)throw"melonJS: me.video.init() called before engine initialization.";x=d||!1;y="auto"===e||!1;v=void 0!==f?f:!0;e="auto"!==e?parseFloat(e||1):1;me.sys.scale=new me.Vector2d(e,e);if(y||1!==e)x=!0;t=c*me.sys.scale.x;C=b*me.sys.scale.y;window.addEventListener("resize",function(a){me.event.publish(me.event.WINDOW_ONRESIZE,
[a])},!1);window.addEventListener("orientationchange",function(a){me.event.publish(me.event.WINDOW_ONRESIZE,[a])},!1);me.event.subscribe(me.event.WINDOW_ONRESIZE,me.video.onresize.bind(me.video));q=h.createCanvas(t,C);a&&(w=document.getElementById(a));w||(w=document.body);w.appendChild(q);if(!q.getContext)return!1;s=q.getContext("2d");x?(l=h.createCanvas(c,b),u=l.getContext("2d")):(l=q,u=s);if(y)me.video.onresize(null);return!0};h.getWrapper=function(){return w};h.getWidth=function(){return l.width};
h.getPos=function(a){a=a||q;for(var c=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)c.x+=a.offsetLeft,c.y+=a.offsetTop;return c};h.getHeight=function(){return l.height};h.createCanvas=function(a,c){var b=document.createElement("canvas");b.width=a||l.width;b.height=c||l.height;return b};h.createCanvasSurface=function(a,c){return h.createCanvas(a,c).getContext("2d")};h.getScreenCanvas=function(){return q};h.getScreenContext=function(){return s};h.getSystemCanvas=function(){return l};h.getSystemContext=
function(){return u};h.onresize=function(){if(y){var a=me.video.getScreenCanvas().parentNode,c=a.width||window.innerWidth,a=a.height||window.innerHeight;j&&clearTimeout(j);if(v){var b=me.video.getWidth()/me.video.getHeight(),c=c/a<b?c/me.video.getWidth():a/me.video.getHeight();j=me.video.updateDisplaySize.defer(c,c)}else j=me.video.updateDisplaySize.defer(c/me.video.getWidth(),a/me.video.getHeight())}else me.input.mouse.offset=me.video.getPos()};h.updateDisplaySize=function(a,c){me.sys.scale.set(a,
c);q.width=t=l.width*a;q.height=C=l.height*c;me.input.mouse.offset=me.video.getPos();h.blitSurface();j=-1};h.clearSurface=function(a,c){a.save();a.setTransform(1,0,0,1,0,0);a.fillStyle=c;a.fillRect(0,0,h.getWidth(),h.getHeight());a.restore()};h.scale=function(a,c){a.translate(-(a.canvas.width*c-a.canvas.width>>1),-(a.canvas.height*c-a.canvas.height>>1));a.scale(c,c)};h.setImageSmoothing=function(a){for(var c=["ms","moz","webkit","o"],b=0;b<c.length;++b)void 0!==s[c[b]+"ImageSmoothingEnabled"]&&(s[c[b]+
"ImageSmoothingEnabled"]=a);s.imageSmoothingEnabled=a};h.setAlpha=function(a,c){a.globalCompositeOperation=c?"source-over":"copy"};h.blitSurface=function(){h.blitSurface=x?function(){s.drawImage(l,0,0,l.width,l.height,0,0,t,C)}:function(){};h.blitSurface()};h.applyRGBFilter=function(a,c,b){var d=h.createCanvasSurface(a.width,a.height);a=me.utils.getPixels(a);var e=a.data;switch(c){case "b&w":c=0;for(var f=e.length;c<f;c+=4)b=3*e[c]+4*e[c+1]+e[c+2]>>>3,e[c]=b,e[c+1]=b,e[c+2]=b;break;case "brightness":b=
Math.abs(b).clamp(0,1);c=0;for(f=e.length;c<f;c+=4)e[c]*=b,e[c+1]*=b,e[c+2]*=b;break;case "transparent":c=0;for(f=e.length;c<f;c+=4)me.utils.RGBToHex(e[c],e[c+1],e[c+2])===b&&(e[c+3]=0);break;default:return null}d.putImageData(a,0,0);return d};a.video=h})(window);
(function(a){var b=me,c=function(){if(!C){l.touches.push({x:0,y:0});l.mouse.pos=new me.Vector2d(0,0);l.mouse.offset=me.video.getPos();if(me.sys.touch){me.video.getScreenCanvas().addEventListener("touchmove",n,!1);for(var c=2;c<D.length;++c)me.video.getScreenCanvas().addEventListener(D[c],q,!1)}else{me.video.getScreenCanvas().addEventListener("mousemove",n,!1);a.addEventListener("mousewheel",m,!1);for(c=2;c<v.length;++c)me.video.getScreenCanvas().addEventListener(v[c],h,!1)}C=!0}},d=function(a){a.stopPropagation?
a.stopPropagation():a.cancelBubble=!0;a.preventDefault?a.preventDefault():a.returnValue=!1;return!1},f=function(a,c){var b=u[c||a.keyCode||a.which];return b?(x[b]||(w[b]=!0,x[b]=j[b],me.event.publish(me.event.KEYDOWN,[b])),d(a)):!0},g=function(a,c){var b=u[c||a.keyCode||a.which];return b?(w[b]=!1,x[b]=!1,me.event.publish(me.event.KEYUP,[b]),d(a)):!0},e=function(a){var c=!1,b=l.mouse.handlers[a.type];if(b)for(var d=me.game.viewport.pos,e=me.game.currentLevel.pos,f=0,g=l.touches.length;f<g;f++)for(var h=
l.touches[f].x,n=l.touches[f].y,j=b.length,k;j--,k=b[j];){var s=!1===k.floating?{x:h+d.x-e.x,y:n+d.y-e.y}:{x:h,y:n};if((null===k.rect||k.rect.containsPoint(s))&&!1===k.cb(a)){c=!0;break}}return c},k=function(a){l.touches.length=0;if(a.touches)for(var c=l.mouse.offset,b=0,d=a.changedTouches.length;b<d;b++){var e=a.changedTouches[b],f=e.clientX-c.x,g=e.clientY-c.y,h=me.sys.scale;if(1!=h.x||1!=h.y)f/=h.x,g/=h.y;l.touches.push({x:f,y:g,id:e.identifier})}else{var c=l.mouse.offset,f=a.pageX-c.x,g=a.pageY-
c.y,h=me.sys.scale;if(1!=h.x||1!=h.y)f/=h.x,g/=h.y;l.touches.push({x:f,y:g,id:0})}l.mouse.pos.set(l.touches[0].x,l.touches[0].y)},m=function(a){return a.target==me.video.getScreenCanvas()&&e(a)?d(a):!0},n=function(a){k(a);return e(a)?d(a):!0},h=function(a){if(e(a))return d(a);var c=l.mouse.bind[a.button||0];return c?"mousedown"===a.type||"touchstart"===a.type?f(a,c):g(a,c):!0},q=function(a){k(a);return h(a)},s=function(a){l.accel=a.accelerationIncludingGravity},l={},u={},w={},j={},x={},t=!1,C=!1,
y=!1,v="mousewheel mousemove mousedown mouseup click dblclick".split(" "),D=[void 0,"touchmove","touchstart","touchend","tap","dbltap"];l.accel={x:0,y:0,z:0};l.mouse={pos:null,offset:null,LEFT:0,MIDDLE:1,RIGHT:2,bind:[0,0,0],handlers:{}};l.touches=[];l.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};l.isKeyPressed=function(a){return w[a]?(j[a]&&(x[a]=!0,w[a]=!1),!0):!1};l.keyStatus=function(a){return!0===x[a]?!0:w[a]};l.triggerKeyEvent=function(a,c){c?f({},a):g({},a)};l.bindKey=function(c,b,d){t||(a.addEventListener("keydown",f,!1),a.addEventListener("keyup",g,!1),t=!0);u[c]=b;w[b]=!1;j[b]=d?d:!1;x[b]=!1};l.unbindKey=function(a){w[u[a]]=!1;j[u[a]]=!1;u[a]=null};l.bindMouse=function(a,b){c();if(!u[b])throw"melonJS : no action defined for keycode "+
b;l.mouse.bind[a]=b};l.unbindMouse=function(a){l.mouse.bind[a]=null};l.bindTouch=function(a){l.bindMouse(me.input.mouse.LEFT,a)};l.unbindTouch=function(){l.unbindMouse(me.input.mouse.LEFT)};l.registerMouseEvent=function(a,b,d,e){c();me.sys.touch&&-1!==v.indexOf(a)&&(a=D[v.indexOf(a)]);if(a&&(-1!==v.indexOf(a)||-1!==D.indexOf(a))){l.mouse.handlers[a]||(l.mouse.handlers[a]=[]);var f=!0===b.floating?!0:!1;e&&(f=!0===e?!0:!1);l.mouse.handlers[a].push({rect:b||null,cb:d,floating:f})}else throw"melonJS : invalid event type : "+
a;};l.releaseMouseEvent=function(a,c){me.sys.touch&&-1!==v.indexOf(a)&&(a=D[v.indexOf(a)]);if(a&&(-1!==v.indexOf(a)||-1!==D.indexOf(a))){l.mouse.handlers[a]||(l.mouse.handlers[a]=[]);var b=l.mouse.handlers[a];if(b)for(var d=b.length,e;d--,e=b[d];)e.rect===c&&(e.rect=e.cb=e.floating=null,l.mouse.handlers[a].splice(d,1))}else throw"melonJS : invalid event type : "+a;};l.watchAccelerometer=function(){return a.sys.gyro?(y||(a.addEventListener("devicemotion",s,!1),y=!0),!0):!1};l.unwatchAccelerometer=
function(){y&&(a.removeEventListener("devicemotion",s,!1),y=!1)};b.input=l})(window);
(function(a){var b={decode:function(c){c=c.replace(/[^A-Za-z0-9\+\/\=]/g,"");if(me.sys.nativeBase64)return a.atob(c);for(var b=[],d,e,f,g,k,j=0;j<c.length;)d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(c.charAt(j++)),e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(c.charAt(j++)),g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(c.charAt(j++)),k="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(c.charAt(j++)),
d=d<<2|e>>4,e=(e&15)<<4|g>>2,f=(g&3)<<6|k,b.push(String.fromCharCode(d)),64!=g&&b.push(String.fromCharCode(e)),64!=k&&b.push(String.fromCharCode(f));return b=b.join("")}},c=me,d={},f={},g="",e=0,k=/^.*(\\|\/|\:)/,m=/\.[^\.]*$/;d.decodeBase64=function(a){return b.decode(a)};d.decodeBase64AsArray=function(a,c){c=c||1;var d=b.decode(a),e=[],f,g,k;f=0;for(k=d.length/c;f<k;f++){e[f]=0;for(g=c-1;0<=g;--g)e[f]+=d.charCodeAt(f*c+g)<<(g<<3)}return e};d.decodeCSV=function(a,c){a=a.trim().split("\n");for(var b=
[],d=0;d<a.length;d++){entries=a[d].split(",",c);for(var e=0;e<entries.length;e++)b.push(+entries[e])}return b};d.getBasename=function(a){return a.replace(k,"").replace(m,"")};d.getFileExtension=function(a){return a.substring(a.lastIndexOf(".")+1,a.length)};d.setNocache=function(a){me.nocache=a?"?"+parseInt(1E7*Math.random()):""};d.HexToRGB=function(a,c){if("#"!==a.charAt(0))return a;a=a.substring(1,a.length);if(null==f[a]){if(6>a.length)var b=a.charAt(0)+a.charAt(0),d=a.charAt(1)+a.charAt(1),e=a.charAt(2)+
a.charAt(2);else b=a.substring(0,2),d=a.substring(2,4),e=a.substring(4,6);f[a]=parseInt(b,16)+","+parseInt(d,16)+","+parseInt(e,16)}return(c?"rgba(":"rgb(")+f[a]+(c?","+c+")":")")};d.RGBToHex=function(a,c,b){return a.toHex()+c.toHex()+b.toHex()};d.getPixels=function(a){if(a instanceof HTMLImageElement){var c=me.video.createCanvasSurface(a.width,a.height);c.drawImage(a,0,0);return c.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();e=0};d.createGUID=function(){return g+"-"+e++};d.applyFriction=function(a,c){return 0>a+c?a+c*me.timer.tick:0<a-c?a-c*me.timer.tick:0};c.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 b=me,c={},d={},f=[],g=0;c.add=function(c,b){if(c.constructor===Object)for(var m in c){var n=m;d[n]=new a(c[m]);f.push(d[n]);g++}else d[c]=new a(b),f.push(d[c]),g++};c.updateValue=function(a,c){if(a.constructor===Object)for(var b in a)d[b]&&
d[b].update(a[b]);else d[a]&&d[a].update(c)};c.setValue=function(a,c){if(a.constructor===Object)for(var b in a)d[b]&&d[b].set(a[b]);else d[a]&&d[a].set(c)};c.getItemValue=function(a){return d[a]?d[a].value:0};c.reset=function(a){void 0!=a?d[a]&&d[a].reset():c.resetAll()};c.resetAll=function(){for(var a=g,c;a--,c=f[a];)c.reset()};b.gamestat=c})(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,b){var c=b.getElementsByTagName(me.TMX_TAG_PROPERTIES)[0];if(c)for(var c=c.getElementsByTagName(me.TMX_TAG_PROPERTY),d=0;d<c.length;d++){var f=me.TMXParser.getStringAttribute(c[d],me.TMX_TAG_NAME),g=me.TMXParser.getStringAttribute(c[d],me.TMX_TAG_VALUE);!g||g.isBoolean()?g=g?"true"==g:!0:g.isNumeric()&&(g=Number(g));a[f]=g}},mergeProperties:function(a,b,c){for(var d in b)if(c||void 0===a[d])a[d]=b[d];return a}}})(window);
(function(){me.TMXOBjectGroup=Object.extend({init:function(a,b,c,d){this.objects=[];this.name=a;this.width=me.TMXParser.getIntAttribute(b,me.TMX_TAG_WIDTH);this.height=me.TMXParser.getIntAttribute(b,me.TMX_TAG_HEIGHT);this.visible=1==me.TMXParser.getIntAttribute(b,me.TMX_TAG_VISIBLE,1);this.z=d;b.firstChild&&b.firstChild.nextSibling.nodeName===me.TMX_TAG_PROPERTIES&&me.TMXUtils.setTMXProperties(this,b);a=b.getElementsByTagName(me.TMX_TAG_OBJECT);for(b=0;b<a.length;b++)this.objects.push(new me.TMXOBject(a[b],
c,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,b,c){this.name=me.TMXParser.getStringAttribute(a,me.TMX_TAG_NAME);this.x=me.TMXParser.getIntAttribute(a,me.TMX_TAG_X);this.y=me.TMXParser.getIntAttribute(a,me.TMX_TAG_Y);this.z=c;this.width=me.TMXParser.getIntAttribute(a,me.TMX_TAG_WIDTH,0);this.height=me.TMXParser.getIntAttribute(a,me.TMX_TAG_HEIGHT,0);
if(this.gid=me.TMXParser.getIntAttribute(a,me.TMX_TAG_GID,null))b=b.getTilesetByGid(this.gid),this.width=b.tilewidth,this.height=b.tileheight,this.spritewidth=this.width,this.y-=this.height,c=new me.Tile(this.x,this.y,b.tilewidth,b.tileheight,this.gid),this.image=b.getTileImage(c);else if(b=a.getElementsByTagName(me.TMX_TAG_POLYGON),this.isPolygon=!0,b.length||(b=a.getElementsByTagName(me.TMX_TAG_POLYLINE),this.isPolygon=!1),b.length){this.points=[];b=me.TMXParser.getStringAttribute(b[0],me.TMX_TAG_POINTS).split(" ");
c=0;for(var d;c<b.length;c++)d=b[c].split(","),this.points[c]=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,b,c,d,f){this.parent(new me.Vector2d(a*c,b*d),c,d);this.col=a;this.row=b;this.tileId=f;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,b,c,d,f,g){this.name=a;this.tilewidth=b;this.tileheight=c;this.spacing=d;this.margin=f;(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.TMXParser.getIntAttribute(a,me.TMX_TAG_FIRSTGID);var b=me.TMXParser.getStringAttribute(a,me.TMX_TAG_SOURCE);if(b){b=me.utils.getBasename(b);a=me.loader.getTMX(b);if(!a)throw"melonJS:"+b+" TSX tileset not found";me.TMXParser.parseFromString(a);a=me.TMXParser.getFirstElementByTagName("tileset")}this.parent(me.TMXParser.getStringAttribute(a,me.TMX_TAG_NAME),me.TMXParser.getIntAttribute(a,
me.TMX_TAG_TILEWIDTH),me.TMXParser.getIntAttribute(a,me.TMX_TAG_TILEHEIGHT),me.TMXParser.getIntAttribute(a,me.TMX_TAG_SPACING,0),me.TMXParser.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);b=a.getElementsByTagName(me.TMX_TAG_TILEOFFSET);0<b.length&&(this.tileoffset.x=me.TMXParser.getIntAttribute(b[0],me.TMX_TAG_X),this.tileoffset.y=me.TMXParser.getIntAttribute(b[0],me.TMX_TAG_Y));a=a.getElementsByTagName(me.TMX_TAG_TILE);for(b=0;b<a.length;b++){var c=me.TMXParser.getIntAttribute(a[b],me.TMX_TAG_ID)+this.firstgid;this.TileProperties[c]={};c=this.TileProperties[c];me.TMXUtils.setTMXProperties(c,a[b]);c.isSolid=c.type?
c.type.toLowerCase()===this.type.SOLID:!1;c.isPlatform=c.type?c.type.toLowerCase()===this.type.PLATFORM:!1;c.isLeftSlope=c.type?c.type.toLowerCase()===this.type.L_SLOPE:!1;c.isRightSlope=c.type?c.type.toLowerCase()===this.type.R_SLOPE:!1;c.isBreakable=c.type?c.type.toLowerCase()===this.type.BREAKABLE:!1;c.isLadder=c.type?c.type.toLowerCase()===this.type.LADDER:!1;c.isSlope=c.isLeftSlope||c.isRightSlope;c.isCollidable=!!c.type}},contains:function(a){return a>=this.firstgid&&a<=this.lastgid},getTileImage:function(a){var b=
me.video.createCanvasSurface(this.tilewidth,this.tileheight);this.drawTile(b,0,0,a);return b.canvas},drawTile:function(a,b,c,d){if(d.flipped){var f=1,g=0,e=0,k=1,m=b,n=c;b=c=0;a.save();d.flipAD&&(f=0,e=g=1,k=0,n+=this.tileheight-this.tilewidth);d.flipX&&(f=-f,e=-e,m+=d.flipAD?this.tileheight:this.tilewidth);d.flipY&&(g=-g,k=-k,n+=d.flipAD?this.tilewidth:this.tileheight);a.transform(f,g,e,k,m,n)}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;c<d;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.width=a;this.height=b;this.tilewidth=c;this.tileheight=d},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)},drawTile:function(a,b,c,d,f){f.drawTile(a,f.tileoffset.x+b*this.tilewidth,f.tileoffset.y+(c+1)*this.tileheight-f.tileheight,d)},drawTileLayer:function(a,b,c,d){var f=this.pixelToTileCoords(c.x+
d.pos.x,c.y+d.pos.y).floorSelf();c=this.pixelToTileCoords(c.x+d.pos.x+d.width+this.tilewidth,c.y+d.pos.y+d.height+this.tileheight).ceilSelf();c.x=c.x>this.width?this.width:c.x;c.y=c.y>this.height?this.height:c.y;for(d=f.y;d<c.y;d++)for(var g=f.x;g<c.x;g++){var e=b.layerData[g][d];e&&(b.tileset.contains(e.tileId)||(b.tileset=b.tilesets.getTilesetByGid(e.tileId)),this.drawTile(a,g,d,e,b.tileset))}}});me.TMXIsometricRenderer=Object.extend({init:function(a,b,c,d){this.width=a;this.height=b;this.tilewidth=
c;this.tileheight=d;this.hTilewidth=c/2;this.hTileheight=d/2;this.ratio=this.tilewidth/this.tileheight;this.originX=this.height*this.hTilewidth},pixelToTileCoords:function(a,b){a-=this.originX;return new me.Vector2d((b+a/this.ratio)/this.tileheight,(b-a/this.ratio)/this.tileheight)},tileToPixelCoords:function(a,b){return new me.Vector2d((a-b)*this.hTilewidth+this.originX,(a+b)*this.hTileheight)},drawTile:function(a,b,c,d,f){f.drawTile(a,(this.width-1)*f.tilewidth+(b-c)*f.tilewidth>>1,-f.tilewidth+
(b+c)*f.tileheight>>2,d)},drawTileLayer:function(a,b,c,d){var f=b.tileset,g=f.tileoffset,e=this.pixelToTileCoords(c.x+d.pos.x-f.tilewidth,c.y+d.pos.y-f.tileheight).floorSelf(),k=this.pixelToTileCoords(c.x+d.pos.x+d.width+f.tilewidth,c.y+d.pos.y+d.height+f.tileheight).ceilSelf(),k=this.tileToPixelCoords(k.x,k.y),m=this.tileToPixelCoords(e.x,e.y);m.x-=this.hTilewidth;m.y+=this.tileheight;var n=m.y-d.pos.y+c.y>this.hTileheight;c=d.pos.x+c.x-m.x<this.hTilewidth;n&&(c?(e.x--,m.x-=this.hTilewidth):(e.y--,
m.x+=this.hTilewidth),m.y-=this.hTileheight);c^=n;d=e.clone();for(n=m.y;n-this.tileheight<k.y;n+=this.hTileheight){d.setV(e);for(var h=m.x;h<k.x;h+=this.tilewidth){if(0<=d.x&&0<=d.y&&d.x<this.width&&d.y<this.height){var q=b.layerData[d.x][d.y];q&&(f.contains(q.tileId)||(f=b.tileset=b.tilesets.getTilesetByGid(q.tileId),g=f.tileoffset),f.drawTile(a,g.x+h,g.y+n-f.tileheight,q))}d.x++;d.y--}c?(e.y++,m.x-=this.hTilewidth,c=!1):(e.x++,m.x+=this.hTilewidth,c=!0)}}})})(window);
(function(a,b){me.ColorLayer=Object.extend({init:function(a,b,f){this.name=a;this.color=me.utils.HexToRGB(b);this.z=f;this.visible=!0;this.opacity=1;this.floating=!0},reset:function(){},getOpacity:function(){return this.opacity},setOpacity:function(a){a&&(this.opacity=a.clamp(0,1))},update:function(){return!1},draw:function(a,b){var f=a.globalAlpha;a.globalAlpha=this.opacity;a.fillStyle=this.color;a.fillRect(b.left,b.top,b.width,b.height);a.globalAlpha=f}});me.ImageLayer=Object.extend({ratio:1,init:function(a,
d,f,g,e,k){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=e;this.ratio=k||1;this.lastpos=b.viewport.pos.clone();this.offset=new me.Vector2d(0,0);this.width=d?Math.min(b.viewport.width,d):b.viewport.width;this.height=f?Math.min(b.viewport.height,f):b.viewport.height;this.visible=!0;this.opacity=1;this.floating=!0;this._repeat=
"repeat";this.repeatY=this.repeatX=!0;Object.defineProperty(this,"repeat",{get:function(){return this._repeat},set:function(a){this._repeat=a;switch(this._repeat){case "no-repeat":this.repeatY=this.repeatX=!1;break;case "repeat-x":this.repeatX=!0;this.repeatY=!1;break;case "repeat-y":this.repeatX=!1;this.repeatY=!0;break;default:this.repeatY=this.repeatX=!0}}})},reset:function(){this.offset=this.viewport=this.lastpos=this.image=null},getOpacity:function(){return this.opacity},setOpacity:function(a){a&&
(this.opacity=a.clamp(0,1))},update:function(){if(0!==this.ratio){var a=b.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,b){if(1>this.opacity){var f=a.globalAlpha;a.globalAlpha=this.opacity}if(0===this.ratio)n=Math.min(b.width,this.imagewidth),h=Math.min(b.height,
this.imageheight),a.drawImage(this.image,b.left,b.top,n,h,b.left,b.top,n,h);else{var g=~~this.offset.x,e=~~this.offset.y,k=0,m=0,n=Math.min(this.imagewidth-g,this.width),h=Math.min(this.imageheight-e,this.height);do{do a.drawImage(this.image,g,e,n,h,k,m,n,h),e=0,m+=h,h=Math.min(this.imageheight,this.height-m);while(this.repeatY&&m<this.height);k+=n;if(!this.repeatX||k>=this.width)break;g=0;n=Math.min(this.imagewidth,this.width-k);e=~~this.offset.y;m=0;h=Math.min(this.imageheight-~~this.offset.y,this.height)}while(1)}1>
this.opacity&&(a.globalAlpha=f)}});CollisionTiledLayer=Object.extend({init:function(a,b){this.realwidth=a;this.realheight=b;this.isCollisionMap=!0},reset:function(){},checkCollision:function(a,b){var f=0>b.x?a.left+b.x:a.right+b.x,g=0>b.y?a.top+b.y:a.bottom+b.y,e={x:0,y:0,xprop:{},yprop:{}};if(0>=f||f>=this.realwidth)e.x=b.x;if(0>=g||g>=this.realheight)e.y=b.y;return e}});me.TiledLayer=Object.extend({init:function(a,b,f,g,e,k){this.width=a;this.height=b;this.tilewidth=f;this.tileheight=g;this.realwidth=
this.width*this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.opacity=1;this.layerData=null;this.tileset=(this.tilesets=e)?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 b=0;b<this.height;b++)this.layerData[a][b]=null}},getOpacity:function(){return this.opacity},setOpacity:function(a){a&&(this.opacity=
a.clamp(0,1))},getTileId:function(a,b){var f=this.getTile(a,b);return f?f.tileId:null},getTile:function(a,b){return this.layerData[~~(a/this.tilewidth)][~~(b/this.tileheight)]},setTile:function(a,b,f){this.layerData[a][b]=new me.Tile(a,b,this.tilewidth,this.tileheight,f)},clearTile:function(a,b){this.layerData[a][b]=null},checkCollision:function(a,b){var f=0>b.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),g=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),e={x:0,xtile:void 0,xprop:{},y:0,ytile:void 0,yprop:{}};
0>=f||f>=this.realwidth?e.x=b.x:0!=b.x&&(e.xtile=this.getTile(f,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(f,~~a.top),e.xtile&&this.tileset.isTileCollidable(e.xtile.tileId)&&(e.x=b.x,e.xprop=this.tileset.getTileProperties(e.xtile.tileId))));0!=b.y&&(e.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),g),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(0>b.x?Math.ceil(a.right-1):~~a.left,g),e.ytile&&this.tileset.isTileCollidable(e.ytile.tileId)&&(e.y=b.y||1,e.yprop=this.tileset.getTileProperties(e.ytile.tileId))));return e},update:function(){return!1}});me.TMXLayer=me.TiledLayer.extend({init:function(a,b,f,g,e,k){this.parent(me.TMXParser.getIntAttribute(a,me.TMX_TAG_WIDTH),me.TMXParser.getIntAttribute(a,me.TMX_TAG_HEIGHT),b,f,e,k);this.orientation=g;this.name=me.TMXParser.getStringAttribute(a,
me.TMX_TAG_NAME);this.visible=1==me.TMXParser.getIntAttribute(a,me.TMX_TAG_VISIBLE,1);this.opacity=me.TMXParser.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];b=me.TMXParser.getStringAttribute(a,me.TMX_TAG_ENCODING,null);
f=me.TMXParser.getStringAttribute(a,me.TMX_TAG_COMPRESSION,null);""==b&&(b=null);""==f&&(f=null);if(!this.isCollisionMap){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.layerCanvas=
me.video.createCanvas(this.width*this.tilewidth,this.height*this.tileheight),this.layerSurface=this.layerCanvas.getContext("2d"),this.layerSurface.globalAlpha=this.opacity)}this.initArray();this.fillArray(a,b,f)},reset:function(){this.preRender&&(this.layerSurface=this.layerCanvas=null);this.renderer=null;this.parent()},fillArray:function(a,b,f){switch(f){case null:switch(b){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:f="";for(var g=0,
e=a.childNodes.length;g<e;g++)f+=a.childNodes[g].nodeValue;a=b==me.TMX_TAG_ATTR_BASE64?me.utils.decodeBase64AsArray(f,4):me.utils.decodeCSV(f,this.width);break;default:throw"melonJS: TMX Tile Map "+b+" encoding not supported!";}break;default:throw"melonJS: "+f+" compressed TMX Tile Map not supported!";}for(g=f=0;g<this.height;g++)for(e=0;e<this.width;e++){var k=null==b?me.TMXParser.getIntAttribute(a[f++],me.TMX_TAG_GID):a[f++];0!==k&&(k=new me.Tile(e,g,this.tilewidth,this.tileheight,k),this.layerData[e][g]=
k,this.tileset.contains(k.tileId)||(this.tileset=this.tilesets.getTilesetByGid(k.tileId)),this.visible&&this.preRender&&this.renderer.drawTile(this.layerSurface,e,g,k,this.tileset))}},clearTile:function(a,b){this.parent(a,b);this.visible&&this.preRender&&this.layerSurface.clearRect(a*this.tilewidth,b*this.tileheight,this.tilewidth,this.tileheight)},setOpacity:function(a){this.parent(a);this.preRender&&(this.layerSurface.globalAlpha=this.opacity)},draw:function(a,d){var f=b.viewport.pos;if(this.preRender){var g=
Math.min(d.width,this.realwidth),e=Math.min(d.height,this.realheight);a.drawImage(this.layerCanvas,f.x+d.pos.x,f.y+d.pos.y,g,e,d.pos.x,d.pos.y,g,e)}else g=a.globalAlpha,a.globalAlpha=this.opacity,this.renderer.drawTileLayer(a,this,f,d),a.globalAlpha=g}})})(window,me.game);
(function(){me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);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){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}a.toLowerCase().contains(me.LevelConstants.COLLISION_MAP)&&null==b&&(b=new CollisionTiledLayer(me.game.currentLevel.realwidth,me.game.currentLevel.realheight));return b},clearTile:function(a,
b){for(var c=this.mapLayers.length;c--;)this.mapLayers[c]instanceof me.TiledLayer&&this.mapLayers[c].clearTile(a,b)}});me.TMXTileMap=me.TileMap.extend({init:function(a,b,c){this.parent(b,c);this.xmlMap=me.loader.getTMX(a);this.isJSON="json"===me.loader.getTMXFormat(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;me.TMXParser.parseFromString(this.xmlMap,this.isJSON);for(var b=me.TMXParser.getAllTagElements(),c=0;c<b.length;c++)switch(b.item(c).nodeName){case me.TMX_TAG_MAP:var d=b.item(c);this.version=me.TMXParser.getStringAttribute(d,me.TMX_TAG_VERSION);this.orientation=me.TMXParser.getStringAttribute(d,me.TMX_TAG_ORIENTATION);this.width=
me.TMXParser.getIntAttribute(d,me.TMX_TAG_WIDTH);this.height=me.TMXParser.getIntAttribute(d,me.TMX_TAG_HEIGHT);this.tilewidth=me.TMXParser.getIntAttribute(d,me.TMX_TAG_TILEWIDTH);this.tileheight=me.TMXParser.getIntAttribute(d,me.TMX_TAG_TILEHEIGHT);this.realwidth=this.width*this.tilewidth;this.realheight=this.height*this.tileheight;this.backgroundcolor=me.TMXParser.getStringAttribute(d,me.TMX_BACKGROUND_COLOR);this.z=a++;if(this.realwidth<me.game.viewport.width||this.realheight<me.game.viewport.height){var f=
~~((me.game.viewport.width-this.realwidth)/2),g=~~((me.game.viewport.height-this.realheight)/2);this.pos.add({x:0<f?f:0,y:0<g?g:0})}me.TMXUtils.setTMXProperties(this,d);(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(c)));break;case me.TMX_TAG_IMAGE_LAYER:var d=me.TMXParser.getStringAttribute(b.item(c),me.TMX_TAG_NAME),f=me.TMXParser.getIntAttribute(b.item(c),me.TMX_TAG_WIDTH),g=me.TMXParser.getIntAttribute(b.item(c),me.TMX_TAG_HEIGHT),e=b.item(c).getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE),d=new me.ImageLayer(d,f*this.tilewidth,g*this.tileheight,e,a++);d.visible=1==me.TMXParser.getIntAttribute(b.item(c),
me.TMX_TAG_VISIBLE,1);d.opacity=me.TMXParser.getFloatAttribute(b.item(c),me.TMX_TAG_OPACITY,1);me.TMXUtils.setTMXProperties(d,b.item(c));this.mapLayers.push(d);break;case me.TMX_TAG_LAYER:this.mapLayers.push(new me.TMXLayer(b.item(c),this.tilewidth,this.tileheight,this.orientation,this.tilesets,a++));break;case me.TMX_TAG_OBJECTGROUP:d=me.TMXParser.getStringAttribute(b.item(c),me.TMX_TAG_NAME),this.objectGroups.push(new me.TMXOBjectGroup(d,b.item(c),this.tilesets,a++))}me.TMXParser.free();this.initialized=
!0}}})})(window);
(function(){var a=me,b={},c={},d=[],f=0;b.reset=function(){};b.addLevel=function(){throw"melonJS: no level loader defined";};b.addTMXLevel=function(a,b){if(null==c[a])c[a]=new me.TMXTileMap(a,0,0),c[a].name=a,d[d.length]=a;else return!1;b&&b();return!0};b.loadLevel=function(a){a=a.toString().toLowerCase();if(void 0===c[a])throw"melonJS: level "+a+" not found";if(c[a]instanceof me.TMXTileMap){var e=me.state.isRunning();e&&me.state.pause();me.game.reset();me.utils.resetGUID(a);c[b.getCurrentLevelId()]&&c[b.getCurrentLevelId()].reset();
c[a].load();f=d.indexOf(a);me.game.loadTMXLevel(c[a]);e&&me.state.resume()}else throw"melonJS: no level loader defined";return!0};b.getCurrentLevelId=function(){return d[f]};b.reloadLevel=function(){return b.loadLevel(b.getCurrentLevelId())};b.nextLevel=function(){return f+1<d.length?b.loadLevel(d[f+1]):!1};b.previousLevel=function(){return 0<=f-1?b.loadLevel(d[f-1]):!1};b.levelCount=function(){return d.length};a.levelDirector=b})(window);
(function(){me.Tween=function(a){var b={},c={},d={},f=1E3,g=0,e=null,k=0,m=me.Tween.Easing.Linear.EaseNone,n=null,h=null,q=null;this.to=function(b,c){void 0!==c&&(f=c);for(var e in b)null!==a[e]&&(d[e]=b[e]);return this};this.start=function(){me.game.add(this,999);e=me.timer.getTime()+g;k=0;for(var f in d)null!==a[f]&&(b[f]=a[f],c[f]=d[f]-a[f]);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(){e&&
(k=me.timer.getTime())});me.event.subscribe(me.event.STATE_RESUME,function(){e&&k&&(e+=me.timer.getTime()-k)});this.easing=function(a){m=a;return this};this.chain=function(a){n=a;return this};this.onUpdate=function(a){h=a;return this};this.onComplete=function(a){q=a;return this};this.update=function(){var d,g,k;g=me.timer.getTime();if(g<e)return!0;if(1<=(g=(g-e)/f))g=1;k=m(g);for(d in c)a[d]=b[d]+c[d]*k;null!==h&&h.call(a,k);return 1===g?(me.game.remove(this),null!==q&&q.call(a),null!==n&&n.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 b,c=0.1;if(0===a)return 0;if(1===a)return 1;!c||1>c?(c=1,b=0.1):b=0.4*Math.asin(1/c)/(2*Math.PI);
return-(c*Math.pow(2,10*(a-=1))*Math.sin((a-b)*2*Math.PI/0.4))};me.Tween.Easing.Elastic.EaseOut=function(a){var b,c=0.1;if(0===a)return 0;if(1===a)return 1;!c||1>c?(c=1,b=0.1):b=0.4*Math.asin(1/c)/(2*Math.PI);return c*Math.pow(2,-10*a)*Math.sin((a-b)*2*Math.PI/0.4)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var b,c=0.1;if(0===a)return 0;if(1===a)return 1;!c||1>c?(c=1,b=0.1):b=0.4*Math.asin(1/c)/(2*Math.PI);return 1>(a*=2)?-0.5*c*Math.pow(2,10*(a-=1))*Math.sin((a-b)*2*Math.PI/0.4):0.5*c*Math.pow(2,
-10*(a-=1))*Math.sin((a-b)*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,b={},c={};b.STATE_PAUSE="me.state.onPause";b.STATE_RESUME="me.state.onResume";b.GAME_INIT="me.game.onInit";b.LEVEL_LOADED="me.game.onLevelLoaded";b.LOADER_COMPLETE="me.loader.onload";b.LOADER_PROGRESS="me.loader.onProgress";b.KEYDOWN="me.input.keydown";b.KEYUP="me.input.keyup";b.WINDOW_ONRESIZE="window.onresize";b.publish=function(a,b){for(var g=c[a],e=g?g.length:0;e--;)g[e].apply(window,b||[])};b.subscribe=function(a,b){c[a]||(c[a]=[]);c[a].push(b);return[a,b]};b.unsubscribe=
function(a,b){var g=c[b?a:a[0]];b=b||a[1];for(var e=g?g.length:0;e--;)g[e]===b&&g.splice(e,1)};a.event=b})();
(function(){var a=me,b={};b.Base=Object.extend({version:void 0,init:function(){}});b.patch=function(a,b,f){void 0!==a.prototype&&(a=a.prototype);if("function"==typeof a[b]){var g=a[b];a[b]=function(){var a=this.parent;this.parent=g;var b=f.apply(this,arguments);this.parent=a;return b}}else console.error(b+" is not an existing function")};b.register=function(a,b){me.plugin[b]&&console.error("plugin "+b+" already registered");if(void 0===a.prototype.version)throw"melonJS: Plugin version not defined !";
if(0<me.sys.checkVersion(a.prototype.version))throw"melonJS: Plugin version mismatch, expected: "+a.prototype.version+", got: "+me.version;var f=[];2<arguments.length&&(f=Array.prototype.slice.call(arguments,1));f[0]=a;me.plugin[b]=new (a.bind.apply(a,f));if(!(me.plugin[b]instanceof me.plugin.Base))throw"melonJS: Plugin should extend the me.plugin.Base Class !";};a.plugin=b})();
