text: /*! Quintus - v0.2.0 - 2015-06-04
   *  http://html5quintus.com
   *  Copyright (c) 2015 Pascal Rettig; Licensed MIT, GPLv2 */
  var quintusCore=function(a,b){"use strict";var c=a[b]=function(b){var d=function(a,b,c){return d.select(a,b,c)};d.select=function(){},d.include=function(a){return d._each(d._normalizeArg(a),function(a){var b=c[a]||a;if(!d._isFunction(b))throw"Invalid Module:"+a;b(d)}),d},d._normalizeArg=function(a){return d._isString(a)&&(a=a.replace(/\s+/g,"").split(",")),d._isArray(a)||(a=[a]),a},d._extend=function(a,b){if(!b)return a;for(var c in b)a[c]=b[c];return a},d._clone=function(a){return d._extend({},a)},d._defaults=function(a,b){if(!b)return a;for(var c in b)void 0===a[c]&&(a[c]=b[c]);return a},d._has=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},d._isString=function(a){return"string"==typeof a},d._isNumber=function(a){return"[object Number]"===Object.prototype.toString.call(a)},d._isFunction=function(a){return"[object Function]"===Object.prototype.toString.call(a)},d._isObject=function(a){return"[object Object]"===Object.prototype.toString.call(a)},d._isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)},d._isUndefined=function(a){return void 0===a},d._popProperty=function(a,b){var c=a[b];return delete a[b],c},d._each=function(a,b,c){if(null!=a)if(a.forEach)a.forEach(b,c);else if(a.length===+a.length)for(var d=0,e=a.length;e>d;d++)b.call(c,a[d],d,a);else for(var f in a)b.call(c,a[f],f,a)},d._invoke=function(a,b,c,d){if(null!==a)for(var e=0,f=a.length;f>e;e++)a[e][b](c,d)},d._detect=function(a,b,c,d,e){var f;if(null!==a){if(a.length===+a.length){for(var g=0,h=a.length;h>g;g++)if(f=b.call(c,a[g],g,d,e))return f;return!1}for(var i in a)if(f=b.call(c,a[i],i,d,e))return f;return!1}},d._map=function(a,b,c){var e=[];return null===a?e:a.map?a.map(b,c):(d._each(a,function(a,d,f){e[e.length]=b.call(c,a,d,f)}),a.length===+a.length&&(e.length=a.length),e)},d._uniq=function(a){a=a.slice().sort();for(var b=[],c=null,d=0;d<a.length;d++)void 0!==a[d]&&c!==a[d]&&b.push(a[d]),c=a[d];return b},d._shuffle=function(a){var b,c=[];return d._each(a,function(a,d,e){b=Math.floor(Math.random()*(d+1)),c[d]=c[b],c[b]=a}),c},d._keys=Object.keys||function(a){if(d._isObject(a))throw new TypeError("Invalid object");var b=[];for(var c in a)d._has(a,c)&&(b[b.length]=c);return b},d._range=function(a,b,c){c=c||1;for(var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=new Array(d);d>e;)f[e++]=a,a+=c;return f};var e=0;return d._uniqueId=function(){return e++},d.options={imagePath:"images/",audioPath:"audio/",dataPath:"data/",audioSupported:["mp3","ogg"],sound:!0,frameTimeLimit:100,autoFocus:!0},b&&d._extend(d.options,b),d.scheduleFrame=function(b){return a.requestAnimationFrame(b)},d.cancelFrame=function(b){a.cancelAnimationFrame(b)},d.gameLoop=function(a){return d.lastGameLoopFrame=(new Date).getTime(),d.loop=!0,d._loopFrame=0,d.gameLoopCallbackWrapper=function(){var b=(new Date).getTime();d._loopFrame++,d.loop=d.scheduleFrame(d.gameLoopCallbackWrapper);var c=b-d.lastGameLoopFrame;c>d.options.frameTimeLimit&&(c=d.options.frameTimeLimit),a.apply(d,[c/1e3]),d.lastGameLoopFrame=b},d.scheduleFrame(d.gameLoopCallbackWrapper),d},d.pauseGame=function(){d.loop&&d.cancelFrame(d.loop),d.loop=null},d.unpauseGame=function(){d.loop||(d.lastGameLoopFrame=(new Date).getTime(),d.loop=d.scheduleFrame(d.gameLoopCallbackWrapper))},function(){var a=!1,b=/xyz/.test(function(){})?/\b_super\b/:/.*/;d.Class=function(){},d.Class.prototype.isA=function(a){return this.className===a},d.Class.extend=function(c,e,f){function g(a,b){return function(){var c=this._super;this._super=i[a];var d=b.apply(this,arguments);return this._super=c,d}}function h(){!a&&this.init&&this.init.apply(this,arguments)}d._isString(c)||(f=e,e=c,c=null);var i=this.prototype,j=this;a=!0;var k=new j;a=!1;for(var l in e)k[l]="function"==typeof e[l]&&"function"==typeof i[l]&&b.test(e[l])?g(l,e[l]):e[l];return h.prototype=k,h.prototype.constructor=h,h.extend=d.Class.extend,f&&d._extend(h,f),c&&(d[c]=h,h.prototype.className=c,h.className=c),h}}(),d.Class.extend("Evented",{on:function(a,b,c){if(d._isArray(a)||-1!==a.indexOf(",")){a=d._normalizeArg(a);for(var e=0;e<a.length;e++)this.on(a[e],b,c)}else c||(c=b,b=null),c||(c=a),d._isString(c)&&(c=(b||this)[c]),this.listeners=this.listeners||{},this.listeners[a]=this.listeners[a]||[],this.listeners[a].push([b||this,c]),b&&(b.binds||(b.binds=[]),b.binds.push([this,a,c]))},trigger:function(a,b){if(this.listeners&&this.listeners[a])for(var c=0,d=this.listeners[a].length;d>c;c++){var e=this.listeners[a][c];e[1].call(e[0],b)}},off:function(a,b,c){if(b){d._isString(c)&&b[c]&&(c=b[c]);var e=this.listeners&&this.listeners[a];if(e)for(var f=e.length-1;f>=0;f--)e[f][0]===b&&(c&&c!==e[f][1]||this.listeners[a].splice(f,1))}else this.listeners[a]&&delete this.listeners[a]},debind:function(){if(this.binds)for(var a=0,b=this.binds.length;b>a;a++){var c=this.binds[a],d=c[0],e=c[1];d.off(e,this)}}}),d.components={},d.Evented.extend("Component",{init:function(a){this.entity=a,this.extend&&d._extend(a,this.extend),a[this.name]=this,a.activeComponents.push(this.componentName),a.stage&&a.stage.addToList&&a.stage.addToList(this.componentName,a),this.added&&this.added()},destroy:function(){if(this.extend)for(var a=d._keys(this.extend),b=0,c=a.length;c>b;b++)delete this.entity[a[b]];delete this.entity[this.name];var e=this.entity.activeComponents.indexOf(this.componentName);-1!==e&&(this.entity.activeComponents.splice(e,1),this.entity.stage&&this.entity.stage.addToList&&this.entity.stage.addToLists(this.componentName,this.entity)),this.debind(),this.destroyed&&this.destroyed()}}),d.Evented.extend("GameObject",{has:function(a){return this[a]?!0:!1},add:function(a){a=d._normalizeArg(a),this.activeComponents||(this.activeComponents=[]);for(var b=0,c=a.length;c>b;b++){var e=a[b],f=d.components[e];if(!this.has(e)&&f){var g=new f(this);this.trigger("addComponent",g)}}return this},del:function(a){a=d._normalizeArg(a);for(var b=0,c=a.length;c>b;b++){var e=a[b];e&&this.has(e)&&(this.trigger("delComponent",this[e]),this[e].destroy())}return this},destroy:function(){this.isDestroyed||(this.trigger("destroyed"),this.debind(),this.stage&&this.stage.remove&&this.stage.remove(this),this.isDestroyed=!0,this.destroyed&&this.destroyed())}}),d.component=function(a,b){return b?(b.name=a,b.componentName="."+a,d.components[a]=d.Component.extend(a+"Component",b)):d.components[a]},d.GameObject.extend("GameState",{init:function(a){this.p=d._extend({},a),this.listeners={}},reset:function(a){this.init(a),this.trigger("reset")},_triggerProperty:function(a,b){this.p[b]!==a&&(this.p[b]=a,this.trigger("change."+b,a))},set:function(a,b){d._isObject(a)?d._each(a,this._triggerProperty,this):this._triggerProperty(b,a),this.trigger("change")},inc:function(a,b){this.set(a,this.get(a)+b)},dec:function(a,b){this.set(a,this.get(a)-b)},get:function(a){return this.p[a]}}),d.state=new d.GameState,d.reset=function(){d.state.reset()},d.touchDevice="undefined"==typeof exports&&"ontouchstart"in document,d.setup=function(b,c){d._isObject(b)&&(c=b,b=null),c=c||{},b=b||"quintus",d._isString(b)?d.el=document.getElementById(b):d.el=b,d.el||(d.el=document.createElement("canvas"),d.el.width=c.width||320,d.el.height=c.height||420,d.el.id=b,document.body.appendChild(d.el));var e=parseInt(d.el.width,10),f=parseInt(d.el.height,10),g=c.maxWidth||5e3,h=c.maxHeight||5e3,i=c.resampleWidth,j=c.resampleHeight,k=c.upsampleWidth,l=c.upsampleHeight;c.maximize===!0||d.touchDevice&&"touch"===c.maximize?(document.body.style.padding=0,document.body.style.margin=0,e=c.width||Math.min(a.innerWidth,g)-(c.pagescroll?17:0),f=c.height||Math.min(a.innerHeight-5,h),d.touchDevice&&(d.el.style.height=2*f+"px",a.scrollTo(0,1),e=Math.min(a.innerWidth,g),f=Math.min(a.innerHeight,h))):d.touchDevice&&a.scrollTo(0,1),k&&k>=e||l&&l>=f?(d.el.style.height=f+"px",d.el.style.width=e+"px",d.el.width=2*e,d.el.height=2*f):(i&&e>i||j&&f>j)&&d.touchDevice?(d.el.style.height=f+"px",d.el.style.width=e+"px",d.el.width=e/2,d.el.height=f/2):(d.el.style.height=f+"px",d.el.style.width=e+"px",d.el.width=e,d.el.height=f);var m=d.el.parentNode;if(m&&!d.wrapper&&(d.wrapper=document.createElement("div"),d.wrapper.id=d.el.id+"_container",d.wrapper.style.width=e+"px",d.wrapper.style.margin="0 auto",d.wrapper.style.position="relative",m.insertBefore(d.wrapper,d.el),d.wrapper.appendChild(d.el)),d.el.style.position="relative",d.ctx=d.el.getContext&&d.el.getContext("2d"),d.width=parseInt(d.el.width,10),d.height=parseInt(d.el.height,10),d.cssWidth=e,d.cssHeight=f,c.scaleToFit){var n=1,o=a.innerWidth*n,p=a.innerHeight*n,q=o/p,r=d.el.width/d.el.height,s=q>r?p/d.el.height:o/d.el.width,t=d.el.width*s,u=d.el.height*s;if(d.el.style.width=t+"px",d.el.style.height=u+"px",d.el.parentNode&&(d.el.parentNode.style.width=t+"px",d.el.parentNode.style.height=u+"px"),d.cssWidth=parseInt(t,10),d.cssHeight=parseInt(u,10),r>q){var v=(p-u)/2;d.el.style.top=v+"px"}}return a.addEventListener("orientationchange",function(){setTimeout(function(){a.scrollTo(0,1)},0)}),d},d.clear=function(){d.clearColor?(d.ctx.globalAlpha=1,d.ctx.fillStyle=d.clearColor,d.ctx.fillRect(0,0,d.width,d.height)):d.ctx.clearRect(0,0,d.width,d.height)},d.setImageSmoothing=function(a){d.ctx.mozImageSmoothingEnabled=a,d.ctx.webkitImageSmoothingEnabled=a,d.ctx.msImageSmoothingEnabled=a,d.ctx.imageSmoothingEnabled=a},d.imageData=function(a){var b=document.createElement("canvas");b.width=a.width,b.height=a.height;var c=b.getContext("2d");return c.drawImage(a,0,0),c.getImageData(0,0,a.width,a.height)},d.assetTypes={png:"Image",jpg:"Image",gif:"Image",jpeg:"Image",ogg:"Audio",wav:"Audio",m4a:"Audio",mp3:"Audio"},d._fileExtension=function(a){var b=a.split("."),c=b[b.length-1].toLowerCase();return c},d.assetType=function(a){var b=d._fileExtension(a),c=d.assetTypes[b];return"Audio"===c&&d.audio&&"WebAudio"===d.audio.type&&(c="WebAudio"),c||"Other"},d.assetUrl=function(a,b){var c="";return d.options.development&&(c=(/\?/.test(b)?"&":"?")+"_t="+(new Date).getTime()),/^https?:\/\//.test(b)||"/"===b[0]?b+c:a+b+c},d.loadAssetImage=function(a,b,c,e){var f=new Image;f.onload=function(){c(a,f)},f.onerror=e,f.src=d.assetUrl(d.options.imagePath,b)},d.audioMimeTypes={mp3:"audio/mpeg",ogg:'audio/ogg; codecs="vorbis"',m4a:"audio/m4a",wav:"audio/wav"},d._audioAssetExtension=function(){if(d._audioAssetPreferredExtension)return d._audioAssetPreferredExtension;var a=new Audio;return d._audioAssetPreferredExtension=d._detect(d.options.audioSupported,function(b){return a.canPlayType(d.audioMimeTypes[b])?b:null})},d.loadAssetAudio=function(a,b,c,e){if(!document.createElement("audio").play||!d.options.sound)return void c(a,null);var f=d._removeExtension(b),g=d._audioAssetExtension(),h=new Audio;return g?(h.addEventListener("error",e),d.touchDevice||h.addEventListener("canplaythrough",function(){c(a,h)}),h.src=d.assetUrl(d.options.audioPath,f+"."+g),h.load(),void(d.touchDevice&&c(a,h))):void c(a,null)},d.loadAssetWebAudio=function(a,b,c,e){var f=new XMLHttpRequest,g=d._removeExtension(b),h=d._audioAssetExtension();f.open("GET",d.assetUrl(d.options.audioPath,g+"."+h),!0),f.responseType="arraybuffer",f.onload=function(){f.response;d.audioContext.decodeAudioData(f.response,function(b){c(a,b)},e)},f.send()},d.loadAssetOther=function(a,b,c,e){var f=new XMLHttpRequest,g=b.split("."),h=g[g.length-1].toLowerCase();return"file://"===document.location.origin||"null"===document.location.origin?(d.fileURLAlert||(d.fileURLAlert=!0,alert("Quintus Error: Loading assets is not supported from file:// urls - please run from a local web-server and try again")),e()):(f.onreadystatechange=function(){4===f.readyState&&(200===f.status?"json"===h?c(a,JSON.parse(f.responseText)):c(a,f.responseText):e())},f.open("GET",d.assetUrl(d.options.dataPath,b),!0),void f.send(null))},d._removeExtension=function(a){return a.replace(/\.(\w{3,4})$/,"")},d.assets={},d.asset=function(a){return d.assets[a]},d.load=function(a,b,c){var e={};c||(c={});var f=c.progressCallback,g=!1,h=function(a){g=!0,(c.errorCallback||function(a){throw"Error Loading: "+a})(a)};d._isString(a)&&(a=d._normalizeArg(a)),d._isArray(a)?d._each(a,function(a){d._isObject(a)?d._extend(e,a):e[a]=a}):e=a;var i=d._keys(e).length,j=i,k=function(a,c,e){g||((!d.assets[a]||e)&&(d.assets[a]=c,j--,f&&f(i-j,i)),0===j&&b&&b.apply(d))};d._each(e,function(a,b){var c=d.assetType(a);d.assets[b]?k(b,d.assets[b],!0):d["loadAsset"+c](b,a,k,function(){h(a)})})},d.preloads=[],d.preload=function(a,b){d._isFunction(a)?(d.load(d._uniq(d.preloads),a,b),d.preloads=[]):d.preloads=d.preloads.concat(a)},d.matrices2d=[],d.matrix2d=function(){return d.matrices2d.length>0?d.matrices2d.pop().identity():new d.Matrix2D},d.Matrix2D=d.Class.extend({init:function(a){a?(this.m=[],this.clone(a)):this.m=[1,0,0,0,1,0]},identity:function(){var a=this.m;return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,this},clone:function(a){var b=this.m,c=a.m;return b[0]=c[0],b[1]=c[1],b[2]=c[2],b[3]=c[3],b[4]=c[4],b[5]=c[5],this},multiply:function(a){var b=this.m,c=a.m,d=b[0]*c[0]+b[1]*c[3],e=b[0]*c[1]+b[1]*c[4],f=b[0]*c[2]+b[1]*c[5]+b[2],g=b[3]*c[0]+b[4]*c[3],h=b[3]*c[1]+b[4]*c[4],i=b[3]*c[2]+b[4]*c[5]+b[5];return b[0]=d,b[1]=e,b[2]=f,b[3]=g,b[4]=h,b[5]=i,this},rotate:function(a){if(0===a)return this;var b=Math.cos(a),c=Math.sin(a),d=this.m,e=d[0]*b+d[1]*c,f=d[0]*-c+d[1]*b,g=d[3]*b+d[4]*c,h=d[3]*-c+d[4]*b;return d[0]=e,d[1]=f,d[3]=g,d[4]=h,this},rotateDeg:function(a){return 0===a?this:this.rotate(Math.PI*a/180)},scale:function(a,b){var c=this.m;return void 0===b&&(b=a),c[0]*=a,c[1]*=b,c[3]*=a,c[4]*=b,this},translate:function(a,b){var c=this.m;return c[2]+=c[0]*a+c[1]*b,c[5]+=c[3]*a+c[4]*b,this},transform:function(a,b){return[a*this.m[0]+b*this.m[1]+this.m[2],a*this.m[3]+b*this.m[4]+this.m[5]]},transformPt:function(a){var b=a.x,c=a.y;return a.x=b*this.m[0]+c*this.m[1]+this.m[2],a.y=b*this.m[3]+c*this.m[4]+this.m[5],a},transformArr:function(a,b){var c=a[0],d=a[1];return b[0]=c*this.m[0]+d*this.m[1]+this.m[2],b[1]=c*this.m[3]+d*this.m[4]+this.m[5],b},transformX:function(a,b){return a*this.m[0]+b*this.m[1]+this.m[2]},transformY:function(a,b){return a*this.m[3]+b*this.m[4]+this.m[5]},release:function(){return d.matrices2d.push(this),null},setContextTransform:function(a){var b=this.m;a.transform(b[0],b[3],b[1],b[4],b[2],b[5])}}),d};return function(){for(var b=0,c=["ms","moz","webkit","o"],d=0;d<c.length&&!a.requestAnimationFrame;++d)a.requestAnimationFrame=a[c[d]+"RequestAnimationFrame"],a.cancelAnimationFrame=a[c[d]+"CancelAnimationFrame"]||a[c[d]+"CancelRequestAnimationFrame"];a.requestAnimationFrame||(a.requestAnimationFrame=function(a,c){var d=(new Date).getTime(),e=Math.max(0,16-(d-b)),f=setTimeout(function(){a(d+e)},e);return b=d+e,f}),a.cancelAnimationFrame||(a.cancelAnimationFrame=function(a){clearTimeout(a)})}(),c};if("undefined"==typeof exports)quintusCore(this,"Quintus");else var Quintus=quintusCore(module,"exports");var quintus2D=function(a){"use strict";a["2D"]=function(a){a.component("viewport",{added:function(){this.entity.on("prerender",this,"prerender"),this.entity.on("render",this,"postrender"),this.x=0,this.y=0,this.offsetX=0,this.offsetY=0,this.centerX=a.width/2,this.centerY=a.height/2,this.scale=1},extend:{follow:function(b,c,d){this.off("poststep",this.viewport,"follow"),this.viewport.directions=c||{x:!0,y:!0},this.viewport.following=b,a._isUndefined(d)&&void 0!==this.lists.TileLayer?this.viewport.boundingBox=a._detect(this.lists.TileLayer,function(a){return a.p.boundingBox?{minX:0,maxX:a.p.w,minY:0,maxY:a.p.h}:null}):this.viewport.boundingBox=d,this.on("poststep",this.viewport,"follow"),this.viewport.follow(!0)},unfollow:function(){this.off("poststep",this.viewport,"follow")},centerOn:function(a,b){this.viewport.centerOn(a,b)},moveTo:function(a,b){return this.viewport.moveTo(a,b)}},follow:function(b){var c=a._isFunction(this.directions.x)?this.directions.x(this.following):this.directions.x,d=a._isFunction(this.directions.y)?this.directions.y(this.following):this.directions.y;this[b===!0?"centerOn":"softCenterOn"](c?this.following.p.x-this.offsetX:void 0,d?this.following.p.y-this.offsetY:void 0)},offset:function(a,b){this.offsetX=a,this.offsetY=b},softCenterOn:function(b,c){if(void 0!==b){var d=(b-a.width/2/this.scale-this.x)/3;this.boundingBox?this.x+d<this.boundingBox.minX?this.x=this.boundingBox.minX/this.scale:this.x+d>(this.boundingBox.maxX-a.width)/this.scale?this.x=Math.max(this.boundingBox.maxX-a.width,this.boundingBox.minX)/this.scale:this.x+=d:this.x+=d}if(void 0!==c){var e=(c-a.height/2/this.scale-this.y)/3;this.boundingBox?this.y+e<this.boundingBox.minY?this.y=this.boundingBox.minY/this.scale:this.y+e>(this.boundingBox.maxY-a.height)/this.scale?this.y=Math.max(this.boundingBox.maxY-a.height,this.boundingBox.minY)/this.scale:this.y+=e:this.y+=e}},centerOn:function(b,c){void 0!==b&&(this.x=b-a.width/2/this.scale),void 0!==c&&(this.y=c-a.height/2/this.scale)},moveTo:function(a,b){return void 0!==a&&(this.x=a),void 0!==b&&(this.y=b),this.entity},prerender:function(){this.centerX=this.x+a.width/2/this.scale,this.centerY=this.y+a.height/2/this.scale,a.ctx.save(),a.ctx.translate(Math.floor(a.width/2),Math.floor(a.height/2)),a.ctx.scale(this.scale,this.scale),a.ctx.translate(-Math.floor(this.centerX),-Math.floor(this.centerY))},postrender:function(){a.ctx.restore()}}),a.Sprite.extend("TileLayer",{init:function(a){this._super(a,{tileW:32,tileH:32,blockTileW:10,blockTileH:10,type:1,renderAlways:!0}),this.p.dataAsset&&this.load(this.p.dataAsset),this.setDimensions(),this.blocks=[],this.p.blockW=this.p.tileW*this.p.blockTileW,this.p.blockH=this.p.tileH*this.p.blockTileH,this.colBounds={},this.directions=["top","left","right","bottom"],this.tileProperties={},this.collisionObject={p:{w:this.p.tileW,h:this.p.tileH,cx:this.p.tileW/2,cy:this.p.tileH/2}},this.tileCollisionObjects={},this.collisionNormal={separate:[]},this._generateCollisionObjects()},_generateCollisionObjects:function(){function b(a){return[a[0]*c.p.tileW-c.p.tileW/2,a[1]*c.p.tileH-c.p.tileH/2]}var c=this;if(this.sheet()&&this.sheet().frameProperties){var d=this.sheet().frameProperties;for(var e in d){var f=this.tileCollisionObjects[e]={p:a._clone(this.collisionObject.p)};a._extend(f.p,d[e]),f.p.points&&(f.p.points=a._map(f.p.points,b)),this.tileCollisionObjects[e]=f}}},load:function(b){var c,d=b.split("."),e=d[d.length-1].toLowerCase();if("json"!==e)throw"file type not supported";c=a._isString(b)?a.asset(b):b,this.p.tiles=c},setDimensions:function(){var a=this.p.tiles;a&&(this.p.rows=a.length,this.p.cols=a[0].length,this.p.w=this.p.cols*this.p.tileW,this.p.h=this.p.rows*this.p.tileH)},getTile:function(a,b){return this.p.tiles[b]&&this.p.tiles[b][a]},getTileProperty:function(a,b){return void 0!==this.tileProperties[a]?this.tileProperties[a][b]:void 0},getTileProperties:function(a){return void 0!==this.tileProperties[a]?this.tileProperties[a]:{}},getTilePropertyAt:function(a,b,c){return this.getTileProperty(this.getTile(a,b),c)},getTilePropertiesAt:function(a,b){return this.getTileProperties(this.getTile(a,b))},tileHasProperty:function(a,b){return void 0!==this.getTileProperty(a,b)},setTile:function(a,b,c){var d=this.p,e=Math.floor(a/d.blockTileW),f=Math.floor(b/d.blockTileH);a>=0&&a<this.p.cols&&b>=0&&b<this.p.rows&&(this.p.tiles[b][a]=c,this.blocks[f]&&(this.blocks[f][e]=null))},tilePresent:function(a,b){return this.p.tiles[b]&&this.collidableTile(this.p.tiles[b][a])},drawableTile:function(a){return a>0},collidableTile:function(a){return a>0},getCollisionObject:function(a,b){var c,d=this.p,e=this.getTile(a,b);return c=void 0!==this.tileCollisionObjects[e]?this.tileCollisionObjects[e]:this.collisionObject,c.p.x=a*d.tileW+d.x+d.tileW/2,c.p.y=b*d.tileH+d.y+d.tileH/2,c},collide:function(b){var c,d,e=this.p,f=b.c||b.p,g=Math.floor((f.x-f.cx-e.x)/e.tileW),h=Math.floor((f.y-f.cy-e.y)/e.tileH),i=Math.ceil((f.x-f.cx+f.w-e.x)/e.tileW),j=Math.ceil((f.y-f.cy+f.h-e.y)/e.tileH),k=this.collisionNormal;k.collided=!1;for(var l=h;j>=l;l++)for(var m=g;i>=m;m++)this.tilePresent(m,l)&&(d=this.getCollisionObject(m,l),c=a.collision(b,d),c&&c.magnitude>0&&(d.p.sensor?(d.tile=this.getTile(m,l),b.trigger&&b.trigger("sensor.tile",d)):(!k.collided||k.magnitude<c.magnitude)&&(k.collided=!0,k.separate[0]=c.separate[0],k.separate[1]=c.separate[1],k.magnitude=c.magnitude,k.distance=c.distance,k.normalX=c.normalX,k.normalY=c.normalY,k.tileX=m,k.tileY=l,k.tile=this.getTile(m,l),void 0!==b.p.collisions&&b.p.collisions.push(k))));return k.collided?k:!1},prerenderBlock:function(a,b){var c=this.p,d=c.tiles,e=this.sheet(),f=a*c.blockTileW,g=b*c.blockTileH;if(!(0>f||f>=this.p.cols||0>g||g>=this.p.rows)){var h=document.createElement("canvas"),i=h.getContext("2d");h.width=c.blockW,h.height=c.blockH,this.blocks[b]=this.blocks[b]||{},this.blocks[b][a]=h;for(var j=0;j<c.blockTileH;j++)if(d[j+g])for(var k=0;k<c.blockTileW;k++)this.drawableTile(d[j+g][k+f])&&e.draw(i,k*c.tileW,j*c.tileH,d[j+g][k+f])}},drawBlock:function(a,b,c){var d=this.p,e=Math.floor(b*d.blockW+d.x),f=Math.floor(c*d.blockH+d.y);this.blocks[c]&&this.blocks[c][b]||this.prerenderBlock(b,c),this.blocks[c]&&this.blocks[c][b]&&a.drawImage(this.blocks[c][b],e,f)},draw:function(b){for(var c=this.p,d=this.stage.viewport,e=d?d.scale:1,f=d?d.x:0,g=d?d.y:0,h=a.width/e,i=a.height/e,j=Math.floor((f-c.x)/c.blockW),k=Math.floor((g-c.y)/c.blockH),l=Math.floor((f+h-c.x)/c.blockW),m=Math.floor((g+i-c.y)/c.blockH),n=k;m>=n;n++)for(var o=j;l>=o;o++)this.drawBlock(b,o,n)}}),a.gravityY=9.8*100,a.gravityX=0,a.component("2d",{added:function(){var b=this.entity;a._defaults(b.p,{vx:0,vy:0,ax:0,ay:0,gravity:1,collisionMask:a.SPRITE_DEFAULT}),b.on("step",this,"step"),b.on("hit",this,"collision")},collision:function(a,b){var c=this.entity,d=c.p;if(a.obj.p&&a.obj.p.sensor)return void a.obj.trigger("sensor",c);a.impact=0;var e=Math.abs(d.vx),f=Math.abs(d.vy);d.x-=a.separate[0],d.y-=a.separate[1],a.normalY<-.3&&(!d.skipCollide&&d.vy>0&&(d.vy=0),a.impact=f,c.trigger("bump.bottom",a)),a.normalY>.3&&(!d.skipCollide&&d.vy<0&&(d.vy=0),a.impact=f,c.trigger("bump.top",a)),a.normalX<-.3&&(!d.skipCollide&&d.vx>0&&(d.vx=0),a.impact=e,c.trigger("bump.right",a)),a.normalX>.3&&(!d.skipCollide&&d.vx<0&&(d.vx=0),a.impact=e,c.trigger("bump.left",a))},step:function(b){for(var c=this.entity.p,d=b;d>0;)b=Math.min(1/30,d),c.vx+=c.ax*b+(void 0===c.gravityX?a.gravityX:c.gravityX)*b*c.gravity,c.vy+=c.ay*b+(void 0===c.gravityY?a.gravityY:c.gravityY)*b*c.gravity,c.x+=c.vx*b,c.y+=c.vy*b,this.entity.stage.collide(this.entity),d-=b}}),a.component("aiBounce",{added:function(){this.entity.on("bump.right",this,"goLeft"),this.entity.on("bump.left",this,"goRight")},goLeft:function(a){this.entity.p.vx=-a.impact,"right"===this.entity.p.defaultDirection?this.entity.p.flip="x":this.entity.p.flip=!1},goRight:function(a){this.entity.p.vx=a.impact,"left"===this.entity.p.defaultDirection?this.entity.p.flip="x":this.entity.p.flip=!1}})}};"undefined"==typeof Quintus?module.exports=quintus2D:quintus2D(Quintus);var quintusAnim=function(a){"use strict";a.Anim=function(a){a._animations={},a.animations=function(b,c){a._animations[b]||(a._animations[b]={}),a._extend(a._animations[b],c)},a.animation=function(b,c){return a._animations[b]&&a._animations[b][c]},a.component("animation",{added:function(){var a=this.entity.p;a.animation=null,a.animationPriority=-1,a.animationFrame=0,a.animationTime=0,this.entity.on("step",this,"step")},extend:{play:function(a,b,c){this.animation.play(a,b,c)}},step:function(b){var c=this.entity,d=c.p;if(d.animation){var e=a.animation(d.sprite,d.animation),f=e.rate||d.rate,g=0;if(d.animationTime+=b,d.animationChanged?d.animationChanged=!1:(d.animationTime+=b,d.animationTime>f&&(g=Math.floor(d.animationTime/f),d.animationTime-=g*f,d.animationFrame+=g)),g>0){if(d.animationFrame>=e.frames.length){if(e.loop===!1||e.next)return d.animationFrame=e.frames.length-1,c.trigger("animEnd"),c.trigger("animEnd."+d.animation),d.animation=null,d.animationPriority=-1,e.trigger&&c.trigger(e.trigger,e.triggerData),void(e.next&&this.play(e.next,e.nextPriority));c.trigger("animLoop"),c.trigger("animLoop."+d.animation),d.animationFrame=d.animationFrame%e.frames.length}c.trigger("animFrame")}d.sheet=e.sheet||d.sheet,d.frame=e.frames[d.animationFrame],e.hasOwnProperty("flip")&&(d.flip=e.flip)}},play:function(a,b,c){var d=this.entity,e=d.p;b=b||0,a!==e.animation&&b>=e.animationPriority&&(void 0===c&&(c=!0),e.animation=a,c&&(e.animationChanged=!0,e.animationTime=0,e.animationFrame=0),e.animationPriority=b,d.trigger("anim"),d.trigger("anim."+e.animation))}}),a.Sprite.extend("Repeater",{init:function(b){this._super(a._defaults(b,{speedX:1,speedY:1,repeatY:!0,repeatX:!0,renderAlways:!0,type:0})),this.p.repeatW=this.p.repeatW||this.p.w,this.p.repeatH=this.p.repeatH||this.p.h},draw:function(b){var c,d,e,f,g,h=this.p,i=this.asset(),j=this.sheet(),k=this.stage.viewport?this.stage.viewport.scale:1,l=Math.floor(this.stage.viewport?this.stage.viewport.x:0),m=Math.floor(this.stage.viewport?this.stage.viewport.y:0),n=Math.floor(h.x+l*this.p.speedX),o=Math.floor(h.y+m*this.p.speedY);for(h.repeatX?(c=-n%h.repeatW,c>0&&(c-=h.repeatW)):c=h.x-l,h.repeatY?(d=-o%h.repeatH,d>0&&(d-=h.repeatH)):d=h.y-m,e=c,f=a.width/k+h.repeatW,g=a.height/k+h.repeatH;g>d;){for(c=e;f>c&&(j?j.draw(b,c+l,d+m,h.frame):b.drawImage(i,c+l,d+m),c+=h.repeatW,h.repeatX););if(d+=h.repeatH,!h.repeatY)break}}}),a.Tween=a.Class.extend({init:function(b,c,d,e,f){a._isObject(e)&&(f=e,e=a.Easing.Linear),a._isObject(d)&&(f=d,d=1),this.entity=b,this.duration=d||1,this.time=0,this.options=f||{},this.delay=this.options.delay||0,this.easing=e||this.options.easing||a.Easing.Linear,this.startFrame=a._loopFrame+1,this.properties=c,this.start={},this.diff={}},step:function(b){var c;if(this.startFrame>a._loopFrame)return!0;if(this.delay>=b)return this.delay-=b,!0;if(this.delay>0&&(b-=this.delay,this.delay=0),0===this.time){var d=this.entity,e=this.properties;this.p=d instanceof a.Stage?d.viewport:d.p;for(c in e)this.start[c]=this.p[c],a._isUndefined(this.start[c])||(this.diff[c]=e[c]-this.start[c])}this.time+=b;var f=Math.min(1,this.time/this.duration),g=this.easing(f);for(c in this.start)a._isUndefined(this.p[c])||(this.p[c]=this.start[c]+this.diff[c]*g);return f>=1&&this.options.callback&&this.options.callback.apply(this.entity),1>f}}),a.Easing={Linear:function(a){return a},Quadratic:{In:function(a){return a*a},Out:function(a){return a*(2-a)},InOut:function(a){return(a*=2)<1?.5*a*a:-.5*(--a*(a-2)-1)}}},a.component("tween",{added:function(){this._tweens=[],this.entity.on("step",this,"step")},extend:{animate:function(b,c,d,e){return this.tween._tweens.push(new a.Tween(this,b,c,d,e)),this},chain:function(b,c,d,e){a._isObject(d)&&(e=d,d=a.Easing.Linear);var f=this.tween._tweens.length;if(f>0){var g=this.tween._tweens[f-1];e=e||{},e.delay=g.duration-g.time+g.delay}return this.animate(b,c,d,e),this},stop:function(){return this.tween._tweens.length=0,this}},step:function(a){for(var b=0;b<this._tweens.length;b++)this._tweens[b].step(a)||(this._tweens.splice(b,1),b--)}})}};"undefined"==typeof Quintus?module.exports=quintusAnim:quintusAnim(Quintus);var quintusAudio=function(a){"use strict";a.Audio=function(a){a.audio={channels:[],channelMax:a.options.channelMax||10,active:{},play:function(){}},a.hasWebAudio="undefined"!=typeof AudioContext||"undefined"!=typeof webkitAudioContext,a.hasWebAudio&&("undefined"!=typeof AudioContext?a.audioContext=new AudioContext:a.audioContext=new window.webkitAudioContext),a.enableSound=function(){"undefined"!=typeof window&&!!("ontouchstart"in window);return a.hasWebAudio?a.audio.enableWebAudioSound():a.audio.enableHTML5Sound(),a},a.audio.enableWebAudioSound=function(){a.audio.type="WebAudio",a.audio.soundID=0,a.audio.playingSounds={},a.audio.removeSound=function(b){delete a.audio.playingSounds[b]},a.audio.play=function(b,c){var d=(new Date).getTime();if(!(a.audio.active[b]&&a.audio.active[b]>d)){c&&c.debounce?a.audio.active[b]=d+c.debounce:delete a.audio.active[b];var e=a.audio.soundID++,f=a.audioContext.createBufferSource();f.buffer=a.asset(b),f.connect(a.audioContext.destination),c&&c.loop?f.loop=!0:setTimeout(function(){a.audio.removeSound(e)},1e3*f.buffer.duration),f.assetName=b,f.start?f.start(0):f.noteOn(0),a.audio.playingSounds[e]=f}},a.audio.stop=function(b){for(var c in a.audio.playingSounds){var d=a.audio.playingSounds[c];b&&b!==d.assetName||(d.stop?d.stop(0):d.noteOff(0))}}},a.audio.enableHTML5Sound=function(){a.audio.type="HTML5";for(var b=0;b<a.audio.channelMax;b++)a.audio.channels[b]={},a.audio.channels[b].channel=new Audio,a.audio.channels[b].finished=-1;a.audio.play=function(b,c){var d=(new Date).getTime();if(!(a.audio.active[b]&&a.audio.active[b]>d)){c&&c.debounce?a.audio.active[b]=d+c.debounce:delete a.audio.active[b];for(var e=0;e<a.audio.channels.length;e++)if(!a.audio.channels[e].loop&&a.audio.channels[e].finished<d){a.audio.channels[e].channel.src=a.asset(b).src,c&&c.loop?(a.audio.channels[e].loop=!0,a.audio.channels[e].channel.loop=!0):a.audio.channels[e].finished=d+1e3*a.asset(b).duration,a.audio.channels[e].channel.load(),a.audio.channels[e].channel.play();break}}},a.audio.stop=function(b){for(var c=b?a.asset(b).src:null,d=(new Date).getTime(),e=0;e<a.audio.channels.length;e++)c&&a.audio.channels[e].channel.src!==c||!(a.audio.channels[e].loop||a.audio.channels[e].finished>=d)||(a.audio.channels[e].channel.pause(),a.audio.channels[e].loop=!1)}}}};"undefined"==typeof Quintus?module.exports=quintusAudio:quintusAudio(Quintus);var quintusInput=function(a){"use strict";a.Input=function(a){var b=a.KEY_NAMES={LEFT:37,RIGHT:39,UP:38,DOWN:40,ZERO:48,ONE:49,TWO:50,THREE:51,FOUR:52,FIVE:53,SIX:54,SEVEN:55,EIGHT:56,NINE: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,ENTER:13,ESC:27,BACKSPACE:8,TAB:9,SHIFT:16,CTRL:17,ALT:18,SPACE:32,HOME:36,END:35,PGGUP:33,PGDOWN:34},c={LEFT:"left",RIGHT:"right",UP:"up",DOWN:"down",SPACE:"fire",Z:"fire",X:"action",ENTER:"confirm",ESC:"esc",P:"P",S:"S"},d=[["left","<"],["right",">"],[],["action","b"],["fire","a"]],e=["up","right","down","left"];a.inputs={},a.joypad={};var f=!!("ontouchstart"in window);a.canvasToStageX=function(b,c){return b=b/a.cssWidth*a.width,c.viewport&&(b/=c.viewport.scale,b+=c.viewport.x),b},a.canvasToStageY=function(b,c){return b=b/a.cssWidth*a.width,c.viewport&&(b/=c.viewport.scale,b+=c.viewport.y),b},a.InputSystem=a.Evented.extend({keys:{},keypad:{},keyboardEnabled:!1,touchEnabled:!1,joypadEnabled:!1,bindKey:function(c,d){a.input.keys[b[c]||c]=d},enableKeyboard:function(){return this.keyboardEnabled?!1:(a.el.tabIndex=0,a.el.style.outline=0,a.el.addEventListener("keydown",function(b){if(a.input.keys[b.keyCode]){var c=a.input.keys[b.keyCode];a.inputs[c]=!0,a.input.trigger(c),a.input.trigger("keydown",b.keyCode)}b.ctrlKey||b.metaKey||b.preventDefault()},!1),a.el.addEventListener("keyup",function(b){if(a.input.keys[b.keyCode]){var c=a.input.keys[b.keyCode];a.inputs[c]=!1,a.input.trigger(c+"Up"),a.input.trigger("keyup",b.keyCode)}b.preventDefault()},!1),a.options.autoFocus&&a.el.focus(),void(this.keyboardEnabled=!0))},keyboardControls:function(b){b=b||c,a._each(b,function(a,b){this.bindKey(b,a)},a.input),this.enableKeyboard()},_containerOffset:function(){a.input.offsetX=0,a.input.offsetY=0;var b=a.el;do a.input.offsetX+=b.offsetLeft,a.input.offsetY+=b.offsetTop;while(b=b.offsetParent)},touchLocation:function(b){var c,d,e=(a.el,b.offsetX),f=b.offsetY;return(a._isUndefined(e)||a._isUndefined(f))&&(e=b.layerX,f=b.layerY),(a._isUndefined(e)||a._isUndefined(f))&&(void 0===a.input.offsetX&&a.input._containerOffset(),e=b.pageX-a.input.offsetX,f=b.pageY-a.input.offsetY),c=a.width*e/a.cssWidth,d=a.height*f/a.cssHeight,{x:c,y:d}},touchControls:function(b){function c(c){for(var d=a.input.touchLocation(c),e=b.bottom-b.unit,f=0,g=b.controls.length;g>f;f++){var h=f*b.unit+b.gutter;if(d.x>=h&&d.x<=h+b.size&&(b.fullHeight||d.y>=e+b.gutter&&d.y<=e+b.unit-b.gutter))return b.controls[f][0]}}function e(d){var e,f,g,h,i,j={};for(e=0,f=b.controls.length;f>e;e++)i=b.controls[e][0],
  a.inputs[i]&&(j[i]=!0),a.inputs[i]=!1;var k=d.touches?d.touches:[d];for(e=0,f=k.length;f>e;e++)g=k[e],h=c(g),h&&(a.inputs[h]=!0,j[h]?delete j[h]:a.input.trigger(h));for(i in j)a.input.trigger(i+"Up");return null}return this.touchEnabled?!1:f?(a.input.keypad=b=a._extend({left:0,gutter:10,controls:d,width:a.width,bottom:a.height,fullHeight:!1},b),b.unit=b.width/b.controls.length,b.size=b.unit-2*b.gutter,this.touchDispatchHandler=function(a){e(a),a.preventDefault()},a._each(["touchstart","touchend","touchmove","touchcancel"],function(b){a.el.addEventListener(b,this.touchDispatchHandler)},this),void(this.touchEnabled=!0)):!1},disableTouchControls:function(){a._each(["touchstart","touchend","touchmove","touchcancel"],function(b){a.el.removeEventListener(b,this.touchDispatchHandler)},this),a.el.removeEventListener("touchstart",this.joypadStart),a.el.removeEventListener("touchmove",this.joypadMove),a.el.removeEventListener("touchend",this.joypadEnd),a.el.removeEventListener("touchcancel",this.joypadEnd),this.touchEnabled=!1;for(var b in a.inputs)a.inputs[b]=!1},joypadControls:function(b){if(this.joypadEnabled)return!1;if(!f)return!1;var c=a.joypad=a._defaults(b||{},{size:50,trigger:20,center:25,color:"#CCC",background:"#000",alpha:.5,zone:a.width/2,joypadTouch:null,inputs:e,triggers:[]});this.joypadStart=function(b){if(null===c.joypadTouch){var d=b.changedTouches[0],e=a.input.touchLocation(d);e.x<c.zone&&(c.joypadTouch=d.identifier,c.centerX=e.x,c.centerY=e.y,c.x=null,c.y=null)}},this.joypadMove=function(b){if(null!==c.joypadTouch)for(var d=b,e=0,f=d.changedTouches.length;f>e;e++){var g=d.changedTouches[e];if(g.identifier===c.joypadTouch){var h=a.input.touchLocation(g),i=h.x-c.centerX,j=h.y-c.centerY,k=Math.sqrt(i*i+j*j),l=Math.max(1,k/c.size),m=Math.atan2(i,j);l>1&&(i/=l,j/=l,k/=l);for(var n=[j<-c.trigger,i>c.trigger,j>c.trigger,i<-c.trigger],o=0;o<n.length;o++){var p=c.inputs[o];n[o]?(a.inputs[p]=!0,c.triggers[o]||a.input.trigger(p)):(a.inputs[p]=!1,c.triggers[o]&&a.input.trigger(p+"Up"))}a._extend(c,{dx:i,dy:j,x:c.centerX+i,y:c.centerY+j,dist:k,ang:m,triggers:n});break}}b.preventDefault()},this.joypadEnd=function(b){var d=b;if(null!==c.joypadTouch)for(var e=0,f=d.changedTouches.length;f>e;e++){var g=d.changedTouches[e];if(g.identifier===c.joypadTouch){for(var h=0;h<c.triggers.length;h++){var i=c.inputs[h];a.inputs[i]=!1,c.triggers[h]&&a.input.trigger(i+"Up")}c.joypadTouch=null;break}}b.preventDefault()},a.el.addEventListener("touchstart",this.joypadStart),a.el.addEventListener("touchmove",this.joypadMove),a.el.addEventListener("touchend",this.joypadEnd),a.el.addEventListener("touchcancel",this.joypadEnd),this.joypadEnabled=!0},mouseControls:function(b){b=b||{};var c=b.stageNum||0,d=b.mouseX||"mouseX",e=b.mouseY||"mouseY",f=b.cursor||"off",g={};"on"!==f&&("off"===f?a.el.style.cursor="none":a.el.style.cursor=f),a.inputs[d]=0,a.inputs[e]=0,a._mouseMove=function(b){b.preventDefault();var f=b.touches?b.touches[0]:b,h=a.el,i=h.getBoundingClientRect(),j=window.getComputedStyle(h),k=f.clientX-i.left-parseInt(j.paddingLeft,10),l=f.clientY-i.top-parseInt(j.paddingTop,10),m=a.stage(c);(a._isUndefined(k)||a._isUndefined(l))&&(k=f.offsetX,l=f.offsetY),(a._isUndefined(k)||a._isUndefined(l))&&(k=f.layerX,l=f.layerY),(a._isUndefined(k)||a._isUndefined(l))&&(void 0===a.input.offsetX&&a.input._containerOffset(),k=f.pageX-a.input.offsetX,l=f.pageY-a.input.offsetY),m&&(g.x=a.canvasToStageX(k,m),g.y=a.canvasToStageY(l,m),a.inputs[d]=g.x,a.inputs[e]=g.y,a.input.trigger("mouseMove",g))},a.el.addEventListener("mousemove",a._mouseMove,!0),a.el.addEventListener("touchstart",a._mouseMove,!0),a.el.addEventListener("touchmove",a._mouseMove,!0)},disableMouseControls:function(){a._mouseMove&&(a.el.removeEventListener("mousemove",a._mouseMove,!0),a.el.style.cursor="inherit",a._mouseMove=null)},drawButtons:function(){var b=a.input.keypad,c=a.ctx;c.save(),c.textAlign="center",c.textBaseline="middle";for(var d=0;d<b.controls.length;d++){var e=b.controls[d];if(e[0]){c.font="bold "+b.size/2+"px arial";var f=b.left+d*b.unit+b.gutter,g=b.bottom-b.unit,h=a.inputs[e[0]];c.fillStyle=b.color||"#FFFFFF",c.globalAlpha=h?1:.5,c.fillRect(f,g,b.size,b.size),c.fillStyle=b.text||"#000000",c.fillText(e[1],f+b.size/2,g+b.size/2)}}c.restore()},drawCircle:function(b,c,d,e){var f=a.ctx,g=a.joypad;f.save(),f.beginPath(),f.globalAlpha=g.alpha,f.fillStyle=d,f.arc(b,c,e,0,2*Math.PI,!0),f.closePath(),f.fill(),f.restore()},drawJoypad:function(){var b=a.joypad;null!==b.joypadTouch&&(a.input.drawCircle(b.centerX,b.centerY,b.background,b.size),null!==b.x&&a.input.drawCircle(b.x,b.y,b.color,b.center))},drawCanvas:function(){this.touchEnabled&&this.drawButtons(),this.joypadEnabled&&this.drawJoypad()}}),a.input=new a.InputSystem,a.controls=function(b){return a.input.keyboardControls(),b?(a.input.touchControls({controls:[[],[],[],["action","b"],["fire","a"]]}),a.input.joypadControls()):a.input.touchControls(),a},a.component("platformerControls",{defaults:{speed:200,jumpSpeed:-300,collisions:[]},added:function(){var b=this.entity.p;a._defaults(b,this.defaults),this.entity.on("step",this,"step"),this.entity.on("bump.bottom",this,"landed"),b.landed=0,b.direction="right"},landed:function(a){var b=this.entity.p;b.landed=.2},step:function(b){var c=this.entity.p;if(void 0===c.ignoreControls||!c.ignoreControls){var d=null;if(void 0!==c.collisions&&c.collisions.length>0&&(a.inputs.left||a.inputs.right||c.landed>0)){if(1===c.collisions.length)d=c.collisions[0];else{d=null;for(var e=0;e<c.collisions.length;e++)c.collisions[e].normalY<0&&(d=c.collisions[e])}null!==d&&d.normalY>-.3&&d.normalY<.3&&(d=null)}a.inputs.left?(c.direction="left",d&&c.landed>0?(c.vx=c.speed*d.normalY,c.vy=-c.speed*d.normalX):c.vx=-c.speed):a.inputs.right?(c.direction="right",d&&c.landed>0?(c.vx=-c.speed*d.normalY,c.vy=c.speed*d.normalX):c.vx=c.speed):(c.vx=0,d&&c.landed>0&&(c.vy=0)),c.landed>0&&(a.inputs.up||a.inputs.action)&&!c.jumping?(c.vy=c.jumpSpeed,c.landed=-b,c.jumping=!0):(a.inputs.up||a.inputs.action)&&(this.entity.trigger("jump",this.entity),c.jumping=!0),!c.jumping||a.inputs.up||a.inputs.action||(c.jumping=!1,this.entity.trigger("jumped",this.entity),c.vy<c.jumpSpeed/3&&(c.vy=c.jumpSpeed/3))}c.landed-=b}}),a.component("stepControls",{added:function(){var a=this.entity.p;a.stepDistance||(a.stepDistance=32),a.stepDelay||(a.stepDelay=.2),a.stepWait=0,this.entity.on("step",this,"step"),this.entity.on("hit",this,"collision")},collision:function(a){var b=this.entity.p;b.stepping&&(b.stepping=!1,b.x=b.origX,b.y=b.origY)},step:function(b){var c=this.entity.p;c.stepWait-=b,c.stepping&&(c.x+=c.diffX*b/c.stepDelay,c.y+=c.diffY*b/c.stepDelay),c.stepWait>0||(c.stepping&&(c.x=c.destX,c.y=c.destY),c.stepping=!1,c.diffX=0,c.diffY=0,a.inputs.left?c.diffX=-c.stepDistance:a.inputs.right&&(c.diffX=c.stepDistance),a.inputs.up?c.diffY=-c.stepDistance:a.inputs.down&&(c.diffY=c.stepDistance),(c.diffY||c.diffX)&&(c.stepping=!0,c.origX=c.x,c.origY=c.y,c.destX=c.x+c.diffX,c.destY=c.y+c.diffY,c.stepWait=c.stepDelay))}})}};"undefined"==typeof Quintus?module.exports=quintusInput:quintusInput(Quintus);var quintusScenes=function(a){"use strict";a.Scenes=function(a){a.scenes={},a.stages=[],a.Class.extend("Scene",{init:function(a,b){this.opts=b||{},this.sceneFunc=a}}),a.scene=function(b,c,d){return void 0===c?a.scenes[b]:(a._isFunction(c)&&(c=new a.Scene(c,d),c.name=b),a.scenes[b]=c,c)},a._nullContainer={c:{x:0,y:0,angle:0,scale:1},matrix:a.matrix2d()},a.collision=function(){function b(a,b){var c=a[b],d=a[b+1]||a[0];f=-(d[1]-c[1]),g=d[0]-c[0];var e=Math.sqrt(f*f+g*g);e>0&&(f/=e,g/=e)}function c(a){return f*a[0]+g*a[1]}function d(a,d,e){var k,l,m,n,o,p,q,r,s,t,u,v,w,x,y=Number.POSITIVE_INFINITY,z=!1,A=e?j:i;for(h[0]=0,h[1]=0,a.c?w=a.c.points:(w=a.p.points,h[0]+=a.p.x,h[1]+=a.p.y),d.c?x=d.c.points:(x=d.p.points,h[0]+=-d.p.x,h[1]+=-d.p.y),a=a.p,d=d.p,s=0;s<w.length;s++){for(b(w,s),k=c(w[0]),l=k,t=1;t<w.length;t++)r=c(w[t]),k>r&&(k=r),r>l&&(l=r);for(m=c(x[0]),n=m,t=1;t<x.length;t++)r=c(x[t]),m>r&&(m=r),r>n&&(n=r);if(q=c(h),k+=q,l+=q,o=k-n,p=m-l,o>0||p>0)return null;u=-1*(n-k),e&&(u*=-1),v=Math.abs(u),y>v&&(A.distance=u,A.magnitude=v,A.normalX=f,A.normalY=g,A.distance>0&&(A.distance*=-1,A.normalX*=-1,A.normalY*=-1),z=!0,y=v)}return z?A:null}function e(b,c){var e,f,g;return b.p.points||a._generatePoints(b),c.p.points||a._generatePoints(c),(e=d(b,c))&&(f=d(c,b,!0))?(g=f.magnitude<e.magnitude?f:e,0===g.magnitude?!1:(g.separate[0]=g.distance*g.normalX,g.separate[1]=g.distance*g.normalY,g)):!1}var f,g,h=[0,0],i={separate:[]},j={separate:[]};return e}(),a.overlap=function(a,b){var c=a.c||a.p||a,d=b.c||b.p||b,e=c.x-(c.cx||0),f=c.y-(c.cy||0),g=d.x-(d.cx||0),h=d.y-(d.cy||0);return!(f+c.h<h||f>h+d.h||e+c.w<g||e>g+d.w)},a.Stage=a.GameObject.extend({defaults:{sort:!1,gridW:400,gridH:400,x:0,y:0},init:function(b,c){this.scene=b,this.items=[],this.lists={},this.index={},this.removeList=[],this.grid={},this._collisionLayers=[],this.time=0,this.defaults.w=a.width,this.defaults.h=a.height,this.options=a._extend({},this.defaults),this.scene&&a._extend(this.options,b.opts),c&&a._extend(this.options,c),this.options.sort&&!a._isFunction(this.options.sort)&&(this.options.sort=function(a,b){return(a.p&&a.p.z||-1)-(b.p&&b.p.z||-1)})},destroyed:function(){this.invoke("debind"),this.trigger("destroyed")},loadScene:function(){this.scene&&this.scene.sceneFunc(this)},loadAssets:function(b){for(var c=a._isArray(b)?b:a.asset(b),d=0;d<c.length;d++){var e=c[d][0],f=c[d][1];this.insert(new a[e](f))}},each:function(a){for(var b=0,c=this.items.length;c>b;b++)a.call(this.items[b],arguments[1],arguments[2])},invoke:function(a){for(var b=0,c=this.items.length;c>b;b++)this.items[b][a].call(this.items[b],arguments[1],arguments[2])},detect:function(a){for(var b=this.items.length-1;b>=0;b--)if(a.call(this.items[b],arguments[1],arguments[2],arguments[3]))return this.items[b];return!1},identify:function(a){for(var b,c=this.items.length-1;c>=0;c--)if(b=a.call(this.items[c],arguments[1],arguments[2],arguments[3]))return b;return!1},find:function(a){return this.index[a]},addToLists:function(a,b){for(var c=0;c<a.length;c++)this.addToList(a[c],b)},addToList:function(a,b){this.lists[a]||(this.lists[a]=[]),this.lists[a].push(b)},removeFromLists:function(a,b){for(var c=0;c<a.length;c++)this.removeFromList(a[c],b)},removeFromList:function(a,b){var c=this.lists[a].indexOf(b);-1!==c&&this.lists[a].splice(c,1)},insert:function(b,c){return this.items.push(b),b.stage=this,b.container=c,c&&c.children.push(b),b.grid={},a._generatePoints(b),a._generateCollisionPoints(b),b.className&&this.addToList(b.className,b),b.activeComponents&&this.addToLists(b.activeComponents,b),b.p&&(this.index[b.p.id]=b),this.trigger("inserted",b),b.trigger("inserted",this),this.regrid(b),b},remove:function(a){this.delGrid(a),this.removeList.push(a)},forceRemove:function(a){var b=this.items.indexOf(a);if(-1!==b){if(this.items.splice(b,1),a.className&&this.removeFromList(a.className,a),a.activeComponents&&this.removeFromLists(a.activeComponents,a),a.container){var c=a.container.children.indexOf(a);-1!==c&&a.container.children.splice(c,1)}a.destroy&&a.destroy(),a.p.id&&delete this.index[a.p.id],this.trigger("removed",a)}},pause:function(){this.paused=!0},unpause:function(){this.paused=!1},_gridCellCheck:function(b,c,d,e){if(a._isUndefined(e)||e&b){var f=this.index[c];if(f&&f!==d&&a.overlap(d,f)){var g=a.collision(d,f);return g?(g.obj=f,g):!1}}},gridTest:function(b,c){for(var d,e,f=b.grid,g=f.Y1;g<=f.Y2;g++)if(this.grid[g])for(var h=f.X1;h<=f.X2;h++)if(d=this.grid[g][h],d&&(e=a._detect(d,this._gridCellCheck,this,b,c)))return e;return!1},collisionLayer:function(a){return this._collisionLayers.push(a),a.collisionLayer=!0,this.insert(a)},_collideCollisionLayer:function(a,b){for(var c,d=0,e=this._collisionLayers.length;e>d;d++){var f=this._collisionLayers[d];if(f.p.type&b&&(c=f.collide(a)))return c.obj=f,c}return!1},search:function(b,c){var d;return b.grid||this.regrid(b,b.stage!==this),c=a._isUndefined(c)?b.p&&b.p.collisionMask:c,d=this._collideCollisionLayer(b,c),d=d||this.gridTest(b,c)},_locateObj:{p:{x:0,y:0,cx:0,cy:0,w:1,h:1},grid:{}},locate:function(a,b,c){var d=null;return this._locateObj.p.x=a,this._locateObj.p.y=b,this.regrid(this._locateObj,!0),d=this._collideCollisionLayer(this._locateObj,c),d=d||this.gridTest(this._locateObj,c),d&&d.obj?d.obj:!1},collide:function(b,c){var d,e,f,g,h,i;for(a._isObject(c)?(f=c.collisionMask,g=c.maxCol,i=c.skipEvents):f=c,f=a._isUndefined(f)?b.p&&b.p.collisionMask:f,g=g||3,a._generateCollisionPoints(b),this.regrid(b),h=g;h>0&&(d=this._collideCollisionLayer(b,f));)i||(b.trigger("hit",d),b.trigger("hit.collision",d)),a._generateCollisionPoints(b),this.regrid(b),h--;for(h=g;h>0&&(e=this.gridTest(b,f));){if(b.trigger("hit",e),b.trigger("hit.sprite",e),!i){var j=e.obj;e.obj=b,e.normalX*=-1,e.normalY*=-1,e.distance=0,e.magnitude=0,e.separate[0]=0,e.separate[1]=0,j.trigger("hit",e),j.trigger("hit.sprite",e)}a._generateCollisionPoints(b),this.regrid(b),h--}return e||d},delGrid:function(a){for(var b=a.grid,c=b.Y1;c<=b.Y2;c++)if(this.grid[c])for(var d=b.X1;d<=b.X2;d++)this.grid[c][d]&&delete this.grid[c][d][a.p.id]},addGrid:function(a){for(var b=a.grid,c=b.Y1;c<=b.Y2;c++){this.grid[c]||(this.grid[c]={});for(var d=b.X1;d<=b.X2;d++)this.grid[c][d]||(this.grid[c][d]={}),this.grid[c][d][a.p.id]=a.p.type}},regrid:function(a,b){if(!a.collisionLayer){a.grid=a.grid||{};var c=a.c||a.p,d=Math.floor((c.x-c.cx)/this.options.gridW),e=Math.floor((c.y-c.cy)/this.options.gridH),f=Math.floor((c.x-c.cx+c.w)/this.options.gridW),g=Math.floor((c.y-c.cy+c.h)/this.options.gridH),h=a.grid;(h.X1!==d||h.X2!==f||h.Y1!==e||h.Y2!==g)&&(void 0!==h.X1&&this.delGrid(a),h.X1=d,h.X2=f,h.Y1=e,h.Y2=g,b||this.addGrid(a))}},markSprites:function(b,c){for(var d,e,f=this.viewport,g=f?f.scale:1,h=f?f.x:0,i=f?f.y:0,j=a.width/g,k=a.height/g,l=Math.floor(h/this.options.gridW),m=Math.floor(i/this.options.gridH),n=Math.floor((h+j)/this.options.gridW),o=Math.floor((i+k)/this.options.gridH),p=m;o>=p;p++)if(d=this.grid[p])for(var q=l;n>=q;q++)if(e=d[q])for(var r in e)this.index[r]&&(this.index[r].mark=c,this.index[r].container&&(this.index[r].container.mark=c))},updateSprites:function(b,c,d){for(var e,f=0,g=b.length;g>f;f++)e=b[f],(d||!e.p.visibleOnly||e.mark&&!(e.mark<this.time))&&(d||!e.container)&&(e.update(c),a._generateCollisionPoints(e),this.regrid(e))},step:function(a){if(this.paused)return!1;if(this.time+=a,this.markSprites(this.items,this.time),this.trigger("prestep",a),this.updateSprites(this.items,a),this.trigger("step",a),this.removeList.length>0){for(var b=0,c=this.removeList.length;c>b;b++)this.forceRemove(this.removeList[b]);this.removeList.length=0}this.trigger("poststep",a)},hide:function(){this.hidden=!0},show:function(){this.hidden=!1},stop:function(){this.hide(),this.pause()},start:function(){this.show(),this.unpause()},render:function(a){if(this.hidden)return!1;this.options.sort&&this.items.sort(this.options.sort),this.trigger("prerender",a),this.trigger("beforerender",a);for(var b=0,c=this.items.length;c>b;b++){var d=this.items[b];!d.container&&(d.p.renderAlways||d.mark>=this.time)&&d.render(a)}this.trigger("render",a),this.trigger("postrender",a)}}),a.activeStage=0,a.StageSelector=a.Class.extend({emptyList:[],init:function(a,b){this.stage=a,this.selector=b,this.items=this.stage.lists[this.selector]||this.emptyList,this.length=this.items.length},each:function(a){for(var b=0,c=this.items.length;c>b;b++)a.call(this.items[b],arguments[1],arguments[2]);return this},invoke:function(a){for(var b=0,c=this.items.length;c>b;b++)this.items[b][a].call(this.items[b],arguments[1],arguments[2]);return this},trigger:function(a,b){this.invoke("trigger",a,b)},destroy:function(){this.invoke("destroy")},detect:function(a){for(var b=0,c=this.items.length;c>b;b++)if(a.call(this.items[b],arguments[1],arguments[2]))return this.items[b];return!1},identify:function(a){for(var b=null,c=0,d=this.items.length;d>c;c++)if(b=a.call(this.items[c],arguments[1],arguments[2]))return b;return!1},_pObject:function(b){a._extend(this.p,b)},_pSingle:function(a,b){this.p[a]=b},set:function(a,b){return void 0===b?this.each(this._pObject,a):this.each(this._pSingle,a,b),this},at:function(a){return this.items[a]},first:function(){return this.items[0]},last:function(){return this.items[this.items.length-1]}}),a.select=function(b,c){return c=void 0===c?a.activeStage:c,c=a.stage(c),a._isNumber(b)?c.index[b]:new a.StageSelector(c,b)},a.stage=function(b){return b=void 0===b?a.activeStage:b,a.stages[b]},a.stageScene=function(b,c,d){a._isString(b)&&(b=a.scene(b)),a._isObject(c)&&(d=c,c=a._popProperty(d,"stage")||b&&b.opts.stage||0),d=a._clone(d);var e=a._popProperty(d,"stageClass")||b&&b.opts.stageClass||a.Stage;c=a._isUndefined(c)?b&&b.opts.stage||0:c,a.stages[c]&&a.stages[c].destroy(),a.activeStage=c;var f=a.stages[c]=new e(b,d);return f.options.asset&&f.loadAssets(f.options.asset),b&&f.loadScene(),a.activeStage=0,a.loop||a.gameLoop(a.stageGameLoop),f},a.stageStepLoop=function(b){var c,d,e;for(0>b&&(b=1/60),b>1/15&&(b=1/15),c=0,d=a.stages.length;d>c;c++)a.activeStage=c,e=a.stage(),e&&e.step(b);a.activeStage=0},a.stageRenderLoop=function(){a.ctx&&a.clear();for(var b=0,c=a.stages.length;c>b;b++){a.activeStage=b;var d=a.stage();d&&d.render(a.ctx)}a.input&&a.ctx&&a.input.drawCanvas(a.ctx),a.activeStage=0},a.stageGameLoop=function(b){a.stageStepLoop(b),a.stageRenderLoop()},a.clearStage=function(b){a.stages[b]&&(a.stages[b].destroy(),a.stages[b]=null)},a.clearStages=function(){for(var b=0,c=a.stages.length;c>b;b++)a.stages[b]&&a.stages[b].destroy();a.stages.length=0}}};"undefined"==typeof Quintus?module.exports=quintusScenes:quintusScenes(Quintus);var quintusSprites=function(a){"use strict";a.Sprites=function(a){return a.Class.extend("SpriteSheet",{init:function(b,c,d){if(!a.asset(c))throw"Invalid Asset:"+c;a._extend(this,{name:b,asset:c,w:a.asset(c).width,h:a.asset(c).height,tileW:64,tileH:64,sx:0,sy:0,spacingX:0,spacingY:0,frameProperties:{}}),d&&a._extend(this,d),this.tilew&&(this.tileW=this.tilew,delete this.tilew),this.tileh&&(this.tileH=this.tileh,delete this.tileh),this.cols=this.cols||Math.floor(this.w/(this.tileW+this.spacingX)),this.frames=this.cols*Math.floor(this.h/(this.tileH+this.spacingY))},fx:function(a){return Math.floor(a%this.cols*(this.tileW+this.spacingX)+this.sx)},fy:function(a){return Math.floor(Math.floor(a/this.cols)*(this.tileH+this.spacingY)+this.sy)},draw:function(b,c,d,e){b||(b=a.ctx),b.drawImage(a.asset(this.asset),this.fx(e),this.fy(e),this.tileW,this.tileH,Math.floor(c),Math.floor(d),this.tileW,this.tileH)}}),a.sheets={},a.sheet=function(b,c,d){return c?void(a.sheets[b]=new a.SpriteSheet(b,c,d)):a.sheets[b]},a.compileSheets=function(b,c){var d=a.asset(c);a._each(d,function(c,d){a.sheet(d,b,c)})},a.SPRITE_NONE=0,a.SPRITE_DEFAULT=1,a.SPRITE_PARTICLE=2,a.SPRITE_ACTIVE=4,a.SPRITE_FRIENDLY=8,a.SPRITE_ENEMY=16,a.SPRITE_POWERUP=32,a.SPRITE_UI=64,a.SPRITE_ALL=65535,a._generatePoints=function(a,b){if(!a.p.points||b){var c=a.p,d=c.w/2,e=c.h/2;c.points=[[-d,-e],[d,-e],[d,e],[-d,e]]}},a._generateCollisionPoints=function(b){if(b.matrix||b.refreshMatrix){b.c||(b.c={points:[]});var c=b.p,d=b.c;if(c.moved||d.origX!==c.x||d.origY!==c.y||d.origScale!==c.scale||d.origAngle!==c.angle){d.origX=c.x,d.origY=c.y,d.origScale=c.scale,d.origAngle=c.angle,b.refreshMatrix();var e;if(b.container||c.scale&&1!==c.scale||0!==c.angle){var f=b.container||a._nullContainer;d.x=f.matrix.transformX(c.x,c.y),d.y=f.matrix.transformY(c.x,c.y),d.angle=c.angle+f.c.angle,d.scale=(f.c.scale||1)*(c.scale||1);var g=1/0,h=1/0,i=-(1/0),j=-(1/0);for(e=0;e<b.p.points.length;e++){b.c.points[e]||(b.c.points[e]=[]),b.matrix.transformArr(b.p.points[e],b.c.points[e]);var k=b.c.points[e][0],l=b.c.points[e][1];g>k&&(g=k),k>i&&(i=k),h>l&&(h=l),l>j&&(j=l)}g===i&&(i+=1),h===j&&(j+=1),d.cx=d.x-g,d.cy=d.y-h,d.w=i-g,d.h=j-h}else{for(e=0;e<b.p.points.length;e++)b.c.points[e]=b.c.points[e]||[],b.c.points[e][0]=c.x+b.p.points[e][0],b.c.points[e][1]=c.y+b.p.points[e][1];d.x=c.x,d.y=c.y,d.cx=c.cx,d.cy=c.cy,d.w=c.w,d.h=c.h}c.moved=!1,b.children&&b.children.length>0&&a._invoke(b.children,"moved")}}},a.GameObject.extend("Sprite",{init:function(b,c){this.p=a._extend({x:0,y:0,z:0,opacity:1,angle:0,frame:0,type:a.SPRITE_DEFAULT|a.SPRITE_ACTIVE,name:"",spriteProperties:{}},c),this.matrix=new a.Matrix2D,this.children=[],a._extend(this.p,b),this.size(),this.p.id=this.p.id||a._uniqueId(),this.refreshMatrix()},size:function(a){!a&&this.p.w&&this.p.h||(this.asset()?(this.p.w=this.asset().width,this.p.h=this.asset().height):this.sheet()&&(this.p.w=this.sheet().tileW,this.p.h=this.sheet().tileH)),this.p.cx=a||void 0===this.p.cx?this.p.w/2:this.p.cx,this.p.cy=a||void 0===this.p.cy?this.p.h/2:this.p.cy},asset:function(b,c){return b?(this.p.asset=b,void(c&&(this.size(!0),a._generatePoints(this,!0)))):a.asset(this.p.asset)},sheet:function(b,c){return b?(this.p.sheet=b,void(c&&(this.size(!0),a._generatePoints(this,!0)))):a.sheet(this.p.sheet)},hide:function(){this.p.hidden=!0},show:function(){this.p.hidden=!1},set:function(b){return a._extend(this.p,b),this},_sortChild:function(a,b){return(a.p&&a.p.z||-1)-(b.p&&b.p.z||-1)},_flipArgs:{x:[-1,1],y:[1,-1],xy:[-1,-1]},render:function(b){var c=this.p;c.hidden||0===c.opacity||(b||(b=a.ctx),this.trigger("predraw",b),b.save(),void 0!==this.p.opacity&&1!==this.p.opacity&&(b.globalAlpha=this.p.opacity),this.matrix.setContextTransform(b),this.p.flip&&b.scale.apply(b,this._flipArgs[this.p.flip]),this.trigger("beforedraw",b),this.draw(b),this.trigger("draw",b),b.restore(),this.p.sort&&this.children.sort(this._sortChild),a._invoke(this.children,"render",b),this.trigger("postdraw",b),a.debug&&this.debugRender(b))},center:function(){this.container?(this.p.x=0,this.p.y=0):(this.p.x=a.width/2,this.p.y=a.height/2)},draw:function(b){var c=this.p;c.sheet?this.sheet().draw(b,-c.cx,-c.cy,c.frame):c.asset?b.drawImage(a.asset(c.asset),-c.cx,-c.cy):c.color&&(b.fillStyle=c.color,b.fillRect(-c.cx,-c.cy,c.w,c.h))},debugRender:function(b){this.p.points||a._generatePoints(this),b.save(),this.matrix.setContextTransform(b),b.beginPath(),b.fillStyle=this.p.hit?"blue":"red",b.strokeStyle="#FF0000",b.fillStyle="rgba(0,0,0,0.5)",b.moveTo(this.p.points[0][0],this.p.points[0][1]);for(var c=0;c<this.p.points.length;c++)b.lineTo(this.p.points[c][0],this.p.points[c][1]);if(b.lineTo(this.p.points[0][0],this.p.points[0][1]),b.stroke(),a.debugFill&&b.fill(),b.restore(),this.c){var d=this.c;b.save(),b.globalAlpha=1,b.lineWidth=2,b.strokeStyle="#FF00FF",b.beginPath(),b.moveTo(d.x-d.cx,d.y-d.cy),b.lineTo(d.x-d.cx+d.w,d.y-d.cy),b.lineTo(d.x-d.cx+d.w,d.y-d.cy+d.h),b.lineTo(d.x-d.cx,d.y-d.cy+d.h),b.lineTo(d.x-d.cx,d.y-d.cy),b.stroke(),b.restore()}},update:function(b){this.trigger("prestep",b),this.step&&this.step(b),this.trigger("step",b),a._generateCollisionPoints(this),this.stage&&this.children.length>0&&this.stage.updateSprites(this.children,b,!0),this.p.collisions&&(this.p.collisions=[])},refreshMatrix:function(){var a=this.p;this.matrix.identity(),this.container&&this.matrix.multiply(this.container.matrix),this.matrix.translate(a.x,a.y),a.scale&&this.matrix.scale(a.scale,a.scale),this.matrix.rotateDeg(a.angle)},moved:function(){this.p.moved=!0}}),a.Sprite.extend("MovingSprite",{init:function(b,c){this._super(a._extend({vx:0,vy:0,ax:0,ay:0},b),c)},step:function(a){var b=this.p;b.vx+=b.ax*a,b.vy+=b.ay*a,b.x+=b.vx*a,b.y+=b.vy*a}}),a}};"undefined"==typeof Quintus?module.exports=quintusSprites:quintusSprites(Quintus);var quintusTMX=function(a){"use strict";a.TMX=function(a){function b(a,b){var c=a.getAttribute(b);return isNaN(c)?c:+c}function c(a){for(var c=a.querySelectorAll("property"),d={},e=0;e<c.length;e++){var f=c[e];d[b(f,"name")]=b(f,"value")}return d}a.assetTypes.tmx="TMX",a.loadAssetTMX=function(b,c,d,e){a.loadAssetOther(b,c,function(a,b){var c=new DOMParser,e=c.parseFromString(b,"application/xml");d(a,e)},e)},a._tmxExtractAssetName=function(a){var b=a.getAttribute("source"),c=b.split("/");return c[c.length-1]},a._tmxExtractSources=function(b){var c=b.querySelectorAll("[source]");return a._map(c,a._tmxExtractAssetName)},a.loadTMX=function(b,c,d){a._isString(b)&&(b=a._normalizeArg(b));var e=[];a._each(b,function(b){"tmx"===a._fileExtension(b)&&e.push(b)});var f=[];a.load(b,function(){a._each(e,function(b){var c=a._tmxExtractSources(a.asset(b));f=f.concat(c)}),f.length>0?a.load(f,c,d):c()})},a._tmxLoadTilesets=function(d,e){function f(a){var b=a.split(",");return[parseFloat(b[0]),parseFloat(b[1])]}for(var g=[],h=0;h<d.length;h++){for(var i=d[h],j=b(i,"name"),k=b(i,"firstgid"),l=a._tmxExtractAssetName(i.querySelector("image")),m={},n={tileW:b(i,"tilewidth"),tileH:b(i,"tileheight"),spacingX:b(i,"spacing"),spacingY:b(i,"spacing")},o=i.querySelectorAll("tile"),p=0;p<o.length;p++){var q=o[p],r=b(q,"id"),s=k+r,t=c(q);t.points&&(t.points=a._map(t.points.split(" "),f)),e[s]=t,m[r]=t}n.frameProperties=m,g.push([k,j]),a.sheet(j,l,n)}return g},a._tmxProcessImageLayer=function(b,d,e,f){var g=a._tmxExtractAssetName(f.querySelector("image")),h=c(f);h.asset=g,b.insert(new a.Repeater(h))},a._lookupGid=function(a,b){for(var c=0;b[c+1]&&a>=b[c+1][0];)c++;return b[c]},a._tmxProcessTileLayer=function(d,e,f,g){for(var h,i,j,k=g.querySelectorAll("tile"),l=b(g,"width"),m=b(g,"height"),n=[],o=0,p=0;m>p;p++){n[p]=[];for(var q=0;l>q;q++){var r=b(k[o],"gid");0===r?n[p].push(null):(i||(h=a._lookupGid(b(k[o],"gid"),e),i=h[0],j=h[1]),n[p].push(r-i)),o++}}var s=a._extend({tileW:a.sheet(j).tileW,tileH:a.sheet(j).tileH,sheet:j,tiles:n},c(g)),t=s.Class||"TileLayer";s.collision?d.collisionLayer(new a[t](s)):d.insert(new a[t](s))},a._tmxProcessObjectLayer=function(d,e,f,g){for(var h=g.querySelectorAll("object"),i=0;i<h.length;i++){var j=h[i],k=b(j,"gid"),l=b(j,"x"),m=b(j,"y"),n=f[k],o=c(j);if(!n)throw"Invalid TMX Object: missing properties for GID:"+k;if(!n.Class)throw"Invalid TMX Object: missing Class for GID:"+k;var p=n.Class;if(!p)throw"Invalid TMX Object Class: "+p+" GID:"+k;var q=a._extend(a._extend({x:l,y:m},n),o),r=new a[p](q);r.p.x+=r.p.w/2,r.p.y-=r.p.h/2,d.insert(r)}},a._tmxProcessors={objectgroup:a._tmxProcessObjectLayer,layer:a._tmxProcessTileLayer,imagelayer:a._tmxProcessImageLayer},a.stageTMX=function(b,c){var d=a._isString(b)?a.asset(b):b,e={},f=d.getElementsByTagName("tileset"),g=a._tmxLoadTilesets(f,e);a._each(d.documentElement.childNodes,function(b){var d=b.tagName;a._tmxProcessors[d]&&a._tmxProcessors[d](c,g,e,b)})}}};"undefined"==typeof Quintus?module.exports=quintusTMX:quintusTMX(Quintus);var quintusTouch=function(a){"use strict";a.Touch=function(b){if(b._isUndefined(a.Sprites))throw"Quintus.Touch requires Quintus.Sprites Module";var c=[0],d=0;b.Evented.extend("TouchSystem",{init:function(){var a=this;this.boundTouch=function(b){a.touch(b)},this.boundDrag=function(b){a.drag(b)},this.boundEnd=function(b){a.touchEnd(b)},b.el.addEventListener("touchstart",this.boundTouch),b.el.addEventListener("mousedown",this.boundTouch),b.el.addEventListener("touchmove",this.boundDrag),b.el.addEventListener("mousemove",this.boundDrag),b.el.addEventListener("touchend",this.boundEnd),b.el.addEventListener("mouseup",this.boundEnd),b.el.addEventListener("touchcancel",this.boundEnd),this.touchPos=new b.Evented,this.touchPos.grid={},this.touchPos.p={w:1,h:1,cx:0,cy:0},this.activeTouches={},this.touchedObjects={}},destroy:function(){b.el.removeEventListener("touchstart",this.boundTouch),b.el.removeEventListener("mousedown",this.boundTouch),b.el.removeEventListener("touchmove",this.boundDrag),b.el.removeEventListener("mousemove",this.boundDrag),b.el.removeEventListener("touchend",this.boundEnd),b.el.removeEventListener("mouseup",this.boundEnd),b.el.removeEventListener("touchcancel",this.boundEnd)},normalizeTouch:function(a,c){var d=b.el,e=d.getBoundingClientRect(),f=window.getComputedStyle(d),g=a.clientX-e.left-parseInt(f.paddingLeft,10),h=a.clientY-e.top-parseInt(f.paddingTop,10);if((b._isUndefined(g)||b._isUndefined(h))&&(g=a.offsetX,h=a.offsetY),(b._isUndefined(g)||b._isUndefined(h))&&(g=a.layerX,h=a.layerY),b._isUndefined(g)||b._isUndefined(h)){if(void 0===b.touch.offsetX){b.touch.offsetX=0,b.touch.offsetY=0,d=b.el;do b.touch.offsetX+=d.offsetLeft,b.touch.offsetY+=d.offsetTop;while(d=d.offsetParent)}g=a.pageX-b.touch.offsetX,h=a.pageY-b.touch.offsetY}return this.touchPos.p.ox=this.touchPos.p.px=g/b.cssWidth*b.width,this.touchPos.p.oy=this.touchPos.p.py=h/b.cssHeight*b.height,c.viewport&&(this.touchPos.p.px/=c.viewport.scale,this.touchPos.p.py/=c.viewport.scale,this.touchPos.p.px+=c.viewport.x,this.touchPos.p.py+=c.viewport.y),this.touchPos.p.x=this.touchPos.p.px,this.touchPos.p.y=this.touchPos.p.py,this.touchPos.obj=null,this.touchPos},touch:function(a){for(var e=a.changedTouches||[a],f=0;f<e.length;f++)for(var g=0;g<c.length;g++){var h=e[f],i=b.stage(c[g]);if(i){h.identifier=h.identifier||0;var j=this.normalizeTouch(h,i);i.regrid(j,!0);var k,l=i.search(j,d);if((l||g===c.length-1)&&(k=l&&l.obj,j.obj=k,this.trigger("touch",j)),k&&!this.touchedObjects[k]){this.activeTouches[h.identifier]={x:j.p.px,y:j.p.py,origX:k.p.x,origY:k.p.y,sx:j.p.ox,sy:j.p.oy,identifier:h.identifier,obj:k,stage:i},this.touchedObjects[k.p.id]=!0,k.trigger("touch",this.activeTouches[h.identifier]);break}}}},drag:function(a){for(var b=a.changedTouches||[a],c=0;c<b.length;c++){var d=b[c];d.identifier=d.identifier||0;var e=this.activeTouches[d.identifier],f=e&&e.stage;if(e){var g=this.normalizeTouch(d,f);e.x=g.p.px,e.y=g.p.py,e.dx=g.p.ox-e.sx,e.dy=g.p.oy-e.sy,e.obj.trigger("drag",e)}}a.preventDefault()},touchEnd:function(a){for(var b=a.changedTouches||[a],c=0;c<b.length;c++){var d=b[c];d.identifier=d.identifier||0;var e=this.activeTouches[d.identifier];e&&(e.obj.trigger("touchEnd",e),delete this.touchedObjects[e.obj.p.id],this.activeTouches[d.identifier]=null)}a.preventDefault()}}),b.touch=function(a,e){return b.untouch(),d=a||b.SPRITE_UI,c=e||[2,1,0],b._isArray(c)||(c=[c]),b._touch||(b.touchInput=new b.TouchSystem),b},b.untouch=function(){return b.touchInput&&(b.touchInput.destroy(),delete b.touchInput),b}}};"undefined"==typeof Quintus?module.exports=quintusTouch:quintusTouch(Quintus);var quintusUI=function(a){"use strict";a.UI=function(b){if(b._isUndefined(a.Touch))throw"Quintus.UI requires Quintus.Touch Module";b.UI={},b.UI.roundRect=function(a,b){a.beginPath(),a.moveTo(-b.cx+b.radius,-b.cy),a.lineTo(-b.cx+b.w-b.radius,-b.cy),a.quadraticCurveTo(-b.cx+b.w,-b.cy,-b.cx+b.w,-b.cy+b.radius),a.lineTo(-b.cx+b.w,-b.cy+b.h-b.radius),a.quadraticCurveTo(-b.cx+b.w,-b.cy+b.h,-b.cx+b.w-b.radius,-b.cy+b.h),a.lineTo(-b.cx+b.radius,-b.cy+b.h),a.quadraticCurveTo(-b.cx,-b.cy+b.h,-b.cx,-b.cy+b.h-b.radius),a.lineTo(-b.cx,-b.cy+b.radius),a.quadraticCurveTo(-b.cx,-b.cy,-b.cx+b.radius,-b.cy),a.closePath()},b.UI.Container=b.Sprite.extend("UI.Container",{init:function(a,c){var d,e=b._clone(a||{});a&&b._isString(a.w)&&(d=a.w.match(/^[0-9]+%$/))&&(e.w=parseInt(a.w,10)*b.width/100,e.x=b.width/2-e.w/2),a&&b._isString(a.h)&&(d=a.h.match(/^[0-9]+%$/))&&(e.h=parseInt(a.h,10)*b.height/100,e.y=b.height/2-e.h/2),this._super(b._defaults(e,c),{opacity:1,hidden:!1,fill:null,highlight:null,radius:5,stroke:"#000",border:!1,shadow:!1,shadowColor:!1,outlineWidth:!1,outlineColor:"#000",type:b.SPRITE_NONE})},insert:function(a){return this.stage.insert(a,this),a},fit:function(a,c){if(0!==this.children.length){void 0===a&&(a=0),void 0===c&&(c=a);for(var d=1/0,e=1/0,f=-(1/0),g=-(1/0),h=0;h<this.children.length;h++){var i=this.children[h],j=i.p.x-i.p.cx,k=i.p.y-i.p.cy,l=i.p.x-i.p.cx+i.p.w,m=i.p.y-i.p.cy+i.p.h;d>j&&(d=j),e>k&&(e=k),l>f&&(f=l),m>g&&(g=m)}this.p.cx=-d+c,this.p.cy=-e+a,this.p.w=f-d+2*c,this.p.h=g-e+2*a,b._generatePoints(this,!0),b._generateCollisionPoints(this,!0)}},addShadow:function(a){if(this.p.shadow){var c=b._isNumber(this.p.shadow)?this.p.shadow:5;a.shadowOffsetX=c,a.shadowOffsetY=c,a.shadowColor=this.p.shadowColor||"rgba(0,0,50,0.1)"}},clearShadow:function(a){a.shadowColor="transparent"},drawRadius:function(a){
  b.UI.roundRect(a,this.p),this.addShadow(a),a.fill(),this.p.border&&(this.clearShadow(a),a.lineWidth=this.p.border,a.stroke())},drawSquare:function(a){this.addShadow(a),this.p.fill&&a.fillRect(-this.p.cx,-this.p.cy,this.p.w,this.p.h),this.p.border&&(this.clearShadow(a),a.lineWidth=this.p.border,a.strokeRect(-this.p.cx,-this.p.cy,this.p.w,this.p.h))},draw:function(a){return this.p.hidden?!1:void((this.p.border||this.p.fill)&&(a.globalAlpha=this.p.opacity,1===this.p.frame&&this.p.highlight?a.fillStyle=this.p.highlight:a.fillStyle=this.p.fill,a.strokeStyle=this.p.stroke,this.p.radius>0?this.drawRadius(a):this.drawSquare(a)))}}),b.UI.Text=b.Sprite.extend("UI.Text",{init:function(a,c){this._super(b._defaults(a||{},c),{type:b.SPRITE_UI,size:24,lineHeight:1.2,align:"center"}),this.p.label&&this.calcSize()},calcSize:function(){var a=this.p;this.setFont(b.ctx),this.splitLabel=a.label.split("\n");a.w=0;for(var c=0;c<this.splitLabel.length;c++){var d=b.ctx.measureText(this.splitLabel[c]);d.width>a.w&&(a.w=d.width)}a.lineHeightPx=a.size*a.lineHeight,a.h=a.lineHeightPx*this.splitLabel.length,a.halfLeading=.5*a.size*Math.max(0,a.lineHeight-1),a.cy=0,"center"===a.align?(a.cx=a.w/2,a.points=[[-a.cx,0],[a.cx,0],[a.cx,a.h],[-a.cx,a.h]]):"right"===a.align?(a.cx=a.w,a.points=[[-a.w,0],[0,0],[0,a.h],[-a.w,a.h]]):(a.cx=0,a.points=[[0,0],[a.w,0],[a.w,a.h],[0,a.h]])},prerender:function(){this.p.oldLabel!==this.p.label&&(this.p.oldLabel=this.p.label,this.calcSize(),this.el.width=this.p.w,this.el.height=4*this.p.h,this.ctx.clearRect(0,0,this.p.w,this.p.h),this.ctx.fillStyle="#FF0",this.ctx.fillRect(0,0,this.p.w,this.p.h/2),this.setFont(this.ctx),this.ctx.fillText(this.p.label,0,0))},draw:function(a){var b=this.p;if(0!==b.opacity){b.oldLabel!==b.label&&this.calcSize(),this.setFont(a),void 0!==b.opacity&&(a.globalAlpha=b.opacity);for(var c=0;c<this.splitLabel.length;c++)b.outlineWidth&&a.strokeText(this.splitLabel[c],0,b.halfLeading+c*b.lineHeightPx),a.fillText(this.splitLabel[c],0,b.halfLeading+c*b.lineHeightPx)}},asset:function(){return this.el},setFont:function(a){a.textBaseline="top",a.font=this.font(),a.fillStyle=this.p.color||"black",a.textAlign=this.p.align||"left",a.strokeStyle=this.p.outlineColor||"black",a.lineWidth=this.p.outlineWidth||0},font:function(){return this.fontString?this.fontString:(this.fontString=(this.p.weight||"800")+" "+(this.p.size||24)+"px "+(this.p.family||"Arial"),this.fontString)}}),b.UI.Button=b.UI.Container.extend("UI.Button",{init:function(a,c,d){if(this._super(b._defaults(a||{},d),{type:b.SPRITE_UI|b.SPRITE_DEFAULT,keyActionName:null}),this.p.label&&(!this.p.w||!this.p.h)){b.ctx.save(),this.setFont(b.ctx);var e=b.ctx.measureText(this.p.label);b.ctx.restore(),this.p.h||(this.p.h=44),this.p.w||(this.p.w=e.width+20)}isNaN(this.p.cx)&&(this.p.cx=this.p.w/2),isNaN(this.p.cy)&&(this.p.cy=this.p.h/2),this.callback=c,this.on("touch",this,"highlight"),this.on("touchEnd",this,"push"),this.p.keyActionName&&b.input.on(this.p.keyActionName,this,"push")},highlight:function(){"undefined"!=typeof this.sheet()&&this.sheet().frames>1&&(this.p.frame=1)},push:function(){this.p.frame=0,this.callback&&this.callback(),this.trigger("click")},draw:function(a){this._super(a),(this.p.asset||this.p.sheet)&&b.Sprite.prototype.draw.call(this,a),this.p.label&&(a.save(),this.setFont(a),a.fillText(this.p.label,0,0),a.restore())},setFont:function(a){a.textBaseline="middle",a.font=this.p.font||"400 24px arial",a.fillStyle=this.p.fontColor||"black",a.textAlign="center"}}),b.UI.IFrame=b.Sprite.extend("UI.IFrame",{init:function(a){this._super(a,{opacity:1,type:b.SPRITE_UI|b.SPRITE_DEFAULT}),b.wrapper.style.overflow="hidden",this.iframe=document.createElement("IFRAME"),this.iframe.setAttribute("src",this.p.url),this.iframe.style.position="absolute",this.iframe.style.zIndex=500,this.iframe.setAttribute("width",this.p.w),this.iframe.setAttribute("height",this.p.h),this.iframe.setAttribute("frameborder",0),this.p.background&&(this.iframe.style.backgroundColor=this.p.background),b.wrapper.appendChild(this.iframe),this.on("inserted",function(a){this.positionIFrame(),a.on("destroyed",this,"remove")})},positionIFrame:function(){var a=this.p.x,b=this.p.y;this.stage.viewport&&(a-=this.stage.viewport.x,b-=this.stage.viewport.y),(this.oldX!==a||this.oldY!==b||this.oldOpacity!==this.p.opacity)&&(this.iframe.style.top=b-this.p.cy+"px",this.iframe.style.left=a-this.p.cx+"px",this.iframe.style.opacity=this.p.opacity,this.oldX=a,this.oldY=b,this.oldOpacity=this.p.opacity)},step:function(a){this._super(a),this.positionIFrame()},remove:function(){this.iframe&&(b.wrapper.removeChild(this.iframe),this.iframe=null)}}),b.UI.HTMLElement=b.Sprite.extend("UI.HTMLElement",{init:function(a){this._super(a,{opacity:1,type:b.SPRITE_UI}),b.wrapper.style.overflow="hidden",this.el=document.createElement("div"),this.el.innerHTML=this.p.html,b.wrapper.appendChild(this.el),this.on("inserted",function(a){this.position(),a.on("destroyed",this,"remove"),a.on("clear",this,"remove")})},position:function(){},step:function(a){this._super(a),this.position()},remove:function(){this.el&&(b.wrapper.removeChild(this.el),this.el=null)}}),b.UI.VerticalLayout=b.Sprite.extend("UI.VerticalLayout",{init:function(a){this.children=[],this._super(a,{type:0})},insert:function(a){return this.stage.insert(a,this),this.relayout(),a},relayout:function(){for(var a=0,b=0;b<this.children.length;b++)a+=this.children[b].p.h||0;this.p.h-a}})}};"undefined"==typeof Quintus?module.exports=quintusUI:quintusUI(Quintus);