forked from GameJs/gamejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamejs.mini.js
69 lines (69 loc) · 30.3 KB
/
gamejs.mini.js
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
require.define({gamejs:function(j,a){function h(){var c=0,d=0,a=0,e=0;if(arguments.length===2)arguments[0]instanceof Array&&arguments[1]instanceof Array?(c=arguments[0][0],d=arguments[0][1],a=arguments[1][0],e=arguments[1][1]):(c=arguments[0],d=arguments[1]);else if(arguments.length===1&&arguments[0]instanceof Array)c=arguments[0][0],d=arguments[0][1],a=arguments[0][2],e=arguments[0][3];else if(arguments.length===1&&arguments[0]instanceof b)c=arguments[0].left,d=arguments[0].top,a=arguments[0].width,
e=arguments[0].height;else if(arguments.length===4)c=arguments[0],d=arguments[1],a=arguments[2],e=arguments[3];else throw Error("not a valid rectangle specification");return{left:c||0,top:d||0,width:a||0,height:e||0}}var g=j("./gamejs/utils/matrix"),f=j("./gamejs/utils/objects"),e=["info","warn","error","fatal"],d=2;a.setLogLevel=function(b){if(typeof b==="string"&&e.indexOf(b))d=e.indexOf(b);else if(typeof b==="number")d=b;else throw Error("invalid logLevel ",b," Must be one of: ",e);return d};var c=
a.log=function(){var b=Array.prototype.slice.apply(arguments,[0]);b.unshift(Date.now());window.console!==void 0&&console.log.apply&&console.log.apply(console,b)};a.info=function(){d<=e.indexOf("info")&&c.apply(this,arguments)};a.warn=function(){d<=e.indexOf("warn")&&c.apply(this,arguments)};a.error=function(){d<=e.indexOf("error")&&c.apply(this,arguments)};a.fatal=function(){d<=e.indexOf("fatal")&&c.apply(this,arguments)};var b=a.Rect=function(){var b=h.apply(this,arguments);this.left=b.left;this.top=
b.top;this.width=b.width;this.height=b.height;return this};f.accessors(b.prototype,{bottom:{get:function(){return this.top+this.height},set:function(b){this.top=b-this.height}},right:{get:function(){return this.left+this.width},set:function(b){this.left=b-this.width}},center:{get:function(){return[this.left+this.width/2,this.top+this.height/2]},set:function(){var b=h.apply(this,arguments);this.left=b.left-this.width/2;this.top=b.top-this.height/2}},topleft:{get:function(){return[this.left,this.top]},
set:function(){var b=h.apply(this,arguments);this.left=b.left;this.top=b.top}},bottomleft:{get:function(){return[this.left,this.bottom]},set:function(){var b=h.apply(this,arguments);this.left=b.left;this.bottom=b.bottom}},topright:{get:function(){return[this.right,this.top]},set:function(){var b=h.apply(this,arguments);this.right=b.right;this.top=b.top}},bottomright:{get:function(){return[this.right,this.bottom]},set:function(){var b=h.apply(this,arguments);this.right=b.right;this.bottom=b.bottom}},
x:{get:function(){return this.left},set:function(b){this.left=b}},y:{get:function(){return this.top},set:function(b){this.top=b}}});b.prototype.move=function(){var c=h.apply(this,arguments);return new b(this.left+c.left,this.top+c.top,this.width,this.height)};b.prototype.moveIp=function(){var b=h.apply(this,arguments);this.left+=b.left;this.top+=b.top};b.prototype.clip=function(c){if(!this.collideRect(c))return new b(0,0,0,0);var d,a,e,k;if(this.left>=c.left&&this.left<c.right)d=this.left;else if(c.left>=
this.left&&c.left<this.right)d=c.left;this.right>c.left&&this.right<=c.right?e=this.right-d:c.right>this.left&&c.right<=this.right&&(e=c.right-d);if(this.top>=c.top&&this.top<c.bottom)a=this.top;else if(c.top>=this.top&&c.top<this.bottom)a=c.top;this.bottom>c.top&&this.bottom<=c.bottom?k=this.bottom-a:c.bottom>this.top&&c.bottom<=this.bottom&&(k=c.bottom-a);return new b(d,a,e,k)};b.prototype.union=function(c){var d,a;d=Math.min(this.left,c.left);a=Math.min(this.top,c.top);return new b(d,a,Math.max(this.right,
c.right)-d,Math.max(this.bottom,c.bottom)-a)};b.prototype.collidePoint=function(){var b=h.apply(this,arguments);return this.left<=b.left&&b.left<=this.right&&this.top<=b.top&&b.top<=this.bottom};b.prototype.collideRect=function(b){return!(this.left>b.right||this.right<b.left||this.top>b.bottom||this.bottom<b.top)};b.prototype.collideLine=function(b,c){var d=b[0],a=b[1],e=c[0],k=c[1],f=!0,h=!0,g=!0;[[this.left,this.top],[this.left,this.bottom],[this.right,this.top],[this.right,this.bottom]].map(function(b){return(k-
a)*b[0]+(d-e)*b[1]+(e*a-d*k)}).forEach(function(b){b>0?h=!1:b<0?f=!1:b===0&&(g=!1)},this);if((f||h)&&g)return!1;return!(d>this.right&&e>this.right||d<this.left&&e<this.left||a<this.top&&k<this.top||a>this.bottom&&k>this.bottom)};b.prototype.toString=function(){return["[",this.left,",",this.top,"] [",this.width,",",this.height,"]"].join("")};b.prototype.clone=function(){return new b(this)};var k=a.Surface=function(){var c=h.apply(this,arguments),d=c.left,a=c.top;if(arguments.length==1&&arguments[0]instanceof
b)d=c.width,a=c.height;this._matrix=g.identity();this._canvas=document.createElement("canvas");this._canvas.width=d;this._canvas.height=a;this._blitAlpha=1;this._context=this._canvas.getContext("2d");this._smooth();return this};k.prototype._noSmooth=function(){this.context.mozImageSmoothingEnabled=!1;this.canvas.style.setProperty("image-rendering","optimizeSpeed","important");this.canvas.style.setProperty("image-rendering","-moz-crisp-edges","important");this.canvas.style.setProperty("image-rendering",
"-webkit-optimize-contrast","important");this.canvas.style.setProperty("image-rendering","optimize-contrast","important");this.canvas.style.setProperty("-ms-interpolation-mode","nearest-neighbor","important")};k.prototype._smooth=function(){this.canvas.style.setProperty("image-rendering","optimizeQuality","important");this.canvas.style.setProperty("-ms-interpolation-mode","bicubic","important");this.context.mozImageSmoothingEnabled=!0};k.prototype.blit=function(c,d,a,e){if(d instanceof b){var d=d.clone(),
k=c.getSize();if(!d.width)d.width=k[0];if(!d.height)d.height=k[1]}else d=d&&d instanceof Array&&d.length==2?new b(d,c.getSize()):new b([0,0],c.getSize());e=e||"source-over";a instanceof b||(a&&a instanceof Array&&a.length==2?(k=c.getSize(),a=new b(a,[k[0]-a[0],k[1]-a[1]])):a=new b([0,0],c.getSize()));if(isNaN(d.left)||isNaN(d.top)||isNaN(d.width)||isNaN(d.height))throw Error("[blit] bad parameters, destination is "+d);this.context.save();this.context.globalCompositeOperation=e;e=g.translate(g.identity(),
d.left,d.top);e=g.multiply(e,c._matrix);this.context.transform(e[0],e[1],e[2],e[3],e[4],e[5]);c.getRect();this.context.globalAlpha=c._blitAlpha;this.context.drawImage(c.canvas,a.left,a.top,a.width,a.height,0,0,d.width,d.height);this.context.restore()};k.prototype.getSize=function(){return[this.canvas.width,this.canvas.height]};k.prototype.getRect=function(){return new b([0,0],this.getSize())};k.prototype.fill=function(b){this.context.save();this.context.fillStyle=b||"#000000";this.context.fillRect(0,
0,this.canvas.width,this.canvas.height);this.context.restore()};k.prototype.clear=function(){var b=this.getSize();this.context.clearRect(0,0,b[0],b[1])};f.accessors(k.prototype,{rect:{get:function(){return this.getRect()}},context:{get:function(){return this._context}},canvas:{get:function(){return this._canvas}}});k.prototype.clone=function(){var b=new k(this.getRect());b.blit(this);return b};k.prototype.getAlpha=function(){return 1-this._blitAlpha};k.prototype.setAlpha=function(b){if(!isNaN(b)&&
!(b<0||b>1))return this._blitAlpha=1-b,1-this._blitAlpha};k.prototype.getImageData=function(){var b=this.getSize();return this.context.getImageData(0,0,b[0],b[1])};a.display=j("./gamejs/display");a.draw=j("./gamejs/draw");a.event=j("./gamejs/event");a.font=j("./gamejs/font");a.http=j("./gamejs/http");a.image=j("./gamejs/image");a.mask=j("./gamejs/mask");a.mixer=j("./gamejs/mixer");a.sprite=j("./gamejs/sprite");a.surfacearray=j("./gamejs/surfacearray");a.time=j("./gamejs/time");a.transform=j("./gamejs/transform");
a.utils={arrays:j("./gamejs/utils/arrays"),objects:j("./gamejs/utils/objects"),matrix:j("./gamejs/utils/matrix"),vectors:j("./gamejs/utils/vectors"),math:j("./gamejs/utils/math")};a.pathfinding={astar:j("./gamejs/pathfinding/astar")};var m=a,l={};a.ready=function(b){function c(){if(!document.body)return window.setTimeout(c,50);e=m.image.preload(l);try{a=m.mixer.preload(l)}catch(b){m.debug("Error loading audio files ",b)}window.setTimeout(d,50)}function d(){if(e()<1||a()<1)return window.setTimeout(d,
100);m.display.init();m.image.init();m.mixer.init();m.event.init();b()}var a=null,e=null;m.time.init();window.setTimeout(c,13);return function(){if(e)return 0.5*e()+0.5*a();return 0.1}};a.preload=function(b){var c=window.$g&&window.$g.resourceBaseHref||".";c.slice(-1)=="/"&&(c=c.slice(0,c.length-1));b.forEach(function(b){l[b]=(window.$g&&window.$g.resourceBaseHref||".")+("/"+b).replace(/\/+/g,"/")},this)}}},["gamejs/utils/matrix","gamejs/utils/objects","gamejs/display","gamejs/draw","gamejs/event",
"gamejs/font","gamejs/http","gamejs/image","gamejs/mask","gamejs/mixer","gamejs/sprite","gamejs/surfacearray","gamejs/time","gamejs/transform","gamejs/utils/arrays","gamejs/utils/vectors","gamejs/utils/math","gamejs/pathfinding/astar"]);
require.define({"gamejs/transform":function(j,a){var h=j("../gamejs").Surface,g=j("./utils/matrix");j("./utils/math");var f=j("./utils/vectors");a.rotate=function(a,d){var c=a.getSize(),b=d*Math.PI/180,k=c;if(d%360!==0)var k=a.getRect(),k=[[-k.width/2,k.height/2],[k.width/2,k.height/2],[-k.width/2,-k.height/2],[k.width/2,-k.height/2]].map(function(c){return f.rotate(c,b)}),m=k.map(function(b){return b[0]}),l=k.map(function(b){return b[1]}),k=Math.min.apply(Math,m),m=Math.max.apply(Math,m),j=Math.min.apply(Math,
l),l=Math.max.apply(Math,l),k=[m-k,l-j];l=new h(k);m=a._matrix;a._matrix=g.translate(a._matrix,c[0]/2,c[1]/2);a._matrix=g.rotate(a._matrix,b);a._matrix=g.translate(a._matrix,-c[0]/2,-c[1]/2);l.blit(a,[(k[0]-c[0])/2,(k[1]-c[1])/2]);a._matrix=m;return l};a.scale=function(a,d){var c=d[0],b=d[1];if(c<=0||b<=0)throw Error("[gamejs.transform.scale] Invalid arguments for height and width",[c,b]);var k=a.getSize(),f=c/k[0],k=b/k[1],c=new h([c,b]),b=a._matrix.slice(0);a._matrix=g.scale(a._matrix,[f,k]);c.blit(a);
a._matrix=b;return c};a.flip=function(a,d,c){var b=a.getSize(),k=new h(b),f=1,g=1,j=0,o=0;d===!0&&(f=-1,j=-b[0]);c===!0&&(g=-1,o=-b[1]);k.context.save();k.context.scale(f,g);k.context.drawImage(a.canvas,j,o);k.context.restore();return k}}},["gamejs","gamejs/utils/matrix","gamejs/utils/math","gamejs/utils/vectors"]);
require.define({"gamejs/time":function(j,a){var h={},g={};a.init=function(){Date.now();setInterval(f,10)};a.fpsCallback=function(a,d,c){c=parseInt(1E3/c,10);h[c]=h[c]||[];g[c]=g[c]||0;h[c].push({rawFn:a,callback:function(b){a.apply(d,[b])}})};a.deleteCallback=function(a,d){var d=parseInt(1E3/d,10),c=h[d];c&&(h[d]=c.filter(function(b){if(b.rawFn!==a)return!0;return!1}))};var f=function(){function a(c){c.callback(b)}var d=Date.now(),c;for(c in g){g[c]||(g[c]=d);var b=d-g[c];c<=b&&(g[c]=d,h[c].forEach(a,
this))}}}},[]);
require.define({"gamejs/mask":function(j,a){var h=j("../gamejs"),g=j("./utils/objects");a.fromSurface=function(a,d){for(var d=d&&255-d||255,c=a.getImageData().data,b=a.getSize(),k=new f(b),h=0;h<c.length;h+=4){var g=parseInt(h/4/b[0],10),j=parseInt(h/4%b[0],10);c[h+3]>=d&&k.setAt(j,g)}return k};var f=a.Mask=function(a){this.width=a[0];this.height=a[1];this._bits=[];for(a=0;a<this.width;a++){this._bits[a]=[];for(var d=0;d<this.height;d++)this._bits[a][d]=!1}};f.prototype.overlapRect=function(a,d){var c=
this.rect,b=a.rect;d&&b.moveIp(d);if(!b.collideRect(c))return null;var k=Math.max(c.left,b.left),f=Math.max(c.top,b.top);return new h.Rect([k,f],[Math.min(c.right,b.right)-k,Math.min(c.bottom,b.bottom)-f])};f.prototype.overlap=function(a,d){var c=this.overlapRect(a,d);if(c===null)return!1;var b=this.rect,k=a.rect;d&&k.moveIp(d);for(var f=c.top;f<=c.bottom;f++)for(var h=c.left;h<=c.right;h++)if(this.getAt(h-b.left,f-b.top)&&a.getAt(h-k.left,f-k.top))return!0;return!1};f.prototype.overlapArea=function(a,
d){var c=this.overlapRect(a,d);if(c===null)return 0;var b=this.rect,k=a.rect;d&&k.moveIp(d);for(var f=0,h=c.top;h<=c.bottom;h++)for(var g=c.left;g<=c.right;g++)this.getAt(g-b.left,h-b.top)&&a.getAt(g-k.left,h-k.top)&&f++;return f};f.prototype.overlapMask=function(a,d){var c=this.overlapRect(a,d);if(c===null)return 0;var b=this.rect,k=a.rect;d&&k.moveIp(d);for(var h=new f([c.width,c.height]),g=c.top;g<=c.bottom;g++)for(var j=c.left;j<=c.right;j++)this.getAt(j-b.left,g-b.top)&&a.getAt(j-k.left,g-k.top)&&
h.setAt(j,g);return h};f.prototype.setAt=function(a,d){this._bits[a][d]=!0};f.prototype.getAt=function(a,d){a=parseInt(a,10);d=parseInt(d,10);if(a<0||d<0||a>=this.width||d>=this.height)return!1;return this._bits[a][d]};f.prototype.invert=function(){this._bits=this._bits.map(function(a){return a.map(function(a){return!a})})};f.prototype.getSize=function(){return[this.width,this.height]};g.accessors(f.prototype,{rect:{get:function(){return new h.Rect([0,0],[this.width,this.height])}},length:{get:function(){var a=
0;this._bits.forEach(function(d){d.forEach(function(c){c&&a++})});return a}}})}},["gamejs","gamejs/utils/objects"]);
require.define({"gamejs/event":function(j,a){var h=j("./display"),g=j("../gamejs");a.K_UP=38;a.K_DOWN=40;a.K_RIGHT=39;a.K_LEFT=37;a.K_SPACE=32;a.K_BACKSPACE=8;a.K_TAB=9;a.K_ENTER=13;a.K_SHIFT=16;a.K_CTRL=17;a.K_ALT=18;a.K_ESC=27;a.K_0=48;a.K_1=49;a.K_2=50;a.K_3=51;a.K_4=52;a.K_5=53;a.K_6=54;a.K_7=55;a.K_8=56;a.K_9=57;a.K_a=65;a.K_b=66;a.K_c=67;a.K_d=68;a.K_e=69;a.K_f=70;a.K_g=71;a.K_h=72;a.K_i=73;a.K_j=74;a.K_k=75;a.K_l=76;a.K_m=77;a.K_n=78;a.K_o=79;a.K_p=80;a.K_q=81;a.K_r=82;a.K_s=83;a.K_t=84;a.K_u=
85;a.K_v=86;a.K_w=87;a.K_x=88;a.K_y=89;a.K_z=90;a.K_KP1=97;a.K_KP2=98;a.K_KP3=99;a.K_KP4=100;a.K_KP5=101;a.K_KP6=102;a.K_KP7=103;a.K_KP8=104;a.K_KP9=105;a.NOEVENT=0;a.NUMEVENTS=32E3;a.QUIT=0;a.KEY_DOWN=1;a.KEY_UP=2;a.MOUSE_MOTION=3;a.MOUSE_UP=4;a.MOUSE_DOWN=5;a.MOUSE_WHEEL=6;a.USEREVENT=24;var f=[];a.get=function(){return f.splice(0,f.length)};a.poll=function(){return f.pop()};a.post=function(a){f.push(a)};a.clear=function(){f=[]};a.Event=function(){this.pos=this.button=this.rel=this.key=this.type=
null};a.init=function(){function e(b){var a=h._getCanvasOffset();f.push({type:g.event.MOUSE_WHEEL,pos:[b.clientX-a[0],b.clientY-a[1]],delta:b.detail||-b.wheelDeltaY/40})}var d=[],c=h.getSurface()._canvas;c.addEventListener("mousedown",function(b){var a=h._getCanvasOffset();f.push({type:g.event.MOUSE_DOWN,pos:[b.clientX-a[0],b.clientY-a[1]],button:b.button,shiftKey:b.shiftKey,ctrlKey:b.ctrlKey,metaKey:b.metaKey})},!1);c.addEventListener("mouseup",function(b){var a=h._getCanvasOffset();f.push({type:g.event.MOUSE_UP,
pos:[b.clientX-a[0],b.clientY-a[1]],button:b.button,shiftKey:b.shiftKey,ctrlKey:b.ctrlKey,metaKey:b.metaKey})},!1);document.addEventListener("keydown",function(b){var c=b.keyCode||b.which;f.push({type:g.event.KEY_DOWN,key:c,shiftKey:b.shiftKey,ctrlKey:b.ctrlKey,metaKey:b.metaKey});(!b.ctrlKey&&!b.metaKey&&(c>=a.K_LEFT&&c<=a.K_DOWN||c>=a.K_0&&c<=a.K_z||c>=a.K_KP1&&c<=a.K_KP9||c===a.K_SPACE||c===a.K_TAB||c===a.K_ENTER)||c===a.K_ALT||c===a.K_BACKSPACE)&&b.preventDefault()},!1);document.addEventListener("keyup",
function(b){f.push({type:g.event.KEY_UP,key:b.keyCode,shiftKey:b.shiftKey,ctrlKey:b.ctrlKey,metaKey:b.metaKey})},!1);c.addEventListener("mousemove",function(b){var a=h._getCanvasOffset(),a=[b.clientX-a[0],b.clientY-a[1]],c=[];d.length&&(c=[d[0]-a[0],d[1]-a[1]]);f.push({type:g.event.MOUSE_MOTION,pos:a,rel:c,buttons:null,timestamp:b.timeStamp});d=a},!1);c.addEventListener("mousewheel",e,!1);c.addEventListener("DOMMouseScroll",e,!1);c.addEventListener("beforeunload",function(){f.push({type:g.event.QUIT})},
!1)}}},["gamejs/display","gamejs"]);
require.define({"gamejs/draw":function(j,a){a.line=function(a,g,f,e,d){a=a.context;a.save();a.beginPath();a.strokeStyle=g;a.lineWidth=d||1;a.moveTo(f[0],f[1]);a.lineTo(e[0],e[1]);a.stroke();a.restore()};a.lines=function(a,g,f,e,d){var f=f||!1,c=a.context;c.save();c.beginPath();c.strokeStyle=c.fillStyle=g;c.lineWidth=d||1;e.forEach(function(b,a){a===0?c.moveTo(b[0],b[1]):c.lineTo(b[0],b[1])});f&&c.lineTo(e[0][0],e[0][1]);c.stroke();c.restore()};a.circle=function(a,g,f,e,d){if(!e)throw Error("[circle] radius required argument");
if(!f||!(f instanceof Array))throw Error("[circle] pos must be given & array"+f);a=a.context;a.save();a.beginPath();a.strokeStyle=a.fillStyle=g;a.lineWidth=d||1;a.arc(f[0],f[1],e,0,2*Math.PI,!0);d===void 0||d===0?a.fill():a.stroke();a.restore()};a.rect=function(a,g,f,e){a=a.context;a.save();a.beginPath();a.strokeStyle=a.fillStyle=g;isNaN(e)||e===0?a.fillRect(f.left,f.top,f.width,f.height):(a.lineWidth=e||1,a.strokeRect(f.left,f.top,f.width,f.height));a.restore()};a.arc=function(a,g,f,e,d,c){a=a.context;
a.save();a.beginPath();a.strokeStyle=a.fillStyle=g;a.arc(f.center[0],f.center[1],f.width/2,e*(Math.PI/180),d*(Math.PI/180),!1);isNaN(c)||c===0?a.fill():(a.lineWidth=c||1,a.stroke());a.restore()};a.polygon=function(a,g,f,e){var d=a.context;d.save();d.fillStyle=d.strokeStyle=g;d.beginPath();f.forEach(function(a,b){b==0?d.moveTo(a[0],a[1]):d.lineTo(a[0],a[1])});d.closePath();isNaN(e)||e===0?d.fill():(d.lineWidth=e||1,d.stroke());d.restore()}}},[]);
require.define({"gamejs/display":function(j,a){var h=j("../gamejs").Surface,g=null,f=function(){var a=null;Array.prototype.slice.call(document.getElementsByTagName("canvas")).every(function(c){if(c.getAttribute("id")=="gjs-canvas")return a=c,!1;return!0});return a};a.init=function(){var a=null;f()===null&&(a=document.createElement("canvas"),a.setAttribute("id","gjs-canvas"),document.body.appendChild(a));(a=document.getElementById("gjs-loader"))&&a.parentNode.removeChild(a)};a.setMode=function(a){var c=
f();c.width=a[0];c.height=a[1];return e()};a.setCaption=function(a){document.title=a};a._getCanvasOffset=function(){var a=f().getBoundingClientRect();return[a.left,a.top]};var e=a.getSurface=function(){if(g===null){var a=f();g=new h([a.clientWidth,a.clientHeight]);g._canvas=a;g._context=a.getContext("2d");g._smooth()}return g}}},["gamejs"]);
require.define({"gamejs/surfacearray":function(j,a){var h=j("../gamejs"),g=j("./utils/objects").accessors;a.blitArray=function(a,e){a.context.putImageData(e.imageData,0,0)};a.SurfaceArray=function(a){var e=null,d=null,c=null;this.set=function(a,c,f){a=a*4+c*e[0]*4;d[a]=f[0];d[a+1]=f[1];d[a+2]=f[2];d[a+3]=f[3]===void 0?255:f[3]};this.get=function(a,c){var f=a*4+c*e[0]*4;return[d[f],d[f+1],d[f+2],d[f+3]]};this.surface=null;g(this,{surface:{get:function(){var a=new h.Surface(e);a.context.putImageData(c,
0,0);return a}},imageData:{get:function(){return c}}});this.getSize=function(){return e};a instanceof Array?(e=a,c=h.display.getSurface().context.createImageData(e[0],e[1])):(e=a.getSize(),c=a.getImageData(0,0,e[0],e[1]));d=c.data;return this}}},["gamejs","gamejs/utils/objects"]);
require.define({"gamejs/http":function(j,a){function h(a){return eval("("+a.responseText+")")}a.Response=function(){this.getResponseHeader=function(){};throw Error("response class not instantiable");};var g=a.ajax=function(a,c,b,f){var b=b||null,e=new XMLHttpRequest;e.open(a,c,!1);f&&e.setRequestHeader("Accept",f);b instanceof Object&&(b=JSON.stringify(b),e.setRequestHeader("Content-Type","application/json"));e.setRequestHeader("X-Requested-With","XMLHttpRequest");e.send(b);return e},f=a.get=function(a){return g("GET",
a)},e=a.post=function(a,c,b){return g("POST",a,c,b)};a.load=function(a){return h(f((window.$g&&window.$g.ajaxBaseHref||"./")+a))};a.save=function(a,c,b){return h(e((window.$g&&window.$g.ajaxBaseHref||"./")+a,{payload:c},b))}}},[]);
require.define({"gamejs/sprite":function(j,a){j("../gamejs");var h=j("./utils/arrays"),g=j("./utils/objects"),f=j("./utils/vectors"),e=a.Sprite=function(){this._groups=[];this._alive=!0;this.rect=this.image=null;g.accessor(this,"groups",function(){return this._groups});return this};e.prototype.kill=function(){this._alive=!1;this._groups.forEach(function(a){a.remove(this)},this)};e.prototype.remove=function(a){a instanceof Array||(a=[a]);a.forEach(function(a){a.remove(this)},this)};e.prototype.add=
function(a){a instanceof Array||(a=[a]);a.forEach(function(a){a.add(this)},this)};e.prototype.draw=function(a){a.blit(this.image,this.rect)};e.prototype.update=function(){};e.prototype.isDead=function(){return!this._alive};var d=a.Group=function(a){this._sprites=[];(a instanceof e||a instanceof Array&&a.length&&a[0]instanceof e)&&this.add(a);return this};d.prototype.update=function(){var a=arguments;this._sprites.forEach(function(c){c.update.apply(c,a)},this)};d.prototype.add=function(a){a instanceof
Array||(a=[a]);a.forEach(function(a){this._sprites.push(a);a._groups.push(this)},this)};d.prototype.remove=function(a){a instanceof Array||(a=[a]);a.forEach(function(a){h.remove(a,this._sprites);h.remove(this,a._groups)},this)};d.prototype.has=function(a){a instanceof Array||(a=[a]);return a.every(function(a){return this._sprites.indexOf(a)!==-1},this)};d.prototype.sprites=function(){return this._sprites};d.prototype.draw=function(){var a=arguments;this._sprites.forEach(function(c){c.draw.apply(c,
a)},this)};d.prototype.clear=function(a,c){this._sprites.forEach(function(d){a.blit(c,d.rect)},this)};d.prototype.empty=function(){this._sprites=[]};d.prototype.collidePoint=function(){var a=Array.prototype.slice.apply(arguments);return this._sprites.filter(function(c){return c.rect.collidePoint.apply(c.rect,a)},this)};d.prototype.forEach=function(a,c){return this._sprites.forEach(a,c)};d.prototype.some=function(a,c){return this._sprites.some(a,c)};a.spriteCollide=function(a,d,f,e){var e=e||c,f=f||
!1,g=[];d.sprites().forEach(function(c){e(a,c)&&(f&&c.kill(),g.push(c))});return g};a.groupCollide=function(a,d,f,e,g){var f=f||!1,e=e||!1,h=[],j=g||c;a.sprites().forEach(function(a){d.sprites().forEach(function(c){j(a,c)&&(f&&a.kill(),e&&c.kill(),h.push({a:a,b:c}))})});return h};var c=a.collideRect=function(a,c){return a.rect.collideRect(c.rect)};a.collideMask=function(a,c){if(!a.mask||!c.mask)throw Error("Both sprites must have 'mask' attribute set to an gamejs.mask.Mask");return a.mask.overlap(c.mask,
[c.rect.left-a.rect.left,c.rect.top-a.rect.top])};a.collideCircle=function(a,c){var d=a.radius||Math.max(a.rect.width,a.rect.height),e=c.radius||Math.max(c.rect.width,c.rect.height);return f.distance(a.rect.center,c.rect.center)<=d+e}}},["gamejs","gamejs/utils/arrays","gamejs/utils/objects","gamejs/utils/vectors"]);
require.define({"gamejs/font":function(j,a){var h=j("../gamejs").Surface,g=j("./utils/objects"),f=a.Font=function(a){this.sampleSurface=new h([10,10]);this.sampleSurface.context.font=a;this.sampleSurface.context.textAlign="start";this.sampleSurface.context.textBaseline="bottom";return this};f.prototype.render=function(a,d){var c=this.size(a),c=new h(c),b=c.context;b.save();b.font=this.sampleSurface.context.font;b.textBaseline=this.sampleSurface.context.textBaseline;b.textAlign=this.sampleSurface.context.textAlign;
b.fillStyle=b.strokeStyle=d||"#000000";b.fillText(a,0,c.rect.height,c.rect.width);b.restore();return c};f.prototype.size=function(a){return[this.sampleSurface.context.measureText(a).width,this.fontHeight]};g.accessors(f.prototype,{fontHeight:{get:function(){return this.sampleSurface.context.measureText("M").width*1.5}}})}},["gamejs","gamejs/utils/objects"]);
require.define({"gamejs/pathfinding/astar":function(j,a){function h(a){var b={};this.store=function(d,f){b[a(d)]=f};this.find=function(d){return b[a(d)]};return this}var g=j("../utils/binaryheap").BinaryHeap;a.findRoute=function(a,b,d,j){function l(a){o.push(a);q.store(a.point,a)}function n(b){var d=q.find(b),f=p.length+a.actualDistance(p.point,b);if(!d||d.length>f)d&&o.remove(d),l({point:b,from:p,length:f})}var o=new g(function(b){if(b.score===void 0)b.score=a.estimatedDistance(b.point,d)+b.length;
return b.score}),q=new h(typeof a.hash==="function"?a.hash:e),r=Date.now(),p=null;l({point:b,from:null,length:0});for(b=typeof a.equals==="function"?a.equals:f;o.size()>0&&(!j||Date.now()-r<j);){p=o.pop();if(b(d,p.point))return p;a.adjacent(p.point).forEach(n)}return null};var f=function(a,b){return a[0]===b[0]&&a[1]===b[1]},e=function(a){return a[0]+"-"+a[1]},d=a.Map=function(){throw Error("not instantiable, this is an interface");};d.prototype.adjacent=function(){};d.prototype.equals=f;d.prototype.hash=
e;d.prototype.estimatedDistance=function(){return 1};d.prototype.actualDistance=function(){return 1}}},["gamejs/utils/binaryheap"]);require.define({"gamejs/utils/arrays":function(j,a){a.remove=function(a,g){if(g.indexOf(a)!==-1)return g.splice(g.indexOf(a),1);return[]};a.shuffle=function(a){for(i=a.length-1;i>0;i--){var g=parseInt(Math.random()*(i+1)),f=a[i];a[i]=a[g];a[g]=f}return a}}},[]);
require.define({"gamejs/utils/vectors":function(j,a){var h=j("./math");a.distance=function(a,b){return e(g(a,b))};var g=a.subtract=function(a,b){return[a[0]-b[0],a[1]-b[1]]};a.add=function(a,b){return[a[0]+b[0],a[1]+b[1]]};var f=a.multiply=function(a,b){if(typeof b==="number")return[a[0]*b,a[1]*b];return[a[0]*b[0],a[1]*b[1]]};a.divide=function(a,b){if(typeof b==="number")return[a[0]/b,a[1]/b];throw Error("only divide by scalar supported");};var e=a.len=function(a){return Math.sqrt(a[0]*a[0]+a[1]*
a[1])},d=a.unit=function(a){var b=e(a);if(b)return[a[0]/b,a[1]/b];return[0,0]};a.rotate=function(a,b){b=h.normaliseRadians(b);return[a[0]*Math.cos(b)-a[1]*Math.sin(b),a[0]*Math.sin(b)+a[1]*Math.cos(b)]};a.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]};a.angle=function(a,b){var d=Math.atan2(a[0],a[1])-Math.atan2(b[0],b[1]);return d-Math.floor((d+Math.PI)/(2*Math.PI))*2*Math.PI-2*Math.PI};a.truncate=function(a,b){if(e(a)>b)return f(d(a),b);return a}}},["gamejs/utils/math"]);
require.define({"gamejs/utils/math":function(j,a){a.normaliseDegrees=function(a){a%=360;a<0&&(a+=360);return a};a.normaliseRadians=function(a){a%=2*Math.PI;a<0&&(a+=2*Math.PI);return a};a.degrees=function(a){return a*(180/Math.PI)};a.radians=function(a){return a*(Math.PI/180)};a.centroid=function(){var a=Array.prototype.slice.apply(arguments,[0]),g=[0,0];a.forEach(function(a){g[0]+=parseInt(a[0],10);g[1]+=parseInt(a[1],10)});a=a.length;return[g[0]/a,g[1]/a]}}},[]);
require.define({"gamejs/utils/matrix":function(j,a){a.identity=function(){return[1,0,0,1,0,0]};a.add=function(a,f){return[a[0]+f[0],a[1]+f[1],a[2]+f[2],a[3]+f[3],a[4]+f[4],a[5]+f[5],a[6]+f[6]]};var h=a.multiply=function(a,f){return[a[0]*f[0]+a[2]*f[1],a[1]*f[0]+a[3]*f[1],a[0]*f[2]+a[2]*f[3],a[1]*f[2]+a[3]*f[3],a[0]*f[4]+a[2]*f[5]+a[4],a[1]*f[4]+a[3]*f[5]+a[5]]};a.translate=function(a,f,e){return h(a,[1,0,0,1,f,e])};a.rotate=function(a,f){var e=Math.sin(f),d=Math.cos(f);return h(a,[d,e,-e,d,0,0])};
a.rotation=function(a){return Math.atan2(a[1],a[0])};a.scale=function(a,f){return h(a,[f[0],0,0,f[1],0,0])}}},[]);
require.define({"gamejs/utils/binaryheap":function(j,a){var h=a.BinaryHeap=function(a){this.content=[];this.scoreFunction=a;return this};h.prototype.push=function(a){this.content.push(a);this.sinkDown(this.content.length-1)};h.prototype.pop=function(){var a=this.content[0],f=this.content.pop();this.content.length>0&&(this.content[0]=f,this.bubbleUp(0));return a};h.prototype.remove=function(a){if(!this.content.some(function(f,e){if(f==a){var d=this.content.pop();e!=this.content.length&&(this.content[e]=
d,this.scoreFunction(d)<this.scoreFunction(a)?this.sinkDown(e):this.bubbleUp(e));return!0}return!1},this))throw Error("Node not found.");};h.prototype.size=function(){return this.content.length};h.prototype.sinkDown=function(a){for(var f=this.content[a];a>0;){var e=Math.floor((a+1)/2)-1,d=this.content[e];if(this.scoreFunction(f)<this.scoreFunction(d))this.content[e]=f,this.content[a]=d,a=e;else break}};h.prototype.bubbleUp=function(a){for(var f=this.content.length,e=this.content[a],d=this.scoreFunction(e);;){var c=
(a+1)*2,b=c-1,k=null;if(b<f){var h=this.scoreFunction(this.content[b]);h<d&&(k=b)}if(c<f&&this.scoreFunction(this.content[c])<(k===null?d:h))k=c;if(k!==null)this.content[a]=this.content[k],this.content[k]=e,a=k;else break}}}},[]);
require.define({"gamejs/utils/objects":function(j,a){a.extend=function(a,e){if(a===void 0)throw Error("unknown subClass");if(e===void 0)throw Error("unknown superClass");var d=new Function;d.prototype=e.prototype;a.prototype=new d;a.prototype.constructor=a;a.superClass=e.prototype;a.superConstructor=e};a.merge=function(){for(var a={},e=arguments.length;e>0;--e){var d=arguments[e-1],c;for(c in d)a[c]=d[c]}return a};var h=a.keys=function(a){if(Object.keys)return Object.keys(a);var e=[],d;for(d in a)Object.prototype.hasOwnProperty.call(a,
d)&&e.push(d);return e},g=a.accessor=function(a,e,d,c){Object.defineProperty!==void 0?Object.defineProperty(a,e,{get:d,set:c}):Object.prototype.__defineGetter__!==void 0&&(a.__defineGetter__(e,d),c&&a.__defineSetter__(e,c))};a.accessors=function(a,e){h(e).forEach(function(d){g(a,d,e[d].get,e[d].set)})}}},[]);
require.define({"gamejs/image":function(j,a){var h=j("../gamejs"),g={};a.load=function(a){var e;if(typeof a==="string"){if(e=g[a],!e)throw Error('Missing "'+a+'", gamejs.preload() all images before trying to load them.');}else e=a;a=document.createElement("canvas");a.width=e.naturalWidth||e.width;a.height=e.naturalHeight||e.height;var d=a.getContext("2d");d.drawImage(e,0,0);e.getSize=function(){return[e.naturalWidth,e.naturalHeight]};var c=new h.Surface(e.getSize());c._canvas=a;c._context=d;return c};
a.init=function(){};a.preload=function(a){function e(){b++;b%10===0&&h.log("gamejs.image: preloaded "+b+" of "+k)}function d(){g[this.gamejsKey]=this;e()}function c(){e();throw Error("Error loading "+this.src);}var b=0,k=0,j;for(j in a)if(!(j.indexOf("png")==-1&&j.indexOf("jpg")==-1&&j.indexOf("gif")==-1)){var l=new Image;l.addEventListener("load",d,!0);l.addEventListener("error",c,!0);l.src=a[j];l.gamejsKey=j;k++}return function(){return k>0?b/k:1}}}},["gamejs"]);
require.define({"gamejs/mixer":function(j,a){function h(a){a instanceof Array||(a=[a]);a.forEach(function(a){g[a.gamejsKey]=a})}j("../gamejs");var g={},f=!1,e=8;a.setNumChannels=function(a){e=parseInt(a,10)||e};a.getNumChannels=function(){return e};a.init=function(){var a=Array.prototype.slice.call(document.getElementsByTagName("audio"),0);h(a)};a.preload=function(a){function c(){h(this);g++;g==e&&(f=!1)}function b(){g++;g==e&&(f=!1);throw Error("Error loading "+this.src);}var e=0,g=0,j;for(j in a)if(!(j.indexOf("wav")==
-1&&j.indexOf("ogg")==-1&&j.indexOf("webm")==-1)){e++;var n=new Audio;n.addEventListener("canplay",c,!0);n.addEventListener("error",b,!0);n.src=a[j];n.gamejsKey=j;n.load()}e>0&&(f=!0);return function(){return e>0?g/e:1}};a.isPreloading=function(){return f};a.Sound=function(a){var c;c=typeof a==="string"?g[a]:a;if(!c)throw Error('Missing "'+a+'", gamejs.preload() all audio files before loading');for(var b=[],a=e;a-- >0;){var f=new Audio;f.preload="auto";f.loop=!1;f.src=c.src;b.push(f)}this.play=function(a){f.loop=
!!a;b.some(function(a){if(a.ended||a.paused)return a.play(),!0;return!1})};this.stop=function(){b.forEach(function(a){a.stop()})};this.setVolume=function(a){b.forEach(function(b){b.volume=a})};this.getVolume=function(){return b[0].volume};this.getLength=function(){return b[0].duration};return this}}},["gamejs"]);