-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjaws-min.js
More file actions
78 lines (78 loc) · 35.8 KB
/
Copy pathjaws-min.js
File metadata and controls
78 lines (78 loc) · 35.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* Built at 2013-03-09 15:23:47 +0100 */
var jaws=function(c){function b(b){c.mouse_x=b.pageX||b.clientX;c.mouse_y=b.pageY||b.clientY;b=c.canvas?c.canvas:c.dom;c.mouse_x-=b.offsetLeft;c.mouse_y-=b.offsetTop}var d,e;c.title=function(b){return b?d.innerHTML=b:d.innerHTML};c.unpack=function(){"Sprite SpriteList Animation Viewport SpriteSheet Parallax TileMap Rect pressed".split(" ").forEach(function(b){window[b]?c.log(b+"already exists in global namespace"):window[b]=c[b]})};c.log=function(b,c){e&&(b+="<br />",e.innerHTML=c?e.innerHTML.toString()+
b:b)};c.init=function(f){d=document.getElementsByTagName("title")[0];c.url_parameters=c.getUrlParameters();e=document.getElementById("jaws-log");c.url_parameters.debug&&!e&&(e=document.createElement("div"),e.id="jaws-log",e.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(e));c.canvas=document.getElementsByTagName("canvas")[0];
c.canvas||(c.dom=document.getElementById("canvas"));c.canvas?c.context=c.canvas.getContext("2d"):c.dom?c.dom.style.position="relative":(c.canvas=document.createElement("canvas"),c.canvas.width=f.width,c.canvas.height=f.height,c.context=c.canvas.getContext("2d"),document.body.appendChild(c.canvas));c.width=c.canvas?c.canvas.width:c.dom.offsetWidth;c.height=c.canvas?c.canvas.height:c.dom.offsetHeight;c.mouse_x=0;c.mouse_y=0;window.addEventListener("mousemove",b)};c.start=function(b,d,e){function g(b,
e){c.log(e+"%: "+b,!0);d.loading_screen&&c.assets.displayProgress(e)}function h(b){c.log("Error loading: "+b,!0)}function r(){c.log("all assets loaded",!0);c.switchGameState(b||window,{fps:p},e)}d||(d={});var p=d.fps||60;void 0===d.loading_screen&&(d.loading_screen=!0);d.width||(d.width=500);d.height||(d.height=300);c.init(d);d.loading_screen&&c.assets.displayProgress(0);c.log("setupInput()",!0);c.setupInput();c.log("assets.loadAll()",!0);0<c.assets.length()?c.assets.loadAll({onload:g,onerror:h,onfinish:r}):
r()};c.switchGameState=function(b,d,e){d=d&&d.fps||c.game_loop&&c.game_loop.fps||60;c.game_loop&&c.game_loop.stop();c.clearKeyCallbacks();c.isFunction(b)&&(b=new b);c.previous_game_state=c.game_state;c.game_state=b;c.game_loop=new c.GameLoop(b,{fps:d},e);c.game_loop.start()};c.imageToCanvas=function(b){var c=document.createElement("canvas");c.src=b.src;c.width=b.width;c.height=b.height;c.getContext("2d").drawImage(b,0,0,b.width,b.height);return c};c.forceArray=function(b){return Array.isArray(b)?
b:[b]};c.clear=function(){c.context.clearRect(0,0,c.width,c.height)};c.isImage=function(b){return"[object HTMLImageElement]"===Object.prototype.toString.call(b)};c.isCanvas=function(b){return"[object HTMLCanvasElement]"===Object.prototype.toString.call(b)};c.isDrawable=function(b){return c.isImage(b)||c.isCanvas(b)};c.isString=function(b){return"string"==typeof b};c.isArray=function(b){return void 0===b?!1:-1!=b.constructor.toString().indexOf("Array")};c.isFunction=function(b){return"[object Function]"===
Object.prototype.toString.call(b)};c.isOutsideCanvas=function(b){return 0>b.x||0>b.y||b.x>c.width||b.y>c.height};c.forceInsideCanvas=function(b){0>b.x&&(b.x=0);b.x>c.width&&(b.x=c.width);0>b.y&&(b.y=0);b.y>c.height&&(b.y=c.height)};c.getUrlParameters=function(){for(var b=[],c,d=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),e=0;e<d.length;e++)c=d[e].split("="),b.push(c[0]),b[c[0]]=c[1];return b};c.parseOptions=function(b,c,d){b.options=c;for(option in c)if(void 0===d[option])throw"Unsupported option '"+
option+"' sent to constructor";for(option in d)b[option]=void 0!==c[option]?c[option]:d[option]};return c}(jaws||{}),jaws=function(c){function b(){h={}}function d(b){event=b?b:window.event;var c=r[event.keyCode];h[c]=!1;s[c]&&(s[c](c),b.preventDefault());m[c]&&b.preventDefault()}function e(b){event=b?b:window.event;var c=r[event.keyCode];h[c]=!0;p[c]&&(p[c](c),b.preventDefault());m[c]&&b.preventDefault()}function f(b){event=b?b:window.event;var c=q[event.button];"Microsoft Internet Explorer"==navigator.appName&&
(c=n[event.button]);h[c]=!0;p[c]&&(p[c](c),b.preventDefault())}function k(b){event=b?b:window.event;var c=q[event.button];"Microsoft Internet Explorer"==navigator.appName&&(c=n[event.button]);h[c]=!1;s[c]&&(s[c](c),b.preventDefault())}function l(b){event=b?b:window.event;h.left_mouse_button=!0;c.mouse_x=b.touches[0].pageX-c.canvas.offsetLeft;c.mouse_y=b.touches[0].pageY-c.canvas.offsetTop}function g(b){event=b?b:window.event;h.left_mouse_button=!1;c.mouse_x=void 0;c.mouse_y=void 0}var h={},r=[],p=
[],s=[],q=[],n=[];c.setupInput=function(){var j=[];j[8]="backspace";j[9]="tab";j[13]="enter";j[16]="shift";j[17]="ctrl";j[18]="alt";j[19]="pause";j[20]="capslock";j[27]="esc";j[32]="space";j[33]="pageup";j[34]="pagedown";j[35]="end";j[36]="home";j[37]="left";j[38]="up";j[39]="right";j[40]="down";j[45]="insert";j[46]="delete";j[91]="leftwindowkey";j[92]="rightwindowkey";j[93]="selectkey";j[106]="multiply";j[107]="add";j[109]="subtract";j[110]="decimalpoint";j[111]="divide";j[144]="numlock";j[145]=
"scrollock";j[186]="semicolon";j[187]="equalsign";j[188]="comma";j[189]="dash";j[190]="period";j[191]="forwardslash";j[192]="graveaccent";j[219]="openbracket";j[220]="backslash";j[221]="closebracket";j[222]="singlequote";q=["left_mouse_button","center_mouse_button","right_mouse_button"];n=[,"left_mouse_button","right_mouse_button",,"center_mouse_button"];for(var h="numpad0 numpad1 numpad2 numpad3 numpad4 numpad5 numpad6 numpad7 numpad8 numpad9".split(" "),m="f1 f2 f3 f4 f5 f6 f7 f8 f9".split(" "),
p="0123456789".split(""),s="abcdefghijklmnopqrstuvwxyz".split(""),t=0;p[t];t++)j[48+t]=p[t];for(t=0;s[t];t++)j[65+t]=s[t];for(t=0;h[t];t++)j[96+t]=h[t];for(t=0;m[t];t++)j[112+t]=m[t];r=j;window.addEventListener("keydown",e);window.addEventListener("keyup",d);c.canvas.addEventListener("mousedown",f,!1);c.canvas.addEventListener("mouseup",k,!1);c.canvas.addEventListener("touchstart",l,!1);c.canvas.addEventListener("touchend",g,!1);window.addEventListener("blur",b,!1);document.oncontextmenu=function(){return!1}};
var m=[];c.preventDefaultKeys=function(b){b.forEach(function(b){m[b]=!0})};c.pressed=function(b){return h[b]};c.on_keydown=function(b,d){if(c.isArray(b))for(var e=0;b[e];e++)p[b[e]]=d;else p[b]=d};c.on_keyup=function(b,d){if(c.isArray(b))for(var e=0;b[e];e++)s[b[e]]=d;else s[b]=d};c.clearKeyCallbacks=function(){s=[];p=[]};return c}(jaws||{}),jaws=function(c){c.Assets=function(){if(!(this instanceof arguments.callee))return new arguments.callee;this.loaded=[];this.loading=[];this.src_list=[];this.data=
[];this.bust_cache=!1;this.fuchia_to_transparent=this.image_to_canvas=!0;this.root="";this.file_type={};this.file_type.json="json";this.file_type.wav="audio";this.file_type.mp3="audio";this.file_type.ogg="audio";this.file_type.png="image";this.file_type.jpg="image";this.file_type.jpeg="image";this.file_type.gif="image";this.file_type.bmp="image";this.file_type.tiff="image";var b=this;this.length=function(){return this.src_list.length};this.get=function(d){if(c.isArray(d))return d.map(function(c){return b.data[c]});
if(this.loaded[d])return this.data[d];c.log("No such asset: "+d,!0)};this.isLoading=function(b){return this.loading[b]};this.isLoaded=function(b){return this.loaded[b]};this.getPostfix=function(b){postfix_regexp=/\.([a-zA-Z0-9]+)/;return postfix_regexp.exec(b)[1]};this.getType=function(b){b=this.getPostfix(b);return this.file_type[b]?this.file_type[b]:b};this.add=function(b){if(c.isArray(b))for(var e=0;b[e];e++)this.add(b[e]);else this.src_list.push(b);return this};this.loadAll=function(b){this.error_count=
this.load_count=0;this.onload=b.onload;this.onerror=b.onerror;this.onfinish=b.onfinish;for(i=0;this.src_list[i];i++)this.load(this.src_list[i])};this.getOrLoad=function(b,c,f){this.data[b]?c():this.load(b,c,f)};this.load=function(b,c,f){var k={};k.src=b;k.onload=c;k.onerror=f;this.loading[b]=!0;b=this.root+k.src;this.bust_cache&&(b+="?"+parseInt(1E7*Math.random()));switch(this.getType(k.src)){case "image":k.image=new Image;k.image.asset=k;k.image.onload=this.assetLoaded;k.image.onerror=this.assetError;
k.image.src=b;break;case "audio":k.audio=new Audio(b);k.audio.asset=k;this.data[k.src]=k.audio;k.audio.addEventListener("canplay",this.assetLoaded,!1);k.audio.addEventListener("error",this.assetError,!1);k.audio.load();break;default:c=new XMLHttpRequest,c.asset=k,c.onreadystatechange=this.assetLoaded,c.open("GET",b,!0),c.send(null)}};this.assetLoaded=function(){var d=this.asset,e=d.src,f=b.getType(d.src);b.loaded[e]=!0;b.loading[e]=!1;if("json"==f){if(4!=this.readyState)return;b.data[d.src]=JSON.parse(this.responseText)}else if("image"==
f){e=b.image_to_canvas?c.imageToCanvas(d.image):d.image;if(b.fuchia_to_transparent&&"bmp"==b.getPostfix(d.src)){canvas=c.isImage(e)?c.imageToCanvas(e):e;for(var e=canvas.getContext("2d"),f=e.getImageData(0,0,canvas.width,canvas.height),k=f.data,l=0;l<k.length;l+=4)255==k[l]&&(0==k[l+1]&&255==k[l+2])&&(k[l+3]=0);e.putImageData(f,0,0);e=canvas}b.data[d.src]=e}else"audio"==f&&(d.audio.removeEventListener("canplay",b.assetLoaded,!1),b.data[d.src]=d.audio);b.load_count++;b.processCallbacks(d,!0)};this.assetError=
function(){var c=this.asset;b.error_count++;b.processCallbacks(c,!1)};this.processCallbacks=function(c,e){var f=parseInt(100*((b.load_count+b.error_count)/b.src_list.length));if(e){if(b.onload)b.onload(c.src,f);if(c.onload)c.onload()}else{if(b.onerror)b.onerror(c.src,f);if(c.onerror)c.onerror(c)}if(100==f){if(b.onfinish)b.onfinish();b.onload=null;b.onerror=null;b.onfinish=null}};this.displayProgress=function(b){c.context&&(c.context.save(),c.context.fillStyle="black",c.context.fillRect(0,0,c.width,
c.height),c.context.fillStyle="white",c.context.strokeStyle="white",c.context.textAlign="center",c.context.strokeRect(49,c.height/2-30-1,c.width-100+2,62),c.context.fillRect(50,c.height/2-30,(c.width-100)/100*b,60),c.context.font="11px verdana",c.context.fillText("Loading game ... "+b+"%",c.width/2,c.height/2-35),c.context.font="11px verdana",c.context.fillStyle="#ccc",c.context.textBaseline="bottom",c.context.fillText("powered by www.jawsjs.com",c.width/2,c.height-1),c.context.restore())}};c.assets=
new c.Assets;return c}(jaws||{}),jaws=function(c){function b(b){this.size=b;this.values=Array(this.size);this.value;this.add=function(b){if(this.values.length>this.size){this.values.splice(0,1);for(var c=this.value=0;this.values[c];c++)this.value+=this.values[c];this.value/=this.size}this.values.push(b);return this};this.get=function(){return parseInt(this.value)}}window.requestAnimFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||
window.msRequestAnimationFrame||function(b){window.setTimeout(b,16.666)};c.GameLoop=function(d,e,f){if(!(this instanceof arguments.callee))return new arguments.callee(d,e);this.ticks=this.fps=this.tick_duration=0;var k,l=!1,g=!1,h=this,r=new b(20);this.runtime=function(){return this.last_tick-this.first_tick};this.start=function(){c.log("game loop start",!0);this.first_tick=(new Date).getTime();this.current_tick=(new Date).getTime();this.last_tick=(new Date).getTime();d.setup&&d.setup(f);step_delay=
1E3/e.fps;60==e.fps?requestAnimFrame(this.loop):k=setInterval(this.loop,step_delay);c.log("game loop loop",!0)};this.loop=function(){h.current_tick=(new Date).getTime();h.tick_duration=h.current_tick-h.last_tick;h.fps=r.add(1E3/h.tick_duration).get();!g&&!l&&(d.update&&d.update(),d.draw&&d.draw(),h.ticks++);60==e.fps&&!g&&requestAnimFrame(h.loop);h.last_tick=h.current_tick};this.pause=function(){l=!0};this.unpause=function(){l=!1};this.stop=function(){k&&clearInterval(k);g=!0}};return c}(jaws||{}),
jaws=function(c){c.Rect=function(b,c,e,f){if(!(this instanceof arguments.callee))return new arguments.callee(b,c,e,f);this.x=b;this.y=c;this.width=e;this.height=f;this.right=b+e;this.bottom=c+f};c.Rect.prototype.getPosition=function(){return[this.x,this.y]};c.Rect.prototype.move=function(b,c){this.x+=b;this.y+=c;this.right+=b;this.bottom+=c;return this};c.Rect.prototype.moveTo=function(b,c){this.x=b;this.y=c;this.right=this.x+this.width;this.bottom=this.y+this.height;return this};c.Rect.prototype.resize=
function(b,c){this.width+=b;this.height+=c;this.right=this.x+this.width;this.bottom=this.y+this.height;return this};c.Rect.prototype.resizeTo=function(b,c){this.width=b;this.height=c;this.right=this.x+this.width;this.bottom=this.y+this.height;return this};c.Rect.prototype.draw=function(){c.context.strokeStyle="red";c.context.strokeRect(this.x,this.y,this.width,this.height);return this};c.Rect.prototype.collidePoint=function(b,c){return b>=this.x&&b<=this.right&&c>=this.y&&c<=this.bottom};c.Rect.prototype.collideRect=
function(b){return(this.x>=b.x&&this.x<=b.right||b.x>=this.x&&b.x<=this.right)&&(this.y>=b.y&&this.y<=b.bottom||b.y>=this.y&&b.y<=this.bottom)};c.Rect.prototype.toString=function(){return"[Rect "+this.x+", "+this.y+", "+this.width+", "+this.height+"]"};return c}(jaws||{});"undefined"!==typeof module&&"exports"in module&&(module.exports=jaws.Rect);
jaws=function(c){c.Sprite=function(b){if(!(this instanceof arguments.callee))return new arguments.callee(b);this.set(b);b.context?this.context=b.context:b.dom&&(this.dom=b.dom,this.createDiv());!b.context&&!b.dom&&(c.context?this.context=c.context:(this.dom=c.dom,this.createDiv()))};c.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,_constructor:null,dom:null};c.Sprite.prototype.set=
function(b){c.parseOptions(this,b,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.cacheOffsets();return this};c.Sprite.prototype.clone=function(){var b=new (this._constructor?eval(this._constructor):this.constructor)(this.attributes());b._constructor=this._constructor||this.constructor.name;return b};c.Sprite.prototype.setImage=function(b){var d=
this;if(c.isDrawable(b))return this.image=b,this.cacheOffsets();c.assets.isLoaded(b)?(this.image=c.assets.get(b),this.cacheOffsets()):(console.log("WARNING: Image '"+b+"' not preloaded with jaws.assets.add(). Image and a working sprite.rect() will be delayed."),c.assets.load(b,function(){d.image=c.assets.get(b);d.cacheOffsets()}));return this};c.Sprite.prototype.flip=function(){this.flipped=this.flipped?!1:!0;return this};c.Sprite.prototype.flipTo=function(b){this.flipped=b;return this};c.Sprite.prototype.rotate=
function(b){this.angle+=b;return this};c.Sprite.prototype.rotateTo=function(b){this.angle=b;return this};c.Sprite.prototype.moveTo=function(b,c){this.x=b;this.y=c;return this};c.Sprite.prototype.move=function(b,c){b&&(this.x+=b);c&&(this.y+=c);return this};c.Sprite.prototype.scaleAll=function(b){this.scale_x*=b;this.scale_y*=b;return this.cacheOffsets()};c.Sprite.prototype.scaleTo=function(b){this.scale_x=this.scale_y=b;return this.cacheOffsets()};c.Sprite.prototype.scaleWidth=function(b){this.scale_x*=
b;return this.cacheOffsets()};c.Sprite.prototype.scaleHeight=function(b){this.scale_y*=b;return this.cacheOffsets()};c.Sprite.prototype.setX=function(b){this.x=b;return this};c.Sprite.prototype.setY=function(b){this.y=b;return this};c.Sprite.prototype.setTop=function(b){this.y=b+this.top_offset;return this};c.Sprite.prototype.setBottom=function(b){this.y=b-this.bottom_offset;return this};c.Sprite.prototype.setLeft=function(b){this.x=b+this.left_offset;return this};c.Sprite.prototype.setRight=function(b){this.x=
b-this.right_offset;return this};c.Sprite.prototype.setWidth=function(b){this.scale_x=b/this.image.width;return this.cacheOffsets()};c.Sprite.prototype.setHeight=function(b){this.scale_y=b/this.image.height;return this.cacheOffsets()};c.Sprite.prototype.resize=function(b,c){this.scale_x=(this.width+b)/this.image.width;this.scale_y=(this.height+c)/this.image.height;return this.cacheOffsets()};c.Sprite.prototype.resizeTo=function(b,c){this.scale_x=b/this.image.width;this.scale_y=c/this.image.height;
return this.cacheOffsets()};c.Sprite.prototype.setAnchor=function(b){if(a={top_left:[0,0],left_top:[0,0],center_left:[0,0.5],left_center:[0,0.5],bottom_left:[0,1],left_bottom:[0,1],top_center:[0.5,0],center_top:[0.5,0],center_center:[0.5,0.5],center:[0.5,0.5],bottom_center:[0.5,1],center_bottom:[0.5,1],top_right:[1,0],right_top:[1,0],center_right:[1,0.5],right_center:[1,0.5],bottom_right:[1,1],right_bottom:[1,1]}[b])this.anchor_x=a[0],this.anchor_y=a[1],this.image&&this.cacheOffsets();return this};
c.Sprite.prototype.cacheOffsets=function(){if(this.image)return 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};c.Sprite.prototype.rect=function(){!this.cached_rect&&this.width&&(this.cached_rect=new c.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);return this.cached_rect};c.Sprite.prototype.createDiv=function(){this.div=document.createElement("div");this.div.style.position="absolute";this.image&&(this.div.style.width=this.image.width+"px",this.div.style.height=this.image.height+"px",this.div.style.backgroundImage=this.image.toDataURL?"url("+this.image.toDataURL()+")":"url("+this.image.src+")");this.dom&&this.dom.appendChild(this.div);
this.updateDiv()};c.Sprite.prototype.updateDiv=function(){this.div.style.left=this.x+"px";this.div.style.top=this.y+"px";var b;b=""+("rotate("+this.angle+"deg) ");b=this.flipped?b+("scale(-"+this.scale_x+","+this.scale_y+")"):b+("scale("+this.scale_x+","+this.scale_y+")");this.div.style.MozTransform=b;this.div.style.WebkitTransform=b;this.div.style.OTransform=b;this.div.style.msTransform=b;this.div.style.transform=b;return this};c.Sprite.prototype.draw=function(){if(!this.image)return this;if(this.dom)return this.updateDiv();
this.context.save();this.context.translate(this.x,this.y);0!=this.angle&&c.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();return this};c.Sprite.prototype.scaleImage=function(b){if(this.image)return this.setImage(c.gfx.retroScaleImage(this.image,b)),this};c.Sprite.prototype.asCanvasContext=
function(){var b=document.createElement("canvas");b.width=this.width;b.height=this.height;b=b.getContext("2d");b.mozImageSmoothingEnabled=c.context.mozImageSmoothingEnabled;b.drawImage(this.image,0,0,this.width,this.height);return b};c.Sprite.prototype.asCanvas=function(){var b=document.createElement("canvas");b.width=this.width;b.height=this.height;var d=b.getContext("2d");d.mozImageSmoothingEnabled=c.context.mozImageSmoothingEnabled;d.drawImage(this.image,0,0,this.width,this.height);return b};c.Sprite.prototype.toString=
function(){return"[Sprite "+this.x.toFixed(2)+", "+this.y.toFixed(2)+", "+this.width+", "+this.height+"]"};c.Sprite.prototype.attributes=function(){var b=this.options;b._constructor=this._constructor||"jaws.Sprite";b.x=parseFloat(this.x.toFixed(2));b.y=parseFloat(this.y.toFixed(2));b.image=this.image_path;b.alpha=this.alpha;b.flipped=this.flipped;b.angle=parseFloat(this.angle.toFixed(2));b.scale_x=this.scale_x;b.scale_y=this.scale_y;b.anchor_x=this.anchor_x;b.anchor_y=this.anchor_y;return b};c.Sprite.prototype.toJSON=
function(){return JSON.stringify(this.attributes())};return c}(jaws||{});"undefined"!==typeof module&&"exports"in module&&(module.exports=jaws.Sprite);
jaws=function(c){c.SpriteList=function(b){if(!(this instanceof arguments.callee))return new arguments.callee(b);this.sprites=[];this.length=0;b&&this.load(b)};c.SpriteList.prototype.at=function(b){return this.sprites[b]};c.SpriteList.prototype.concat=function(){return this.sprites.concat.apply(this.sprites,arguments)};c.SpriteList.prototype.indexOf=function(b,c){return this.sprites.indexOf(b,c)};c.SpriteList.prototype.join=function(b){return this.sprites.join(b)};c.SpriteList.prototype.lastIndexOf=
function(){return this.sprites.lastIndexOf.apply(this.sprites,arguments)};c.SpriteList.prototype.pop=function(){var b=this.sprites.pop();this.updateLength();return b};c.SpriteList.prototype.push=function(){this.sprites.push.apply(this.sprites,arguments);this.updateLength();return this.length};c.SpriteList.prototype.reverse=function(){this.sprites.reverse()};c.SpriteList.prototype.shift=function(){var b=this.sprites.shift();this.updateLength();return b};c.SpriteList.prototype.slice=function(b,c){return this.sprites.slice(b,
c)};c.SpriteList.prototype.sort=function(){this.sprites.sort.apply(this.sprites,arguments)};c.SpriteList.prototype.splice=function(){var b=this.sprites.splice.apply(this.sprites,arguments);this.updateLength();return b};c.SpriteList.prototype.unshift=function(){this.sprites.unshift.apply(this.sprites,arguments);this.updateLength();return this.length};c.SpriteList.prototype.updateLength=function(){this.length=this.sprites.length};c.SpriteList.prototype.valueOf=function(){return this.toString()};c.SpriteList.prototype.filter=
function(){return this.sprites.filter.apply(this.sprites,arguments)};c.SpriteList.prototype.forEach=function(){this.sprites.forEach.apply(this.sprites,arguments);this.updateLength()};c.SpriteList.prototype.every=function(){return this.sprites.every.apply(this.sprites,arguments)};c.SpriteList.prototype.map=function(){return this.sprites.map.apply(this.sprites,arguments)};c.SpriteList.prototype.reduce=function(){return this.sprites.reduce.apply(this.sprites,arguments)};c.SpriteList.prototype.reduceRight=
function(){return this.sprites.reduceRight.apply(this.sprites,arguments)};c.SpriteList.prototype.some=function(){return this.sprites.some.apply(this.sprites,arguments)};c.SpriteList.prototype.isSpriteList=function(){return!0};c.SpriteList.prototype.load=function(b){function d(b){b.forEach(function(b){var d=b._constructor?eval(b._constructor):b.constructor;c.isFunction(d)&&(c.log("Creating "+b._constructor+"("+b.toString()+")",!0),d=new d(b),d._constructor=b._constructor||b.constructor.name,e.push(d))})}
var e=this;c.isArray(b)?b.every(function(b){return b._constructor})?d(b):this.sprites=b:c.isString(b)&&(d(JSON.parse(b)),console.log(b));this.updateLength()};c.SpriteList.prototype.remove=function(b){b=this.indexOf(b);-1<b&&this.splice(b,1);this.updateLength()};c.SpriteList.prototype.draw=function(){this.forEach(function(b){b.draw()})};c.SpriteList.prototype.drawIf=function(b){this.forEach(function(c){b(c)&&c.draw()})};c.SpriteList.prototype.update=function(){this.forEach(function(b){b.update()})};
c.SpriteList.prototype.updateIf=function(b){this.forEach(function(c){b(c)&&c.update()})};c.SpriteList.prototype.deleteIf=function(b){this.removeIf(b)};c.SpriteList.prototype.removeIf=function(b){this.sprites=this.filter(function(c){return!b(c)});this.updateLength()};c.SpriteList.prototype.toString=function(){return"[SpriteList "+this.length+" sprites]"};return c}(jaws||{});
jaws=function(c){function b(b,c,f,k,l){var g=document.createElement("canvas");g.width=k;g.height=l;g.getContext("2d").drawImage(b,c,f,k,l,0,0,g.width,g.height);return g}c.SpriteSheet=function(d){if(!(this instanceof arguments.callee))return new arguments.callee(d);c.parseOptions(this,d,this.default_options);if(c.isString(this.image)&&!d.frame_size){var e=RegExp("_(\\d+)x(\\d+)","g").exec(this.image);this.frame_size=[];this.frame_size[0]=parseInt(e[1]);this.frame_size[1]=parseInt(e[2])}this.image=
c.isDrawable(this.image)?this.image:c.assets.data[this.image];this.scale_image&&(e=c.isDrawable(this.image)?this.image:c.assets.get(this.image),this.frame_size[0]*=this.scale_image,this.frame_size[1]*=this.scale_image,this.image=c.gfx.retroScaleImage(e,this.scale_image));this.frames=[];if("down"==this.orientation)for(e=this.offset;e<this.image.width;e+=this.frame_size[0])for(var f=0;f<this.image.height;f+=this.frame_size[1])this.frames.push(b(this.image,e,f,this.frame_size[0],this.frame_size[1]));
else for(f=this.offset;f<this.image.height;f+=this.frame_size[1])for(e=0;e<this.image.width;e+=this.frame_size[0])this.frames.push(b(this.image,e,f,this.frame_size[0],this.frame_size[1]))};c.SpriteSheet.prototype.default_options={image:null,orientation:"down",frame_size:[32,32],offset:0,scale_image:null};c.SpriteSheet.prototype.toString=function(){return"[SpriteSheet "+this.frames.length+" frames]"};return c}(jaws||{});
jaws=function(c){c.Parallax=function(b){if(!(this instanceof arguments.callee))return new arguments.callee(b);c.parseOptions(this,b,this.default_options)};c.Parallax.prototype.default_options={scale:1,repeat_x:null,repeat_y:null,camera_x:0,camera_y:0,layers:[]};c.Parallax.prototype.draw=function(){for(var b,d,e=0;e<this.layers.length;e++){b=this.layers[e];d=this.repeat_x?-(this.camera_x/b.damping%b.width):-(this.camera_x/b.damping);b.y=this.repeat_y?-(this.camera_y/b.damping%b.height):-(this.camera_y/
b.damping);for(b.x=d;b.y<c.height;){for(;b.x<c.width&&!(0<=b.x+b.width&&0<=b.y+b.height&&b.draw(),b.x+=b.width,!this.repeat_x););b.y+=b.height;b.x=d;if(!this.repeat_y)break}}};c.Parallax.prototype.addLayer=function(b){b=new c.ParallaxLayer(b);b.scaleAll(this.scale);this.layers.push(b)};c.Parallax.prototype.toString=function(){return"[Parallax "+this.x+", "+this.y+". "+this.layers.length+" layers]"};c.ParallaxLayer=function(b){if(!(this instanceof arguments.callee))return new arguments.callee(b);this.damping=
b.damping||0;c.Sprite.call(this,b)};c.ParallaxLayer.prototype=c.Sprite.prototype;return c}(jaws||{});
jaws=function(c){c.Animation=function(b){if(!(this instanceof arguments.callee))return new arguments.callee(b);c.parseOptions(this,b,this.default_options);if(b.sprite_sheet){var d=new c.SpriteSheet({image:b.sprite_sheet,scale_image:this.scale_image,frame_size:this.frame_size,orientation:this.orientation,offset:this.offset});this.frames=d.frames;this.frame_size=d.frame_size}b.scale_image&&(d=c.isDrawable(b.sprite_sheet)?b.sprite_sheet:c.assets.get(b.sprite_sheet),this.frame_size[0]*=b.scale_image,
this.frame_size[1]*=b.scale_image,b.sprite_sheet=c.gfx.retroScaleImage(d,b.scale_image));this.current_tick=(new Date).getTime();this.last_tick=(new Date).getTime();this.sum_tick=0;if(b.subsets)for(subset in this.subsets={},b.subsets)start_stop=b.subsets[subset],this.subsets[subset]=this.slice(start_stop[0],start_stop[1])};c.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};c.Animation.prototype.subset=function(b){return this.subsets[b]};c.Animation.prototype.update=function(){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);if(this.index>=this.frames.length||0>this.index)this.bounce?(this.frame_direction=-this.frame_direction,this.index+=2*this.frame_direction):this.loop?this.index=
0:(this.index-=this.frame_direction,this.on_end&&(this.on_end(),this.on_end=null));return this};c.Animation.prototype.slice=function(b,d){var e={};e.frame_duration=this.frame_duration;e.loop=this.loop;e.bounce=this.bounce;e.on_end=this.on_end;e.frame_direction=this.frame_direction;e.frames=this.frames.slice().slice(b,d);return new c.Animation(e)};c.Animation.prototype.next=function(){this.update();return this.frames[this.index]};c.Animation.prototype.atLastFrame=function(){return this.index==this.frames.length-
1};c.Animation.prototype.atFirstFrame=function(){return 0==this.index};c.Animation.prototype.currentFrame=function(){return this.frames[this.index]};c.Animation.prototype.toString=function(){return"[Animation, "+this.frames.length+" frames]"};return c}(jaws||{});
jaws=function(c){c.Viewport=function(b){if(!(this instanceof arguments.callee))return new arguments.callee(b);c.parseOptions(this,b,this.default_options);this.context||(this.context=c.context);this.width||(this.width=c.width);this.height||(this.height=c.height);this.max_x||(this.max_x=c.width);this.max_y||(this.max_y=c.height);var d=this;this.move=function(b,c){b&&(this.x+=b);c&&(this.y+=c);this.verifyPosition()};this.moveTo=function(b,c){void 0!=b&&(this.x=b);void 0!=c&&(this.y=c);this.verifyPosition()};
this.isOutside=function(b){return!d.isInside(b)};this.isInside=function(b){return b.x>=d.x&&b.x<=d.x+d.width&&b.y>=d.y&&b.y<=d.y+d.height};this.isPartlyInside=function(b){var c=b.rect();return c.right>=d.x&&c.x<=d.x+d.width&&c.bottom>=d.y&&b.y<=d.y+d.height};this.isLeftOf=function(b){return b.x<d.x};this.isRightOf=function(b){return b.x>d.x+d.width};this.isAbove=function(b){return b.y<d.y};this.isBelow=function(b){return b.y>d.y+d.height};this.centerAround=function(b){this.x=Math.floor(b.x-this.width/
2);this.y=Math.floor(b.y-this.height/2);this.verifyPosition()};this.forceInsideVisibleArea=function(b,d){b.x<this.x+d&&(b.x=this.x+d);b.x>this.x+c.width-d&&(b.x=this.x+c.width-d);b.y<this.y+d&&(b.y=this.y+d);b.y>this.y+c.height-d&&(b.y=this.y+c.height-d)};this.forceInside=function(b,c){b.x<c&&(b.x=c);b.x>this.max_x-c&&(b.x=this.max_x-c);b.y<c&&(b.y=c);b.y>this.max_y-c&&(b.y=this.max_y-c)};this.apply=function(b){this.context.save();this.context.translate(-this.x,-this.y);b();this.context.restore()};
this.draw=function(b){this.apply(function(){b.forEach?b.forEach(d.drawIfPartlyInside):b.draw&&d.drawIfPartlyInside(b)})};this.drawTileMap=function(b){var c=b.atRect({x:this.x,y:this.y,right:this.x+this.width,bottom:this.y+this.height});this.apply(function(){for(var b=0;b<c.length;b++)c[b].draw()})};this.drawIfPartlyInside=function(b){d.isPartlyInside(b)&&b.draw()};this.verifyPosition=function(){var b=this.max_x-this.width;0>this.x&&(this.x=0);this.x>b&&(this.x=b);b=this.max_y-this.height;0>this.y&&
(this.y=0);this.y>b&&(this.y=b)};this.moveTo(b.x||0,b.y||0)};c.Viewport.prototype.default_options={context:null,width:null,height:null,max_x:null,max_y:null,x:0,y:0};c.Viewport.prototype.toString=function(){return"[Viewport "+this.x.toFixed(2)+", "+this.y.toFixed(2)+", "+this.width+", "+this.height+"]"};return c}(jaws||{});
jaws=function(c){c.TileMap=function(b){if(!(this instanceof arguments.callee))return new arguments.callee(b);c.parseOptions(this,b,this.default_options);this.cells=Array(this.size[0]);for(var d=0;d<this.size[0];d++){this.cells[d]=Array(this.size[1]);for(var e=0;e<this.size[1];e++)this.cells[d][e]=[]}};c.TileMap.prototype.default_options={cell_size:[32,32],size:[100,100],sortFunction:null};c.TileMap.prototype.clear=function(){for(var b=0;b<this.size[0];b++)for(var c=0;c<this.size[1];c++)this.cells[b][c]=
[]};c.TileMap.prototype.sortCells=function(b){for(var c=0;c<this.size[0];c++)for(var e=0;e<this.size[1];e++)this.cells[c][e].sort(b)};c.TileMap.prototype.push=function(b){var c=this;if(b.forEach)return b.forEach(function(b){c.push(b)}),b;if(b.rect)return this.pushAsRect(b,b.rect());var e=parseInt(b.x/this.cell_size[0]),f=parseInt(b.y/this.cell_size[1]);return this.pushToCell(e,f,b)};c.TileMap.prototype.pushAsPoint=function(b){if(Array.isArray(b)){for(var c=0;c<b.length;c++)this.pushAsPoint(b[c]);
return b}var c=parseInt(b.x/this.cell_size[0]),e=parseInt(b.y/this.cell_size[1]);return this.pushToCell(c,e,b)};c.TileMap.prototype.pushAsRect=function(b,c){for(var e=parseInt(c.x/this.cell_size[0]),f=parseInt((c.right-1)/this.cell_size[0]);e<=f;e++)for(var k=parseInt(c.y/this.cell_size[1]),l=parseInt((c.bottom-1)/this.cell_size[1]);k<=l;k++)this.pushToCell(e,k,b);return b};c.TileMap.prototype.pushToCell=function(b,c,e){this.cells[b][c].push(e);this.sortFunction&&this.cells[b][c].sort(this.sortFunction);
return this};c.TileMap.prototype.at=function(b,c){var e=parseInt(b/this.cell_size[0]),f=parseInt(c/this.cell_size[1]);return this.cells[e][f]};c.TileMap.prototype.atRect=function(b){var c=[];try{var e=parseInt(b.x/this.cell_size[0]);0>e&&(e=0);var f=parseInt(b.right/this.cell_size[0]);f>=this.size[0]&&(f=this.size[0]-1);var k=parseInt(b.y/this.cell_size[1]);0>k&&(k=0);var l=parseInt(b.bottom/this.cell_size[1]);l>=this.size[1]&&(l=this.size[1]-1);for(b=e;b<=f;b++)for(e=k;e<=l;e++)this.cells[b][e].forEach(function(b){-1==
c.indexOf(b)&&c.push(b)})}catch(g){}return c};c.TileMap.prototype.all=function(){for(var b=[],c=0;c<this.size[0];c++)for(var e=0;e<this.size[1];e++)this.cells[c][e].forEach(function(c){b.push(c)});return b};c.TileMap.prototype.cell=function(b,c){return this.cells[b][c]};c.TileMap.prototype.findPath=function(b,c,e){"undefined"==typeof e&&(e=!1);var f=parseInt(b[0]/this.cell_size[0]),k=parseInt(b[1]/this.cell_size[1]),l=parseInt(c[0]/this.cell_size[0]);c=parseInt(c[1]/this.cell_size[1]);if(f===l&&k===
c)return[{x:b[0],y:b[1]}];for(var g=f,h=k,r=0,p=0,s=2*this.size[0]*this.size[1]+1,q=Array(this.size[0]),n=0;n<this.size[0];n++){q[n]=Array(this.size[1]);for(var m=0;m<this.size[1];m++)q[n][m]=!1}q[g][h]={parent:[],G:0,score:s};b=Array(this.size[0]);for(n=0;n<this.size[0];n++){b[n]=Array(this.size[1]);for(m=0;m<this.size[1];m++)b[n][m]=!1}for(;!(g===l&&h===c);){m=[];0<g&&m.push([g-1,h]);g<this.size[0]-1&&m.push([g+1,h]);0<h&&m.push([g,h-1]);h<this.size[1]-1&&m.push([g,h+1]);for(n=0;n<m.length;n++){var j=
m[n][0],u=m[n][1];if(p=0===this.cell(j,u).length&&!e||0<this.cell(j,u).length&&e)p=b[j][u]?!0:!1,p=!p;if(p){var p=r+1,v;v=[j,u];var w=[l,c];v=Math.abs(w[0]-v[0])+Math.abs(w[1]-v[1]);p+=v;if(!q[j][u]||q[j][u]&&q[j][u].score>p)q[j][u]={parent:[g,h],G:r+1,score:p}}}h=[];j=[];g=s;for(n=r=0;n<this.size[0];n++)for(m=0;m<this.size[1];m++)q[n][m]&&q[n][m].score<g&&(h=[n,m],j=q[n][m].parent,g=q[n][m].score,r=q[n][m].G);if(0===h.length)return[];q[h[0]][h[1]]=!1;g=h[0];h=h[1];b[g][h]={parent:j}}e=[];l=b[g][h];
for(e.unshift({x:g*this.cell_size[0],y:h*this.cell_size[1]});!(g===f&&h===k);)g=l.parent[0],h=l.parent[1],e.unshift({x:g*this.cell_size[0],y:h*this.cell_size[1]}),l=b[g][h];return e};c.TileMap.prototype.lineOfSight=function(b,c,e){"undefined"==typeof e&&(e=!1);var f=b[0],k=c[0];b=b[1];c=c[1];var l=Math.abs(k-f),g=Math.abs(c-b),h,r;h=f<k?1:-1;r=b<c?1:-1;for(var p=l-g,s;!(f===k&&b===c);){if(e){if(0===this.at(f,b).length)return!1}else if(0<this.at(f,b).length)return!1;s=2*p;s>-g&&(p-=g,f+=h);s<l&&(p+=
l,b+=r)}return!0};c.TileMap.prototype.toString=function(){return"[TileMap "+this.size[0]+" cols, "+this.size[1]+" rows]"};return c}(jaws||{});"undefined"!==typeof module&&"exports"in module&&(module.exports=jaws.TileMap);
jaws=function(c){c.collideOneWithOne=function(b,d){return b.radius&&d.radius&&b!==d&&c.collideCircles(b,d)||b.rect&&d.rect&&b!==d&&c.collideRects(b.rect(),d.rect())?!0:!1};c.collideOneWithMany=function(b,d){return d.filter(function(d){return c.collideOneWithOne(b,d)})};c.collideManyWithMany=function(b,d){var e=[];if(b===d){for(var f=function(c){return void 0!==b.isSpriteList?b.at(c):b[c]},k=[],l=Array(2),g=0;2>g;g++)l[g]=g;for(var g=1,h=b.length;0<=g;h=b.length){for(k.push(l.map(f));0<=g&&l[g]==h-
1;)g--,h--;if(0<=g){l[g]+=1;for(g+=1;2>g;g++)l[g]=l[g-1]+1;g=1}}k.forEach(function(b){c.collideOneWithOne(b[0],b[1])&&e.push([b[0],b[1]])})}else b.forEach(function(b){d.forEach(function(d){c.collideOneWithOne(b,d)&&e.push([b,d])})});return e};c.collideCircles=function(b,d){return c.distanceBetween(b,d)<b.radius+d.radius};c.collideRects=function(b,c){return(b.x>=c.x&&b.x<=c.right||c.x>=b.x&&c.x<=b.right)&&(b.y>=c.y&&b.y<=c.bottom||c.y>=b.y&&c.y<=b.bottom)};c.distanceBetween=function(b,c){return Math.sqrt(Math.pow(b.x-
c.x,2)+Math.pow(b.y-c.y,2))};return c}(jaws||{});
jaws=function(c){c.gfx={};c.gfx.retroScaleImage=function(b,d){var e=c.isImage(b)?c.imageToCanvas(b):b,e=e.getContext("2d").getImageData(0,0,e.width,e.height).data,f=document.createElement("canvas");f.width=b.width*d;f.height=b.height*d;for(var k=f.getContext("2d"),l=k.createImageData(f.width,f.height),g=l.width,h=l.height,r=0;r<h;r+=1)for(var p=r*l.width,s=Math.floor(r/d)*b.width,q=0;q<g;q+=1){var n=4*(p+q),m=4*(s+Math.floor(q/d));l.data[n]=e[m];l.data[n+1]=e[m+1];l.data[n+2]=e[m+2];l.data[n+3]=e[m+
3]}k.putImageData(l,0,0);return f};return c}(jaws||{});window.addEventListener("load",function(){if(jaws.onload)jaws.onload()},!1);