-
Notifications
You must be signed in to change notification settings - Fork 15
/
melonJS-0.9.2-min.js
24 lines (24 loc) · 66.6 KB
/
melonJS-0.9.2-min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*!
* MelonJS Game Engine
* Copyright (C) 2011, Olivier BIOT
* http://www.melonjs.org
*
* melonJS is licensed under a Creative Commons
* Attribution-NonCommercial-ShareAlike 3.0 Unported License.
* http://creativecommons.org/licenses/by-nc-sa/3.0/
*
* @author Olivier Biot 2011
*
*/
(function(g,b){var k=g.document;me={mod:"melonJS",nocache:"",audio:null,video:null,timer:null,input:null,state:null,game:null,entityPool:null,levelDirector:null,XMLParser:null,loadingScreen:null,TMXTileMap:null};me.debug={displayFPS:false,renderHitBox:false,renderDirty:false};me.sys={ua:navigator.userAgent.toLowerCase(),sound:false,storage:false,gyro:(g.DeviceMotionEvent!==b),fps:60,interpolation:false,scale:1,useNativeAnimFrame:false,cacheImage:false,dirtyRegion:false,enableWebGL:false,stopOnAudioError:true};g.me=me;var h=false;var i=false,j=false,m=[];function c(){if(!j){if(!k.body){return setTimeout(c,13)}if(k.removeEventListener){k.removeEventListener("DOMContentLoaded",c,false)}else{g.removeEventListener("load",c,false)}j=true;for(var n=0;n<m.length;n++){m[n].call(g,[])}m=[]}}function f(){if(i){return}i=true;if(k.readyState==="complete"){return util.domReady()}else{if(k.addEventListener){k.addEventListener("DOMContentLoaded",c,false)}g.addEventListener("load",c,false)}}onReady=function(n){f();if(j){n.call(g,[])}else{m.push(function(){return n.call(g,[])})}return this};g.onReady(function(){a()});var e=false,l=/xyz/.test(function(){xyz})?/\bparent\b/:/.*/;Object.extend=function(s){var q=this.prototype;e=true;var r=new this();e=false;for(var o in s){r[o]=typeof s[o]=="function"&&typeof q[o]=="function"&&l.test(s[o])?(function(t,u){return function(){var w=this.parent;this.parent=q[t];var v=u.apply(this,arguments);this.parent=w;return v}})(o,s[o]):s[o]}function n(){if(!e&&this.init){this.init.apply(this,arguments)}}n.prototype=r;n.constructor=n;n.extend=arguments.callee;return n};if(typeof Object.create!=="function"){Object.create=function(n){function q(){}q.prototype=n;return new q()}}if(!Function.bind){Function.prototype.bind=function(){var q=this,o=Array.prototype.slice.call(arguments),n=o.shift();return function(){return q.apply(n,o.concat(Array.prototype.slice.call(arguments)))}}}Function.prototype.defer=function(){var o=this,n=Array.prototype.slice.call(arguments);return window.setTimeout(function(){return o.apply(o,n)},0.01)};if(!Object.defineProperty){Object.defineProperty=function(n,q,o){if(n.__defineGetter__){if(o.get){n.__defineGetter__(q,o.get)}if(o.set){n.__defineSetter__(q,o.set)}}else{throw"melonJS: Object.defineProperty not supported"}}}String.prototype.trim=function(){return(this.replace(/^\s+/,"")).replace(/\s+$/,"")};String.prototype.isNumeric=function(){return(this!=null&&!isNaN(this)&&this.trim()!="")};String.prototype.isBoolean=function(){return(this!=null&&("true"==this.trim()||"false"==this.trim()))};String.prototype.contains=function(n){return this.indexOf(n)>-1};Number.prototype.clamp=function(n,o){return this<n?n:this>o?o:this};Number.prototype.random=function(o,n){return(~~(Math.random()*(n-o+1))+o)};Number.prototype.round=function(){num=(arguments.length==1)?this:arguments[0];powres=Math.pow(10,arguments[1]||arguments[0]);return(Math.round(num*powres)/powres)};Number.prototype.toHex=function(){return"0123456789ABCDEF".charAt((this-this%16)>>4)+"0123456789ABCDEF".charAt(this%16)};Number.prototype.sign=function(){return this<0?-1:(this>0?1:0)};function d(){var n={xmlDoc:null,parser:null,parseFromString:function(o){if(g.DOMParser){parser=new DOMParser();xmlDoc=parser.parseFromString(o,"text/xml")}else{xmlDoc=new ActiveXObject("Microsoft.XMLDOM");xmlDoc.async="false";xmlDoc.loadXML(o)}if(xmlDoc==null){console.log("xml "+xmlDoc+" not found!")}},getFirstElementByTagName:function(o){return xmlDoc?xmlDoc.getElementsByTagName(o)[0]:null},getAllTagElements:function(){return xmlDoc?xmlDoc.getElementsByTagName("*"):null},getStringAttribute:function(q,s,r){var o=q.getAttribute(s);return o?o.trim().toLowerCase():r},getIntAttribute:function(q,s,r){var o=this.getStringAttribute(q,s,r);return o?parseInt(o):r},getFloatAttribute:function(q,s,r){var o=this.getStringAttribute(q,s,r);return o?parseFloat(o):r},getBooleanAttribute:function(q,s,r){var o=this.getStringAttribute(q,s,r);return o?(o=="true"):r},free:function(){xmlDoc=null;parser=null}};return n}function a(){if(h){return}var n=k.createElement("audio");me.utils.setNocache(k.location.href.match(/\?nocache/));if(n.canPlayType){me.audio.capabilities.mp3=("no"!=n.canPlayType("audio/mpeg"))&&(""!=n.canPlayType("audio/mpeg"));me.audio.capabilities.ogg=("no"!=n.canPlayType('audio/ogg; codecs="vorbis"'))&&(""!=n.canPlayType('audio/ogg; codecs="vorbis"'));me.audio.capabilities.wav=("no"!=n.canPlayType('audio/wav; codecs="1"'))&&(""!=n.canPlayType('audio/wav; codecs="1"'));me.sys.sound=me.audio.capabilities.mp3||me.audio.capabilities.ogg||me.audio.capabilities.wav}if((me.sys.ua.search("iphone")>-1)||(me.sys.ua.search("ipod")>-1)||(me.sys.ua.search("ipad")>-1)||(me.sys.ua.search("android")>-1)){me.sys.sound=false}me.timer.init();me.XMLParser=new d();me.loadingScreen=new me.DefaultLoadingScreen();me.state.init();me.entityPool.init();me.levelDirector.reset();h=true}drawManager=(function(){var o={};var r=[];var n;var q=[];o.isDirty=false;o.reset=function(){r=[];q=[];n=me.game.viewport.getRect();o.makeAllDirty()};o.makeDirty=function(u,s,t){if(s){o.isDirty=true;if(me.sys.dirtyRegion){if(t){r.push(t.union(u))}else{if(u.getRect){r.push(u.getRect())}}}}if(u.visible){q.splice(0,0,u)}};o.makeAllDirty=function(){r=[];r.push(n);o.isDirty=true};o.remove=function(s){q.splice(q.indexOf(s),1);wasVisible=s.visible;s.visible=false;o.makeDirty(s,true);s.visible=wasVisible};o.draw=function(s){for(var u=r.length,t;u--,t=r[u];){for(var w=q.length,v;w--,v=q[w];){if(me.sys.dirtyRegion&&v.isEntity&&!v.checkAxisAligned(t)){continue}v.draw(s,t)}if(me.debug.renderDirty){t.draw(s,"white")}}};o.flush=function(){if(me.sys.dirtyRegion){r=[]}q=[];o.isDirty=false};return o})();game=(function(){var r={};var q=null;var s=[];var n=0;var u=false;var t=[];var o=null;r.viewport=null;r.HUD=null;r.collisionMap=null;r.currentLevel=null;r.NO_OBJECT=0;r.ENEMY_OBJECT=1;r.COLLECTABLE_OBJECT=2;r.ACTION_OBJECT=3;r.init=function(w,v){if(!u){var w=w||me.video.getWidth();var v=v||me.video.getHeight();r.viewport=new me.Viewport(0,0,w,v);q=me.video.getScreenFrameBuffer();u=true}};r.reset=function(){if(o){clearTimeout(o)}o=null;if(!u){r.init()}r.removeAll();if(r.viewport){r.viewport.reset()}if(r.HUD!=null){r.add(r.HUD)}drawManager.reset()};r.loadTMXLevel=function(A){r.currentLevel=A;r.collisionMap=r.currentLevel.getLayerByName("collision");if(!r.collisionMap||!r.collisionMap.isCollisionMap){alert("WARNING : no collision map detected")}r.currentLevel.addTo(me.game);r.viewport.setBounds(r.currentLevel.realwidth,r.currentLevel.realheight);var v=r.currentLevel.getObjectGroups();for(var z=0;z<v.length;z++){for(var w=0;w<v[z].objects.length;w++){r.addEntity(v[z].objects[w],v[z].z)}}r.sort()};r.add=function(v,w){v.z=(w)?w:v.z;s.push(v);if(v.mouseEvent){t.push(v)}n=s.length};r.addEntity=function(v,w){r.add(me.entityPool.newIstanceOf(v),w)};r.getEntityByName=function(z){var v=[];for(var w=n,A;w--,A=s[w];){if(A.isEntity&&A.name==z){v.push(A)}}return v};r.addHUD=function(v,C,z,B,A){if(r.HUD==null){r.HUD=new me.HUD_Object(v,C,z,B,A);r.add(r.HUD)}};r.disableHUD=function(){if(r.HUD!=null){r.remove(r.HUD);r.HUD=null}};r.mouseEvent=function(v,z){for(var w=t.length;w--;){t[w].mouseEvent(v,z)}};r.update=function(){me.timer.update();for(var v=n,w;v--,w=s[v];){oldRect=(me.sys.dirtyRegion&&w.isEntity)?w.getRect():null;updated=w.update();if(w.isEntity&&!w.flickering){w.visible=r.viewport.isVisible(w.collisionBox)}drawManager.makeDirty(w,updated,updated?oldRect:null)}if(r.viewport.update(drawManager.isDirty)){drawManager.makeAllDirty()}};r.remove=function(v){if(!v.destroy||v.destroy()){v.visible=false;v.isEntity=false;drawManager.remove(v);if(v.mouseEvent){t.splice(t.indexOf(v),1)}o=(function(w){idx=s.indexOf(w);if(idx!=-1){s.splice(idx,1);n=s.length}o=null}).defer(v)}};r.removeAll=function(){n=0;s=[];t=[];drawManager.flush()};r.sort=function(){s.sort(function(w,v){return(v.z-w.z)});r.repaint()};r.collide=function(w){var v=null;for(var z=n,A;z--,A=s[z];){if(A.visible&&A.collidable&&A.isEntity&&(A!=w)){if(v=A.checkCollision(w)){break}}}return v};r.repaint=function(){drawManager.makeAllDirty()};r.draw=function(){if(drawManager.isDirty){drawManager.draw(q);r.viewport.draw(q)}drawManager.flush()};return r})();ScreenObject=Object.extend({visible:true,addAsObject:false,rect:null,init:function(n){this.addAsObject=n;this.visible=(n===true)||false;this.rect=new me.Rect(new Vector2d(0,0),0,0)},reset:function(){me.game.reset();if(this.addAsObject){this.visible=true;this.rect=me.game.viewport.getRect();me.game.add(this,999)}this.onResetEvent.apply(this,arguments);me.game.sort()},getRect:function(){return this.rect},destroy:function(){this.onDestroyEvent.apply(this,arguments);return true},update:function(){return false},onUpdateFrame:function(){me.game.update();me.game.draw();me.video.blitSurface()},draw:function(){},onResetEvent:function(){},onDestroyEvent:function(){}});g.me.ScreenObject=ScreenObject;window.requestAnimFrame=(function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(){return -1}})();window.cancelRequestAnimFrame=(function(){return window.cancelAnimationFrame||window.webkitCancelRequestAnimationFrame||window.mozCancelRequestAnimationFrame||window.oCancelRequestAnimationFrame||window.msCancelRequestAnimationFrame||function(){return -1}})();state=(function(){var v={};var s=-1;var C=-1;var r=-1;var w={};var n={color:"",duration:0};var q=null;var z=null;var A=null;var u=null;function t(){if((C==-1)&&(r==-1)){me.timer.reset();if(me.sys.useNativeAnimFrame){r=window.requestAnimFrame(D);if(r!=-1){return}me.sys.useNativeAnimFrame=false}C=setInterval(A,u)}}function D(){A();window.requestAnimFrame(D)}function o(){if(C!=-1){clearInterval(C);C=-1}if(r!=-1){cancelRequestAnimFrame(r);r=-1}}function B(E){o();if(w[s]){if(w[s].screen.visible){me.game.remove(w[s].screen)}else{w[s].screen.destroy()}}s=E;w[s].screen.reset.apply(w[s].screen,z);A=w[s].screen.onUpdateFrame;t();if(q){q()}me.game.repaint()}v.LOADING=0;v.MENU=1;v.READY=2;v.PLAY=3;v.GAMEOVER=4;v.GAME_END=5;v.SCORE=6;v.CREDITS=7;v.SETTINGS=8;v.onPause=null;v.onResume=null;v.init=function(){v.set(v.LOADING,me.loadingScreen);g.addEventListener("blur",function(){if(s!=v.LOADING){v.pause(true);if(v.onPause){v.onPause()}}},false);g.addEventListener("focus",function(){if(s!=v.LOADING){v.resume(true);if(v.onResume){v.onResume()}me.game.repaint()}},false);u=~~(1000/me.sys.fps)};v.pause=function(E){o();if(E){me.audio.pauseTrack()}};v.resume=function(E){t(s);if(E){me.audio.resumeTrack()}};v.isRunning=function(){return((C!=-1)||(r!=-1))};v.set=function(E,F){w[E]={};w[E].screen=F;w[E].transition=true};v.current=function(){return w[s].screen};v.transition=function(F,E,G){if(F=="fade"){n.color=E;n.duration=G}};v.setTransition=function(F,E){w[F].transition=E};v.change=function(E){switch(E){case v.LOADING:case v.MENU:case v.PLAY:case v.READY:case v.GAMEOVER:case v.GAME_END:case v.SCORE:case v.CREDITS:case v.SETTINGS:z=null;if(arguments.length>1){z=Array.prototype.slice.call(arguments,1)}if(n.duration&&w[E].transition){q=function(){me.game.viewport.fadeOut(n.color,n.duration)};me.game.viewport.fadeIn(n.color,n.duration,function(){B(E)})}else{B.defer(E)}break;default:break}};v.isCurrent=function(E){return s==E};return v})();g.me.state=state;g.me.game=game})(window);(function(b,c){var a=me.ScreenObject.extend({init:function(){this.parent(true);this.logo1=new me.Font("century gothic",32,"white");this.logo2=new me.Font("century gothic",32,"#89b002");this.logo2.bold();this.invalidate=false;this.loadPercent=0;me.loader.onProgress=this.onProgressUpdate.bind(this)},onDestroyEvent:function(){this.logo1=this.logo2=null},onProgressUpdate:function(d){this.loadPercent=d;this.invalidate=true},update:function(){if(this.invalidate===true){this.invalidate=false;return true}return false},draw:function(d){var f=d.canvas.height/2;me.video.clearSurface(d,"black");logo1_width=this.logo1.measureText(d,"melon").width;logo_width=logo1_width+this.logo2.measureText(d,"JS").width;this.logo1.draw(d,"melon",((d.canvas.width-logo_width)/2),(d.canvas.height+60)/2);this.logo2.draw(d,"JS",((d.canvas.width-logo_width)/2)+logo1_width,(d.canvas.height+60)/2);f+=40;var e=Math.floor(this.loadPercent*d.canvas.width);d.strokeStyle="silver";d.strokeRect(0,f,d.canvas.width,6);d.fillStyle="#89b002";d.fillRect(2,f+2,e-4,2)},});loader=(function(){var l={};var f=[];var d={};var m=0;var h=0;var j=0;var i=0;function g(){if(h==(m-i)){for(var o in d){if(d[o].isTMX){me.levelDirector.addTMXLevel(o);l.onResourceLoaded()}}if(l.onload){j=setTimeout(l.onload,300)}else{alert("no load callback defined")}}else{j=setTimeout(g,100)}}function k(o){throw"melonJS: Failed loading image resource"}function n(q,r,o){f.push(q.name);f[q.name]=new Image();f[q.name].onload=r||l.onResourceLoaded.bind(l);f[q.name].onerror=o||k.bind(this);f[q.name].src=q.src+me.nocache}function e(q,o){if(b.XMLHttpRequest){xmlhttp=new XMLHttpRequest();if(xmlhttp.overrideMimeType){xmlhttp.overrideMimeType("text/xml")}}else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")}xmlhttp.open("GET",q.src+me.nocache,false);xmlhttp.onload=l.onResourceLoaded.bind(l);xmlhttp.send();d[q.name]={};d[q.name].xml=xmlhttp.responseText;d[q.name].isTMX=o||false;if(d[q.name].isTMX){m+=1;i+=1}}l.onload=c;l.onProgress=c;l.onResourceLoaded=function(o){h++;if(l.onProgress){l.onProgress(l.getLoadProgress())}};l.preload=function(q){me.audio.setLoadCallback(l.onResourceLoaded.bind(l));for(var o=0;o<q.length;o++){switch(q[o].type){case"image":n(q[o]);m+=1;break;case"audio":if(me.audio.isAudioEnable()){me.audio.load(q[o]);m+=1}break;case"tmx":e(q[o],true);m+=1;break;default:throw"melonJS: me.loader.preload : unknow resource type : %s"+q[o].type;break}}g()};l.load=function(q,r,o){switch(q.type){case"image":n(q,r,o);break;default:throw"melonJS: me.loader.load : unknow or invalide resource type : %s"+q.type;break}};l.getXML=function(o){if(d!=null){return d[o].xml}else{return null}};l.getImage=function(o){if(f[o]!=null){if(me.sys.cacheImage===true){var q=me.video.createCanvasSurface(f[o].width,f[o].height);q.drawImage(f[o],0,0);return q.canvas}else{return f[o]}}else{return null}};l.getLoadProgress=function(){return h/m};return l})();b.me.loader=loader;b.me.DefaultLoadingScreen=a})(window);(function(a,b){Vector2d=Object.extend({x:0,y:0,init:function(c,d){this.x=c||0;this.y=d||0},set:function(c,d){this.x=c;this.y=d},setZero:function(){this.set(0,0)},setV:function(c){this.x=c.x;this.y=c.y},add:function(c){this.x+=c.x;this.y+=c.y},sub:function(c){this.x-=c.x;this.y-=c.y},scale:function(c){this.x*=c.x;this.y*=c.y},div:function(c){this.x/=c;this.y/=c},abs:function(){if(this.x<0){this.x=-this.x}if(this.y<0){this.y=-this.y}},clamp:function(c,d){return new Vector2d(this.x.clamp(c,d),this.y.clamp(c,d))},minV:function(c){this.x=this.x<c.x?this.x:c.x;this.y=this.y<c.y?this.y:c.y},maxV:function(c){this.x=this.x>c.x?this.x:c.x;this.y=this.y>c.y?this.y:c.y},negate:function(){return new Vector2d(-this.x,-this.y)},negateSelf:function(){this.x=-this.x;this.y=-this.y},copy:function(c){this.x=c.x;this.y=c.y},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},normalize:function(){var c=this.length();if(c<Number.MIN_VALUE){return 0}var d=1/c;this.x*=d;this.y*=d;return c},dotProduct:function(c){return this.x*c.x+this.y*c.y},distance:function(c){return Math.sqrt((this.x-c.x)*(this.x-c.x)+(this.y-c.y)*(this.y-c.y))},clone:function(){return new Vector2d(this.x,this.y)},toString:function(){return"x:"+this.x+"y:"+this.y},});Rect=Object.extend({pos:null,colPos:null,left:null,right:null,top:null,bottom:null,width:0,height:0,hWidth:0,hHeight:0,init:function(d,c,e){this.pos=d;this.colPos=new Vector2d();this.width=c;this.height=e;this.hWidth=~~(c/2);this.hHeight=~~(e/2);Object.defineProperty(this,"left",{get:function(){return this.pos.x},configurable:true});Object.defineProperty(this,"right",{get:function(){return this.pos.x+this.width},configurable:true});Object.defineProperty(this,"top",{get:function(){return this.pos.y},configurable:true});Object.defineProperty(this,"bottom",{get:function(){return this.pos.y+this.height},configurable:true})},set:function(d,c,e){this.pos=d;this.width=c;this.height=e;this.hWidth=~~(c/2);this.hHeight=~~(e/2)},getRect:function(){return new me.Rect(this.pos.clone(),this.width,this.height)},union:function(c){x1=Math.min(this.pos.x,c.pos.x);y1=Math.min(this.pos.y,c.pos.y);this.width=Math.ceil(Math.max(this.pos.x+this.width,c.pos.x+c.width)-x1);this.height=Math.ceil(Math.max(this.pos.y+this.height,c.pos.y+c.height)-y1);this.pos.x=~~x1;this.pos.y=~~y1;return this},adjustSize:function(c,d,f,e){if(c!=-1){this.colPos.x=c;this.width=d;this.hWidth=~~(this.width/2);Object.defineProperty(this,"left",{get:function(){return this.pos.x+this.colPos.x},configurable:true});Object.defineProperty(this,"right",{get:function(){return this.pos.x+this.colPos.x+this.width},configurable:true})}if(f!=-1){this.colPos.y=f;this.height=e;this.hHeight=~~(this.height/2);Object.defineProperty(this,"top",{get:function(){return this.pos.y+this.colPos.y},configurable:true});Object.defineProperty(this,"bottom",{get:function(){return this.pos.y+this.colPos.y+this.height},configurable:true})}},flipX:function(c){this.colPos.x=c-this.width-this.colPos.x;this.hWidth=~~(this.width/2)},flipY:function(c){this.colPos.y=c-this.height-this.colPos.y;this.hHeight=~~(this.height/2)},checkAxisAligned:function(c){return(this.left<c.right&&c.left<this.right&&this.top<c.bottom&&c.top<this.bottom)},collideVsAABB:function(e){p=new Vector2d(0,0);if(this.checkAxisAligned(e)){var d=this.left+this.hWidth-e.left-e.hWidth;var c=this.top+this.hHeight-e.top-e.hHeight;p.x=(e.hWidth+this.hWidth)-(d<0?-d:d);p.y=(e.hHeight+this.hHeight)-(c<0?-c:c);if(p.x<p.y){p.y=0;p.x=d<0?-p.x:p.x}else{p.x=0;p.y=c<0?-p.y:p.y}}return p},draw:function(d,c){d.strokeStyle=c||"red";d.strokeRect(this.left-me.game.viewport.pos.x,this.top-me.game.viewport.pos.y,this.width,this.height)}});a.me.Vector2d=Vector2d;a.me.Rect=Rect})(window);(function(b,d){var a=Math.min,c=Math.max;ViewportEntity=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(e,j,i,h,f,g){this.parent(new me.Vector2d(e,j),i-e,h-j);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(f||this.width,g||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,onComplete:null};this._fadeIn={color:0,alpha:0,duration:0,onComplete:null};this.setDeadzone(this.width/6,this.height/6)},_followH:function(e){if((e.x-this.pos.x)>(this._deadwidth)){this.pos.x=~~a((e.x)-(this._deadwidth),this._limitwidth)}else{if((e.x-this.pos.x)<(this.deadzone.x)){this.pos.x=~~c((e.x)-this.deadzone.x,0)}}},_followV:function(e){if((e.y-this.pos.y)>(this._deadheight)){this.pos.y=~~a((e.y)-(this._deadheight),this._limitheight)}else{if((e.y-this.pos.y)<(this.deadzone.y)){this.pos.y=~~c((e.y)-this.deadzone.y,0)}}},reset:function(e,f){this.pos.x=e||0;this.pos.y=f||0;this.last.set(-1,-1);this.target=null;this.follow_axis=null},setDeadzone:function(e,f){this.deadzone=new me.Vector2d(~~((this.width-e)/2),~~((this.height-f)/2-f*0.25));this._deadwidth=this.width-this.deadzone.x;this._deadheight=this.height-this.deadzone.y;this.update(true)},setBounds:function(e,f){this.limits.set(e,f);this._limitwidth=this.limits.x-this.width;this._limitheight=this.limits.y-this.height},follow:function(f,e){if(f instanceof me.ObjectEntity){this.target=f.pos}else{if(f instanceof me.Vector2d){this.target=f}else{throw"melonJS: invalid target for viewport.follow"}}this.follow_axis=e||this.AXIS.BOTH;this.update(true)},move:function(e,f){newx=~~(this.pos.x+e);newy=~~(this.pos.y+f);if((newx>=0)&&(newx<=this._limitwidth)){this.pos.x=newx}if((newy>=0)&&(newy<=this._limitheight)){this.pos.y=newy}},update:function(g){if(this.target&&g){switch(this.follow_axis){case this.AXIS.NONE:break;case this.AXIS.HORIZONTAL:this._followH(this.target,(this._shake.duration>0));break;case this.AXIS.VERTICAL:this._followV(this.target,(this._shake.duration>0));break;case this.AXIS.BOTH:this._followH(this.target,(this._shake.duration>0));this._followV(this.target,(this._shake.duration>0));break;default:break}g=(this.last.x!=this.pos.x)||(this.last.y!=this.pos.y);this.last.copy(this.pos)}if(this._shake.duration>0){this._shake.duration-=me.timer.tick;if(this._shake.duration<0){if(this._shake.onComplete){this._shake.onComplete()}}else{if((this._shake.axis==this.AXIS.BOTH)||(this._shake.axis==this.AXIS.HORIZONTAL)){var f=(Math.random()*this._shake.intensity);if(this.pos.x+this.width+f<this.limits.x){this.pos.x+=~~f}else{this.pos.x-=~~f}}if((this._shake.axis==this.AXIS.BOTH)||(this._shake.axis==this.AXIS.VERTICAL)){var e=(Math.random()*this._shake.intensity);if(this.pos.y+this.height+e<this.limits.y){this.pos.y+=~~e}else{this.pos.y-=~~e}}g=true}}if(this._fadeIn.alpha<1){this._fadeIn.alpha+=me.timer.tick/this._fadeIn.duration;if(this._fadeIn.alpha>=1){this._fadeIn.alpha=1;if(this._fadeIn.onComplete){this._fadeIn.onComplete()}}g=true}if(this._fadeOut.alpha>0){this._fadeOut.alpha-=me.timer.tick/this._fadeOut.duration;if(this._fadeOut.alpha<=0){this._fadeOut.alpha=0;if(this._fadeOut.onComplete){this._fadeOut.onComplete()}}g=true}return g},shake:function(e,h,f,g){f=f||this.AXIS.BOTH;if(f==this.AXIS.BOTH){if(this.width==this.limits.x){f=this.AXIS.VERTICAL}else{if(this.height==this.limits.y){f=this.AXIS.HORIZONTAL}}}if((f==this.AXIS.HORIZONTAL)&&(this.width==this.limits.x)){return}if((f==this.AXIS.VERTICAL)&&(this.height==this.limits.y)){return}this._shake.intensity=e;this._shake.duration=h;this._shake.axis=f;this._shake.onComplete=g||null},fadeOut:function(e,g,f){this._fadeOut.color=e;this._fadeOut.duration=g||30;this._fadeOut.alpha=1;this._fadeOut.onComplete=f||null},fadeIn:function(e,g,f){this._fadeIn.color=e;this._fadeIn.duration=g||30;this._fadeIn.alpha=0;this._fadeIn.onComplete=f||null},getWidth:function(){return this.width},getHeight:function(){return this.height},focusOn:function(e){this.pos.x=e.x-this.width*0.5;this.pos.y=e.y-this.height*0.5},isVisible:function(e){return this.checkAxisAligned(e)},draw:function(e){if(this._fadeIn.alpha<1){if(me.sys.enableWebGL){me.video.clearSurface(e,me.utils.HexToRGB(this._fadeIn.color,this._fadeIn.alpha))}else{e.globalAlpha=this._fadeIn.alpha;me.video.clearSurface(e,me.utils.HexToRGB(this._fadeIn.color));e.globalAlpha=1}}if(this._fadeOut.alpha>0){if(me.sys.enableWebGL){me.video.clearSurface(e,me.utils.HexToRGB(this._fadeOut.color,this._fadeOut.alpha))}else{e.globalAlpha=this._fadeOut.alpha;me.video.clearSurface(e,me.utils.HexToRGB(this._fadeOut.color));e.globalAlpha=1}}}});b.me.Viewport=ViewportEntity})(window);(function(b,c){var a=Math.min;ObjectSettings={name:null,image:null,spritewidth:null,type:0,collidable:false};me.ObjectSettings=ObjectSettings;entityPool=(function(){var e={};var d={};e.init=function(){e.add("me.LevelEntity",LevelEntity);e.add("me.ObjectEntity",ObjectEntity);e.add("me.CollectableEntity",CollectableEntity);e.add("me.InvisibleEntity",InvisibleEntity)};e.add=function(g,f){d[g.toLowerCase()]=f};e.newIstanceOf=function(f){if(!d[f.name]){alert("cannot instance entity of type '"+f.name+"': Class not found!");return null}return new d[f.name](f.x,f.y,f)};return e})();b.me.entityPool=entityPool;ParallaxLayer=me.Rect.extend({init:function(d,f,e){this.image=me.loader.getImage(d);this.parent(new me.Vector2d(0,0),this.image.width,this.image.height);this.baseOffset=0;this.z=e||0;this.scrollspeed=f;this.vp_width=me.game.viewport.width},draw:function(g,d,h){var f=0;var e=a(this.width-d,this.vp_width);do{g.drawImage(this.image,d,0,e,this.height,f,h,e,this.height);f+=e;d=0;e=a(this.width,this.vp_width-f)}while((f<this.vp_width))}});ParallaxBackgroundEntity=me.Rect.extend({init:function(d){this.parent(new me.Vector2d(0,0),0,0);this.name="parallaxBackgroundEntity";this.visible=true;this.z=d||0;this.vp=me.game.viewport.pos;this.lastx=this.vp.x;this.parallaxLayers=[];this.updated=true},addLayer:function(e,g,f){var d=this.parallaxLayers.length;this.parallaxLayers.push(new ParallaxLayer(e,g,f));if(this.parallaxLayers[d].width>this.width){this.width=this.parallaxLayers[d].width}if(this.parallaxLayers[d].height>this.height){this.height=this.parallaxLayers[d].height}},clearTile:function(d,e){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(f){x=this.vp.x;if(x>this.lastx){for(var e=0,d;d=this.parallaxLayers[e++];){d.baseOffset=(d.baseOffset+d.scrollspeed*me.timer.tick)%d.width;d.draw(f,~~d.baseOffset,0);this.lastx=x;this.updated=true}return}else{if(x<this.lastx){for(var e=0,d;d=this.parallaxLayers[e++];){d.baseOffset=(d.width+(d.baseOffset-d.scrollspeed*me.timer.tick))%d.width;d.draw(f,~~d.baseOffset,0);this.lastx=x;this.updated=true}return}}for(var e=0,d;d=this.parallaxLayers[e++];){d.draw(f,~~d.baseOffset,0);this.lastx=x;this.updated=false}}});b.me.ParallaxBackgroundEntity=ParallaxBackgroundEntity;SpriteObject=me.Rect.extend({scale:null,lastflipX:false,lastflipY:false,z:0,currentSprite:0,currentSpriteOff:0,scaleFlag:false,autodestroy:true,visible:true,image:null,collisionBox:null,vp:null,fpscount:0,animationspeed:0,init:function(d,g,f,e){this.parent(new me.Vector2d(d,g),e||f.width,f.height);this.image=f;this.spritecount=e?~~(f.width/e):1;this.scale=new me.Vector2d(1,1);this.collisionBox=new me.Rect(this.pos,this.width,this.height);this.vp=me.game.viewport;this.animationspeed=me.sys.fps/10;this.currentSprite=0,this.currentSpriteOff=0;if(this.image.width==e){this.update=function(){return false}}},flipX:function(d){if(d!=this.lastflipX){this.lastflipX=d;this.scale.x=-this.scale.x;this.scaleFlag=((this.scale.x!=1)||(this.scale.y!=1));this.collisionBox.flipX(this.width)}},flipY:function(d){if(d!=this.lastflipY){this.lastflipY=d;this.scale.y=-this.scale.y;this.scaleFlag=((this.scale.x!=1)||(this.scale.y!=1));this.collisionBox.flipY(this.height)}},setCurrentSprite:function(d){this.currentSprite=d;this.currentSpriteOff=this.width*d},update:function(){if(this.visible&&(this.fpscount++>this.animationspeed)){this.setCurrentSprite(++this.currentSprite%this.spritecount);this.fpscount=0;return true}return false},draw:function(e){var d=this.pos.x-this.vp.pos.x,f=this.pos.y-this.vp.pos.y;if(this.scaleFlag){e.scale(this.scale.x,this.scale.y);d=(d*this.scale.x)-(this.scale.x<0?this.width:0);f=(f*this.scale.y)-(this.scale.y<0?this.height:0)}e.drawImage(this.image,this.currentSpriteOff,0,this.width,this.height,~~d,~~f,this.width,this.height);if(this.scaleFlag){e.setTransform(1,0,0,1,0,0)}if(me.debug.renderHitBox){this.parent(e,"blue");this.collisionBox.draw(e,"red")}},destroy:function(){if(this.autodestroy){this.onDestroyEvent()}return this.autodestroy},onDestroyEvent:function(){}});b.me.SpriteObject=SpriteObject;AnimationSheet=me.SpriteObject.extend({init:function(d,g,f,e){this.anim=[];this.resetAnim=null;this.current=null;this.parent(d,g,f,e);if(this.image.width==e){this.update=function(){return false}}else{this.addAnimation("default",null);this.setCurrentAnimation("default")}},addAnimation:function(e,g){this.anim[e]={name:null,frame:[],idx:0,length:0};if(g==null){for(var f=0;f<this.spritecount;f++){this.anim[e].frame[f]=f*this.width}}else{var d=0;for(var f=0;f<g.length;f++){this.anim[e].frame[d]=g[f]*this.width;d++}}this.anim[e].name=e;this.anim[e].length=this.anim[e].frame.length},setCurrentAnimation:function(d,e){this.current=this.anim[d];this.resetAnim=e||null;this.currentSpriteOff=this.current.frame[this.current.idx]},isCurrentAnimation:function(d){return(this.current.name==d)},setCurrentSprite:function(d){this.current.idx=d;this.currentSpriteOff=this.current.frame[d]},update:function(){if(this.visible&&(this.fpscount++>this.animationspeed)){this.setCurrentSprite(++this.current.idx%this.current.length);if((this.current.idx==0)&&this.resetAnim){this.setCurrentAnimation(this.resetAnim)}this.fpscount=0;return true}return false}});b.me.AnimationSheet=AnimationSheet;ObjectEntity=AnimationSheet.extend({type:0,collidable:false,init:function(d,f,e){this.parent(d,f,(typeof e.image=="string")?me.loader.getImage(e.image):e.image,e.spritewidth);this.name=e.name;this.pos.set(d,f+me.game.currentLevel.tileheight-this.height);this.vel=new me.Vector2d();this.accel=new me.Vector2d();this.friction=new me.Vector2d();this.maxVel=new me.Vector2d(1000,1000);this.gravity=0.98;this.isEntity=true;this.canBreakTile=false;this.alive=true;this.falling=false;this.jumping=false;this.jumpspeed=0;this.slopeY=0;this.onslope=false;this.onladder=false;this.collidable=e.collidable||false;this.type=e.type||0;this.flickering=false;this.flickerTimer=-1;this.flickercb=null;this.collisionMap=me.game.collisionMap;this.onTileBreak=null},updateColRect:function(d,e,g,f){this.collisionBox.adjustSize(d,e,g,f)},checkCollision:function(e){var d=this.collisionBox.collideVsAABB(e.collisionBox);if(d.x!=0||d.y!=0){this.onCollision(d,e);d.type=this.type;return d}return null},onCollision:function(d,e){if(this.collidable&&(this.type==me.game.COLLECTABLE_OBJECT)){me.game.remove(this)}},setVelocity:function(d,e){this.accel.x=(d!=0)?d:this.accel.x;this.accel.y=(d!=0)?e:this.accel.y;this.setMaxVelocity(d,e)},setMaxVelocity:function(d,e){this.maxVel.x=d;this.maxVel.y=e},setFriction:function(d,e){this.friction.x=d||0;this.friction.y=e||0},doWalk:function(d){this.flipX(d);this.vel.x+=(d)?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(d){if(this.onladder){this.vel.y=(d)?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick;return true}return false},doJump:function(){if(!this.jumping&&!this.falling){this.jumpspeed=this.accel.y;this.jumping=true;if(this.onslope){}return true}return false},forceJump:function(){this.jumping=false;this.falling=false;this.doJump()},distanceTo:function(d){dx=(this.pos.x+(this.width>>1))-(d.pos.x+(d.width>>1));dy=(this.pos.y+(this.height>>1))-(d.pos.y+(d.height>>1));return Math.sqrt(dx*dx+dy*dy)},checkSlope:function(d,e){this.pos.y=d.pos.y-this.height;if(e){this.slopeY=d.height-(this.collisionBox.right+this.vel.x-d.pos.x)}else{this.slopeY=(this.collisionBox.left+this.vel.x-d.pos.x)}this.slopeY=this.slopeY.clamp(0,d.height);if((this.vel.x!=0)||this.falling){this.vel.y=this.slopeY}else{this.vel.y=0;this.pos.y+=this.slopeY}},computeVelocity:function(d){if(this.jumping){this.jumpspeed-=this.gravity;if((this.jumpspeed<0)){this.jumping=false;this.falling=true;d.y=0}else{d.y=-this.jumpspeed}}else{if(!this.onladder&&this.gravity){this.falling=true;d.y+=(this.gravity*me.timer.tick)}}if(this.friction.x){d.x=me.utils.applyFriction(d.x,this.friction.x)}if(this.friction.y){d.y=me.utils.applyFriction(d.y,this.friction.y)}if(d.y!=0){d.y=d.y.clamp(-this.maxVel.y,this.maxVel.y)}if(d.x!=0){d.x=d.x.clamp(-this.maxVel.x,this.maxVel.x)}return d},updateMovement:function(){this.vel=this.computeVelocity(this.vel);collision=this.collisionMap.checkCollision(this.collisionBox,this.vel);this.onladder=collision.xprop.isLadder;this.onslope=collision.yprop.isSlope||collision.xprop.isSlope;if(collision.y){if(this.vel.y>0){if(collision.yprop.isSolid||(collision.yprop.isPlatform&&(~~this.pos.y+this.height<=collision.ytile.pos.y))){this.pos.y=~~this.pos.y;this.vel.y=(this.falling)?collision.ytile.pos.y-this.pos.y-this.height:0;this.falling=false}else{if(collision.yprop.isSlope&&!this.jumping){this.checkSlope(collision.ytile,collision.yprop.isLeftSlope);this.falling=false}else{if(collision.yprop.isBreakable){if(this.canBreakTile){me.game.currentLevel.clearTile(collision.ytile.row,collision.ytile.col);if(this.onTileBreak){this.onTileBreak()}}else{this.pos.y=~~this.pos.y;this.vel.y=(this.falling)?collision.ytile.pos.y-this.pos.y-this.height:0;this.falling=false}}}}}else{if(this.vel.y<0){if(!collision.yprop.isPlatform&&!collision.yprop.isLadder){this.jumping=false;this.falling=true;this.vel.y=0}}}}if(collision.x){if(collision.xprop.isSlope&&!this.jumping){this.checkSlope(collision.xtile,collision.xprop.isLeftSlope);this.falling=false}else{if(!collision.xprop.isPlatform&&!collision.xprop.isLadder){if(collision.xprop.isBreakable&&this.canBreakTile){me.game.currentLevel.clearTile(collision.xtile.row,collision.xtile.col);if(this.onTileBreak){this.onTileBreak()}}else{this.vel.x=0}}}}this.updateFlickering();if((this.vel.x!=0)||(this.vel.y!=0)){this.pos.add(this.vel);if((this.onslope&&!this.jumping)||this.onladder){this.vel.y=0}return true}return false},updateFlickering:function(){if(this.flickering){this.flickerTimer-=me.timer.tick;if(this.flickerTimer<0){if(this.flickercb){this.flickercb()}this.flicker(-1)}else{this.visible=!this.visible;return true}}return false},flicker:function(d,e){this.flickerTimer=d;if(this.flickerTimer<0){this.flickering=false;this.visible=true;this.flickercb=null}else{if(!this.flickering){this.flickercb=e;this.flickering=true}}}});b.me.ObjectEntity=ObjectEntity;CollectableEntity=ObjectEntity.extend({init:function(d,f,e){this.parent(d,f,e);this.collidable=true;this.type=me.game.COLLECTABLE_OBJECT}});b.me.CollectableEntity=CollectableEntity;InvisibleEntity=me.Rect.extend({z:0,collisionBox:null,init:function(d,f,e){this.parent(new me.Vector2d(d,f),e.width,e.height);this.collisionBox=new me.Rect(this.pos,e.width,e.height);this.visible=true;this.collidable=true;this.isEntity=true},updateColRect:function(d,e,g,f){this.collisionBox.adjustSize(d,e,g,f)},checkCollision:function(e){var d=this.collisionBox.collideVsAABB(e.collisionBox);if(d.x!=0||d.y!=0){this.onCollision(d,e);d.type=this.type;return d}return null},onCollision:function(d,e){if(this.collidable&&(this.type==me.game.COLLECTABLE_OBJECT)){me.game.remove(this)}},destroy:function(){this.onDestroyEvent();return true},onDestroyEvent:function(){},update:function(){return false},draw:function(d){if(me.debug.renderHitBox){d.strokeStyle="blue";d.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height);this.collisionBox.draw(d)}}});b.me.InvisibleEntity=InvisibleEntity;LevelEntity=InvisibleEntity.extend({init:function(d,f,e){this.parent(d,f,e);this.nextlevel=e.to;this.fade=e.fade;this.duration=e.duration;this.fading=false;this.gotolevel=e.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(d){this.gotolevel=d||this.nextlevel;if(this.fade&&this.duration){if(!this.fading){this.fading=true;me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}}else{me.levelDirector.loadLevel(this.gotolevel)}},onCollision:function(){this.goTo()}});b.me.LevelEntity=LevelEntity})(window);(function(a,b){Font=Object.extend({ALIGN:{LEFT:"left",CENTER:"center",RIGHT:"right"},font:null,height:null,color:null,align:null,init:function(d,e,c,f){this.set(d,e,c,f)},bold:function(){this.font="bold "+this.font},italic:function(){this.font="italic "+this.font},set:function(d,e,c,f){this.font=""+e+"px "+d;this.height=e;this.color=c;this.align=f||"top"},getRect:function(){return new me.Rect(new Vector2d(0,0),0,0)},measureText:function(c,d){c.font=this.font;c.fillStyle=this.color;c.textBaseLine=this.align;dim=c.measureText(d);dim.height=this.height;return dim},draw:function(d,e,c,f){d.font=this.font;d.fillStyle=this.color;d.textBaseLine=this.align;d.fillText(e,~~c,~~f)}});BitmapFont=Font.extend({size:null,sSize:null,scale:1,firstChar:32,init:function(c,d,f,e){this.parent(c,null,null);this.size=new me.Vector2d(d,0);this.sSize=new me.Vector2d();this.scale=f||1;this.firstChar=e||32;this.loadFontMetrics(c);this.align=this.ALIGN.RIGHT},loadFontMetrics:function(c){this.font=me.loader.getImage(c);this.size.y=this.font.height||0;this.sSize.copy(this.size);this.sSize.x*=this.scale;this.sSize.y*=this.scale},set:function(d,c){this.align=d;if(c){this.sSize.copy(this.size);this.sSize.x*=this.scale;this.sSize.y*=this.scale}},measureText:function(c){return{width:c.length*this.sSize.x,height:this.sSize.y}},draw:function(e,f,c,g){if(typeof(f)!="string"){f=f.toString()}if(this.align==this.ALIGN.RIGHT){c-=f.length*this.sSize.x}for(var d=0;d<f.length;d++){e.drawImage(this.font,(f.charCodeAt(d)-this.firstChar)*this.size.x,0,this.sSize.x,this.sSize.y,~~c,~~g,this.size.x,this.size.y);c+=this.sSize.x}}});a.me.Font=Font;a.me.BitmapFont=BitmapFont})(window);(function(b,c){var a=me.SpriteObject.extend({isClickable:true,updated:false,init:function(d,g,f,e){this.parent(this,d,g,f,e)},update:function(){if(this.updated){this.updated=false;return true}return false},clicked:function(){return false},mouseEvent:function(d,e){if((d>this.pos.x)&&(d<this.pos.x+this.displayWidth)&&(e>this.pos.y)&&(e<this.pos.y+this.displayHeight)){if(this.isClickable){this.updated=this.clicked()}}return this.updated}});b.me.GUI_Object=a})(window);(function(a,b){HUD_Item=Object.extend({init:function(c,e,d){this.pos=new me.Vector2d(c||0,e||0);this.visible=true;this.defaultvalue=d||0;this.value=d||0;this.updated=true},reset:function(){this.set(this.defaultvalue)},set:function(c){this.value=c;this.updated=true;return true},update:function(c){return this.set(this.value+c)},draw:function(d,c,e){if(this.updated){this.updated=false}}});HUD_Object=me.Rect.extend({init:function(c,g,d,f,e){this.parent(new me.Vector2d(c||0,g||0),d||me.video.getWidth(),f||me.video.getHeight());this.bgcolor=e;this.HUDItems={};this.HUDobj=[];this.objCount=0;this.visible=true;this.HUD_invalidated=true;HUDCanvasSurface=me.video.createCanvasSurface(this.width,this.height);this.z=999},addItem:function(c,d){this.HUDItems[c]=d;this.HUDobj.push(this.HUDItems[c]);this.objCount++;this.HUD_invalidated=true},setItemValue:function(c,d){if(this.HUDItems[c]&&(this.HUDItems[c].set(d)==true)){this.HUD_invalidated=true}},updateItemValue:function(c,d){if(this.HUDItems[c]&&(this.HUDItems[c].update(d)==true)){this.HUD_invalidated=true}},getItemValue:function(c){return(this.HUDItems[c])?this.HUDItems[c].value:0},update:function(){return this.HUD_invalidated},reset:function(c){if(c!=b){if(this.HUDItems[c]){this.HUDItems[c].reset()}this.HUD_invalidated=true}else{singleton.resetAll()}},resetAll:function(){for(var c=this.objCount,d;c--,d=this.HUDobj[c];){d.reset()}this.HUD_invalidated=true},getRect:function(){p=this.pos.clone();p.add(me.game.viewport.pos);return new me.Rect(p,this.width,this.height)},draw:function(d){if(this.HUD_invalidated){if(this.bgcolor){me.video.clearSurface(HUDCanvasSurface,this.bgcolor)}else{HUDCanvasSurface.canvas.width=HUDCanvasSurface.canvas.width}for(var c=this.objCount,e;c--,e=this.HUDobj[c];){if(e.visible){e.draw(HUDCanvasSurface,0,0)}}}d.drawImage(HUDCanvasSurface.canvas,this.pos.x,this.pos.y);this.HUD_invalidated=false}});a.me.HUD_Item=HUD_Item;a.me.HUD_Object=HUD_Object})(window);(function(a,b){audio=(function(){var j={};var s=[];var c=["mp3","ogg","wav"];var g=null;var r=-1;var e=null;var m=null;var k=true;var q=0;var l=0;function h(){var t=0;if(!me.sys.sound){k=false;return}if((g.search(/mp3/i)!=-1)&&j.capabilities.mp3){return c[t]}if((g.search(/ogg/i)!=-1)&&j.capabilities.ogg){return c[++t]}if((g.search(/wav/i)!=-1)&&j.capabilities.wav){return c[++t]}k=false;return -1}function f(u){var t=s[u];for(var v=0,w;w=t[v++];){if(w.ended||!w.currentTime){w.currentTime=q;return w}}t[0].pause();t[0].currentTime=q;return t[0]}function n(t){if(l++>3){var u="melonJS: failed loading "+t+"."+r;if(me.sys.stopOnAudioError===false){me.audio.disable();if(e){e()}console.log(u+", disabling audio")}else{throw u}}else{s[t][0].load()}}function d(t,w){l=0;if(w>1){var u=s[t][0];for(channel=1;channel<w;channel++){var v=u.cloneNode(true);if(v.currentSrc.length==0){v.src=u.src}s[t][channel]=v;s[t][channel].load()}}if(e){e()}}function o(u,t,w){var v=f(u);v.loop=t||false;v.play();if(w&&!t){v.addEventListener("ended",function(z){v.removeEventListener("ended",arguments.callee,false);w()},false)}}function i(u,t,v){if(v&&!t){setTimeout(v,2000)}}j.capabilities={mp3:false,ogg:false,ma4:false,wav:false,};j.init=function(t){if(t){g=new String(t)}else{g=new String("mp3")}r=h();if(k){j.play=o}else{j.play=i}return k};j.setLoadCallback=function(t){e=t};j.isAudioEnable=function(){return k};j.enable=function(){k=me.sys.sound;if(k){j.play=o}else{j.play=i}};j.disable=function(){k=false;j.play=i};j.load=function(u){if(r==-1){return 0}var t=new Audio(u.src+u.name+"."+r+me.nocache);t.preload="auto";t.addEventListener("canplaythrough",function(v){this.removeEventListener("canplaythrough",arguments.callee,false);d(u.name,u.channel)},false);t.addEventListener("error",function(v){n(u.name)},false);t.src=u.src+u.name+"."+r+me.nocache;t.load();s[u.name]=[t];return 1};j.stop=function(t){if(k){var u=s[t];for(channel_id=u.length;channel_id--;){u[channel_id].pause();u[channel_id].currentTime=q}}};j.pause=function(t){if(k){var u=s[t];for(channel_id=u.length;channel_id--;){u[channel_id].pause()}}};j.playTrack=function(t){if(k){if(m!=null){j.stopTrack()}m=f(t);if(m){m.loop=true;m.play()}}};j.stopTrack=function(){if(k&&m){m.pause();m=null}};j.pauseTrack=function(){if(k&&m){m.pause()}};j.resumeTrack=function(){if(k&&m){m.play()}};return j})();a.me.audio=audio})(window);(function(a,b){timer=(function(){var g={};var l=null;var c=false;var f=0;var h=0;var k=0;var d=0;var j=0;var e=Math.ceil(1000/me.sys.fps);var m=(1000/me.sys.fps)*1.25;function i(n){l.replaceChild(document.createTextNode("("+n+"/"+me.sys.fps+" fps)"),l.firstChild)}g.tick=1;g.init=function(){l=document.getElementById("framecounter");c=(l!==null);g.reset()};g.reset=function(){d=k=new Date().getTime();h=0;f=0};g.getTime=function(){return d};g.update=function(){k=d;d=new Date().getTime();j=(d-k);if(c){f++;h+=j;if(f%10==0){lastfps=~~((1000*f)/h);i(lastfps.clamp(0,me.sys.fps));h=0;f=0}}g.tick=(j>m&&me.sys.interpolation)?j/e:1};return g})();video=(function(){var g={};var e=null;var i=null;var j=null;var h=null;var d=null;var k=false;var f=0;var c=0;g.init=function(n,r,m,l,q){k=l||false;me.sys.scale=k===true?q||1:1;f=r*me.sys.scale;c=m*me.sys.scale;d=document.getElementById(n);e=document.createElement("canvas");e.setAttribute("width",(f)+"px");e.setAttribute("height",(c)+"px");e.setAttribute("border","0px solid black");d.appendChild(e);if(me.sys.enableWebGL&&window.WebGLRenderingContext){try{WebGL2D.enable(e);i=e.getContext("webgl-2d");me.sys.cacheImage=true}catch(o){i=null}}if(i==null){me.sys.enableWebGL=false;if(!e.getContext){return false}i=e.getContext("2d")}if(k){h=g.createCanvasSurface(r,m);j=h.canvas}else{h=i;j=i.canvas}return true};g.getWrapper=function(){return d};g.getWidth=function(){return j.width};g.getHeight=function(){return j.height};g.createCanvasSurface=function(m,l){var n=document.createElement("canvas");n.width=m||j.width;n.height=l||j.height;return n.getContext("2d")};g.getScreenCanvas=function(){return e};g.getScreenFrameBuffer=function(){return h};g.updateDisplaySize=function(l){if(k){if(l){me.sys.scale=l}else{me.sys.scale=document.getElementById("screen size").value}f=j.width*me.sys.scale;c=j.height*me.sys.scale;e.width=f;e.height=c}};g.clearSurface=function(m,l){m.fillStyle=l;m.fillRect(0,0,m.canvas.width,m.canvas.height)};g.scale=function(l,m){l.translate(-(((l.canvas.width*m)-l.canvas.width)>>1),-(((l.canvas.height*m)-l.canvas.height)>>1));l.scale(m,m)};g.setAlpha=function(m,l){m.globalCompositeOperation=l?"source-over":"copy"};g.blitSurface=function(){if(k){g.blitSurface=function(){i.drawImage(j,0,0,j.width,j.height,0,0,f,c)}}else{g.blitSurface=function(){}}g.blitSurface()};g.applyRGBFilter=function(){if(typeof arguments[0]=="string"){var w=arguments[0];var r=arguments[1];var s=g.createCanvasSurface();var t=h.getImageData(0,0,j.width,j.height)}else{var s=g.createCanvasSurface(arguments[0].width,arguments[0].height);if(arguments[0] instanceof HTMLImageElement){var o=me.video.createCanvasSurface(arguments[0].width,arguments[0].height);o.drawImage(arguments[0],0,0);var t=o.getImageData(0,0,arguments[0].width,arguments[0].height)}else{var t=arguments[0].getContext("2d").getImageData(0,0,arguments[0].width,arguments[0].height)}var w=arguments[1];var r=arguments[2]}var u=t.data;switch(w){case"b&w":for(var q=0,m=u.length;q<m;q+=4){var l=(3*u[q]+4*u[q+1]+u[q+2])>>>3;u[q]=l;u[q+1]=l;u[q+2]=l}break;case"brightness":var v=Math.abs(r);v=(v>1)?1:v;for(var q=0,m=u.length;q<m;q+=4){u[q]*=v;u[q+1]*=v;u[q+2]*=v}break;case"transparent":for(var q=0,m=u.length;q<m;q+=4){if(me.utils.RGBToHex(u[q],u[q+1],u[q+2])===r){u[q+3]=0}}break;default:return null}s.putImageData(t,0,0);return s};return g})();a.me.timer=timer;a.me.video=video})(window);(function(a,b){input=(function(){var h={};var f=[];var k=[];var n=[];var d=[];var g=null;var j=null;var m=false;function o(r){if(r){if(!m){a.addEventListener("keydown",e,false);a.addEventListener("keyup",c,false)}}else{a.removeEventListener("keydown",e,false);a.removeEventListener("keyup",c,false)}m=r}function l(r){r.stopPropagation();if(r.preventDefault){r.preventDefault()}r.returnValue=false}function e(s){var r=f[s.keyCode||s.which];if(r){if(!d[r]){k[r]=true;d[r]=n[r]}l(s);return false}return true}function c(s){var r=f[s.keyCode||s.which];if(r){k[r]=false;d[r]=false;l(s);return false}return true}function i(s){var r=s.clientX-me.video.getScreenCanvas().offsetLeft;var t=s.clientY-me.video.getScreenCanvas().offsetTop;g(r,t)}function q(r){}h.KEY={LEFT:37,UP:38,RIGHT:39,DOWN:40,ENTER:13,SHIFT:16,CTRL:17,ALT:18,PAUSE:19,ESC:27,SPACE:32,"0":48,"1":49,"2":50,"3":51,"4":52,"5":53,"6":54,"7":55,"8":56,"9":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(r){if(k[r]){if(n[r]){d[r]=true;k[r]=false}return true}return false};h.keyStatus=function(r){return(d[r]===true)?true:k[r]};h.bindKey=function(r,t,s){if(!m){o(true)}f[r]=t;n[t]=s?s:false;d[t]=false};h.unbindKey=function(r){k[f[r]]=false;n[f[r]]=false;f[r]=null};h.enableMouseEvent=function(r,s){if(r){me.video.getScreenCanvas().addEventListener("click",i,false);g=s||me.game.mouseEvent.bind(me.game)}else{me.video.getScreenCanvas().removeEventListener("click",i,false)}};h.enableGyroscopicEvent=function(r,s){if(a.sys.gyro){a.ondevicemotion=r?q:null;j=r?s:null}};return h})();a.me.input=input})(window);(function(b,d){var c=(function(){var f={};var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";f.decode=function(j){var g=[],r,o,m,q,n,l,k,h=0;j=j.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(h<j.length){q=e.indexOf(j.charAt(h++));n=e.indexOf(j.charAt(h++));l=e.indexOf(j.charAt(h++));k=e.indexOf(j.charAt(h++));r=(q<<2)|(n>>4);o=((n&15)<<4)|(l>>2);m=((l&3)<<6)|k;g.push(String.fromCharCode(r));if(l!=64){g.push(String.fromCharCode(o))}if(k!=64){g.push(String.fromCharCode(m))}}g=g.join("");return g};return f})();var a=(function(){var e={};var f={};e.decodeBase64=function(g){return c.decode(g)};e.decodeBase64AsArray=function(l,h){h=h||1;var o=c.decode(l),k=[],n,m,g;for(n=0,g=o.length/h;n<g;n++){k[n]=0;for(m=h-1;m>=0;--m){k[n]+=o.charCodeAt((n*h)+m)<<(m<<3)}}return k};e.decodeCSV=function(j,h){j=j.trim().split("\n");var g=[];for(var k=0;k<j.length;k++){entries=j[k].split(",",h);for(var l=0;l<entries.length;l++){g.push(+entries[l])}}return g};e.setNocache=function(g){me.nocache=g?"?"+parseInt(Math.random()*10000000):""};e.HexToRGB=function(i,g){i=(i.charAt(0)=="#")?i.substring(1,7):i;if(f[i]==null){f[i]=parseInt(i.substring(0,2),16)+","+parseInt(i.substring(2,4),16)+","+parseInt(i.substring(4,6),16)}return(g?"rgba(":"rgb(")+f[i]+(g?","+g+")":")")};e.RGBToHex=function(j,i,h){return j.toHex()+i.toHex()+h.toHex()};e.applyFriction=function(g,h){return(g+h<0)?g+(h*me.timer.tick):(g-h>0)?g-(h*me.timer.tick):0};return e})();b.me.utils=a})(window);(function(b,c){function a(d){this.defaultvalue=d||0;this.value=d||0;this.updated=true}a.prototype.reset=function(){this.set(this.defaultvalue)};a.prototype.update=function(d){return this.set(this.value+d)};a.prototype.set=function(d){this.value=d;this.updated=true;return this.updated};gamestat=(function(){var f={};var e={};var g=[];var d=0;f.add=function(h,i){e[h]=new a(i);g.push(e[h]);d++};f.updateValue=function(h,i){if(e[h]){e[h].update(i)}};f.setValue=function(h,i){if(e[h]){e[h].set(i)}};f.getItemValue=function(h){return(e[h])?e[h].value:0};f.reset=function(h){if(h!=c){if(e[h]){e[h].reset()}}else{f.resetAll()}};f.resetAll=function(){for(var h=d,j;h--,j=g[h];){j.reset()}};return f})();b.me.gamestat=gamestat})(window);(function(f,g){removepath=/^.*(\\|\/|\:)/;removeext=/\.[^\.]*$/;var e={COLLISION_MAP:"collision",PARALLAX_MAP:"parallax",};var c=me.Rect.extend({init:function(i,m,j,k,l){this.parent(new me.Vector2d(i*j,m*k),j,k);this.tileId=l;this.row=i;this.col=m}});function b(k,l,j,n,m,i){this.name=k;this.tilewidth=l;this.tileheight=j;this.spacing=n;this.margin=m;this.image=(i)?me.loader.getImage(i.replace(removepath,"").replace(removeext,"")):null;this.type={SOLID:"solid",PLATFORM:"platform",L_SLOPE:"lslope",R_SLOPE:"rslope",LADDER:"ladder",BREAKABLE:"breakable"};this.TileProperties=[];if(this.image){this.hTileCount=~~((this.image.width-this.margin)/(this.tilewidth+this.spacing));this.vTileCount=~~((this.image.height-this.margin)/(this.tileheight+this.spacing))}}b.prototype.getPropertyList=function(){return{isCollidable:false,isSolid:false,isPlatform:false,isSlope:false,isLeftSlope:false,isRightSlope:false,isLadder:false,isBreakable:false}};b.prototype.getTileProperties=function(i){return this.TileProperties[i]};b.prototype.isTileCollidable=function(i){return this.TileProperties[i].isCollidable};b.prototype.getTileImage=function(j){var i=me.video.createCanvasSurface(this.tilewidth,this.tileheight);this.drawTile(i,0,0,j);return i.canvas};b.prototype.drawTile=function(l,i,q,o,k,j){var n=this.margin+(this.spacing+this.tilewidth)*(o%this.hTileCount);var m=this.margin+(this.spacing+this.tileheight)*~~(o/this.hTileCount);if(k||j){k=(k==0)?1:-1;j=(j==0)?1:-1;l.scale(k,j);i=(i*k)-(k<0?this.tilewidth:0);q=(q*j)-(j<0?this.tileheight:0)}l.drawImage(this.image,n,m,this.tilewidth,this.tileheight,i,q,this.tilewidth,this.tileheight);if(k||j){l.setTransform(1,0,0,1,0,0)}};function d(i,j){this.realwidth=i;this.realheight=j;this.isCollisionMap=true}d.prototype.checkCollision=function(l,j){var i=(j.x<0)?l.left+j.x:l.right+j.x-1;var m=(j.y<0)?l.top+j.y:l.bottom+j.y;var k={x:false,y:false,tile:g,xprop:{},yprop:{}};if(i<=0||i>=this.realwidth){k.x=true}if(m<=0||m>=this.realheight){k.y=true}return k};function h(j,k,i,l){this.width=j;this.height=k;this.z=l;this.name=null;this.visible=false;this.layerData=null;this.xLUT={};this.yLUT={};this.tilesets=i;this.tileset=i?this.tilesets.getTilesetByIndex(0):null;this.tilewidth=this.tileset?this.tileset.tilewidth:0;this.tileheight=this.tileset?this.tileset.tileheight:0;this.realwidth=this.width*this.tilewidth;this.realheight=this.height*this.tileheight}h.prototype.initArray=function(j){this.layerData=[];for(var i=0;i<this.width+1;i++){this.layerData[i]=[];for(var k=0;k<this.height+1;k++){this.layerData[i][k]=null}}if(j){for(var i=0;i<this.width*this.tilewidth;i++){this.xLUT[i]=~~(i/this.tilewidth)}for(var k=0;k<this.height*this.tileheight;k++){this.yLUT[k]=~~(k/this.tileheight)}}};h.prototype.getTileId=function(i,k){var j=this.layerData[this.xLUT[~~i]][this.yLUT[~~k]];return j?j.tileId:null};h.prototype.getTile=function(i,j){return this.layerData[this.xLUT[~~i]][this.yLUT[~~j]]};h.prototype.setTile=function(i,k,j){this.layerData[i][k]=new c(i,k,this.tilewidth,this.tileheight,j)};h.prototype.clearTile=function(i,j){this.layerData[i][j]=null};h.prototype.checkCollision=function(j,i){x=(i.x<0)?j.left+i.x:j.right+i.x;y=(i.y<0)?j.top+i.y:j.bottom+i.y;collide={x:false,xtile:g,xprop:{},y:false,ytile:g,yprop:{}};if(x<=0||x>=this.realwidth){collide.x=true}else{collide.xtile=this.getTile(x,j.bottom-1);if(collide.xtile&&this.tileset.isTileCollidable(collide.xtile.tileId)){collide.x=true;collide.xprop=this.tileset.getTileProperties(collide.xtile.tileId)}else{collide.xtile=this.getTile(x,j.top);if(collide.xtile&&this.tileset.isTileCollidable(collide.xtile.tileId)){collide.x=true;collide.xprop=this.tileset.getTileProperties(collide.xtile.tileId)}}}collide.ytile=this.getTile((i.x<0)?j.left:j.right,y);if(collide.ytile&&this.tileset.isTileCollidable(collide.ytile.tileId)){collide.y=true;collide.yprop=this.tileset.getTileProperties(collide.ytile.tileId)}else{collide.ytile=this.getTile((i.x<0)?j.right:j.left,y);if(collide.ytile&&this.tileset.isTileCollidable(collide.ytile.tileId)){collide.y=true;collide.yprop=this.tileset.getTileProperties(collide.ytile.tileId)}}return collide};h.prototype.update=function(){return false};function a(i,j){this.pos=new me.Vector2d(i,j);this.z=0;this.width=0;this.height=0;this.realwidth=-1;this.realheight=-1;this.tilewidth=0;this.tileheight=0;this.tilesets=null;this.mapLayers=[];this.objectGroups=[];this.initialized=false}a.prototype.reset=function(){this.tilesets=null;this.mapLayers=[];this.objectGroups=[];this.initialized=false};a.prototype.getObjectGroupByName=function(i){return this.objectGroups[i]};a.prototype.getObjectGroups=function(){return this.objectGroups};a.prototype.getLayerByName=function(j){var l=null;j=j.trim().toLowerCase();for(var k=this.mapLayers.length;k--;){if(this.mapLayers[k].name.contains(j)){l=this.mapLayers[k];break}}if((j.contains(e.COLLISION_MAP))&&(l==null)){l=new d(me.game.currentLevel.realwidth,me.game.currentLevel.realheight)}return l};a.prototype.clearTile=function(j,l){for(var k=this.mapLayers.length;k--;){if(this.mapLayers[k].visible||this.mapLayers[k].isCollisionMap){this.mapLayers[k].clearTile(j,l)}}};a.prototype.addTo=function(j){if(this.visible){j.add(this)}for(var k=this.mapLayers.length;k--;){if(this.mapLayers[k].visible){j.add(this.mapLayers[k])}}};a.prototype.update=function(){return false};levelDirector=(function(){var k={};var i={};var j=null;k.reset=function(){};k.addLevel=function(l){throw"melonJS: no level loader defined"};k.addTMXLevel=function(l,m){if(i[l]==null){i[l]=new me.TMXTileMap(l,0,0)}if(m){m()}};k.loadLevel=function(l){if(i[l]===g){throw ("melonJS: level %s not found"+l);return}if(i[l] instanceof me.TMXTileMap){isRunning=me.state.isRunning();if(isRunning){me.state.pause()}me.game.reset();i[l].reset();i[l].load();j=l;me.game.loadTMXLevel(i[j]);if(isRunning){me.state.resume()}}else{throw"melonJS: no level loader defined"}};k.getCurrentLevelId=function(){return j},k.reloadLevel=function(){return k.loadLevel(j)},k.nextLevel=function(){if(j+1<i.length){return k.loadLevel(j+1)}else{return false}};k.previousLevel=function(){if(j-1>=0){return k.loadLevel(j-1)}else{return false}};return k})();f.me.Tile=c;f.me.TileSet=b;f.me.TiledLayer=h;f.me.TileMap=a;f.me.LevelConstants=e;f.me.levelDirector=levelDirector})(window);(function(D,l){var V="map",E="name",v="value",I="version",R="orientation",M="width",J="height",H="opacity",q="trans",o="tilewidth",a="tileheight",r="firstgid",g="gid",w="tile",z="id",n="data",t="compression",k="encoding",d="base64",h="csv",T="spacing",S="margin",u="properties",m="property",Q="image",f="source",j="visible",G="tileset",P="layer",N="objectgroup",s="object",C="x",B="y",M="width",J="height",L=2147483648,U=1073741824;function e(aa,Z){var X=Z.getElementsByTagName(u)[0];if(X){var W=X.getElementsByTagName(m);for(var Y=0;Y<W.length;Y++){O(aa,W[Y])}}}function O(W,Z){var Y=me.XMLParser.getStringAttribute(Z,E);var X=me.XMLParser.getStringAttribute(Z,v);if(!X||X.isBoolean()){X=X?(X=="true"):true}else{if(X.isNumeric()){X=parseInt(X)}}W[Y]=X}function K(X,W,Y){me.TileMap.call(this,W,Y);this.xmlMap=me.loader.getXML(X);if(!this.xmlMap){throw"melonJS:"+X+" TMX map not found"}this.version="";this.orientation="";this.tileMapCanvas=null;this.tilesets=null}K.prototype=new me.TileMap();K.prototype.load=function(){if(this.initialized){return}var ab=0,ad=1;me.XMLParser.parseFromString(this.xmlMap);var ae=me.XMLParser.getAllTagElements();for(var ac=0;ac<ae.length;ac++){var Z=ae.item(ac).nodeName;switch(Z){case V:var X=ae.item(ac);this.version=me.XMLParser.getStringAttribute(X,I);this.orientation=me.XMLParser.getStringAttribute(X,R);this.width=me.XMLParser.getIntAttribute(X,M);this.height=me.XMLParser.getIntAttribute(X,J);this.tilewidth=me.XMLParser.getIntAttribute(X,o);this.tileheight=me.XMLParser.getIntAttribute(X,a);this.realwidth=this.width*this.tilewidth;this.realheight=this.height*this.tileheight;this.z=ab++;if(this.orientation!="orthogonal"){throw"melonJS: "+this.orientation+" type TMX Tile Map not supported!"}e(this,X);this.visible=false;if(this.background_color){this.visible=true;this.background_color=me.utils.HexToRGB(this.background_color)}if(this.background_image){this.visible=true;this.background_image=me.loader.getImage(this.background_image)}break;case G:if(!this.tilesets){this.tilesets=new A()}this.tilesets.add(new F(ae.item(ac)));break;case P:var Y=me.XMLParser.getStringAttribute(ae.item(ac),E);if(Y.contains(me.LevelConstants.PARALLAX_MAP)){var aa=(me.XMLParser.getIntAttribute(ae.item(ac),j,1)==1);if(aa){var af={};e(af,ae.item(ac));parallax_layer=this.getLayerByName(me.LevelConstants.PARALLAX_MAP);if(!parallax_layer){parallax_layer=new me.ParallaxBackgroundEntity(ab);this.mapLayers.push(parallax_layer)}parallax_layer.addLayer(af.imagesrc,ad++,ab++)}}else{this.mapLayers.push(new c(ae.item(ac),this.tilesets,ab++));ab++}break;case N:var W=me.XMLParser.getStringAttribute(ae.item(ac),E);this.objectGroups.push(new i(W,ae.item(ac),this.tilesets,ab++));break}}me.XMLParser.free();this.initialized=true};K.prototype.draw=function(W,X){if(this.background_color){W.fillStyle=this.background_color;W.fillRect(X.left,X.top,X.width,X.height)}if(this.background_image){W.drawImage(this.background_image,X.left,X.top,X.width,X.height,X.left,X.top,X.width,X.height)}};function A(){this.tilesets=[]}A.prototype.add=function(W){this.tilesets.push(W)};A.prototype.getTilesetByIndex=function(W){return this.tilesets[W]};A.prototype.getTilesetByGid=function(Z){var Y=-1;for(var X=0,W=this.tilesets.length;X<W;X++){if(this.tilesets[X].contains(Z)){return this.tilesets[X]}if(this.tilesets[X].firstgid==this.tilesets[X].lastgid){if(Z>=this.tilesets[X].firstgid){Y=X}}}if(Y!=-1){return this.tilesets[Y]}else{throw"no matching tileset found for gid "+Z}};function F(X){this.firstgid=me.XMLParser.getIntAttribute(X,r);me.TileSet.call(this,me.XMLParser.getStringAttribute(X,E),me.XMLParser.getIntAttribute(X,o),me.XMLParser.getIntAttribute(X,a),me.XMLParser.getIntAttribute(X,T,0),me.XMLParser.getIntAttribute(X,S,0),X.getElementsByTagName(Q)[0].getAttribute(f));this.lastgid=this.firstgid+(((this.hTileCount*this.vTileCount)-1)||0);this.trans=X.getElementsByTagName(Q)[0].getAttribute(q);if(this.trans!==null&&this.image){this.image=me.video.applyRGBFilter(this.image,"transparent",this.trans.toUpperCase()).canvas}var W=X.getElementsByTagName(w);for(var Y=0;Y<W.length;Y++){var Z=me.XMLParser.getIntAttribute(W[Y],z)+this.firstgid;this.TileProperties[Z]={};tileProp=this.TileProperties[Z];e(tileProp,W[Y]);tileProp.isSolid=tileProp.type?tileProp.type.toLowerCase()===this.type.SOLID:false;tileProp.isPlatform=tileProp.type?tileProp.type.toLowerCase()===this.type.PLATFORM:false;tileProp.isLeftSlope=tileProp.type?tileProp.type.toLowerCase()===this.type.L_SLOPE:false;tileProp.isRightSlope=tileProp.type?tileProp.type.toLowerCase()===this.type.R_SLOPE:false;tileProp.isBreakable=tileProp.type?tileProp.type.toLowerCase()===this.type.BREAKABLE:false;tileProp.isLadder=tileProp.type?tileProp.type.toLowerCase()===this.type.LADDER:false;tileProp.isSlope=tileProp.isLeftSlope||tileProp.isRightSlope;tileProp.isCollidable=tileProp.isSolid||tileProp.isPlatform||tileProp.isSlope||tileProp.isLadder||tileProp.isBreakable}}F.prototype=new me.TileSet();F.prototype.contains=function(W){return(W>=this.firstgid&&W<=this.lastgid)};function c(Y,W,aa){me.TiledLayer.call(this,me.XMLParser.getIntAttribute(Y,M),me.XMLParser.getIntAttribute(Y,J),W,aa);this.layerInvalidated=true;this.name=me.XMLParser.getStringAttribute(Y,E);this.visible=(me.XMLParser.getIntAttribute(Y,j,1)==1);this.opacity=me.XMLParser.getFloatAttribute(Y,H,1);e(this,Y);this.isCollisionMap=(this.name.contains(me.LevelConstants.COLLISION_MAP));if(this.isCollisionMap){this.visible=false}this.vp=me.game.viewport;var ab=Y.getElementsByTagName(n)[0];var Z=me.XMLParser.getStringAttribute(ab,k,null);var X=me.XMLParser.getStringAttribute(ab,t,null);if(Z==""){Z=null}if(X==""){X=null}if(this.visible){this.layerSurface=me.video.createCanvasSurface(this.width*this.tilewidth,this.height*this.tileheight);this.layerCanvas=this.layerSurface.canvas;if(this.opacity>0&&this.opacity<1){this.layerSurface.globalAlpha=this.opacity}}if(this.visible||this.isCollisionMap){this.initArray(this.isCollisionMap);this.fillArray(ab,Z,X)}}c.prototype=new me.TiledLayer();c.prototype.fillArray=function(ad,W,ah){switch(ah){case null:switch(W){case null:var X=ad.getElementsByTagName(w);break;case h:case d:var aa="";for(var Y=0,ab=ad.childNodes.length;Y<ab;Y++){aa+=ad.childNodes[Y].nodeValue}if(W==d){var X=me.utils.decodeBase64AsArray(aa,4)}else{var X=me.utils.decodeCSV(aa,this.width)}aa=null;break;default:throw"melonJS: TMX Tile Map "+W+" encoding not supported!";break}break;default:throw"melonJS: "+ah+" compressed TMX Tile Map not supported!";break}var ag=X.length-1;var ac,Z;for(var ae=this.height-1;ae>=0;ae--){for(var af=this.width-1;af>=0;af--){gid=(W==null)?me.XMLParser.getIntAttribute(X[ag--],g):X[ag--];ac=(gid&L);Z=(gid&U);gid&=~(L|U);if(gid>0){this.setTile(af,ae,gid);if(!this.tileset.contains(gid)){this.tileset=this.tilesets.getTilesetByGid(gid)}if(this.visible){this.tileset.drawTile(this.layerSurface,af*this.tilewidth,ae*this.tileheight,gid-this.tileset.firstgid,ac,Z)}}}}X=null};c.prototype.clearTile=function(W,X){me.TiledLayer.prototype.clearTile.call(this,W,X);if(this.visible){this.layerSurface.clearRect(W*this.tilewidth,X*this.tileheight,this.tilewidth,this.tileheight)}};c.prototype.draw=function(W,X){W.drawImage(this.layerCanvas,this.vp.pos.x+X.pos.x,this.vp.pos.y+X.pos.y,X.width,X.height,X.pos.x,X.pos.y,X.width,X.height)};function i(Y,X,W,ab){this.objects=[];this.name=Y;this.width=me.XMLParser.getIntAttribute(X,M);this.height=me.XMLParser.getIntAttribute(X,J);this.z=ab;var aa=X.getElementsByTagName(s);for(var Z=0;Z<aa.length;Z++){this.objects.push(new b(aa[Z],W,ab))}}i.prototype.getObjectCount=function(){return this.objects.length};i.prototype.getObjectByIndex=function(W){return this.objects[W]};function b(X,W,Y){this.name=me.XMLParser.getStringAttribute(X,E);this.x=me.XMLParser.getIntAttribute(X,C);this.y=me.XMLParser.getIntAttribute(X,B);this.z=Y;this.gid=me.XMLParser.getIntAttribute(X,g,null);if(this.gid){tileset=W.getTilesetByGid(this.gid);this.width=tileset.tilewidth;this.height=tileset.tileheight;this.spritewidth=this.width;this.y-=this.height;this.image=tileset.getTileImage(this.gid-tileset.firstgid)}else{this.width=me.XMLParser.getIntAttribute(X,M,0);this.height=me.XMLParser.getIntAttribute(X,J,0)}e(this,X)}b.prototype.getObjectPropertyByName=function(W){return this[W]};D.me.TMXTileMap=K})(window);
/*!
* Tween JS
* https://github.com/sole/Tween.js
*
* author sole / http://soledadpenades.com
* author mr.doob / http://mrdoob.com
* author Robert Eisele / http://www.xarg.org
* author Philippe / http://philippe.elsass.me
* author Robert Penner / http://www.robertpenner.com/easing_terms_of_use.html
*/
(function(a,b){Tween=function(f){var m=f,l={},i={},j={},g=1000,k=0,c=null,n=Tween.Easing.Linear.EaseNone,e=null,h=null,d=null;this.to=function(o,r){if(r!==null){g=r}for(var q in o){if(m[q]===null){continue}j[q]=o[q]}return this};this.start=function(){me.game.add(this,999);c=me.timer.getTime()+k;for(var o in j){if(m[o]===null){continue}l[o]=m[o];i[o]=j[o]-m[o]}return this};this.stop=function(){me.game.remove(this);return this};this.delay=function(o){k=o;return this};this.easing=function(o){n=o;return this};this.chain=function(o){e=o};this.onUpdate=function(o){h=o;return this};this.onComplete=function(o){d=o;return this};this.update=function(){var r,o,q;var s=me.timer.getTime();if(s<c){return true}o=(s-c)/g;o=o>1?1:o;q=n(o);for(r in i){m[r]=l[r]+i[r]*q}if(h!==null){h.call(m,q)}if(o==1){me.game.remove(this);if(d!==null){d.call(m)}if(e!==null){e.start()}return false}return true};this.destroy=function(){return true}};Tween.Easing={Linear:{},Quadratic:{},Cubic:{},Quartic:{},Quintic:{},Sinusoidal:{},Exponential:{},Circular:{},Elastic:{},Back:{},Bounce:{}};Tween.Easing.Linear.EaseNone=function(c){return c};Tween.Easing.Quadratic.EaseIn=function(c){return c*c};Tween.Easing.Quadratic.EaseOut=function(c){return -c*(c-2)};Tween.Easing.Quadratic.EaseInOut=function(c){if((c*=2)<1){return 0.5*c*c}return -0.5*(--c*(c-2)-1)};Tween.Easing.Cubic.EaseIn=function(c){return c*c*c};Tween.Easing.Cubic.EaseOut=function(c){return --c*c*c+1};Tween.Easing.Cubic.EaseInOut=function(c){if((c*=2)<1){return 0.5*c*c*c}return 0.5*((c-=2)*c*c+2)};Tween.Easing.Quartic.EaseIn=function(c){return c*c*c*c};Tween.Easing.Quartic.EaseOut=function(c){return -(--c*c*c*c-1)};Tween.Easing.Quartic.EaseInOut=function(c){if((c*=2)<1){return 0.5*c*c*c*c}return -0.5*((c-=2)*c*c*c-2)};Tween.Easing.Quintic.EaseIn=function(c){return c*c*c*c*c};Tween.Easing.Quintic.EaseOut=function(c){return(c=c-1)*c*c*c*c+1};Tween.Easing.Quintic.EaseInOut=function(c){if((c*=2)<1){return 0.5*c*c*c*c*c}return 0.5*((c-=2)*c*c*c*c+2)};Tween.Easing.Sinusoidal.EaseIn=function(c){return -Math.cos(c*Math.PI/2)+1};Tween.Easing.Sinusoidal.EaseOut=function(c){return Math.sin(c*Math.PI/2)};Tween.Easing.Sinusoidal.EaseInOut=function(c){return -0.5*(Math.cos(Math.PI*c)-1)};Tween.Easing.Exponential.EaseIn=function(c){return c==0?0:Math.pow(2,10*(c-1))};Tween.Easing.Exponential.EaseOut=function(c){return c==1?1:-Math.pow(2,-10*c)+1};Tween.Easing.Exponential.EaseInOut=function(c){if(c==0){return 0}if(c==1){return 1}if((c*=2)<1){return 0.5*Math.pow(2,10*(c-1))}return 0.5*(-Math.pow(2,-10*(c-1))+2)};Tween.Easing.Circular.EaseIn=function(c){return -(Math.sqrt(1-c*c)-1)};Tween.Easing.Circular.EaseOut=function(c){return Math.sqrt(1- --c*c)};Tween.Easing.Circular.EaseInOut=function(c){if((c/=0.5)<1){return -0.5*(Math.sqrt(1-c*c)-1)}return 0.5*(Math.sqrt(1-(c-=2)*c)+1)};Tween.Easing.Elastic.EaseIn=function(d){var e,c=0.1,f=0.4;if(d==0){return 0}if(d==1){return 1}if(!f){f=0.3}if(!c||c<1){c=1;e=f/4}else{e=f/(2*Math.PI)*Math.asin(1/c)}return -(c*Math.pow(2,10*(d-=1))*Math.sin((d-e)*(2*Math.PI)/f))};Tween.Easing.Elastic.EaseOut=function(d){var e,c=0.1,f=0.4;if(d==0){return 0}if(d==1){return 1}if(!f){f=0.3}if(!c||c<1){c=1;e=f/4}else{e=f/(2*Math.PI)*Math.asin(1/c)}return(c*Math.pow(2,-10*d)*Math.sin((d-e)*(2*Math.PI)/f)+1)};Tween.Easing.Elastic.EaseInOut=function(d){var e,c=0.1,f=0.4;if(d==0){return 0}if(d==1){return 1}if(!f){f=0.3}if(!c||c<1){c=1;e=f/4}else{e=f/(2*Math.PI)*Math.asin(1/c)}if((d*=2)<1){return -0.5*(c*Math.pow(2,10*(d-=1))*Math.sin((d-e)*(2*Math.PI)/f))}return c*Math.pow(2,-10*(d-=1))*Math.sin((d-e)*(2*Math.PI)/f)*0.5+1};Tween.Easing.Back.EaseIn=function(c){var d=1.70158;return c*c*((d+1)*c-d)};Tween.Easing.Back.EaseOut=function(c){var d=1.70158;return(c=c-1)*c*((d+1)*c+d)+1};Tween.Easing.Back.EaseInOut=function(c){var d=1.70158*1.525;if((c*=2)<1){return 0.5*(c*c*((d+1)*c-d))}return 0.5*((c-=2)*c*((d+1)*c+d)+2)};Tween.Easing.Bounce.EaseIn=function(c){return 1-Tween.Easing.Bounce.EaseOut(1-c)};Tween.Easing.Bounce.EaseOut=function(c){if((c/=1)<(1/2.75)){return 7.5625*c*c}else{if(c<(2/2.75)){return 7.5625*(c-=(1.5/2.75))*c+0.75}else{if(c<(2.5/2.75)){return 7.5625*(c-=(2.25/2.75))*c+0.9375}else{return 7.5625*(c-=(2.625/2.75))*c+0.984375}}}};Tween.Easing.Bounce.EaseInOut=function(c){if(c<0.5){return Tween.Easing.Bounce.EaseIn(c*2)*0.5}return Tween.Easing.Bounce.EaseOut(c*2-1)*0.5+0.5};a.me.Tween=Tween})(window);