/*
 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) 2011 - 2013, 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(!e){if(!d.body)return setTimeout(c,13);d.removeEventListener?d.removeEventListener("DOMContentLoaded",c,!1):a.removeEventListener("load",c,!1);e=!0;for(var b=0;b<l.length;b++)l[b].call(a,[]);l.length=0}}function b(){return{tmxDoc:null,isJSON:!1,parseFromString:function(a,b){this.tmxDoc=(this.isJSON=b||!1)?JSON.parse(a):a},getFirstElementByTagName:function(a){return this.tmxDoc?this.tmxDoc.getElementsByTagName(a)[0]:null},getAllTagElements:function(){return this.tmxDoc?this.tmxDoc.getElementsByTagName("*"):
null},getStringAttribute:function(a,b,d){return(a=a.getAttribute(b))?a.trim():d},getIntAttribute:function(a,b,d){return(a=this.getStringAttribute(a,b,d))?parseInt(a):d},getFloatAttribute:function(a,b,d){return(a=this.getStringAttribute(a,b,d))?parseFloat(a):d},getBooleanAttribute:function(a,b,d){return(a=this.getStringAttribute(a,b,d))?"true"==a:d},free:function(){this.tmxDoc=null}}}var d=a.document;me={mod:"melonJS",version:"0.9.6",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,b){b=b||me.version;for(var d=a.split("."),c=b.split("."),
g=Math.min(d.length,c.length),f=0,e=0;e<g&&!(f=+d[e]-+c[e]);e++);return f?f:d.length-c.length}};var g=!1,f=!1,e=!1,l=[];a.onReady=function(b){f||(f=!0,"complete"===d.readyState?c():(d.addEventListener&&d.addEventListener("DOMContentLoaded",c,!1),a.addEventListener("load",c,!1)));e?b.call(a,[]):l.push(function(){return b.call(a,[])});return this};a.onReady(function(){g||(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 b,me.loadingScreen=new me.DefaultLoadingScreen,me.state.init(),me.entityPool.init(),me.levelDirector.reset(),g=!0)});var n=!1,k=/xyz/.test(function(){})?/\bparent\b/:/.*/;Object.extend=function(a){function b(){!n&&this.init&&this.init.apply(this,arguments)}var d=this.prototype;n=!0;var c=new this;n=!1;for(var g in a)c[g]="function"==typeof a[g]&&"function"==typeof d[g]&&k.test(a[g])?function(a,b){return function(){var c=this.parent;this.parent=
d[a];var g=b.apply(this,arguments);this.parent=c;return g}}(g,a[g]):a[g];b.prototype=c;b.constructor=b;b.extend=Object.extend;return b};"function"!==typeof Object.create&&(Object.create=function(a){function b(){}b.prototype=a;return new b});if(!Function.prototype.bind){var m=function(){};Function.prototype.bind=function(a){var b=this;if("function"!=typeof b)throw new TypeError("Function.prototype.bind called on incompatible "+b);var d=Array.prototype.slice.call(arguments,1),c=function(){if(this instanceof
c){var g=b.apply(this,d.concat(Array.prototype.slice.call(arguments)));return Object(g)===g?g:this}return b.apply(a,d.concat(Array.prototype.slice.call(arguments)))};b.prototype&&(m.prototype=b.prototype,c.prototype=new m,m.prototype=null);return c}}"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,b=Array.prototype.slice.call(arguments);return window.setTimeout(function(){return a.apply(a,b)},0.01)};Object.defineProperty||(Object.defineProperty=function(a,b,d){if(a.__defineGetter__)d.get&&a.__defineGetter__(b,d.get),d.set&&a.__defineSetter__(b,d.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="",b=0;b<this.length;)a+=this.charCodeAt(b++).toString(16);return a};Number.prototype.clamp=function(a,b){return this<a?a:this>b?b:+this};Number.prototype.random=function(a,b){return~~(Math.random()*(b-a+1))+a};Number.prototype.round=function(){var a=2>arguments.length?
this:arguments[0],b=Math.pow(10,arguments[1]||arguments[0]||0);return Math.round(a*b)/b};Number.prototype.toHex=function(){return"0123456789ABCDEF".charAt(this-this%16>>4)+"0123456789ABCDEF".charAt(this%16)};Number.prototype.sign=function(){return 0>this?-1: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,b){for(var d=0,c=this.length;c--;d++)a.call(b||this,this[d],d,this)});Object.defineProperty(me,"initialized",{get:function(){return g}});var q={},t=[],h,u=[],v=0;q.isDirty=!1;q.reset=function(){t.length=0;u.length=0;h=me.game.viewport.getRect();q.makeAllDirty()};q.makeDirty=function(a,b,d){b&&(q.isDirty=!0,me.sys.dirtyRegion&&(d?t.push(d.union(a)):a.getRect&&t.push(a.getRect())));a.inViewport&&u.unshift(a)};q.makeAllDirty=
function(){t.length=0;t.push(h);q.isDirty=!0};q.remove=function(a){var b=u.indexOf(a);-1!=b&&(u.splice(b,1),a.inViewport=!1,q.makeDirty(a,!0))};q.getDrawCount=function(){return v};q.draw=function(a){var b=me.game.viewport.pos.x,d=me.game.viewport.pos.y;a.save();a.translate(-b,-d);for(var b=b-me.game.currentLevel.pos.x,d=d-me.game.currentLevel.pos.y,c=t.length,g;c--,g=t[c];){for(var f=u.length,e;f--,e=u[f];)if(!me.sys.dirtyRegion||!e.isSprite||e.overlaps(g))!0===e.floating&&(a.save(),a.translate(b,
d)),e.draw(a,g),!0===e.floating&&a.restore(),v++;me.debug.renderDirty&&g.draw(a,"white")}a.restore()};q.flush=function(){me.sys.dirtyRegion&&(t.length=0);u.length=0;q.isDirty=!1;v=0};var y=me,j={},z=null,s=[],A=!1,w=null,B=null,Q=function(a,b){return b.z-a.z};j.viewport=null;j.HUD=null;j.collisionMap=null;j.currentLevel=null;j.renderer=null;j.NO_OBJECT=0;j.ENEMY_OBJECT=1;j.COLLECTABLE_OBJECT=2;j.ACTION_OBJECT=3;j.onLevelLoaded=null;j.init=function(a,b){A||(a=a||me.video.getWidth(),b=b||me.video.getHeight(),
j.viewport=new me.Viewport(0,0,a,b),z=me.video.getSystemContext(),me.event.publish(me.event.GAME_INIT),A=!0)};j.reset=function(){A||j.init();j.removeAll();j.viewport&&j.viewport.reset();q.reset();z.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 b=j.currentLevel.getLayers(),d=
b.length;d--;)b[d].visible&&j.add(b[d]);j.viewport.setBounds(Math.max(j.currentLevel.realwidth,j.viewport.width),Math.max(j.currentLevel.realheight,j.viewport.height));b=j.currentLevel.getObjectGroups();for(d=0;d<b.length;d++)if(b[d].visible)for(var c=0;c<b[d].objects.length;c++)j.addEntity(b[d].objects[c],b[d].z);j.currentLevel.pos.x!=j.currentLevel.pos.y&&z.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,b){a.z=b?b:a.z;s.push(a)};j.addEntity=function(a,b){var d=me.entityPool.newInstanceOf(a.name,a.x,a.y,a);d&&j.add(d,b)};j.getEntityByName=function(a){var b=[];a=a.toLowerCase();for(var d=s.length,c;d--,c=s[d];)c.name&&c.name.toLowerCase()===a&&b.push(c);return b};j.getObjectCount=function(){return s.length};j.getDrawCount=function(){return q.getDrawCount()};j.getEntityByGUID=function(a){for(var b=s.length,d;b--,d=s[b];)if(d.isEntity&&d.GUID==a)return d;return null};j.addHUD=
function(a,b,d,c,g){null==j.HUD&&(j.HUD=new me.HUD_Object(a,b,d,c,g),j.add(j.HUD))};j.disableHUD=function(){null!=j.HUD&&(j.remove(j.HUD),j.HUD=null)};j.update=function(){for(var a=null,b=s.length,d;b--,d=s[b];){var a=me.sys.dirtyRegion&&d.isSprite?d.getRect():null,c=d.update();d.inViewport=d.visible?!d.isSprite||d.floating?!0:j.viewport.isVisible(d):!1;q.makeDirty(d,c,c?a:null)}j.viewport.update(q.isDirty)&&q.makeAllDirty()};j.remove=function(a,b){a.destroy&&a.destroy();q.remove(a);!0===b?(s.remove(a),
me.entityPool.freeInstance(a)):(a.visible=!1,w=function(a){s.remove(a);me.entityPool.freeInstance(a);w=null}.defer(a))};j.removeAll=function(){w&&(clearTimeout(w),w=null);B&&(clearTimeout(B),B=null);for(var a=s.length;a--;)s[a].isPersistent||j.remove(s[a],!0);q.flush()};j.sort=function(a){null===B&&("function"!==typeof a&&(a=Q),B=function(a){s.sort(a);B=null;me.game.repaint()}.defer(a))};j.collide=function(a,b){var d;b=!0===b?!0:!1;if(!0===b)var c=[],g=0;for(var f=s.length,e;f--,e=s[f];)if(e.inViewport&&
(e.visible&&e.collidable&&e!=a)&&(d=e.collisionBox.collideVsAABB.call(e.collisionBox,a.collisionBox),0!=d.x||0!=d.y)){e.onCollision.call(e,d,a);d.type=e.type;d.obj=e;if(!b)return d;c[g++]=d}return b?c:null};j.collideType=function(a,b,d){var c;d=!0===d?!0:!1;if(!0===d)var g=[],f=0;for(var e=s.length,k;e--,k=s[e];)if(k.inViewport&&(k.visible&&k.collidable&&k.type===b&&k!=a)&&(c=k.collisionBox.collideVsAABB.call(k.collisionBox,a.collisionBox),0!=c.x||0!=c.y)){k.onCollision.call(k,c,a);c.type=k.type;
c.obj=k;if(!d)return c;g[f++]=c}return d?g:null};j.repaint=function(){q.makeAllDirty()};j.draw=function(){q.isDirty&&(q.draw(z),j.viewport.draw(z));q.flush()};y.game=j;me.ScreenObject=Object.extend({inViewport:!1,visible:!1,addAsObject:!1,isPersistent:!1,z:999,rect:null,init:function(a,b){this.isPersistent=(this.addAsObject=this.visible=!0===a||!1)&&!0===b||!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 y=me,N=function(){if(-1==E&&-1==D){me.timer.reset();if(me.sys.useNativeAnimFrame){D=window.requestAnimationFrame(M);
if(-1!=D)return;me.sys.useNativeAnimFrame=!1}E=setInterval(I,~~(1E3/me.sys.fps))}},M=function(){I();-1!=D&&(D=window.requestAnimationFrame(M))},O=function(){-1!=E&&(clearInterval(E),E=-1);-1!=D&&(window.cancelAnimationFrame(D),D=-1)},P=function(a){O();x[C]&&(x[C].screen.visible&&me.game.remove.call(me.game,x[C].screen,!0),x[C].screen.destroy());x[a]&&(C=a,x[C].screen.reset.apply(x[C].screen,J),I=x[C].screen.onUpdateFrame.bind(x[C].screen),N(),K&&K(),me.game.repaint())},G=["ms","moz","webkit","o"],
F=0;F<G.length&&!window.requestAnimationFrame;++F)window.requestAnimationFrame=window[G[F]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[G[F]+"CancelAnimationFrame"]||window[G[F]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(){return-1});window.cancelAnimationFrame||(window.cancelAnimationFrame=function(){return-1});var r={},C=-1,E=-1,D=-1,x={},L="",H=0,K=null,J=null,I=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&&C!=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&&C!=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){N();a&&me.audio.resumeTrack()};r.isRunning=function(){return-1!=E||-1!=D};r.set=function(a,b){x[a]={};x[a].screen=b;x[a].transition=!0};r.current=function(){return x[C].screen};r.transition=function(a,b,d){"fade"==a&&(L=b,H=d)};r.setTransition=function(a,b){x[a].transition=b};r.change=function(a){J=null;1<arguments.length&&(J=Array.prototype.slice.call(arguments,1));H&&x[a].transition?(K=function(){me.game.viewport.fadeOut(L,H)},me.game.viewport.fadeIn(L,H,function(){P.defer(a)})):
P.defer(a)};r.isCurrent=function(a){return C==a};y.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 b=this.logo1.measureText(a,"melon").width,d=(me.video.getWidth()-b-this.logo2.measureText(a,"JS").width)/2,c=me.video.getHeight()/2;me.video.clearSurface(a,"black");this.logo1.draw(a,"melon",d,c);this.logo2.draw(a,"JS",d+b,c);c+=this.logo1.measureText(a,"melon").height/2;b=Math.floor(this.loadPercent*me.video.getWidth());
a.strokeStyle="silver";a.strokeRect(0,c,me.video.getWidth(),6);a.fillStyle="#89b002";a.fillRect(2,c+2,b-4,2)}});var a=me,c=function(){l==e?b.onload?(clearTimeout(n),setTimeout(function(){b.onload();me.event.publish(me.event.LOADER_COMPLETE)},300)):console.error("no load callback defined"):n=setTimeout(c,100)},b={},d={},g={},f={},e=0,l=0,n=0;b.onload=void 0;b.onProgress=void 0;b.onResourceLoaded=function(){l++;var a=b.getLoadProgress();if(b.onProgress)b.onProgress(a);me.event.publish(me.event.LOADER_PROGRESS,
[a])};b.onLoadingError=function(a){throw"melonJS: Failed loading resource "+a.src;};b.preload=function(a){for(var d=0;d<a.length;d++)e+=b.load(a[d],b.onResourceLoaded.bind(b),b.onLoadingError.bind(b,a[d]));c()};b.load=function(a,b,c){a.name=a.name.toLowerCase();switch(a.type){case "binary":var e=new XMLHttpRequest;e.open("GET",a.src+me.nocache,!1);e.responseType="arraybuffer";e.onerror=c;e.onload=function(){var d=e.response;if(d){var d=new Uint8Array(d),c=[];f[a.name]=new dataType;for(var g=0;g<d.byteLength;g++)c[g]=
String.fromCharCode(d[g]);f[a.name].data=c.join("");b()}};e.send();return 1;case "image":return d[a.name]=new Image,d[a.name].onload=b,d[a.name].onerror=c,d[a.name].src=a.src+me.nocache,1;case "tmx":case "tsx":var h=new XMLHttpRequest;"json"!==me.utils.getFileExtension(a.src).toLowerCase()&&h.overrideMimeType&&h.overrideMimeType("text/xml");h.open("GET",a.src+me.nocache,!0);h.ontimeout=c;h.onreadystatechange=function(){if(4==h.readyState)if(200==h.status||0==h.status&&h.responseText){var d=null,d=
me.sys.ua.contains("msie")||!h.responseXML?(new DOMParser).parseFromString(h.responseText,"text/xml"):h.responseXML;g[a.name]={data:d,isTMX:"tmx"===a.type,type:me.utils.getFileExtension(a.src).toLowerCase()};"tmx"===a.type&&me.levelDirector.addTMXLevel(a.name);b()}else c()};h.send(null);return 1;case "audio":if(me.audio.isAudioEnable())return me.audio.load(a,b,c),1;break;default:throw"melonJS: me.loader.load : unknown or invalid resource type : "+a.type;}return 0};b.unload=function(a){a.name=a.name.toLowerCase();
switch(a.type){case "binary":if(!(a.name in f))return!1;delete f[a.name];return!0;case "image":if(!(a.name in d))return!1;delete d[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;}};b.unloadAll=function(){for(var a in f)b.unload(a);for(a in d)b.unload(a);for(a in g)b.unload(a);me.audio.unloadAll()};b.getTMXFormat=function(a){a=
a.toLowerCase();return a in g?g[a].type:null};b.getTMX=function(a){a=a.toLowerCase();return a in g?g[a].data:null};b.getBinary=function(a){a=a.toLowerCase();return a in f?f[a]:null};b.getImage=function(a){a=a.toLowerCase();if(a in d){if(!0===me.sys.cacheImage){var b=me.video.createCanvasSurface(d[a].width,d[a].height);b.drawImage(d[a],0,0);return b.canvas}return d[a]}return null};b.getLoadProgress=function(){return l/e};a.loader=b})(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))},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,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)},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 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,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,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,f,e,l){this.parent(new me.Vector2d(a,d),c-a,f-d);this.limits=new me.Vector2d(e||this.width,l||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,f){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=
f||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,inViewport:!1,angle:0,anchorPoint:null,alpha:1,floating:!1,image:null,flickering:!1,flickerTimer:-1,flickercb:null,flickerState:!1,init:function(a,c,b,d,g){this.isSprite=!0;this.parent(new me.Vector2d(a,c),d||b.width,g||b.height);this.image=b;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,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)},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 c=~~this.pos.x,b=~~this.pos.y;if(this.scaleFlag||0!==this.angle){var d=this.width*this.anchorPoint.x,g=this.height*this.anchorPoint.y;a.translate(c+d,b+g);this.scaleFlag&&a.scale(this.scale.x,this.scale.y);0!==this.angle&&a.rotate(this.angle);c=-d;b=-g}a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,
c,b,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,c,b,d,g,f,e){this.anim=[];this.current=this.resetAnim=null;this.spacing=f||0;this.margin=e||0;this.parent(a,c,b,d,g,f,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,c,b){this.anim[a]={name:a,frame:[],idx:0,length:0,animationspeed:b||this.animationspeed};if(null==c){c=[];b=0;for(var 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.margin+(this.spacing+this.width)*(c[b]%this.spritecount.x),this.margin+(this.spacing+this.height)*~~(c[b]/this.spritecount.x));this.anim[a].length=this.anim[a].frame.length},setCurrentAnimation:function(a,c){if(this.anim[a])this.current=this.anim[a],this.resetAnim=c||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,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,f){f?b[a.toLowerCase()]={"class":c,pool:[],active:[]}:b[a.toLowerCase()]=c};c.newInstanceOf=function(a){var c="string"===typeof a?a.toLowerCase():
void 0;if(c&&b[c]){if(!b[c].pool){var f=b[c];arguments[0]=f;return new (f.bind.apply(f,arguments))}var e=b[c],f=e["class"];0<e.pool.length?(f=e.pool.pop(),f.init.apply(f,Array.prototype.slice.call(arguments,1))):(arguments[0]=f,f=new (f.bind.apply(f,arguments)),f.className=c);e.active.push(f);return f}if((e=arguments[3])&&e.image)return new me.SpriteObject(e.x,e.y,e.image);c&&console.error("Cannot instantiate entity of type '"+c+"': Class not found!");return null};c.purge=function(){for(className in b)b[className].pool=
[]};c.freeInstance=function(a){var c=a.className;if(c&&b[c]){for(var f=!0,e=0,l=b[c].active.length;e<l;e++)if(b[c].active[e]===a){f=!1;b[c].active.splice(e,1);break}f||b[c].pool.push(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.spacing,c.margin);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,e){this.collisionBox.adjustSize(a,b,c,e)},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)},distanceToPoint:function(a){var b=this.pos.x+this.hWidth-a.x;a=this.pos.y+this.hHeight-a.y;return Math.sqrt(b*b+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,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.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,b){return me.game.collideType(this,a,b||!1)},draw:function(a){this.parent(a);if(me.debug.renderHitBox){this.collisionBox.draw(a,
"red");var b=~~(this.pos.x+this.hWidth),c=~~(this.pos.y+this.hHeight);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,e){this.collisionBox.adjustSize(a,b,c,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,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,textAlign: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){a=a.split(",");for(var g=0;g<a.length;g++)a[g]="'"+a[g]+"'";this.height=parseInt(c);"number"===typeof c&&(c=""+c+"px");this.font=c+" "+a.join(",");this.color=b;this.textAlign=d||"left"},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.textAlign=this.textAlign;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.textAlign=this.textAlign;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.textAlign=
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.textAlign=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.textAlign){case this.ALIGN.RIGHT:b-=
this.measureText(c).width;break;case this.ALIGN.CENTER:b-=0.5*this.measureText(c).width}for(var g=0,f=c.length;g<f;g++){var e=c.charCodeAt(g)-this.firstChar;a.drawImage(this.font,this.size.x*(e%this.charCount),this.size.y*~~(e/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);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,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,g){this.parent(new me.Vector2d(a||0,c||0),b||me.video.getWidth(),d||me.video.getHeight());this.bgcolor=g;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,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.HUDCanvas.width=this.HUDCanvas.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))}a.drawImage(this.HUDCanvas,this.pos.x,this.pos.y);this.HUD_invalidated=
!1}})})(window);
(function(){var a=me,c=function(a,b){if(3<t++){var c="melonJS: failed loading "+a+"."+l;if(!1===me.sys.stopOnAudioError)me.audio.disable(),b&&b(),console.log(c+", disabling audio");else throw c;}else e[a][0].load()},b=function(a,b,c){t=0;if(1<b)for(var d=e[a][0],f=1;f<b;f++)e[a][f]=new Audio(d.src),e[a][f].preload="auto",e[a][f].load();c&&c()},d=function(a,b,c,d){var f;a:{a=a.toLowerCase();a=e[a];for(var g=0,k;k=a[g++];)if(k.ended||!k.currentTime){k.currentTime=q;f=k;break a}a[0].pause();a[0].currentTime=
q;f=a[0]}f.loop=b||!1;f.volume=d?parseFloat(d).clamp(0,1):h.volume;f.muted=h.muted;f.play();c&&!b&&f.addEventListener("ended",function(a){f.removeEventListener("ended",arguments.callee,!1);c()},!1);return f},g=function(a,b,c){c&&!b&&setTimeout(c,2E3);return null},f={},e={},l=-1,n=null,k=null,m=!0,q=0,t=0,h={volume:1,muted:!1};f.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"}};f.detectCapabilities=function(){var a=document.createElement("audio");if(a.canPlayType)for(var b in f.capabilities){var c=a.canPlayType(f.capabilities[b].codec);""!==c&&"no"!==c&&(f.capabilities[b].canPlay=!0,f.capabilities[b].canPlayType=c);me.sys.sound|=f.capabilities[b].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};f.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 b="",c=a.length;if(me.sys.sound)for(var e="",k=0;k<c;k++)if(e=a[k].toLowerCase().trim(),f.capabilities[e]&&f.capabilities[e].canPlay&&(""===b||"probably"===f.capabilities[e].canPlayType))if(b=e,"probably"===f.capabilities[e].canPlayType)break;""===b&&(m=!1);l=b;f.play=f.isAudioEnable()?d:g;return f.isAudioEnable()};
f.isAudioEnable=function(){return m};f.enable=function(){m=me.sys.sound;f.play=m?d:g};f.disable=function(){me.audio.stopTrack();f.play=g;m=!1};f.load=function(a,d,f){if(-1==l)return 0;var g=new Audio(a.src+a.name+"."+l+me.nocache);g.preload="auto";var k=a.channel||1,h="canplaythrough";!0===a.stream&&(k=1,h="canplay");g.addEventListener(h,function(c){this.removeEventListener(h,arguments.callee,!1);b.call(me.audio,a.name,k,d)},!1);g.addEventListener("error",function(){c.call(me.audio,a.name,f)},!1);
g.load();e[a.name]=[g];return 1};f.stop=function(a){if(m){a=e[a.toLowerCase()];for(var b=a.length;b--;)a[b].pause(),a[b].currentTime=q}};f.pause=function(a){if(m){a=e[a.toLowerCase()];for(var b=a.length;b--;)a[b].pause()}};f.playTrack=function(a,b){k=me.audio.play(a,!0,null,b);n=a.toLowerCase()};f.stopTrack=function(){m&&k&&(k.pause(),k=n=null)};f.setVolume=function(a){a&&(h.volume=parseFloat(a).clamp(0,1))};f.getVolume=function(){return h.volume};f.mute=function(a,b){b=void 0===b?!0:!!b;for(var c=
e[a.toLowerCase()],d=0,f;f=c[d++];)f.muted=b};f.unmute=function(a){f.mute(a,!1)};f.muteAll=function(){h.muted=!0;for(var a in e)f.mute(a,h.muted)};f.unmuteAll=function(){h.muted=!1;for(var a in e)f.mute(a,h.muted)};f.getCurrentTrack=function(){return n};f.pauseTrack=function(){m&&k&&k.pause()};f.resumeTrack=function(){m&&k&&k.play()};f.unload=function(a){a=a.toLowerCase();if(!(a in e))return!1;n===a?f.stopTrack():f.stop(a);delete e[a];return!0};f.unloadAll=function(){for(var a in e)f.unload(a)};a.audio=
f})(window);
(function(){var a=me,c={},b=null,d=0,g=0,f=0,e=0,l=0,n=Math.ceil(1E3/me.sys.fps),k=1.25*(1E3/me.sys.fps);c.tick=1;c.fps=0;c.init=function(){b=document.getElementById("framecounter");null!==b&&(me.debug.displayFPS=!0);c.reset()};c.reset=function(){e=f=Date.now();d=g=0};c.getTime=function(){return e};c.update=function(){f=e;e=Date.now();l=e-f;me.debug.displayFPS&&(d++,g+=l,0==d%10&&(this.fps=(~~(1E3*d/g)).clamp(0,me.sys.fps),d=g=0),null!==b&&b.replaceChild(document.createTextNode("("+this.fps+"/"+me.sys.fps+
" fps)"),b.firstChild));c.tick=l>k&&me.sys.interpolation?l/n:1};a.timer=c;var a=me,m={},q=null,t=null,h=null,u=null,v=null,y=-1,j=!1,z=0,s=0,A=!1,w=!0;m.init=function(a,b,c,d,e,f){if(!me.initialized)throw"melonJS: me.video.init() called before engine initialization.";j=d||!1;A="auto"===e||!1;w=void 0!==f?f:!0;e="auto"!==e?parseFloat(e||1):1;me.sys.scale=new me.Vector2d(e,e);if(A||1!==e)j=!0;z=b*me.sys.scale.x;s=c*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=m.createCanvas(z,s);a&&(v=document.getElementById(a));v||(v=document.body);v.appendChild(q);if(!q.getContext)return!1;t=q.getContext("2d");j?(h=m.createCanvas(b,c),u=h.getContext("2d")):(h=q,u=t);if(A)me.video.onresize(null);return!0};m.getWrapper=function(){return v};m.getWidth=function(){return h.width};
m.getPos=function(a){a=a||q;for(var b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};m.getHeight=function(){return h.height};m.createCanvas=function(a,b){var c=document.createElement("canvas");c.width=a||h.width;c.height=b||h.height;return c};m.createCanvasSurface=function(a,b){return m.createCanvas(a,b).getContext("2d")};m.getScreenCanvas=function(){return q};m.getScreenContext=function(){return t};m.getSystemCanvas=function(){return h};m.getSystemContext=
function(){return u};m.onresize=function(){if(A){var a=me.video.getScreenCanvas().parentNode,b=a.width||window.innerWidth,a=a.height||window.innerHeight;y&&clearTimeout(y);if(w){var c=me.video.getWidth()/me.video.getHeight(),b=b/a<c?b/me.video.getWidth():a/me.video.getHeight();y=me.video.updateDisplaySize.defer(b,b)}else y=me.video.updateDisplaySize.defer(b/me.video.getWidth(),a/me.video.getHeight())}else me.input.mouse.offset=me.video.getPos()};m.updateDisplaySize=function(a,b){me.sys.scale.set(a,
b);q.width=z=h.width*a;q.height=s=h.height*b;me.input.mouse.offset=me.video.getPos();m.blitSurface();y=-1};m.clearSurface=function(a,b){a.save();a.setTransform(1,0,0,1,0,0);a.fillStyle=b;a.fillRect(0,0,m.getWidth(),m.getHeight());a.restore()};m.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)};m.setImageSmoothing=function(a){for(var b=["ms","moz","webkit","o"],c=0;c<b.length;++c)void 0!==t[b[c]+"ImageSmoothingEnabled"]&&(t[b[c]+
"ImageSmoothingEnabled"]=a);t.imageSmoothingEnabled=a};m.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};m.blitSurface=function(){m.blitSurface=j?function(){t.drawImage(h,0,0,h.width,h.height,0,0,z,s)}:function(){};m.blitSurface()};m.applyRGBFilter=function(a,b,c){var d=m.createCanvasSurface(a.width,a.height);a=me.utils.getPixels(a);var e=a.data;switch(b){case "b&w":b=0;for(var f=e.length;b<f;b+=4)c=3*e[b]+4*e[b+1]+e[b+2]>>>3,e[b]=c,e[b+1]=c,e[b+2]=c;break;case "brightness":c=
Math.abs(c).clamp(0,1);b=0;for(f=e.length;b<f;b+=4)e[b]*=c,e[b+1]*=c,e[b+2]*=c;break;case "transparent":b=0;for(f=e.length;b<f;b+=4)me.utils.RGBToHex(e[b],e[b+1],e[b+2])===c&&(e[b+3]=0);break;default:return null}d.putImageData(a,0,0);return d};a.video=m})(window);
(function(a){var c=me,b=function(){if(!s){h.touches.push({x:0,y:0});h.mouse.pos=new me.Vector2d(0,0);h.mouse.offset=me.video.getPos();if(me.sys.touch){me.video.getScreenCanvas().addEventListener("touchmove",k,!1);for(var b=2;b<B.length;++b)me.video.getScreenCanvas().addEventListener(B[b],q,!1)}else{me.video.getScreenCanvas().addEventListener("mousemove",k,!1);a.addEventListener("mousewheel",n,!1);for(b=2;b<w.length;++b)me.video.getScreenCanvas().addEventListener(w[b],m,!1)}s=!0}},d=function(a){a.stopPropagation?
a.stopPropagation():a.cancelBubble=!0;a.preventDefault?a.preventDefault():a.returnValue=!1;return!1},g=function(a,b){var c=u[b||a.keyCode||a.which];return c?(j[c]||(v[c]=!0,j[c]=y[c],me.event.publish(me.event.KEYDOWN,[c])),d(a)):!0},f=function(a,b){var c=u[b||a.keyCode||a.which];return c?(v[c]=!1,j[c]=!1,me.event.publish(me.event.KEYUP,[c]),d(a)):!0},e=function(a){var b=!1,c=h.mouse.handlers[a.type];if(c)for(var d=me.game.viewport.pos,e=me.game.currentLevel.pos,f=0,g=h.touches.length;f<g;f++)for(var k=
h.touches[f].x,m=h.touches[f].y,j=c.length,l;j--,l=c[j];){var t=!1===l.floating?{x:k+d.x-e.x,y:m+d.y-e.y}:{x:k,y:m};if((null===l.rect||l.rect.containsPoint(t))&&!1===l.cb(a)){b=!0;break}}return b},l=function(a){h.touches.length=0;if(a.touches)for(var b=h.mouse.offset,c=0,d=a.changedTouches.length;c<d;c++){var e=a.changedTouches[c],f=e.clientX-b.x,g=e.clientY-b.y,k=me.sys.scale;if(1!=k.x||1!=k.y)f/=k.x,g/=k.y;h.touches.push({x:f,y:g,id:e.identifier})}else{var b=h.mouse.offset,f=a.pageX-b.x,g=a.pageY-
b.y,k=me.sys.scale;if(1!=k.x||1!=k.y)f/=k.x,g/=k.y;h.touches.push({x:f,y:g,id:0})}h.mouse.pos.set(h.touches[0].x,h.touches[0].y)},n=function(a){return a.target==me.video.getScreenCanvas()&&e(a)?d(a):!0},k=function(a){l(a);return e(a)?d(a):!0},m=function(a){if(e(a))return d(a);var b=h.mouse.bind[a.button||0];return b?"mousedown"===a.type||"touchstart"===a.type?g(a,b):f(a,b):!0},q=function(a){l(a);return m(a)},t=function(a){h.accel=a.accelerationIncludingGravity},h={},u={},v={},y={},j={},z=!1,s=!1,
A=!1,w="mousewheel mousemove mousedown mouseup click dblclick".split(" "),B=[void 0,"touchmove","touchstart","touchend","tap","dbltap"];h.accel={x:0,y:0,z:0};h.mouse={pos:null,offset:null,LEFT:0,MIDDLE:1,RIGHT:2,bind:[0,0,0],handlers:{}};h.touches=[];h.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};h.isKeyPressed=function(a){return v[a]?(y[a]&&(j[a]=!0,v[a]=!1),!0):!1};h.keyStatus=function(a){return!0===j[a]?!0:v[a]};h.triggerKeyEvent=function(a,b){b?g({},a):f({},a)};h.bindKey=function(b,c,d){z||(a.addEventListener("keydown",g,!1),a.addEventListener("keyup",f,!1),z=!0);u[b]=c;v[c]=!1;y[c]=d?d:!1;j[c]=!1};h.unbindKey=function(a){v[u[a]]=!1;y[u[a]]=!1;u[a]=null};h.bindMouse=function(a,c){b();if(!u[c])throw"melonJS : no action defined for keycode "+
c;h.mouse.bind[a]=c};h.unbindMouse=function(a){h.mouse.bind[a]=null};h.bindTouch=function(a){h.bindMouse(me.input.mouse.LEFT,a)};h.unbindTouch=function(){h.unbindMouse(me.input.mouse.LEFT)};h.registerMouseEvent=function(a,c,d,e){b();me.sys.touch&&-1!==w.indexOf(a)&&(a=B[w.indexOf(a)]);if(a&&(-1!==w.indexOf(a)||-1!==B.indexOf(a))){h.mouse.handlers[a]||(h.mouse.handlers[a]=[]);var f=!0===c.floating?!0:!1;e&&(f=!0===e?!0:!1);h.mouse.handlers[a].push({rect:c||null,cb:d,floating:f})}else throw"melonJS : invalid event type : "+
a;};h.releaseMouseEvent=function(a,b){me.sys.touch&&-1!==w.indexOf(a)&&(a=B[w.indexOf(a)]);if(a&&(-1!==w.indexOf(a)||-1!==B.indexOf(a))){h.mouse.handlers[a]||(h.mouse.handlers[a]=[]);var c=h.mouse.handlers[a];if(c)for(var d=c.length,e;d--,e=c[d];)e.rect===b&&(e.rect=e.cb=e.floating=null,h.mouse.handlers[a].splice(d,1))}else throw"melonJS : invalid event type : "+a;};h.watchAccelerometer=function(){return a.sys.gyro?(A||(a.addEventListener("devicemotion",t,!1),A=!0),!0):!1};h.unwatchAccelerometer=
function(){A&&(a.removeEventListener("devicemotion",t,!1),A=!1)};c.input=h})(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 c=[],d,e,f,g,l,n=0;n<b.length;)d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(n++)),e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(n++)),g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(n++)),l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(n++)),
d=d<<2|e>>4,e=(e&15)<<4|g>>2,f=(g&3)<<6|l,c.push(String.fromCharCode(d)),64!=g&&c.push(String.fromCharCode(e)),64!=l&&c.push(String.fromCharCode(f));return c=c.join("")}},b=me,d={},g={},f="",e=0,l=/^.*(\\|\/|\:)/,n=/\.[^\.]*$/;d.decodeBase64=function(a){return c.decode(a)};d.decodeBase64AsArray=function(a,b){b=b||1;var d=c.decode(a),e,f,g,l="function"===typeof window.Uint32Array?new Uint32Array(d.length/b):[];e=0;for(g=d.length/b;e<g;e++){l[e]=0;for(f=b-1;0<=f;--f)l[e]+=d.charCodeAt(e*b+f)<<(f<<3)}return l};
d.decodeCSV=function(a,b){a=a.trim().split("\n");for(var c=[],d=0;d<a.length;d++){entries=a[d].split(",",b);for(var e=0;e<entries.length;e++)c.push(+entries[e])}return c};d.getBasename=function(a){return a.replace(l,"").replace(n,"")};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,b){if("#"!==a.charAt(0))return a;a=a.substring(1,a.length);if(null==g[a]){if(6>a.length)var c=
a.charAt(0)+a.charAt(0),d=a.charAt(1)+a.charAt(1),e=a.charAt(2)+a.charAt(2);else c=a.substring(0,2),d=a.substring(2,4),e=a.substring(4,6);g[a]=parseInt(c,16)+","+parseInt(d,16)+","+parseInt(e,16)}return(b?"rgba(":"rgb(")+g[a]+(b?","+b+")":")")};d.RGBToHex=function(a,b,c){return a.toHex()+b.toHex()+c.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){f=a.toString().toUpperCase().toHex();e=0};d.createGUID=function(){return f+"-"+e++};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={},g=[],f=0;b.add=function(b,c){if(b.constructor===Object)for(var n in b){var k=n;d[k]=new a(b[n]);g.push(d[k]);f++}else d[b]=new a(c),g.push(d[b]),f++};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=f,b;a--,b=g[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 g=me.TMXParser.getStringAttribute(b[d],me.TMX_TAG_NAME),f=me.TMXParser.getStringAttribute(b[d],me.TMX_TAG_VALUE);!f||f.isBoolean()?f=f?"true"==f:!0:f.isNumeric()&&(f=Number(f));a[g]=f}},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.TMXParser.getIntAttribute(c,me.TMX_TAG_WIDTH);this.height=me.TMXParser.getIntAttribute(c,me.TMX_TAG_HEIGHT);this.visible=1==me.TMXParser.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.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=b;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))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=[];c=me.TMXParser.getStringAttribute(c[0],me.TMX_TAG_POINTS).split(" ");
b=0;for(var 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,g){this.parent(new me.Vector2d(a*b,c*d),b,d);this.col=a;this.row=c;this.tileId=g;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.TMXTileset=Object.extend({init:function(a){this.firstgid=me.TMXParser.getIntAttribute(a,me.TMX_TAG_FIRSTGID);var c=me.TMXParser.getStringAttribute(a,me.TMX_TAG_SOURCE);
if(c){c=me.utils.getBasename(c);a=me.loader.getTMX(c);if(!a)throw"melonJS:"+c+" TSX tileset not found";me.TMXParser.parseFromString(a);a=me.TMXParser.getFirstElementByTagName("tileset")}this.name=me.TMXParser.getStringAttribute(a,me.TMX_TAG_NAME);this.tilewidth=me.TMXParser.getIntAttribute(a,me.TMX_TAG_TILEWIDTH);this.tileheight=me.TMXParser.getIntAttribute(a,me.TMX_TAG_TILEHEIGHT);this.spacing=me.TMXParser.getIntAttribute(a,me.TMX_TAG_SPACING,0);this.margin=me.TMXParser.getIntAttribute(a,me.TMX_TAG_MARGIN,
0);this.image=(c=a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE))?me.loader.getImage(me.utils.getBasename(c)):null;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))):
console.log("melonJS: '"+c+"' file for tileset '"+this.name+"' not found!");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);c=a.getElementsByTagName(me.TMX_TAG_TILEOFFSET);0<c.length&&(this.tileoffset.x=me.TMXParser.getIntAttribute(c[0],
me.TMX_TAG_X),this.tileoffset.y=me.TMXParser.getIntAttribute(c[0],me.TMX_TAG_Y));a=a.getElementsByTagName(me.TMX_TAG_TILE);for(c=0;c<a.length;c++){var b=me.TMXParser.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.type}},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},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]},drawTile:function(a,c,b,d){if(d.flipped){var g=1,f=0,e=0,l=1,n=c,k=b;c=b=0;a.save();d.flipAD&&
(g=0,e=f=1,l=0,k+=this.tileheight-this.tilewidth);d.flipX&&(g=-g,e=-e,n+=d.flipAD?this.tileheight:this.tilewidth);d.flipY&&(f=-f,l=-l,k+=d.flipAD?this.tilewidth:this.tileheight);a.transform(g,f,e,l,n,k)}g=d.tileId-this.firstgid;a.drawImage(this.image,this.getTileOffsetX(g),this.getTileOffsetY(g),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},canRender:function(a){return"orthogonal"===a.orientation&&this.width===a.width&&this.height===a.height&&this.tilewidth===a.tilewidth&&this.tileheight===a.tileheight},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,g){g.drawTile(a,g.tileoffset.x+c*this.tilewidth,g.tileoffset.y+(b+1)*this.tileheight-g.tileheight,d)},drawTileLayer:function(a,c,b,d){var g=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=g.y;d<b.y;d++)for(var f=g.x;f<b.x;f++){var e=c.layerData[f][d];e&&(c.tileset.contains(e.tileId)||(c.tileset=c.tilesets.getTilesetByGid(e.tileId)),
this.drawTile(a,f,d,e,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},canRender:function(a){return"isometric"===a.orientation&&this.width===a.width&&this.height===a.height&&this.tilewidth===a.tilewidth&&this.tileheight===a.tileheight},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,g){g.drawTile(a,(this.width-1)*g.tilewidth+(c-b)*g.tilewidth>>1,-g.tilewidth+(c+b)*g.tileheight>>2,d)},drawTileLayer:function(a,c,b,d){var g=c.tileset,f=g.tileoffset,e=this.pixelToTileCoords(b.x+d.pos.x-g.tilewidth,b.y+d.pos.y-g.tileheight).floorSelf(),l=this.pixelToTileCoords(b.x+d.pos.x+d.width+
g.tilewidth,b.y+d.pos.y+d.height+g.tileheight).ceilSelf(),l=this.tileToPixelCoords(l.x,l.y),n=this.tileToPixelCoords(e.x,e.y);n.x-=this.hTilewidth;n.y+=this.tileheight;var k=n.y-d.pos.y+b.y>this.hTileheight;b=d.pos.x+b.x-n.x<this.hTilewidth;k&&(b?(e.x--,n.x-=this.hTilewidth):(e.y--,n.x+=this.hTilewidth),n.y-=this.hTileheight);b^=k;d=e.clone();for(k=n.y;k-this.tileheight<l.y;k+=this.hTileheight){d.setV(e);for(var m=n.x;m<l.x;m+=this.tilewidth){if(0<=d.x&&0<=d.y&&d.x<this.width&&d.y<this.height){var q=
c.layerData[d.x][d.y];q&&(g.contains(q.tileId)||(g=c.tileset=c.tilesets.getTilesetByGid(q.tileId),f=g.tileoffset),g.drawTile(a,f.x+m,f.y+k-g.tileheight,q))}d.x++;d.y--}b?(e.y++,n.x-=this.hTilewidth,b=!1):(e.x++,n.x+=this.hTilewidth,b=!0)}}})})(window);
(function(a,c){me.ColorLayer=Object.extend({init:function(a,c,g){this.name=a;this.color=me.utils.HexToRGB(c);this.z=g;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,c){var g=a.globalAlpha;a.globalAlpha=this.opacity;a.fillStyle=this.color;a.fillRect(c.left,c.top,c.width,c.height);a.globalAlpha=g}});me.ImageLayer=Object.extend({ratio:1,init:function(a,
d,g,f,e,l){this.name=a;(this.image=f?me.loader.getImage(me.utils.getBasename(f)):null)||console.log("melonJS: '"+f+"' file for Image Layer '"+this.name+"' not found!");this.imagewidth=this.image.width;this.imageheight=this.image.height;this.z=e;this.ratio=l||1;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=g?Math.min(c.viewport.height,g):c.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=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,c){if(1>this.opacity){var g=a.globalAlpha;a.globalAlpha=this.opacity}if(0===this.ratio)k=Math.min(c.width,this.imagewidth),m=Math.min(c.height,
this.imageheight),a.drawImage(this.image,c.left,c.top,k,m,c.left,c.top,k,m);else{var f=~~this.offset.x,e=~~this.offset.y,l=0,n=0,k=Math.min(this.imagewidth-f,this.width),m=Math.min(this.imageheight-e,this.height);do{do a.drawImage(this.image,f,e,k,m,l,n,k,m),e=0,n+=m,m=Math.min(this.imageheight,this.height-n);while(this.repeatY&&n<this.height);l+=k;if(!this.repeatX||l>=this.width)break;f=0;k=Math.min(this.imagewidth,this.width-l);e=~~this.offset.y;n=0;m=Math.min(this.imageheight-~~this.offset.y,this.height)}while(1)}1>
this.opacity&&(a.globalAlpha=g)}});CollisionTiledLayer=Object.extend({init:function(a,c){this.realwidth=a;this.realheight=c;this.isCollisionMap=!0},reset:function(){},checkCollision:function(a,c){var g=0>c.x?a.left+c.x:a.right+c.x,f=0>c.y?a.top+c.y:a.bottom+c.y,e={x:0,y:0,xprop:{},yprop:{}};if(0>=g||g>=this.realwidth)e.x=c.x;if(0>=f||f>=this.realheight)e.y=c.y;return e}});me.TMXLayer=Object.extend({init:function(a,c,g,f,e,l){this.width=me.TMXParser.getIntAttribute(a,me.TMX_TAG_WIDTH);this.height=
me.TMXParser.getIntAttribute(a,me.TMX_TAG_HEIGHT);this.tilewidth=c;this.tileheight=g;this.realwidth=this.width*this.tilewidth;this.realheight=this.height*this.tileheight;this.z=l;this.layerData=null;this.tileset=(this.tilesets=e)?this.tilesets.getTilesetByIndex(0):null;this.orientation=f;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];c=me.TMXParser.getStringAttribute(a,me.TMX_TAG_ENCODING,null);g=me.TMXParser.getStringAttribute(a,me.TMX_TAG_COMPRESSION,null);""==c&&(c=null);""==g&&(g=null);if(!this.isCollisionMap)if(me.game.renderer.canRender(this))this.renderer=me.game.renderer;else 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,c,g)},reset:function(){this.preRender&&(this.layerSurface=this.layerCanvas=null);this.tilesets=this.tileset=this.layerData=this.renderer=null},initArray:function(){this.layerData=[];for(var a=0;a<this.width;a++){this.layerData[a]=[];for(var c=0;c<this.height;c++)this.layerData[a][c]=null}},fillArray:function(a,c,g){switch(g){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:g="";for(var f=0,e=a.childNodes.length;f<
e;f++)g+=a.childNodes[f].nodeValue;a=c==me.TMX_TAG_ATTR_BASE64?me.utils.decodeBase64AsArray(g,4):me.utils.decodeCSV(g,this.width);break;default:throw"melonJS: TMX Tile Map "+c+" encoding not supported!";}break;default:throw"melonJS: "+g+" compressed TMX Tile Map not supported!";}for(f=g=0;f<this.height;f++)for(e=0;e<this.width;e++){var l=null==c?me.TMXParser.getIntAttribute(a[g++],me.TMX_TAG_GID):a[g++];0!==l&&(l=new me.Tile(e,f,this.tilewidth,this.tileheight,l),this.layerData[e][f]=l,this.tileset.contains(l.tileId)||
(this.tileset=this.tilesets.getTilesetByGid(l.tileId)),this.visible&&this.preRender&&this.renderer.drawTile(this.layerSurface,e,f,l,this.tileset))}},getTileId:function(a,c){var g=this.getTile(a,c);return g?g.tileId:null},getTile:function(a,c){return this.layerData[~~(a/this.tilewidth)][~~(c/this.tileheight)]},setTile:function(a,c,g){this.layerData[a][c]=new me.Tile(a,c,this.tilewidth,this.tileheight,g)},clearTile:function(a,c){this.layerData[a][c]=null;this.visible&&this.preRender&&this.layerSurface.clearRect(a*
this.tilewidth,c*this.tileheight,this.tilewidth,this.tileheight)},getOpacity:function(){return this.opacity},setOpacity:function(a){a&&(this.opacity=a.clamp(0,1),this.preRender&&(this.layerSurface.globalAlpha=this.opacity))},checkCollision:function(a,c){var g=0>c.x?~~(a.left+c.x):Math.ceil(a.right-1+c.x),f=0>c.y?~~(a.top+c.y):Math.ceil(a.bottom-1+c.y),e={x:0,xtile:void 0,xprop:{},y:0,ytile:void 0,yprop:{}};0>=g||g>=this.realwidth?e.x=c.x:0!=c.x&&(e.xtile=this.getTile(g,Math.ceil(a.bottom-1)),e.xtile&&
this.tileset.isTileCollidable(e.xtile.tileId)?(e.x=c.x,e.xprop=this.tileset.getTileProperties(e.xtile.tileId)):(e.xtile=this.getTile(g,~~a.top),e.xtile&&this.tileset.isTileCollidable(e.xtile.tileId)&&(e.x=c.x,e.xprop=this.tileset.getTileProperties(e.xtile.tileId))));0!=c.y&&(e.ytile=this.getTile(0>c.x?~~a.left:Math.ceil(a.right-1),f),e.ytile&&this.tileset.isTileCollidable(e.ytile.tileId)?(e.y=c.y||1,e.yprop=this.tileset.getTileProperties(e.ytile.tileId)):(e.ytile=this.getTile(0>c.x?Math.ceil(a.right-
1):~~a.left,f),e.ytile&&this.tileset.isTileCollidable(e.ytile.tileId)&&(e.y=c.y||1,e.yprop=this.tileset.getTileProperties(e.ytile.tileId))));return e},update:function(){return!1},draw:function(a,d){var g=c.viewport.pos;if(this.preRender){var f=Math.min(d.width,this.realwidth),e=Math.min(d.height,this.realheight);a.drawImage(this.layerCanvas,g.x+d.pos.x,g.y+d.pos.y,f,e,g.x+d.pos.x,g.y+d.pos.y,f,e)}else f=a.globalAlpha,a.globalAlpha=this.opacity,this.renderer.drawTileLayer(a,this,g,d),a.globalAlpha=
f}})})(window,me.game);
(function(){me.TMXTileMap=Object.extend({init:function(a,c,b){this.pos=new me.Vector2d(c,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;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.tilesets=null;this.mapLayers.length=0;this.objectGroups.length=0;this.pos.set(0,0);this.initialized=!1}},load:function(){if(!this.initialized){var a=0;me.TMXParser.parseFromString(this.xmlMap,this.isJSON);for(var c=me.TMXParser.getAllTagElements(),b=0;b<c.length;b++)switch(c.item(b).nodeName){case me.TMX_TAG_MAP:var d=c.item(b);
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(null===me.game.renderer||!me.game.renderer.canRender(this))switch(this.orientation){case "orthogonal":me.game.renderer=new me.TMXOrthogonalRenderer(this.width,this.height,this.tilewidth,this.tileheight);break;case "isometric":me.game.renderer=new me.TMXIsometricRenderer(this.width,this.height,this.tilewidth,this.tileheight);break;default:throw"melonJS: "+this.orientation+" type TMX Tile Map not supported!";}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,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(c.item(b)));break;case me.TMX_TAG_IMAGE_LAYER:var d=me.TMXParser.getStringAttribute(c.item(b),me.TMX_TAG_NAME),g=me.TMXParser.getIntAttribute(c.item(b),me.TMX_TAG_WIDTH),f=me.TMXParser.getIntAttribute(c.item(b),me.TMX_TAG_HEIGHT),e=c.item(b).getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE),d=new me.ImageLayer(d,g*this.tilewidth,
f*this.tileheight,e,a++);d.visible=1==me.TMXParser.getIntAttribute(c.item(b),me.TMX_TAG_VISIBLE,1);d.opacity=me.TMXParser.getFloatAttribute(c.item(b),me.TMX_TAG_OPACITY,1);me.TMXUtils.setTMXProperties(d,c.item(b));this.mapLayers.push(d);break;case me.TMX_TAG_LAYER:this.mapLayers.push(new me.TMXLayer(c.item(b),this.tilewidth,this.tileheight,this.orientation,this.tilesets,a++));break;case me.TMX_TAG_OBJECTGROUP:d=me.TMXParser.getStringAttribute(c.item(b),me.TMX_TAG_NAME),this.objectGroups.push(new me.TMXOBjectGroup(d,
c.item(b),this.tilesets,a++))}me.TMXParser.free();this.initialized=!0}},getObjectGroupByName:function(a){var c=null;a=a.trim().toLowerCase();for(var b=this.objectGroups.length;b--;)if(this.objectGroups[b].name.toLowerCase().contains(a)){c=this.objectGroups[b];break}return c},getObjectGroups:function(){return this.objectGroups},getLayers:function(){return this.mapLayers},getLayerByName:function(a){var c=null;a=a.trim().toLowerCase();for(var 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]instanceof me.TMXLayer&&this.mapLayers[b].clearTile(a,c)}})})(window);
(function(){var a=me,c={},b={},d=[],g=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 e=me.state.isRunning();e&&me.state.pause();me.game.reset();me.utils.resetGUID(a);b[c.getCurrentLevelId()]&&
b[c.getCurrentLevelId()].reset();b[a].load();g=d.indexOf(a);me.game.loadTMXLevel(b[a]);e&&me.state.resume()}else throw"melonJS: no level loader defined";return!0};c.getCurrentLevelId=function(){return d[g]};c.reloadLevel=function(){return c.loadLevel(c.getCurrentLevelId())};c.nextLevel=function(){return g+1<d.length?c.loadLevel(d[g+1]):!1};c.previousLevel=function(){return 0<=g-1?c.loadLevel(d[g-1]):!1};c.levelCount=function(){return d.length};a.levelDirector=c})(window);
(function(){me.Tween=function(a){var c={},b={},d={},g=1E3,f=0,e=null,l=0,n=me.Tween.Easing.Linear.EaseNone,k=null,m=null,q=null;this.to=function(b,c){void 0!==c&&(g=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()+f;l=0;for(var g in d)null!==a[g]&&(c[g]=a[g],b[g]=d[g]-a[g]);return this};this.stop=function(){me.game.remove(this);return this};this.delay=function(a){f=a;return this};me.event.subscribe(me.event.STATE_PAUSE,function(){e&&
(l=me.timer.getTime())});me.event.subscribe(me.event.STATE_RESUME,function(){e&&l&&(e+=me.timer.getTime()-l)});this.easing=function(a){n=a;return this};this.chain=function(a){k=a;return this};this.onUpdate=function(a){m=a;return this};this.onComplete=function(a){q=a;return this};this.update=function(){var d,f,l;f=me.timer.getTime();if(f<e)return!0;if(1<=(f=(f-e)/g))f=1;l=n(f);for(d in b)a[d]=c[d]+b[d]*l;null!==m&&m.call(a,l);return 1===f?(me.game.remove(this),null!==q&&q.call(a),null!==k&&k.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.KEYDOWN="me.input.keydown";c.KEYUP="me.input.keyup";c.WINDOW_ONRESIZE="window.onresize";c.publish=function(a,c){for(var f=b[a],e=f?f.length:0;e--;)f[e].apply(window,c||[])};c.subscribe=function(a,c){b[a]||(b[a]=[]);b[a].push(c);return[a,c]};c.unsubscribe=
function(a,c){var f=b[c?a:a[0]];c=c||a[1];for(var e=f?f.length:0;e--;)f[e]===c&&f.splice(e,1)};a.event=c})();
(function(){var a=me,c={};c.Base=Object.extend({version:void 0,init:function(){}});c.patch=function(a,c,g){void 0!==a.prototype&&(a=a.prototype);if("function"==typeof a[c]){var f=a[c];a[c]=function(){var a=this.parent;this.parent=f;var b=g.apply(this,arguments);this.parent=a;return b}}else console.error(c+" is not an existing function")};c.register=function(a,c){me.plugin[c]&&console.error("plugin "+c+" 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 g=[];2<arguments.length&&(g=Array.prototype.slice.call(arguments,1));g[0]=a;me.plugin[c]=new (a.bind.apply(a,g));if(!(me.plugin[c]instanceof me.plugin.Base))throw"melonJS: Plugin should extend the me.plugin.Base Class !";};a.plugin=c})();
