add lasers

This commit is contained in:
Asraelite 2016-03-30 19:15:06 +01:00
parent cf4e8024af
commit f87aa1446d
31 changed files with 298 additions and 125 deletions

View file

@ -11,6 +11,7 @@ class World {
this.physics = new Physics();
this.spawner = new Spawner(this);
this.bodies = new Set();
this.discharges = new Set();
this.asteroids = new Set();
this.copulae = new Set();
this.players = new Set();
@ -73,6 +74,11 @@ class World {
projectile.connect();
}
addDischarge(discharge) {
this.discharges.add(discharge);
this.room.broadcast('create', discharge.packFull());
}
addBody(body) {
this.bodies.add(body);
if (body.type == 'asteroid') this.asteroids.add(body);
@ -147,6 +153,11 @@ class World {
this.room.broadcast('destroy', copula.id);
}
removeDischarge(discharge) {
this.discharges.delete(discharge);
this.room.broadcast('destroy', discharge.id);
}
weld(bodyA, bodyB, point) {
this.physics.weld(bodyA, bodyB, point);
}
@ -162,18 +173,21 @@ class World {
tick() {
this.physics.step();
let tickBodies = (set, interval, canSleep) => {
let tickBodies = (set, interval, forceInterval) => {
set.forEach(body => {
if (this.tickCount % interval == 0 && body.awake)
let force = this.tickCount % forceInterval == 0;
if ((this.tickCount % interval == 0 && body.awake) || force)
body.applyDelta();
body.tick();
});
};
tickBodies(this.ships, 1);
tickBodies(this.asteroids, 1);
tickBodies(this.asteroids, 1, 100);
tickBodies(this.projectiles, 1);
this.discharges.forEach(d => d.tick());
if (Date.now() - this.tpsStart > 5000) {
this.tps = this.tpsCount / 5 | 0;
this.tpsCount = 0;