/*! Quintus - v0.1.5 - 2013-08-04
* http://html5quintus.com
* Copyright (c) 2013 Pascal Rettig; Licensed MIT, GPLv2 */
var Quintus=function a(b){var c=function(a,b,d){return c.select(a,b,d)};c.select=function(){},c.include=function(b){return c._each(c._normalizeArg(b),function(b){var d=a[b]||b;if(!c._isFunction(d))throw"Invalid Module:"+b;d(c)}),c},c._normalizeArg=function(a){return c._isString(a)&&(a=a.replace(/\s+/g,"").split(",")),c._isArray(a)||(a=[a]),a},c._extend=function(a,b){if(!b)return a;for(var c in b)a[c]=b[c];return a},c._clone=function(a){return c._extend({},a)},c._defaults=function(a,b){if(!b)return a;for(var c in b)void 0===a[c]&&(a[c]=b[c]);return a},c._has=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},c._isString=function(a){return"string"==typeof a},c._isNumber=function(a){return"[object Number]"===Object.prototype.toString.call(a)},c._isFunction=function(a){return"[object Function]"===Object.prototype.toString.call(a)},c._isObject=function(a){return"[object Object]"===Object.prototype.toString.call(a)},c._isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)},c._isUndefined=function(a){return void 0===a},c._popProperty=function(a,b){var c=a[b];return delete a[b],c},c._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)},c._invoke=function(a,b,c,d){if(null!=a)for(var e=0,f=a.length;f>e;e++)a[e][b](c,d)},c._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}},c._map=function(a,b,d){var e=[];return null==a?e:a.map?a.map(b,d):(c._each(a,function(a,c,f){e[e.length]=b.call(d,a,c,f)}),a.length===+a.length&&(e.length=a.length),e)},c._uniq=function(a){a=a.slice().sort();for(var b=[],c=null,d=0;de;)f[e++]=a,a+=c;return f};var d=0;return c._uniqueId=function(){return d++},c.options={imagePath:"images/",audioPath:"audio/",dataPath:"data/",audioSupported:["mp3","ogg"],sound:!0,frameTimeLimit:100},b&&c._extend(c.options,b),c.gameLoop=function(a){return c.lastGameLoopFrame=(new Date).getTime(),c.loop=!0,c._loopFrame=0,c.gameLoopCallbackWrapper=function(){var b=(new Date).getTime();c._loopFrame++,c.loop=window.requestAnimationFrame(c.gameLoopCallbackWrapper);var d=b-c.lastGameLoopFrame;d>c.options.frameTimeLimit&&(d=c.options.frameTimeLimit),a.apply(c,[d/1e3]),c.lastGameLoopFrame=b},window.requestAnimationFrame(c.gameLoopCallbackWrapper),c},c.pauseGame=function(){c.loop&&window.cancelAnimationFrame(c.loop),c.loop=null},c.unpauseGame=function(){c.loop||(c.lastGameLoopFrame=(new Date).getTime(),c.loop=window.requestAnimationFrame(c.gameLoopCallbackWrapper))},function(){var a=!1,b=/xyz/.test(function(){})?/\b_super\b/:/.*/;c.Class=function(){},c.Class.prototype.isA=function(a){return this.className===a},c.Class.extend=function(d,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)}c._isString(d)||(f=e,e=d,d=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=c.Class.extend,f&&c._extend(h,f),d&&(c[d]=h,h.prototype.className=d,h.className=d),h}}(),c.Class.extend("Evented",{on:function(a,b,d){if(c._isArray(a)||-1!==a.indexOf(",")){a=c._normalizeArg(a);for(var e=0;ec;c++){var e=this.listeners[a][c];e[1].call(e[0],b)}},off:function(a,b,d){if(b){c._isString(d)&&b[d]&&(d=b[d]);var e=this.listeners&&this.listeners[a];if(e)for(var f=e.length-1;f>=0;f--)e[f][0]===b&&(d&&d!==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)}}}),c.components={},c.Evented.extend("Component",{init:function(a){this.entity=a,this.extend&&c._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=c._keys(this.extend),b=0,d=a.length;d>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()}}),c.Evented.extend("GameObject",{has:function(a){return this[a]?!0:!1},add:function(a){a=c._normalizeArg(a),this.activeComponents||(this.activeComponents=[]);for(var b=0,d=a.length;d>b;b++){var e=a[b],f=c.components[e];if(!this.has(e)&&f){var g=new f(this);this.trigger("addComponent",g)}}return this},del:function(a){a=c._normalizeArg(a);for(var b=0,d=a.length;d>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())}}),c.component=function(a,b){return b?(b.name=a,b.componentName="."+a,c.components[a]=c.Component.extend(a+"Component",b)):c.components[a]},c.GameObject.extend("GameState",{init:function(a){this.p=c._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){c._isObject(a)?c._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]}}),c.state=new c.GameState,c.reset=function(){c.state.reset()},c.touchDevice="ontouchstart"in document,c.setup=function(a,b){c._isObject(a)&&(b=a,a=null),b=b||{},a=a||"quintus",c.el=c._isString(a)?document.getElementById(a):a,c.el||(c.el=document.createElement("canvas"),c.el.width=b.width||320,c.el.height=b.height||420,c.el.id=a,document.body.appendChild(c.el));var d=parseInt(c.el.width,10),e=parseInt(c.el.height,10),f=b.maxWidth||5e3,g=b.maxHeight||5e3,h=b.resampleWidth,i=b.resampleHeight,j=b.upsampleWidth,k=b.upsampleHeight;b.maximize===!0||c.touchDevice&&"touch"===b.maximize?(document.body.style.padding=0,document.body.style.margin=0,d=Math.min(window.innerWidth,f),e=Math.min(window.innerHeight-5,g),c.touchDevice&&(c.el.style.height=2*e+"px",window.scrollTo(0,1),d=Math.min(window.innerWidth,f),e=Math.min(window.innerHeight,g))):c.touchDevice&&window.scrollTo(0,1),j&&j>=d||k&&k>=e?(c.el.style.height=e+"px",c.el.style.width=d+"px",c.el.width=2*d,c.el.height=2*e):(h&&d>h||i&&e>i)&&c.touchDevice?(c.el.style.height=e+"px",c.el.style.width=d+"px",c.el.width=d/2,c.el.height=e/2):(c.el.style.height=e+"px",c.el.style.width=d+"px",c.el.width=d,c.el.height=e);var l=c.el.parentNode;return l&&(c.wrapper=document.createElement("div"),c.wrapper.id=a+"_container",c.wrapper.style.width=d+"px",c.wrapper.style.margin="0 auto",c.wrapper.style.position="relative",l.insertBefore(c.wrapper,c.el),c.wrapper.appendChild(c.el)),c.el.style.position="relative",c.ctx=c.el.getContext&&c.el.getContext("2d"),c.width=parseInt(c.el.width,10),c.height=parseInt(c.el.height,10),c.cssWidth=d,c.cssHeight=e,window.addEventListener("orientationchange",function(){setTimeout(function(){window.scrollTo(0,1)},0)}),c},c.clear=function(){c.clearColor?(c.ctx.globalAlpha=1,c.ctx.fillStyle=c.clearColor,c.ctx.fillRect(0,0,c.width,c.height)):c.ctx.clearRect(0,0,c.width,c.height)},c.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)},c.assetTypes={png:"Image",jpg:"Image",gif:"Image",jpeg:"Image",ogg:"Audio",wav:"Audio",m4a:"Audio",mp3:"Audio"},c.assetType=function(a){var b=a.split("."),d=b[b.length-1].toLowerCase(),e=c.assetTypes[d];return"Audio"===e&&c.audio&&"WebAudio"===c.audio.type&&(e="WebAudio"),e||"Other"},c.assetUrl=function(a,b){var d="";return c.options.development&&(d=(/\?/.test(b)?"&":"?")+"_t="+(new Date).getTime()),/^https?:\/\//.test(b)||"/"===b[0]?b+d:a+b+d},c.loadAssetImage=function(a,b,d,e){var f=new Image;f.onload=function(){d(a,f)},f.onerror=e,f.src=c.assetUrl(c.options.imagePath,b)},c.audioMimeTypes={mp3:"audio/mpeg",ogg:'audio/ogg; codecs="vorbis"',m4a:"audio/m4a",wav:"audio/wav"},c._audioAssetExtension=function(){if(c._audioAssetPreferredExtension)return c._audioAssetPreferredExtension;var a=new Audio;return c._audioAssetPreferredExtension=c._detect(c.options.audioSupported,function(b){return a.canPlayType(c.audioMimeTypes[b])?b:null})},c.loadAssetAudio=function(a,b,d,e){if(!document.createElement("audio").play||!c.options.sound)return d(a,null),void 0;var f=c._removeExtension(b),g=c._audioAssetExtension(),h=new Audio;return g?(h.addEventListener("error",e),c.touchDevice||h.addEventListener("canplaythrough",function(){d(a,h)}),h.src=c.assetUrl(c.options.audioPath,f+"."+g),h.load(),c.touchDevice&&d(a,h),void 0):(d(a,null),void 0)},c.loadAssetWebAudio=function(a,b,d,e){var f=new XMLHttpRequest,g=c._removeExtension(b),h=c._audioAssetExtension();f.open("GET",c.assetUrl(c.options.audioPath,g+"."+h),!0),f.responseType="arraybuffer",f.onload=function(){f.response,c.audioContext.decodeAudioData(f.response,function(b){d(a,b)},e)},f.send()},c.loadAssetOther=function(a,b,d,e){var f=new XMLHttpRequest,g=b.split("."),h=g[g.length-1].toLowerCase();f.onreadystatechange=function(){4===f.readyState&&(200===f.status?"json"===h?d(a,JSON.parse(f.responseText)):d(a,f.responseText):e())},f.open("GET",c.assetUrl(c.options.dataPath,b),!0),f.send(null)},c._removeExtension=function(a){return a.replace(/\.(\w{3,4})$/,"")},c.assets={},c.asset=function(a){return c.assets[a]},c.load=function(a,b,d){var e={};d||(d={});var f=d.progressCallback,g=!1,h=function(a){g=!0,(d.errorCallback||function(a){throw"Error Loading: "+a})(a)};c._isString(a)&&(a=c._normalizeArg(a)),c._isArray(a)?c._each(a,function(a){c._isObject(a)?c._extend(e,a):e[a]=a}):e=a;var i=c._keys(e).length,j=i,k=function(a,d,e){g||((!c.assets[a]||e)&&(c.assets[a]=d,j--,f&&f(i-j,i)),0===j&&b&&b.apply(c))};c._each(e,function(a,b){var d=c.assetType(a);c.assets[b]?k(b,c.assets[b],!0):c["loadAsset"+d](b,a,k,function(){h(a)})})},c.preloads=[],c.preload=function(a,b){c._isFunction(a)?(c.load(c._uniq(c.preloads),a,b),c.preloads=[]):c.preloads=c.preloads.concat(a)},c.matrices2d=[],c.matrix2d=function(){return c.matrices2d.length>0?c.matrices2d.pop().identity():new c.Matrix2D},c.Matrix2D=c.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 c.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])}}),c};!function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;cm;m++){e[m]=[];for(var n=0;i>n;n++){var o=k[l];e[m].push(parseInt(o.getAttribute("gid")-1)),l++}}}this.p.tiles=e,this.p.rows=e.length,this.p.cols=e[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]},setTile:function(a,b,c){var d=this.p,e=Math.floor(a/d.blockTileW),f=Math.floor(b/d.blockTileH);e>=0&&f>=0&&e0},collidableTile:function(a){return a>0},collide:function(b){var c,d=this.p,e=Math.floor((b.p.x-b.p.cx-d.x)/d.tileW),f=Math.floor((b.p.y-b.p.cy-d.y)/d.tileH),g=Math.ceil((b.p.x-b.p.cx+b.p.w-d.x)/d.tileW),h=Math.ceil((b.p.y-b.p.cy+b.p.h-d.y)/d.tileH),i=this.collisionObject,j=this.collisionNormal;j.collided=!1;for(var k=f;h>=k;k++)for(var l=e;g>=l;l++)this.tilePresent(l,k)&&(i.p.x=l*d.tileW+d.x+d.tileW/2,i.p.y=k*d.tileH+d.y+d.tileH/2,c=a.collision(b,i),c&&c.magnitude>0&&(!j.collided||j.magnitudef||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=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){var b=this.entity,c=b.p;if(a.obj.p&&a.obj.p.sensor)return a.obj.trigger("sensor",b),void 0;a.impact=0;var d=Math.abs(c.vx),e=Math.abs(c.vy);c.x-=a.separate[0],c.y-=a.separate[1],a.normalY<-.3&&(c.vy>0&&(c.vy=0),a.impact=e,b.trigger("bump.bottom",a)),a.normalY>.3&&(c.vy<0&&(c.vy=0),a.impact=e,b.trigger("bump.top",a)),a.normalX<-.3&&(c.vx>0&&(c.vx=0),a.impact=d,b.trigger("bump.right",a)),a.normalX>.3&&(c.vx<0&&(c.vx=0),a.impact=d,b.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},goRight:function(a){this.entity.p.vx=a.impact}})},Quintus.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){this.animation.play(a,b)}},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),e.next&&this.play(e.next,e.nextPriority),void 0;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]}},play:function(a,b){var c=this.entity,d=c.p;b=b||0,a!==d.animation&&b>=d.animationPriority&&(d.animation=a,d.animationChanged=!0,d.animationTime=0,d.animationFrame=0,d.animationPriority=b,c.trigger("anim"),c.trigger("anim."+d.animation))}}),a.Sprite.extend("Repeater",{init:function(b){this._super(a._defaults(b,{speedX:1,speedY:1,repeatY:!0,repeatX:!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=this.p,g=this.asset(),h=this.sheet(),i=this.stage.viewport?this.stage.viewport.scale:1,j=this.stage.viewport?this.stage.viewport.x:0,k=this.stage.viewport?this.stage.viewport.y:0,l=f.x+j*this.p.speedX,m=f.y+k*this.p.speedY;for(f.repeatX?(c=Math.floor(-l%f.repeatW),c>0&&(c-=f.repeatW)):c=f.x-j,f.repeatY?(d=Math.floor(-m%f.repeatH),d>0&&(d-=f.repeatH)):d=f.y-k,e=c;da._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;bd)){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;bd)){c&&c.debounce?a.audio.active[b]=d+c.debounce:delete a.audio.active[b];for(var e=0;e=d)||(a.audio.channels[e].channel.pause(),a.audio.channels[e].loop=!1)}}},Quintus.Input=function(a){var b={LEFT:37,RIGHT:39,SPACE:32,UP:38,DOWN:40,Z:90,X:88},c={LEFT:"left",RIGHT:"right",UP:"up",DOWN:"down",SPACE:"fire",Z:"fire",X:"action"},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},keyboardControls:function(b){b=b||c,a._each(b,function(a,b){this.bindKey(b,a)},a.input),this.enableKeyboard()},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.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.el.focus(),this.keyboardEnabled=!0,void 0)},_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=0,f=b.controls.length;f>e;e++)if(d.xe;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},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),this.touchEnabled=!0,void 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},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.xe;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;oe;e++){var g=d.changedTouches[e];if(g.identifier===c.joypadTouch){for(var h=0;h0&&(a.inputs.up||a.inputs.action)&&(c.vy=c.jumpSpeed,c.landed=-b),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(){var a=this.entity.p;a.stepping&&(a.stepping=!1,a.x=a.origX,a.y=a.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))}})},Quintus.Scenes=function(a){a.scenes={},a.stages=[],a.Scene=a.Class.extend({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)),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;sr&&(k=r),r>l&&(l=r);for(m=c(x[0]),n=m,t=1;tr&&(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),a._generateCollisionPoints(b),a._generateCollisionPoints(c),(e=d(b,c))?(f=d(c,b,!0))?(g=f.magnitudeh+d.h||e+c.wg+d.w)},a.Stage=a.GameObject.extend({defaults:{sort:!1,gridW:400,gridH:400},init:function(b,c){this.scene=b,this.items=[],this.lists={},this.index={},this.removeList=[],this.grid={},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(stage.options.asset),d=0;db;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},addToLists:function(a,b){for(var c=0;c0&&(d=this._collisionLayer.collide(b));)d.obj=this._collisionLayer,i||(b.trigger("hit",d),b.trigger("hit.collision",d)),this.regrid(b),h--;for(h=g;h>0&&(e=this.gridTest(b,f,this._collisionLayer));){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)}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((!this._collisionLayer||a!==this._collisionLayer)&&(a.p.type||b)){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))}},updateSprites:function(b,c,d){for(var e,f=0,g=b.length;g>f;f++)e=b[f],(d||!e.container)&&(e.update(c),a._generateCollisionPoints(e),this.regrid(e))},step:function(a){if(this.paused)return!1;if(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.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(),b&&f.loadScene(),a.activeStage=0,a.loop||a.gameLoop(a.stageGameLoop),f},a.stageGameLoop=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);for(a.ctx&&a.clear(),c=0,d=a.stages.length;d>c;c++)a.activeStage=c,e=a.stage(),e&&e.render(a.ctx);a.activeStage=0,a.input&&a.ctx&&a.input.drawCanvas(a.ctx)},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}},Quintus.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}),d&&a._extend(this,d),this.cols=this.cols||Math.floor(this.w/this.tilew)},fx:function(a){return Math.floor(a%this.cols*this.tilew+this.sx)},fy:function(a){return Math.floor(Math.floor(a/this.cols)*this.tileh+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?(a.sheets[b]=new a.SpriteSheet(b,c,d),void 0):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.origScale!==c.angle){d.origX=c.x,d.origY=c.y,d.origScale=c.scale,d.origAngle=c.angle,b.refreshMatrix();var e=b.container||a._nullContainer;d.x=e.matrix.transformX(c.x,c.y),d.y=e.matrix.transformY(c.x,c.y),d.angle=c.angle+e.c.angle,d.scale=(e.c.scale||1)*(c.scale||1);for(var f=1/0,g=1/0,h=-1/0,i=-1/0,j=0;jk&&(f=k),k>h&&(h=k),g>l&&(g=l),l>i&&(i=l)}f===h&&(h+=1),g===i&&(i+=1),d.cx=d.x-f,d.cy=d.y-g,d.w=h-f,d.h=i-g}}},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},c),this.matrix=new a.Matrix2D,this.children=[],a._extend(this.p,b),this.size(),this.p.id=this.p.id||a._uniqueId(),this.c={points:[]},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,c&&(this.size(!0),a._generatePoints(this,!0)),void 0):a.asset(this.p.asset)},sheet:function(b,c){return b?(this.p.sheet=b,c&&(this.size(!0),a._generatePoints(this,!0)),void 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||(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=this.container.p.w/2,this.p.y=this.container.p.h/2):(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)},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;c0&&this.stage.updateSprites(this.children,a,!0)},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)}}),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},Quintus.Touch=function(a){if(a._isUndefined(Quintus.Sprites))throw"Quintus.Touch requires Quintus.Sprites Module";var b=[0],c=0;a.Evented.extend("TouchSystem",{init:function(){var b=this;this.boundTouch=function(a){b.touch(a)},this.boundDrag=function(a){b.drag(a)},this.boundEnd=function(a){b.touchEnd(a)},a.el.addEventListener("touchstart",this.boundTouch),a.el.addEventListener("mousedown",this.boundTouch),a.el.addEventListener("touchmove",this.boundDrag),a.el.addEventListener("mousemove",this.boundDrag),a.el.addEventListener("touchend",this.boundEnd),a.el.addEventListener("mouseup",this.boundEnd),a.el.addEventListener("touchcancel",this.boundEnd),this.touchPos=new a.Evented,this.touchPos.grid={},this.touchPos.p={w:1,h:1,cx:0,cy:0},this.activeTouches={},this.touchedObjects={}},destroy:function(){a.el.removeEventListener("touchstart",this.boundTouch),a.el.removeEventListener("mousedown",this.boundTouch),a.el.removeEventListener("touchmove",this.boundDrag),a.el.removeEventListener("mousemove",this.boundDrag),a.el.removeEventListener("touchend",this.boundEnd),a.el.removeEventListener("mouseup",this.boundEnd),a.el.removeEventListener("touchcancel",this.boundEnd)},normalizeTouch:function(b,c){var d=b.offsetX,e=b.offsetY;if((a._isUndefined(d)||a._isUndefined(e))&&(d=b.layerX,e=b.layerY),a._isUndefined(d)||a._isUndefined(e)){if(void 0===a.touch.offsetX){a.touch.offsetX=0,a.touch.offsetY=0;var f=a.el;do a.touch.offsetX+=f.offsetLeft,a.touch.offsetY+=f.offsetTop;while(f=f.offsetParent)}d=b.pageX-a.touch.offsetX,e=b.pageY-a.touch.offsetY}return this.touchPos.p.ox=this.touchPos.p.px=d/a.cssWidth*a.width,this.touchPos.p.oy=this.touchPos.p.py=e/a.cssHeight*a.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(d){for(var e=d.changedTouches||[d],f=0;fi&&(c=i),d>j&&(d=j),k>e&&(e=k),l>f&&(f=l)}this.p.cx=-c+b,this.p.cy=-d+a,this.p.w=e-c+2*b,this.p.h=f-d+2*a}},addShadow:function(b){if(this.p.shadow){var c=a._isNumber(this.p.shadow)?this.p.shadow:5;b.shadowOffsetX=c,b.shadowOffsetY=c,b.shadowColor=this.p.shadowColor||"rgba(0,0,50,0.1)"}},clearShadow:function(a){a.shadowColor="transparent"},drawRadius:function(b){a.UI.roundRect(b,this.p),this.addShadow(b),b.fill(),this.p.border&&(this.clearShadow(b),b.lineWidth=this.p.border,b.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:((this.p.border||this.p.fill)&&(a.globalAlpha=this.p.opacity,a.fillStyle=1===this.p.frame&&this.p.highlight?this.p.highlight:this.p.fill,a.strokeStyle=this.p.stroke,this.p.radius>0?this.drawRadius(a):this.drawSquare(a)),void 0)}}),a.UI.Text=a.Sprite.extend("UI.Text",{init:function(b,c){this._super(a._defaults(b||{},c),{type:a.SPRITE_UI,size:24}),this.p.label&&this.calcSize()},calcSize:function(){this.setFont(a.ctx),this.splitLabel=this.p.label.split("\n");for(var b="",c=0;cb.length&&(b=this.splitLabel[c]);var d=a.ctx.measureText(b);this.p.h=1.2*(this.p.size||24)*this.splitLabel.length,this.p.w=d.width,this.p.cx=this.p.w/2,this.p.cy=this.p.h/2},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){if(0!==this.p.opacity){this.p.oldLabel!==this.p.label&&this.calcSize(),this.setFont(a),void 0!==this.p.opacity&&(a.globalAlpha=this.p.opacity);for(var b=0;b1)&&(this.p.frame=1)},push:function(){this.p.frame=0,this.callback&&this.callback(),this.trigger("click")},draw:function(b){this._super(b),(this.p.asset||this.p.sheet)&&a.Sprite.prototype.draw.call(this,b),this.p.label&&(b.save(),this.setFont(b),b.fillText(this.p.label,0,0),b.restore())},setFont:function(a){a.textBaseline="middle",a.font=this.p.font||"400 24px arial",a.fillStyle=this.p.fontColor||"black",a.textAlign="center"}}),a.UI.IFrame=a.Sprite.extend("UI.IFrame",{init:function(b){this._super(b,{opacity:1,type:a.SPRITE_UI|a.SPRITE_DEFAULT}),a.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),a.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&&(a.wrapper.removeChild(this.iframe),this.iframe=null)}}),a.UI.HTMLElement=a.Sprite.extend("UI.HTMLElement",{init:function(b){this._super(b,{opacity:1,type:a.SPRITE_UI}),a.wrapper.style.overflow="hidden",this.el=document.createElement("div"),this.el.innerHTML=this.p.html,a.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&&(a.wrapper.removeChild(this.el),this.el=null)}}),a.UI.VerticalLayout=a.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