reorder and rename hardpoints and particles

This commit is contained in:
asraelite 2016-10-18 17:35:14 +01:00
parent d302bd4149
commit ea533015ba
16 changed files with 65 additions and 64 deletions

View file

@ -0,0 +1,9 @@
'use strict';
class Bay {
constructor() {
}
}
module.exports = Bay;

View file

@ -2,7 +2,7 @@
const uuid = require('uuid'); const uuid = require('uuid');
const Mount = require('./turret/mount.js'); const Hardpoint = require('./hardpoint/hardpoint.js');
const b2Vec2 = require('box2d-html5').b2Vec2; const b2Vec2 = require('box2d-html5').b2Vec2;
@ -21,12 +21,12 @@ class Body {
this.r = data.r || 0; this.r = data.r || 0;
this.rvel = data.rvel || 0; this.rvel = data.rvel || 0;
this.mounts = data.mounts || []; this.hardpoints = data.hardpoints || [];
this.fixtures = data.fixtures || []; this.fixtures = data.fixtures || [];
this.health = data.health || 1; this.health = data.health || 1;
this.mounts = this.mounts.map((m, i) => { this.hardpoints = this.hardpoints.map((m, i) => {
let fixture = this.fixtures[i]; let fixture = this.fixtures[i];
return new Mount(this, m, fixture); return new Hardpoint(this, m, fixture);
}); });
this.interface = { this.interface = {
@ -44,7 +44,7 @@ class Body {
'angle', 'angle',
'state' 'state'
], ],
num: this.mounts.length num: this.hardpoints.length
} }
}; };
@ -52,7 +52,7 @@ class Body {
} }
destruct() { destruct() {
this.mounts.forEach(mount => mount.destruct()); this.hardpoints.forEach(hardpoint => hardpoint.destruct());
this.world.physics.remove(this); this.world.physics.remove(this);
this.destructType(); this.destructType();
@ -113,7 +113,7 @@ class Body {
if(pos.y < bounds.top) this.applyForce(0, 0.03); if(pos.y < bounds.top) this.applyForce(0, 0.03);
if(pos.y > bounds.bottom) 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++; this.sleepTime++;
@ -129,7 +129,7 @@ class Body {
let values = [this.id, pos.x, pos.y, vel.x, vel.y, pos.r, vel.r]; let values = [this.id, pos.x, pos.y, vel.x, vel.y, pos.r, vel.r];
values = values.concat(this.packTypeDelta()); 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; return values;
} }
@ -145,7 +145,7 @@ class Body {
class: this.class, class: this.class,
id: this.id, id: this.id,
frame: this.frame, frame: this.frame,
fixtures: this.mounts.map(m => m.packFull()), fixtures: this.hardpoints.map(m => m.packFull()),
delta: this.packDelta(), delta: this.packDelta(),
interface: this.interface interface: this.interface
}; };

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
const Fixture = require('./fixture.js'); const Fixture = require('./fixture.js');
const Laser = require('./discharge/laser.js'); const Laser = require('../../particle/laser.js');
class Blaster extends Fixture { class Blaster extends Fixture {
constructor(mount, data) { constructor(mount, data) {

View file

@ -5,7 +5,7 @@ const Grapple = require('./grapple.js');
const traits = require('../../traits/fixtures.json'); const traits = require('../../traits/fixtures.json');
class Mount { class Hardpoint {
constructor(body, data, fixture) { constructor(body, data, fixture) {
this.body = body; this.body = body;
@ -84,4 +84,4 @@ class Mount {
} }
} }
module.exports = Mount; module.exports = Hardpoint;

View file

@ -62,7 +62,7 @@ class Ship extends Body {
this.thrust.right = packet.thrust[2]; this.thrust.right = packet.thrust[2];
packet.fire.forEach((m, i) => { 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();
}); });
} }

View file

@ -1,11 +0,0 @@
'use strict';
const Discharge = require('./discharge.js');
class Beam extends Discharge {
constructor() {
super();
}
}
module.exports = Beam;

View file

@ -1,11 +0,0 @@
'use strict';
const Discharge = require('./discharge.js');
class Bullet extends Discharge {
constructor() {
super();
}
}
module.exports = Bullet;

View file

@ -11,7 +11,7 @@ class World {
this.physics = new Physics(); this.physics = new Physics();
this.spawner = new Spawner(this); this.spawner = new Spawner(this);
this.bodies = new Set(); this.bodies = new Set();
this.discharges = new Set(); this.particles = new Set();
this.asteroids = new Set(); this.asteroids = new Set();
this.copulae = new Set(); this.copulae = new Set();
this.players = new Set(); this.players = new Set();
@ -66,9 +66,9 @@ class World {
projectile.connect(); projectile.connect();
} }
addDischarge(discharge) { addParticle(particle) {
this.discharges.add(discharge); this.particles.add(particle);
this.room.broadcast('create', discharge.packFull()); this.room.broadcast('create', particle.packFull());
} }
addBody(body) { addBody(body) {
@ -149,9 +149,9 @@ class World {
this.room.broadcast('destroy', copula.id); this.room.broadcast('destroy', copula.id);
} }
removeDischarge(discharge) { removeParticle(particle) {
this.discharges.delete(discharge); this.particles.delete(particle);
this.room.broadcast('destroy', discharge.id); this.room.broadcast('destroy', particle.id);
} }
weld(bodyA, bodyB, point) { weld(bodyA, bodyB, point) {
@ -187,7 +187,7 @@ class World {
tickBodies(this.asteroids, 1, 100); tickBodies(this.asteroids, 1, 100);
tickBodies(this.projectiles, 1); tickBodies(this.projectiles, 1);
this.discharges.forEach(d => d.tick()); this.particles.forEach(d => d.tick());
if (Date.now() - this.tpsStart > 5000) { if (Date.now() - this.tpsStart > 5000) {
this.tps = this.tpsCount / 5 | 0; this.tps = this.tpsCount / 5 | 0;

View file

@ -0,0 +1,11 @@
'use strict';
const Particle = require('./particle.js');
class Beam extends Particle {
constructor() {
super();
}
}
module.exports = Beam;

View file

@ -0,0 +1,11 @@
'use strict';
const Particle = require('./particle.js');
class Bullet extends Particle {
constructor() {
super();
}
}
module.exports = Bullet;

View file

@ -1,8 +1,8 @@
'use strict'; 'use strict';
const Discharge = require('./discharge.js'); const Particle = require('./particle.js');
class Laser extends Discharge { class Laser extends Particle {
constructor(fixture, data) { constructor(fixture, data) {
super(fixture, data); super(fixture, data);
} }

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
class Discharge { class Particle {
constructor(fixture, data) { constructor(fixture, data) {
this.x = data.x; this.x = data.x;
this.y = data.y; this.y = data.y;
@ -17,7 +17,7 @@ class Discharge {
} }
destroy() { destroy() {
this.world.removeDischarge(this); this.world.removeParticle(this);
} }
contact(body, point) { contact(body, point) {
@ -31,7 +31,7 @@ class Discharge {
} }
packDelta() { 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. // derived from the fixture so it's efficient.
return [this.id, this.x, this.y]; return [this.id, this.x, this.y];
} }
@ -40,7 +40,7 @@ class Discharge {
// TODO: Create creation interface using fixture then send this as // TODO: Create creation interface using fixture then send this as
// an array. // an array.
return { return {
form: 'discharge', form: 'particle',
id: this.id, id: this.id,
x: this.x, x: this.x,
y: this.y, y: this.y,
@ -52,28 +52,20 @@ class Discharge {
} }
tick() { tick() {
let start = { let start = { x: this.x, y: this.y };
x: this.x,
y: this.y
};
this.x += this.xvel; this.x += this.xvel;
this.y += this.yvel this.y += this.yvel
let end = { let end = { x: this.x, y: this.y };
x: this.x,
y: this.y
};
let contact = this.world.physics.raycast(start, end); let contact = this.world.physics.raycast(start, end);
if (contact) { if (contact)
this.contact(contact.body, contact.point); this.contact(contact.body, contact.point);
}
if (this.lifetime-- <= 0) if (this.lifetime-- <= 0)
this.destroy(); this.destroy();
} }
} }
module.exports = Discharge; module.exports = Particle;

View file

@ -3,7 +3,7 @@
const Asteroid = require('./body/asteroid.js'); const Asteroid = require('./body/asteroid.js');
const Grapple = require('./body/projectile/grapple.js'); const Grapple = require('./body/projectile/grapple.js');
const Missile = require('./body/projectile/missile.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'); const Ship = require('./body/ship.js');
class Spawner { class Spawner {
@ -93,7 +93,7 @@ class Spawner {
yvel: fixture.body.vel.y + vy yvel: fixture.body.vel.y + vy
}; };
let laser = new Laser(fixture, pos); let laser = new Laser(fixture, pos);
this.world.addDischarge(laser); this.world.addParticle(laser);
return laser; return laser;
} }
} }

View file

@ -17,7 +17,7 @@
[3, 1] [3, 1]
] ]
], ],
"mounts": [ "hardpoints": [
{ {
"pos": [0.5625, 0.125], "pos": [0.5625, 0.125],
"type": "fixed", "type": "fixed",