prevent asteroids from spawning as wedges
This commit is contained in:
parent
9533184a94
commit
a2a93882f0
5 changed files with 30 additions and 17 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ node_modules/
|
|||
log/
|
||||
public/static/css/*.css
|
||||
*.log
|
||||
*.sh
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -28,7 +28,7 @@ class World {
|
|||
|
||||
this.bounds = {
|
||||
left: 0,
|
||||
right: 250,
|
||||
right: 10,
|
||||
top: 0,
|
||||
bottom: 30
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue