UNPKG

odin

Version:

Node.js Canvas/WebGL Javascript Game Framework

2 lines 529 kB
var define;"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/base/event_emitter",[],function(){function EventEmitter(){this._events={}}var shift=Array.prototype.shift;return EventEmitter.prototype.on=function(type,listener,ctx){var events=this._events;return(events[type]||(events[type]=[])).push({listener:listener,ctx:ctx||this}),this},EventEmitter.prototype.once=function(type,listener,ctx){function once(){self.off(type,once),listener.apply(ctx,arguments)}var self=this;return ctx=ctx||this,this.on(type,once,ctx)},EventEmitter.prototype.listenTo=function(obj,type,listener,ctx){if(!obj.on||!obj.addEventListenerTo){throw"Can't listen to Object, it's not a instance of EventEmitter"}return obj.on(type,listener,ctx||this),this},EventEmitter.prototype.off=function(type,listener,ctx){var events,event,i,thisEvents=this._events;if(!type){for(i in thisEvents){thisEvents[i].length=0}return this}if(events=thisEvents[type],!events){return this}if(listener){for(ctx=ctx||this,i=events.length;i--;){if(event=events[i],event.listener===listener&&event.ctx===ctx){events.splice(i,1);break}}}else{events.length=0}return this},EventEmitter.prototype.emit=function(type){var a1,a2,a3,a4,length,event,i,events=this._events[type];if(!events||!events.length){return this}if(length=arguments.length,1===length){for(i=events.length;i--;){(event=events[i])&&event.listener.call(event.ctx)}}else{if(2===length){for(a1=arguments[1],i=events.length;i--;){(event=events[i])&&event.listener.call(event.ctx,a1)}}else{if(3===length){for(a1=arguments[1],a2=arguments[2],i=events.length;i--;){(event=events[i])&&event.listener.call(event.ctx,a1,a2)}}else{if(4===length){for(a1=arguments[1],a2=arguments[2],a3=arguments[3],i=events.length;i--;){(event=events[i])&&event.listener.call(event.ctx,a1,a2,a3)}}else{if(5===length){for(a1=arguments[1],a2=arguments[2],a3=arguments[3],a4=arguments[4],i=events.length;i--;){(event=events[i])&&event.listener.call(event.ctx,a1,a2,a3,a4)}}else{for(shift.apply(arguments),i=events.length;i--;){(event=events[i])&&event.listener.apply(event.ctx,arguments)}}}}}}return this},EventEmitter.extend=function(child,parent){return parent||(parent=this),child.prototype=Object.create(parent.prototype),child.prototype.constructor=child,child.extend=parent.extend||this.extend,parent.onExtend&&(child.onExtend||(child.onExtend=parent.onExtend),parent.onExtend(child)),child},EventEmitter}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/base/class",["odin/base/event_emitter"],function(EventEmitter){function Class(){EventEmitter.call(this),this._id=++CLASS_ID,this._jsonId=-1,this._name=""}var CLASS_ID=0;return EventEmitter.extend(Class),Class.prototype.clone=function(){return(new this.constructor).copy(this)},Class.prototype.copy=function(){return this},Class.prototype.clear=function(){return this},Class.prototype.toJSON=function(json){return json||(json={}),json._id=this._id,json._jsonId=this._id,json._className=this._className,json},Class.prototype.fromJSON=function(json){return this._jsonId=json._jsonId,this},Class.prototype.toString=function(){return this._name},Class.extend=function(child,parent){return parent||(parent=this),child.prototype=Object.create(parent.prototype),child.prototype.constructor=child,child.extend=parent.extend,child.prototype._className=child._className=child.name,Class._classes[child.name]=child,parent.onExtend&&(child.onExtend||(child.onExtend=parent.onExtend),parent.onExtend(child)),child},Class.fromJSON=function(json){return(new Class._classes[json._className]).fromJSON(json)},Class.create=function(type){return new Class._classes[type]},Class._classes={},Class}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/base/util",[],function(){function isObject(obj){return obj===Object(obj)}function isArrayLike(obj){return"object"==typeof obj&&"number"==typeof obj.length}function isArguments(obj){return"[object Arguments]"===toString.call(obj)}function isFunction(obj){return"function"==typeof obj}function isString(obj){return"[object String]"===toString.call(obj)}function isNumber(obj){return"[object Number]"===toString.call(obj)}function isDecimal(obj){return isNumber(obj)&&obj%1!==0}function isInteger(obj){return isNumber(obj)&&obj%1===0}function isDate(obj){return"[object Date]"===toString.call(obj)}function isRegExp(obj){return"[object RegExp]"===toString.call(obj)}function isBoolean(obj){return obj===!0||obj===!1||"[object Boolean]"===toString.call(obj)}function isNull(obj){return null===obj}function isUndefined(obj){return void 0===obj}function has(obj,key){return hasOwnProperty.call(obj,key)}function format(fmt){var i=1,args=arguments,len=args.length;return String(fmt).replace(FORMAT_REGEX,function(x){if("%%"===x){return"%"}if(i>=len){return x}if("%s"===x){return String(args[i++])}if("%d"===x){return Number(args[i++])}if("%j"!==x){return x}try{return JSON.stringify(args[i++])}catch(e){return"[Circular]"}})}function camelize(word,lowFirstLetter){var part,i,il,parts=word.split(SPILTER),string="";for(i=0,il=parts.length;il>i;i++){part=parts[i],string+=part[0].toUpperCase()+part.slice(1).toLowerCase()}return lowFirstLetter?string[0].toLowerCase()+string.slice(1):string}function underscore(word){return word.replace(SPILTER,"").replace(UNDERSCORE,"$1_$2").toLowerCase()}function merge(obj,add){var key;for(key in add){void 0==obj[key]&&(obj[key]=add[key])}return obj}function override(obj,add){var key;for(key in add){void 0!=add[key]&&(obj[key]=add[key])}return obj}function copy(obj,out){var key,i,il,type=typeof obj;if("object"!==type){return obj}if(isArrayLike(obj)){for(out=[],i=0,il=obj.length;il>i;i++){out[i]=copy(obj[i])}}else{if(isObject(obj)){out={};for(key in obj){out[key]=copy(obj[key])}}}return out}function clear(obj){var key;for(key in obj){delete obj[key]}return obj}function arrayBufferToBase64(buffer){for(var binary="",bytes=new Uint8Array(buffer),len=bytes.byteLength,i=0;len>i;i++){binary+=String.fromCharCode(bytes[i])}return isServer?new Buffer(binary.toString(),"binary").toString("base64"):window.btoa(binary)}function base64ToArrayBuffer(str){for(var binary=isServer?new Buffer(str,"base64").toString("binary"):window.atob(str),len=binary.length,bytes=new Uint8Array(len).i=0;len>i;i++){bytes[i]=str.charCodeAt(i)}return bytes.buffer}function uid(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(UID_REPLACER,function(c){var a=16*random()|0;return("x"==c?a:3&a|8).toString(16)})}function each(obj,iterator,ctx){var i,length,objKeys;if(null!=obj){if(ArrayForEach&&obj.forEach===ArrayForEach){obj.forEach(iterator,ctx)}else{if(obj.length===+obj.length){for(i=0,length=obj.length;length>i;i++){if(iterator.call(ctx,obj[i],i,obj)===!1){return}}}else{for(objKeys=keys(obj),i=0,length=objKeys.length;length>i;i++){if(iterator.call(ctx,obj[objKeys[i]],objKeys[i],obj)===!1){return}}}}}}var UID_REPLACER,util={},random=Math.random,isServer="undefined"==typeof window,ObjectProto=Object.prototype,toString=ObjectProto.toString,hasOwnProperty=ObjectProto.hasOwnProperty,ArrayProto=Array.prototype,ArrayForEach=ArrayProto.forEach,keys=Object.keys||(Object.keys=function(obj){var key,out=[];for(key in obj){hasOwnProperty.call(obj,key)&&out.push(key)}return out}),isArray=Array.isArray||(Array.isArray=function(obj){return"[object Array]"===toString.call(obj)}),SPILTER=/[ \_\-\.]+|(?=[A-Z][^A-Z])/g,UNDERSCORE=/([a-z])([A-Z])/g,FORMAT_REGEX=/%[sdj%]/g;return util.isObject=isObject,util.isArrayLike=isArrayLike,util.isArray=isArray,util.isArguments=isArguments,util.isFunction=isFunction,util.isString=isString,util.isNumber=isNumber,util.isDecimal=isDecimal,util.isInteger=isInteger,util.isDate=isDate,util.isRegExp=isRegExp,util.isFinite=isFinite,util.isNaN=isNaN,util.isBoolean=isBoolean,util.isNull=isNull,util.isUndefined=isUndefined,util.has=has,util.format=format,util.camelize=camelize,util.underscore=underscore,util.merge=merge,util.override=override,util.copy=copy,util.clear=clear,util.keys=keys,util.arrayBufferToBase64=arrayBufferToBase64,util.base64ToArrayBuffer=base64ToArrayBuffer,UID_REPLACER=/[xy]/g,util.uid=uid,util.each=each,isServer||(util.createWorker=function(fn){var blobURL=URL.createObjectURL(new Blob(["("+fn.toString()+")()"],{type:"application/javascript"})),worker=new Worker(blobURL);return URL.revokeObjectURL(blobURL),worker},util.ajax=function(opts){opts||(opts={});var request=new XMLHttpRequest,src=opts.src,method=opts.method||(opts.method="GET"),before=opts.before,success=opts.success,error=opts.error,async=void 0!=opts.async?!!opts.async:!0;request.addEventListener("load",function(){var status=this.status;if(status>199&&301>status||304==status){"function"==typeof success&&success.call(this)}else{if("function"!=typeof error){throw new Error(method+" "+src+" "+status)}error.call(this,new Error(method+" "+src+" "+status))}},!1),request.addEventListener("error",function(){if("function"!=typeof error){throw new Error(method+" "+src)}error(new Error(method+" "+src))},!1),request.open(method,src,async),"function"==typeof before&&before.call(request),request.send()}),util}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/base/enum",["odin/base/util"],function(util){function Enum(enums){enums=isArray(enums)?enums:enums.split(SPLITER);for(var i=enums.length;i--;){this[enums[i]]=++COUNTER}}var isArray=util.isArray,SPLITER=/[ ,]+/,COUNTER=0;return Enum.prototype.add=function(enums){enums=isArray(enums)?enums:enums.split(SPLITER);for(var i=enums.length;i--;){this[enums[i]]=++COUNTER}return this},Enum.prototype.in=function(num){var key;for(key in this){if(this[key]==num){return!0}}return!1},Enum}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/phys2d/p2enums",["odin/base/enum"],function(Enum){return{BodyType:new Enum("Particle RigidBody"),ShapeType:new Enum("Convex Circle Segment"),MotionState:new Enum("Dynamic Static Kinematic"),SleepState:new Enum("Awake Sleepy Sleeping")}}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/phys2d/collision/p2broadphase",["odin/base/class","odin/phys2d/p2enums"],function(Class,P2Enums){function P2Broadphase(){Class.call(this)}function bodiesNeedsBroadphase(bi,bj){return bi.motionState!==MotionState.Dynamic&&bj.motionState!==MotionState.Dynamic?!1:bi.sleepState===SleepState.Sleeping&&bj.sleepState===SleepState.Sleeping?!1:bi.aabb&&bj.aabb&&!bi.aabb.intersects(bj.aabb)?!1:!0}function shapesNeedsBroadphase(bi,bj,si,sj,pairsi,pairsj){return si||sj?si?sj?0===(si.filterGroup&sj.filterMask)||0===(sj.filterGroup&si.filterMask)?!1:!0:(pairsi.push(si),pairsj.push(bj),!1):(pairsi.push(bi),pairsj.push(sj),!1):!1}var MotionState=P2Enums.MotionState,SleepState=P2Enums.SleepState;return Class.extend(P2Broadphase),P2Broadphase.prototype.collisions=function(bodies,pairsi,pairsj){var bi,bj,shapesi,shapesj,shapesNumi,shapesNumj,si,sj,i,j,k,l,num=bodies.length;for(pairsi.length=pairsj.length=0,i=0;num>i;i++){for(j=0;j!==i;j++){if(bi=bodies[i],bj=bodies[j],bodiesNeedsBroadphase(bi,bj)){for(shapesi=bi.shapes,shapesj=bj.shapes,shapesNumi=shapesi.length,shapesNumj=shapesj.length,k=shapesNumi;k--;){for(l=shapesNumj;l--;){si=shapesi[k],sj=shapesj[l],shapesNeedsBroadphase(bi,bj,si,sj,pairsi,pairsj)&&si.aabb.intersects(sj.aabb)&&(pairsi.push(si),pairsj.push(sj))}}}}}},P2Broadphase}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/base/object_pool",[],function(){function ObjectPool(constructor){this.pooled=[],this.objects=[],this.object=constructor}return ObjectPool.prototype.create=function(){var pooled=this.pooled,object=pooled.length?pooled.pop():new this.object;return this.objects.push(object),object},ObjectPool.prototype.removeObject=function(object){var objects=this.objects,pooled=this.pooled,index=objects.indexOf(object);return index>-1&&(pooled.push(object),objects.splice(index,1)),this},ObjectPool.prototype.remove=ObjectPool.prototype.removeObjects=function(){for(var i=arguments.length;i--;){this.removeObject(arguments[i])}return this},ObjectPool.prototype.clear=function(){var i,objects=this.objects,pooled=this.pooled;for(i=objects.length;i--;){pooled.push(objects[i])}return objects.length=0,this},ObjectPool.prototype.clearForEach=function(fn){var object,i,objects=this.objects,pooled=this.pooled;for(i=objects.length;i--;){object=objects[i],pooled.push(object),fn(object)}return objects.length=0,this},ObjectPool}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/math/mathf",[],function(){function Mathf(){this.PI=PI,this.TWO_PI=TWO_PI,this.HALF_PI=HALF_PI,this.EPSILON=EPSILON,this.TO_RADS=TO_RADS,this.TO_DEGS=TO_DEGS,this._classes={}}var modulo,clamp01,standardRadian,standardAngle,radsToDegs,RIGHT,UP_RIGHT,UP,UP_LEFT,LEFT,DOWN_LEFT,DOWN,DOWN_RIGHT,n225,n675,n1125,n1575,n2025,n2475,n2925,n3375,random=Math.random,abs=Math.abs,cos=Math.cos,pow=Math.pow,floor=Math.floor,ceil=Math.ceil,atan2=Math.atan2,EPSILON=1e-6,PI=3.141592653589793,TWO_PI=2*PI,HALF_PI=.5*PI,TO_RADS=PI/180,TO_DEGS=180/PI,keys=Object.keys;return Mathf.prototype.acos=Math.acos,Mathf.prototype.asin=Math.asin,Mathf.prototype.atan=Math.atan,Mathf.prototype.atan2=Math.atan2,Mathf.prototype.cos=Math.cos,Mathf.prototype.sin=Math.sin,Mathf.prototype.tan=Math.tan,Mathf.prototype.abs=Math.abs,Mathf.prototype.ceil=Math.ceil,Mathf.prototype.exp=Math.exp,Mathf.prototype.floor=Math.floor,Mathf.prototype.log=Math.log,Mathf.prototype.max=Math.max,Mathf.prototype.min=Math.min,Mathf.prototype.pow=Math.pow,Mathf.prototype.random=Math.random,Mathf.prototype.round=Math.round,Mathf.prototype.sqrt=Math.sqrt,Mathf.prototype.equals=function(a,b,e){return abs(a-b)<(e||EPSILON)},Mathf.prototype.modulo=modulo=function(a,b){var r=a%b;return 0>r*b?r+b:r},Mathf.prototype.standardRadian=standardRadian=function(x){return modulo(x,TWO_PI)},Mathf.prototype.standardAngle=standardAngle=function(x){return modulo(x,360)},Mathf.prototype.sign=function(x){return 0>x?-1:1},Mathf.prototype.clamp=function(x,min,max){return min>x?min:x>max?max:x},Mathf.prototype.clampBottom=function(x,min){return min>x?min:x},Mathf.prototype.clampTop=function(x,max){return x>max?max:x},Mathf.prototype.clamp01=clamp01=function(x){return 0>x?0:x>1?1:x},Mathf.prototype.truncate=function(x,n){var p=pow(10,n),num=x*p;return(0>num?ceil(num):floor(num))/p},Mathf.prototype.lerp=function(a,b,x){return a+(b-a)*x},Mathf.prototype.lerpAngle=function(a,b,x){return standardRadian(a+(b-a)*x)},Mathf.prototype.lerpCos=function(a,b,x){var ft=x*PI,f=.5*(1-cos(ft));return a*(1-f)+b*f},Mathf.prototype.lerpCubic=function(v0,v1,v2,v3,x){v0||(v0=v1),v3||(v3=v2);var P=v3-v2-(v0-v1),Q=v0-v1-P,R=v2-v0,S=v1,Px=P*x,Qx=Q*x,Rx=R*x;return Px*Px*Px+Qx*Qx+Rx+S},Mathf.prototype.smoothStep=function(x,min,max){return min>=x?0:x>=max?1:(x=(x-min)/(max-min),x*x*(3-2*x))},Mathf.prototype.smootherStep=function(x,min,max){return min>=x?0:x>=max?1:(x=(x-min)/(max-min),x*x*x*(x*(6*x-15)+10))},Mathf.prototype.pingPong=function(x,length){return length||(length=1),length-abs(x%(2*length)-length)},Mathf.prototype.degsToRads=function(x){return standardRadian(x*TO_RADS)},Mathf.prototype.radsToDegs=radsToDegs=function(x){return standardAngle(x*TO_DEGS)},Mathf.prototype.randInt=function(min,max){return floor(min+random()*(max+1-min))},Mathf.prototype.randFloat=function(min,max){return min+random()*(max-min)},Mathf.prototype.randSign=function(){return random()<.5?1:-1},Mathf.prototype.randChoice=function(array){return array[random()*array.length|0]},Mathf.prototype.shuffle=function(array){for(var j,x,i=array.length;i;j=random()*i|0,x=array[--i],array[i]=array[j],array[j]=x){}return array},Mathf.prototype.randArg=function(){return arguments[random()*arguments.length|0]},Mathf.prototype.randChoiceObject=function(obj){var array=keys(obj);return array[random()*array.length|0]},Mathf.prototype.isPowerOfTwo=function(x){return(x&-x)===x},Mathf.prototype.toPowerOfTwo=function(x){for(var i=2;x>i;){i*=2}return i},Mathf.prototype.fromJSON=function(json){return(new this._classes[json._className]).fromJSON(json)},RIGHT="right",UP_RIGHT="up_right",UP="up",UP_LEFT="up_left",LEFT="left",DOWN_LEFT="down_left",DOWN="down",DOWN_RIGHT="down_right",n225=.39269908169872414,n675=1.1780972450961724,n1125=1.9634954084936207,n1575=2.748893571891069,n2025=3.5342917352885173,n2475=4.319689898685966,n2925=5.105088062083414,n3375=5.8904862254808625,Mathf.prototype.directionAngle=function(a){return a=standardRadian(a),a>=n3375&&n225>a?RIGHT:a>=n225&&n675>a?UP_RIGHT:a>=n675&&n1125>a?UP:a>=n1125&&n1575>a?UP_LEFT:a>=n1575&&n2025>a?LEFT:a>=n2025&&n2475>a?DOWN_LEFT:a>=n2475&&n2925>a?DOWN:a>=n2925&&n3375>a?DOWN_RIGHT:RIGHT},Mathf.prototype.direction=function(x,y){var a=standardRadian(atan2(y,x));return a>=n3375&&n225>a?RIGHT:a>=n225&&n675>a?UP_RIGHT:a>=n675&&n1125>a?UP:a>=n1125&&n1575>a?UP_LEFT:a>=n1575&&n2025>a?LEFT:a>=n2025&&n2475>a?DOWN_LEFT:a>=n2475&&n2925>a?DOWN:a>=n2925&&n3375>a?DOWN_RIGHT:RIGHT},new Mathf}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/math/vec2",["odin/math/mathf"],function(Mathf){function Vec2(x,y){this.x=x||0,this.y=y||0}var sqrt=Math.sqrt;return Mathf._classes.Vec2=Vec2,Vec2.prototype.clone=function(){return new Vec2(this.x,this.y)},Vec2.prototype.copy=function(other){return this.x=other.x,this.y=other.y,this},Vec2.prototype.set=function(x,y){return this.x=x,this.y=y,this},Vec2.prototype.add=function(other){return this.x+=other.x,this.y+=other.y,this},Vec2.prototype.vadd=function(a,b){return this.x=a.x+b.x,this.y=a.y+b.y,this},Vec2.prototype.sadd=function(s){return this.x+=s,this.y+=s,this},Vec2.prototype.sub=function(other){return this.x-=other.x,this.y-=other.y,this},Vec2.prototype.vsub=function(a,b){return this.x=a.x-b.x,this.y=a.y-b.y,this},Vec2.prototype.ssub=function(s){return this.x-=s,this.y-=s,this},Vec2.prototype.mul=function(other){return this.x*=other.x,this.y*=other.y,this},Vec2.prototype.vmul=function(a,b){return this.x=a.x*b.x,this.y=a.y*b.y,this},Vec2.prototype.smul=function(s){return this.x*=s,this.y*=s,this},Vec2.prototype.div=function(other){var x=other.x,y=other.y;return this.x*=0!==x?1/x:0,this.y*=0!==y?1/y:0,this},Vec2.prototype.vdiv=function(a,b){var x=b.x,y=b.y;return this.x=0!==x?a.x/x:0,this.y=0!==y?a.y/y:0,this},Vec2.prototype.sdiv=function(s){return s=0===s?0:1/s,this.x*=s,this.y*=s,this},Vec2.prototype.length=function(){var x=this.x,y=this.y,lsq=x*x+y*y;return 1===lsq?1:lsq>0?sqrt(lsq):0},Vec2.prototype.lengthSq=function(){var x=this.x,y=this.y;return x*x+y*y},Vec2.prototype.setLength=function(length){var x=this.x,y=this.y,l=x*x+y*y;return 1===l?(this.x*=length,this.y*=length,this):(l=l>0?1/sqrt(l):0,this.x*=l*length,this.y*=l*length,this)},Vec2.prototype.normalize=function(){var x=this.x,y=this.y,l=x*x+y*y;return 1===l?this:(l=l>0?1/sqrt(l):0,this.x*=l,this.y*=l,this)},Vec2.prototype.inverse=function(){return this.x*=-1,this.y*=-1,this},Vec2.prototype.inverseVec=function(other){return this.x=-other.x,this.y=-other.y,this},Vec2.prototype.lerp=function(other,x){return this.x+=(other.x-this.x)*x,this.y+=(other.y-this.y)*x,this},Vec2.prototype.vlerp=function(a,b,x){var ax=a.x,ay=a.y;return this.x=ax+(b.x-ax)*x,this.y=ay+(b.y-ay)*x,this},Vec2.vdot=Vec2.prototype.vdot=function(a,b){return a.x*b.x+a.y*b.y},Vec2.prototype.dot=function(other){return this.x*other.x+this.y*other.y},Vec2.vcross=Vec2.prototype.vcross=function(a,b){return a.x*b.y-a.y*b.x},Vec2.prototype.cross=function(other){return this.x*other.y-this.y*other.x},Vec2.prototype.min=function(other){var ax=this.x,ay=this.y,bx=other.x,by=other.y;return this.x=ax>bx?bx:ax,this.y=ay>by?by:ay,this},Vec2.prototype.max=function(other){var ax=this.x,ay=this.y,bx=other.x,by=other.y;return this.x=bx>ax?bx:ax,this.y=by>ay?by:ay,this},Vec2.prototype.clamp=function(min,max){var x=this.x,y=this.y,minx=min.x,miny=min.y,maxx=max.x,maxy=max.y;return this.x=minx>x?minx:x>maxx?maxx:x,this.y=miny>y?miny:y>maxy?maxy:y,this},Vec2.prototype.transformAngle=function(a){var x=this.x,y=this.y,c=cos(a),s=sin(a);return this.x=x*c-y*s,this.y=x*s+y*c,this},Vec2.prototype.transformMat2=function(m){var me=m.elements,x=this.x,y=this.y;return this.x=x*me[0]+y*me[2],this.y=x*me[1]+y*me[3],this},Vec2.prototype.untransformMat2=function(m){var me=m.elements,x=this.x,y=this.y;return this.x=x*me[0]+y*me[1],this.y=x*me[2]+y*me[3],this},Vec2.prototype.transformMat32=function(m){var me=m.elements,x=this.x,y=this.y;return this.x=x*me[0]+y*me[2]+me[4],this.y=x*me[1]+y*me[3]+me[5],this},Vec2.prototype.untransformMat32=function(m){var me=m.elements,x=this.x-me[4],y=this.y-me[5];return this.x=x*me[0]+y*me[1],this.y=x*me[2]+y*me[3],this},Vec2.prototype.transformMat3=function(m){var me=m.elements,x=this.x,y=this.y;return this.x=x*me[0]+y*me[3]+me[6],this.y=x*me[1]+y*me[4]+me[7],this},Vec2.prototype.transformMat4=function(m){var me=m.elements,x=this.x,y=this.y;return this.x=x*me[0]+y*me[4]+me[12],this.y=x*me[1]+y*me[5]+me[13],this},Vec2.prototype.transformProjection=function(m){var me=m.elements,x=this.x,y=this.y,d=1/(me[3]*x+me[7]*y+me[11]*z+me[15]);return this.x=(me[0]*x+me[4]*y+me[12])*d,this.y=(me[1]*x+me[5]*y+me[13])*d,this},Vec2.prototype.fromVec3=function(v){return this.x=v.x,this.y=v.y,this},Vec2.prototype.fromVec4=function(v){return this.x=v.x,this.y=v.y,this},Vec2.prototype.positionFromMat32=function(m){var me=m.elements;return this.x=me[4],this.y=me[5],this},Vec2.prototype.positionFromMat4=function(m){var me=m.elements;return this.x=me[12],this.y=me[13],this},Vec2.prototype.scaleFromMat2=function(m){var me=m.elements,x=this.set(me[0],m[2]).length(),y=this.set(me[1],m[3]).length();return this.x=x,this.y=y,this},Vec2.prototype.scaleFromMat32=Vec2.prototype.scaleFromMat2,Vec2.prototype.equals=function(other){return!(this.x!==other.x||this.y!==other.y)},Vec2.prototype.fromJSON=function(json){return this.x=json.x,this.y=json.y,this},Vec2.prototype.toJSON=function(json){return json||(json={}),json._className="Vec2",json.x=this.x,json.y=this.y,json},Vec2.prototype.fromArray=function(array){return this.x=array[0],this.y=array[1],this},Vec2.prototype.toArray=function(array){return array||(array=[]),array[0]=this.x,array[1]=this.y,array},Vec2.prototype.toString=function(){return"Vec2( "+this.x+", "+this.y+" )"},Vec2}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/phys2d/constraints/p2equation",["odin/base/class"],function(Class){function P2Equation(){Class.call(this),this.bi=void 0,this.bj=void 0,this.minForce=-1e6,this.maxForce=1e6,this.relaxation=3,this.stiffness=1e7,this.a=0,this.b=0,this.eps=0,this.lambda=0,this.B=0,this.invC=0}return Class.extend(P2Equation,Class),P2Equation.prototype.updateConstants=function(h){var k=this.stiffness,d=this.relaxation;this.a=4/(h*(1+4*d)),this.b=4*d/(1+4*d),this.eps=4/(h*h*k*(1+4*d))},P2Equation}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/phys2d/constraints/p2contact",["odin/base/class","odin/math/mathf","odin/math/vec2","odin/phys2d/constraints/p2equation"],function(Class,Mathf,Vec2,P2Equation){function P2Contact(){P2Equation.call(this),this.minForce=0,this.p=new Vec2,this.n=new Vec2,this.s=0,this.e=1,this.u=1,this.ri=new Vec2,this.rj=new Vec2,this.rixn=0,this.rjxn=0}return Class.extend(P2Contact,P2Equation),P2Contact.prototype.init=function(h){var bi=this.bi,bj=this.bj,p=this.p,px=p.x,py=p.y,n=this.n,nx=n.x,ny=n.y,xi=bi.position,xj=bj.position,ri=this.ri,rix=px-xi.x,riy=py-xi.y,rj=this.rj,rjx=px-xj.x,rjy=py-xj.y,rixn=rix*ny-riy*nx,rjxn=rjx*ny-rjy*nx;ri.x=rix,ri.y=riy,rj.x=rjx,rj.y=rjy,this.rixn=rixn,this.rjxn=rjxn,this.lambda=0,this.calculateB(h),this.calculateC()},P2Contact.prototype.calculateB=function(h){var bi=this.bi,bj=this.bj,n=this.n,nx=n.x,ny=n.y,vi=bi.velocity,wi=bi.angularVelocity||0,fi=bi.force,ti=bi.torque||0,invMi=bi.invMass,invIi=bi.invInertia||0,vj=bj.velocity,wj=bj.angularVelocity||0,fj=bj.force,tj=bj.torque||0,invMj=bj.invMass,invIj=bj.invInertia||0,ri=this.ri,rix=ri.x,riy=ri.y,rj=this.rj,rjx=rj.x,rjy=rj.y,e=this.e,Gq=this.s,GWx=vj.x+-wj*rjy-vi.x- -wi*riy,GWy=vj.y+wj*rjx-vi.y-wi*rix,GW=e*GWx*nx+e*GWy*ny,GiMfx=fj.x*invMj+-tj*invIj*rjy-fi.x*invMi- -ti*invIi*riy,GiMfy=fj.y*invMj+tj*invIj*rjx-fi.y*invMi-ti*invIi*rix,GiMf=GiMfx*nx+GiMfy*ny;this.B=-this.a*Gq-this.b*GW-h*GiMf},P2Contact.prototype.calculateC=function(){var bi=this.bi,bj=this.bj,rixn=this.rixn,rjxn=this.rjxn,invIi=bi.invInertia||0,invIj=bj.invInertia||0,C=bi.invMass+bj.invMass+this.eps+invIi*rixn*rixn+invIj*rjxn*rjxn;this.invC=0===C?0:1/C},P2Contact.prototype.calculateGWlambda=function(){var bi=this.bi,bj=this.bj,n=this.n,vlambdai=bi.vlambda,wlambdai=bi.wlambda||0,vlambdaj=bj.vlambda,wlambdaj=bj.wlambda||0,ulambdax=vlambdaj.x-vlambdai.x,ulambday=vlambdaj.y-vlambdai.y,GWlambda=ulambdax*n.x+ulambday*n.y;return void 0!==wlambdai&&(GWlambda-=wlambdai*this.rixn),void 0!==wlambdaj&&(GWlambda+=wlambdaj*this.rjxn),GWlambda},P2Contact.prototype.addToLambda=function(deltaLambda){var bi=this.bi,bj=this.bj,n=this.n,nx=n.x,ny=n.y,invMi=bi.invMass,vlambdai=bi.vlambda,invMj=bj.invMass,vlambdaj=bj.vlambda;vlambdai.x-=deltaLambda*invMi*nx,vlambdai.y-=deltaLambda*invMi*ny,vlambdaj.x+=deltaLambda*invMj*nx,vlambdaj.y+=deltaLambda*invMj*ny,void 0!==bi.wlambda&&(bi.wlambda-=deltaLambda*bi.invInertia*this.rixn),void 0!==bj.wlambda&&(bj.wlambda+=deltaLambda*bj.invInertia*this.rjxn)},P2Contact}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/phys2d/collision/p2nearphase",["odin/base/class","odin/base/object_pool","odin/math/mathf","odin/math/vec2","odin/phys2d/p2enums","odin/phys2d/constraints/p2contact"],function(Class,ObjectPool,Mathf,Vec2,P2Enums,P2Contact){function clearContact(contact){contact.bi=contact.bj=void 0}function P2Nearphase(){Class.call(this)}function collide(si,sj){var bi=si.body,bj=sj.body,i=bi._index,j=bj._index,space=bi.space;return space?(space.collisionMatrixSet(i,j,1,!0),space.collisionMatrixGet(i,j,!0)!==space.collisionMatrixGet(i,j,!1)?(bi.wake(),bj.wake(),bi.emit("collide",bj,si,sj),bj.emit("collide",bi,sj,si)):(bi.emit("colliding",bj,si,sj),bj.emit("colliding",bi,sj,si)),si.isTrigger||sj.isTrigger?!1:!0):!1}function circleCircle(si,sj,contacts){if(collide(si,sj)){var invDist,c,n,nx,ny,p,xi=si.position,xj=sj.position,xjx=xj.x,xjy=xj.y,dx=xjx-xi.x,dy=xjy-xi.y,dist=dx*dx+dy*dy,separation=0,ri=si.radius,rj=sj.radius,r=ri+rj;dist>r*r||(c=CONTACT_POOL.create(),n=c.n,p=c.p,c.bi=si.body,c.bj=sj.body,c.e=1+min(si.elasticity,sj.elasticity),c.u=min(si.friction,sj.friction),EPSILON>dist?(nx=0,ny=1,invDist=0,separation=-r):(dist=sqrt(dist),invDist=1/dist,nx=dx*invDist,ny=dy*invDist,separation=dist-r),n.x=nx,n.y=ny,p.x=xjx-rj*nx,p.y=xjy-rj*ny,c.s=separation,contacts.push(c))}}function circleParticle(si,sj,contacts){var invDist,c,n,nx,ny,p,xi=si.position,xj=sj.position,xjx=xj.x,xjy=xj.y,dx=xjx-xi.x,dy=xjy-xi.y,dist=dx*dx+dy*dy,separation=0,r=si.radius;dist>r*r||(c=CONTACT_POOL.create(),n=c.n,p=c.p,c.bi=si.body,c.bj=sj.body,c.e=1+si.elasticity,c.u=si.friction,EPSILON>dist?(nx=0,ny=1,invDist=0,separation=-r):(dist=sqrt(dist),invDist=1/dist,nx=dx*invDist,ny=dy*invDist,separation=dist-r),n.x=nx,n.y=ny,p.x=xjx,p.y=xjy,c.s=separation,contacts.push(c))}function convexParticle(si,sj,contacts){var vertex,normal,s,v1,v2,v1x,v1y,v2x,v2y,ex,ey,dx,dy,u,dist,invDist,c,n,nx,ny,p,i,vertices=si._vertices,normals=si._normals,xj=sj.position,xjx=xj.x,xjy=xj.y,separation=-1/0,index=-1;for(i=vertices.length;i--;){if(vertex=vertices[i],normal=normals[i],s=normal.x*(xjx-vertex.x)+normal.y*(xjy-vertex.y),s>EPSILON){return}s>separation&&(separation=s,index=i)}if(!(0>index)){if(normal=normals[index],nx=normal.x,ny=normal.y,v1=vertices[index],v1x=v1.x,v1y=v1.y,v2=vertices[index+1]||vertices[0],v2x=v2.x,v2y=v2.y,ex=v2x-v1x,ey=v2y-v1y,dx=xjx-v1x,dy=xjy-v1y,u=(ex*dx+ey*dy)/(ex*ex+ey*ey),0>u){if(dx=xjx-v1x,dy=xjy-v1y,dist=dx*dx+dy*dy,dist>EPSILON){return}dist=sqrt(dist),invDist=dist>0?1/dist:0,nx=dx*invDist,ny=dy*invDist}else{if(u>1){if(dx=xjx-v2x,dy=xjy-v2y,dist=dx*dx+dy*dy,dist>EPSILON){return}dist=sqrt(dist),invDist=dist>0?1/dist:0,nx=dx*invDist,ny=dy*invDist}else{normal=normals[index],nx=normal.x,ny=normal.y,dist=separation}}c=CONTACT_POOL.create(),n=c.n,p=c.p,c.bi=si.body,c.bj=sj.body,c.e=1+si.elasticity,c.u=si.friction,n.x=nx,n.y=ny,p.x=xjx,p.y=xjy,c.s=dist,contacts.push(c)}}function convexCircle(si,sj,contacts){if(collide(si,sj)){var vertex,normal,s,v1,v2,v1x,v1y,v2x,v2y,ex,ey,dx,dy,u,dist,invDist,c,n,nx,ny,p,i,vertices=si._vertices,normals=si._normals,xj=sj.position,xjx=xj.x,xjy=xj.y,radius=sj.radius,separation=-1/0,index=-1;for(i=vertices.length;i--;){if(vertex=vertices[i],normal=normals[i],s=normal.x*(xjx-vertex.x)+normal.y*(xjy-vertex.y),s>radius){return}s>separation&&(separation=s,index=i)}if(!(0>index)){if(normal=normals[index],nx=normal.x,ny=normal.y,v1=vertices[index],v1x=v1.x,v1y=v1.y,v2=vertices[index+1]||vertices[0],v2x=v2.x,v2y=v2.y,ex=v2x-v1x,ey=v2y-v1y,dx=xjx-v1x,dy=xjy-v1y,u=(ex*dx+ey*dy)/(ex*ex+ey*ey),0>u){if(dx=xjx-v1x,dy=xjy-v1y,dist=dx*dx+dy*dy,dist>radius*radius){return}dist=sqrt(dist),invDist=dist>0?1/dist:0,nx=dx*invDist,ny=dy*invDist}else{if(u>1){if(dx=xjx-v2x,dy=xjy-v2y,dist=dx*dx+dy*dy,dist>radius*radius){return}dist=sqrt(dist),invDist=dist>0?1/dist:0,nx=dx*invDist,ny=dy*invDist}else{normal=normals[index],nx=normal.x,ny=normal.y,dist=separation}}c=CONTACT_POOL.create(),n=c.n,p=c.p,c.bi=si.body,c.bj=sj.body,c.e=1+min(si.elasticity,sj.elasticity),c.u=min(si.friction,sj.friction),n.x=nx,n.y=ny,p.x=xjx-radius*nx,p.y=xjy-radius*ny,c.s=dist-radius,contacts.push(c)}}}function contains(vertices,normals,px,py){var n,nx,ny,v,vx,vy,i;for(i=vertices.length;i--;){if(n=normals[i],nx=n.x,ny=n.y,v=vertices[i],vx=v.x,vy=v.y,nx*px+ny*py-(nx*vx+ny*vy)>0){return!1}}return!0}function findContacts(si,sj,normal,dist,contacts){var v,vx,vy,c,n,p,i,verticesi=si._vertices,normalsi=si._normals,verticesj=sj._vertices,normalsj=sj._normals,nx=normal.x,ny=normal.y,e=1+min(si.elasticity,sj.elasticity),u=min(si.friction,sj.friction);for(i=verticesi.length;i--;){v=verticesi[i],vx=v.x,vy=v.y,contains(verticesj,normalsj,vx,vy)&&(c=CONTACT_POOL.create(),n=c.n,p=c.p,c.bi=si.body,c.bj=sj.body,c.e=e,c.u=u,n.x=nx,n.y=ny,p.x=vx,p.y=vy,c.s=dist,contacts.push(c))}for(i=verticesj.length;i--;){v=verticesj[i],vx=v.x,vy=v.y,contains(verticesi,normalsi,vx,vy)&&(c=CONTACT_POOL.create(),n=c.n,p=c.p,c.bi=si.body,c.bj=sj.body,c.e=e,c.u=u,n.x=nx,n.y=ny,p.x=vx,p.y=vy,c.s=dist,contacts.push(c))}}function valueOnAxis(vertices,n,d){var v,i,nx=n.x,ny=n.y,m=1/0;for(i=vertices.length;i--;){v=vertices[i],m=min(m,nx*v.x+ny*v.y)}return m-d}function findMSA(si,sj){var n,v,dist,i,verticesi=si._vertices,normalsi=si._normals,counti=normalsi.length,verticesj=sj._vertices,min=-1/0,index=-1;for(i=counti;i--;){if(n=normalsi[i],v=verticesi[i],dist=valueOnAxis(verticesj,n,n.x*v.x+n.y*v.y),dist>0){return-1}dist>min&&(min=dist,index=i)}return lastMinMSA=min,index}function convexConvex(si,sj,contacts){if(collide(si,sj)){var indexi,mini,indexj,minj;indexi=findMSA(si,sj),0>indexi||(mini=lastMinMSA,indexj=findMSA(sj,si),0>indexj||(minj=lastMinMSA,mini>minj?findContacts(si,sj,si._normals[indexi],mini,contacts):findContacts(sj,si,sj._normals[indexj],minj,contacts)))}}function collisionType(si,sj,contacts){if(si.type!==BodyType.Particle||sj.type!==BodyType.Particle){if(si.type===BodyType.Particle&&sj.type!==BodyType.Particle){switch(sj.type){case ShapeType.Circle:circleParticle(sj,si,contacts);break;case ShapeType.Convex:convexParticle(sj,si,contacts)}}else{if(sj.type===BodyType.Particle&&si.type!==BodyType.Particle){switch(si.type){case ShapeType.Circle:circleParticle(si,sj,contacts);break;case ShapeType.Convex:convexParticle(si,sj,contacts)}}else{if(si.type===ShapeType.Circle){switch(sj.type){case ShapeType.Circle:circleCircle(si,sj,contacts);break;case ShapeType.Convex:convexCircle(sj,si,contacts)}}else{if(si.type===ShapeType.Convex){switch(sj.type){case ShapeType.Circle:convexCircle(si,sj,contacts);break;case ShapeType.Convex:convexConvex(si,sj,contacts) }}}}}}}var lastMinMSA,min=Math.min,sqrt=Math.sqrt,EPSILON=Mathf.EPSILON,BodyType=P2Enums.BodyType,ShapeType=P2Enums.ShapeType,CONTACT_POOL=new ObjectPool(P2Contact);return Class.extend(P2Nearphase),P2Nearphase.CONTACT_POOL=CONTACT_POOL,P2Nearphase.prototype.collisions=function(pairsi,pairsj,contacts){var si,sj,i;for(contacts.length=0,CONTACT_POOL.clearForEach(clearContact),i=pairsi.length;i--;){si=pairsi[i],sj=pairsj[i],collisionType(si,sj,contacts)}},lastMinMSA=0,P2Nearphase}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/math/mat32",["odin/math/mathf"],function(Mathf){function Mat32(m11,m12,m13,m21,m22,m23){var te=new Float32Array(6);this.elements=te,te[0]=void 0!==m11?m11:1,te[2]=m12||0,te[4]=m13||0,te[1]=m21||0,te[3]=void 0!==m22?m22:1,te[5]=m23||0}var sqrt=Math.sqrt,cos=Math.cos,sin=Math.sin,atan2=Math.atan2;return Mathf._classes.Mat32=Mat32,Mat32.prototype.clone=function(){var te=this.elements;return new Mat32(te[0],te[1],te[2],te[3],te[4],te[5])},Mat32.prototype.copy=function(other){var te=this.elements,me=other.elements;return te[0]=me[0],te[1]=me[1],te[2]=me[2],te[3]=me[3],te[4]=me[4],te[5]=me[5],this},Mat32.prototype.set=function(m11,m12,m13,m21,m22,m23){var te=this.elements;return te[0]=m11,te[2]=m12,te[4]=m13,te[1]=m21,te[3]=m22,te[5]=m23,this},Mat32.prototype.mul=function(other){var ae=this.elements,be=other.elements,a11=ae[0],a12=ae[2],a13=ae[4],a21=ae[1],a22=ae[3],a23=ae[5],b11=be[0],b12=be[2],b13=be[4],b21=be[1],b22=be[3],b23=be[5];return ae[0]=a11*b11+a21*b12,ae[2]=a12*b11+a22*b12,ae[1]=a11*b21+a21*b22,ae[3]=a12*b21+a22*b22,ae[4]=a11*b13+a12*b23+a13,ae[5]=a21*b13+a22*b23+a23,this},Mat32.prototype.mmul=function(a,b){var te=this.elements,ae=a.elements,be=b.elements,a11=ae[0],a12=ae[2],a13=ae[4],a21=ae[1],a22=ae[3],a23=ae[5],b11=be[0],b12=be[2],b13=be[4],b21=be[1],b22=be[3],b23=be[5];return te[0]=a11*b11+a21*b12,te[2]=a12*b11+a22*b12,te[1]=a11*b21+a21*b22,te[3]=a12*b21+a22*b22,te[4]=a11*b13+a12*b23+a13,te[5]=a21*b13+a22*b23+a23,this},Mat32.prototype.smul=function(s){var te=this.elements;return te[0]*=s,te[1]*=s,te[2]*=s,te[3]*=s,te[4]*=s,te[5]*=s,this},Mat32.prototype.sdiv=function(s){var te=this.elements;return s=0!==s?1/s:1,te[0]*=s,te[1]*=s,te[2]*=s,te[3]*=s,te[4]*=s,te[5]*=s,this},Mat32.prototype.identity=function(){var te=this.elements;return te[0]=1,te[1]=0,te[2]=0,te[3]=1,te[4]=0,te[5]=0,this},Mat32.prototype.zero=function(){var te=this.elements;return te[0]=0,te[1]=0,te[2]=0,te[3]=0,te[4]=0,te[5]=0,this},Mat32.prototype.determinant=function(){var te=this.elements;return te[0]*te[3]-te[2]*te[1]},Mat32.prototype.inverse=function(){var te=this.elements,m11=te[0],m12=te[2],m13=te[4],m21=te[1],m22=te[3],m23=te[5],det=m11*m22-m12*m21;return det=0!==det?1/det:0,te[0]=m22*det,te[1]=-m12*det,te[2]=-m21*det,te[3]=m11*det,te[4]=(m12*m23-m22*m13)*det,te[5]=(m21*m13-m11*m23)*det,this},Mat32.prototype.inverseMat=function(other){var te=this.elements,me=other.elements,m11=me[0],m12=me[2],m13=me[4],m21=me[1],m22=me[3],m23=me[5],det=m11*m22-m12*m21;return det=0!==det?1/det:0,te[0]=m22*det,te[1]=-m12*det,te[2]=-m21*det,te[3]=m11*det,te[4]=(m12*m23-m22*m13)*det,te[5]=(m21*m13-m11*m23)*det,this},Mat32.prototype.transpose=function(){var tmp,te=this.elements;return tmp=te[1],te[1]=te[2],te[2]=tmp,this},Mat32.prototype.setTrace=function(x,y){var te=this.elements;return te[0]=x,te[3]=y,this},Mat32.prototype.lookAt=function(eye,target){var te=this.elements,x=target.x-eye.x,y=target.y-eye.y,a=atan2(y,x)-HALF_PI,c=cos(a),s=sin(a);return te[0]=c,te[1]=s,te[2]=-s,te[3]=c,this},Mat32.prototype.compose=function(position,scale,angle){var te=this.elements,sx=scale.x,sy=scale.y,c=cos(angle),s=sin(angle);return te[0]=c*sx,te[1]=s*sx,te[2]=-s*sy,te[3]=c*sy,te[4]=position.x,te[5]=position.y,this},Mat32.prototype.decompose=function(position,scale){var te=this.elements,m11=te[0],m12=te[1],sx=scale.set(m11,m12).length(),sy=scale.set(te[2],te[3]).length();return position.x=te[4],position.y=te[5],scale.x=sx,scale.y=sy,atan2(m12,m11)},Mat32.prototype.setRotation=function(angle){var te=this.elements,c=cos(angle),s=sin(angle);return te[0]=c,te[1]=s,te[2]=-s,te[3]=c,this},Mat32.prototype.getRotation=function(){var te=this.elements;return atan2(te[1],te[0])},Mat32.prototype.setPosition=function(v){var te=this.elements;return te[4]=v.x,te[5]=v.y,this},Mat32.prototype.getPosition=function(v){var te=this.elements;return v.x=te[4],v.y=te[5],v},Mat32.prototype.extractPosition=function(other){var te=this.elements,me=other.elements;return te[4]=me[4],te[5]=me[5],this},Mat32.prototype.extractRotation=function(other){var te=this.elements,me=other.elements,m11=me[0],m12=me[2],m21=me[1],m22=me[3],x=m11*m11+m21*m21,y=m12*m12+m22*m22,sx=x>0?1/sqrt(x):0,sy=y>0?1/sqrt(y):0;return te[0]=m11*sx,te[1]=m21*sx,te[2]=m12*sy,te[3]=m22*sy,this},Mat32.prototype.translate=function(v){var te=this.elements,x=v.x,y=v.y;return te[4]=te[0]*x+te[2]*y+te[4],te[5]=te[1]*x+te[3]*y+te[5],this},Mat32.prototype.rotate=function(angle){var te=this.elements,m11=te[0],m12=te[2],m21=te[1],m22=te[3],s=sin(angle),c=sin(angle);return te[0]=m11*c+m12*s,te[1]=m11*-s+m12*c,te[2]=m21*c+m22*s,te[3]=m21*-s+m22*c,this},Mat32.prototype.scale=function(v){var te=this.elements,x=v.x,y=v.y;return te[0]*=x,te[1]*=x,te[4]*=x,te[2]*=y,te[3]*=y,te[5]*=y,this},Mat32.prototype.orthographic=function(left,right,top,bottom){var te=this.elements,w=right-left,h=top-bottom,x=(right+left)/w,y=(top+bottom)/h;return te[0]=2/w,te[1]=0,te[2]=0,te[3]=2/h,te[4]=-x,te[5]=-y,this},Mat32.prototype.fromMat3=function(m){var te=this.elements,me=m.elements;return te[0]=me[0],te[1]=me[1],te[2]=me[3],te[3]=me[4],te[4]=0,te[5]=0,this},Mat32.prototype.fromMat4=function(m){var te=this.elements,me=m.elements;return te[0]=me[0],te[1]=me[1],te[2]=me[4],te[3]=me[5],te[4]=me[11],te[5]=me[12],this},Mat32.prototype.equals=function(other){var ae=this.elements,be=other.elements;return!(ae[0]!==be[0]||ae[1]!==be[1]||ae[2]!==be[2]||ae[3]!==be[3]||ae[4]!==be[4]||ae[5]!==be[5])},Mat32.prototype.fromJSON=function(json){var te=this.elements,me=json.elements;return te[0]=me[0],te[1]=me[1],te[2]=me[2],te[3]=me[3],te[4]=me[4],te[5]=me[5],this},Mat32.prototype.toJSON=function(json){json||(json={});var te=this.elements,je=json.elements||(json.elements=[]);return json._className="Mat32",je[0]=te[0],je[1]=te[1],je[2]=te[2],je[3]=te[3],je[4]=te[4],je[5]=te[5],json},Mat32.prototype.toString=function(){var te=this.elements;return"Mat32[ "+te[0]+", "+te[2]+", "+te[4]+"]\n [ "+te[1]+", "+te[3]+", "+te[5]+"]"},Mat32}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/math/aabb2",["odin/math/mathf","odin/math/vec2"],function(Mathf,Vec2){function AABB2(min,max){this.min=min||new Vec2(1/0,1/0),this.max=max||new Vec2(-1/0,-1/0)}return AABB2.prototype.clone=function(){return new AABB2(this.min.clone(),this.max.clone())},AABB2.prototype.copy=function(other){return this.min.copy(other.min),this.max.copy(other.max),this},AABB2.prototype.set=function(min,max){return this.min.copy(min),this.max.copy(max),this},AABB2.prototype.expandPoint=function(v){return this.min.min(v),this.max.max(v),this},AABB2.prototype.expandVec=function(v){return this.min.sub(v),this.max.add(v),this},AABB2.prototype.expandScalar=function(s){return this.min.ssub(s),this.max.sadd(s),this},AABB2.prototype.union=function(other){return this.min.min(other.min),this.max.max(other.max),this},AABB2.prototype.clear=function(){return this.min.set(1/0,1/0),this.max.set(-1/0,-1/0),this},AABB2.prototype.contains=function(point){var min=this.min,max=this.max,px=point.x,py=point.y;return!(px<min.x||px>max.x||py<min.y||py>max.y)},AABB2.prototype.intersects=function(other){var aMin=this.min,aMax=this.max,bMin=other.min,bMax=other.max;return!(bMax.x<aMin.x||bMin.x>aMax.x||bMax.y<aMin.y||bMin.y>aMax.y)},AABB2.prototype.fromPoints=function(points){for(var v,x,y,i=points.length,minx=1/0,miny=1/0,maxx=-1/0,maxy=-1/0,min=this.min,max=this.max;i--;){v=points[i],x=v.x,y=v.y,minx=minx>x?x:minx,miny=miny>y?y:miny,maxx=x>maxx?x:maxx,maxy=y>maxy?y:maxy}return min.x=minx,min.y=miny,max.x=maxx,max.y=maxy,this},AABB2.prototype.fromCenterSize=function(center,size){var min=this.min,max=this.max,x=center.x,y=center.y,hx=.5*size.x,hy=.5*size.y;return min.x=x-hx,min.y=y-hy,max.x=x+hx,max.y=y+hy,this},AABB2.prototype.equals=function(other){return!(!this.min.equals(other.min)||!this.max.equals(other.max))},AABB2.prototype.fromJSON=function(json){return this.min.fromJSON(json.min),this.max.fromJSON(json.max),this},AABB2.prototype.toJSON=function(json){return json||(json={}),json.min=this.min.toJSON(json.min),json.max=this.max.toJSON(json.max),json},AABB2.prototype.toString=function(){var min=this.min,max=this.max;return"AABB2( min: "+min+", max: "+max+" )"},AABB2}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/phys2d/objects/p2shape",["odin/base/class","odin/math/vec2","odin/math/mat32","odin/math/aabb2"],function(Class,Vec2,Mat32,AABB2){function P2Shape(opts){opts||(opts={}),Class.call(this),this.type=-1,this.body=void 0,this.density=void 0!=opts.density?opts.density:1,this.localPosition=void 0!=opts.position?opts.position:new Vec2,this.localRotation=void 0!=opts.rotation?opts.rotation:0,this.position=new Vec2,this.rotation=0,this.matrix=new Mat32,this.matrixWorld=new Mat32,this.friction=void 0!=opts.friction?opts.friction:.5,this.elasticity=void 0!=opts.elasticity?opts.elasticity:.25,this.isTrigger=void 0!=opts.isTrigger?!!opts.isTrigger:!1,this.filterMask=void 0!=opts.filterMask?opts.filterMask:1,this.filterGroup=void 0!=opts.filterGroup?opts.filterGroup:1,this.aabb=new AABB2}return Class.extend(P2Shape),P2Shape.prototype.copy=function(other){return this.density=other.density,this.localPosition.copy(other.localPosition),this.localRotation=other.localRotation,this.friction=other.friction,this.elasticity=other.elasticity,this.isTrigger=other.isTrigger,this.filterMask=other.filterMask,this.filterGroup=other.filterGroup,this},P2Shape.prototype.toJSON=function(json){return json=Class.prototype.toJSON.call(this,json),json.density=this.density,json.localPosition=this.localPosition.toJSON(json.localPosition),json.localRotation=this.localRotation,json.friction=this.friction,json.elasticity=this.elasticity,json.isTrigger=this.isTrigger,json.filterMask=this.filterMask,json.filterGroup=this.filterGroup,json},P2Shape.prototype.fromJSON=function(json){return Class.prototype.fromJSON.call(this,json),this.density=json.density,this.localPosition.fromJSON(json.localPosition),this.localRotation=json.localRotation,this.friction=json.friction,this.elasticity=json.elasticity,this.isTrigger=json.isTrigger,this.filterMask=json.filterMask,this.filterGroup=json.filterGroup,this},P2Shape}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/phys2d/objects/p2circle",["odin/base/class","odin/phys2d/p2enums","odin/phys2d/objects/p2shape"],function(Class,P2Enums,P2Shape){function P2Circle(opts){opts||(opts={}),P2Shape.call(this,opts),this.type=ShapeType.Circle,this.radius=void 0!=opts.radius?abs(opts.radius):.5}var ShapeType=P2Enums.ShapeType,abs=Math.abs,PI=Math.PI;return P2Shape.extend(P2Circle),P2Circle.prototype.copy=function(other){return P2Shape.prototype.copy.call(this,other),this.radius=other.radius,this},P2Circle.prototype.pointQuery=function(p){var x=this.position,dx=x.x-p.x,dy=x.y-p.y,r=this.radius;return r*r>dx*dx+dy*dy},P2Circle.prototype.centroid=function(v){var localPos=this.localPosition;return v.x=localPos.x,v.y=localPos.y,v},P2Circle.prototype.area=function(){var r=this.radius;return PI*r*r},P2Circle.prototype.inertia=function(mass){var r=this.radius,localPos=this.localPosition,lx=localPos.x,ly=localPos.y;return mass*(r*r*.5+(lx*lx+ly*ly))},P2Circle.prototype.update=function(matrix){var x,y,localMatrix=this.matrix,matrixWorld=this.matrixWorld,localPos=this.localPosition,pos=this.position,r=this.radius,aabb=this.aabb,min=aabb.min,max=aabb.max;localMatrix.setRotation(this.localRotation),localMatrix.setPosition(localPos),matrixWorld.mmul(matrix,localMatrix),pos.x=localPos.x,pos.y=localPos.y,pos.transformMat32(matrix),x=pos.x,y=pos.y,min.x=x-r,min.y=y-r,max.x=x+r,max.y=y+r},P2Circle.prototype.toJSON=function(json){return json=P2Shape.prototype.toJSON.call(this,json),json.radius=this.radius,json},P2Circle.prototype.fromJSON=function(json){return P2Shape.prototype.fromJSON.call(this,json),this.radius=json.radius,this},P2Circle}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/core/game/config",[],function(){function Config(){this.debug=!1,this.forceCanvas=!1,this.host="127.0.0.1",this.port=3e3,this.FAKE_LAG=0,this.SCENE_SYNC_RATE=.5,this.MAX_SCENE_STATES=5,this.MIN_DELTA=1e-6,this.MAX_DELTA=1}return Config.prototype.fromJSON=function(json){for(var key in json){void 0!=this[key]&&(this[key]=json[key])}return this},new Config}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/core/game/log",["odin/base/util","odin/core/game/config"],function(util,Config){function Log(){}function cacheKey(args){var i,key="";for(i=args.length;i--;){key+=args[i]}return key}var CACHE,each=util.each;return Log.prototype.debug=Log.prototype.info=Log.prototype.log=function(){Config.debug&&console.log.apply(console,arguments)},Log.prototype.warn=function(){(Config.debug||Config.warn)&&console.warn.apply(console,arguments)},Log.prototype.error=function(){(Config.debug||Config.error)&&console.error.apply(console,arguments)},CACHE={},Log.prototype.once=function(){!Config.debug&&!Config.error||CACHE[cacheKey(arguments)]||(CACHE[cacheKey(arguments)]=!0,console.error.apply(console,arguments))},Log.prototype.object=function(obj,values){if(!Config.debug){return""}var str="";return values||(values=[]),each(obj,function(value,i){if(!~values.indexOf(value)){var type=typeof value;"object"===type?(values.push(value),str+=" "+i+" = "+this.object(value,values)):"function"!==type?str+=" "+i+" = "+value+"\n":values.push(value)}},this),str},new Log}),"function"!=typeof define&&(define=require("amdefine")(module)),define("odin/phys2d/objects/p2convex",["odin/math/vec2","odin/core/game/log","odin/phys2d/p2enums","odin/phys2d/objects/p2shape"],function(Vec2,Log,P2Enums,P2Shape){function P2Convex(opts){opts||(opts={}),P2Shape.call(this,opts),this.type=ShapeType.Convex,this.vertices=void 0!=opts.vertices?opts.vertices:[new Vec2(.5,.5),new Vec2(-.5,.5),new Vec2(-.5,-.5),new Vec2(.5,-.5)],P2Convex.validateVertices(this.vertices)||(log.warn("P2Convex.constructor: passed vertices are invalid, creating convex hull from vertices with gift wrapping algorithm"),this.vertices=P2Convex.createConvexHull(this.vertices)),this.normals=[],this._vertices=[],this._normals=[];var v1,v2,i,vertices=this.vertices,wverts=this._vertices,normals=this.normals,wnorms=this._normals;for(i=vertices.length;i--;){v1=vertices[i],v2=vertices[i+1]||vertices[0],normals[i]=new Vec2(v2.y-v1.y,-(v2.x-v1.x)).normalize(),wverts[i]=new Vec2(v1),wnorms[i]=new Vec2(normals[i])}}var ShapeType=P2Enums.ShapeType;return P2Shape.extend(P2Convex),P2Convex.prototype.copy=function(other){P2Shape.prototype.copy.call(this,other);var i,vertices=other.vertices,normals=other.normals;for(this.vertices.length=this.normals.length=this._vertices.length=this._normals.length=0,i=vertices.length;i--;){this.vertices[i]=vertices[i].clone()}for(i=normals.length;i--;){this.normals[i]=normals[i].clone()}return this},P2Convex.prototype.pointQuery=function(p){if(!this.aabb.contains(p)){return!1}var n,nx,ny,v,vx,vy,i,vertices=this._vertices,normals=this._normals,px=p.x,py=p.y;for(i=vertices.length;i--;){if(n=normals[i],nx=n.x,ny=n.y,v=vertices[i],vx=v.x,vy=v.y,nx*px+ny*py-(nx*vx+ny*vy)>0){return!1}}return!0},P2Convex.prototype.centroid=function(){var v1=new Vec2,v2=new Vec2,vsum=new Vec2;return function(v){var v1x,v1y,v2x,v2y,cross,i,localPosition=this.localPosition,vertices=this.vertices,len=vertices.length,area=0;for(vsum.x=vsum.y=0,i=len;i--;){v1.vadd(localPosition,vertices[i]),v2.vadd(localPosition,vertices[(i+1)%len]),v1x=v1.x,v1y=v1.y,v2x=v2.x,v2y=v2.y,cross=v1x*v2y-v1y*v2x,area+=cross,vsum.x+=(v1x+v2x)*cross,vsum.y+=(v1y+v2y)*cross}return v.copy(vsum).smul(1/(3*area))}}(),P2Convex.prototype.area=function(){var v1,v2,i,vertices=this.vertices,len=vertices.length,area=0;for(i=len;i--;){v1=vertices[i],v2=vertices[(i+1)%len],area+=v1.x*v2.y-v1.y*v2.x}return.5*area},P2Convex.prototype.inertia=function(){var v1=new Vec2,v2=new Vec2;return function(mass){var v1x,v1y,v2x,v2y,i,localPosition=this.localPosition,vertices=this.vertices,len=vertices.length,a=0,b=0,sum1=0,sum2=0;for(i=len;i--;){v1.vadd(localPosition,vertices[i]),v2.vadd(localPosition,vertices[(i+1)%len]),v1x=v1.x,v1y=v1.y,v2x=v2.x,v2y=v2.y,a=v2x*v1y-v2y*v1x,b=v1x*v1x+v1y*v1y+(v1x*v2x+v1y*v2y)+(v2x*v2x+v2y*v2y),sum1+=a*b,sum2+=a}return mass*sum1/(6*sum2)}}(),P2Convex.prototype.update=function(matrix){var wnorm,wvert,x,y,i,localMatrix=this.matrix,matrixWorld=this.matrixWorld,localPos=this.localPosition,vertices=this.vertices,normals=this.normals,pos=this.position,aabb=this.aabb,min=aabb.min,max=aabb.max,minx=1/0,miny=1/0,maxx=-1/0,maxy=-1/0,wnorms=this._normals,wverts=this._vertices;for(localMatrix.setRotation(this.localRotation),localMatrix.setPosition(localPos),matrixWorld.mmul(matrix,localMatrix),pos.x=localPos.x,pos.y=localPos.y,pos.transformMat32(matrix),i=vertices.length;i--;){wvert=wverts[i]||(wverts[i]=new Vec2),wnorm=wnorms[i]||(wnorms[i]=new Vec2),wnorm.copy(normals[i]).transformMat2(matrixWorld),wvert.copy(vertices[i]).transformMat32(matrixWorld),x=wvert.x,y=wvert.y,minx=minx>x?x:minx,miny=miny>y?y:miny,maxx=x>maxx?x:maxx,maxy=y>maxy?y:maxy}min.x=minx,min.y=miny,max.x=maxx,max.y=maxy},P2Convex.prototype.toJSON=function(json){json=P2Shape.prototype.toJSON.call(this,json);var i,vertices=this.vertices,normals=this.normals,jsonVertices=json.vertices||(json.vertices=[]),jsonNormals=json.normals||(json.normals=[]);for(i=vertices.length;i--;){jsonVertices[i]=vert