reorder and rename hardpoints and particles
This commit is contained in:
parent
d302bd4149
commit
ea533015ba
16 changed files with 65 additions and 64 deletions
9
server/game/room/world/body/bay/bay.js
Normal file
9
server/game/room/world/body/bay/bay.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
class Bay {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Bay;
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const uuid = require('uuid');
|
||||
|
||||
const Mount = require('./turret/mount.js');
|
||||
const Hardpoint = require('./hardpoint/hardpoint.js');
|
||||
|
||||
const b2Vec2 = require('box2d-html5').b2Vec2;
|
||||
|
||||
|
@ -21,12 +21,12 @@ class Body {
|
|||
this.r = data.r || 0;
|
||||
this.rvel = data.rvel || 0;
|
||||
|
||||
this.mounts = data.mounts || [];
|
||||
this.hardpoints = data.hardpoints || [];
|
||||
this.fixtures = data.fixtures || [];
|
||||
this.health = data.health || 1;
|
||||
this.mounts = this.mounts.map((m, i) => {
|
||||
this.hardpoints = this.hardpoints.map((m, i) => {
|
||||
let fixture = this.fixtures[i];
|
||||
return new Mount(this, m, fixture);
|
||||
return new Hardpoint(this, m, fixture);
|
||||
});
|
||||
|
||||
this.interface = {
|
||||
|
@ -44,7 +44,7 @@ class Body {
|
|||
'angle',
|
||||
'state'
|
||||
],
|
||||
num: this.mounts.length
|
||||
num: this.hardpoints.length
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -52,7 +52,7 @@ class Body {
|
|||
}
|
||||
|
||||
destruct() {
|
||||
this.mounts.forEach(mount => mount.destruct());
|
||||
this.hardpoints.forEach(hardpoint => hardpoint.destruct());
|
||||
this.world.physics.remove(this);
|
||||
|
||||
this.destructType();
|
||||
|
@ -113,7 +113,7 @@ class Body {
|
|||
if(pos.y < bounds.top) this.applyForce(0, 0.03);
|
||||
if(pos.y > bounds.bottom) this.applyForce(-0, -0.03);
|
||||
|
||||
this.mounts.forEach(m => m.tick());
|
||||
this.hardpoints.forEach(m => m.tick());
|
||||
|
||||
this.sleepTime++;
|
||||
|
||||
|
@ -129,7 +129,7 @@ class Body {
|
|||
|
||||
let values = [this.id, pos.x, pos.y, vel.x, vel.y, pos.r, vel.r];
|
||||
values = values.concat(this.packTypeDelta());
|
||||
this.mounts.forEach(m => [].push.apply(values, m.packDelta()));
|
||||
this.hardpoints.forEach(m => [].push.apply(values, m.packDelta()));
|
||||
|
||||
return values;
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ class Body {
|
|||
class: this.class,
|
||||
id: this.id,
|
||||
frame: this.frame,
|
||||
fixtures: this.mounts.map(m => m.packFull()),
|
||||
fixtures: this.hardpoints.map(m => m.packFull()),
|
||||
delta: this.packDelta(),
|
||||
interface: this.interface
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const Fixture = require('./fixture.js');
|
||||
const Laser = require('./discharge/laser.js');
|
||||
const Laser = require('../../particle/laser.js');
|
||||
|
||||
class Blaster extends Fixture {
|
||||
constructor(mount, data) {
|
|
@ -5,7 +5,7 @@ const Grapple = require('./grapple.js');
|
|||
|
||||
const traits = require('../../traits/fixtures.json');
|
||||
|
||||
class Mount {
|
||||
class Hardpoint {
|
||||
constructor(body, data, fixture) {
|
||||
this.body = body;
|
||||
|
||||
|
@ -84,4 +84,4 @@ class Mount {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = Mount;
|
||||
module.exports = Hardpoint;
|
|
@ -62,7 +62,7 @@ class Ship extends Body {
|
|||
this.thrust.right = packet.thrust[2];
|
||||
|
||||
packet.fire.forEach((m, i) => {
|
||||
m ? this.mounts[i].fire(m) : this.mounts[i].rest();
|
||||
m ? this.hardpoints[i].fire(m) : this.hardpoints[i].rest();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const Discharge = require('./discharge.js');
|
||||
|
||||
class Beam extends Discharge {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Beam;
|
|
@ -1,11 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const Discharge = require('./discharge.js');
|
||||
|
||||
class Bullet extends Discharge {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Bullet;
|
|
@ -11,7 +11,7 @@ class World {
|
|||
this.physics = new Physics();
|
||||
this.spawner = new Spawner(this);
|
||||
this.bodies = new Set();
|
||||
this.discharges = new Set();
|
||||
this.particles = new Set();
|
||||
this.asteroids = new Set();
|
||||
this.copulae = new Set();
|
||||
this.players = new Set();
|
||||
|
@ -66,9 +66,9 @@ class World {
|
|||
projectile.connect();
|
||||
}
|
||||
|
||||
addDischarge(discharge) {
|
||||
this.discharges.add(discharge);
|
||||
this.room.broadcast('create', discharge.packFull());
|
||||
addParticle(particle) {
|
||||
this.particles.add(particle);
|
||||
this.room.broadcast('create', particle.packFull());
|
||||
}
|
||||
|
||||
addBody(body) {
|
||||
|
@ -149,9 +149,9 @@ class World {
|
|||
this.room.broadcast('destroy', copula.id);
|
||||
}
|
||||
|
||||
removeDischarge(discharge) {
|
||||
this.discharges.delete(discharge);
|
||||
this.room.broadcast('destroy', discharge.id);
|
||||
removeParticle(particle) {
|
||||
this.particles.delete(particle);
|
||||
this.room.broadcast('destroy', particle.id);
|
||||
}
|
||||
|
||||
weld(bodyA, bodyB, point) {
|
||||
|
@ -187,7 +187,7 @@ class World {
|
|||
tickBodies(this.asteroids, 1, 100);
|
||||
tickBodies(this.projectiles, 1);
|
||||
|
||||
this.discharges.forEach(d => d.tick());
|
||||
this.particles.forEach(d => d.tick());
|
||||
|
||||
if (Date.now() - this.tpsStart > 5000) {
|
||||
this.tps = this.tpsCount / 5 | 0;
|
||||
|
|
11
server/game/room/world/particle/beam.js
Normal file
11
server/game/room/world/particle/beam.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
const Particle = require('./particle.js');
|
||||
|
||||
class Beam extends Particle {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Beam;
|
11
server/game/room/world/particle/bullet.js
Normal file
11
server/game/room/world/particle/bullet.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
const Particle = require('./particle.js');
|
||||
|
||||
class Bullet extends Particle {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Bullet;
|
|
@ -1,8 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
const Discharge = require('./discharge.js');
|
||||
const Particle = require('./particle.js');
|
||||
|
||||
class Laser extends Discharge {
|
||||
class Laser extends Particle {
|
||||
constructor(fixture, data) {
|
||||
super(fixture, data);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
class Discharge {
|
||||
class Particle {
|
||||
constructor(fixture, data) {
|
||||
this.x = data.x;
|
||||
this.y = data.y;
|
||||
|
@ -17,7 +17,7 @@ class Discharge {
|
|||
}
|
||||
|
||||
destroy() {
|
||||
this.world.removeDischarge(this);
|
||||
this.world.removeParticle(this);
|
||||
}
|
||||
|
||||
contact(body, point) {
|
||||
|
@ -31,7 +31,7 @@ class Discharge {
|
|||
}
|
||||
|
||||
packDelta() {
|
||||
// TODO: Implement some sort of delta interface for discharges that is
|
||||
// TODO: Implement some sort of delta interface for particles that is
|
||||
// derived from the fixture so it's efficient.
|
||||
return [this.id, this.x, this.y];
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class Discharge {
|
|||
// TODO: Create creation interface using fixture then send this as
|
||||
// an array.
|
||||
return {
|
||||
form: 'discharge',
|
||||
form: 'particle',
|
||||
id: this.id,
|
||||
x: this.x,
|
||||
y: this.y,
|
||||
|
@ -52,28 +52,20 @@ class Discharge {
|
|||
}
|
||||
|
||||
tick() {
|
||||
let start = {
|
||||
x: this.x,
|
||||
y: this.y
|
||||
};
|
||||
let start = { x: this.x, y: this.y };
|
||||
|
||||
this.x += this.xvel;
|
||||
this.y += this.yvel
|
||||
|
||||
let end = {
|
||||
x: this.x,
|
||||
y: this.y
|
||||
};
|
||||
|
||||
let end = { x: this.x, y: this.y };
|
||||
let contact = this.world.physics.raycast(start, end);
|
||||
|
||||
if (contact) {
|
||||
if (contact)
|
||||
this.contact(contact.body, contact.point);
|
||||
}
|
||||
|
||||
if (this.lifetime-- <= 0)
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Discharge;
|
||||
module.exports = Particle;
|
|
@ -3,7 +3,7 @@
|
|||
const Asteroid = require('./body/asteroid.js');
|
||||
const Grapple = require('./body/projectile/grapple.js');
|
||||
const Missile = require('./body/projectile/missile.js');
|
||||
const Laser = require('./body/turret/discharge/laser.js');
|
||||
const Laser = require('./particle/laser.js');
|
||||
const Ship = require('./body/ship.js');
|
||||
|
||||
class Spawner {
|
||||
|
@ -93,7 +93,7 @@ class Spawner {
|
|||
yvel: fixture.body.vel.y + vy
|
||||
};
|
||||
let laser = new Laser(fixture, pos);
|
||||
this.world.addDischarge(laser);
|
||||
this.world.addParticle(laser);
|
||||
return laser;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
[3, 1]
|
||||
]
|
||||
],
|
||||
"mounts": [
|
||||
"hardpoints": [
|
||||
{
|
||||
"pos": [0.5625, 0.125],
|
||||
"type": "fixed",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue