diff --git a/public/static/audio/main.mp3 b/public/static/audio/main.mp3 new file mode 100644 index 0000000..42cde16 Binary files /dev/null and b/public/static/audio/main.mp3 differ diff --git a/public/static/js/lib/domeventslevel3.shim.min.js b/public/static/js/lib/domeventslevel3.shim.min.js new file mode 100644 index 0000000..02db92a --- /dev/null +++ b/public/static/js/lib/domeventslevel3.shim.min.js @@ -0,0 +1,22 @@ +/* DOM Keyboard Event Level 3 polyfill | @version 0.4.4 | MIT License | github.com/termi */ +void function(){"use strict"; +var f=void 0,h=!0,j=null,k=!1,l;try{l="a"==(new this.KeyboardEvent("keyup",{key:"a"})).key}catch(aa){l=k} +if(!l){var x=function(a,b){var c;try{c=document.createEvent("KeyboardEvent")}catch(d){c=document.createEvent("Event")}b=b||{};var e={},n,g;for(n in m)p(m,n)&&(e[n]=n in b&&(g=b[n])!==f?g:m[n]);g=e.ctrlKey||k;var q=e.shiftKey||k,r=e.altKey||k,L=e.metaKey||k,S=e.altGraphKey||k,T=3b&&(64Y.h&&(z[107]=z[61],A[109]=A[173]))}var ca={Escape:j,Win:j,Scroll:j,Apps:j,Delete:j,Window:j,ContextMenu:j,Mul:j};x.DOM_KEY_LOCATION_STANDARD=0;x.DOM_KEY_LOCATION_LEFT=ha;x.DOM_KEY_LOCATION_RIGHT=ia;x.DOM_KEY_LOCATION_NUMPAD= +I;x.DOM_KEY_LOCATION_MOBILE=ja;x.DOM_KEY_LOCATION_JOYSTICK=ka;x.prototype=J;$=new x("keyup");try{delete $.keyCode,w($,"keyCode",{writable:h,value:9}),delete $.which,w($,"which",{writable:h,value:9})}catch(va){}ea=9===$.which;!(t=9==$.keyCode)&&N?(w(J,"keyCode",{enumerable:h,configurable:h,get:function(){return"__keyCode"in this?this.__keyCode:N.call(this)},set:function(a){return this.__keyCode=isNaN(a)?0:a}}),w(J,"charCode",{enumerable:h,configurable:h,get:function(){return"__charCode"in this?this.__charCode: +N.call(this)},set:function(a){return this.__charCode=isNaN(a)?0:a}})):N=f;sa=function(a){a=a||"";if(1b&&b;return(b&&String.fromCharCode(b)||a).toLowerCase()};w(J,"key",{enumerable:h,configurable:h,get:function(){var a;if(G&&((a=G.call(this))&&2>a.length||y(a)))return sa.call(this,a);if("__key"in this)return this.__key;if(this.type in na){var b= +this.which||this.keyCode,c="keypress"!=this.type;a=c?"keyIdentifier"in this&&y(this.keyIdentifier)?this.keyIdentifier:!c||(a=z[b])?((a=a||A[b])&&"object"==typeof a?a.a:a)||this["char"]:sa.call(this,a):this["char"];X.value=a;w(this,"__key",X);return a}}});w(J,"char",{enumerable:h,configurable:h,get:function(){if(this.type in na){if(this.ctrlKey||this.altKey||this.metaKey)return"";if("__char"in this)return this.__char;var a,b="keypress"!=this.type,c=!b&&this.__keyCode||this.which||this.keyCode,d;if(b&& +(a=z[c])&&"object"!=typeof a)return"";if(!(K&&(a=K.call(this))!==j))d=(a=A[c]||z[c])&&"object"==typeof a,!d||a.b===k?a="":d&&a.b!==f?a=a.b||"":"keyIdentifier"in this&&y(this.keyIdentifier)?a="":(a=String.fromCharCode(c),b&&!this.shiftKey&&(a=a.toLowerCase()));X.value=a;w(this,"__char",X);return a}}});F=function(){if(ma)return ma.call(this);if("__location"in this)return this.__location;if(this.type in na){var a=this.which||this.keyCode,b="keypress"!=this.type;"keyLocation"in this?a=this.keyLocation: +(a=b&&(z[a]||A[a]),a="object"==typeof a&&a.c||0);X.value=a;w(this,"__location",X);return a}};w(J,"location",{enumerable:h,configurable:h,get:F});K?document.addEventListener("keydown",function(a){var b=K?K.call(a):a["char"],b=b&&b.charCodeAt(0),c,d;if(b&&!A[b+=999])c=A[b]={},a=a.keyCode,b=(d=A[a])?"object"==typeof d&&d.a||d:String.fromCharCode(a),64a&&a)&&(b=b.toLowerCase()),c.a=b},h):[($=u.Document)&&$.prototype||u.document,($=u.HTMLDocument)&&$.prototype,($=u.Window)&&$.prototype||u,($=u.Node)&& +$.prototype,($=u.Element)&&$.prototype].forEach(function(a){if(a&&p(a,"addEventListener")){var b=a.addEventListener,c=a.removeEventListener;b&&(a.addEventListener=function(a,c,n){var g,q,r;if("keydown"===(a+"").toLowerCase()){g="_e_8vj"+(n?"-":"")+a;q=g+(c._h_9e2||(c._h_9e2=++oa));r=g+"__count";if(!(g=this._))g=this._={};if(q in g)return;g[r]===f&&b.call(this,"keypress",ga,h);g[r]=(g[r]||0)+1;arguments[1]=g[q]=qa.call(da,{f:c,g:this})}return b.apply(this,arguments)},c&&(a.removeEventListener=function(a, +b,n){var g,q,r;"keydown"===(a+"").toLowerCase()&&(g="_e_8vj"+(n?"-":"")+a,q=g+b._h_9e2,r=g+"__count",g=this._,q&&(g&&g[r])&&(--g[r],(arguments[1]=g[q])&&delete g[q]));return c.apply(this,arguments)}))}});u.KeyboardEvent=x;ha=ia=I=ja=ka=O=P=$=R=x=J=Z=la=ua=Y=j;f}; +}.call(this); diff --git a/public/static/js/wingbase/gui/chat.js b/public/static/js/wingbase/gui/chat.js index 6be3b81..d8bbb9a 100644 --- a/public/static/js/wingbase/gui/chat.js +++ b/public/static/js/wingbase/gui/chat.js @@ -44,9 +44,10 @@ GUI.prototype.Chat = class { } tick() { - if (game.input.keys.pressed[13] || game.input.keys.pressed[27]) { + let keys = game.input.keys; + if (keys.pressed['Enter'] || keys.pressed['Esc']) { if (this.typing) { - if (game.input.keys.pressed[13]) { + if (keys.pressed['Enter']) { let message = this.inputElement.value; this.inputElement.value = ''; if (message[0] == '/') { diff --git a/public/static/js/wingbase/input.js b/public/static/js/wingbase/input.js index 3df8479..f26a3de 100644 --- a/public/static/js/wingbase/input.js +++ b/public/static/js/wingbase/input.js @@ -53,19 +53,19 @@ class Input { keyDown() { if (this.locked) { - if (event.which == '13' || event.which == '27') { - this.keys.pressed[event.which] = true; + if (event.key == 'Esc' || event.key == 'Enter') { + this.keys.pressed[event.key] = true; } return; } - if (!this.keys.held[event.which]) - this.keys.pressed[event.which] = true; - this.keys.held[event.which] = true; + if (!this.keys.held[event.ket]) + this.keys.pressed[event.key] = true; + this.keys.held[event.key] = true; } keyUp() { if (this.locked) return; - this.keys.held[event.which] = false; + this.keys.held[event.key] = false; } mouseAnyPressed() { diff --git a/public/static/js/wingbase/player.js b/public/static/js/wingbase/player.js index f964c15..343b81a 100644 --- a/public/static/js/wingbase/player.js +++ b/public/static/js/wingbase/player.js @@ -5,13 +5,15 @@ class Player { this.ship = ship; this.lastInputs = []; + + this.interface = []; } packDelta() { // W, A, D, Space - let inputs = [87, 65, 68]; + let inputs = ['w', 'a', 'd']; inputs = inputs.map(k => game.input.keys.held[k] || false); - inputs[3] = game.input.keys.pressed[32] || false; + inputs[3] = game.input.keys.pressed['Spacebar'] || false; inputs[4] = game.input.mouse.wx; inputs[5] = game.input.mouse.wy; inputs[6] = game.input.mouse.held[3]; diff --git a/public/static/js/wingbase/render/render.js b/public/static/js/wingbase/render/render.js index de421cb..533181d 100644 --- a/public/static/js/wingbase/render/render.js +++ b/public/static/js/wingbase/render/render.js @@ -37,7 +37,7 @@ class Renderer { this.pallet.fill('#020202'); this.context.save(); - + this.context.beginPath(); this.context.rect(0, 0, cw, ch); this.context.clip(); diff --git a/public/views/game.jade b/public/views/game.jade index 3872800..3973b8f 100644 --- a/public/views/game.jade +++ b/public/views/game.jade @@ -3,11 +3,12 @@ extends layout.jade block head title | Wingbase - script(src="js/lib/dexie.min.js") - script(src="socket.io/socket.io.js") - script(src="js/lib/box2dweb.min.js") - script(src="https://rawgit.com/Asraelite/pallet.js/master/pallet.js") - script(src="wingbase.min.js") + script(src='js/lib/dexie.min.js') + script(src='js/lib/domeventslevel3.shim.min.js') + script(src='socket.io/socket.io.js') + script(src='js/lib/box2dweb.min.js') + script(src='https://rawgit.com/Asraelite/pallet.js/master/pallet.js') + script(src='wingbase.min.js') block body canvas#wingbase_canvas diff --git a/server/game/player.js b/server/game/player.js index 1de71d9..223d8cb 100644 --- a/server/game/player.js +++ b/server/game/player.js @@ -14,6 +14,12 @@ class Player { this.delta = []; this.chatCooldown = 0; + + this.inputInterface = [ + 'thrust', + 'aim', + 'fire' + ]; } disconnect() { diff --git a/server/game/room/index.js b/server/game/room/index.js index abd44eb..c85d3c9 100644 --- a/server/game/room/index.js +++ b/server/game/room/index.js @@ -115,6 +115,7 @@ class Room { sendWorld(player) { let data = { playerShipId: player.ship.id, + inputInterface: player.inputInterface, bounds: this.world.bounds, tps: this.tps, bodies: Array.from(this.world.bodies).map(b => b.packFull())