neingeist
/
cosmos
Archived
1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

5 lines
57 KiB
JavaScript

/*! Quintus - v0.1.5 - 2013-08-04
* http://html5quintus.com
* Copyright (c) 2013 Pascal Rettig; Licensed MIT, GPLv2 */
var Quintus=function a(b){var c=function(a,b,d){return c.select(a,b,d)};c.select=function(){},c.include=function(b){return c._each(c._normalizeArg(b),function(b){var d=a[b]||b;if(!c._isFunction(d))throw"Invalid Module:"+b;d(c)}),c},c._normalizeArg=function(a){return c._isString(a)&&(a=a.replace(/\s+/g,"").split(",")),c._isArray(a)||(a=[a]),a},c._extend=function(a,b){if(!b)return a;for(var c in b)a[c]=b[c];return a},c._clone=function(a){return c._extend({},a)},c._defaults=function(a,b){if(!b)return a;for(var c in b)void 0===a[c]&&(a[c]=b[c]);return a},c._has=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},c._isString=function(a){return"string"==typeof a},c._isNumber=function(a){return"[object Number]"===Object.prototype.toString.call(a)},c._isFunction=function(a){return"[object Function]"===Object.prototype.toString.call(a)},c._isObject=function(a){return"[object Object]"===Object.prototype.toString.call(a)},c._isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)},c._isUndefined=function(a){return void 0===a},c._popProperty=function(a,b){var c=a[b];return delete a[b],c},c._each=function(a,b,c){if(null!=a)if(a.forEach)a.forEach(b,c);else if(a.length===+a.length)for(var d=0,e=a.length;e>d;d++)b.call(c,a[d],d,a);else for(var f in a)b.call(c,a[f],f,a)},c._invoke=function(a,b,c,d){if(null!=a)for(var e=0,f=a.length;f>e;e++)a[e][b](c,d)},c._detect=function(a,b,c,d,e){var f;if(null!=a){if(a.length===+a.length){for(var g=0,h=a.length;h>g;g++)if(f=b.call(c,a[g],g,d,e))return f;return!1}for(var i in a)if(f=b.call(c,a[i],i,d,e))return f;return!1}},c._map=function(a,b,d){var e=[];return null==a?e:a.map?a.map(b,d):(c._each(a,function(a,c,f){e[e.length]=b.call(d,a,c,f)}),a.length===+a.length&&(e.length=a.length),e)},c._uniq=function(a){a=a.slice().sort();for(var b=[],c=null,d=0;d<a.length;d++)void 0!==a[d]&&c!==a[d]&&b.push(a[d]),c=a[d];return b},c._shuffle=function(a){var b,d=[];return c._each(a,function(a,c){b=Math.floor(Math.random()*(c+1)),d[c]=d[b],d[b]=a}),d},c._keys=Object.keys||function(a){if(c._isObject(a))throw new TypeError("Invalid object");var b=[];for(var d in a)c._has(a,d)&&(b[b.length]=d);return b},c._range=function(a,b,c){c=c||1;for(var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=new Array(d);d>e;)f[e++]=a,a+=c;return f};var d=0;return c._uniqueId=function(){return d++},c.options={imagePath:"images/",audioPath:"audio/",dataPath:"data/",audioSupported:["mp3","ogg"],sound:!0,frameTimeLimit:100},b&&c._extend(c.options,b),c.gameLoop=function(a){return c.lastGameLoopFrame=(new Date).getTime(),c.loop=!0,c._loopFrame=0,c.gameLoopCallbackWrapper=function(){var b=(new Date).getTime();c._loopFrame++,c.loop=window.requestAnimationFrame(c.gameLoopCallbackWrapper);var d=b-c.lastGameLoopFrame;d>c.options.frameTimeLimit&&(d=c.options.frameTimeLimit),a.apply(c,[d/1e3]),c.lastGameLoopFrame=b},window.requestAnimationFrame(c.gameLoopCallbackWrapper),c},c.pauseGame=function(){c.loop&&window.cancelAnimationFrame(c.loop),c.loop=null},c.unpauseGame=function(){c.loop||(c.lastGameLoopFrame=(new Date).getTime(),c.loop=window.requestAnimationFrame(c.gameLoopCallbackWrapper))},function(){var a=!1,b=/xyz/.test(function(){})?/\b_super\b/:/.*/;c.Class=function(){},c.Class.prototype.isA=function(a){return this.className===a},c.Class.extend=function(d,e,f){function g(a,b){return function(){var c=this._super;this._super=i[a];var d=b.apply(this,arguments);return this._super=c,d}}function h(){!a&&this.init&&this.init.apply(this,arguments)}c._isString(d)||(f=e,e=d,d=null);var i=this.prototype,j=this;a=!0;var k=new j;a=!1;for(var l in e)k[l]="function"==typeof e[l]&&"function"==typeof i[l]&&b.test(e[l])?g(l,e[l]):e[l];return h.prototype=k,h.prototype.constructor=h,h.extend=c.Class.extend,f&&c._extend(h,f),d&&(c[d]=h,h.prototype.className=d,h.className=d),h}}(),c.Class.extend("Evented",{on:function(a,b,d){if(c._isArray(a)||-1!==a.indexOf(",")){a=c._normalizeArg(a);for(var e=0;e<a.length;e++)this.on(a[e],b,d)}else d||(d=b,b=null),d||(d=a),c._isString(d)&&(d=(b||this)[d]),this.listeners=this.listeners||{},this.listeners[a]
}}c.restore()},drawCircle:function(b,c,d,e){var f=a.ctx,g=a.joypad;f.save(),f.beginPath(),f.globalAlpha=g.alpha,f.fillStyle=d,f.arc(b,c,e,0,2*Math.PI,!0),f.closePath(),f.fill(),f.restore()},drawJoypad:function(){var b=a.joypad;null!==b.joypadTouch&&(a.input.drawCircle(b.centerX,b.centerY,b.background,b.size),null!==b.x&&a.input.drawCircle(b.x,b.y,b.color,b.center))},drawCanvas:function(){this.touchEnabled&&this.drawButtons(),this.joypadEnabled&&this.drawJoypad()}}),a.input=new a.InputSystem,a.controls=function(b){return a.input.keyboardControls(),b?(a.input.touchControls({controls:[[],[],[],["action","b"],["fire","a"]]}),a.input.joypadControls()):a.input.touchControls(),a},a.component("platformerControls",{defaults:{speed:200,jumpSpeed:-300},added:function(){var b=this.entity.p;a._defaults(b,this.defaults),this.entity.on("step",this,"step"),this.entity.on("bump.bottom",this,"landed"),b.landed=0,b.direction="right"},landed:function(){var a=this.entity.p;a.landed=.2},step:function(b){var c=this.entity.p;a.inputs.left?(c.vx=-c.speed,c.direction="left"):a.inputs.right?(c.direction="right",c.vx=c.speed):c.vx=0,c.landed>0&&(a.inputs.up||a.inputs.action)&&(c.vy=c.jumpSpeed,c.landed=-b),c.landed-=b}}),a.component("stepControls",{added:function(){var a=this.entity.p;a.stepDistance||(a.stepDistance=32),a.stepDelay||(a.stepDelay=.2),a.stepWait=0,this.entity.on("step",this,"step"),this.entity.on("hit",this,"collision")},collision:function(){var a=this.entity.p;a.stepping&&(a.stepping=!1,a.x=a.origX,a.y=a.origY)},step:function(b){var c=this.entity.p;c.stepWait-=b,c.stepping&&(c.x+=c.diffX*b/c.stepDelay,c.y+=c.diffY*b/c.stepDelay),c.stepWait>0||(c.stepping&&(c.x=c.destX,c.y=c.destY),c.stepping=!1,c.diffX=0,c.diffY=0,a.inputs.left?c.diffX=-c.stepDistance:a.inputs.right&&(c.diffX=c.stepDistance),a.inputs.up?c.diffY=-c.stepDistance:a.inputs.down&&(c.diffY=c.stepDistance),(c.diffY||c.diffX)&&(c.stepping=!0,c.origX=c.x,c.origY=c.y,c.destX=c.x+c.diffX,c.destY=c.y+c.diffY,c.stepWait=c.stepDelay))}})},Quintus.Scenes=function(a){a.scenes={},a.stages=[],a.Scene=a.Class.extend({init:function(a,b){this.opts=b||{},this.sceneFunc=a}}),a.scene=function(b,c,d){return void 0===c?a.scenes[b]:(a._isFunction(c)&&(c=new a.Scene(c,d)),a.scenes[b]=c,c)},a._nullContainer={c:{x:0,y:0,angle:0,scale:1},matrix:a.matrix2d()},a.collision=function(){function b(a,b){var c=a[b],d=a[b+1]||a[0];f=-(d[1]-c[1]),g=d[0]-c[0];var e=Math.sqrt(f*f+g*g);e>0&&(f/=e,g/=e)}function c(a){return f*a[0]+g*a[1]}function d(a,d,e){var k,l,m,n,o,p,q,r,s,t,u,v,w,x,y=Number.POSITIVE_INFINITY,z=!1,A=e?j:i;for(h[0]=0,h[1]=0,a.c?w=a.c.points:(w=a.p.points,h[0]+=a.p.x,h[1]+=a.p.y),d.c?x=d.c.points:(x=d.p.points,h[0]+=-d.p.x,h[1]+=-d.p.y),a=a.p,d=d.p,s=0;s<w.length;s++){for(b(w,s),k=c(w[0]),l=k,t=1;t<w.length;t++)r=c(w[t]),k>r&&(k=r),r>l&&(l=r);for(m=c(x[0]),n=m,t=1;t<x.length;t++)r=c(x[t]),m>r&&(m=r),r>n&&(n=r);if(q=c(h),k+=q,l+=q,o=k-n,p=m-l,o>0||p>0)return null;u=-1*(n-k),e&&(u*=-1),v=Math.abs(u),y>v&&(A.distance=u,A.magnitude=v,A.normalX=f,A.normalY=g,A.distance>0&&(A.distance*=-1,A.normalX*=-1,A.normalY*=-1),z=!0,y=v)}return z?A:null}function e(b,c){var e,f,g;return b.p.points||a._generatePoints(b),c.p.points||a._generatePoints(c),a._generateCollisionPoints(b),a._generateCollisionPoints(c),(e=d(b,c))?(f=d(c,b,!0))?(g=f.magnitude<e.magnitude?f:e,0===g.magnitude?!1:(g.separate[0]=g.distance*g.normalX,g.separate[1]=g.distance*g.normalY,g)):!1:!1}var f,g,h=[0,0],i={separate:[]},j={separate:[]};return e}(),a.overlap=function(a,b){var c=a.c||a.p,d=b.c||b.p,e=c.x-c.cx,f=c.y-c.cy,g=d.x-d.cx,h=d.y-d.cy;return!(f+c.h<h||f>h+d.h||e+c.w<g||e>g+d.w)},a.Stage=a.GameObject.extend({defaults:{sort:!1,gridW:400,gridH:400},init:function(b,c){this.scene=b,this.items=[],this.lists={},this.index={},this.removeList=[],this.grid={},this.options=a._extend({},this.defaults),this.scene&&a._extend(this.options,b.opts),c&&a._extend(this.options,c),this.options.sort&&!a._isFunction(this.options.sort)&&(this.options.sort=function(a,b){return(a.p&&a.p.z||-1)-(b.p&&b.p.z||-1)})},destroyed:function(){this.invoke("debind"