-
Notifications
You must be signed in to change notification settings - Fork 73
/
jaws-min.js
2 lines (2 loc) · 51.2 KB
/
jaws-min.js
1
2
var jaws=function(t){function e(e){t.mouse_x=e.pageX||e.clientX,t.mouse_y=e.pageY||e.clientY;var i=t.canvas?t.canvas:t.dom;t.mouse_x-=i.offsetLeft,t.mouse_y-=i.offsetTop}var i,s;return t.SpriteList=function(){throw"To use SpriteList() you need to include src/extras/sprite_list.js"},t.Audio=function(){throw"To use jaws.Audio() you need to include src/extras/audio.js"},t.title=function(e){return t.isString(e)?e?i.innerHTML=e:i.innerHTML:void t.log.error("jaws.title: Passed in value is not a String.")},t.unpack=function(){var e=["Sprite","SpriteList","Animation","Viewport","SpriteSheet","Parallax","TileMap","pressed","QuadTree"];e.forEach(function(e){window[e]?t.log.warn("jaws.unpack: "+e+" already exists in global namespace."):window[e]=t[e]})},t.log=function(e,i){t.isString(e)||(e=JSON.stringify(e)),t.log.on&&(s&&t.log.use_log_element&&(i?s.innerHTML+=e+"<br />":s.innerHTML=e),console.log&&t.log.use_console&&console.log("JawsJS: ",e))},t.log.on=!0,t.log.use_console=!1,t.log.use_log_element=!0,t.log.warn=function(e){console.warn&&t.log.use_console&&t.log.on?console.warn(e):t.log("[WARNING]: "+JSON.stringify(e),!0)},t.log.error=function(e){console.error&&t.log.use_console&&t.log.on?console.error(e):t.log("[ERROR]: "+JSON.stringify(e),!0)},t.log.info=function(e){console.info&&t.log.use_console&&t.log.on?console.info(e):t.log("[INFO]: "+JSON.stringify(e),!0)},t.log.debug=function(e){console.debug&&t.log.use_console&&t.log.on?console.debug(e):t.log("[DEBUG]: "+JSON.stringify(e),!0)},t.log.clear=function(){s&&(s.innerHTML=""),console.clear&&console.clear()},t.init=function(o){i=document.getElementsByTagName("title")[0],t.url_parameters=t.getUrlParameters(),t.canvas=document.getElementsByTagName("canvas")[0],t.canvas||(t.dom=document.getElementById("canvas")),t.canvas?t.context=t.canvas.getContext("2d"):t.dom?t.dom.style.position="relative":(t.canvas=document.createElement("canvas"),t.canvas.width=o.width,t.canvas.height=o.height,t.context=t.canvas.getContext("2d"),document.body.appendChild(t.canvas)),s=document.getElementById("jaws-log"),t.url_parameters.debug&&(s||(s=document.createElement("div"),s.id="jaws-log",s.style.cssText="overflow: auto; color: #aaaaaa; width: 300px; height: 150px; margin: 40px auto 0px auto; padding: 5px; border: #444444 1px solid; clear: both; font: 10px verdana; text-align: left;",document.body.appendChild(s))),t.url_parameters.bust_cache&&(t.log.info("Busting cache when loading assets"),t.assets.bust_cache=!0),t.context&&t.useCrispScaling(),t.width=t.canvas?t.canvas.width:t.dom.offsetWidth,t.height=t.canvas?t.canvas.height:t.dom.offsetHeight,t.mouse_x=0,t.mouse_y=0,window.addEventListener("mousemove",e)},t.useCrispScaling=function(){t.context.imageSmoothingEnabled=!1,t.context.webkitImageSmoothingEnabled=!1,t.context.mozImageSmoothingEnabled=!1},t.useSmoothScaling=function(){t.context.imageSmoothingEnabled=!0,t.context.webkitImageSmoothingEnabled=!0,t.context.mozImageSmoothingEnabled=!0},t.start=function(e,i,s){function o(e,s){t.log.info(s+"%: "+e,!0),i.loading_screen&&t.assets.displayProgress(s)}function n(e,i){t.log.info(i+"%: Error loading asset "+e,!0)}function r(){t.log.info("all assets loaded",!0),t.switchGameState(e||window,{fps:a},s)}i||(i={});var a=i.fps||60;return void 0===i.loading_screen&&(i.loading_screen=!0),i.width||(i.width=500),i.height||(i.height=300),t.init(i),t.isFunction(e)||t.isObject(e)?t.isObject(s)||void 0===s?(i.loading_screen&&t.assets.displayProgress(0),t.log.info("setupInput()",!0),t.setupInput(),t.log.info("assets.loadAll()",!0),void(t.assets.length()>0?t.assets.loadAll({onprogress:o,onerror:n,onload:r}):r())):void t.log.error("jaws.start: The setup options for the game state is not an object."):void t.log.error("jaws.start: Passed in GameState is niether function or object")},t.switchGameState=function(e,i,s){if(void 0===i&&(i={}),t.isFunction(e)&&(e=new e),!t.isObject(e))return void t.log.error("jaws.switchGameState: Passed in GameState should be a Function or an Object.");var o=i&&i.fps||t.game_loop&&t.game_loop.fps||60,n=i.setup;t.game_loop&&t.game_loop.stop(),t.clearKeyCallbacks(),t.previous_game_state=t.game_state,t.game_state=e,t.game_loop=new t.GameLoop(e,{fps:o,setup:n},s),t.game_loop.start()},t.imageToCanvas=function(e){if(t.isCanvas(e))return e;if(!t.isImage(e))return void t.log.error("jaws.imageToCanvas: Passed in object is not an Image.");var i=document.createElement("canvas");i.src=e.src,i.width=e.width,i.height=e.height;var s=i.getContext("2d");return s.drawImage(e,0,0,e.width,e.height),i},t.forceArray=function(t){return Array.isArray(t)?t:[t]},t.clear=function(){t.context.clearRect(0,0,t.width,t.height)},t.fill=function(e){t.context.fillStyle=e,t.context.fillRect(0,0,t.width,t.height)},t.draw=function(){var e=arguments;1==e.length&&t.isArray(e[0])&&(e=e[0]);for(var i=0;i<e.length;i++)t.isArray(e[i])?t.draw(e[i]):e[i].draw&&e[i].draw()},t.update=function(){var e=arguments;1==e.length&&t.isArray(e[0])&&(e=e[0]);for(var i=0;i<e.length;i++)t.isArray(e[i])?t.update(e[i]):e[i].update&&e[i].update()},t.isImage=function(t){return"[object HTMLImageElement]"===Object.prototype.toString.call(t)},t.isCanvas=function(t){return"[object HTMLCanvasElement]"===Object.prototype.toString.call(t)},t.isDrawable=function(e){return t.isImage(e)||t.isCanvas(e)},t.isString=function(t){return"string"==typeof t||"object"==typeof t&&t.constructor===String},t.isNumber=function(t){return!isNaN(parseFloat(t))&&isFinite(t)},t.isArray=function(t){return t?!(-1===t.constructor.toString().indexOf("Array")):!1},t.isObject=function(t){return null!==t&&"object"==typeof t},t.isFunction=function(t){return"[object Function]"===Object.prototype.toString.call(t)},t.isRegExp=function(t){return t instanceof RegExp},t.isOutsideCanvas=function(e){return e.x&&e.y?e.x<0||e.y<0||e.x>t.width||e.y>t.height:void 0},t.forceInsideCanvas=function(e){e.x&&e.y&&(e.x<0&&(e.x=0),e.x>t.width&&(e.x=t.width),e.y<0&&(e.y=0),e.y>t.height&&(e.y=t.height))},t.getUrlParameters=function(){for(var t,e=[],i=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),s=0;s<i.length;s++)t=i[s].split("="),e.push(t[0]),e[t[0]]=t[1];return e},t.parseOptions=function(e,i,s){e.options=i;for(var o in i)void 0===s[o]&&t.log.warn("jaws.parseOptions: Unsupported property "+o+"for "+e.constructor);for(var o in s)t.isFunction(s[o])&&(s[o]=s[o]()),e[o]=void 0!==i[o]?i[o]:t.clone(s[o])},t.clone=function(e){return t.isArray(e)?e.slice(0):t.isObject(e)?JSON.parse(JSON.stringify(e)):e},t.imageToCanvasContext=function(e){var i=document.createElement("canvas");i.width=e.width,i.height=e.height;var s=i.getContext("2d");return t.context&&(s.imageSmoothingEnabled=t.context.mozImageSmoothingEnabled,s.webkitImageSmoothingEnabled=t.context.mozImageSmoothingEnabled,s.mozImageSmoothingEnabled=t.context.mozImageSmoothingEnabled),s.drawImage(e,0,0,i.width,i.height),s},t.retroScaleImage=function(e,i){var s=t.isImage(e)?t.imageToCanvas(e):e,o=s.getContext("2d"),n=o.getImageData(0,0,s.width,s.height).data,r=document.createElement("canvas");r.width=e.width*i,r.height=e.height*i;for(var a=r.getContext("2d"),h=a.createImageData(r.width,r.height),c=h.width,l=h.height,u=0;l>u;u+=1)for(var d=Math.floor(u/i),f=u*h.width,p=d*e.width,g=0;c>g;g+=1){var m=Math.floor(g/i),w=4*(f+g),y=4*(p+m);h.data[w]=n[y],h.data[w+1]=n[y+1],h.data[w+2]=n[y+2],h.data[w+3]=n[y+3]}return a.putImageData(h,0,0),r},t}(jaws||{});"undefined"!=typeof module&&"exports"in module&&(module.exports=jaws);var jaws=function(t){function e(){h={}}function i(t){event=t?t:window.event;var e=l[event.keyCode].split(" ");e.forEach(function(e){h[e]=!1,d[e]&&(d[e](e),t.preventDefault()),g[e]&&t.preventDefault()})}function s(t){event=t?t:window.event;var e=l[event.keyCode].split(" ");e.forEach(function(e){h[e]=!0,u[e]&&(u[e](e),t.preventDefault()),g[e]&&t.preventDefault()})}function o(t){event=t?t:window.event;var e=f[event.button];"Microsoft Internet Explorer"==navigator.appName&&(e=p[event.button]),h[e]=!0,u[e]&&(u[e](e),t.preventDefault())}function n(t){event=t?t:window.event;var e=f[event.button];"Microsoft Internet Explorer"==navigator.appName&&(e=p[event.button]),h[e]=!1,d[e]&&(d[e](e),t.preventDefault())}function r(e){event=e?e:window.event,h.left_mouse_button=!0,t.mouse_x=e.touches[0].pageX-t.canvas.offsetLeft,t.mouse_y=e.touches[0].pageY-t.canvas.offsetTop}function a(e){event=e?e:window.event,h.left_mouse_button=!1,t.mouse_x=void 0,t.mouse_y=void 0}var h={},c={},l=[],u=[],d=[],f=[],p=[];t.setupInput=function(){var h=[];h[8]="backspace",h[9]="tab",h[13]="enter",h[16]="shift",h[17]="ctrl",h[18]="alt",h[19]="pause",h[20]="capslock",h[27]="esc",h[32]="space",h[33]="pageup",h[34]="pagedown",h[35]="end",h[36]="home",h[37]="left",h[38]="up",h[39]="right",h[40]="down",h[45]="insert",h[46]="delete",h[91]="left_window_key leftwindowkey",h[92]="right_window_key rightwindowkey",h[93]="select_key selectkey",h[106]="multiply *",h[107]="add plus +",h[109]="subtract minus -",h[110]="decimalpoint",h[111]="divide /",h[144]="numlock",h[145]="scrollock",h[186]="semicolon ;",h[187]="equalsign =",h[188]="comma ,",h[189]="dash -",h[190]="period .",h[191]="forwardslash /",h[192]="graveaccent `",h[219]="openbracket [",h[220]="backslash \\",h[221]="closebracket ]",h[222]="singlequote '";var c=[];c[0]="left_mouse_button",c[1]="center_mouse_button",c[2]="right_mouse_button";var u=[];u[1]="left_mouse_button",u[2]="right_mouse_button",u[4]="center_mouse_button",f=c,p=u;for(var d=["numpad0","numpad1","numpad2","numpad3","numpad4","numpad5","numpad6","numpad7","numpad8","numpad9"],g=["f1","f2","f3","f4","f5","f6","f7","f8","f9"],m=["0","1","2","3","4","5","6","7","8","9"],w=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],y=0;m[y];y++)h[48+y]=m[y];for(var y=0;w[y];y++)h[65+y]=w[y];for(var y=0;d[y];y++)h[96+y]=d[y];for(var y=0;g[y];y++)h[112+y]=g[y];l=h,window.addEventListener("keydown",s),window.addEventListener("keyup",i);var x=t.canvas||t.dom;x.addEventListener("mousedown",o,!1),x.addEventListener("mouseup",n,!1),x.addEventListener("touchstart",r,!1),x.addEventListener("touchend",a,!1),window.addEventListener("blur",e,!1),document.oncontextmenu=function(){return!1}};var g=[];return t.preventDefaultKeys=function(){var e=arguments;1==e.length&&t.isArray(e[0])&&(e=e[0]);for(var i=0;i<e.length;i++)g[e[i]]=!0},t.pressed=function(e,i){return t.isString(e)&&(e=e.split(" ")),i?e.every(function(t){return h[t]}):e.some(function(t){return h[t]})},t.pressedWithoutRepeat=function(e,i){return t.pressed(e,i)?c[e]?void 0:(c[e]=!0,!0):(c[e]=!1,!1)},t.on_keydown=function(e,i){if(t.isArray(e))for(var s=0;e[s];s++)u[e[s]]=i;else u[e]=i},t.on_keyup=function(e,i){if(t.isArray(e))for(var s=0;e[s];s++)d[e[s]]=i;else d[e]=i},t.clearKeyCallbacks=function(){d=[],u=[]},t}(jaws||{}),jaws=function(t){function e(e){if(t.isDrawable(e)){for(var i=t.isImage(e)?t.imageToCanvas(e):e,s=i.getContext("2d"),o=s.getImageData(0,0,i.width,i.height),n=o.data,r=0;r<n.length;r+=4)255===n[r]&&0===n[r+1]&&255===n[r+2]&&(n[r+3]=0);return s.putImageData(o,0,0),i}}return t.Assets=function(){function i(e){if(t.isString(e)){var i=a.getPostfix(e);return a.file_type[i]?a.file_type[i]:i}t.log.error("jaws.assets.getType: Argument not a String with "+e)}function s(s){var o=this.asset,n=o.src,h=i(o.src);try{if("json"===h){if(4!==this.readyState)return;a.data[o.src]=JSON.parse(this.responseText)}else if("image"===h){var c=a.image_to_canvas?t.imageToCanvas(o.image):o.image;a.fuchia_to_transparent&&"bmp"===a.getPostfix(o.src)&&(c=e(c)),a.data[o.src]=c}else a.data[o.src]="audio"===h&&a.can_play[a.getPostfix(o.src)]?o.audio:"video"===h&&a.can_play[a.getPostfix(o.src)]?o.video:this.response}catch(l){t.log.error("Cannot process "+n+" (Message: "+l.message+", Name: "+l.name+")"),a.data[o.src]=null}a.loaded[n]||a.load_count++,a.loaded[n]=!0,a.loading[n]=!1,r(o,!0,s)}function o(t){a.loaded[t.src]=!0,a.loading[t.src]=!1,a.load_count++,r(t,!0)}function n(t){var e=this.asset;a.error_count++,r(e,!1,t)}function r(t,e,i){var s=parseInt((a.load_count+a.error_count)/a.src_list.length*100);e?(a.onprogress&&a.onprogress(t.src,s),t.onprogress&&void 0!==i&&t.onprogress(i)):(a.onerror&&a.onerror(t.src,s),t.onerror&&void 0!==i&&t.onerror(i)),100===s&&(a.onload&&a.onload(),a.onprogress=null,a.onerror=null,a.onload=null)}if(!(this instanceof arguments.callee))return new arguments.callee;var a=this;a.loaded=[],a.loading=[],a.src_list=[],a.data=[],a.bust_cache=!1,a.image_to_canvas=!0,a.fuchia_to_transparent=!0,a.root="",a.file_type={},a.file_type.json="json",a.file_type.wav="audio",a.file_type.mp3="audio",a.file_type.ogg="audio",a.file_type.m4a="audio",a.file_type.weba="audio",a.file_type.aac="audio",a.file_type.mka="audio",a.file_type.flac="audio",a.file_type.png="image",a.file_type.jpg="image",a.file_type.jpeg="image",a.file_type.gif="image",a.file_type.bmp="image",a.file_type.tiff="image",a.file_type.mp4="video",a.file_type.webm="video",a.file_type.ogv="video",a.file_type.mkv="video",a.can_play={};try{var h=new Audio;a.can_play.wav=!!h.canPlayType('audio/wav; codecs="1"').replace(/^no$/,""),a.can_play.ogg=!!h.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),a.can_play.mp3=!!h.canPlayType("audio/mpeg;").replace(/^no$/,""),a.can_play.m4a=!!(h.canPlayType("audio/x-m4a;")||h.canPlayType("audio/aac;")).replace(/^no$/,""),a.can_play.weba=!!h.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,""),a.can_play.aac=!!h.canPlayType("audio/aac;").replace(/^no$/,""),a.can_play.mka=!!h.canPlayType("audio/x-matroska;").replace(/^no$/,""),a.can_play.flac=!!h.canPlayType("audio/x-flac;").replace(/^no$/,"")}catch(c){}try{var l=document.createElement("video");a.can_play.mp4=!!l.canPlayType("video/mp4;").replace(/^no$/,""),a.can_play.webm=!!l.canPlayType('video/webm; codecs="vorbis"').replace(/^no$/,""),a.can_play.ogv=!!l.canPlayType('video/ogg; codecs="vorbis"').replace(/^no$/,""),a.can_play.mkv=!!l.canPlayType("video/x-matroska;").replace(/^no$/,"")}catch(c){}a.length=function(){return a.src_list.length},a.setRoot=function(t){return a.root=t,a},a.get=function(e){if(t.isArray(e))return e.map(function(t){return a.data[t]});if(!t.isString(e))return void t.log.error("jaws.get: Neither String nor Array. Incorrect URL resource "+e);if("*"===e[e.length-1])for(var i=e.replace("*",""),s=0;s<a.src_list.length;s++)if(0==a.src_list[s].indexOf(i)&&a.data[a.src_list[s]])return a.data[a.src_list[s]];return a.data[e]?a.data[e]:void t.log.warn("No such asset: "+e,!0)},a.isLoading=function(e){return t.isString(e)?a.loading[e]:void t.log.error("jaws.isLoading: Argument not a String with "+e)},a.isLoaded=function(e){return t.isString(e)?a.loaded[e]:void t.log.error("jaws.isLoaded: Argument not a String with "+e)},a.getPostfix=function(e){return t.isString(e)?e.toLowerCase().match(/.+\.([^?]+)(\?|$)/)[1]:void t.log.error("jaws.assets.getPostfix: Argument not a String with "+e)},a.add=function(e){var i=arguments;1==i.length&&t.isArray(i[0])&&(i=i[0]);for(var s=0;s<i.length;s++)t.isArray(i[s])?a.add(i[s]):t.isString(i[s])?a.src_list.push(i[s]):t.log.error("jaws.assets.add: Neither String nor Array. Incorrect URL resource "+e);return a},a.loadAll=function(e){return a.load_count=0,a.error_count=0,e.onprogress&&t.isFunction(e.onprogress)&&(a.onprogress=e.onprogress),e.onerror&&t.isFunction(e.onerror)&&(a.onerror=e.onerror),e.onload&&t.isFunction(e.onload)&&(a.onload=e.onload),a.src_list.forEach(function(t){a.load(t)}),a},a.load=function(e,r){if(r||(r={}),!t.isString(e))return void t.log.error("jaws.assets.load: Argument not a String with "+e);var h={},c="";h.src=e,h.onload=r.onload,h.onerror=r.onerror,a.loading[e]=!0;var l=RegExp("^((f|ht)tp(s)?:)?//");c=l.test(e)?h.src:a.root+h.src,a.bust_cache&&(c+="?"+parseInt(1e7*Math.random()));var u=i(h.src);if("image"===u)try{h.image=new Image,h.image.asset=h,h.image.addEventListener("load",s),h.image.addEventListener("error",n),h.image.src=c}catch(d){t.log.error("Cannot load Image resource "+c+" (Message: "+d.message+", Name: "+d.name+")")}else if(a.can_play[a.getPostfix(h.src)]){if("audio"===u)try{h.audio=new Audio,h.audio.asset=h,h.audio.addEventListener("error",n),h.audio.addEventListener("canplay",s),a.data[h.src]=h.audio,h.audio.src=c,h.audio.load()}catch(d){t.log.error("Cannot load Audio resource "+c+" (Message: "+d.message+", Name: "+d.name+")")}else if("video"===u)try{h.video=document.createElement("video"),h.video.asset=h,a.data[h.src]=h.video,h.video.setAttribute("style","display:none;"),h.video.addEventListener("error",n),h.video.addEventListener("canplay",s),document.body.appendChild(h.video),h.video.src=c,h.video.load()}catch(d){t.log.error("Cannot load Video resource "+c+" (Message: "+d.message+", Name: "+d.name+")")}}else{if("audio"===u&&!a.can_play[a.getPostfix(h.src)])return o(h),a;try{var f=new XMLHttpRequest;f.asset=h,f.onreadystatechange=s,f.onerror=n,f.open("GET",c,!0),"json"!==u&&(f.responseType="blob"),f.send(null)}catch(d){t.log.error("Cannot load "+c+" (Message: "+d.message+", Name: "+d.name+")")}}return a},a.displayProgress=function(e){t.isNumber(e)&&t.context&&(t.context.save(),t.context.fillStyle="black",t.context.fillRect(0,0,t.width,t.height),t.context.fillStyle="white",t.context.strokeStyle="white",t.context.textAlign="center",t.context.strokeRect(49,t.height/2-30-1,t.width-100+2,62),t.context.fillRect(50,t.height/2-30,(t.width-100)/100*e,60),t.context.font="11px verdana",t.context.fillText("Loading... "+e+"%",t.width/2,t.height/2-35),t.context.font="11px verdana",t.context.fillStyle="#ccc",t.context.textBaseline="bottom",t.context.fillText("powered by www.jawsjs.com",t.width/2,t.height-1),t.context.restore())}},t.assets=new t.Assets,t}(jaws||{});if("undefined"!=typeof require)var jaws=require("./core.js");var jaws=function(t){function e(t){this.size=t,this.values=new Array(this.size),this.value,this.add=function(t){if(this.values.length>this.size){this.values.splice(0,1),this.value=0;for(var e=0;this.values[e];e++)this.value+=this.values[e];this.value=this.value/this.size}return this.values.push(t),this},this.get=function(){return parseInt(this.value)}}return window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){window.setTimeout(t,16.666)}}(),t.GameLoop=function(i,s,o){if(!(this instanceof arguments.callee))return new arguments.callee(i,s);this.tick_duration=0,this.fps=0,this.ticks=0;var n,r=!1,a=!1,h=this,c=new e(20);this.runtime=function(){return this.last_tick-this.first_tick},this.start=function(){t.log.info("Game loop start",!0),this.first_tick=(new Date).getTime(),this.current_tick=(new Date).getTime(),this.last_tick=(new Date).getTime(),s.setup!==!1&&i.setup&&i.setup(o),step_delay=1e3/s.fps,60==s.fps?requestAnimFrame(this.loop):n=setInterval(this.loop,step_delay)},this.loop=function(){h.current_tick=(new Date).getTime(),h.tick_duration=h.current_tick-h.last_tick,h.fps=c.add(1e3/h.tick_duration).get(),a||r||(i.update&&i.update(),i.draw&&i.draw(),h.ticks++),60!=s.fps||a||requestAnimFrame(h.loop),h.last_tick=h.current_tick},this.pause=function(){r=!0},this.unpause=function(){r=!1},this.stop=function(){n&&clearInterval(n),a=!0}},t}(jaws||{}),jaws=function(t){var e=0;return t.Rect=function(t,i,s,o){return this instanceof arguments.callee?(this.x=t,this.y=i,this.width=s,this.height=o,this.right=t+s-e,void(this.bottom=i+o-e)):new arguments.callee(t,i,s,o)},t.Rect.prototype.getPosition=function(){return[this.x,this.y]},t.Rect.prototype.move=function(t,e){return this.x+=t,this.y+=e,this.right+=t,this.bottom+=e,this},t.Rect.prototype.moveTo=function(t,i){return this.x=t,this.y=i,this.right=this.x+this.width-e,this.bottom=this.y+this.height-e,this},t.Rect.prototype.resize=function(t,i){return this.width+=t,this.height+=i,this.right=this.x+this.width-e,this.bottom=this.y+this.height-e,this},t.Rect.prototype.clone=function(){return new t.Rect(this.x,this.y,this.width,this.height)},t.Rect.prototype.shrink=function(t,i){return this.x+=t,this.y+=i,this.width-=t+t,this.height-=i+i,this.right=this.x+this.width-e,this.bottom=this.y+this.height-e,this},t.Rect.prototype.resizeTo=function(t,i){return this.width=t,this.height=i,this.right=this.x+this.width-e,this.bottom=this.y+this.height-e,this},t.Rect.prototype.draw=function(){return t.context.strokeStyle="red",t.context.strokeRect(this.x-.5,this.y-.5,this.width,this.height),this},t.Rect.prototype.collidePoint=function(t,e){return t>=this.x&&t<=this.right&&e>=this.y&&e<=this.bottom},t.Rect.prototype.collideRect=function(t){return(this.x>=t.x&&this.x<=t.right||t.x>=this.x&&t.x<=this.right)&&(this.y>=t.y&&this.y<=t.bottom||t.y>=this.y&&t.y<=this.bottom)},t.Rect.prototype.toString=function(){return"[Rect "+this.x+", "+this.y+", "+this.width+", "+this.height+"]"},t}(jaws||{});"undefined"!=typeof module&&"exports"in module&&(module.exports=jaws.Rect);var jaws=function(jaws){return jaws.Sprite=function(t){return this instanceof arguments.callee?(this.set(t),void(this.context=t.context?t.context:jaws.context)):new arguments.callee(t)},jaws.Sprite.prototype.default_options={x:0,y:0,alpha:1,angle:0,flipped:!1,anchor_x:0,anchor_y:0,image:null,image_path:null,anchor:null,scale_image:null,damping:1,scale_x:1,scale_y:1,scale:1,color:"#ddd",width:16,height:16,_constructor:null,context:null,data:null},jaws.Sprite.prototype.set=function(t){if(jaws.isString(this.image)&&(this.image_path=this.image),jaws.parseOptions(this,t,this.default_options),this.scale&&(this.scale_x=this.scale_y=this.scale),this.image&&this.setImage(this.image),this.scale_image&&this.scaleImage(this.scale_image),this.anchor&&this.setAnchor(this.anchor),!this.image&&this.color&&this.width&&this.height){var e=document.createElement("canvas"),i=e.getContext("2d");e.width=this.width,e.height=this.height,i.fillStyle=this.color,i.fillRect(0,0,this.width,this.height),this.image=e}return this.cacheOffsets(),this},jaws.Sprite.prototype.clone=function(object){var constructor=this._constructor?eval(this._constructor):this.constructor,new_sprite=new constructor(this.attributes());return new_sprite._constructor=this._constructor||this.constructor.name,new_sprite},jaws.Sprite.prototype.setImage=function(t){var e=this;return jaws.isDrawable(t)?(this.image=t,this.cacheOffsets()):(jaws.assets.isLoaded(t)?(this.image=jaws.assets.get(t),this.cacheOffsets()):(jaws.log.warn("Image '"+t+"' not preloaded with jaws.assets.add(). Image and a working sprite.rect() will be delayed."),jaws.assets.load(t,{onload:function(){e.image=jaws.assets.get(t),e.cacheOffsets()}})),this)},jaws.Sprite.prototype.stepToWhile=function(t,e,i){var s=1,o=t<this.x?-s:s,n=e<this.y?-s:s;t=parseInt(t),e=parseInt(e);for(var r=!1,a=!1;;)if(r===!1&&(this.x!=t&&(this.x+=o),i(this)||(this.x-=o,r=!0)),a===!1&&(this.y!=e&&(this.y+=n),i(this)||(this.y-=n,a=!0)),(r||this.x==t)&&(a||this.y==e))return{x:r,y:a}},jaws.Sprite.prototype.stepWhile=function(t,e,i){return this.stepToWhile(this.x+t,this.y+e,i)},jaws.Sprite.prototype.flip=function(){return this.flipped=this.flipped?!1:!0,this},jaws.Sprite.prototype.flipTo=function(t){return this.flipped=t,this},jaws.Sprite.prototype.rotate=function(t){return this.angle+=t,this},jaws.Sprite.prototype.rotateTo=function(t){return this.angle=t,this},jaws.Sprite.prototype.moveTo=function(t,e){return jaws.isArray(t)&&void 0===e&&(e=t[1],t=t[0]),this.x=t,this.y=e,this},jaws.Sprite.prototype.move=function(t,e){return jaws.isArray(t)&&void 0===e&&(e=t[1],t=t[0]),t&&(this.x+=t),e&&(this.y+=e),this},jaws.Sprite.prototype.scaleAll=function(t){return this.scale_x*=t,this.scale_y*=t,this.cacheOffsets()},jaws.Sprite.prototype.scaleTo=function(t){return this.scale_x=this.scale_y=t,this.cacheOffsets()},jaws.Sprite.prototype.scaleWidth=function(t){return this.scale_x*=t,this.cacheOffsets()},jaws.Sprite.prototype.scaleHeight=function(t){return this.scale_y*=t,this.cacheOffsets()},jaws.Sprite.prototype.setX=function(t){return this.x=t,this},jaws.Sprite.prototype.setY=function(t){return this.y=t,this},jaws.Sprite.prototype.setTop=function(t){return this.y=t+this.top_offset,this},jaws.Sprite.prototype.setBottom=function(t){return this.y=t-this.bottom_offset,this},jaws.Sprite.prototype.setLeft=function(t){return this.x=t+this.left_offset,this},jaws.Sprite.prototype.setRight=function(t){return this.x=t-this.right_offset,this},jaws.Sprite.prototype.setWidth=function(t){return this.scale_x=t/this.image.width,this.cacheOffsets()},jaws.Sprite.prototype.setHeight=function(t){return this.scale_y=t/this.image.height,this.cacheOffsets()},jaws.Sprite.prototype.resize=function(t,e){return jaws.isArray(t)&&void 0===e&&(e=t[1],t=t[0]),this.scale_x=(this.width+t)/this.image.width,this.scale_y=(this.height+e)/this.image.height,this.cacheOffsets()},jaws.Sprite.prototype.resizeTo=function(t,e){return jaws.isArray(t)&&void 0===e&&(e=t[1],t=t[0]),this.scale_x=t/this.image.width,this.scale_y=e/this.image.height,this.cacheOffsets()},jaws.Sprite.prototype.setAnchor=function(t){var e={top_left:[0,0],left_top:[0,0],center_left:[0,.5],left_center:[0,.5],bottom_left:[0,1],left_bottom:[0,1],top_center:[.5,0],center_top:[.5,0],center_center:[.5,.5],center:[.5,.5],bottom_center:[.5,1],center_bottom:[.5,1],top_right:[1,0],right_top:[1,0],center_right:[1,.5],right_center:[1,.5],bottom_right:[1,1],right_bottom:[1,1]};return(a=e[t])&&(this.anchor_x=a[0],this.anchor_y=a[1],this.image&&this.cacheOffsets()),this},jaws.Sprite.prototype.cacheOffsets=function(){return this.image?(this.width=this.image.width*this.scale_x,this.height=this.image.height*this.scale_y,this.left_offset=this.width*this.anchor_x,this.top_offset=this.height*this.anchor_y,this.right_offset=this.width*(1-this.anchor_x),this.bottom_offset=this.height*(1-this.anchor_y),this.cached_rect&&this.cached_rect.resizeTo(this.width,this.height),this):void 0},jaws.Sprite.prototype.rect=function(){return!this.cached_rect&&this.width&&(this.cached_rect=new jaws.Rect(this.x,this.y,this.width,this.height)),this.cached_rect&&this.cached_rect.moveTo(this.x-this.left_offset,this.y-this.top_offset),this.cached_rect},jaws.Sprite.prototype.draw=function(){return this.image?(this.context.save(),this.context.translate(this.x,this.y),0!=this.angle&&jaws.context.rotate(this.angle*Math.PI/180),this.flipped&&this.context.scale(-1,1),this.context.globalAlpha=this.alpha,this.context.translate(-this.left_offset,-this.top_offset),this.context.drawImage(this.image,0,0,this.width,this.height),this.context.restore(),this):this},jaws.Sprite.prototype.scaleImage=function(t){return this.image?(this.setImage(jaws.retroScaleImage(this.image,t)),this):void 0},jaws.Sprite.prototype.asCanvasContext=function(){var t=document.createElement("canvas");t.width=this.width,t.height=this.height;var e=t.getContext("2d");return jaws.context&&(e.mozImageSmoothingEnabled=jaws.context.mozImageSmoothingEnabled),e.drawImage(this.image,0,0,this.width,this.height),e},jaws.Sprite.prototype.asCanvas=function(){var t=document.createElement("canvas");t.width=this.width,t.height=this.height;var e=t.getContext("2d");return jaws.context&&(e.mozImageSmoothingEnabled=jaws.context.mozImageSmoothingEnabled),e.drawImage(this.image,0,0,this.width,this.height),t},jaws.Sprite.prototype.toString=function(){return"[Sprite "+this.x.toFixed(2)+", "+this.y.toFixed(2)+", "+this.width+", "+this.height+"]"},jaws.Sprite.prototype.attributes=function(){var t={};return t._constructor=this._constructor||"jaws.Sprite",t.x=parseFloat(this.x.toFixed(2)),t.y=parseFloat(this.y.toFixed(2)),t.image=this.image_path,t.alpha=this.alpha,t.flipped=this.flipped,t.angle=parseFloat(this.angle.toFixed(2)),t.scale_x=this.scale_x,t.scale_y=this.scale_y,t.anchor_x=this.anchor_x,t.anchor_y=this.anchor_y,null!==this.data&&(t.data=jaws.clone(this.data)),t},jaws.Sprite.parse=function(objects){function parseArray(array){array.forEach(function(data){var constructor=data._constructor?eval(data._constructor):data.constructor;if(jaws.isFunction(constructor)){jaws.log.info("Creating "+data._constructor+"("+data.toString()+")",!0);var object=new constructor(data);object._constructor=data._constructor||data.constructor.name,sprites.push(object)}})}var sprites=[];return jaws.isArray(objects)?objects.every(function(t){return t._constructor})?parseArray(objects):sprites=objects:jaws.isString(objects)&&(parseArray(JSON.parse(objects)),jaws.log.info(objects)),sprites},jaws.Sprite.prototype.toJSON=function(){return JSON.stringify(this.attributes())},jaws}(jaws||{});"undefined"!=typeof module&&"exports"in module&&(module.exports=jaws.Sprite);var jaws=function(t){function e(t,e,i,s,o){var n=document.createElement("canvas");n.width=s,n.height=o;var r=n.getContext("2d");return r.drawImage(t,e,i,s,o,0,0,n.width,n.height),n}return t.SpriteSheet=function(i){if(!(this instanceof arguments.callee))return new arguments.callee(i);if(t.parseOptions(this,i,this.default_options),t.isString(this.image)&&!i.frame_size){var s=new RegExp("_(\\d+)x(\\d+)","g"),o=s.exec(this.image);this.frame_size=[],this.frame_size[0]=parseInt(o[1]),this.frame_size[1]=parseInt(o[2])}if(this.image=t.isDrawable(this.image)?this.image:t.assets.data[this.image],this.scale_image){var n=t.isDrawable(this.image)?this.image:t.assets.get(this.image);this.frame_size[0]*=this.scale_image,this.frame_size[1]*=this.scale_image,this.image=t.retroScaleImage(n,this.scale_image)}if(this.frames=[],"down"==this.orientation)for(var r=this.offset;r<this.image.width;r+=this.frame_size[0])for(var a=0;a<this.image.height;a+=this.frame_size[1])this.frames.push(e(this.image,r,a,this.frame_size[0],this.frame_size[1]));else for(var a=this.offset;a<this.image.height;a+=this.frame_size[1])for(var r=0;r<this.image.width;r+=this.frame_size[0])this.frames.push(e(this.image,r,a,this.frame_size[0],this.frame_size[1]))},t.SpriteSheet.prototype.default_options={image:null,orientation:"down",frame_size:[32,32],offset:0,scale_image:null},t.SpriteSheet.prototype.toString=function(){return"[SpriteSheet "+this.frames.length+" frames]"},t}(jaws||{}),jaws=function(t){return t.Animation=function(e){if(!(this instanceof arguments.callee))return new arguments.callee(e);if(t.parseOptions(this,e,this.default_options),e.sprite_sheet){var i=new t.SpriteSheet({image:e.sprite_sheet,scale_image:this.scale_image,frame_size:this.frame_size,orientation:this.orientation,offset:this.offset});this.frames=i.frames,this.frame_size=i.frame_size}if(e.scale_image){var s=t.isDrawable(e.sprite_sheet)?e.sprite_sheet:t.assets.get(e.sprite_sheet);this.frame_size[0]*=e.scale_image,this.frame_size[1]*=e.scale_image,e.sprite_sheet=t.retroScaleImage(s,e.scale_image)}if(this.current_tick=(new Date).getTime(),this.last_tick=(new Date).getTime(),this.sum_tick=0,e.subsets){this.subsets={};for(subset in e.subsets)start_stop=e.subsets[subset],this.subsets[subset]=this.slice(start_stop[0],start_stop[1])}},t.Animation.prototype.default_options={frames:[],subsets:[],frame_duration:100,index:0,loop:1,bounce:0,frame_direction:1,frame_size:null,orientation:"down",on_end:null,offset:0,scale_image:null,sprite_sheet:null},t.Animation.prototype.subset=function(t){return this.subsets[t]},t.Animation.prototype.update=function(){return this.current_tick=(new Date).getTime(),this.sum_tick+=this.current_tick-this.last_tick,this.last_tick=this.current_tick,this.sum_tick>this.frame_duration&&(this.index+=this.frame_direction,this.sum_tick=0),(this.index>=this.frames.length||this.index<0)&&(this.bounce?(this.frame_direction=-this.frame_direction,this.index+=2*this.frame_direction):this.loop?this.index=this.frame_direction<0?this.frames.length-1:0:(this.index-=this.frame_direction,this.on_end&&(this.on_end(),this.on_end=null))),this},t.Animation.prototype.slice=function(e,i){var s={};return s.frame_duration=this.frame_duration,s.loop=this.loop,s.bounce=this.bounce,s.on_end=this.on_end,s.frame_direction=this.frame_direction,s.frames=this.frames.slice().slice(e,i),new t.Animation(s)
},t.Animation.prototype.next=function(){return this.update(),this.frames[this.index]},t.Animation.prototype.atLastFrame=function(){return this.index==this.frames.length-1},t.Animation.prototype.atFirstFrame=function(){return 0==this.index},t.Animation.prototype.currentFrame=function(){return this.frames[this.index]},t.Animation.prototype.toString=function(){return"[Animation, "+this.frames.length+" frames]"},t}(jaws||{}),jaws=function(t){return t.Viewport=function(e){if(!(this instanceof arguments.callee))return new arguments.callee(e);t.parseOptions(this,e,this.default_options),this.context||(this.context=t.context),this.width||(this.width=t.width),this.height||(this.height=t.height),this.max_x||(this.max_x=t.width),this.max_y||(this.max_y=t.height);var i=this;this.move=function(t,e){t&&(this.x+=t),e&&(this.y+=e),this.verifyPosition()},this.moveTo=function(t,e){void 0!=t&&(this.x=t),void 0!=e&&(this.y=e),this.verifyPosition()},this.isOutside=function(t){return!i.isInside(t)},this.isInside=function(t){return t.x>=i.x&&t.x<=i.x+i.width&&t.y>=i.y&&t.y<=i.y+i.height},this.isPartlyInside=function(t){var e=t.rect();return e.right>=i.x&&e.x<=i.x+i.width&&e.bottom>=i.y&&t.y<=i.y+i.height},this.isLeftOf=function(t){return t.x<i.x},this.isRightOf=function(t){return t.x>i.x+i.width},this.isAbove=function(t){return t.y<i.y},this.isBelow=function(t){return t.y>i.y+i.height},this.centerAround=function(t){this.x=Math.floor(t.x-this.width/2),this.y=Math.floor(t.y-this.height/2),this.verifyPosition()},this.forceInsideVisibleArea=function(e,i){e.x<this.x+i&&(e.x=this.x+i),e.x>this.x+t.width-i&&(e.x=this.x+t.width-i),e.y<this.y+i&&(e.y=this.y+i),e.y>this.y+t.height-i&&(e.y=this.y+t.height-i)},this.forceInside=function(t,e){t.x<e&&(t.x=e),t.x>this.max_x-e&&(t.x=this.max_x-e),t.y<e&&(t.y=e),t.y>this.max_y-e&&(t.y=this.max_y-e)},this.apply=function(t){this.context.save(),this.context.translate(-this.x,-this.y),t(),this.context.restore()},this.draw=function(t){this.apply(function(){t.forEach?t.forEach(i.drawIfPartlyInside):t.draw&&i.drawIfPartlyInside(t)})},this.drawTileMap=function(t){var e=t.atRect({x:this.x,y:this.y,right:this.x+this.width,bottom:this.y+this.height});this.apply(function(){for(var t=0;t<e.length;t++)e[t].draw()})},this.drawIfPartlyInside=function(t){i.isPartlyInside(t)&&t.draw()},this.verifyPosition=function(){var t=this.max_x-this.width;this.x<0&&(this.x=0),this.x>t&&(this.x=t);var t=this.max_y-this.height;this.y<0&&(this.y=0),this.y>t&&(this.y=t)},this.moveTo(e.x||0,e.y||0)},t.Viewport.prototype.default_options={context:null,width:null,height:null,max_x:null,max_y:null,x:0,y:0},t.Viewport.prototype.toString=function(){return"[Viewport "+this.x.toFixed(2)+", "+this.y.toFixed(2)+", "+this.width+", "+this.height+"]"},t}(jaws||{});if("undefined"!=typeof require)var jaws=require("./core.js");var jaws=function(t){function e(t,e){for(var i=function(e){return void 0!==t.isSpriteList?t.at(e):t[e]},s=[],o=new Array(e),n=0;e>n;n++)o[n]=n;for(var n=e-1,r=t.length;n>=0;r=t.length){for(s.push(o.map(i));n>=0&&o[n]===r-1;)n--,r--;if(n>=0){o[n]+=1;for(var a=n+1;e>a;a++)o[a]=o[a-1]+1;n=e-1}}return s}return t.collideOneWithOne=function(e,i){return e.radius&&i.radius&&e!==i&&t.collideCircles(e,i)?!0:e.rect&&i.rect&&e!==i&&t.collideRects(e.rect(),i.rect())?!0:!1},t.collideOneWithMany=function(e,i,s){var o=[];if(s){for(var n=0;n<i.length;n++)t.collideOneWithOne(e,i[n])&&(s(e,i[n]),o.push(i[n]));return o}return i.filter(function(i){return t.collideOneWithOne(e,i)})},t.collideManyWithMany=function(i,s,o){var n=[];return i===s?e(i,2).forEach(function(e){t.collideOneWithOne(e[0],e[1])&&(o?o(e[0],e[1]):n.push([e[0],e[1]]))}):i.forEach(function(e){s.forEach(function(i){t.collideOneWithOne(e,i)&&(o?o(e,i):n.push([e,i]))})}),n},t.collideCircles=function(e,i){return t.distanceBetween(e,i)<e.radius+i.radius},t.collideRects=function(t,e){return(t.x>=e.x&&t.x<=e.right||e.x>=t.x&&e.x<=t.right)&&(t.y>=e.y&&t.y<=e.bottom||e.y>=t.y&&e.y<=t.bottom)},t.distanceBetween=function(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))},t.collide=function(e,i,s){if((e.rect||e.radius)&&i.forEach)return t.collideOneWithMany(e,i,s).length>0;if(e.forEach&&i.forEach)return t.collideManyWithMany(e,i,s).length>0;if(e.forEach&&(i.rect||i.radius))return t.collideOneWithMany(i,e,s).length>0;if(e.rect&&i.rect||e.radius&&i.radius){var o=t.collideOneWithOne(e,i);if(!s||!o)return o;s(e,i)}},t}(jaws||{});if("undefined"!=typeof require)var jaws=require("./core.js");var jaws=function(t){return t.TileMap=function(e){if(!(this instanceof arguments.callee))return new arguments.callee(e);t.parseOptions(this,e,this.default_options),this.cells=new Array(this.size[0]);for(var i=0;i<this.size[0];i++){this.cells[i]=new Array(this.size[1]);for(var s=0;s<this.size[1];s++)this.cells[i][s]=[]}},t.TileMap.prototype.default_options={cell_size:[32,32],size:[100,100],sortFunction:null},t.TileMap.prototype.clear=function(){for(var t=0;t<this.size[0];t++)for(var e=0;e<this.size[1];e++)this.cells[t][e]=[]},t.TileMap.prototype.sortCells=function(t){for(var e=0;e<this.size[0];e++)for(var i=0;i<this.size[1];i++)this.cells[e][i].sort(t)},t.TileMap.prototype.push=function(t){var e=this;if(t.forEach)return t.forEach(function(t){e.push(t)}),t;if(t.rect)return this.pushAsRect(t,t.rect());var i=parseInt(t.x/this.cell_size[0]),s=parseInt(t.y/this.cell_size[1]);return this.pushToCell(i,s,t)},t.TileMap.prototype.pushAsPoint=function(t){if(Array.isArray(t)){for(var e=0;e<t.length;e++)this.pushAsPoint(t[e]);return t}var i=parseInt(t.x/this.cell_size[0]),s=parseInt(t.y/this.cell_size[1]);return this.pushToCell(i,s,t)},t.TileMap.prototype.pushAsRect=function(t,e){for(var i=parseInt(e.x/this.cell_size[0]),s=parseInt((e.right-1)/this.cell_size[0]),o=i;s>=o;o++)for(var n=parseInt(e.y/this.cell_size[1]),r=parseInt((e.bottom-1)/this.cell_size[1]),a=n;r>=a;a++)this.pushToCell(o,a,t);return t},t.TileMap.prototype.pushToCell=function(t,e,i){return this.cells[t][e].push(i),this.sortFunction&&this.cells[t][e].sort(this.sortFunction),this},t.TileMap.prototype.at=function(t,e){var i=parseInt(t/this.cell_size[0]),s=parseInt(e/this.cell_size[1]);return this.cells[i][s]},t.TileMap.prototype.atRect=function(t){var e=[];try{var i=parseInt(t.x/this.cell_size[0]);0>i&&(i=0);var s=parseInt(t.right/this.cell_size[0]);s>=this.size[0]&&(s=this.size[0]-1);var o=parseInt(t.y/this.cell_size[1]);0>o&&(o=0);var n=parseInt(t.bottom/this.cell_size[1]);n>=this.size[1]&&(n=this.size[1]-1);for(var r=i;s>=r;r++)for(var a=o;n>=a;a++)this.cells[r][a].forEach(function(t){-1==e.indexOf(t)&&e.push(t)})}catch(h){}return e},t.TileMap.prototype.all=function(){for(var t=[],e=0;e<this.size[0];e++)for(var i=0;i<this.size[1];i++)this.cells[e][i].forEach(function(e){t.push(e)});return t},t.TileMap.prototype.cell=function(t,e){return this.cells[t][e]},t.TileMap.prototype.toString=function(){return"[TileMap "+this.size[0]+" cols, "+this.size[1]+" rows]"},t}(jaws||{});"undefined"!=typeof module&&"exports"in module&&(module.exports=jaws.TileMap);var jaws=function(t){return t.PixelMap=function(e){return this instanceof arguments.callee?(this.options=e,this.scale=e.scale||1,this.x=e.x||0,this.y=e.y||0,e.image?(this.setContext(e.image),e.scale_image&&this.setContext(t.retroScaleImage(this.context.canvas,e.scale_image)),this.width=this.context.canvas.width*this.scale,this.height=this.context.canvas.height*this.scale):t.log.warn("PixelMap needs an image to work with"),this.named_colors=[],void this.update()):new arguments.callee(e)},t.PixelMap.prototype.setContext=function(e){var e=t.isDrawable(e)?e:t.assets.get(e);this.context=t.imageToCanvasContext(e)},t.PixelMap.prototype.update=function(t,e,i,s){if((void 0===t||0>t)&&(t=0),(void 0===e||0>e)&&(e=0),(void 0===i||i>this.width)&&(i=this.width),(void 0===s||s>this.height)&&(s=this.height),0==arguments.length)this.data=this.context.getImageData(t,e,i,s).data;else for(var o=this.context.getImageData(t,e,i,s).data,n=0,r=4*this.width,a=e*this.width*4+4*t,h=4*i,c=0;s>c;c++){for(var l=0;h>l;l++)this.data[a+l]=o[n++];a+=r}},t.PixelMap.prototype.draw=function(){t.context.drawImage(this.context.canvas,this.x,this.y,this.width,this.height)},t.PixelMap.prototype.namedColorAtRect=function(t,e){for(var i=t.x,s=t.y;i<t.right-1;i++)if(this.namedColorAt(i,s)==e||void 0===e)return this.namedColorAt(i,s);for(;s<t.bottom-1;s++)if(this.namedColorAt(i,s)==e||void 0===e)return this.namedColorAt(i,s);for(;i>t.x;i--)if(this.namedColorAt(i,s)==e||void 0===e)return this.namedColorAt(i,s);for(;s>t.y;s--)if(this.namedColorAt(i,s)==e||void 0===e)return this.namedColorAt(i,s);return!1},t.PixelMap.prototype.at=function(t,e){t=parseInt(t),e=parseInt(e),0>e&&(e=0);var i=e*this.width*4+4*t,s=this.data[i],o=this.data[i+1],n=this.data[i+2],r=this.data[i+3];return[s,o,n,r]},t.PixelMap.prototype.namedColorAt=function(t,e){for(var i=this.at(t,e),s=0;s<this.named_colors.length;s++){var o=this.named_colors[s].name,n=this.named_colors[s].color;if(n[0]==i[0]&&n[1]==i[1]&&n[2]==i[2]&&n[3]==i[3])return o}},t.PixelMap.prototype.nameColor=function(t,e){this.named_colors.push({name:e,color:t})},t}(jaws||{}),jaws=function(t){return t.Parallax=function(e){return this instanceof arguments.callee?void t.parseOptions(this,e,this.default_options):new arguments.callee(e)},t.Parallax.prototype.default_options={width:function(){return t.width},height:function(){return t.height},scale:1,repeat_x:null,repeat_y:null,camera_x:0,camera_y:0,layers:[]},t.Parallax.prototype.draw=function(){for(var t,e,i=0;i<this.layers.length;i++)for(t=this.layers[i],e=this.repeat_x?-(this.camera_x/t.damping%t.width):-(this.camera_x/t.damping),t.y=this.repeat_y?-(this.camera_y/t.damping%t.height):-(this.camera_y/t.damping),t.x=e;t.y<this.height;){for(;t.x<this.width&&(t.x+t.width>=0&&t.y+t.height>=0&&t.draw(),t.x=t.x+t.width,this.repeat_x););if(t.y=t.y+t.height,t.x=e,!this.repeat_y)break}},t.Parallax.prototype.addLayer=function(e){var i=new t.ParallaxLayer(e);i.scaleAll(this.scale),this.layers.push(i)},t.Parallax.prototype.toString=function(){return"[Parallax "+this.x+", "+this.y+". "+this.layers.length+" layers]"},t.ParallaxLayer=function(e){return this instanceof arguments.callee?(this.damping=e.damping||0,void t.Sprite.call(this,e)):new arguments.callee(e)},t.ParallaxLayer.prototype=t.Sprite.prototype,t}(jaws||{}),jaws=function(jaws){return jaws.Text=function(t){return this instanceof arguments.callee?(this.set(t),t.context&&(this.context=t.context),void(t.context||jaws.context&&(this.context=jaws.context))):new arguments.callee(t)},jaws.Text.prototype.default_options={x:0,y:0,alpha:1,angle:0,anchor_x:0,anchor_y:0,anchor:"top_left",damping:1,style:"normal",fontFace:"serif",fontSize:12,color:"black",textAlign:"start",textBaseline:"alphabetic",text:"",wordWrap:!1,width:function(){return jaws.width},height:function(){return jaws.height},shadowColor:null,shadowBlur:null,shadowOffsetX:null,shadowOffsetY:null,_constructor:null},jaws.Text.prototype.set=function(t){return jaws.parseOptions(this,t,this.default_options),this.anchor&&this.setAnchor(this.anchor),this.cacheOffsets(),this},jaws.Text.prototype.clone=function(){var constructor=this._constructor?eval(this._constructor):this.constructor,new_sprite=new constructor(this.attributes());return new_sprite._constructor=this._constructor||this.constructor.name,new_sprite},jaws.Text.prototype.rotate=function(t){return this.angle+=t,this},jaws.Text.prototype.rotateTo=function(t){return this.angle=t,this},jaws.Text.prototype.moveTo=function(t,e){return this.x=t,this.y=e,this},jaws.Text.prototype.move=function(t,e){return t&&(this.x+=t),e&&(this.y+=e),this},jaws.Text.prototype.setX=function(t){return this.x=t,this},jaws.Text.prototype.setY=function(t){return this.y=t,this},jaws.Text.prototype.setTop=function(t){return this.y=t+this.top_offset,this},jaws.Text.prototype.setBottom=function(t){return this.y=t-this.bottom_offset,this},jaws.Text.prototype.setLeft=function(t){return this.x=t+this.left_offset,this},jaws.Text.prototype.setRight=function(t){return this.x=t-this.right_offset,this},jaws.Text.prototype.setWidth=function(t){return this.width=t,this.cacheOffsets(),this},jaws.Text.prototype.setHeight=function(t){return this.height=t,this.cacheOffsets(),this},jaws.Text.prototype.resize=function(t,e){return this.width+=t,this.height+=e,this.cacheOffsets(),this},jaws.Text.prototype.resizeTo=function(t,e){return this.width=t,this.height=e,this.cacheOffsets(),this},jaws.Text.prototype.setAnchor=function(t){var e={top_left:[0,0],left_top:[0,0],center_left:[0,.5],left_center:[0,.5],bottom_left:[0,1],left_bottom:[0,1],top_center:[.5,0],center_top:[.5,0],center_center:[.5,.5],center:[.5,.5],bottom_center:[.5,1],center_bottom:[.5,1],top_right:[1,0],right_top:[1,0],center_right:[1,.5],right_center:[1,.5],bottom_right:[1,1],right_bottom:[1,1]};return e.hasOwnProperty(t)&&(this.anchor_x=e[t][0],this.anchor_y=e[t][1],this.cacheOffsets()),this},jaws.Text.prototype.cacheOffsets=function(){return this.left_offset=this.width*this.anchor_x,this.top_offset=this.height*this.anchor_y,this.right_offset=this.width*(1-this.anchor_x),this.bottom_offset=this.height*(1-this.anchor_y),this.cached_rect&&this.cached_rect.resizeTo(this.width,this.height),this},jaws.Text.prototype.rect=function(){return!this.cached_rect&&this.width&&(this.cached_rect=new jaws.Rect(this.x,this.y,this.width,this.height)),this.cached_rect&&this.cached_rect.moveTo(this.x-this.left_offset,this.y-this.top_offset),this.cached_rect},jaws.Text.prototype.draw=function(){this.context.save(),0!==this.angle&&this.context.rotate(this.angle*Math.PI/180),this.context.globalAlpha=this.alpha,this.context.translate(-this.left_offset,-this.top_offset),this.context.fillStyle=this.color,this.context.font=this.style+" "+this.fontSize+"px "+this.fontFace,this.context.textBaseline=this.textBaseline,this.context.textAlign=this.textAlign,this.shadowColor&&(this.context.shadowColor=this.shadowColor),this.shadowBlur&&(this.context.shadowBlur=this.shadowBlur),this.shadowOffsetX&&(this.context.shadowOffsetX=this.shadowOffsetX),this.shadowOffsetY&&(this.context.shadowOffsetY=this.shadowOffsetY);var t=this.y,e=this.x;if(this.wordWrap)for(var i=this.text.split(" "),s="",o=0;o<i.length;o++){var n=s+i[o]+" ",r=this.context.measureText(n);this.y<t+this.height&&(r.width>this.width?(this.context.fillText(s,this.x,this.y),s=i[o]+" ",this.y+=this.fontSize):s=n,this.context.fillText(s,this.x,this.y))}else if(this.context.measureText(this.text).width<this.width)this.context.fillText(this.text,this.x,this.y);else for(var i=this.text.split(" "),s=" ",o=0;o<i.length;o++){var n=s+i[o]+" ";this.context.measureText(n).width<Math.abs(this.width-this.x)&&(this.context.fillText(n,this.x,this.y),s=i[o]+" ",s=n)}return this.y=t,this.x=e,this.context.restore(),this},jaws.Text.prototype.asCanvasContext=function(){var t=document.createElement("canvas");t.width=this.width,t.height=this.height;var e=t.getContext("2d");e.mozImageSmoothingEnabled=jaws.context.mozImageSmoothingEnabled,this.context.fillStyle=this.color,this.context.font=this.style+this.fontSize+"px "+this.fontFace,this.context.textBaseline=this.textBaseline,this.context.textAlign=this.textAlign,this.shadowColor&&(this.context.shadowColor=this.shadowColor),this.shadowBlur&&(this.context.shadowBlur=this.shadowBlur),this.shadowOffsetX&&(this.context.shadowOffsetX=this.shadowOffsetX),this.shadowOffsetY&&(this.context.shadowOffsetY=this.shadowOffsetY);var i=this.y,s=this.x;if(this.wordWrap)for(var o=this.text.split(" "),n="",r=0;r<o.length;r++){var a=n+o[r]+" ",h=this.context.measureText(a);this.y<i+this.height&&(h.width>this.width?(this.context.fillText(n,this.x,this.y),n=o[r]+" ",this.y+=this.fontSize):n=a,this.context.fillText(n,this.x,this.y))}else if(this.context.measureText(this.text).width<this.width)this.context.fillText(this.text,this.x,this.y);else for(var o=this.text.split(" "),n=" ",r=0;r<o.length;r++){var a=n+o[r]+" ";this.context.measureText(a).width<Math.abs(this.width-this.x)&&(this.context.fillText(a,this.x,this.y),n=o[r]+" ",n=a)}return this.y=i,this.x=s,e},jaws.Text.prototype.asCanvas=function(){var t=document.createElement("canvas");t.width=this.width,t.height=this.height;var e=t.getContext("2d");e.mozImageSmoothingEnabled=jaws.context.mozImageSmoothingEnabled,this.context.fillStyle=this.color,this.context.font=this.style+this.fontSize+"px "+this.fontFace,this.context.textBaseline=this.textBaseline,this.context.textAlign=this.textAlign,this.shadowColor&&(this.context.shadowColor=this.shadowColor),this.shadowBlur&&(this.context.shadowBlur=this.shadowBlur),this.shadowOffsetX&&(this.context.shadowOffsetX=this.shadowOffsetX),this.shadowOffsetY&&(this.context.shadowOffsetY=this.shadowOffsetY);var i=this.y,s=this.x;if(this.wordWrap)for(var o=this.text.split(" "),n="",r=0;r<o.length;r++){var a=n+o[r]+" ",h=e.measureText(a);this.y<i+this.height&&(h.width>this.width?(e.fillText(n,this.x,this.y),n=o[r]+" ",this.y+=this.fontSize):n=a,e.fillText(n,this.x,this.y))}else if(e.measureText(this.text).width<this.width)this.context.fillText(this.text,this.x,this.y);else for(var o=this.text.split(" "),n=" ",r=0;r<o.length;r++){var a=n+o[r]+" ";e.measureText(a).width<Math.abs(this.width-this.x)&&(e.fillText(a,this.x,this.y),n=o[r]+" ",n=a)}return this.y=i,this.x=s,t},jaws.Text.prototype.toString=function(){return"[Text "+this.x.toFixed(2)+", "+this.y.toFixed(2)+", "+this.width+", "+this.height+"]"},jaws.Text.prototype.attributes=function(){var t=this.options;return t._constructor=this._constructor||"jaws.Text",t.x=parseFloat(this.x.toFixed(2)),t.y=parseFloat(this.y.toFixed(2)),t.text=this.text,t.alpha=this.alpha,t.angle=parseFloat(this.angle.toFixed(2)),t.anchor_x=this.anchor_x,t.anchor_y=this.anchor_y,t.style=this.style,t.fontSize=this.fontSize,t.fontFace=this.fontFace,t.color=this.color,t.textAlign=this.textAlign,t.textBaseline=this.textBaseline,t.wordWrap=this.wordWrap,t.width=this.width,t.height=this.height,t},jaws.Text.prototype.toJSON=function(){return JSON.stringify(this.attributes())},jaws}(jaws||{});if("undefined"!=typeof module&&"exports"in module&&(module.exports=jaws.Text),"undefined"!=typeof require)var jaws=require("./core.js");var jaws=function(t){return t.QuadTree=function(e){this.depth=arguments[1]||0,this.bounds=e||new t.Rect(0,0,t.width,t.height),this.nodes=[],this.objects=[]},t.QuadTree.prototype.clear=function(){this.objects=[];for(var t=0;t<this.nodes.length;t++)"undefined"!=typeof this.nodes[t]&&(this.nodes[t].clear(),delete this.nodes[t])},t.QuadTree.prototype.split=function(){var e=Math.round(this.bounds.width/2),i=Math.round(this.bounds.height/2),s=this.bounds.x,o=this.bounds.y;this.nodes[0]=new t.QuadTree(new t.Rect(s+e,o,e,i),this.depth+1),this.nodes[1]=new t.QuadTree(new t.Rect(s,o,e,i),this.depth+1),this.nodes[2]=new t.QuadTree(new t.Rect(s,o+i,e,i),this.depth+1),this.nodes[3]=new t.QuadTree(new t.Rect(s+e,o+i,e,i),this.depth+1)},t.QuadTree.prototype.getIndex=function(t){var e=-1,i=this.bounds.x+this.bounds.width/2,s=this.bounds.y+this.bounds.height/2,o=t.y<s&&t.y+t.height<s,n=t.y>s;return t.x<i&&t.x+t.width<i?o?e=1:n&&(e=2):t.x>i&&(o?e=0:n&&(e=3)),e},t.QuadTree.prototype.insert=function(t){if(t.hasOwnProperty("x")||t.hasOwnProperty("y")||t.hasOwnProperty("width")||t.hasOwnProperty("height")){if("undefined"!=typeof this.nodes[0]){var e=this.getIndex(t);if(-1!==e)return void this.nodes[e].insert(t)}this.objects.push(t),"undefined"==typeof this.nodes[0]&&this.split();for(var i=0;i<this.objects.length;){var e=this.getIndex(this.objects[i]);-1!==e?this.nodes[e].insert(this.objects.splice(i,1)[0]):i++}}},t.QuadTree.prototype.retrieve=function(t){if(t.hasOwnProperty("x")||t.hasOwnProperty("y")||t.hasOwnProperty("width")||t.hasOwnProperty("height")){var e=this.getIndex(t),i=this.objects;if("undefined"!=typeof this.nodes[0])if(-1!==e)i=i.concat(this.nodes[e].retrieve(t));else for(var s=0;s<this.nodes.length;s++)i=i.concat(this.nodes[s].retrieve(t));return i}},t.QuadTree.prototype.collide=function(e,i,s){var o=!1,n=new t.QuadTree,r=[];return e.forEach||(r.push(e),e=r),i.forEach||(r=[],r.push(i),i=r),i.forEach(function(t){n.insert(t)}),e.forEach(function(e){t.collide(e,n.retrieve(e),s)&&(o=!0)}),n.clear(),o},t}(jaws||{});"undefined"!=typeof module&&"exports"in module&&(module.exports=jaws.QuadTree),window.addEventListener("load",function(){jaws.onload&&jaws.onload()},!1);