view on requirebin
-
-
Save ajsb85/7527341 to your computer and use it in GitHub Desktop.
requirebin sketch
This file contains 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 inherits = require('inherits'); | |
var Game = require('crtrdg-gameloop'); | |
var Entity = require('crtrdg-entity'); | |
var Keyboard = require('crtrdg-keyboard'); | |
var canvas = document.createElement('canvas'); | |
canvas.id = 'game'; | |
var body = document.getElementsByTagName('body')[0]; | |
body.appendChild(canvas); | |
inherits(Player, Entity); | |
function Player(options){ | |
this.position = { | |
x: options.position.x, | |
y: options.position.y | |
}; | |
this.size = { | |
x: options.size.x, | |
y: options.size.y | |
}; | |
this.velocity = { | |
x: options.velocity.x, | |
y: options.velocity.y | |
}; | |
this.speed = options.speed; | |
this.friction = options.friction; | |
this.color = options.color; | |
} | |
Player.prototype.move = function(velocity){ | |
this.position.x += velocity.x; | |
this.position.y += velocity.y; | |
}; | |
Player.prototype.checkBoundaries = function(){ | |
if (this.position.x <= 0){ | |
this.position.x = 0; | |
} | |
if (this.position.x >= this.game.width - this.size.x){ | |
this.position.x = this.game.width - this.size.x; | |
} | |
if (this.position.y <= 0){ | |
this.position.y = 0; | |
} | |
if (this.position.y >= this.game.height - this.size.y){ | |
this.position.y = this.game.height - this.size.y; | |
} | |
}; | |
Player.prototype.keyboardInput = function(){ | |
if ('A' in keyboard.keysDown){ | |
this.velocity.x = -this.speed; | |
} | |
if ('D' in keyboard.keysDown){ | |
this.velocity.x = this.speed; | |
} | |
if ('W' in keyboard.keysDown){ | |
this.velocity.y = -this.speed; | |
} | |
if ('S' in keyboard.keysDown){ | |
this.velocity.y = this.speed; | |
} | |
}; | |
var game = new Game({ | |
canvasId: 'game', | |
width: window.innerWidth, | |
height: window.innerHeight, | |
backgroundColor: '#E187B8' | |
}); | |
var keyboard = new Keyboard(game); | |
var player = new Player({ | |
position: { x: 10, y: 10 }, | |
size: { x: 10, y: 10 }, | |
velocity: { x: 0, y: 0 }, | |
speed: 3, | |
friction: 0.9, | |
color: '#fff' | |
}); | |
player.addTo(game); | |
player.on('update', function(interval){ | |
this.keyboardInput(keyboard); | |
this.move(this.velocity); | |
this.velocity.x *= this.friction; | |
this.velocity.y *= this.friction; | |
this.checkBoundaries(); | |
}); | |
player.on('draw', function(draw){ | |
draw.fillStyle = this.color; | |
draw.fillRect(this.position.x, this.position.y, this.size.x, this.size.y); | |
}); |
This file contains 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 Player(t){this.position={x:t.position.x,y:t.position.y},this.size={x:t.size.x,y:t.size.y},this.velocity={x:t.velocity.x,y:t.velocity.y},this.speed=t.speed,this.friction=t.friction,this.color=t.color}require=function(t,e,n){function r(n,o){if(!e[n]){if(!t[n]){var s="function"==typeof require&&require;if(!o&&s)return s(n,!0);if(i)return i(n,!0);throw Error("Cannot find module '"+n+"'")}var a=e[n]={exports:{}};t[n][0].call(a.exports,function(e){var i=t[n][1][e];return r(i?i:e)},a,a.exports)}return e[n].exports}for(var i="function"==typeof require&&require,o=0;n.length>o;o++)r(n[o]);return r}({1:[function(t,e){var n=e.exports={};n.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var n=[];return window.addEventListener("message",function(t){if(t.source===window&&"process-tick"===t.data&&(t.stopPropagation(),n.length>0)){var e=n.shift();e()}},!0),function(t){n.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.binding=function(){throw Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(){throw Error("process.chdir is not supported")}},{}],2:[function(t,e,n){(function(t){function e(t,e){if(t.indexOf)return t.indexOf(e);for(var n=0;t.length>n;n++)if(e===t[n])return n;return-1}t.EventEmitter||(t.EventEmitter=function(){});var r=n.EventEmitter=t.EventEmitter,i="function"==typeof Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},o=10;r.prototype.setMaxListeners=function(t){this._events||(this._events={}),this._events.maxListeners=t},r.prototype.emit=function(t){if("error"===t&&(!this._events||!this._events.error||i(this._events.error)&&!this._events.error.length))throw arguments[1]instanceof Error?arguments[1]:Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var e=this._events[t];if(!e)return!1;if("function"==typeof e){switch(arguments.length){case 1:e.call(this);break;case 2:e.call(this,arguments[1]);break;case 3:e.call(this,arguments[1],arguments[2]);break;default:var n=Array.prototype.slice.call(arguments,1);e.apply(this,n)}return!0}if(i(e)){for(var n=Array.prototype.slice.call(arguments,1),r=e.slice(),o=0,s=r.length;s>o;o++)r[o].apply(this,n);return!0}return!1},r.prototype.addListener=function(t,e){if("function"!=typeof e)throw Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",t,e),this._events[t])if(i(this._events[t])){if(!this._events[t].warned){var n;n=void 0!==this._events.maxListeners?this._events.maxListeners:o,n&&n>0&&this._events[t].length>n&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),console.trace())}this._events[t].push(e)}else this._events[t]=[this._events[t],e];else this._events[t]=e;return this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(t,e){var n=this;return n.on(t,function r(){n.removeListener(t,r),e.apply(this,arguments)}),this},r.prototype.removeListener=function(t,n){if("function"!=typeof n)throw Error("removeListener only takes instances of Function");if(!this._events||!this._events[t])return this;var r=this._events[t];if(i(r)){var o=e(r,n);if(0>o)return this;r.splice(o,1),0==r.length&&delete this._events[t]}else this._events[t]===n&&delete this._events[t];return this},r.prototype.removeAllListeners=function(t){return 0===arguments.length?(this._events={},this):(t&&this._events&&this._events[t]&&(this._events[t]=null),this)},r.prototype.listeners=function(t){return this._events||(this._events={}),this._events[t]||(this._events[t]=[]),i(this._events[t])||(this._events[t]=[this._events[t]]),this._events[t]}})(t("__browserify_process"))},{__browserify_process:1}],"crtrdg-entity":[function(t,e){e.exports=t("LeCYzl")},{}],LeCYzl:[function(t,e){function n(){return this}var r=t("events").EventEmitter,i=t("inherits"),o=t("aabb-2d");e.exports=n,i(n,r),n.prototype.addTo=function(t){return this.game=t||{},this.game.entities||(this.game.entities=[]),this.game.entities.push(this),this.game.findEntity=this.findEntity,this.initializeListeners(),this.setBoundingBox(),this.on("update",function(){this.setBoundingBox()}),this.exists=!0,this},n.prototype.initializeListeners=function(){var t=this;this.findEntity(this,function(e){e&&(t.game.on("update",function(e){t.emit("update",e)}),t.game.on("draw",function(e){t.emit("draw",e)}))})},n.prototype.remove=function(){this.exists=!1,this.removeAllListeners("update"),this.removeAllListeners("draw"),this.findEntity(this,function(t,e,n){t&&e.splice(n,1)})},n.prototype.findEntity=function(t,e){var n;n=void 0===this.game?this.entities:this.game.entities;for(var r=0;n.length>r;r++)n[r]===t&&e(!0,n,r)},n.prototype.touches=function(t){return t.exists?this.boundingBox.intersects(t.boundingBox):!1},n.prototype.setBoundingBox=function(){this.boundingBox=o([this.position.x,this.position.y],[this.size.x,this.size.y])}},{events:2,inherits:3,"aabb-2d":4}],3:[function(t,e){e.exports="function"==typeof Object.create?function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:function(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}},{}],4:[function(t,e){function n(t,e){return this instanceof n?(this.base=t,this.vec=e,this.mag=r.length(this.vec),this.max=r.create(),r.add(this.max,this.base,this.vec),void 0):new n(t,e)}e.exports=n;var r=t("gl-matrix").vec2,i=n,o=i.prototype;o.perimeter=function(){return 2*(this.vec[0]+this.vec[1])},o.area=function(){return this.vec[0]*this.vec[0]+this.vec[1]*this.vec[1]},o.intperimeter=function(){return this.vec[0]+this.vec[1]<<1},o.width=function(){return this.vec[0]},o.height=function(){return this.vec[1]},o.x0=function(){return this.base[0]},o.y0=function(){return this.base[1]},o.x1=function(){return this.max[0]},o.y1=function(){return this.max[1]},o.translate=function(t){return r.add(this.max,this.max,t),r.add(this.base,this.base,t),this},o.expand=function(t){var e=r.create(),i=r.create();return r.max(e,t.max,this.max),r.min(i,t.base,this.base),r.sub(e,e,i),new n(i,e)},o.intersects=function(t){return t.base[0]>this.max[0]?!1:t.base[1]>this.max[1]?!1:t.max[0]<this.base[0]?!1:t.max[1]<this.base[1]?!1:!0},o.union=function(t){if(!this.intersects(t))return null;var e=Math.max(t.base[0],this.base[0]),r=Math.max(t.base[1],this.base[1]),i=Math.min(t.max[0],this.max[0]),o=Math.min(t.max[1],this.max[1]);return new n([e,r],[i-e,o-r])}},{"gl-matrix":5}],5:[function(t,e,n){(function(){(function(){"use strict";var t={};n===void 0?"function"==typeof define&&"object"==typeof define.amd&&define.amd?(t.exports={},define(function(){return t.exports})):t.exports=window:t.exports=n,function(t){var e={};if(!n)var n=1e-6;e.create=function(){return new Float32Array(2)},e.clone=function(t){var e=new Float32Array(2);return e[0]=t[0],e[1]=t[1],e},e.fromValues=function(t,e){var n=new Float32Array(2);return n[0]=t,n[1]=e,n},e.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t},e.set=function(t,e,n){return t[0]=e,t[1]=n,t},e.add=function(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t},e.sub=e.subtract=function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t},e.mul=e.multiply=function(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t},e.div=e.divide=function(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t},e.min=function(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t},e.max=function(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t},e.scale=function(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t},e.dist=e.distance=function(t,e){var n=e[0]-t[0],r=e[1]-t[1];return Math.sqrt(n*n+r*r)},e.sqrDist=e.squaredDistance=function(t,e){var n=e[0]-t[0],r=e[1]-t[1];return n*n+r*r},e.len=e.length=function(t){var e=t[0],n=t[1];return Math.sqrt(e*e+n*n)},e.sqrLen=e.squaredLength=function(t){var e=t[0],n=t[1];return e*e+n*n},e.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t},e.normalize=function(t,e){var n=e[0],r=e[1],i=n*n+r*r;return i>0&&(i=1/Math.sqrt(i),t[0]=e[0]*i,t[1]=e[1]*i),t},e.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]},e.cross=function(t,e,n){var r=e[0]*n[1]-e[1]*n[0];return t[0]=t[1]=0,t[2]=r,t},e.lerp=function(t,e,n,r){var i=e[0],o=e[1];return t[0]=i+r*(n[0]-i),t[1]=o+r*(n[1]-o),t},e.transformMat2=function(t,e,n){var r=e[0],i=e[1];return t[0]=r*n[0]+i*n[1],t[1]=r*n[2]+i*n[3],t},e.forEach=function(){var t=new Float32Array(2);return function(e,n,r,i,o,s){var a,u;for(n||(n=2),r||(r=0),u=i?Math.min(i*n+r,e.length):e.length,a=r;u>a;a+=n)t[0]=e[a],t[1]=e[a+1],o(t,t,s),e[a]=t[0],e[a+1]=t[1];return e}}(),e.str=function(t){return"vec2("+t[0]+", "+t[1]+")"},t!==void 0&&(t.vec2=e);var r={};if(!n)var n=1e-6;r.create=function(){return new Float32Array(3)},r.clone=function(t){var e=new Float32Array(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e},r.fromValues=function(t,e,n){var r=new Float32Array(3);return r[0]=t,r[1]=e,r[2]=n,r},r.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},r.set=function(t,e,n,r){return t[0]=e,t[1]=n,t[2]=r,t},r.add=function(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t},r.sub=r.subtract=function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t},r.mul=r.multiply=function(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t},r.div=r.divide=function(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t[2]=e[2]/n[2],t},r.min=function(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t[2]=Math.min(e[2],n[2]),t},r.max=function(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t[2]=Math.max(e[2],n[2]),t},r.scale=function(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t},r.dist=r.distance=function(t,e){var n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(n*n+r*r+i*i)},r.sqrDist=r.squaredDistance=function(t,e){var n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return n*n+r*r+i*i},r.len=r.length=function(t){var e=t[0],n=t[1],r=t[2];return Math.sqrt(e*e+n*n+r*r)},r.sqrLen=r.squaredLength=function(t){var e=t[0],n=t[1],r=t[2];return e*e+n*n+r*r},r.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t},r.normalize=function(t,e){var n=e[0],r=e[1],i=e[2],o=n*n+r*r+i*i;return o>0&&(o=1/Math.sqrt(o),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o),t},r.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]},r.cross=function(t,e,n){var r=e[0],i=e[1],o=e[2],s=n[0],a=n[1],u=n[2];return t[0]=i*u-o*a,t[1]=o*s-r*u,t[2]=r*a-i*s,t},r.lerp=function(t,e,n,r){var i=e[0],o=e[1],s=e[2];return t[0]=i+r*(n[0]-i),t[1]=o+r*(n[1]-o),t[2]=s+r*(n[2]-s),t},r.transformMat4=function(t,e,n){var r=e[0],i=e[1],o=e[2];return t[0]=n[0]*r+n[4]*i+n[8]*o+n[12],t[1]=n[1]*r+n[5]*i+n[9]*o+n[13],t[2]=n[2]*r+n[6]*i+n[10]*o+n[14],t},r.transformQuat=function(t,e,n){var r=e[0],i=e[1],o=e[2],s=n[0],a=n[1],u=n[2],c=n[3],f=c*r+a*o-u*i,h=c*i+u*r-s*o,v=c*o+s*i-a*r,p=-s*r-a*i-u*o;return t[0]=f*c+p*-s+h*-u-v*-a,t[1]=h*c+p*-a+v*-s-f*-u,t[2]=v*c+p*-u+f*-a-h*-s,t},r.forEach=function(){var t=new Float32Array(3);return function(e,n,r,i,o,s){var a,u;for(n||(n=3),r||(r=0),u=i?Math.min(i*n+r,e.length):e.length,a=r;u>a;a+=n)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],o(t,t,s),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2];return e}}(),r.str=function(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"},t!==void 0&&(t.vec3=r);var i={};if(!n)var n=1e-6;i.create=function(){return new Float32Array(4)},i.clone=function(t){var e=new Float32Array(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},i.fromValues=function(t,e,n,r){var i=new Float32Array(4);return i[0]=t,i[1]=e,i[2]=n,i[3]=r,i},i.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},i.set=function(t,e,n,r,i){return t[0]=e,t[1]=n,t[2]=r,t[3]=i,t},i.add=function(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t[3]=e[3]+n[3],t},i.sub=i.subtract=function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t[3]=e[3]-n[3],t},i.mul=i.multiply=function(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t[3]=e[3]*n[3],t},i.div=i.divide=function(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t[2]=e[2]/n[2],t[3]=e[3]/n[3],t},i.min=function(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t[2]=Math.min(e[2],n[2]),t[3]=Math.min(e[3],n[3]),t},i.max=function(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t[2]=Math.max(e[2],n[2]),t[3]=Math.max(e[3],n[3]),t},i.scale=function(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t},i.dist=i.distance=function(t,e){var n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2],o=e[3]-t[3];return Math.sqrt(n*n+r*r+i*i+o*o)},i.sqrDist=i.squaredDistance=function(t,e){var n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2],o=e[3]-t[3];return n*n+r*r+i*i+o*o},i.len=i.length=function(t){var e=t[0],n=t[1],r=t[2],i=t[3];return Math.sqrt(e*e+n*n+r*r+i*i)},i.sqrLen=i.squaredLength=function(t){var e=t[0],n=t[1],r=t[2],i=t[3];return e*e+n*n+r*r+i*i},i.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t},i.normalize=function(t,e){var n=e[0],r=e[1],i=e[2],o=e[3],s=n*n+r*r+i*i+o*o;return s>0&&(s=1/Math.sqrt(s),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t[3]=e[3]*s),t},i.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]},i.lerp=function(t,e,n,r){var i=e[0],o=e[1],s=e[2],a=e[3];return t[0]=i+r*(n[0]-i),t[1]=o+r*(n[1]-o),t[2]=s+r*(n[2]-s),t[3]=a+r*(n[3]-a),t},i.transformMat4=function(t,e,n){var r=e[0],i=e[1],o=e[2],s=e[3];return t[0]=n[0]*r+n[4]*i+n[8]*o+n[12]*s,t[1]=n[1]*r+n[5]*i+n[9]*o+n[13]*s,t[2]=n[2]*r+n[6]*i+n[10]*o+n[14]*s,t[3]=n[3]*r+n[7]*i+n[11]*o+n[15]*s,t},i.transformQuat=function(t,e,n){var r=e[0],i=e[1],o=e[2],s=n[0],a=n[1],u=n[2],c=n[3],f=c*r+a*o-u*i,h=c*i+u*r-s*o,v=c*o+s*i-a*r,p=-s*r-a*i-u*o;return t[0]=f*c+p*-s+h*-u-v*-a,t[1]=h*c+p*-a+v*-s-f*-u,t[2]=v*c+p*-u+f*-a-h*-s,t},i.forEach=function(){var t=new Float32Array(4);return function(e,n,r,i,o,s){var a,u;for(n||(n=4),r||(r=0),u=i?Math.min(i*n+r,e.length):e.length,a=r;u>a;a+=n)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],t[3]=e[a+3],o(t,t,s),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2],e[a+3]=t[3];return e}}(),i.str=function(t){return"vec4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},t!==void 0&&(t.vec4=i);var o={},s=new Float32Array([1,0,0,1]);if(!n)var n=1e-6;o.create=function(){return new Float32Array(s)},o.clone=function(t){var e=new Float32Array(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},o.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},o.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},o.transpose=function(t,e){if(t===e){var n=e[1];t[1]=e[2],t[2]=n}else t[0]=e[0],t[1]=e[2],t[2]=e[1],t[3]=e[3];return t},o.invert=function(t,e){var n=e[0],r=e[1],i=e[2],o=e[3],s=n*o-i*r;return s?(s=1/s,t[0]=o*s,t[1]=-r*s,t[2]=-i*s,t[3]=n*s,t):null},o.adjoint=function(t,e){var n=e[0];return t[0]=e[3],t[1]=-e[1],t[2]=-e[2],t[3]=n,t},o.determinant=function(t){return t[0]*t[3]-t[2]*t[1]},o.mul=o.multiply=function(t,e,n){var r=e[0],i=e[1],o=e[2],s=e[3],a=n[0],u=n[1],c=n[2],f=n[3];return t[0]=r*a+i*c,t[1]=r*u+i*f,t[2]=o*a+s*c,t[3]=o*u+s*f,t},o.rotate=function(t,e,n){var r=e[0],i=e[1],o=e[2],s=e[3],a=Math.sin(n),u=Math.cos(n);return t[0]=r*u+i*a,t[1]=r*-a+i*u,t[2]=o*u+s*a,t[3]=o*-a+s*u,t},o.scale=function(t,e,n){var r=e[0],i=e[1],o=e[2],s=e[3],a=n[0],u=n[1];return t[0]=r*a,t[1]=i*u,t[2]=o*a,t[3]=s*u,t},o.str=function(t){return"mat2("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},t!==void 0&&(t.mat2=o);var a={},u=new Float32Array([1,0,0,0,1,0,0,0,1]);if(!n)var n=1e-6;a.create=function(){return new Float32Array(u)},a.clone=function(t){var e=new Float32Array(9);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e},a.copy=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],t[7]=e[7],t[8]=e[8],t},a.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},a.transpose=function(t,e){if(t===e){var n=e[1],r=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=n,t[5]=e[7],t[6]=r,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},a.invert=function(t,e){var n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],a=e[5],u=e[6],c=e[7],f=e[8],h=f*s-a*c,v=-f*o+a*u,p=c*o-s*u,l=n*h+r*v+i*p;return l?(l=1/l,t[0]=h*l,t[1]=(-f*r+i*c)*l,t[2]=(a*r-i*s)*l,t[3]=v*l,t[4]=(f*n-i*u)*l,t[5]=(-a*n+i*o)*l,t[6]=p*l,t[7]=(-c*n+r*u)*l,t[8]=(s*n-r*o)*l,t):null},a.adjoint=function(t,e){var n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],a=e[5],u=e[6],c=e[7],f=e[8];return t[0]=s*f-a*c,t[1]=i*c-r*f,t[2]=r*a-i*s,t[3]=a*u-o*f,t[4]=n*f-i*u,t[5]=i*o-n*a,t[6]=o*c-s*u,t[7]=r*u-n*c,t[8]=n*s-r*o,t},a.determinant=function(t){var e=t[0],n=t[1],r=t[2],i=t[3],o=t[4],s=t[5],a=t[6],u=t[7],c=t[8];return e*(c*o-s*u)+n*(-c*i+s*a)+r*(u*i-o*a)},a.mul=a.multiply=function(t,e,n){var r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],u=e[5],c=e[6],f=e[7],h=e[8],v=n[0],p=n[1],l=n[2],d=n[3],m=n[4],y=n[5],w=n[6],g=n[7],_=n[8];return t[0]=v*r+p*s+l*c,t[1]=v*i+p*a+l*f,t[2]=v*o+p*u+l*h,t[3]=d*r+m*s+y*c,t[4]=d*i+m*a+y*f,t[5]=d*o+m*u+y*h,t[6]=w*r+g*s+_*c,t[7]=w*i+g*a+_*f,t[8]=w*o+g*u+_*h,t},a.str=function(t){return"mat3("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+")"},t!==void 0&&(t.mat3=a);var c={},f=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);if(!n)var n=1e-6;c.create=function(){return new Float32Array(f)},c.clone=function(t){var e=new Float32Array(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},c.copy=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],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},c.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},c.transpose=function(t,e){if(t===e){var n=e[1],r=e[2],i=e[3],o=e[6],s=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=n,t[6]=e[9],t[7]=e[13],t[8]=r,t[9]=o,t[11]=e[14],t[12]=i,t[13]=s,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t},c.invert=function(t,e){var n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],a=e[5],u=e[6],c=e[7],f=e[8],h=e[9],v=e[10],p=e[11],l=e[12],d=e[13],m=e[14],y=e[15],w=n*a-r*s,g=n*u-i*s,_=n*c-o*s,x=r*u-i*a,b=r*c-o*a,M=i*c-o*u,E=f*d-h*l,k=f*m-v*l,L=f*y-p*l,q=h*m-v*d,A=h*y-p*d,F=v*y-p*m,C=w*F-g*A+_*q+x*L-b*k+M*E;return C?(C=1/C,t[0]=(a*F-u*A+c*q)*C,t[1]=(i*A-r*F-o*q)*C,t[2]=(d*M-m*b+y*x)*C,t[3]=(v*b-h*M-p*x)*C,t[4]=(u*L-s*F-c*k)*C,t[5]=(n*F-i*L+o*k)*C,t[6]=(m*_-l*M-y*g)*C,t[7]=(f*M-v*_+p*g)*C,t[8]=(s*A-a*L+c*E)*C,t[9]=(r*L-n*A-o*E)*C,t[10]=(l*b-d*_+y*w)*C,t[11]=(h*_-f*b-p*w)*C,t[12]=(a*k-s*q-u*E)*C,t[13]=(n*q-r*k+i*E)*C,t[14]=(d*g-l*x-m*w)*C,t[15]=(f*x-h*g+v*w)*C,t):null},c.adjoint=function(t,e){var n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],a=e[5],u=e[6],c=e[7],f=e[8],h=e[9],v=e[10],p=e[11],l=e[12],d=e[13],m=e[14],y=e[15];return t[0]=a*(v*y-p*m)-h*(u*y-c*m)+d*(u*p-c*v),t[1]=-(r*(v*y-p*m)-h*(i*y-o*m)+d*(i*p-o*v)),t[2]=r*(u*y-c*m)-a*(i*y-o*m)+d*(i*c-o*u),t[3]=-(r*(u*p-c*v)-a*(i*p-o*v)+h*(i*c-o*u)),t[4]=-(s*(v*y-p*m)-f*(u*y-c*m)+l*(u*p-c*v)),t[5]=n*(v*y-p*m)-f*(i*y-o*m)+l*(i*p-o*v),t[6]=-(n*(u*y-c*m)-s*(i*y-o*m)+l*(i*c-o*u)),t[7]=n*(u*p-c*v)-s*(i*p-o*v)+f*(i*c-o*u),t[8]=s*(h*y-p*d)-f*(a*y-c*d)+l*(a*p-c*h),t[9]=-(n*(h*y-p*d)-f*(r*y-o*d)+l*(r*p-o*h)),t[10]=n*(a*y-c*d)-s*(r*y-o*d)+l*(r*c-o*a),t[11]=-(n*(a*p-c*h)-s*(r*p-o*h)+f*(r*c-o*a)),t[12]=-(s*(h*m-v*d)-f*(a*m-u*d)+l*(a*v-u*h)),t[13]=n*(h*m-v*d)-f*(r*m-i*d)+l*(r*v-i*h),t[14]=-(n*(a*m-u*d)-s*(r*m-i*d)+l*(r*u-i*a)),t[15]=n*(a*v-u*h)-s*(r*v-i*h)+f*(r*u-i*a),t},c.determinant=function(t){var e=t[0],n=t[1],r=t[2],i=t[3],o=t[4],s=t[5],a=t[6],u=t[7],c=t[8],f=t[9],h=t[10],v=t[11],p=t[12],l=t[13],d=t[14],m=t[15],y=e*s-n*o,w=e*a-r*o,g=e*u-i*o,_=n*a-r*s,x=n*u-i*s,b=r*u-i*a,M=c*l-f*p,E=c*d-h*p,k=c*m-v*p,L=f*d-h*l,q=f*m-v*l,A=h*m-v*d;return y*A-w*q+g*L+_*k-x*E+b*M},c.mul=c.multiply=function(t,e,n){var r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],u=e[5],c=e[6],f=e[7],h=e[8],v=e[9],p=e[10],l=e[11],d=e[12],m=e[13],y=e[14],w=e[15],g=n[0],_=n[1],x=n[2],b=n[3];return t[0]=g*r+_*a+x*h+b*d,t[1]=g*i+_*u+x*v+b*m,t[2]=g*o+_*c+x*p+b*y,t[3]=g*s+_*f+x*l+b*w,g=n[4],_=n[5],x=n[6],b=n[7],t[4]=g*r+_*a+x*h+b*d,t[5]=g*i+_*u+x*v+b*m,t[6]=g*o+_*c+x*p+b*y,t[7]=g*s+_*f+x*l+b*w,g=n[8],_=n[9],x=n[10],b=n[11],t[8]=g*r+_*a+x*h+b*d,t[9]=g*i+_*u+x*v+b*m,t[10]=g*o+_*c+x*p+b*y,t[11]=g*s+_*f+x*l+b*w,g=n[12],_=n[13],x=n[14],b=n[15],t[12]=g*r+_*a+x*h+b*d,t[13]=g*i+_*u+x*v+b*m,t[14]=g*o+_*c+x*p+b*y,t[15]=g*s+_*f+x*l+b*w,t},c.translate=function(t,e,n){var r,i,o,s,a,u,c,f,h,v,p,l,d=n[0],m=n[1],y=n[2];return e===t?(t[12]=e[0]*d+e[4]*m+e[8]*y+e[12],t[13]=e[1]*d+e[5]*m+e[9]*y+e[13],t[14]=e[2]*d+e[6]*m+e[10]*y+e[14],t[15]=e[3]*d+e[7]*m+e[11]*y+e[15]):(r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],u=e[5],c=e[6],f=e[7],h=e[8],v=e[9],p=e[10],l=e[11],t[0]=r,t[1]=i,t[2]=o,t[3]=s,t[4]=a,t[5]=u,t[6]=c,t[7]=f,t[8]=h,t[9]=v,t[10]=p,t[11]=l,t[12]=r*d+a*m+h*y+e[12],t[13]=i*d+u*m+v*y+e[13],t[14]=o*d+c*m+p*y+e[14],t[15]=s*d+f*m+l*y+e[15]),t},c.scale=function(t,e,n){var r=n[0],i=n[1],o=n[2];return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*o,t[9]=e[9]*o,t[10]=e[10]*o,t[11]=e[11]*o,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},c.rotate=function(t,e,r,i){var o,s,a,u,c,f,h,v,p,l,d,m,y,w,g,_,x,b,M,E,k,L,q,A,F=i[0],C=i[1],j=i[2],z=Math.sqrt(F*F+C*C+j*j);return n>Math.abs(z)?null:(z=1/z,F*=z,C*=z,j*=z,o=Math.sin(r),s=Math.cos(r),a=1-s,u=e[0],c=e[1],f=e[2],h=e[3],v=e[4],p=e[5],l=e[6],d=e[7],m=e[8],y=e[9],w=e[10],g=e[11],_=F*F*a+s,x=C*F*a+j*o,b=j*F*a-C*o,M=F*C*a-j*o,E=C*C*a+s,k=j*C*a+F*o,L=F*j*a+C*o,q=C*j*a-F*o,A=j*j*a+s,t[0]=u*_+v*x+m*b,t[1]=c*_+p*x+y*b,t[2]=f*_+l*x+w*b,t[3]=h*_+d*x+g*b,t[4]=u*M+v*E+m*k,t[5]=c*M+p*E+y*k,t[6]=f*M+l*E+w*k,t[7]=h*M+d*E+g*k,t[8]=u*L+v*q+m*A,t[9]=c*L+p*q+y*A,t[10]=f*L+l*q+w*A,t[11]=h*L+d*q+g*A,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)},c.rotateX=function(t,e,n){var r=Math.sin(n),i=Math.cos(n),o=e[4],s=e[5],a=e[6],u=e[7],c=e[8],f=e[9],h=e[10],v=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=o*i+c*r,t[5]=s*i+f*r,t[6]=a*i+h*r,t[7]=u*i+v*r,t[8]=c*i-o*r,t[9]=f*i-s*r,t[10]=h*i-a*r,t[11]=v*i-u*r,t},c.rotateY=function(t,e,n){var r=Math.sin(n),i=Math.cos(n),o=e[0],s=e[1],a=e[2],u=e[3],c=e[8],f=e[9],h=e[10],v=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*i-c*r,t[1]=s*i-f*r,t[2]=a*i-h*r,t[3]=u*i-v*r,t[8]=o*r+c*i,t[9]=s*r+f*i,t[10]=a*r+h*i,t[11]=u*r+v*i,t},c.rotateZ=function(t,e,n){var r=Math.sin(n),i=Math.cos(n),o=e[0],s=e[1],a=e[2],u=e[3],c=e[4],f=e[5],h=e[6],v=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*i+c*r,t[1]=s*i+f*r,t[2]=a*i+h*r,t[3]=u*i+v*r,t[4]=c*i-o*r,t[5]=f*i-s*r,t[6]=h*i-a*r,t[7]=v*i-u*r,t},c.fromRotationTranslation=function(t,e,n){var r=e[0],i=e[1],o=e[2],s=e[3],a=r+r,u=i+i,c=o+o,f=r*a,h=r*u,v=r*c,p=i*u,l=i*c,d=o*c,m=s*a,y=s*u,w=s*c;return t[0]=1-(p+d),t[1]=h+w,t[2]=v-y,t[3]=0,t[4]=h-w,t[5]=1-(f+d),t[6]=l+m,t[7]=0,t[8]=v+y,t[9]=l-m,t[10]=1-(f+p),t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t},c.frustum=function(t,e,n,r,i,o,s){var a=1/(n-e),u=1/(i-r),c=1/(o-s);return t[0]=2*o*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2*o*u,t[6]=0,t[7]=0,t[8]=(n+e)*a,t[9]=(i+r)*u,t[10]=(s+o)*c,t[11]=-1,t[12]=0,t[13]=0,t[14]=2*s*o*c,t[15]=0,t},c.perspective=function(t,e,n,r,i){var o=1/Math.tan(e/2),s=1/(r-i);return t[0]=o/n,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=(i+r)*s,t[11]=-1,t[12]=0,t[13]=0,t[14]=2*i*r*s,t[15]=0,t},c.ortho=function(t,e,n,r,i,o,s){var a=1/(e-n),u=1/(r-i),c=1/(o-s);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*u,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*c,t[11]=0,t[12]=(e+n)*a,t[13]=(i+r)*u,t[14]=(s+o)*c,t[15]=1,t},c.lookAt=function(t,e,r,i){var o,s,a,u,f,h,v,p,l,d,m=e[0],y=e[1],w=e[2],g=i[0],_=i[1],x=i[2],b=r[0],M=r[1],E=r[2];return n>Math.abs(m-b)&&n>Math.abs(y-M)&&n>Math.abs(w-E)?c.identity(t):(v=m-b,p=y-M,l=w-E,d=1/Math.sqrt(v*v+p*p+l*l),v*=d,p*=d,l*=d,o=_*l-x*p,s=x*v-g*l,a=g*p-_*v,d=Math.sqrt(o*o+s*s+a*a),d?(d=1/d,o*=d,s*=d,a*=d):(o=0,s=0,a=0),u=p*a-l*s,f=l*o-v*a,h=v*s-p*o,d=Math.sqrt(u*u+f*f+h*h),d?(d=1/d,u*=d,f*=d,h*=d):(u=0,f=0,h=0),t[0]=o,t[1]=u,t[2]=v,t[3]=0,t[4]=s,t[5]=f,t[6]=p,t[7]=0,t[8]=a,t[9]=h,t[10]=l,t[11]=0,t[12]=-(o*m+s*y+a*w),t[13]=-(u*m+f*y+h*w),t[14]=-(v*m+p*y+l*w),t[15]=1,t)},c.str=function(t){return"mat4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+", "+t[9]+", "+t[10]+", "+t[11]+", "+t[12]+", "+t[13]+", "+t[14]+", "+t[15]+")"},t!==void 0&&(t.mat4=c);var h={},v=new Float32Array([0,0,0,1]);if(!n)var n=1e-6;h.create=function(){return new Float32Array(v)},h.clone=i.clone,h.fromValues=i.fromValues,h.copy=i.copy,h.set=i.set,h.identity=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t},h.setAxisAngle=function(t,e,n){n=.5*n;var r=Math.sin(n);return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=Math.cos(n),t},h.add=i.add,h.mul=h.multiply=function(t,e,n){var r=e[0],i=e[1],o=e[2],s=e[3],a=n[0],u=n[1],c=n[2],f=n[3];return t[0]=r*f+s*a+i*c-o*u,t[1]=i*f+s*u+o*a-r*c,t[2]=o*f+s*c+r*u-i*a,t[3]=s*f-r*a-i*u-o*c,t},h.scale=i.scale,h.rotateX=function(t,e,n){n*=.5;var r=e[0],i=e[1],o=e[2],s=e[3],a=Math.sin(n),u=Math.cos(n);return t[0]=r*u+s*a,t[1]=i*u+o*a,t[2]=o*u-i*a,t[3]=s*u-r*a,t},h.rotateY=function(t,e,n){n*=.5;var r=e[0],i=e[1],o=e[2],s=e[3],a=Math.sin(n),u=Math.cos(n);return t[0]=r*u-o*a,t[1]=i*u+s*a,t[2]=o*u+r*a,t[3]=s*u-i*a,t},h.rotateZ=function(t,e,n){n*=.5;var r=e[0],i=e[1],o=e[2],s=e[3],a=Math.sin(n),u=Math.cos(n);return t[0]=r*u+i*a,t[1]=i*u-r*a,t[2]=o*u+s*a,t[3]=s*u-o*a,t},h.calculateW=function(t,e){var n=e[0],r=e[1],i=e[2];return t[0]=n,t[1]=r,t[2]=i,t[3]=-Math.sqrt(Math.abs(1-n*n-r*r-i*i)),t},h.dot=i.dot,h.lerp=i.lerp,h.slerp=function(t,e,n,r){var i,o,s,a,u=e[0],c=e[1],f=e[2],h=e[3],v=n[0],p=n[1],l=n[2],d=e[3],m=u*v+c*p+f*l+h*d;return Math.abs(m)>=1?(t!==e&&(t[0]=u,t[1]=c,t[2]=f,t[3]=h),t):(i=Math.acos(m),o=Math.sqrt(1-m*m),.001>Math.abs(o)?(t[0]=.5*u+.5*v,t[1]=.5*c+.5*p,t[2]=.5*f+.5*l,t[3]=.5*h+.5*d,t):(s=Math.sin((1-r)*i)/o,a=Math.sin(r*i)/o,t[0]=u*s+v*a,t[1]=c*s+p*a,t[2]=f*s+l*a,t[3]=h*s+d*a,t))},h.invert=function(t,e){var n=e[0],r=e[1],i=e[2],o=e[3],s=n*n+r*r+i*i+o*o,a=s?1/s:0;return t[0]=-n*a,t[1]=-r*a,t[2]=-i*a,t[3]=o*a,t},h.conjugate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},h.len=h.length=i.length,h.sqrLen=h.squaredLength=i.squaredLength,h.normalize=i.normalize,h.str=function(t){return"quat("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},t!==void 0&&(t.quat=h)}(t.exports)})()})()},{}]},{},[]),require=function(t,e,n){function r(n,o){if(!e[n]){if(!t[n]){var s="function"==typeof require&&require;if(!o&&s)return s(n,!0);if(i)return i(n,!0);throw Error("Cannot find module '"+n+"'")}var a=e[n]={exports:{}};t[n][0].call(a.exports,function(e){var i=t[n][1][e];return r(i?i:e)},a,a.exports)}return e[n].exports}for(var i="function"==typeof require&&require,o=0;n.length>o;o++)r(n[o]);return r}({inherits:[function(t,e){e.exports=t("0n+j+n")},{}],"0n+j+n":[function(t,e){e.exports="function"==typeof Object.create?function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:function(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}},{}]},{},[]),require=function(t,e,n){function r(n,o){if(!e[n]){if(!t[n]){var s="function"==typeof require&&require;if(!o&&s)return s(n,!0);if(i)return i(n,!0);throw Error("Cannot find module '"+n+"'")}var a=e[n]={exports:{}};t[n][0].call(a.exports,function(e){var i=t[n][1][e];return r(i?i:e)},a,a.exports)}return e[n].exports}for(var i="function"==typeof require&&require,o=0;n.length>o;o++)r(n[o]);return r}({1:[function(t,e){var n=e.exports={};n.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var n=[];return window.addEventListener("message",function(t){if(t.source===window&&"process-tick"===t.data&&(t.stopPropagation(),n.length>0)){var e=n.shift();e()}},!0),function(t){n.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.binding=function(){throw Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(){throw Error("process.chdir is not supported")}},{}],2:[function(t,e,n){(function(t){function e(t,e){if(t.indexOf)return t.indexOf(e);for(var n=0;t.length>n;n++)if(e===t[n])return n;return-1}t.EventEmitter||(t.EventEmitter=function(){});var r=n.EventEmitter=t.EventEmitter,i="function"==typeof Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},o=10;r.prototype.setMaxListeners=function(t){this._events||(this._events={}),this._events.maxListeners=t},r.prototype.emit=function(t){if("error"===t&&(!this._events||!this._events.error||i(this._events.error)&&!this._events.error.length))throw arguments[1]instanceof Error?arguments[1]:Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var e=this._events[t];if(!e)return!1;if("function"==typeof e){switch(arguments.length){case 1:e.call(this);break;case 2:e.call(this,arguments[1]);break;case 3:e.call(this,arguments[1],arguments[2]);break;default:var n=Array.prototype.slice.call(arguments,1);e.apply(this,n)}return!0}if(i(e)){for(var n=Array.prototype.slice.call(arguments,1),r=e.slice(),o=0,s=r.length;s>o;o++)r[o].apply(this,n);return!0}return!1},r.prototype.addListener=function(t,e){if("function"!=typeof e)throw Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",t,e),this._events[t])if(i(this._events[t])){if(!this._events[t].warned){var n;n=void 0!==this._events.maxListeners?this._events.maxListeners:o,n&&n>0&&this._events[t].length>n&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),console.trace())}this._events[t].push(e)}else this._events[t]=[this._events[t],e];else this._events[t]=e;return this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(t,e){var n=this;return n.on(t,function r(){n.removeListener(t,r),e.apply(this,arguments)}),this},r.prototype.removeListener=function(t,n){if("function"!=typeof n)throw Error("removeListener only takes instances of Function");if(!this._events||!this._events[t])return this;var r=this._events[t];if(i(r)){var o=e(r,n);if(0>o)return this;r.splice(o,1),0==r.length&&delete this._events[t]}else this._events[t]===n&&delete this._events[t];return this},r.prototype.removeAllListeners=function(t){return 0===arguments.length?(this._events={},this):(t&&this._events&&this._events[t]&&(this._events[t]=null),this)},r.prototype.listeners=function(t){return this._events||(this._events={}),this._events[t]||(this._events[t]=[]),i(this._events[t])||(this._events[t]=[this._events[t]]),this._events[t]}})(t("__browserify_process"))},{__browserify_process:1}],"crtrdg-keyboard":[function(t,e){e.exports=t("Q9JvK3")},{}],Q9JvK3:[function(t,e){function n(t){this.game=t||{},this.keysDown={},this.initializeListeners()}var r=t("events").EventEmitter,i=t("inherits"),o=t("vkey");e.exports=n,i(n,r),n.prototype.initializeListeners=function(){var t=this; | |
document.addEventListener("keydown",function(e){t.emit("keydown",o[e.keyCode]),t.keysDown[o[e.keyCode]]=!0,(40===e.keyCode||38===e.keyCode||37===e.keyCode||39===e.keyCode||32===e.keyCode)&&e.preventDefault()},!1),document.addEventListener("keyup",function(e){t.emit("keyup",o[e.keyCode]),delete t.keysDown[o[e.keyCode]]},!1)}},{events:2,inherits:3,vkey:4}],3:[function(t,e){e.exports="function"==typeof Object.create?function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:function(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}},{}],4:[function(t,e){(function(){var t,n="undefined"!=typeof window?window.navigator.userAgent:"",r=/OS X/.test(n),i=/Opera/.test(n),o=!/like Gecko/.test(n)&&!i,s=e.exports={0:r?"<menu>":"<UNK>",1:"<mouse 1>",2:"<mouse 2>",3:"<break>",4:"<mouse 3>",5:"<mouse 4>",6:"<mouse 5>",8:"<backspace>",9:"<tab>",12:"<clear>",13:"<enter>",16:"<shift>",17:"<control>",18:"<alt>",19:"<pause>",20:"<caps-lock>",21:"<ime-hangul>",23:"<ime-junja>",24:"<ime-final>",25:"<ime-kanji>",27:"<escape>",28:"<ime-convert>",29:"<ime-nonconvert>",30:"<ime-accept>",31:"<ime-mode-change>",27:"<escape>",32:"<space>",33:"<page-up>",34:"<page-down>",35:"<end>",36:"<home>",37:"<left>",38:"<up>",39:"<right>",40:"<down>",41:"<select>",42:"<print>",43:"<execute>",44:"<snapshot>",45:"<insert>",46:"<delete>",47:"<help>",91:"<meta>",92:"<meta>",93:r?"<meta>":"<menu>",95:"<sleep>",106:"<num-*>",107:"<num-+>",108:"<num-enter>",109:"<num-->",110:"<num-.>",111:"<num-/>",144:"<num-lock>",145:"<scroll-lock>",160:"<shift-left>",161:"<shift-right>",162:"<control-left>",163:"<control-right>",164:"<alt-left>",165:"<alt-right>",166:"<browser-back>",167:"<browser-forward>",168:"<browser-refresh>",169:"<browser-stop>",170:"<browser-search>",171:"<browser-favorites>",172:"<browser-home>",173:r&&o?"-":"<volume-mute>",174:"<volume-down>",175:"<volume-up>",176:"<next-track>",177:"<prev-track>",178:"<stop>",179:"<play-pause>",180:"<launch-mail>",181:"<launch-media-select>",182:"<launch-app 1>",183:"<launch-app 2>",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",223:"<meta>",224:"<meta>",226:"<alt-gr>",229:"<ime-process>",231:i?"`":"<unicode>",246:"<attention>",247:"<crsel>",248:"<exsel>",249:"<erase-eof>",250:"<play>",251:"<zoom>",252:"<no-name>",253:"<pa-1>",254:"<clear>"};for(t=58;65>t;++t)s[t]=String.fromCharCode(t);for(t=48;58>t;++t)s[t]=t-48+"";for(t=65;91>t;++t)s[t]=String.fromCharCode(t);for(t=96;107>t;++t)s[t]="<num-"+(t-96)+">";for(t=112;136>t;++t)s[t]="F"+(t-111)})()},{}]},{},[]),require=function(t,e,n){function r(n,o){if(!e[n]){if(!t[n]){var s="function"==typeof require&&require;if(!o&&s)return s(n,!0);if(i)return i(n,!0);throw Error("Cannot find module '"+n+"'")}var a=e[n]={exports:{}};t[n][0].call(a.exports,function(e){var i=t[n][1][e];return r(i?i:e)},a,a.exports)}return e[n].exports}for(var i="function"==typeof require&&require,o=0;n.length>o;o++)r(n[o]);return r}({1:[function(t,e){var n=e.exports={};n.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var n=[];return window.addEventListener("message",function(t){if(t.source===window&&"process-tick"===t.data&&(t.stopPropagation(),n.length>0)){var e=n.shift();e()}},!0),function(t){n.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.binding=function(){throw Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(){throw Error("process.chdir is not supported")}},{}],2:[function(t,e,n){(function(t){function e(t,e){if(t.indexOf)return t.indexOf(e);for(var n=0;t.length>n;n++)if(e===t[n])return n;return-1}t.EventEmitter||(t.EventEmitter=function(){});var r=n.EventEmitter=t.EventEmitter,i="function"==typeof Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},o=10;r.prototype.setMaxListeners=function(t){this._events||(this._events={}),this._events.maxListeners=t},r.prototype.emit=function(t){if("error"===t&&(!this._events||!this._events.error||i(this._events.error)&&!this._events.error.length))throw arguments[1]instanceof Error?arguments[1]:Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var e=this._events[t];if(!e)return!1;if("function"==typeof e){switch(arguments.length){case 1:e.call(this);break;case 2:e.call(this,arguments[1]);break;case 3:e.call(this,arguments[1],arguments[2]);break;default:var n=Array.prototype.slice.call(arguments,1);e.apply(this,n)}return!0}if(i(e)){for(var n=Array.prototype.slice.call(arguments,1),r=e.slice(),o=0,s=r.length;s>o;o++)r[o].apply(this,n);return!0}return!1},r.prototype.addListener=function(t,e){if("function"!=typeof e)throw Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",t,e),this._events[t])if(i(this._events[t])){if(!this._events[t].warned){var n;n=void 0!==this._events.maxListeners?this._events.maxListeners:o,n&&n>0&&this._events[t].length>n&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),console.trace())}this._events[t].push(e)}else this._events[t]=[this._events[t],e];else this._events[t]=e;return this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(t,e){var n=this;return n.on(t,function r(){n.removeListener(t,r),e.apply(this,arguments)}),this},r.prototype.removeListener=function(t,n){if("function"!=typeof n)throw Error("removeListener only takes instances of Function");if(!this._events||!this._events[t])return this;var r=this._events[t];if(i(r)){var o=e(r,n);if(0>o)return this;r.splice(o,1),0==r.length&&delete this._events[t]}else this._events[t]===n&&delete this._events[t];return this},r.prototype.removeAllListeners=function(t){return 0===arguments.length?(this._events={},this):(t&&this._events&&this._events[t]&&(this._events[t]=null),this)},r.prototype.listeners=function(t){return this._events||(this._events={}),this._events[t]||(this._events[t]=[]),i(this._events[t])||(this._events[t]=[this._events[t]]),this._events[t]}})(t("__browserify_process"))},{__browserify_process:1}],"crtrdg-gameloop":[function(t,e){e.exports=t("tIN60u")},{}],tIN60u:[function(t,e){function n(t){var t=t||{};r.call(this);var e=this;t.canvas?"string"==typeof t.canvas?this.canvas=document.getElementById(t.canvas):"object"==typeof t.canvas&&t.canvas.tagName&&(this.canvas=t.canvas):(this.canvas=document.createElement("canvas"),this.canvas.id="game",document.body.appendChild(this.canvas)),this.context=this.canvas.getContext("2d"),this.width=this.canvas.width=t.width||window.innerWidth,this.height=this.canvas.height=t.height||window.innerHeight,this.backgroundColor=t.backgroundColor||"#E187B8",this.ticker=i(this.canvas),this.paused=!1,t.maxListeners?this.setMaxListeners(t.maxListeners):this.setMaxListeners(0),window.addEventListener("load",function(){e.start()})}var r=t("events").EventEmitter,i=t("raf"),o=t("inherits");e.exports=n,o(n,r),n.prototype.start=function(){var t=this;this.emit("start"),this.ticker.on("data",function(e){t.update(e),t.draw()})},n.prototype.pause=function(){this.paused=!0,this.ticker.pause(),this.emit("pause")},n.prototype.resume=function(){var t=this;this.paused=!1,this.ticker=i(this.canvas),this.ticker.on("data",function(e){t.update(e),t.draw()}),this.emit("resume")},n.prototype.update=function(t){this.currentScene&&this.sceneManager.update(t),this.emit("update",t)},n.prototype.draw=function(){this.currentScene?(this.context.fillStyle=this.currentScene.backgroundColor,this.sceneManager.draw(this.context)):this.context.fillStyle=this.backgroundColor,this.context.fillRect(0,0,this.width,this.height),this.emit("draw",this.context)}},{events:2,raf:3,inherits:4}],4:[function(t,e){e.exports="function"==typeof Object.create?function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:function(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}},{}],3:[function(t,e){(function(){function n(t){function e(){var r=n.now(),a=r-i;i=r,o.emit("data",a),o.paused||s(e,t)}var i=n.now(),o=new r;return o.pause=function(){o.paused=!0},o.resume=function(){o.paused=!1},s(e,t),o}e.exports=n;var r=t("events").EventEmitter,i="undefined"==typeof window?this:window,o=i.performance&&i.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date},s=i.requestAnimationFrame||i.webkitRequestAnimationFrame||i.mozRequestAnimationFrame||i.msRequestAnimationFrame||i.oRequestAnimationFrame||(i.setImmediate?function(t){setImmediate(t)}:function(t){setTimeout(t,0)});n.polyfill=s,n.now=o})()},{events:2}]},{},[]);var inherits=require("inherits"),Game=require("crtrdg-gameloop"),Entity=require("crtrdg-entity"),Keyboard=require("crtrdg-keyboard"),canvas=document.createElement("canvas");canvas.id="game";var body=document.getElementsByTagName("body")[0];body.appendChild(canvas),inherits(Player,Entity),Player.prototype.move=function(t){this.position.x+=t.x,this.position.y+=t.y},Player.prototype.checkBoundaries=function(){0>=this.position.x&&(this.position.x=0),this.position.x>=this.game.width-this.size.x&&(this.position.x=this.game.width-this.size.x),0>=this.position.y&&(this.position.y=0),this.position.y>=this.game.height-this.size.y&&(this.position.y=this.game.height-this.size.y)},Player.prototype.keyboardInput=function(){"A"in keyboard.keysDown&&(this.velocity.x=-this.speed),"D"in keyboard.keysDown&&(this.velocity.x=this.speed),"W"in keyboard.keysDown&&(this.velocity.y=-this.speed),"S"in keyboard.keysDown&&(this.velocity.y=this.speed)};var game=new Game({canvasId:"game",width:window.innerWidth,height:window.innerHeight,backgroundColor:"#E187B8"}),keyboard=new Keyboard(game),player=new Player({position:{x:10,y:10},size:{x:10,y:10},velocity:{x:0,y:0},speed:3,friction:.9,color:"#fff"});player.addTo(game),player.on("update",function(){this.keyboardInput(keyboard),this.move(this.velocity),this.velocity.x*=this.friction,this.velocity.y*=this.friction,this.checkBoundaries()}),player.on("draw",function(t){t.fillStyle=this.color,t.fillRect(this.position.x,this.position.y,this.size.x,this.size.y)}); |
This file contains 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