text: !function(a){var b=[],c=[],d=[],e=[],f={},g=!1,h=2e3,i=null,j={Module:function(a,b){this.name=a,this.func=b},isModule:function(a){return a instanceof j.Module},"throw":function(a){throw Error("Molecule Error: "+a)},getSinon:function(){return a.sinon},getModule:function(a,b){for(var c,d=0;d<b.length;d++)if(b[d].name===a){c=b[d];break}return c||j.throw('Could not require module: "'+a+'". The name does not exist or loading it causes a loop.'),c},addModule:function(a,b,c){a.push(new j.Module(b,c))},registerModules:function(a,b){for(var c,d,e=!0,f=(new Date).getTime(),g=[];a.length&&!j.timeout(f);){e=!0,c=j.getLast(a),d=j.createContext(b);try{d.exports=c.func.apply(d,j.contextToArray(d))}catch(h){if(!h.message.match(/Molecule Error/))throw h;j.addDepException(g,h.message),j.moveLastToFirst(a),e=!1}e&&"undefined"==typeof d.exports&&j.throw("Module "+c.name+" is returning undefined, it has to return something"),e&&(c.exports=d.exports,j.moveLastToTarget(a,b))}j.timeout(f)&&j.throw("Timeout, could not load modules. The following dependencies gave errors: "+(g.length?g.join(", "):"")+". They do not exist or has caused a loop.")},contextToArray:function(a){return i?[i,a.require,a.privates]:[a.require,a.privates]},registerTestModule:function(a,b){for(var c,d,e,f=(new Date).getTime(),g=[];!e&&!j.timeout(f);)if(c=j.getLast(b),d=j.createTestContext(b),c.name===a){try{d.exports=c.func.apply(d,j.contextToArray(d))}catch(h){if(!h.message.match(/Molecule Error/))throw h;j.addDepException(g,h.message),j.moveLastToFirst(b)}e=c}else j.moveLastToFirst(b);return j.timeout(f)&&j.throw("Timeout, could not load modules. The following dependencies gave errors: "+(g.length?g.join(", "):a)+". They do not exist or has caused a loop."),d.exports||g.length?g.length&&j.throw("The following dependencies gave errors: "+g.join(", ")+". They do not exist or has caused a loop."):j.throw("Module "+e.name+" is returning undefined, it has to return something"),d},timeout:function(a){return(new Date).getTime()-a>=h},addDepException:function(a,b){b=b.match(/"(.*)"/)[1],-1===a.indexOf(b)&&a.push(b)},createGame:function(a){var b=j.getModule("Molecule.Game",d).exports;i=new b(a),i.once=k.once,i.log=k.log},createContext:function(a){var b={privates:{},require:function(b){var c=j.getModule(b,a);return j.isModule(c)?c.exports:c},game:i};return b},createTestContext:function(a){var b={privates:{},deps:{}};return b.require=j.createTestRequireMethod(b,a),b},createTestRequireMethod:function(a,b){return function(c){var d=[],e=j.getModule(c,b),f={privates:{},require:function(c){var e=j.getModule(c,b);try{e=e.func.apply(a,j.contextToArray(a))}catch(f){if(!f.message.match(/Molecule Error/))throw f;j.addDepException(d,f.message)}return j.isModule(e)?e.exports:e}};return f.exports=j.isModule(e)?e.func.apply(f,j.contextToArray(f)):e,e.exports=j.stubDepExports(f.exports),a.deps[c]=e.exports,e.exports}},stubDepExports:function(a){var b=j.getSinon();if(b){var c={};if("function"==typeof a)return b.spy();for(var d in a)a.hasOwnProperty(d)&&"function"==typeof a[d]&&(c[d]=a[d],b.stub(c,d));return c}return a},getLast:function(a){return a[a.length-1]},moveLastToFirst:function(a){a.unshift(a.pop())},moveLastToTarget:function(a,b){b.push(a.pop())},extractBrowserArgs:function(a){return{name:a[0],func:a[1]}}},k=function(a){return j.registerModules(c,d),j.createGame(a),k};k.module=function(){var a=j.extractBrowserArgs(arguments);return a.name&&"string"==typeof a.name&&a.func&&"function"==typeof a.func||j.throw("Invalid arguments for module creation, you have to pass a string and a function"),a.name.match(/Molecule/)?j.addModule(c,a.name,a.func):j.addModule(b,a.name,a.func),this},k.init=function(a){var c=function(){j.registerModules(b,d)};return i.init(c,a),i.start(),this},k.update=function(a){return i.update(a),this},k.ready=function(a){var c=function(){j.registerModules(b,d)};return i.init(c,a),i.start(),i},k.sprite=function(a,b,c,d){return i.imageFile.load(a,b,c,d),this},k.audio=function(a,b){return i.audioFile.load(a,b),this},k.webaudio=function(a,b){return i.webAudioFile.load(a,b),this},k.tilemap=function(a,b){return i.mapFile.load(a,b),this},k.spritesheet=function(a,b){return i.spriteSheetFile.load(a,b),this},k.test=function(a,c){g=!0;var d=j.registerTestModule(a,b);c.apply(d,[d.exports,d.privates,d.deps])},k.once=function(a,b){var c=a.toString();-1===e.indexOf(c)&&(a.call(b),e.push(c))},k.log=function(a){var b,c=Array.prototype.slice.call(arguments,0);if("string"!=typeof a||arguments.length<2)throw new Error("You have to pass a string identifier and your arguments to log");c.splice(0,1),b=JSON.stringify(c),f[a]&&f[a]===b||(c.unshift(a.toUpperCase()+": "),c.forEach(function(a,b){(a instanceof Array||"object"==typeof a&&null!==a)&&(c[b]=JSON.stringify(a,null,4))}),console.log.apply(console,c),f[a]=b)},a.Molecule=k}(window),Molecule.module("Molecule.Animation",function(){function a(){this.frame=[],this.id=[],this.current={animation:0,frame:0},this.timer=0,this.loop=!0,this.reverse=!1,this.halt=!1,this.end=!1}return a.prototype.sliceFrames=function(a,b,c,d){this.frame=[],this.id=[];var e,f;for(e=0;b-1>e;e+=d)for(f=0;a-1>f;f+=c)this.frame.push({x:f,y:e});a===c&&b===d&&this.add("")},a.prototype.add=function(a,b){b=b||{},b.frames||(b.frames=[0]),b.speed||(b.speed=60);var c=60*b.speed/b.frames.length;this.id.push({name:a,frame:b.frames,speed:c})},a.prototype.run=function(a,b){if(b=b||{},this.loop="undefined"==typeof b.loop?!0:b.loop,this.reverse="undefined"==typeof b.reverse?!1:b.reverse,this.halt=!1,-1===this.current.animation||this.id[this.current.animation].name!==a){this.current.frame=-1;for(var c=0;c<this.id.length;c++)this.id[c].name===a&&(this.current.animation=c,this.current.frame=0,this.timer=0,this.end=!1)}},a.prototype.stop=function(){this.halt=!0},a.prototype.nextFrame=function(){this.halt||(this.timer++,this.timer>this.id[this.current.animation].speed&&(this.timer=0,this.reverse?(this.current.frame--,this.current.frame<0&&(this.loop?this.current.frame=this.id[this.current.animation].frame.length-1:(this.current.frame=0,this.end=!0))):(this.current.frame++,this.current.frame>=this.id[this.current.animation].frame.length&&(this.loop?this.current.frame=0:(this.current.frame=this.id[this.current.animation].frame.length-1,this.end=!0)))))},a}),Molecule.module("Molecule.AudioFile",function(a){function b(a){this.game=a,this.name=[],this.data=[],this.counter=0}var c=a("Molecule.MAudio");return b.prototype.load=function(a,b){if(!this.getAudioDataByName(b)){var d,e=this,f=new Audio,g=b.split(".");""!=f.canPlayType("audio/"+g[g.length-1])&&(d=b),f.addEventListener("canplay",function(){e.counter++}),f.src=d,this.name.push(b),this.data.push(f)}var h=new c;return h.id=a,h.sound=this.getAudioDataByName(b),this.game.sounds[a]=h,h},b.prototype.isLoaded=function(){return this.counter===this.data.length},b.prototype.getAudioDataByName=function(a){return this.data[this.name.indexOf(a)]},b}),Molecule.module("Molecule.Camera",function(){function a(a){this.game=a,this.layer=null,this.sprite=null,this.scroll={x:!1,y:!1},this.type=0,this.offset={x:0,y:0},this.isSet=!1}return a.prototype.follow=function(a){return this.sprite=a,this.type=1,-1===this.game.scene.sprites.indexOf(this.sprite)?void(this.isSet=!1):void this.set()},a.prototype.unfollow=function(){this.sprite=null,this.type=0},a.prototype.set=function(){if(1===this.type){this.isSet=!0,this.layer=this.game.map.getMainLayer();var a,b,c;for(c=0;c<this.game.scene.sprites.length;c++)this.game.scene.sprites[c].scrollable&&(this.game.scene.sprites[c].position.x+=-this.game.map.json.layers[this.layer].x,this.game.scene.sprites[c].position.y+=-this.game.map.json.layers[this.layer].y);for(this.game.map.resetPosition(),a=this.sprite.position.x,b=this.sprite.position.y,this.sprite.position.x=0,this.sprite.position.y=0,c=0;a>c;c++)this.sprite.move.x=1,this.update(this.game.scene.sprites),this.game.cameraUpdate(),this.game.resetMove();for(c=0;b>c;c++)this.sprite.move.y=1,this.update(this.game.scene.sprites),this.game.cameraUpdate(),this.game.resetMove()}},a.prototype.update=function(a){!this.isSet&&a.indexOf(this.sprite)>=0&&this.set(),null!==this.game.map&&-1!==this.layer&&(this.makeScroll(),this.makeMapScroll()),this.makeSpriteScroll(a,this.sprite.move.x,this.sprite.move.y)},a.prototype.makeScroll=function(){this.scroll.x=!1,this.scroll.y=!1;var a=this.game.map.canvas[this.layer].width,b=this.game.map.canvas[this.layer].height;this.game.map.json.layers[this.layer].properties.scroll.infinite.x&&(a=-this.game.map.json.layers[this.layer].x+this.game.width+1),this.game.map.json.layers[this.layer].properties.scroll.infinite.y&&(b=-this.game.map.json.layers[this.layer].y+this.game.height+1),this.game.map.json.layers[this.layer].properties.scrollable&&((-this.game.map.json.layers[this.layer].x+this.game.width<a&&this.sprite.move.x>0&&this.sprite.position.x+this.offset.x-this.sprite.anchor.x+this.sprite.frame.width/2>=this.game.width/2||-this.game.map.json.layers[this.layer].x>0&&this.sprite.move.x<0&&this.sprite.position.x+this.offset.x-this.sprite.anchor.x+this.sprite.frame.width/2<=this.game.width/2)&&(this.scroll.x=!0),(-this.game.map.json.layers[this.layer].y+this.game.height<b&&this.sprite.move.y>0&&this.sprite.position.y+this.offset.y-this.sprite.anchor.y+this.sprite.frame.height/2>=this.game.height/2||-this.game.map.json.layers[this.layer].y>0&&this.sprite.move.y<0&&this.sprite.position.y+this.offset.y-this.sprite.anchor.y+this.sprite.frame.height/2<=this.game.height/2)&&(this.scroll.y=!0))},a.prototype.makeMapScroll=function(){for(var a=0;a<this.game.map.json.layers.length;a++)if("tilelayer"===this.game.map.json.layers[a].type&&this.game.map.json.layers[a].properties.scrollable){var b=this.game.map.canvas[a].width,c=this.game.map.canvas[a].height;this.game.map.json.layers[a].properties.scroll.infinite.x&&(b=-this.game.map.json.layers[a].x+this.game.width+1),this.game.map.json.layers[a].properties.scroll.infinite.y&&(c=-this.game.map.json.layers[a].y+this.game.height+1),(-this.game.map.json.layers[a].x+this.game.width<b&&this.sprite.move.x>0&&this.sprite.position.x+this.offset.x-this.sprite.anchor.x+this.sprite.frame.width/2>=this.game.width/2||-this.game.map.json.layers[a].x>0&&this.sprite.move.x<0&&this.sprite.position.x+this.offset.x-this.sprite.anchor.x+this.sprite.frame.width/2<=this.game.width/2)&&this.scroll.x&&(this.game.map.json.layers[a].properties.scroll.x=a!==this.layer?this.sprite.move.x*-this.game.map.json.layers[a].properties.scroll.speed:-this.sprite.move.x),(-this.game.map.json.layers[a].y+this.game.height<c&&this.sprite.move.y>0&&this.sprite.position.y+this.offset.y-this.sprite.anchor.y+this.sprite.frame.height/2>=this.game.height/2||-this.game.map.json.layers[a].y>0&&this.sprite.move.y<0&&this.sprite.position.y+this.offset.y-this.sprite.anchor.y+this.sprite.frame.height/2<=this.game.height/2)&&this.scroll.y&&(this.game.map.json.layers[a].properties.scroll.y=a!==this.layer?this.sprite.move.y*-this.game.map.json.layers[a].properties.scroll.speed:-this.sprite.move.y)}},a.prototype.makeSpriteScroll=function(a,b,c){for(var d=0;d<a.length;d++)a[d].scrollable&&(this.scroll.x&&(a[d].move.x=a[d].move.x-b),this.scroll.y&&(a[d].move.y=a[d].move.y-c))},a}),Molecule.module("Molecule.Game",function(a,b){var c=a("Molecule.MapFile"),d=a("Molecule.Camera"),e=a("Molecule.Scene"),f=a("Molecule.Map"),g=a("Molecule.ImageFile"),h=a("Molecule.AudioFile"),i=a("Molecule.WebAudioFile"),j=a("Molecule.Input"),k=a("Molecule.Text"),l=a("Molecule.Physics"),m=a("Molecule.Move"),n=a("Molecule.SpriteCollisions"),o=a("Molecule.MapCollisions"),p=a("Molecule.Sprite"),q=a("Molecule.SpriteSheetFile"),r=a("Molecule.Molecule"),s=a("Molecule.utils");b.init=null,b.inlineMolecules={},b.updateGame=function(){},b.update=function(a,b){for(var c,d=0;d<b.scene.sprites.length;d++)c=b.scene.sprites[d],c.update(),c.flipUpdate(),null!==c.animation&&a&&c.animation.nextFrame();b.map&&b.map.update()},b.loadResources=function(a,c){var d=c.imageFile.data.length+c.mapFile.maps.length+c.audioFile.data.length+c.spriteSheetFile.data.length+c.webAudioFile.data.length,e=c.imageFile.counter+c.mapFile.getCounter()+c.audioFile.counter+c.spriteSheetFile.getCounter()+c.webAudioFile.counter;if(c.imageFile.isLoaded()&&c.mapFile.isLoaded()&&c.audioFile.isLoaded()&&c.spriteSheetFile.isLoaded()&&c.webAudioFile.isLoaded()){clearInterval(a);for(var f=0;f<c.scene.sprites.length;f++)c.scene.sprites[f].getAnimation();b.init(),b.loop(c)}c.context.save(),c.context.fillStyle="#f8f8f8",c.context.fillRect(30,Math.round(c.height/1.25),c.width-60,16),c.context.fillStyle="#ea863a",c.context.fillRect(30,Math.round(c.height/1.25),(c.width-60)*(e/d),16),c.context.restore()},b.updateSpritesID=function(a){for(var b=0;b<a.length;b++)a[b].id=b},b.removeSprites=function(a){for(var b=a.length-1;b>=0;b--)a[b].kill&&a.splice(b,1)},b.resetCollisionState=function(a){for(var b,c=0;c<a.length;c++)b=a[c],b.collision.sprite.id=null,b.collision.sprite.left=!1,b.collision.sprite.right=!1,b.collision.sprite.up=!1,b.collision.sprite.down=!1,b.collision.map.tile=null,b.collision.map.left=!1,b.collision.map.right=!1,b.collision.map.up=!1,b.collision.map.down=!1,b.collision.boundaries.id=null,b.collision.boundaries.left=!1,b.collision.boundaries.right=!1,b.collision.boundaries.up=!1,b.collision.boundaries.down=!1},b.updateMolecules=function(a){for(var b,c=0;c<a.scene.molecules.length;c++)b=a.scene.molecules[c],b.update&&b.update()},b.updateDrawMolecules=function(a){for(var b,c=0;c<a.scene.molecules.length;c++)b=a.scene.molecules[c],b.draw&&b.draw()},b.loop=function(a){if(a.input.checkGamepad(),b.removeSprites(a.scene.sprites),b.updateSpritesID(a.scene.sprites),b.updateMolecules(a),b.update(null,a),1==a.status){var c=!1;for(l(a),b.resetCollisionState(a.scene.sprites);!c;)c=m(a.scene.sprites),b.checkBoundaries(a),o(a),n(a),b.updateSpriteCollisionCheck(a.scene.sprites),1===a.camera.type&&a.camera.update(a.scene.sprites),b.update(c,a),a.resetMove()}b.draw(a),b.updateDrawMolecules(a),b.updateGame(),b.requestAnimFrame(function(){b.loop(a)})},b.updateSpriteCollisionCheck=function(a){for(var b,c=0;c<a.length;c++)b=a[c],b.speed.check.x&&b.speed.check.y&&b.resetMove()},b.checkBoundaries=function(a){for(var b,c=0;c<a.scene.sprites.length;c++)b=a.scene.sprites[c],null!==a.boundaries.x&&b.collides.boundaries&&(b.position.x-b.anchor.x+b.frame.offset.x+b.move.x<a.boundaries.x&&(b.position.x=a.boundaries.x+b.anchor.x-b.frame.offset.x,b.collision.boundaries.left=!0,b.collision.boundaries.id=0,b.move.x=0,b.speed.x=0,b.speed.t.x=0,a.physics.gravity.x<0&&(b.speed.gravity.x=0)),b.position.x+b.frame.width-b.anchor.x-b.frame.offset.x+b.move.x>a.boundaries.x+a.boundaries.width&&(b.position.x=a.boundaries.x+a.boundaries.width-b.frame.width+b.anchor.x+b.frame.offset.x,b.collision.boundaries.right=!0,b.collision.boundaries.id=1,b.move.x=0,b.speed.x=0,b.speed.t.x=0,a.physics.gravity.x>0&&(b.speed.gravity.x=0))),null!==a.boundaries.y&&b.collides.boundaries&&(b.position.y-b.anchor.y+b.frame.offset.y+b.move.y<a.boundaries.y&&(b.position.y=a.boundaries.y+b.anchor.y-b.frame.offset.y,b.collision.boundaries.up=!0,b.collision.boundaries.id=2,b.move.y=0,b.speed.y=0,b.speed.t.y=0,a.physics.gravity.y<0&&(b.speed.gravity.y=0)),b.position.y+b.frame.height-b.anchor.y-b.frame.offset.y+b.move.y>a.boundaries.y+a.boundaries.height&&(b.position.y=a.boundaries.y+a.boundaries.height-b.frame.height+b.anchor.y+b.frame.offset.y,b.collision.boundaries.down=!0,b.collision.boundaries.id=3,b.move.y=0,b.speed.y=0,b.speed.t.y=0,a.physics.gravity.y>0&&(b.speed.gravity.y=0)))},b.draw=function(a){var b;for(a.context.clearRect(0,0,a.width,a.height),a.map&&a.map.visible&&a.map.draw(!1),b=0;b<a.scene.sprites.length;b++)a.scene.sprites[b].visible&&a.scene.sprites[b].draw(!1);for(b=0;b<a.scene.sprites.length;b++)a.scene.sprites[b].visible&&a.scene.sprites[b].draw(!0);for(a.map&&a.map.visible&&a.map.draw(!0),b=0;b<a.scene.text.length;b++)a.scene.text[b].visible&&a.scene.text[b].draw()},b.requestAnimFrame=function(){var a=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,1e3/60)};return a.bind(window)}(),b.start=function(a){var c=setInterval(function(){b.loadResources(c,a)},100)},b.propertiesMatch=function(a,b){var c=!0;if(!b)return!0;for(var d in b)b.hasOwnProperty(d)&&a[d]!==b[d]&&(c=!1);return c},b.timeouts=[];var t=function(a){this.canvas=null,this.context=null,this.next={scene:null,fade:null},this.status=1,this.timer={loop:.06,previus:null,now:null,fps:60,frame:0},this.sounds={},this.sprites={},this.tilemaps={},this.globals=a.globals||{},this.node=a.node,this.smooth=a.smooth||!1,this.scale=a.scale||1,this.width=a.width,this.height=a.height,this.canvas=document.createElement("canvas"),this.canvas.setAttribute("id","canvas"),this.context=this.canvas.getContext("2d");var b=window.devicePixelRatio||1,k=this.context.webkitBackingStorePixelRatio||this.context.mozBackingStorePixelRatio||this.context.msBackingStorePixelRatio||this.context.oBackingStorePixelRatio||this.context.backingStorePixelRatio||1,l=b/k;this.canvas.width=a.width*l*this.scale,this.canvas.height=a.height*l*this.scale,this.canvas.style.width=a.width*this.scale+"px",this.canvas.style.height=a.height*this.scale+"px",this.context.scale(l*this.scale,l*this.scale),this.context.imageSmoothingEnabled=this.smooth,this.context.mozImageSmoothingEnabled=this.smooth,this.context.oImageSmoothingEnabled=this.smooth,this.context.webkitImageSmoothingEnabled=this.smooth,this.context.msImageSmoothingEnabled=this.smooth,this.camera=new d(this),this.scene=new e(this),this.map=new f(this),this.input=new j(this),this.imageFile=new g(this),this.audioFile=new h(this),this.webAudioFile=new i(this),this.mapFile=new c(this),this.spriteSheetFile=new q(this),this.physics={gravity:{x:0,y:0},friction:{x:0,y:0}},this.boundaries={x:null,y:null,width:null,height:null},s.bindMethods(this.molecule,this),s.bindMethods(this.sprite,this),s.bindMethods(this.text,this),s.bindMethods(this.tilemap,this),s.bindMethods(this.audio,this),s.bindMethods(this.webaudio,this),this.node?document.getElementById(this.node).appendChild(this.canvas):document.body.appendChild(this.canvas)};return t.prototype.audio={create:function(a){if(s.isString(a)&&this.sounds[a])return this.sounds[a].clone();throw new Error("No audio loaded with the name "+a)}},t.prototype.webaudio={create:function(a){if(s.isString(a)&&this.sounds[a])return this.sounds[a].clone();throw new Error("No webaudio loaded with the name "+a)}},t.prototype.add=function(a){if(0===arguments.length||arguments.length>1||"string"==typeof arguments[0])throw new Error("You can only add a single sprite, Molecule Object or text, use respective game.sprite.add, game.object.add and game.text.add");if(a instanceof r)return this.molecule.add(a);if(a instanceof p)return this.sprite.add(a);if(a instanceof k)return this.text.add(a);if("function"==typeof a)return this.molecule.add(a);throw new Error("You did not pass sprite, Molecule Object or text")},t.prototype.get=function(){return{sprites:this.scene.sprites,molecules:this.scene.molecules,text:this.scene.text}},t.prototype.remove=function(a){if(0===arguments.length||arguments.length>1)throw new Error("You can only remove a single sprite, Molecule Object or text");if(a instanceof r)return this.molecule.remove(a);if(a instanceof p)return this.sprite.remove(a);if(a instanceof k)return this.text.remove(a);throw new Error("You did not pass sprite, Molecule Object or text")},t.prototype.is=function(a,b){return a._MoleculeType===b},t.prototype.updateTimer=function(){this.timer.frame++,this.timer.now=(new Date).getTime(),null!==this.timer.previus&&(this.timer.loop=(this.timer.now-this.timer.previus)/1e3),this.timer.now-this.timer.previus>=1e3&&(this.timer.previus=this.timer.now,this.timer.fps=this.timer.frame,this.timer.frame=0)},t.prototype.play=function(){this.status=1},t.prototype.stop=function(){this.status=0},t.prototype.resetMove=function(){for(var a=0;a<this.scene.sprites.length;a++)this.scene.sprites[a].resetMove();this.map&&this.map.resetScroll(),b.update(null,this)},t.prototype.cameraUpdate=function(a){for(var b=0;b<this.scene.sprites.length;b++)this.scene.sprites[b].update(),this.scene.sprites[b].flipUpdate(),null!==this.scene.sprites[b].animation&&a&&this.scene.sprites[b].animation.nextFrame();null!==this.map&&this.map.update()},t.prototype.start=function(){b.start(this)},t.prototype.init=function(c,d){var e,f=this;b.init=function(){c(),e=s.isString(d)?a(d):d.call(f.globals,f,a),"function"==typeof e&&f.add(e)}},t.prototype.update=function(c){b.updateGame=c.bind(this.globals,this,a)},t.prototype.molecule={define:function(){var a=arguments.length>1?arguments[0]:null,c=1===arguments.length?arguments[0]:arguments[1],d=r.extend(c);if(!a)return d;if(b.inlineMolecules[a])throw new Error(a+" already exists as an object");return b.inlineMolecules[a]=d,d},create:function(){var c,d,e=arguments[0],f=arguments[1];return"function"==typeof arguments[0]?new arguments[0](arguments[1]):(c=b.inlineMolecules[e]?b.inlineMolecules[e]:a(e),d=new c(f),d._MoleculeType=e,d)},add:function(){var a;if("string"==typeof arguments[0])a=this.molecule.create(arguments[0],arguments[1]);else if(s.isMolecule(arguments[0]))a=arguments[0];else{if("function"!=typeof arguments[0])throw new Error("Wrong parameters, need a string or Molecule Object");a=this.molecule.create(arguments[0],arguments[1])}if(this.scene.molecules.push(a),a.text)for(var b in a.text)a.text.hasOwnProperty(b)&&this.scene.text.push(a.text[b]);if(a.sprite)this.scene.sprites.push(a.sprite);else if(a.sprites)for(var c in a.sprites)a.sprites.hasOwnProperty(c)&&a.sprites[c]&&this.scene.sprites.push(a.sprites[c]);return a},get:function(){var a;return arguments.length?"string"==typeof arguments[0]?(a=arguments[1]||{},a._MoleculeType=arguments[0],s.find(this.scene.molecules,a)):s.find(this.scene.molecules,arguments[0]):this.scene.molecules},remove:function(){var a=arguments[0]instanceof r?[arguments[0]]:this.molecule.get.apply(this,arguments),b=this;a.forEach(function(a){if(a.removeListeners(),a.teardown&&a.teardown(),b.scene.molecules.splice(b.scene.molecules.indexOf(a),1),a.sprite)b.scene.sprites.splice(b.scene.sprites.indexOf(a.sprite),1);else if(a.sprites)for(var c in a.sprites)a.sprites.hasOwnProperty(c)&&a.sprites[c]&&b.scene.sprites.splice(b.scene.sprites.indexOf(a.sprites[c]),1);if(a.text)for(var d in a.text)a.text.hasOwnProperty(d)&&b.scene.text.splice(b.scene.text.indexOf(a.text[d]),1);if(a.audio)for(var e in a.audio)a.audio.hasOwnProperty(e)&&a.audio[e].stop();if(a.webaudio)for(var f in a.webaudio)a.webaudio.hasOwnProperty(f)&&a.webaudio[f].stop()})}},t.prototype.sprite={create:function(a){var b,c;if(!this.sprites[a])throw new Error("Sprite "+a+" does not exist. Has it been loaded?");return b=this.sprites[a],c=b.clone()},add:function(){var a;if("string"==typeof arguments[0])a=this.sprite.create(arguments[0]);else{if(!s.isSprite(arguments[0]))throw new Error("Wrong parameters, need a string or sprite");a=arguments[0]}return this.scene.sprites.push(a),a},get:function(){var a;return arguments.length?"string"==typeof arguments[0]?(a={name:arguments[0]},s.find(this.scene.sprites,a)):s.find(this.scene.sprites,arguments[0]):this.scene.sprites},remove:function(){var a=arguments[0]instanceof p?[arguments[0]]:this.sprite.get.apply(this,arguments),b=this;a.forEach(function(a){b.scene.sprites.splice(b.scene.sprites.indexOf(a),1)})}},t.prototype.text={create:function(a){var b=new k(a,this);return b},add:function(){var a;if(s.isText(arguments[0]))a=arguments[0];else{if(!s.isObject(arguments[0]))throw new Error("Wrong parameters, need a new object or existing Text object");a=this.text.create(arguments[0])}return this.scene.text.push(a),a},get:function(){return arguments.length?s.find(this.scene.text,arguments[0]):this.scene.text},remove:function(){var a=arguments[0]instanceof k?[arguments[0]]:this.text.get.apply(this,arguments),b=this;a.forEach(function(a){b.scene.text.splice(b.scene.text.indexOf(a),1)})}},t.prototype.tilemap={set:function(){var a=this.tilemaps[arguments[0]]||arguments[0],b=this;if(!a||!s.isTilemap(a))throw new Error("There is no tilemap with the name "+arguments[0]+" loaded");this.map&&this.map.molecules.length&&this.map.molecules.forEach(function(a){b.remove(a)}),this.mapFile.set(a)},get:function(){return this.map},remove:function(){var a=this;this.map&&this.map.molecules.length&&this.map.molecules.forEach(function(b){a.remove(b)}),this.map=null}},t.prototype.trigger=function(){var a,b=arguments[0],c=Array.prototype.slice.call(arguments,0);c.splice(0,1),document.createEvent?(a=document.createEvent("CustomEvent"),a.initCustomEvent(b,!0,!0,c)):a=new CustomEvent(b,{detail:c}),window.dispatchEvent(a)},t.prototype.timeout=function(a,c,d){var e=a.toString(),f=function(a){for(var c,d=0;d<b.timeouts.length;d++)if(c=b.timeouts[d],c.funcString===a)return c},g=f(e);return g?g:(g={funcString:e,id:setTimeout(function(){b.timeouts.splice(b.timeouts.indexOf(f(g.funcString)),1),a.call(d)},c),clear:function(){clearTimeout(this.id),b.timeouts.splice(b.timeouts.indexOf(f(this.funcString)),1)}},b.timeouts.push(g),g)},t}),Molecule.module("Molecule.ImageFile",function(a){function b(a){this.game=a,this.name=[],this.data=[],this.counter=0}var c=a("Molecule.Sprite");return b.prototype.preload=function(a){var b=a.substring(0,a.length-4);if(!this.getImageDataByName(b)){var c=this,d=new Image;d.addEventListener("load",function(){c.counter++}),d.src=a,this.name.push(b),this.data.push(d)}return this.getImageDataByName(b)},b.prototype.load=function(a,b,d,e){var f=new c(a,b,d,e);return f.game=this.game,f._MoleculeType=a,f.image=this.preload(b),this.isLoaded()&&f.getAnimation(),this.game.sprites[a]=f,f},b.prototype.loadSpriteSheet=function(a,b,d,e){this.name.push(a),this.data.push(b);var f=new c(a,"",d,e);return f.game=this.game,f._MoleculeType=a,f.image=b,f.getAnimation(),this.game.sprites[a]=f,this.counter++,f},b.prototype.reset=function(){this.game.scene.sprites=[]},b.prototype.isLoaded=function(){return this.counter===this.data.length},b.prototype.getImageDataByName=function(a){return this.data[this.name.indexOf(a)]},b.prototype.getImageDataBySrc=function(a){return a=a.substring(0,a.length-4),this.data[this.name.indexOf(a)]},b}),Molecule.module("Molecule.Input",function(){function a(a){var b=this;this.game=a,this.key={SPACE:0,LEFT_ARROW:0,UP_ARROW:0,RIGHT_ARROW:0,DOWN_ARROW:0,A:0,B:0,C:0,D:0,E:0,F:0,G:0,H:0,I:0,J:0,K:0,L:0,M:0,N:0,O:0,P:0,Q:0,R:0,S:0,T:0,U:0,V:0,W:0,X:0,Y:0,Z:0},this.mouse={x:0,y:0,BUTTON_LEFT:0,BUTTON_MIDDLE:0,BUTTON_RIGHT:0},this.touch=[],this.gamepad=[],this.gamepadEnabled=!1,this.accelerometer={x:0,y:0,z:0,alpha:0,beta:0,gamma:0,interval:0},this.keydown=function(a){b.onkeydown(a)},this.keyup=function(a){b.onkeyup(a)},this.mousedown=function(a){b.onmousedown(a)},this.mousemove=function(a){b.onmousemove(a)},this.mouseup=function(a){b.onmouseup(a)},this.touchstart=function(a){b.ontouchstart(a)},this.touchmove=function(a){b.ontouchmove(a)},this.touchend=function(a){b.ontouchend(a)},this.touchcancel=function(a){b.ontouchcancel(a)},this.devicemotion=function(a){b.ondevicemotion(a)}}return a.prototype.enable=function(a){"keyboard"===a&&(document.addEventListener("keydown",this.keydown,!0),document.addEventListener("keyup",this.keyup,!0)),"mouse"===a&&(this.game.canvas.addEventListener("mousedown",this.mousedown,!0),this.game.canvas.addEventListener("mousemove",this.mousemove,!0),this.game.canvas.addEventListener("mouseup",this.mouseup,!0)),"touch"===a&&(this.game.canvas.addEventListener("MSPointerDown",this.touchstart,!0),this.game.canvas.addEventListener("MSPointerMove",this.touchmove,!0),this.game.canvas.addEventListener("MSPointerUp",this.touchend,!0),this.game.canvas.addEventListener("MSPointerCancel",this.touchcancel,!0),this.game.canvas.addEventListener("touchstart",this.touchstart,!0),this.game.canvas.addEventListener("touchmove",this.touchmove,!0),this.game.canvas.addEventListener("touchend",this.touchend,!0),this.game.canvas.addEventListener("touchcancel",this.touchcancel,!0)),"gamepad"===a&&(this.gamepadEnabled=!0),"accelerometer"===a&&window.addEventListener("devicemotion",this.devicemotion,!0)},a.prototype.disable=function(a){"keyboard"===a&&(document.removeEventListener("keydown",this.keydown,!0),document.removeEventListener("keyup",this.keyup,!0)),"mouse"===a&&(this.game.canvas.removeEventListener("mousedown",this.mousedown,!0),this.game.canvas.removeEventListener("mousemove",this.mousemove,!0),this.game.canvas.removeEventListener("mouseup",this.mouseup,!0)),"touch"===a&&(this.game.canvas.removeEventListener("MSPointerDown",this.touchstart,!0),this.game.canvas.removeEventListener("MSPointerMove",this.touchmove,!0),this.game.canvas.removeEventListener("MSPointerUp",this.touchend,!0),this.game.canvas.removeEventListener("MSPointerCancel",this.touchcancel,!0),this.game.canvas.removeEventListener("touchstart",this.touchstart,!0),this.game.canvas.removeEventListener("touchmove",this.touchmove,!0),this.game.canvas.removeEventListener("touchend",this.touchend,!0),this.game.canvas.removeEventListener("touchcancel",this.touchcancel,!0)),"gamepad"===a&&(this.gamepadEnabled=!1),"accelerometer"===a&&window.removeEventListener("devicemotion",this.devicemotion,!0)},a.prototype.checkGamepad=function(){var a;if(this.gamepad=[],this.gamepadEnabled&&(navigator.getGamepads||navigator.webkitGetGamepads))if(navigator.getGamepads)for(a=0;a<navigator.getGamepads().length;a++)void 0!==navigator.getGamepads()[a]&&0!==navigator.getGamepads()[a].timestamp&&this.gamepad.push(navigator.getGamepads()[a]);else if(navigator.webkitGetGamepads)for(a=0;a<navigator.webkitGetGamepads().length;a++)void 0!==navigator.webkitGetGamepads()[a]&&0!==navigator.webkitGetGamepads()[a].timestamp&&this.gamepad.push(navigator.webkitGetGamepads()[a]);0===this.gamepad.length&&this.gamepad.push({axes:0,buttons:0})},a.prototype.onkeydown=function(a){switch(a.preventDefault(),a.keyCode){case 32:this.key.SPACE=1;break;case 37:this.key.LEFT_ARROW=1;break;case 38:this.key.UP_ARROW=1;break;case 39:this.key.RIGHT_ARROW=1;break;case 40:this.key.DOWN_ARROW=1;break;case 65:this.key.A=1;break;case 66:this.key.B=1;break;case 67:this.key.C=1;break;case 68:this.key.D=1;break;case 69:this.key.E=1;break;case 70:this.key.F=1;break;case 71:this.key.G=1;break;case 72:this.key.H=1;break;case 73:this.key.I=1;break;case 74:this.key.J=1;break;case 75:this.key.K=1;break;case 76:this.key.L=1;break;case 77:this.key.M=1;break;case 78:this.key.N=1;break;case 79:this.key.O=1;break;case 80:this.key.P=1;break;case 81:this.key.Q=1;break;case 82:this.key.R=1;break;case 83:this.key.S=1;break;case 84:this.key.T=1;break;case 85:this.key.U=1;break;case 86:this.key.V=1;break;case 87:this.key.W=1;break;case 88:this.key.X=1;break;case 89:this.key.Y=1;break;case 90:this.key.Z=1}},a.prototype.onkeyup=function(a){switch(a.preventDefault(),a.keyCode){case 32:this.key.SPACE=0;break;case 37:this.key.LEFT_ARROW=0;break;case 38:this.key.UP_ARROW=0;break;case 39:this.key.RIGHT_ARROW=0;break;case 40:this.key.DOWN_ARROW=0;break;case 65:this.key.A=0;break;case 66:this.key.B=0;break;case 67:this.key.C=0;break;case 68:this.key.D=0;break;case 69:this.key.E=0;break;case 70:this.key.F=0;break;case 71:this.key.G=0;break;case 72:this.key.H=0;break;case 73:this.key.I=0;break;case 74:this.key.J=0;break;case 75:this.key.K=0;break;case 76:this.key.L=0;break;case 77:this.key.M=0;break;case 78:this.key.N=0;break;case 79:this.key.O=0;break;case 80:this.key.P=0;break;case 81:this.key.Q=0;break;case 82:this.key.R=0;break;case 83:this.key.S=0;break;case 84:this.key.T=0;break;case 85:this.key.U=0;break;case 86:this.key.V=0;break;case 87:this.key.W=0;break;case 88:this.key.X=0;break;case 89:this.key.Y=0;break;case 90:this.key.Z=0}},a.prototype.onmousedown=function(a){switch(a.button){case 0:this.mouse.BUTTON_LEFT=1;
  break;case 1:this.mouse.BUTTON_MIDDLE=1;break;case 2:this.mouse.BUTTON_RIGHT=1}this.mousePosition(a)},a.prototype.onmousemove=function(a){this.mousePosition(a)},a.prototype.onmouseup=function(a){switch(a.button){case 0:this.mouse.BUTTON_LEFT=0;break;case 1:this.mouse.BUTTON_MIDDLE=0;break;case 2:this.mouse.BUTTON_RIGHT=0}this.mousePosition(a)},a.prototype.mousePosition=function(a){this.mouse.x=(a.pageX-this.game.canvas.offsetLeft)/this.game.scale,this.mouse.y=(a.pageY-this.game.canvas.offsetTop)/this.game.scale},a.prototype.ontouchstart=function(a){a.preventDefault(),this.normalizeTouches(a)},a.prototype.ontouchmove=function(a){a.preventDefault(),this.normalizeTouches(a)},a.prototype.ontouchend=function(a){a.preventDefault(),this.normalizeTouches(a)},a.prototype.ontouchcancel=function(a){a.preventDefault(),this.touch=[]},a.prototype.normalizeTouches=function(a){if(this.touch=[],a.touches)for(var b=0;b<a.touches.length;b++)this.touch.push({x:(a.touches[b].pageX-this.game.canvas.offsetLeft)/this.game.scale,y:(a.touches[b].pageY-this.game.canvas.offsetTop)/this.game.scale});else void 0!==a&&this.touch.push({x:(a.pageX-this.game.canvas.offsetLeft)/this.game.scale,y:(a.pageY-this.game.canvas.offsetTop)/this.game.scale})},a.prototype.ondevicemotion=function(a){this.accelerometer.x=a.acceleration.x,this.accelerometer.y=a.acceleration.y,this.accelerometer.z=a.acceleration.z,this.accelerometer.alpha=a.rotationRate.alpha,this.accelerometer.beta=a.rotationRate.beta,this.accelerometer.gamma=a.rotationRate.gamma,this.accelerometer.interval=a.interval},a}),Molecule.module("Molecule.Map",function(a){function b(a){this.game=a,this.canvas=[],this.context=[],this.name=null,this.visible=!0,this.sprites=[],this.molecules=[],this.image=[],this.path="",this.response=null,this.json=null,this.loaded=!1}var c=a("Molecule.Sprite");return b.prototype.load=function(a,b){this.id=a,this.name=b;for(var c=b.split("/"),d=0;d<c.length-1;d++)this.path+=c[d]+"/";this.ajaxJsonReq(this.name),this.game.tilemaps[a]=this},b.prototype.ajaxJsonReq=function(a){var b=this,c=new XMLHttpRequest;c.open("GET",a,!0),c.setRequestHeader("Content-type","application/json"),c.addEventListener("readystatechange",function(){b.jsonLoaded(c)}),c.send()},b.prototype.jsonLoaded=function(a){4==a.readyState&&200==a.status&&(this.response=a.responseText,this.json=JSON.parse(this.response),this.addProperties(),this.loadImages())},b.prototype.reset=function(){this.json=null,this.json=JSON.parse(this.response),this.addProperties(),this.canvas=[],this.context=[],this.createContext()},b.prototype.loadImages=function(){for(var a=this,b=0;b<this.json.tilesets.length;b++){var c=this.game.imageFile.preload(this.path+this.json.tilesets[b].image);this.image.push(c)}var d=setInterval(function(){a.loadResources(d)},100)},b.prototype.loadResources=function(a){this.game.imageFile.isLoaded()&&(clearInterval(a),this.loaded=!0)},b.prototype.addProperties=function(){var a,b,c,d,e,f,g,h;for(h=0;h<this.json.layers.length;h++)"tilelayer"===this.json.layers[h].type&&(void 0!==this.json.layers[h].properties?(g="true"===this.json.layers[h].properties.main||!1,a=!false,b="true"===this.json.layers[h].properties.collidable||!1,e="true"===this.json.layers[h].properties.overlap||!1,f=this.json.layers[h].properties["scroll.speed"]||1,f=parseFloat(f).toFixed(3),c="true"===this.json.layers[h].properties["scroll.infinite.x"]||!1,d="true"===this.json.layers[h].properties["scroll.infinite.y"]||!1,this.json.layers[h].properties={scroll:{x:0,y:0,speed:f,infinite:{x:c,y:d}},main:g,scrollable:a,collidable:b,overlap:e,infinite:{x:c,y:d}}):this.json.layers[h].properties={scroll:{x:0,y:0,speed:1,infinite:{x:!1,y:!1}},main:!1,scrollable:!0,collidable:!1,overlap:!1,infinite:{x:!1,y:!1}})},b.prototype.createContext=function(){var a,b,d,e,f,g,h;for(g=0;g<this.json.layers.length;g++)if("tilelayer"===this.json.layers[g].type)for(this.canvas.push(document.createElement("canvas")),this.context.push(this.canvas[g].getContext("2d")),this.canvas[g].width=this.json.layers[g].width*this.json.tilewidth,this.canvas[g].height=this.json.layers[g].height*this.json.tileheight,h=0;h<this.json.layers[g].data.length;h++)f=this.json.layers[g].data[h],f>0&&(d=this.getTileset(f),this.context[g].save(),this.context[g].globalAlpha=this.json.layers[g].opacity,this.context[g].drawImage(this.image[d],Math.floor((f-this.json.tilesets[d].firstgid)%(this.json.tilesets[d].imagewidth/this.json.tilesets[d].tilewidth))*this.json.tilesets[d].tilewidth,Math.floor((f-this.json.tilesets[d].firstgid)/(this.json.tilesets[d].imagewidth/this.json.tilesets[d].tilewidth))*this.json.tilesets[d].tileheight,this.json.tilesets[d].tilewidth,this.json.tilesets[d].tileheight,Math.floor(h%this.json.layers[g].width)*this.json.tilesets[d].tilewidth,Math.floor(h/this.json.layers[g].width)*this.json.tilesets[d].tileheight,this.json.tilesets[d].tilewidth,this.json.tilesets[d].tileheight),this.context[g].restore());else if("objectgroup"===this.json.layers[g].type)for(h=0;h<this.json.layers[g].objects.length;h++){f=this.json.layers[g].objects[h].gid,d=this.getTileset(f),a=this.json.tilesets[d].tilewidth,b=this.json.tilesets[d].tileheight,e=new c(this.json.layers[g].objects[h].name||this.json.tilesets[d].name,this.json.tilesets[d].image,a,b),e.game=this.game,e.image=this.game.imageFile.getImageDataBySrc(this.path+this.json.tilesets[d].image),this.game.mapFile.copyMapProperties(g,h,e,this.path),e.getAnimation();var i=this.game.molecule.add(this.json.layers[g].name,{sprite:e});this.molecules.push(i)}},b.prototype.getTileset=function(a){for(var b=0;b<this.json.tilesets.length;b++){if(this.json.tilesets[b].firstgid>a)return b-1;if(1===this.json.tilesets.length||this.json.tilesets.length-1===b||this.json.tilesets[b].firstgid===a)return b}},b.prototype.getMainLayer=function(){if(null!==this.json)for(var a=0;a<this.json.layers.length;a++)if("tilelayer"===this.game.map.json.layers[a].type&&this.json.layers[a].properties.main)return a;return-1},b.prototype.getLayerIdByName=function(a){for(var b=0;b<this.json.layers.length;b++)if(this.json.layers[b].name===a)return b;return-1},b.prototype.getTilesetIdByName=function(a){for(var b=0;b<this.json.tilesets.length;b++)if(this.json.tilesets[b].name===a)return b;return-1},b.prototype.getTile=function(a,b,c,d,e){d=d||0,e=e||0;var f=this.getLayerIdByName(a);if("tilelayer"===this.json.layers[f].type){this.json.layers[f].properties.scroll.infinite.x&&b>=this.canvas[f].width/2&&(b=Math.floor(b%this.canvas[f].width)),this.json.layers[f].properties.scroll.infinite.y&&c>=this.canvas[f].height/2&&(c=Math.floor(c%this.canvas[f].height));var g=Math.floor(c/this.json.tileheight)*this.json.layers[f].width+Math.floor(b/this.json.tilewidth);return g>=this.json.layers[f].data.length||0>g||b>this.json.layers[f].width*this.json.tilewidth||0>b+d||c>this.json.layers[f].height*this.json.tileheight||0>c+e?null:g}return null},b.prototype.getTileData=function(a,b,c){var d=this.getLayerIdByName(a),e=this.getTile(a,b,c);return null===e?null:this.json.layers[d].data[e]},b.prototype.clearTile=function(a,b,c){var d=this.getLayerIdByName(a),e=this.json.layers[d],f=this.getTile(a,b,c);null!==f&&(e.data[f]=0,this.context[d].save(),this.context[d].globalAlpha=e.opacity,this.context[d].clearRect(Math.floor(f%this.json.layers[d].width)*this.json.tilewidth,Math.floor(f/this.json.layers[d].width)*this.json.tilewidth,this.json.tilewidth,this.json.tileheight),this.context[d].restore())},b.prototype.setTile=function(a,b,c,d,e){var f=this.getLayerIdByName(a),g=this.json.layers[f],h=this.getTile(a,b,c),i=this.getTilesetIdByName(d),j=e+this.json.tilesets[i].firstgid;null!==h&&(g.data[h]=j,this.context[f].save(),this.context[f].globalAlpha=this.json.layers[f].opacity,this.context[f].drawImage(this.image[i],Math.floor((j-this.json.tilesets[i].firstgid)%this.json.layers[f].width)*this.json.tilesets[i].tilewidth,Math.floor((j-this.json.tilesets[i].firstgid)/this.json.layers[f].width)*this.json.tilesets[i].tilewidth,this.json.tilesets[i].tilewidth,this.json.tilesets[i].tileheight,Math.floor(h%this.json.layers[f].width)*this.json.tilewidth,Math.floor(h/this.json.layers[f].width)*this.json.tilewidth,this.json.tilewidth,this.json.tileheight),this.context[f].restore())},b.prototype.update=function(){if(null!==this.json)for(var a=0;a<this.json.layers.length;a++)"tilelayer"===this.json.layers[a].type&&(this.json.layers[a].x+=this.json.layers[a].properties.scroll.x,this.json.layers[a].y+=this.json.layers[a].properties.scroll.y,this.json.layers[a].x=parseFloat(this.json.layers[a].x.toFixed(3)),this.json.layers[a].y=parseFloat(this.json.layers[a].y.toFixed(3)),this.json.layers[a].properties.scroll.infinite.x&&Math.round(this.json.layers[a].x)<=-this.canvas[a].width&&this.json.layers[a].properties.scroll.x<0?this.json.layers[a].x=0:this.json.layers[a].properties.scroll.infinite.x&&Math.round(this.json.layers[a].x)>=0&&this.json.layers[a].properties.scroll.x>0&&(this.json.layers[a].x=-this.canvas[a].width+1),this.json.layers[a].properties.scroll.infinite.y&&Math.round(this.json.layers[a].y)<=-this.canvas[a].height&&this.json.layers[a].properties.scroll.y<0?this.json.layers[a].y=0:this.json.layers[a].properties.scroll.infinite.y&&Math.round(this.json.layers[a].y)>=0&&this.json.layers[a].properties.scroll.y>0&&(this.json.layers[a].y=-this.canvas[a].height+1))},b.prototype.resetScroll=function(){if(null!==this.json)for(var a=0;a<this.json.layers.length;a++)"tilelayer"===this.json.layers[a].type&&(this.json.layers[a].properties.scroll.x=0,this.json.layers[a].properties.scroll.y=0)},b.prototype.resetPosition=function(){for(var a=0;a<this.json.layers.length;a++)"tilelayer"===this.json.layers[a].type&&(this.json.layers[a].x=0,this.json.layers[a].y=0)},b.prototype.draw=function(a){for(var b=0;b<this.canvas.length;b++)if("tilelayer"===this.json.layers[b].type&&this.json.layers[b].visible&&this.json.layers[b].properties.overlap===a){var c=this.game.width>this.canvas[b].width?this.canvas[b].width:this.game.width,d=this.game.height>this.canvas[b].height?this.canvas[b].height:this.game.height,e=0,f=0;this.json.layers[b].properties.scroll.infinite.x&&Math.floor(-this.json.layers[b].x)+c>this.canvas[b].width&&(e=Math.floor(-this.json.layers[b].x)+c-this.canvas[b].width),this.json.layers[b].properties.scroll.infinite.y&&Math.floor(-this.json.layers[b].y)+d>this.canvas[b].height&&(f=Math.floor(-this.json.layers[b].y)+d-this.canvas[b].height),this.game.context.save(),this.game.context.drawImage(this.canvas[b],Math.floor(-this.json.layers[b].x),Math.floor(-this.json.layers[b].y),c-e,d-f,0,0,c-e,d-f),this.game.context.restore(),this.json.layers[b].properties.scroll.infinite.x&&e>0&&(this.game.context.save(),this.game.context.drawImage(this.canvas[b],0,Math.floor(-this.json.layers[b].y),e,d,c-e,0,e,d),this.game.context.restore()),this.json.layers[b].properties.scroll.infinite.x&&this.json.layers[b].properties.scroll.infinite.y&&e>0&&f>0&&(this.game.context.save(),this.game.context.drawImage(this.canvas[b],0,Math.floor(-this.json.layers[b].y),e,d-f,c-e,0,e,d-f),this.game.context.restore()),this.json.layers[b].properties.scroll.infinite.y&&f>0&&(this.game.context.save(),this.game.context.drawImage(this.canvas[b],Math.floor(-this.json.layers[b].x),0,c,f,0,d-f,c,f),this.game.context.restore()),this.json.layers[b].properties.scroll.infinite.y&&this.json.layers[b].properties.scroll.infinite.x&&f>0&&e>0&&(this.game.context.save(),this.game.context.drawImage(this.canvas[b],Math.floor(-this.json.layers[b].x),0,c-e,f,0,d-f,c-e,f),this.game.context.restore()),this.json.layers[b].properties.scroll.infinite.x&&this.json.layers[b].properties.scroll.infinite.y&&e>0&&f>0&&(this.game.context.save(),this.game.context.drawImage(this.canvas[b],0,0,e,f,c-e,d-f,e,f),this.game.context.restore())}},b}),Molecule.module("Molecule.MapCollisions",function(a,b){return b.spriteCollidesWithLayer=function(a,b){return"tilelayer"===a.type&&a.properties.collidable&&b.collides.map},b.getHeight=function(a,b){return Math.ceil((b.frame.height-b.frame.offset.y-b.frame.offset.y)/a)},b.getWidth=function(a,b){return Math.ceil((b.frame.width-b.frame.offset.x-b.frame.offset.x)/a)},b.getPosX=function(a,b,c){return b.position.x-b.anchor.x+b.move.x+Math.abs(a.x)+c},b.getPosY=function(a,b,c){return b.position.y-b.anchor.y+b.move.y+Math.abs(a.y)+c},b.updateCollisionX=function(a,b,c,d,e){b.collidesWithTile(a,c,d)&&(b.move.y>0&&(b.collision.map.down=!0,b.collision.map.tile=c),b.move.y<0&&(b.collision.map.up=!0,b.collision.map.tile=c),b.collision.map.down&&e.gravity.y>0&&(b.speed.gravity.y=0),b.collision.map.up&&e.gravity.y<0&&(b.speed.gravity.y=0),(b.collision.check.map.up&&b.collision.map.up||b.collision.check.map.down&&b.collision.map.down)&&(b.move.y=0,b.speed.y=0,b.speed.t.y=0))},b.updateCollisionY=function(a,b,c,d,e){b.collidesWithTile(a,c,d)&&(b.move.x>0&&(b.collision.map.right=!0,b.collision.map.tile=c),b.move.x<0&&(b.collision.map.left=!0,b.collision.map.tile=c),b.collision.map.left&&e.gravity.x<0&&(b.speed.gravity.x=0),b.collision.map.right&&e.gravity.x>0&&(b.speed.gravity.x=0),!b.collision.check.map.up&&b.collision.map.up||!b.collision.check.map.down&&b.collision.map.down||(b.collision.check.map.left&&b.collision.map.left||b.collision.check.map.right&&b.collision.map.right)&&(b.move.x=0,b.speed.x=0,b.speed.t.x=0))},function(a){var c,d,e,f,g,h,i,j,k,l,m=a.map,n=a.scene.sprites;if(m&&m.json)for(c=0;c<n.length;c++)for(g=n[c],d=0;d<m.json.layers.length;d++)if(h=m.json.layers[d],b.spriteCollidesWithLayer(h,g))for(i=0;2>=i;){if(0!==g.move.x||0!==g.move.y)for(e=0;e<=b.getHeight(m.json.tileheight,g);e++)for(f=0;f<=b.getWidth(m.json.tilewidth,g);f++)j=m.getTile(h.name,b.getPosX(h,g,f*m.json.tilewidth),b.getPosY(h,g,e*m.json.tileheight),g.frame.width,g.frame.height),null!==j&&h.data[j%h.data.length]>0&&g.collidesWithTile(h,j,d)&&((0===i||2===i)&&(k=g.move.x,g.move.x=0,b.updateCollisionX(h,g,j,d,a.physics),g.move.x=k),(1===i||2===i)&&(l=g.move.y,2!==i&&(g.move.y=0),b.updateCollisionY(h,g,j,d,a.physics),g.move.y=l));i++}}}),Molecule.module("Molecule.MapFile",function(a,b){function c(a){this.game=a,this.tile=new d(a),this.maps=[]}var d=a("Molecule.Tile"),e=a("Molecule.Map");return b.Boolean=function(a){return"true"===a},b.getProperty=function(a,b,c,d,e){return"undefined"!=typeof c[a]?b(c[a]):"undefined"!=typeof d[a]?b(d[a]):e},b.getMoleculeType=function(a,b){for(var c=a.gid,d=0;d<b.length;d++)if(b[d].firstgid===c)return b[d].name},c.prototype.load=function(a,b){var c=new e(this.game);return c.load(a,b),c._MoleculeType=a,this.maps.push(c),c},c.prototype.isLoaded=function(){for(var a=!0,b=0;b<this.maps.length;b++)this.maps[b].loaded||(a=!1);return a},c.prototype.getCounter=function(){for(var a=0,b=0;b<this.maps.length;b++)this.maps[b].loaded&&a++;return a},c.prototype.set=function(a,b){b=b||!1,this.game.camera.unfollow(),b&&a.reset(),this.game.map=a,this.game.map.createContext()},c.prototype.copyMapProperties=function(a,c,d){var e=this.game.map.json.layers[a].objects[c].properties||{},f=this.game.map.json.layers[a].properties||{};d._MoleculeType=b.getMoleculeType(this.game.map.json.layers[a].objects[c],this.game.map.json.tilesets),d.position.x=parseInt(this.game.map.json.layers[a].objects[c].x),d.position.y=parseInt(this.game.map.json.layers[a].objects[c].y)-d.frame.height,d.visible=this.game.map.json.layers[a].objects[c].visible,d.anchor.x=b.getProperty("anchor.x",Number,e,f,d.anchor.x),d.anchor.y=b.getProperty("anchor.y",Number,e,f,d.anchor.y),d.flip.x=b.getProperty("flip.x",Number,e,f,d.flip.x),d.flip.y=b.getProperty("flip.y",Number,e,f,d.flip.y),d.collides.sprite=b.getProperty("collides.sprite",b.Boolean,e,f,d.collides.sprite),d.collides.map=b.getProperty("collides.map",b.Boolean,e,f,d.collides.map),d.scrollable=b.getProperty("scrollable",b.Boolean,e,f,d.scrollable),d.collidable=b.getProperty("collidable",b.Boolean,e,f,d.collidable),d.speed.min.x=b.getProperty("speed.min.x",Number,e,f,d.speed.min.x),d.speed.min.y=b.getProperty("speed.min.y",Number,e,f,d.speed.min.y),d.speed.max.x=b.getProperty("speed.max.x",Number,e,f,d.speed.max.x),d.speed.max.y=b.getProperty("speed.max.y",Number,e,f,d.speed.max.y),d.affects.physics.gravity=b.getProperty("affects.physics.gravity",b.Boolean,e,f,d.affects.physics.gravity),d.affects.physics.friction=b.getProperty("affects.physics.friction",b.Boolean,e,f,d.affects.physics.friction),d.overlap=b.getProperty("overlap",b.Boolean,e,f,d.overlap)},c}),Molecule.module("Molecule.Molecule",function(a,b){function c(a){a=a||{};for(var b in a)a.hasOwnProperty(b)&&(this[b]=a[b]);this.sprite&&(this.sprite=this.sprite.clone());var c=this.sprites;this.sprites={};for(var d in c)c.hasOwnProperty(d)&&c[d]&&(this.sprites[d]=c[d].clone());var e=this.text;this.text={};for(var f in e)e.hasOwnProperty(f)&&(this.text[f]=e[f].clone());var g=this.audio;this.audio={};for(var h in g)g.hasOwnProperty(h)&&(this.audio[h]=g[h].clone());var i=this.webaudio;this.webaudio={};for(var h in i)i.hasOwnProperty(h)&&(this.webaudio[h]=i[h].clone());this.init()}var d=(a("Molecule.Text"),a("Molecule.utils"));return b.isInstanceOfMoleculeObject=function(a){return d.isMolecule(a)||d.isSprite(a)||d.isText(a)||d.isAudio(a)||d.isTilemap(a)},b.cloneOptions=function(a){var c={};for(var d in a)a.hasOwnProperty(d)&&(c[d]=a[d]instanceof Array?a[d].slice(0):"object"!=typeof a[d]||null===a[d]||b.isInstanceOfMoleculeObject(a[d])?a[d]:this.cloneOptions(a[d]));return c},b.mergeObjects=function(){var a,b,c=arguments[0],d=Array.prototype.slice.call(arguments,0),e=0;for(d.splice(0,1),e;e<d.length;e++){a=d[e];for(b in a)a.hasOwnProperty(b)&&(c[b]=a[b])}return c},b.extend=function(a){var c,d=this;c=function(c){return d.call(this,b.mergeObjects(b.cloneOptions(a),c||{}))},c.extend=b.extend;var e=function(){this.constructor=c};return e.prototype=d.prototype,c.prototype=new e,c.__super__=d.prototype,c},b.registeredEvents=[],b.createEventClosure=function(a,c,d){var e={type:a,context:d,callback:function(a){c.apply(d,a.detail)}};return b.registeredEvents.push(e),e.callback},c.prototype.sprite=null,c.prototype.sprites={},c.prototype.init=function(){},c.prototype.update=function(){},c.prototype.listenTo=function(a,c){window.addEventListener(a,b.createEventClosure(a,c,this))},c.prototype.removeListeners=function(){for(var a,c=0;c<b.registeredEvents.length;c++)a=b.registeredEvents[c],a.context===this&&(window.removeEventListener(a.type,a.callback),b.registeredEvents.splice(c,1),c--)},c.extend=b.extend,c}),Molecule.module("Molecule.Move",function(){return function(a){for(var b,c,d=!0,e=0;e<a.length;e++)c=a[e],b=!0,c.speed.check.x=!0,c.speed.check.y=!0,c.speed.t.x>=1?(c.speed.t.x-=1,c.move.x=1,b=!1,d=!1,c.speed.check.x=!1):c.speed.t.x<=-1&&(c.speed.t.x+=1,c.move.x=-1,b=!1,d=!1,c.speed.check.x=!1),c.speed.t.y>=1?(c.speed.t.y-=1,c.move.y=1,b=!1,d=!1,c.speed.check.y=!1):c.speed.t.y<=-1&&(c.speed.t.y+=1,c.move.y=-1,b=!1,d=!1,c.speed.check.y=!1),b&&(0!==c.speed.t.x&&(c.move.x=c.speed.t.x>0?1:-1),0!==c.speed.t.y&&(c.move.y=c.speed.t.y>0?1:-1));return d}}),Molecule.module("Molecule.MWebAudio",function(){function a(){this.sound=null,this.buffer=null,this.context=null,this.startOffset=0,this.startTime=0}return a.prototype.play=function(a){a="undefined"==typeof a?!1:a,this.startTime=this.context.currentTime,this.sound&&2===this.sound.playbackState&&this.sound.stop(0),this.sound=this.context.createBufferSource(),this.sound.connect(this.context.destination),this.sound.buffer=this.buffer,this.sound.loop=a,this.sound.start(0,this.startOffset%this.buffer.duration)},a.prototype.pause=function(){this.sound&&3!==this.sound.playbackState&&(this.sound.stop(0),this.startOffset+=this.context.currentTime-this.startTime)},a.prototype.stop=function(){this.sound&&3!==this.sound.playbackState&&(this.sound.stop(0),this.startOffset=0)},a.prototype.clone=function(){var b=new a;return b.context=this.context,b.sound=this.sound,b.buffer=this.buffer,b},a}),Molecule.module("Molecule.Physics",function(a,b){return b.addFriction=function(a,b){a.speed.x>0?(a.speed.x=a.speed.x*(1-b.physics.friction.x),a.speed.x<.05&&(a.speed.x=0)):a.speed.x<0&&(a.speed.x=a.speed.x*(1-b.physics.friction.x),a.speed.x>-.05&&(a.speed.x=0)),a.speed.y>0?(a.speed.y=a.speed.y*(1-b.physics.friction.y),a.speed.y<.05&&(a.speed.y=0)):a.speed.y<0&&(a.speed.y=a.speed.y*(1-b.physics.friction.y),a.speed.y>-.05&&(a.speed.y=0))},b.spriteHitsPlatformBelow=function(a,b){return a.affects.physics.gravity&&b.physics.gravity.y>0&&a.collision.sprite.down&&b.scene.sprites[a.collision.sprite.id].platform},b.spriteHitsPlatformAbove=function(a,b){return a.affects.physics.gravity&&b.physics.gravity.y<0&&a.collision.sprite.up&&b.scene.sprites[a.collision.sprite.id].platform},b.spriteHitsPlatformRight=function(a,b){return a.affects.physics.gravity&&b.physics.gravity.x>0&&a.collision.sprite.right&&b.scene.sprites[a.collision.sprite.id].platform},b.spriteHitsPlatformLeft=function(a,b){return a.affects.physics.gravity&&b.physics.gravity.x<0&&a.collision.sprite.left&&b.scene.sprites[a.collision.sprite.id].platform},b.spriteSlowerThanCollisionSprite=function(a,b,c){return b.speed[a]>=0&&b.speed[a]<c.scene.sprites[b.collision.sprite.id].speed[a]},b.spriteFasterThanCollisionSprite=function(a,b,c){return b.speed[a]<=0&&b.speed[a]>c.scene.sprites[b.collision.sprite.id].speed[a]},b.increaseAcceleration=function(a){a.speed.x+=a.acceleration.x,a.speed.y+=a.acceleration.y},b.setSpeed=function(a){var b=a.speed.x>=0?1:-1,c=a.speed.y>=0?1:-1;Math.abs(a.speed.x)>a.speed.max.x&&(a.speed.x=a.speed.max.x*b),Math.abs(a.speed.y)>a.speed.max.y&&(a.speed.y=a.speed.max.y*c)},b.addGravity=function(a,b){a.speed.x-=a.speed.gravity.x,a.speed.y-=a.speed.gravity.y,a.affects.physics.gravity&&(a.speed.gravity.x+=b.physics.gravity.x,a.speed.gravity.y+=b.physics.gravity.y),a.speed.x+=a.speed.gravity.x,a.speed.y+=a.speed.gravity.y},b.cleanUpSpeed=function(a){a.speed.x=parseFloat(a.speed.x.toFixed(3)),a.speed.y=parseFloat(a.speed.y.toFixed(3)),a.speed.t.x+=a.speed.x,a.speed.t.y+=a.speed.y,a.speed.t.x=parseFloat(a.speed.t.x.toFixed(3)),a.speed.t.y=parseFloat(a.speed.t.y.toFixed(3)),a.resetAcceleration(),0===a.speed.x&&(a.speed.t.x=0),0===a.speed.y&&(a.speed.t.y=0)},function(a){for(var c,d=0;d<a.scene.sprites.length;d++)c=a.scene.sprites[d],c.affects.physics.friction&&b.addFriction(c,a),b.spriteHitsPlatformBelow(c,a)||b.spriteHitsPlatformAbove(c,a)?b.spriteSlowerThanCollisionSprite("x",c,a)?c.speed.x=a.scene.sprites[c.collision.sprite.id].speed.x:b.spriteFasterThanCollisionSprite("x",c,a)&&(c.speed.x=a.scene.sprites[c.collision.sprite.id].speed.x):(b.spriteHitsPlatformRight(c,a)||b.spriteHitsPlatformLeft(c,a))&&(b.spriteSlowerThanCollisionSprite("y",c,a)?c.speed.y=a.scene.sprites[c.collision.sprite.id].speed.y:b.spriteFasterThanCollisionSprite("y",c,a)&&(c.speed.y=a.scene.sprites[c.collision.sprite.id].speed.y)),b.increaseAcceleration(c),b.setSpeed(c),b.addGravity(c,a),b.cleanUpSpeed(c)}}),Molecule.module("Molecule.Scene",function(){function a(){this.molecules=[],this.sprites=[],this.text=[],this.tilemaps=[]}return a}),Molecule.module("Molecule.SpriteSheet",function(a,b){function c(a){this.game=a,this.sprites=null,this.image=null,this.response=null,this.json=null,this.path="",this.loaded=!1}a("Molecule.Sprite");return c.prototype.load=function(a,b){var c,d=this,e=new XMLHttpRequest,f=a.split("/");for(this.sprites=b,c=0;c<f.length-1;c++)this.path+=f[c]+"/";e.open("GET",a,!0),e.setRequestHeader("Content-type","application/json"),e.addEventListener("readystatechange",function(){d.jsonLoaded(e)}),e.send()},c.prototype.jsonLoaded=function(a){4==a.readyState&&200==a.status&&(this.response=a.responseText,this.json=JSON.parse(this.response),this.loadImage())},c.prototype.loadImage=function(){var a=this;this.image=this.game.imageFile.preload(this.path+this.json.meta.image);var b=setInterval(function(){a.loadSprites(b)},100)},c.prototype.loadSprites=function(a){var c,d,e;if(this.game.imageFile.isLoaded()){clearInterval(a);for(b in this.sprites){var f=document.createElement("canvas"),g=f.getContext("2d"),h=new Image,i=0,j=0;for(e=!1,c=0;c<this.sprites[b].length;c++)for(d=0;d<this.json.frames.length;d++)this.sprites[b][c]===this.json.frames[d].name&&(e||(i=this.json.frames[d].size.w,j=this.json.frames[d].size.h,f.width=this.json.frames[d].size.w*this.sprites[b].length,f.height=this.json.frames[d].size.h,e=!0),g.drawImage(this.image,this.json.frames[d].position.x,this.json.frames[d].position.y,this.json.frames[d].size.w,this.json.frames[d].size.h,this.json.frames[d].size.w*c,0,this.json.frames[d].size.w,this.json.frames[d].size.h));h.src=f.toDataURL("image/png");{this.game.imageFile.loadSpriteSheet(b,h,i,j)}}}this.loaded=!0},c}),Molecule.module("Molecule.SpriteSheetFile",function(a){function b(a){this.game=a,this.data=[]}var c=a("Molecule.SpriteSheet");return b.prototype.load=function(a,b){var d=new c(this.game);d.load(a,b),this.data.push(d)},b.prototype.isLoaded=function(){var a,b=!0;for(a=0;a<this.data.length;a++)this.data[a].loaded||(b=!1);return b},b.prototype.getCounter=function(){var a,b=0;for(a=0;a<this.data.length;a++)this.data[a].loaded&&b++;return b},b}),Molecule.module("Molecule.MAudio",function(){function a(){this.sound=null}return a.prototype.play=function(a){a="undefined"==typeof a?!1:a,this.sound.currentTime===this.sound.duration&&this.stop(),this.sound.loop=a,this.sound.paused||this.stop(),this.sound.play()},a.prototype.pause=function(){this.sound.pause()},a.prototype.stop=function(){this.sound.pause(),this.sound.currentTime=0},a.prototype.clone=function(){var b=new a;return b.sound=new Audio,b.sound.src=this.sound.src,b},a}),Molecule.module("Molecule.Sprite",function(a){function b(a,b,d,e){return this.name=a,this.src=b,this.id=-1,this.image=null,this.position={x:0,y:0,absolute:{x:0,y:0}},this.rotation=0,this.move={x:0,y:0},this.flip={x:!1,y:!1,offset:{x:0,y:0},f:{x:0,y:0}},this.anchor={x:0,y:0},this.visible=!0,this.alpha=1,this.frame={width:d,height:e,offset:{x:0,y:0,width:0,height:0}},this.animation=new c(this.frame.width,this.frame.height),this.size={width:0,height:0},this.collides={sprite:!0,map:!0,boundaries:!0,group:null},this.scrollable=!0,this.collidable=!0,this.platform=!1,this.acceleration={x:0,y:0},this.speed={x:0,y:0,t:{x:0,y:0},max:{x:100,y:100},min:{x:0,y:0},check:{x:!1,y:!1},gravity:{x:0,y:0}},this.affects={physics:{gravity:!0,friction:!0}},this.collision={map:{up:!1,down:!1,left:!1,right:!1,tile:null},sprite:{up:!1,down:!1,left:!1,right:!1,id:null},boundaries:{up:!1,down:!1,left:!1,right:!1,id:null},check:{map:{up:!0,down:!0,left:!0,right:!0}}},this.overlap=!1,this.kill=!1,this.game=null,this.width=0,this.height=0,this}var c=a("Molecule.Animation"),d=a("Molecule.utils");return b.prototype.getAnimation=function(){this.size={width:this.image.width,height:this.image.height},this.frame.width=this.frame.width||this.size.width,this.frame.height=this.frame.height||this.size.height,this.width=this.frame.width,this.height=this.frame.height,this.animation.sliceFrames(this.image.width,this.image.height,this.frame.width,this.frame.height)},b.prototype.flipUpdate=function(){this.flip.offset.x=this.flip.x?-this.frame.width:0,this.flip.offset.y=this.flip.y?-this.frame.height:0,this.flip.f.x=this.flip.x?-1:1,this.flip.f.y=this.flip.y?-1:1},b.prototype.update=function(){this.position.x+=this.move.x,this.position.y+=this.move.y,this.position.x=parseFloat(this.position.x.toFixed(3)),this.position.y=parseFloat(this.position.y.toFixed(3)),this.position.absolute.x=this.position.x,this.position.absolute.y=this.position.y,-1!==this.game.map.getMainLayer()&&(this.position.absolute.x+=Math.abs(this.game.map.json.layers[this.game.map.getMainLayer()].x),this.position.absolute.y+=Math.abs(this.game.map.json.layers[this.game.map.getMainLayer()].y))},b.prototype.resetMove=function(){this.move={x:0,y:0}},b.prototype.resetAcceleration=function(){this.acceleration={x:0,y:0}},b.prototype.draw=function(a){this.overlap===a&&this.position.x-this.anchor.x+this.frame.width>=0&&this.position.y-this.anchor.y+this.frame.height>=0&&this.position.x-this.anchor.x<=this.game.width&&this.position.y-this.anchor.y<=this.game.height&&(this.game.context.save(),this.game.context.globalAlpha=this.alpha,this.game.context.scale(1*this.flip.f.x,1*this.flip.f.y),this.game.context.translate(Math.round(this.position.x*this.flip.f.x+this.flip.offset.x),Math.round(this.position.y*this.flip.f.y+this.flip.offset.y)),this.game.context.rotate(this.rotation*(Math.PI/180)),this.game.context.translate(Math.round(-this.anchor.x*this.flip.f.x),Math.round(-this.anchor.y*this.flip.f.y)),this.game.context.drawImage(this.image,this.animation.frame[this.animation.id[this.animation.current.animation].frame[this.animation.current.frame]].x,this.animation.frame[this.animation.id[this.animation.current.animation].frame[this.animation.current.frame]].y,this.frame.width,this.frame.height,0,0,this.frame.width,this.frame.height),this.game.context.restore())},b.prototype.touch=function(){for(var a=this.game.input.touch,b=0;b<a.length;b++)if(this.position.x-this.anchor.x+this.frame.offset.x<=a[b].x&&this.position.x-this.anchor.x+this.frame.width-this.frame.offset.x>a[b].x&&this.position.y-this.anchor.y+this.frame.offset.y<=a[b].y&&this.position.y-this.anchor.y+this.frame.height-this.frame.offset.y>a[b].y)return!0;return!1},b.prototype.click=function(a){var b=this.game.input.mouse;return this.position.x-this.anchor.x+this.frame.offset.x<=b.x&&this.position.x-this.anchor.x+this.frame.width-this.frame.offset.x>b.x&&this.position.y-this.anchor.y+this.frame.offset.y<=b.y&&this.position.y-this.anchor.y+this.frame.height-this.frame.offset.y>b.y&&a},b.prototype.collidesWithSprite=function(a){var b={left:this.position.x-this.anchor.x+this.move.x+this.frame.offset.x,right:this.position.x-this.anchor.x+this.frame.width-this.frame.offset.x+this.move.x,top:this.position.y-this.anchor.y+this.move.y+this.frame.offset.y,bottom:this.position.y-this.anchor.y+this.frame.height-this.frame.offset.y+this.move.y},c={left:a.position.x-a.anchor.x+a.move.x+a.frame.offset.x,right:a.position.x-a.anchor.x+a.frame.width-a.frame.offset.x+a.move.x,top:a.position.y-a.anchor.y+a.move.y+a.frame.offset.y,bottom:a.position.y-a.anchor.y+a.frame.height-a.frame.offset.y+a.move.y};return!(c.left>=b.right||c.right<=b.left||c.top>=b.bottom||c.bottom<=b.top)},b.prototype.collidesWithTile=function(a,b,c){var d=Math.abs(a.x),e=Math.abs(a.y),f={position:{x:Math.floor(b%a.width)*this.game.map.json.tilewidth,y:Math.floor(b/a.width)*this.game.map.json.tileheight},width:this.game.map.json.tilesets[this.game.map.getTileset(a.data[b])].tilewidth,height:this.game.map.json.tilesets[this.game.map.getTileset(a.data[b])].tileheight},g=this.position.x-this.anchor.x+this.move.x+this.frame.offset.x+d,h=this.position.x-this.anchor.x+this.frame.width-this.frame.offset.x+this.move.x+d,i=this.position.x-this.anchor.x+this.move.x+this.frame.offset.x+d,j=this.position.x-this.anchor.x+this.move.x+this.frame.offset.x+d;a.properties.scroll.infinite.x&&(g>=this.game.map.canvas[c].width&&(g=Math.floor(g%this.game.map.canvas[c].width)),h>=this.game.map.canvas[c].width&&(h=Math.floor(h%this.game.map.canvas[c].width)),i>=this.game.map.canvas[c].width&&(i=Math.floor(i%this.game.map.canvas[c].width)),j>=this.game.map.canvas[c].width&&(j=Math.floor(j%this.game.map.canvas[c].width)));var k=this.position.y-this.anchor.y+this.move.y+this.frame.offset.y+e,l=this.position.y-this.anchor.y+this.frame.height-this.frame.offset.y+this.move.y+e,m=this.position.y-this.anchor.y+this.move.y+this.frame.offset.y+e,n=this.position.y-this.anchor.y+this.move.y+this.frame.offset.y+e;return a.properties.scroll.infinite.y&&(k>=this.game.map.canvas[c].height&&(k=Math.floor(k%this.game.map.canvas[c].height)),l>=this.game.map.canvas[c].height&&(l=Math.floor(l%this.game.map.canvas[c].height)),m>=this.game.map.canvas[c].height&&(m=Math.floor(m%this.game.map.canvas[c].height)),n>=this.game.map.canvas[c].height&&(n=Math.floor(n%this.game.map.canvas[c].height))),(g<=f.position.x&&h>f.position.x||f.position.x<=i&&f.position.x+f.width>j)&&(k<=f.position.y&&l>f.position.y||f.position.y<=m&&f.position.y+f.height>n)
  },b.prototype.clone=function(){var a=new b(this.name,this.src,this.frame.width,this.frame.height);return a.image=this.image,a.game=this.game,d.deepClone(this,a,["name","src","id","_MoleculeType","position","rotation","move","flip","anchor","visible","alpha","frame","size","collides","scrollable","collidable","platform","acceleration","speed","affects","collision","overlap","kill"]),a.getAnimation(),a},b}),Molecule.module("Molecule.SpriteCollisions",function(a,b){return b.spritesCollide=function(a,b){return(null===a.collides.group||a.collides.group!==b.collides.group)&&a.collides.sprite&&b.collidable&&a.collidable&&a.collidesWithSprite(b)},b.updateCollisionY=function(a,b,c,d,e){a.collidesWithSprite(b)&&(a.move.y>0&&(a.collision.sprite.down=!0,b.collision.sprite.up=!0),a.move.y<0&&(a.collision.sprite.up=!0,b.collision.sprite.down=!0),a.collision.sprite.down&&e.gravity.y>0&&(a.speed.gravity.y=0),a.collision.sprite.up&&e.gravity.y<0&&(a.speed.gravity.y=0),a.collision.sprite.id=d,b.collision.sprite.id=c,a.collision.sprite.target=b,b.collision.sprite.target=a,a.collides.sprite&&b.collides.sprite&&(a.move.y=0,a.speed.y=0,a.speed.t.y=0))},b.updateCollisionX=function(a,b,c,d,e){a.collidesWithSprite(b)&&(a.move.x>0&&(a.collision.sprite.right=!0,b.collision.sprite.left=!0),a.move.x<0&&(a.collision.sprite.left=!0,b.collision.sprite.right=!0),a.collision.sprite.left&&e.gravity.x<0&&(a.speed.gravity.x=0),a.collision.sprite.right&&e.gravity.x>0&&(a.speed.gravity.x=0),a.collision.sprite.id=d,b.collision.sprite.id=c,a.collision.sprite.target=b,b.collision.sprite.target=a,a.collides.sprite&&b.collides.sprite&&(a.move.x=0,a.speed.x=0,a.speed.t.x=0))},function(a){var c,d,e,f,g,h,i,j,k,l=a.scene.sprites,m=a.physics;for(c=0;c<l.length;c++)for(j=l[c],d=0;d<l.length;d++)if(k=l[d],c!==d){if(h=k.move.x,i=k.move.y,d>c&&(k.move.x=0,k.move.y=0),b.spritesCollide(j,k))for(e=0;2>=e;)(0!==j.move.x||0!==j.move.y)&&((0===e||2===e)&&(f=j.move.x,2!==e&&(j.move.x=0),b.updateCollisionY(j,k,c,d,m),j.move.x=f),(1===e||2===e)&&(g=j.move.y,2!==e&&(j.move.y=0),b.updateCollisionX(j,k,c,d,m),j.move.y=g)),e++;k.move.x=h,k.move.y=i}}}),Molecule.module("Molecule.Text",function(a){function b(a,b){this.game=b,this.title="",this.position=a.position||{x:0,y:0},this.align="left",this.font="Arial 16px",this.color="#FFFFFF",this.baseline="top",this.alpha=1,this.visible=!0,this.stroke=null,this.lineWidth=1,c.mergeSafely(a,this,["game"])}var c=a("Molecule.utils");return b.prototype.draw=function(){this.game.context.save(),null!==this.font&&(this.game.context.font=this.font),this.game.context.globalAlpha=this.alpha,this.game.context.textAlign=this.align,this.game.context.textBaseline=this.baseline,this.game.context.fillStyle=this.color,this.game.context.fillText(this.title,this.position.x,this.position.y),this.stroke&&(this.game.context.lineWidth=this.lineWidth,this.game.context.strokeStyle=this.stroke,this.game.context.strokeText(this.title,this.position.x,this.position.y)),this.game.context.restore()},b.prototype.measure=function(){return this.game.context.measureText(this.title).width},b.prototype.clone=function(){var a=c.deepClone(this,{},["title","position","align","font","color","baseline","alpha","visible","stroke","lineWidth"]),d=new b(a,this.game);return d},b}),Molecule.module("Molecule.Tile",function(){function a(a){this.game=a}return a.prototype.get=function(a,b,c){var d=this.game.map.getTileData(a,b,c);return d},a.prototype.set=function(a,b,c,d,e){this.game.map.setTile(a,b,c,d,e)},a.prototype.clear=function(a,b,c){var d=this.game.map.clearTile(a,b,c);return d},a}),Molecule.module("Molecule.utils",function(a,b){return b.createMethodClosure=function(a,b,c){return a[b].bind(c)},b.matchByObject=function(a,b,c){return function(d){c(d,b)&&a.push(d)}},b.matchByFunction=function(a,b){return function(c){"undefined"!=typeof b._MoleculeType&&b._MoleculeType!==c._MoleculeType||!b(c)||a.push(c)}},{deepClone:function(a,b,c){for(var d in a)a.hasOwnProperty(d)&&(!c||c&&c.indexOf(d)>=0)&&(b[d]=a[d]instanceof Array?a[d].slice(0):"object"==typeof a[d]&&null!==a[d]?this.deepClone(a[d],{}):a[d]);return b},mergeSafely:function(a,b,c){c=c||[];for(var d in a)if(a.hasOwnProperty(d)&&-1===c.indexOf(d))b[d]=a[d];else if(c.indexOf(d)>=0)throw new Error("You can not set or change the property "+d)},bindMethods:function(a,c){for(var d in a)a.hasOwnProperty(d)&&"function"==typeof a[d]&&(a[d]=b.createMethodClosure(a,d,c))},isMolecule:function(a){return a?this.isObject(a)&&"init"in a&&"update"in a:!1},isSprite:function(b){var c=a("Molecule.Sprite");return b instanceof c},isAudio:function(b){var c=a("Molecule.MAudio");return b instanceof c},isText:function(b){var c=a("Molecule.Text");return b instanceof c},isTilemap:function(b){var c=a("Molecule.Map");return b instanceof c},isObject:function(a){return a?"object"==typeof a&&!(a instanceof Array)&&null!==a:!1},isString:function(a){return"string"==typeof a},find:function(a){var c=[];return a.forEach("function"==typeof arguments[1]?b.matchByFunction(c,arguments[1]):b.matchByObject(c,arguments[1],this.containsProps)),c},containsProps:function(a,b){var c,d=!0;for(c in b)b.hasOwnProperty(c)&&a[c]!==b[c]&&(d=!1);return d}}}),Molecule.module("Molecule.WebAudioFile",function(a){function b(a){window.AudioContext=window.AudioContext||window.webkitAudioContext,this.context=null,void 0!==window.AudioContext&&(this.context=new AudioContext),this.game=a,this.name=[],this.data=[],this.id=[],this.counter=0}var c=a("Molecule.MWebAudio");return b.prototype.load=function(a,b){var d=this,e=new XMLHttpRequest,f=new c;return f.id=a,f.context=this.context,this.getAudioDataByName(b)?d.game.sounds[a].buffer=this.getAudioDataByName(b):(e.open("GET",b,!0),e.responseType="arraybuffer",e.onload=function(){f.context.decodeAudioData(e.response,function(c){d.name.push(b),d.id.push(a),d.data.push(c),d.game.sounds[a].buffer=c})},e.send(),this.counter++),this.game.sounds[a]=f,f},b.prototype.isLoaded=function(){return this.counter===this.data.length},b.prototype.getAudioDataByName=function(a){return this.data[this.name.indexOf(a)]},b});