Add more modules

This commit is contained in:
asraelite 2018-03-07 19:00:03 +00:00
parent 0c63cb075b
commit 504f5fcc0c
18 changed files with 1448 additions and 11 deletions

View file

@ -23,6 +23,7 @@ export default class Ship extends Body {
this.cargoCapacity = 0;
this.thrust = 0;
this.crashed = false;
this.timeWithoutFuel = 0;
}
get com() {
@ -69,6 +70,13 @@ export default class Ship extends Body {
events.launchShip()
}
}
if (this.fuel === 0 && !state.gameOver) {
if (this.timeWithoutFuel++ > 300)
events.outOfFuel();
} else {
this.timeWithoutFuel = 0;
}
}
clearModules() {
@ -116,6 +124,8 @@ export default class Ship extends Body {
this.thrust += m.data.thrust;
} else if (m.type === 'gyroscope') {
this.rotationPower += m.data.rotation;
} else if (m.type === 'cargo') {
this.cargoCapacity += m.data.capacity;
}
});
}

View file

@ -105,10 +105,16 @@ function randomEntity(x, y) {
if (Math.random() > 0.3) {
entity = new Entity(x, y, 'fuelcan');
} else {
let arr = Object.entries(modules);
[type, arr] = arr[Math.random() * arr.length | 0];
arr = Object.keys(arr);
entity = new Entity(x, y, type, arr[Math.random() * arr.length | 0]);
let type, id;
while (true) {
let arr = Object.entries(modules);
[type, arr] = arr[Math.random() * arr.length | 0];
arr = Object.keys(arr);
id = arr[Math.random() * arr.length | 0];
let value = modules[type][id].value;
if (Math.random() < (1 / value)) break;
}
entity = new Entity(x, y, type, id);
}
world.entities.add(entity);