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;
|
|
@ -1,79 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
class Discharge {
|
||||
constructor(fixture, data) {
|
||||
this.x = data.x;
|
||||
this.y = data.y;
|
||||
this.xvel = data.xvel;
|
||||
this.yvel = data.yvel;
|
||||
this.r = data.r;
|
||||
|
||||
this.lifetime = data.lifetime || 50;
|
||||
this.fixture = fixture;
|
||||
this.body = this.fixture.body;
|
||||
this.world = this.body.world;
|
||||
|
||||
this.id = this.world.room.generateId();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.world.removeDischarge(this);
|
||||
}
|
||||
|
||||
contact(body, point) {
|
||||
if (body == this.body) return;
|
||||
|
||||
if (body.type == 'ship' && body.player.team != this.body.player.team) {
|
||||
body.damage(0.1, point)
|
||||
}
|
||||
|
||||
this.destroy();
|
||||
}
|
||||
|
||||
packDelta() {
|
||||
// TODO: Implement some sort of delta interface for discharges that is
|
||||
// derived from the fixture so it's efficient.
|
||||
return [this.id, this.x, this.y];
|
||||
}
|
||||
|
||||
packFull() {
|
||||
// TODO: Create creation interface using fixture then send this as
|
||||
// an array.
|
||||
return {
|
||||
form: 'discharge',
|
||||
id: this.id,
|
||||
x: this.x,
|
||||
y: this.y,
|
||||
r: this.r,
|
||||
xvel: this.xvel,
|
||||
yvel: this.yvel,
|
||||
delta: this.packDelta()
|
||||
}
|
||||
}
|
||||
|
||||
tick() {
|
||||
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 contact = this.world.physics.raycast(start, end);
|
||||
|
||||
if (contact) {
|
||||
this.contact(contact.body, contact.point);
|
||||
}
|
||||
|
||||
if (this.lifetime-- <= 0)
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Discharge;
|
|
@ -1,11 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const Discharge = require('./discharge.js');
|
||||
|
||||
class Laser extends Discharge {
|
||||
constructor(fixture, data) {
|
||||
super(fixture, data);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Laser;
|
Loading…
Add table
Add a link
Reference in a new issue