made with requirebin
Created
March 12, 2014 11:45
-
-
Save oberhamsi/9505295 to your computer and use it in GitHub Desktop.
requirebin sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gamejs = require('gamejs'); | |
var SCREEN_WIDTH = 400; | |
var SCREEN_HEIGHT = 400; | |
// ball is a colored circle. | |
// ball can circle through color list. | |
// ball constantly pulsates in size. | |
function Ball(center) { | |
this.center = center; | |
this.growPerSec = Ball.GROW_PER_SEC; | |
this.radius = this.growPerSec * 2; | |
this.color = 0; | |
return this; | |
}; | |
Ball.MAX_SIZE = 200; | |
Ball.GROW_PER_SEC = 50; | |
Ball.COLORS = ['#ff0000', '#00ff00', '#0000cc']; | |
Ball.prototype.nextColor = function() { | |
this.color += 1; | |
if (this.color >= Ball.COLORS.length) { | |
this.color = 0; | |
} | |
}; | |
Ball.prototype.draw = function(display) { | |
var rgbColor = Ball.COLORS[this.color]; | |
var lineWidth = 0; // lineWidth zero fills the circle | |
gamejs.draw.circle(display, rgbColor, this.center, this.radius, lineWidth); | |
}; | |
Ball.prototype.update = function(msDuration) { | |
this.radius += this.growPerSec * (msDuration / 1000); | |
if (this.radius > Ball.MAX_SIZE || this.radius < Math.abs(this.growPerSec)) { | |
this.radius = this.radius > Ball.MAX_SIZE ? Ball.MAX_SIZE : Math.abs(this.growPerSec); | |
this.growPerSec = -this.growPerSec; | |
} | |
}; | |
function main() { | |
// setup screen and ball. | |
// ball in screen center. | |
// start game loop. | |
var display = gamejs.display.setMode([SCREEN_WIDTH, SCREEN_HEIGHT]); | |
var ballCenter = [SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2]; | |
var ball = new Ball(ballCenter); | |
// ball changes color on mouse up | |
gamejs.onEvent(function(event) { | |
switch(event.type) { | |
case gamejs.event.MOUSE_UP: | |
ball.nextColor(); | |
break; | |
}; | |
}); | |
// update ball position | |
// clear display | |
// draw | |
gamejs.onTick(function(msDuration) { | |
ball.update(msDuration); | |
display.clear(); | |
ball.draw(display); | |
}); | |
}; | |
// call main after all resources have finished loading | |
gamejs.ready(main); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Ball(t){return this.center=t,this.growPerSec=Ball.GROW_PER_SEC,this.radius=2*this.growPerSec,this.color=0,this}function main(){var t=gamejs.display.setMode([SCREEN_WIDTH,SCREEN_HEIGHT]),e=[SCREEN_WIDTH/2,SCREEN_HEIGHT/2],n=new Ball(e);gamejs.onEvent(function(t){switch(t.type){case gamejs.event.MOUSE_UP:n.nextColor()}}),gamejs.onTick(function(e){n.update(e),t.clear(),n.draw(t)})}require=function e(t,n,r){function i(a,s){if(!n[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(o)return o(a,!0);throw Error("Cannot find module '"+a+"'")}var c=n[a]={exports:{}};t[a][0].call(c.exports,function(e){var n=t[a][1][e];return i(n?n:e)},c,c.exports,e,t,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;r.length>a;a++)i(r[a]);return i}({GUIWXK:[function(t,e,n){function r(){var t=0,e=0,n=0,r=0;if(2===arguments.length)arguments[0]instanceof Array&&arguments[1]instanceof Array?(t=arguments[0][0],e=arguments[0][1],n=arguments[1][0],r=arguments[1][1]):(t=arguments[0],e=arguments[1]);else if(1===arguments.length&&arguments[0]instanceof Array)t=arguments[0][0],e=arguments[0][1],n=arguments[0][2],r=arguments[0][3];else if(1===arguments.length&&arguments[0]instanceof h)t=arguments[0].left,e=arguments[0].top,n=arguments[0].width,r=arguments[0].height;else{if(4!==arguments.length)throw Error("not a valid rectangle specification");t=arguments[0],e=arguments[1],n=arguments[2],r=arguments[3]}return{left:t||0,top:e||0,width:n||0,height:r||0}}var i=t("./gamejs/utils/matrix"),o=t("./gamejs/utils/objects"),a=t("./gamejs/callback").Callback,s=["info","warn","error","fatal"],u=2;n.setLogLevel=function(t){if("string"==typeof t&&s.indexOf(t))u=s.indexOf(t);else{if("number"!=typeof t)throw Error("invalid logLevel ",t," Must be one of: ",s);u=t}return u};var c=n.log=function(){if(f.worker.inWorker===!0)return f.worker._logMessage(arguments),void 0;var t=Array.prototype.slice.apply(arguments,[0]);t.unshift(Date.now()),void 0!==window.console&&console.log.apply&&console.log.apply(console,t)};n.info=function(){s.indexOf("info")>=u&&c.apply(this,arguments)},n.warn=function(){s.indexOf("warn")>=u&&c.apply(this,arguments)},n.error=function(){s.indexOf("error")>=u&&c.apply(this,arguments)},n.fatal=function(){s.indexOf("fatal")>=u&&c.apply(this,arguments)};var h=n.Rect=function(){var t=r.apply(this,arguments);return this.left=t.left,this.top=t.top,this.width=t.width,this.height=t.height,this};o.accessors(h.prototype,{bottom:{get:function(){return this.top+this.height},set:function(t){this.top=t-this.height}},right:{get:function(){return this.left+this.width},set:function(t){this.left=t-this.width}},center:{get:function(){return[0|this.left+this.width/2,0|this.top+this.height/2]},set:function(){var t=r.apply(this,arguments);this.left=0|t.left-this.width/2,this.top=0|t.top-this.height/2}},topleft:{get:function(){return[this.left,this.top]},set:function(){var t=r.apply(this,arguments);this.left=t.left,this.top=t.top}},bottomleft:{get:function(){return[this.left,this.bottom]},set:function(){var t=r.apply(this,arguments);this.left=t.left,this.bottom=t.top}},topright:{get:function(){return[this.right,this.top]},set:function(){var t=r.apply(this,arguments);this.right=t.left,this.top=t.top}},bottomright:{get:function(){return[this.right,this.bottom]},set:function(){var t=r.apply(this,arguments);this.right=t.left,this.bottom=t.top}},x:{get:function(){return this.left},set:function(t){this.left=t}},y:{get:function(){return this.top},set:function(t){this.top=t}}}),h.prototype.move=function(){var t=r.apply(this,arguments);return new h(this.left+t.left,this.top+t.top,this.width,this.height)},h.prototype.moveIp=function(){var t=r.apply(this,arguments);this.left+=t.left,this.top+=t.top},h.prototype.clip=function(t){if(!this.collideRect(t))return new h(0,0,0,0);var e,n,r,i;return this.left>=t.left&&this.left<t.right?e=this.left:t.left>=this.left&&t.left<this.right&&(e=t.left),this.right>t.left&&this.right<=t.right?r=this.right-e:t.right>this.left&&t.right<=this.right&&(r=t.right-e),this.top>=t.top&&this.top<t.bottom?n=this.top:t.top>=this.top&&t.top<this.bottom&&(n=t.top),this.bottom>t.top&&this.bottom<=t.bottom?i=this.bottom-n:t.bottom>this.top&&t.bottom<=this.bottom&&(i=t.bottom-n),new h(e,n,r,i)},h.prototype.union=function(t){var e,n,r,i;return e=Math.min(this.left,t.left),n=Math.min(this.top,t.top),r=Math.max(this.right,t.right)-e,i=Math.max(this.bottom,t.bottom)-n,new h(e,n,r,i)},h.prototype.inflate=function(t,e){var n=this.clone();return n.inflateIp(t,e),n},h.prototype.inflateIp=function(t,e){this.left-=Math.floor(t/2),this.top-=Math.floor(e/2),this.width+=t,this.height+=e},h.prototype.collidePoint=function(){var t=r.apply(this,arguments);return this.left<=t.left&&t.left<=this.right&&this.top<=t.top&&t.top<=this.bottom},h.prototype.collideRect=function(t){return!(this.left>t.right||this.right<t.left||this.top>t.bottom||this.bottom<t.top)},h.prototype.collideLine=function(t,e){function n(t){var e=t[0],n=t[1];return(a-i)*e+(r-o)*n+(o*i-r*a)}var r=t[0],i=t[1],o=e[0],a=e[1],s=[[this.left,this.top],[this.left,this.bottom],[this.right,this.top],[this.right,this.bottom]].map(n),u=!0,c=!0,h=!0;return s.forEach(function(t){t>0?c=!1:0>t?u=!1:0===t&&(h=!1)},this),(u||c)&&h?!1:!(r>this.right&&o>this.right||this.left>r&&this.left>o||this.top>i&&this.top>a||i>this.bottom&&a>this.bottom)},h.prototype.toString=function(){return["[",this.left,",",this.top,"]"," [",this.width,",",this.height,"]"].join("")},h.prototype.clone=function(){return new h(this)};var l=n.Surface=function(){var t=r.apply(this,arguments),e=t.left,o=t.top;return 1==arguments.length&&arguments[0]instanceof h&&(e=t.width,o=t.height),this._matrix=i.identity(),this._canvas=document.createElement("canvas"),this._canvas.width=e,this._canvas.height=o,this._blitAlpha=1,this._context=this._canvas.getContext("2d"),n.display._isSmoothingEnabled()?this._smooth():this._noSmooth(),this};l.prototype._noSmooth=function(){this.context.mozImageSmoothingEnabled=!1,this.context.webkitImageSmoothingEnabled=!1},l.prototype._smooth=function(){this.context.mozImageSmoothingEnabled=!0,this.context.webkitImageSmoothingEnabled=!0},l.prototype.blit=function(t,e,n,r){var o,a;if(e instanceof h){o=e.clone();var s=t.getSize();o.width||(o.width=s[0]),o.height||(o.height=s[1])}else o=e&&e instanceof Array&&2==e.length?new h(e,t.getSize()):new h([0,0],t.getSize());if(r=r||"source-over",n instanceof h)a=n;else if(n&&n instanceof Array&&2==n.length){var u=t.getSize();a=new h(n,[u[0]-n[0],u[1]-n[1]])}else a=new h([0,0],t.getSize());if(isNaN(o.left)||isNaN(o.top)||isNaN(o.width)||isNaN(o.height))throw Error("[blit] bad parameters, destination is "+o);this.context.save(),this.context.globalCompositeOperation=r;var c=i.translate(i.identity(),o.left,o.top);c=i.multiply(c,t._matrix),this.context.transform(c[0],c[1],c[2],c[3],c[4],c[5]),this.context.globalAlpha=t._blitAlpha,this.context.drawImage(t.canvas,a.left,a.top,a.width,a.height,0,0,o.width,o.height),this.context.restore()},l.prototype.getSize=function(){return[this.canvas.width,this.canvas.height]},l.prototype.getRect=function(){return new h([0,0],this.getSize())},l.prototype.fill=function(t,e){this.context.save(),this.context.fillStyle=t||"#000000",void 0===e&&(e=new h(0,0,this.canvas.width,this.canvas.height)),this.context.fillRect(e.left,e.top,e.width,e.height),this.context.restore()},l.prototype.clear=function(t){var e=this.getSize();t=t||new h(0,0,e[0],e[1]),this.context.clearRect(t.left,t.top,t.width,t.height)},o.accessors(l.prototype,{rect:{get:function(){return this.getRect()}},context:{get:function(){return this._context}},canvas:{get:function(){return this._canvas}}}),l.prototype.clone=function(){var t=new l(this.getRect());return t.blit(this),t},l.prototype.getAlpha=function(){return 1-this._blitAlpha},l.prototype.setAlpha=function(t){return isNaN(t)||0>t||t>1?void 0:(this._blitAlpha=1-t,1-this._blitAlpha)},l.prototype.getImageData=function(){var t=this.getSize();return this.context.getImageData(0,0,t[0],t[1])},n.display=t("./gamejs/display"),n.draw=t("./gamejs/draw"),n.event=t("./gamejs/event"),n.font=t("./gamejs/font"),n.http=t("./gamejs/http"),n.image=t("./gamejs/image"),n.mask=t("./gamejs/mask"),n.mixer=t("./gamejs/mixer"),n.sprite=t("./gamejs/sprite"),n.surfacearray=t("./gamejs/surfacearray"),n.time=t("./gamejs/time"),n.transform=t("./gamejs/transform"),n.utils={arrays:t("./gamejs/utils/arrays"),objects:t("./gamejs/utils/objects"),matrix:t("./gamejs/utils/matrix"),vectors:t("./gamejs/utils/vectors"),math:t("./gamejs/utils/math"),uri:t("./gamejs/utils/uri"),prng:t("./gamejs/utils/prng"),base64:t("./gamejs/utils/base64")},n.pathfinding={astar:t("./gamejs/pathfinding/astar")},n.worker=t("./gamejs/worker"),n.xml=t("./gamejs/xml"),n.tmx=t("./gamejs/tmx"),n.noise=t("./gamejs/noise");var f=n,p={};n.ready=f.worker.inWorker===!0?function(e){t("./gamejs/worker")._ready(),f.init(),e()}:function(t){function e(){if(!document.body)return window.setTimeout(e,50);o=f.image.preload(p);try{i=f.mixer.preload(p)}catch(t){f.debug("Error loading audio files ",t)}window.setTimeout(n,50)}function n(){return 1>o()||1>i()?window.setTimeout(n,100):(f.display.init(),f.image.init(),f.mixer.init(),f.event.init(),f.utils.prng.init(),t(),void 0)}function r(){return o?.5*o()+.5*i():.1}var i=null,o=null;return f.time.init(),window.setTimeout(e,13),r},n.init=function(){var t={};return["time","display","image","mixer","event"].forEach(function(e){try{f[e].init()}catch(n){t[e]=""+n}}),t};var m=function(){return window.$g&&window.$g.resourceBaseHref||document.location.href};n.preload=function(e){var n=t("./gamejs/utils/uri"),r=m();e.forEach(function(t){p[t]=n.resolve(r,t)},this)},n.onEvent=function(t,e){n.event._CALLBACK=new a(t,e)},n.onTick=function(t,e){n.time._CALLBACK=new a(t,e)}},{"./gamejs/callback":3,"./gamejs/display":4,"./gamejs/draw":5,"./gamejs/event":6,"./gamejs/font":7,"./gamejs/http":8,"./gamejs/image":9,"./gamejs/mask":10,"./gamejs/mixer":11,"./gamejs/noise":12,"./gamejs/pathfinding/astar":13,"./gamejs/sprite":14,"./gamejs/surfacearray":15,"./gamejs/time":16,"./gamejs/tmx":17,"./gamejs/transform":18,"./gamejs/utils/arrays":19,"./gamejs/utils/base64":20,"./gamejs/utils/math":22,"./gamejs/utils/matrix":23,"./gamejs/utils/objects":24,"./gamejs/utils/prng":25,"./gamejs/utils/uri":26,"./gamejs/utils/vectors":27,"./gamejs/worker":28,"./gamejs/xml":29}],gamejs:[function(t,e){e.exports=t("GUIWXK")},{}],3:[function(t,e,n){var r=n.Callback=function(t,e){return this.fn=t,this.fnScope=e||{},this};r.prototype.trigger=function(){this.fn.apply(this.fnScope,arguments)}},{}],4:[function(t,e,n){var r=t("../gamejs").Surface,i="gjs-canvas",o=null,a=n.DISABLE_SMOOTHING=2,s=n.FULLSCREEN=4,u=n.POINTERLOCK=8,c=0,h=function(){var t=document.getElementById(i);return t||(t=document.createElement("canvas"),t.setAttribute("id",i),document.body.appendChild(t)),t},l=function(){var t=document.getElementById("gjs-fullscreen-toggle");if(!t){t=document.createElement("button"),t.innerHTML="Fullscreen",t.id="gjs-fullscreen-toggle";var e=h();e.parentNode.insertBefore(t,e),e.parentNode.insertBefore(document.createElement("br"),e)}return t},f=function(){var e={type:p()?t("./event").DISPLAY_FULLSCREEN_ENABLED:t("./event").DISPLAY_FULLSCREEN_DISABLED};p()&&c&u&&g(),t("./event")._triggerCallback(e)};n.hasPointerLock=function(){return!!(document.pointerLockElement||document.webkitFullscreenElement||document.mozFullscreenElement||document.mozFullScreenElement)},n.init=function(){var t=h();t.getAttribute("tabindex")||(t.setAttribute("tabindex",1),t.focus());var e=document.getElementById("gjs-loader");e&&(e.style.display="none")};var p=n.isFullscreen=function(){return document.fullScreenElement||document.mozFullScreen||document.webkitIsFullScreen||document.webkitDisplayingFullscreen},m=function(){var t=h();return t.requestFullScreen=t.requestFullScreen||t.mozRequestFullScreen||t.webkitRequestFullScreen,t.requestFullScreen?(Element.ALLOW_KEYBOARD_INPUT?t.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT):t.requestFullScreen(),!0):!1},g=function(){var t=h();t.requestPointerLock=t.requestPointerLock||t.mozRequestPointerLock||t.webkitRequestPointerLock,t.requestPointerLock&&t.requestPointerLock()};n._hasFocus=function(){return document.activeElement==h()},n.setMode=function(t,e){o=null;var n=h();if(n.width=t[0],n.height=t[1],c=c||e,c&u&&(c|=s),c&s){var r=l();r.removeEventListener("click",m,!1),r.addEventListener("click",m,!1),document.removeEventListener("fullScreenchange",f,!1),document.removeEventListener("webkitfullscreenchange",f,!1),document.removeEventListener("mozfullscreenchange",f,!1),document.addEventListener("fullscreenchange",f,!1),document.addEventListener("webkitfullscreenchange",f,!1),document.addEventListener("mozfullscreenchange",f,!1)}return d()},n.setCaption=function(t){document.title=t},n._isSmoothingEnabled=function(){return!(c&a)},n._getCanvasOffset=function(){var t=h().getBoundingClientRect();return[t.left,t.top]};var d=n.getSurface=function(){if(null===o){var t=h();o=new r([t.clientWidth,t.clientHeight]),o._canvas=t,o._context=t.getContext("2d"),c&a?o._noSmooth():o._smooth()}return o}},{"../gamejs":"GUIWXK","./event":6}],5:[function(t,e,n){n.line=function(t,e,n,r,i){var o=t.context;o.save(),o.beginPath(),o.strokeStyle=e,o.lineWidth=i||1,o.moveTo(n[0],n[1]),o.lineTo(r[0],r[1]),o.stroke(),o.restore()},n.lines=function(t,e,n,r,i){n=n||!1;var o=t.context;o.save(),o.beginPath(),o.strokeStyle=o.fillStyle=e,o.lineWidth=i||1,r.forEach(function(t,e){0===e?o.moveTo(t[0],t[1]):o.lineTo(t[0],t[1])}),n&&o.lineTo(r[0][0],r[0][1]),o.stroke(),o.restore()},n.circle=function(t,e,n,r,i){if(!r)throw Error("[circle] radius required argument");if(!(n&&n instanceof Array))throw Error("[circle] pos must be given & array"+n);var o=t.context;o.save(),o.beginPath(),o.strokeStyle=o.fillStyle=e,o.lineWidth=i||1,o.arc(n[0],n[1],r,0,2*Math.PI,!0),void 0===i||0===i?o.fill():o.stroke(),o.restore()},n.rect=function(t,e,n,r){var i=t.context;i.save(),i.beginPath(),i.strokeStyle=i.fillStyle=e,isNaN(r)||0===r?i.fillRect(n.left,n.top,n.width,n.height):(i.lineWidth=r||1,i.strokeRect(n.left,n.top,n.width,n.height)),i.restore()},n.arc=function(t,e,n,r,i,o){var a=t.context;a.save(),a.beginPath(),a.strokeStyle=a.fillStyle=e,a.arc(n.center[0],n.center[1],n.width/2,r*(Math.PI/180),i*(Math.PI/180),!1),isNaN(o)||0===o?a.fill():(a.lineWidth=o||1,a.stroke()),a.restore()},n.polygon=function(t,e,n,r){var i=t.context;i.save(),i.fillStyle=i.strokeStyle=e,i.beginPath(),n.forEach(function(t,e){0==e?i.moveTo(t[0],t[1]):i.lineTo(t[0],t[1])}),i.closePath(),isNaN(r)||0===r?i.fill():(i.lineWidth=r||1,i.stroke()),i.restore()},n.quadraticCurve=function(t,e,n,r,i,o){if(!(n&&n instanceof Array))throw Error("[quadratic_curve] startPos must be defined!");if(!(r&&r instanceof Array))throw Error("[quadratic_curve] endPos must be defined!");if(!(i&&i instanceof Array))throw Error("[quadratic_curve] controlPos must be defined!");var a=t.context;a.save(),a.fillStyle=a.strokeStyle=e,a.lineWidth=o||1,a.beginPath(),a.moveTo(n[0],n[1]),a.quadraticCurveTo(i[0],i[1],r[0],r[1]),a.stroke(),a.restore()},n.bezierCurve=function(t,e,n,r,i,o,a){if(!(n&&n instanceof Array))throw Error("[bezier_curve] startPos must be defined!");if(!(r&&r instanceof Array))throw Error("[bezier_curve] endPos must be defined!");if(!(i&&i instanceof Array))throw Error("[bezier_curve] ct1Pos must be defined!");if(!(o&&o instanceof Array))throw Error("[bezier_curve] ct2Pos must be defined!");var s=t.context;s.save(),s.fillStyle=s.strokeStyle=e,s.lineWidth=a||1,s.beginPath(),s.moveTo(n[0],n[1]),s.bezierCurveTo(i[0],i[1],o[0],o[1],r[0],r[1]),s.stroke(),s.restore()}},{}],6:[function(t,e,n){var r=t("./display"),i=t("./callback").Callback;n._CALLBACK=new i(function(){},{}),n._triggerCallback=function(){n._CALLBACK.trigger.apply(n._CALLBACK,arguments)},n.K_UP=38,n.K_DOWN=40,n.K_RIGHT=39,n.K_LEFT=37,n.K_SPACE=32,n.K_BACKSPACE=8,n.K_TAB=9,n.K_ENTER=13,n.K_SHIFT=16,n.K_CTRL=17,n.K_ALT=18,n.K_ESC=27,n.K_0=48,n.K_1=49,n.K_2=50,n.K_3=51,n.K_4=52,n.K_5=53,n.K_6=54,n.K_7=55,n.K_8=56,n.K_9=57,n.K_a=65,n.K_b=66,n.K_c=67,n.K_d=68,n.K_e=69,n.K_f=70,n.K_g=71,n.K_h=72,n.K_i=73,n.K_j=74,n.K_k=75,n.K_l=76,n.K_m=77,n.K_n=78,n.K_o=79,n.K_p=80,n.K_q=81,n.K_r=82,n.K_s=83,n.K_t=84,n.K_u=85,n.K_v=86,n.K_w=87,n.K_x=88,n.K_y=89,n.K_z=90,n.K_KP1=97,n.K_KP2=98,n.K_KP3=99,n.K_KP4=100,n.K_KP5=101,n.K_KP6=102,n.K_KP7=103,n.K_KP8=104,n.K_KP9=105,n.NOEVENT=0,n.NUMEVENTS=32e3,n.DISPLAY_FULLSCREEN_ENABLED=300,n.DISPLAY_FULLSCREEN_DISABLED=301,n.QUIT=0,n.KEY_DOWN=1,n.KEY_UP=2,n.MOUSE_MOTION=3,n.MOUSE_UP=4,n.MOUSE_DOWN=5,n.MOUSE_WHEEL=6,n.USEREVENT=2e3,n.Event=function(){this.type=null,this.key=null,this.rel=null,this.button=null,this.pos=null},n.init=function(){function t(t){var e=r._getCanvasOffset();n._CALLBACK.trigger({type:n.MOUSE_DOWN,pos:[t.clientX-e[0],t.clientY-e[1]],button:t.button,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey})}function e(t){var e=r._getCanvasOffset();n._CALLBACK.trigger({type:n.MOUSE_UP,pos:[t.clientX-e[0],t.clientY-e[1]],button:t.button,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey})}function i(t){var e=t.keyCode||t.which;n._CALLBACK.trigger({type:n.KEY_DOWN,key:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey}),(r._hasFocus()&&!t.ctrlKey&&!t.metaKey&&(e>=n.K_LEFT&&n.K_DOWN>=e||e>=n.K_0&&n.K_z>=e||e>=n.K_KP1&&n.K_KP9>=e||e===n.K_SPACE||e===n.K_TAB||e===n.K_ENTER)||e===n.K_ALT||e===n.K_BACKSPACE)&&t.preventDefault()}function o(t){n._CALLBACK.trigger({type:n.KEY_UP,key:t.keyCode,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey})}function a(t){var e=r._getCanvasOffset(),i=[t.clientX-e[0],t.clientY-e[1]],o=[];c.length&&(o=[c[0]-i[0],c[1]-i[1]]),n._CALLBACK.trigger({type:n.MOUSE_MOTION,pos:i,rel:o,buttons:null,timestamp:t.timeStamp,movement:[t.movementX||t.mozMovementX||t.webkitMovementX||0,t.movementY||t.mozMovementY||t.webkitMovementY||0]}),c=i}function s(t){var e=r._getCanvasOffset(),i=[t.clientX-e[0],t.clientY-e[1]];n._CALLBACK.trigger({type:n.MOUSE_WHEEL,pos:i,delta:t.detail||-t.wheelDeltaY/40})}function u(){n._CALLBACK.trigger({type:n.QUIT})}var c=[],h=r.getSurface()._canvas;document.addEventListener("mousedown",t,!1),document.addEventListener("mouseup",e,!1),document.addEventListener("keydown",i,!1),document.addEventListener("keyup",o,!1),document.addEventListener("mousemove",a,!1),h.addEventListener("mousewheel",s,!1),h.addEventListener("DOMMouseScroll",s,!1),h.addEventListener("beforeunload",u,!1)}},{"./callback":3,"./display":4}],7:[function(t,e,n){var r=t("../gamejs").Surface,i=t("./utils/objects"),o=n.Font=function(t,e){return this.sampleSurface=new r([10,10]),this.sampleSurface.context.font=t,this.sampleSurface.context.textAlign="start",this.sampleSurface.context.textBaseline="bottom",this.backgroundColor=e||!1,this};o.prototype.render=function(t,e){var n=this.size(t),i=new r(n),o=i.context;return o.save(),this.backgroundColor&&(o.fillStyle=this.backgroundColor,o.fillRect(0,0,i.rect.width,i.rect.height)),o.font=this.sampleSurface.context.font,o.textBaseline=this.sampleSurface.context.textBaseline,o.textAlign=this.sampleSurface.context.textAlign,o.fillStyle=o.strokeStyle=e||"#000000",o.fillText(t,0,i.rect.height,i.rect.width),o.restore(),i},o.prototype.size=function(t){var e=this.sampleSurface.context.measureText(t);return[e.width,this.fontHeight]},i.accessors(o.prototype,{fontHeight:{get:function(){return 1.5*this.sampleSurface.context.measureText("M").width}}})},{"../gamejs":"GUIWXK","./utils/objects":24}],8:[function(require,module,exports){function stringify(response){return eval("("+response.responseText+")")}function ajaxBaseHref(){return window.$g&&window.$g.ajaxBaseHref||"./"}exports.Response=function(){throw this.getResponseHeader=function(){},Error("response class not instantiable")};var ajax=exports.ajax=function(t,e,n,r){n=n||null;var i=new XMLHttpRequest;return i.open(t,e,!1),r&&i.setRequestHeader("Accept",r),n instanceof Object&&(n=JSON.stringify(n),i.setRequestHeader("Content-Type","application/json")),i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.send(n),i},get=exports.get=function(t){return ajax("GET",t)},post=exports.post=function(t,e,n){return ajax("POST",t,e,n)};exports.load=function(t){return stringify(get(ajaxBaseHref()+t))},exports.save=function(t,e,n){return stringify(post(ajaxBaseHref()+t,{payload:e},n))}},{}],9:[function(t,e,n){var r=t("../gamejs"),i={},o=!1;n.load=function(t){var e;if("string"==typeof t){if(e=i[t],!e)throw Error('Missing "'+t+'", gamejs.preload() all images before trying to load them.')}else e=t;var n=document.createElement("canvas");n.width=e.naturalWidth||e.width,n.height=e.naturalHeight||e.height;var o=n.getContext("2d");o.drawImage(e,0,0),e.getSize=function(){return[e.naturalWidth,e.naturalHeight]};var a=new r.Surface(e.getSize());return a._canvas=n,a._context=o,a},n.init=function(){},n.preload=function(t){function e(){c++,c==h&&(o=!1),0===c%10&&r.log("gamejs.image: preloaded "+c+" of "+h)}function n(){return h>0?c/h:1}function i(){a(this),e()}function s(){throw e(),Error("Error loading "+this.src)}var u,c=0,h=0;for(u in t){var l=u.toLowerCase();if(-1!=l.indexOf(".png")||-1!=l.indexOf(".jpg")||-1!=l.indexOf(".jpeg")||-1!=l.indexOf(".svg")||-1!=l.indexOf(".gif")){var f=new Image;f.addEventListener("load",i,!0),f.addEventListener("error",s,!0),f.src=t[u],f.gamejsKey=u,h++}}return h>0&&(o=!0),n};var a=function(t){i[t.gamejsKey]=t}},{"../gamejs":"GUIWXK"}],10:[function(t,e,n){var r=t("../gamejs"),i=t("./utils/objects");n.fromSurface=function(t,e){e=e&&255-e||255;var n,r=t.getImageData().data,i=t.getSize(),a=new o(i);for(n=0;r.length>n;n+=4){var s=parseInt(n/4/i[0],10),u=parseInt(n/4%i[0],10),c=r[n+3];c>=e&&a.setAt(u,s)}return a};var o=n.Mask=function(t){this.width=t[0],this.height=t[1],this._bits=[];var e,n;for(e=0;this.width>e;e++)for(this._bits[e]=[],n=0;this.height>n;n++)this._bits[e][n]=!1};o.prototype.overlapRect=function(t,e){var n=this.rect,i=t.rect;if(e&&i.moveIp(e),!i.collideRect(n))return null;var o=Math.max(n.left,i.left),a=Math.min(n.right,i.right),s=Math.max(n.top,i.top),u=Math.min(n.bottom,i.bottom);return new r.Rect([o,s],[a-o,u-s])},o.prototype.overlap=function(t,e){var n=this.overlapRect(t,e);if(null===n)return!1;var r=this.rect,i=t.rect;e&&i.moveIp(e);var o,a;for(a=n.top;n.bottom>=a;a++)for(o=n.left;n.right>=o;o++)if(this.getAt(o-r.left,a-r.top)&&t.getAt(o-i.left,a-i.top))return!0;return!1},o.prototype.overlapArea=function(t,e){var n=this.overlapRect(t,e);if(null===n)return 0;var r=this.rect,i=t.rect;e&&i.moveIp(e);var o,a,s=0;for(a=n.top;n.bottom>=a;a++)for(o=n.left;n.right>=o;o++)this.getAt(o-r.left,a-r.top)&&t.getAt(o-i.left,a-i.top)&&s++;return s},o.prototype.overlapMask=function(t,e){var n=this.overlapRect(t,e);if(null===n)return 0;var r=this.rect,i=t.rect;e&&i.moveIp(e);var a,s,u=new o([n.width,n.height]);for(s=n.top;n.bottom>=s;s++)for(a=n.left;n.right>=a;a++)this.getAt(a-r.left,s-r.top)&&t.getAt(a-i.left,s-i.top)&&u.setAt(a,s);return u},o.prototype.setAt=function(t,e){this._bits[t][e]=!0},o.prototype.getAt=function(t,e){return t=parseInt(t,10),e=parseInt(e,10),0>t||0>e||t>=this.width||e>=this.height?!1:this._bits[t][e]},o.prototype.invert=function(){this._bits=this._bits.map(function(t){return t.map(function(t){return!t})})},o.prototype.getSize=function(){return[this.width,this.height]},i.accessors(o.prototype,{rect:{get:function(){return new r.Rect([0,0],[this.width,this.height])}},length:{get:function(){var t=0;return this._bits.forEach(function(e){e.forEach(function(e){e&&t++})}),t}}})},{"../gamejs":"GUIWXK","./utils/objects":24}],11:[function(t,e,n){function r(t){t instanceof Array||(t=[t]),document.location.href,t.forEach(function(t){i[t.gamejsKey]=t})}t("../gamejs");var i={},o=!1,a=8;n.setNumChannels=function(t){a=parseInt(t,10)||a},n.getNumChannels=function(){return a},n.init=function(){var t=Array.prototype.slice.call(document.getElementsByTagName("audio"),0);r(t)},n.preload=function(t){function e(){u++,u==s&&(o=!1)}function n(){return s>0?u/s:1}function i(){r(this),e()}function a(){throw e(),Error("Error loading "+this.src)}var s=0,u=0;for(var c in t)if(-1!=c.indexOf("wav")||-1!=c.indexOf("ogg")||-1!=c.indexOf("webm")){s++;var h=new Audio;h.addEventListener("canplay",i,!0),h.addEventListener("error",a,!0),h.src=t[c],h.gamejsKey=c,h.load()}return s>0&&(o=!0),n},n.isPreloading=function(){return o},n.Sound=function(t){var e;if(e="string"==typeof t?i[t]:t,!e)throw Error('Missing "'+t+'", gamejs.preload() all audio files before loading');for(var n=[],r=a;r-->0;){var o=new Audio;o.preload="auto",o.loop=!1,o.src=e.src,n.push(o)}return this.play=function(t){n.some(function(e){return e.ended||e.paused?(e.loop=!!t,e.play(),!0):!1})},this.stop=function(){n.forEach(function(t){t.stop()})},this.setVolume=function(t){n.forEach(function(e){e.volume=t})},this.getVolume=function(){return n[0].volume},this.getLength=function(){return n[0].duration},this}},{"../gamejs":"GUIWXK"}],12:[function(t,e,n){var r=n.Simplex=function(t){void 0==t&&(t=Math),this.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],this.p=[];var e;for(e=0;256>e;e++)this.p[e]=Math.floor(256*t.random());for(this.perm=[],e=0;512>e;e++)this.perm[e]=this.p[255&e];this.simplex=[[0,1,2,3],[0,1,3,2],[0,0,0,0],[0,2,3,1],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,2,3,0],[0,2,1,3],[0,0,0,0],[0,3,1,2],[0,3,2,1],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,3,2,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,2,0,3],[0,0,0,0],[1,3,0,2],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,3,0,1],[2,3,1,0],[1,0,2,3],[1,0,3,2],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,0,3,1],[0,0,0,0],[2,1,3,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,0,1,3],[0,0,0,0],[0,0,0,0],[0,0,0,0],[3,0,1,2],[3,0,2,1],[0,0,0,0],[3,1,2,0],[2,1,0,3],[0,0,0,0],[0,0,0,0],[0,0,0,0],[3,1,0,2],[0,0,0,0],[3,2,0,1],[3,2,1,0]]};r.prototype.dot=function(t,e,n){return t[0]*e+t[1]*n},r.prototype.get=function(t,e){var n,r,i,o,a,s=.5*(Math.sqrt(3)-1),u=(t+e)*s,c=Math.floor(t+u),h=Math.floor(e+u),l=(3-Math.sqrt(3))/6,f=(c+h)*l,p=c-f,m=h-f,g=t-p,d=e-m;g>d?(o=1,a=0):(o=0,a=1);var v=g-o+l,y=d-a+l,w=g-1+2*l,_=d-1+2*l,b=255&c,E=255&h,x=this.perm[b+this.perm[E]]%12,S=this.perm[b+o+this.perm[E+a]]%12,K=this.perm[b+1+this.perm[E+1]]%12,j=.5-g*g-d*d;0>j?n=0:(j*=j,n=j*j*this.dot(this.grad3[x],g,d));var A=.5-v*v-y*y;0>A?r=0:(A*=A,r=A*A*this.dot(this.grad3[S],v,y));var L=.5-w*w-_*_;return 0>L?i=0:(L*=L,i=L*L*this.dot(this.grad3[K],w,_)),70*(n+r+i)},r.prototype.get3d=function(t,e,n){var r,i,o,a,s,u,c,h,l,f,p=1/3,m=(t+e+n)*p,g=Math.floor(t+m),d=Math.floor(e+m),v=Math.floor(n+m),y=1/6,w=(g+d+v)*y,_=g-w,b=d-w,E=v-w,x=t-_,S=e-b,K=n-E;x>=S?S>=K?(s=1,u=0,c=0,h=1,l=1,f=0):x>=K?(s=1,u=0,c=0,h=1,l=0,f=1):(s=0,u=0,c=1,h=1,l=0,f=1):K>S?(s=0,u=0,c=1,h=0,l=1,f=1):K>x?(s=0,u=1,c=0,h=0,l=1,f=1):(s=0,u=1,c=0,h=1,l=1,f=0);var j=x-s+y,A=S-u+y,L=K-c+y,k=x-h+2*y,C=S-l+2*y,M=K-f+2*y,I=x-1+3*y,R=S-1+3*y,O=K-1+3*y,P=255&g,T=255&d,D=255&v,N=this.perm[P+this.perm[T+this.perm[D]]]%12,B=this.perm[P+s+this.perm[T+u+this.perm[D+c]]]%12,q=this.perm[P+h+this.perm[T+l+this.perm[D+f]]]%12,U=this.perm[P+1+this.perm[T+1+this.perm[D+1]]]%12,W=.6-x*x-S*S-K*K;0>W?r=0:(W*=W,r=W*W*this.dot(this.grad3[N],x,S,K));var z=.6-j*j-A*A-L*L;0>z?i=0:(z*=z,i=z*z*this.dot(this.grad3[B],j,A,L));var F=.6-k*k-C*C-M*M;0>F?o=0:(F*=F,o=F*F*this.dot(this.grad3[q],k,C,M));var H=.6-I*I-R*R-O*O;return 0>H?a=0:(H*=H,a=H*H*this.dot(this.grad3[U],I,R,O)),32*(r+i+o+a)}},{}],13:[function(t,e,n){function r(t){var e={};return this.store=function(n,r){e[t(n)]=r},this.find=function(n){return e[t(n)]},this}var i=t("../utils/binaryheap").BinaryHeap;n.findRoute=function(t,e,n,s){function u(e){return void 0===e.score&&(e.score=t.estimatedDistance(e.point,n)+e.length),e.score}function c(t){l.push(t),p.store(t.point,t)}function h(e){var n=p.find(e),r=g.length+t.actualDistance(g.point,e);(!n||n.length>r)&&(n&&l.remove(n),c({point:e,from:g,length:r}))}var l=new i(u),f="function"==typeof t.hash?t.hash:a,p=new r(f),m=Date.now(),g=null;c({point:e,from:null,length:0});for(var d="function"==typeof t.equals?t.equals:o;l.size()>0&&(!s||s>Date.now()-m);){if(g=l.pop(),d(n,g.point))return g;t.adjacent(g.point).forEach(h)}return null};var o=function(t,e){return t[0]===e[0]&&t[1]===e[1]},a=function(t){return t[0]+"-"+t[1]},s=n.Map=function(){throw Error("not instantiable, this is an interface")};s.prototype.adjacent=function(){},s.prototype.equals=o,s.prototype.hash=a,s.prototype.estimatedDistance=function(){return 1},s.prototype.actualDistance=function(){return 1}},{"../utils/binaryheap":21}],14:[function(t,e,n){t("../gamejs");var r=t("./utils/arrays"),i=t("./utils/objects"),o=t("./utils/vectors"),a=n.Sprite=function(){return this._groups=[],this._alive=!0,this.image=null,this.rect=null,i.accessor(this,"groups",function(){return this._groups}),this};a.prototype.kill=function(){this._alive=!1,this._groups.forEach(function(t){t.remove(this)},this)},a.prototype.remove=function(t){t instanceof Array||(t=[t]),t.forEach(function(t){t.remove(this)},this)},a.prototype.add=function(t){t instanceof Array||(t=[t]),t.forEach(function(t){t.add(this)},this)},a.prototype.groups=function(){return this._groups.slice(0)},a.prototype.draw=function(t){t.blit(this.image,this.rect)},a.prototype.update=function(){},a.prototype.isDead=function(){return!this._alive};var s=n.Group=function(){return this._sprites=[],(arguments[0]instanceof a||arguments[0]instanceof Array&&arguments[0].length&&arguments[0][0]instanceof a)&&this.add(arguments[0]),this};s.prototype.update=function(){var t=arguments;this._sprites.forEach(function(e){e.update.apply(e,t)},this)},s.prototype.add=function(t){t instanceof Array||(t=[t]),t.forEach(function(t){this._sprites.push(t),t._groups.push(this)},this)},s.prototype.remove=function(t){t instanceof Array||(t=[t]),t.forEach(function(t){r.remove(t,this._sprites),r.remove(this,t._groups)},this)},s.prototype.has=function(t){return t instanceof Array||(t=[t]),t.every(function(t){return-1!==this._sprites.indexOf(t)},this)},s.prototype.sprites=function(){return this._sprites},s.prototype.draw=function(){var t=arguments;this._sprites.forEach(function(e){e.draw.apply(e,t)},this)},s.prototype.clear=function(t,e){this._sprites.forEach(function(n){t.blit(e,n.rect)},this)},s.prototype.empty=function(){this._sprites=[]},s.prototype.splice=function(t,e){this._sprites.splice(t,e)},s.prototype.shift=function(){this._sprites.shift()},s.prototype.length=function(){return this._sprites.length},s.prototype.collidePoint=function(){var t=Array.prototype.slice.apply(arguments);return this._sprites.filter(function(e){return e.rect.collidePoint.apply(e.rect,t)},this)},s.prototype.forEach=function(t,e){return this._sprites.forEach(t,e)},s.prototype.some=function(t,e){return this._sprites.some(t,e)},n.spriteCollide=function(t,e,n,r){r=r||u,n=n||!1;var i=[];return e.sprites().forEach(function(e){r(t,e)&&(n&&e.kill(),i.push(e))}),i},n.groupCollide=function(t,e,n,r,i){n=n||!1,r=r||!1;var o=[],a=i||u;return t.sprites().forEach(function(t){e.sprites().forEach(function(e){a(t,e)&&(n&&t.kill(),r&&e.kill(),o.push({a:t,b:e}))})}),o};var u=n.collideRect=function(t,e){return t.rect.collideRect(e.rect)};n.collideMask=function(t,e){if(!t.mask||!e.mask)throw Error("Both sprites must have 'mask' attribute set to an gamejs.mask.Mask");var n=[e.rect.left-t.rect.left,e.rect.top-t.rect.top];return t.mask.overlap(e.mask,n)},n.collideCircle=function(t,e){var n=t.radius||Math.max(t.rect.width,t.rect.height),r=e.radius||Math.max(e.rect.width,e.rect.height);return n+r>=o.distance(t.rect.center,e.rect.center)}},{"../gamejs":"GUIWXK","./utils/arrays":19,"./utils/objects":24,"./utils/vectors":27}],15:[function(t,e,n){var r=t("../gamejs"),i=t("./utils/objects").accessors;n.blitArray=function(t,e){t.context.putImageData(e.imageData,0,0)},n.SurfaceArray=function(t){var e=null,n=null,o=null;return this.set=function(t,r,i){var o=4*t+4*r*e[0]; | |
n[o]=i[0],n[o+1]=i[1],n[o+2]=i[2],n[o+3]=void 0===i[3]?255:i[3]},this.get=function(t,r){var i=4*t+4*r*e[0];return[n[i],n[i+1],n[i+2],n[i+3]]},this.surface=null,i(this,{surface:{get:function(){var t=new r.Surface(e);return t.context.putImageData(o,0,0),t}},imageData:{get:function(){return o}}}),this.getSize=function(){return e},t instanceof Array?(e=t,o=r.display.getSurface().context.createImageData(e[0],e[1]),n=o.data):(e=t.getSize(),o=t.getImageData(0,0,e[0],e[1]),n=o.data),this}},{"../gamejs":"GUIWXK","./utils/objects":24}],16:[function(t,e,n){var r=t("./callback").Callback,i=null,o=null;n._CALLBACK=new r(function(){},{});var a="undefined"!=typeof window?window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||null:null,s=function(){u(),a(s)};n.init=function(){o=Date.now(),a?a(s):setInterval(u,10)};var u=function(){var t=Date.now();n._CALLBACK.trigger(t-(i||t)),i=t}},{"./callback":3}],17:[function(t,e,n){var r=t("../gamejs");t("./utils/objects");var i=t("./xml"),o=t("./utils/base64"),a=t("./utils/uri");n.Map=function(t){t=a.resolve(document.location.href,t);var e=i.Document.fromURL(t),n=e.element("map");this.tileWidth=n.attribute("tilewidth"),this.tileHeight=n.attribute("tileheight"),this.width=n.attribute("width"),this.height=n.attribute("height");var r=n.attribute("orientation");if("orthogonal"!==r)throw Error("only orthogonol maps supported");return this.properties={},l(this.properties,n),this.tiles=new s(n,t),this.layers=h(n),this},n.Tile=function(){throw Error("Can not be instantiated.")};var s=n.TileSets=function(t,e){var n=[];this.getSurface=function(t){var e=this.getTile(t);return e&&e.surface||null},this.getProperties=function(t){var e=this.getTile(t);return e&&e.properties||{}},this.getTile=function(t){var e=null;return n.some(function(n){return t>=n.firstGid?(e=n.tiles[t-n.firstGid],!0):!1},this),e};var o=function(t){for(var n=[],i=t.attribute("tilewidth"),o=t.attribute("tileheight"),s=t.attribute("spacing")||0,u=t.element("image"),c=u.attribute("source"),h=a.makeRelative(a.resolve(e,c)),f=r.image.load(h),p=t.elements("tile"),m=f.getSize(),g=new r.Rect([0,0],[i,o]),d=0,v=0;m[1]>=v+o;){for(x=0;m[0]>=x+i;){var y=new r.Surface(i,o),w=new r.Rect([x,v],[i,o]);y.blit(f,g,w);var _={};p.some(function(t){return t.attribute("id")===d?(l(_,t),!0):void 0},this),n.push({surface:y,properties:_}),x+=i+s,d++}v+=o+s}return n};return t.elements("tileset").forEach(function(t){var r=t.attribute("firstgid"),s=t.attribute("source");if(s){var u=i.Document.fromURL(a.resolve(e,s));t=u.element("tileset")}n.push({tiles:o(t),firstGid:r})}),n.reverse(),this},u=2147483648,c=1073741824,h=function(t){var e=[],n=function(t){var e=t.element("data"),n=e.attribute("encoding"),i=e.attribute("compression"),a="";e.children().forEach(function(t){a+=t.value()});var s=[];if("base64"===n){if(i)throw Error("Compression of map data unsupported");s=o.decodeAsArray(a,4)}else{if("csv"!==n)throw Error("individual tile format not supported");a.trim().split("\n").forEach(function(t){t.split(",",r).forEach(function(t){s.push(parseInt(t,10))})})}return s},r=t.attribute("width"),i=t.attribute("height");return t.elements("layer").forEach(function(t){for(var o=[],a=i;a-->0;){var s=r;for(o[a]=[];s-->0;)o[a][s]=0}n(t).forEach(function(t,e){t&=~(u|c),o[parseInt(e/r,10)][parseInt(e%r,10)]=t}),e.push({gids:o,opacity:t.attribute("opacity"),visible:t.attribute("visible"),properties:l({},t)})}),e},l=function(t,e){var n=e.element("properties");if(n)return n.elements("property").forEach(function(e){var n=e.attribute("name"),r=e.attribute("value");t[n]=r}),t}},{"../gamejs":"GUIWXK","./utils/base64":20,"./utils/objects":24,"./utils/uri":26,"./xml":29}],18:[function(t,e,n){var r=t("../gamejs").Surface,i=t("./utils/matrix");t("./utils/math");var o=t("./utils/vectors");n.rotate=function(t,e){var n=t.getSize(),a=e*Math.PI/180,s=n;if(0!==e%360){var u=t.getRect(),c=[[-u.width/2,u.height/2],[u.width/2,u.height/2],[-u.width/2,-u.height/2],[u.width/2,-u.height/2]],h=c.map(function(t){return o.rotate(t,a)}),l=h.map(function(t){return t[0]}),f=h.map(function(t){return t[1]}),p=Math.min.apply(Math,l),m=Math.max.apply(Math,l),g=Math.min.apply(Math,f),d=Math.max.apply(Math,f);s=[m-p,d-g]}var v=new r(s),y=t._matrix;t._matrix=i.translate(t._matrix,n[0]/2,n[1]/2),t._matrix=i.rotate(t._matrix,a),t._matrix=i.translate(t._matrix,-n[0]/2,-n[1]/2);var w=[(s[0]-n[0])/2,(s[1]-n[1])/2];return v.blit(t,w),t._matrix=y,v},n.scale=function(t,e){var n=e[0],o=e[1];if(0>=n||0>=o)throw Error("[gamejs.transform.scale] Invalid arguments for height and width",[n,o]);var a=t.getSize(),s=n/a[0],u=o/a[1],c=new r([n,o]),h=t._matrix.slice(0);return t._matrix=i.scale(t._matrix,[s,u]),c.blit(t),t._matrix=h,c},n.flip=function(t,e,n){var i=t.getSize(),o=new r(i),a=1,s=1,u=0,c=0;return e===!0&&(a=-1,u=-i[0]),n===!0&&(s=-1,c=-i[1]),o.context.save(),o.context.scale(a,s),o.context.drawImage(t.canvas,u,c),o.context.restore(),o}},{"../gamejs":"GUIWXK","./utils/math":22,"./utils/matrix":23,"./utils/vectors":27}],19:[function(t,e,n){n.remove=function(t,e){var n=e.indexOf(t);return-1!==n?e.splice(e.indexOf(t),1):null},n.shuffle=function(t){var e=t.length-1;for(i=e;i>0;i--){var n=parseInt(Math.random()*(i+1),10),r=t[i];t[i]=t[n],t[n]=r}return t}},{}],20:[function(t,e,n){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",i=n.decode=function(t){var e,n,i,o,a,s,u,c=[],h=0;for(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,"");t.length>h;)o=r.indexOf(t.charAt(h++)),a=r.indexOf(t.charAt(h++)),s=r.indexOf(t.charAt(h++)),u=r.indexOf(t.charAt(h++)),e=o<<2|a>>4,n=(15&a)<<4|s>>2,i=(3&s)<<6|u,c.push(String.fromCharCode(e)),64!=s&&c.push(String.fromCharCode(n)),64!=u&&c.push(String.fromCharCode(i));return c=c.join("")};n.decodeAsArray=function(t,e){e=e||1;var n,r,o=i(t),a=o.length/e,s=[];for(n=0;a>n;n++)for(s[n]=0,r=e-1;r>=0;--r)s[n]+=o.charCodeAt(n*e+r)<<(r<<3);return s}},{}],21:[function(t,e,n){var r=n.BinaryHeap=function(t){return this.content=[],this.scoreFunction=t,this};r.prototype.push=function(t){this.content.push(t),this.sinkDown(this.content.length-1)},r.prototype.pop=function(){var t=this.content[0],e=this.content.pop();return this.content.length>0&&(this.content[0]=e,this.bubbleUp(0)),t},r.prototype.remove=function(t){{this.content.some(function(e,n){if(e==t){var r=this.content.pop();return n!=this.content.length&&(this.content[n]=r,this.scoreFunction(r)<this.scoreFunction(t)?this.sinkDown(n):this.bubbleUp(n)),!0}return!1},this)}},r.prototype.size=function(){return this.content.length},r.prototype.sinkDown=function(t){for(var e=this.content[t];t>0;){var n=Math.floor((t+1)/2)-1,r=this.content[n];if(!(this.scoreFunction(e)<this.scoreFunction(r)))break;this.content[n]=e,this.content[t]=r,t=n}},r.prototype.bubbleUp=function(t){for(var e=this.content.length,n=this.content[t],r=this.scoreFunction(n);;){var i=2*(t+1),o=i-1,a=null;if(e>o){var s=this.content[o],u=this.scoreFunction(s);r>u&&(a=o)}if(e>i){var c=this.content[i],h=this.scoreFunction(c);(null===a?r:u)>h&&(a=i)}if(null===a)break;this.content[t]=this.content[a],this.content[a]=n,t=a}}},{}],22:[function(t,e,n){n.normaliseDegrees=function(t){return t%=360,0>t&&(t+=360),t},n.normaliseRadians=function(t){return t%=2*Math.PI,0>t&&(t+=2*Math.PI),t},n.degrees=function(t){return t*(180/Math.PI)},n.radians=function(t){return t*(Math.PI/180)},n.centroid=function(){var t=Array.prototype.slice.apply(arguments,[0]),e=[0,0];t.forEach(function(t){e[0]+=parseInt(t[0],10),e[1]+=parseInt(t[1],10)});var n=t.length;return[e[0]/n,e[1]/n]}},{}],23:[function(t,e,n){n.identity=function(){return[1,0,0,1,0,0]},n.add=function(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2],t[3]+e[3],t[4]+e[4],t[5]+e[5],t[6]+e[6]]};var r=n.multiply=function(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]};n.translate=function(t,e,n){return r(t,[1,0,0,1,e,n])},n.rotate=function(t,e){var n=Math.sin(e),i=Math.cos(e);return r(t,[i,n,-n,i,0,0])},n.rotation=function(t){return Math.atan2(t[1],t[0])},n.scale=function(t,e){var n=e[0],i=e[1];return r(t,[n,0,0,i,0,0])}},{}],24:[function(t,e,n){n.extend=function(t,e){if(void 0===t)throw Error("unknown subClass");if(void 0===e)throw Error("unknown superClass");var n=Function();n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t,t.superClass=e.prototype,t.superConstructor=e},n.merge=function(){var t,e,n={};for(t=arguments.length;t>0;--t){var r=arguments[t-1];for(e in r)n[e]=r[e]}return n};var r=n.keys=function(t){if(Object.keys)return Object.keys(t);var e,n=[];for(e in t)Object.prototype.hasOwnProperty.call(t,e)&&n.push(e);return n},i=n.accessor=function(t,e,n,r){void 0!==Object.defineProperty?Object.defineProperty(t,e,{get:n,set:r}):void 0!==Object.prototype.__defineGetter__&&(t.__defineGetter__(e,n),r&&t.__defineSetter__(e,r))};n.accessors=function(t,e){r(e).forEach(function(n){i(t,n,e[n].get,e[n].set)})}},{}],25:[function(t,e,n){var r=function r(){var t=4022871197;return this.hash=function(e){e=""+e;var n;for(n=0;e.length>n;n++){t+=e.charCodeAt(n);var r=.02519603282416938*t;t=r>>>0,r-=t,r*=t,t=r>>>0,r-=t,t+=4294967296*r}return 2.3283064365386963e-10*(t>>>0)},this.version="Mash 0.9",this},i=n.Alea=function i(){var t=Array.prototype.slice.call(arguments),e=0,n=0,i=0,o=1;0!=t.length&&t[0]||(t=[Date.now()]);var a=new r;e=a.hash(" "),n=a.hash(" "),i=a.hash(" ");var s;for(s=0;t.length>s;s++)e-=a.hash(t[s]),0>e&&(e+=1),n-=a.hash(t[s]),0>n&&(n+=1),i-=a.hash(t[s]),0>i&&(i+=1);return a=null,this.random=function(){var t=2091639*e+2.3283064365386963e-10*o;return e=n,n=i,i=t-(o=0|t)},this},o=null,a=n.integer=function(t,e){return t+parseInt(o.random()*(e-t+1),10)};n.vector=function(t,e){return[a(t[0],e[0]),a(t[1],e[1])]},n.choose=function(t){return t[a(0,t.length-1)]},n.random=function(){return o.random()},n.init=function(t){o=new i(t)}},{}],26:[function(t,e,n){var r=RegExp("^(?:([^:/?#.]+):)?(?://(?:([^/?#]*)@)?([\\w\\d\\-\\u0100-\\uffff.%]*)(?::([0-9]+))?)?([^?#]+)?(?:\\?([^#]*))?(?:#(.*))?$"),i=n.resolve=function(t,e){var n=o(t),r=o(e),i=n[1]+"://"+n[3];if(r[1])return e;n[4]&&(i=i+":"+n[4]);var s=n[5];if("/"!==e.charAt(0)){var u=s.lastIndexOf("/");s=s.substr(0,u+1)+e}else s=e;return i+a(s)},o=n.match=function(t){return t.match(r)};n.makeRelative=function(t){var e=i(document.location.href,"./");return 0==t.indexOf(e)&&(t="./"+t.substring(e.length)),t};var a=function(t){if(".."==t||"."==t)return"";var e,n=t.indexOf("/")>-1,r=t.split("/"),i=[];for(e=0;r.length>e;){var o=r[e++];"."==o?n&&e==r.length&&i.push(""):".."==o?((i.length>1||1==i.length&&""!=i[0])&&i.pop(),n&&e==r.length&&i.push("")):(i.push(o),n=!0)}return i.join("/")}},{}],27:[function(t,e,n){var r=t("./math");n.distance=function(t,e){return a(i(t,e))};var i=n.subtract=function(t,e){return[t[0]-e[0],t[1]-e[1]]};n.add=function(t,e){return[t[0]+e[0],t[1]+e[1]]};var o=n.multiply=function(t,e){return"number"==typeof e?[t[0]*e,t[1]*e]:[t[0]*e[0],t[1]*e[1]]};n.divide=function(t,e){if("number"==typeof e)return[t[0]/e,t[1]/e];throw Error("only divide by scalar supported")};var a=n.len=function(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])},s=n.unit=function(t){var e=a(t);return e?[t[0]/e,t[1]/e]:[0,0]};n.rotate=function(t,e){return e=r.normaliseRadians(e),[t[0]*Math.cos(e)-t[1]*Math.sin(e),t[0]*Math.sin(e)+t[1]*Math.cos(e)]};var u=n.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]};n.angle=function(t,e){var n=t[0]*e[1]-t[1]*e[0];return Math.atan2(n,u(t,e))},n.truncate=function(t,e){return a(t)>e?o(s(t),e):t}},{"./math":22}],28:[function(t,e,n){function r(t){var e=function(){return(0|65536*(1+Math.random())).toString(16).substring(1)};return t+"@"+(e()+e())}var i=t("../gamejs"),o=t("./utils/uri"),a=t("./callback").Callback,s=n._EVENTS={RESULT:1001,ALIVE:1002,LOG:1004},u=n.inWorker=void 0!==this.importScripts;n._ready=function(){self.onmessage=function(t){i.event._triggerCallback(t.data)},self.postMessage({type:s.ALIVE})},n.post=function(t){if(!u)throw Error("gamejs.postMessage only available in a gamejs/worker module");self.postMessage({type:s.RESULT,data:t})},n._logMessage=function(){self.postMessage({type:s.LOG,arguments:Array.prototype.slice.apply(arguments)})};var c=function c(){__scripts.forEach(function(t){try{importScripts(t)}catch(e){}})},h=function(t){var e=o.resolve(document.location.href,window.require.getModuleRoot()),n=[];Array.prototype.slice.apply(document.getElementsByTagName("script"),[0]).forEach(function(t){t.src&&n.push(t.src)});var r=window.URL||window.webkitURL,i=""+c;i=i.substring(i.indexOf("{")+1,i.lastIndexOf("}"));var a=new Blob(['var __scripts = ["'+n.join('","')+'"];',i,';self.require.setModuleRoot("'+e+'");','self.require.run("'+t+'");'],{type:"application/javascript"}),s=r.createObjectURL(a);return new Worker(s)};n.Worker=function(t){var e=this.id=r(t),n=h(t),o=[],u=!1,c=this,l=new a(function(){},{}),f=new a(function(){},{});return n.onmessage=function(t){t.data.type===s.ALIVE?(u=!0,o.forEach(function(t){c.post(t)})):t.data.type===s.LOG?i.log.apply(null,[e].concat(t.data.arguments)):l.trigger(t.data.data)},n.onerror=function(t){i.error('Error in worker "'+e+'" line '+t.lineno+": ",t.message),f.trigger({data:t.data,worker:c,event:t})},this.onEvent=function(t,e){l=new a(t,e)},this.onError=function(t,e){f=new a(t,e)},this.post=function(t){u?n.postMessage(t):o.push(t)},this}},{"../gamejs":"GUIWXK","./callback":3,"./utils/uri":26}],29:[function(t,e,n){n.Parser=function(){var t=null,e=new DOMParser;return this.parseFromString=function(n){return t=e.parseFromString(n,"text/xml")},this};var r=n.Document=function(t){if(!t||!t instanceof XMLDocument)throw Error("Need a valid xmlDocument.");return this._xmlDocument=t,this};r.prototype.element=function(t){var e=this._xmlDocument.getElementsByTagName(t)[0];return e&&new r(e)||null},r.prototype.elements=function(t){var e=this._xmlDocument.getElementsByTagName(t);return Array.prototype.slice.apply(e,[0]).map(function(t){return new r(t)})},r.prototype.attribute=function(t){var e=this._xmlDocument.getAttribute(t);if(e=e?e.trim():null,null===e)return null;if("true"===e.toLowerCase())return!0;if("false"===e.toLowerCase())return!1;var n=parseInt(e,10),r=parseFloat(e,10);return isNaN(n)?e:r!==n?r:n},r.prototype.value=function(){return this._xmlDocument.nodeValue},r.prototype.children=function(){return Array.prototype.slice.apply(this._xmlDocument.childNodes,[0]).map(function(t){return new r(t)})},r.fromString=function(t){var e=new DOMParser,n=e.parseFromString(t,"text/xml");return new r(n)},r.fromURL=function(t){var e=new XMLHttpRequest;return e.open("GET",t,!1),e.setRequestHeader("X-Requested-With","XMLHttpRequest"),e.setRequestHeader("Content-Type","text/xml"),e.overrideMimeType("text/xml"),e.send(),new r(e.responseXML)}},{}]},{},[]);var gamejs=require("gamejs"),SCREEN_WIDTH=400,SCREEN_HEIGHT=400;Ball.MAX_SIZE=200,Ball.GROW_PER_SEC=50,Ball.COLORS=["#ff0000","#00ff00","#0000cc"],Ball.prototype.nextColor=function(){this.color+=1,this.color>=Ball.COLORS.length&&(this.color=0)},Ball.prototype.draw=function(t){var e=Ball.COLORS[this.color],n=0;gamejs.draw.circle(t,e,this.center,this.radius,n)},Ball.prototype.update=function(t){this.radius+=this.growPerSec*(t/1e3),(this.radius>Ball.MAX_SIZE||this.radius<Math.abs(this.growPerSec))&&(this.radius=this.radius>Ball.MAX_SIZE?Ball.MAX_SIZE:Math.abs(this.growPerSec),this.growPerSec=-this.growPerSec)},gamejs.ready(main); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"gamejs": "1.0.0" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; } | |
body, html { height: 100%; width: 100%; }</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment