From a2a93882f0e2273527ed2ab09cfba143c89f1d7a Mon Sep 17 00:00:00 2001 From: Asraelite Date: Wed, 30 Mar 2016 09:53:48 +0100 Subject: [PATCH] prevent asteroids from spawning as wedges --- .gitignore | 1 + public/static/js/wingbase/net.js | 3 +-- public/static/js/wingbase/player.js | 29 +++++++++++++++---------- server/game/room/world/body/asteroid.js | 12 +++++++--- server/game/room/world/index.js | 2 +- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index f35317f..c11046e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules/ log/ public/static/css/*.css *.log +*.sh diff --git a/public/static/js/wingbase/net.js b/public/static/js/wingbase/net.js index 932ef36..1b512a6 100644 --- a/public/static/js/wingbase/net.js +++ b/public/static/js/wingbase/net.js @@ -17,14 +17,13 @@ class Net { }); this.socket.on('update', data => { - window.q = data; game.world.update(data); }); this.socket.on('world', data => { game.world.clear(); - console.log(data); game.world.bounds = data.bounds; + game.player.inputInterface = data.inputInterface; for (var b of data.bodies) { game.world.add(b); } diff --git a/public/static/js/wingbase/player.js b/public/static/js/wingbase/player.js index 343b81a..749f3e2 100644 --- a/public/static/js/wingbase/player.js +++ b/public/static/js/wingbase/player.js @@ -4,22 +4,29 @@ class Player { this.team = team; this.ship = ship; - this.lastInputs = []; + this.lastInputs = {}; - this.interface = []; + this.inputInterface = []; } packDelta() { // W, A, D, Space - let inputs = ['w', 'a', 'd']; - inputs = inputs.map(k => game.input.keys.held[k] || 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]; - inputs[7] = game.input.mouse.pressed[1]; - let delta = this.lastInputs == inputs ? false : inputs; - this.lastInputs = inputs; + let input = game.input; + let packet = {}; + + packet.thrust = ['w', 'a', 'd', 's'].map(k => input.keys.held[k] || 0); + packet.fire = input.mouse.pressed[3] ? [1, 1] : [0, 0]; + packet.aim = { + x: input.mouse.wx, + y: input.mouse.wy + }; + packet.missile = input.keys.pressed['Spacebar']; + + packet = this.inputInterface.map(i => packet[i]); + window.q = packet; + + let delta = this.lastInputs == packet ? false : packet; + this.lastInputs = packet; return delta; } } diff --git a/server/game/room/world/body/asteroid.js b/server/game/room/world/body/asteroid.js index 2447199..db6de62 100644 --- a/server/game/room/world/body/asteroid.js +++ b/server/game/room/world/body/asteroid.js @@ -22,9 +22,15 @@ class Asteroid extends Body { randomFrame() { let s = this.size; let l = (Math.random() * 4 + 4) | 0; - let build = Array(l).fill().map(_ => Math.random() * Math.PI * 2); - build = build.sort().map(a => [Math.cos(a) * s, Math.sin(a) * s]); - return [build]; + // Make sure the frame is not a wedge. + do { + var angles = Array(l).fill().map(_ => Math.random() * Math.PI * 2); + let modded = angles.map(a => a % Math.PI); + var max = modded.reduce((a, b) => Math.max(a, b)); + var min = modded.reduce((a, b) => Math.min(a, b)); + } while (max - min < 1) + + return [angles.sort().map(a => [Math.cos(a) * s, Math.sin(a) * s])]; } tickType() { diff --git a/server/game/room/world/index.js b/server/game/room/world/index.js index 81ae6c5..9c2a41e 100644 --- a/server/game/room/world/index.js +++ b/server/game/room/world/index.js @@ -28,7 +28,7 @@ class World { this.bounds = { left: 0, - right: 250, + right: 10, top: 0, bottom: 30 }