prevent asteroids from spawning as wedges

This commit is contained in:
Asraelite 2016-03-30 09:53:48 +01:00
parent 9533184a94
commit a2a93882f0
5 changed files with 30 additions and 17 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ node_modules/
log/ log/
public/static/css/*.css public/static/css/*.css
*.log *.log
*.sh

View file

@ -17,14 +17,13 @@ class Net {
}); });
this.socket.on('update', data => { this.socket.on('update', data => {
window.q = data;
game.world.update(data); game.world.update(data);
}); });
this.socket.on('world', data => { this.socket.on('world', data => {
game.world.clear(); game.world.clear();
console.log(data);
game.world.bounds = data.bounds; game.world.bounds = data.bounds;
game.player.inputInterface = data.inputInterface;
for (var b of data.bodies) { for (var b of data.bodies) {
game.world.add(b); game.world.add(b);
} }

View file

@ -4,22 +4,29 @@ class Player {
this.team = team; this.team = team;
this.ship = ship; this.ship = ship;
this.lastInputs = []; this.lastInputs = {};
this.interface = []; this.inputInterface = [];
} }
packDelta() { packDelta() {
// W, A, D, Space // W, A, D, Space
let inputs = ['w', 'a', 'd']; let input = game.input;
inputs = inputs.map(k => game.input.keys.held[k] || false); let packet = {};
inputs[3] = game.input.keys.pressed['Spacebar'] || false;
inputs[4] = game.input.mouse.wx; packet.thrust = ['w', 'a', 'd', 's'].map(k => input.keys.held[k] || 0);
inputs[5] = game.input.mouse.wy; packet.fire = input.mouse.pressed[3] ? [1, 1] : [0, 0];
inputs[6] = game.input.mouse.held[3]; packet.aim = {
inputs[7] = game.input.mouse.pressed[1]; x: input.mouse.wx,
let delta = this.lastInputs == inputs ? false : inputs; y: input.mouse.wy
this.lastInputs = inputs; };
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; return delta;
} }
} }

View file

@ -22,9 +22,15 @@ class Asteroid extends Body {
randomFrame() { randomFrame() {
let s = this.size; let s = this.size;
let l = (Math.random() * 4 + 4) | 0; let l = (Math.random() * 4 + 4) | 0;
let build = Array(l).fill().map(_ => Math.random() * Math.PI * 2); // Make sure the frame is not a wedge.
build = build.sort().map(a => [Math.cos(a) * s, Math.sin(a) * s]); do {
return [build]; 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() { tickType() {

View file

@ -28,7 +28,7 @@ class World {
this.bounds = { this.bounds = {
left: 0, left: 0,
right: 250, right: 10,
top: 0, top: 0,
bottom: 30 bottom: 30
} }