add boilerplate for mounts and fixtures
This commit is contained in:
parent
0ea163dfb7
commit
0a90b6b77a
15 changed files with 158 additions and 17 deletions
|
@ -11,11 +11,17 @@ class Body {
|
|||
this.r = 0;
|
||||
this.b2body = false;
|
||||
this.type = 'asteroid';
|
||||
this.mounts = [];
|
||||
this.health = 1;
|
||||
this.world = world;
|
||||
this.id = uuid.v4().slice(0, 8);
|
||||
}
|
||||
|
||||
destruct() {
|
||||
this.mounts.forEach(mount => mount.destruct());
|
||||
this.world.physics.remove(this);
|
||||
}
|
||||
|
||||
applyDelta() {
|
||||
this.world.applyDelta(this.id, this.packDelta());
|
||||
}
|
||||
|
|
|
@ -4,27 +4,39 @@ const defaults = require('../traits/defaults.json');
|
|||
const shipTraits = require('../traits/ships.json');
|
||||
|
||||
const Body = require('./body.js');
|
||||
const Mount = require('./turret/mount.js');
|
||||
|
||||
class Ship extends Body {
|
||||
constructor(world, pos, player, build) {
|
||||
super(world);
|
||||
|
||||
build = build || defaults.spawnShip;
|
||||
|
||||
// Body data.
|
||||
this.x = pos.x || 0;
|
||||
this.y = pos.y || 0;
|
||||
|
||||
build = build || {};
|
||||
this.class = build.ship || defaults.spawnShip.ship;
|
||||
this.turrets = build.turrets || defaults.spawnShip.turrets;
|
||||
let traits = shipTraits[this.class];
|
||||
this.frame = traits.hull;
|
||||
this.power = traits.power;
|
||||
this.mounts = traits.mounts;
|
||||
this.size = traits.size;
|
||||
this.player = player;
|
||||
this.type = 'ship';
|
||||
this.class = build.ship;
|
||||
this.player = player;
|
||||
this.inputs = {};
|
||||
this.grapple = false;
|
||||
|
||||
// Traits.
|
||||
let traits = shipTraits[this.class];
|
||||
this.traits = traits;
|
||||
this.frame = traits.frame;
|
||||
this.power = traits.power;
|
||||
this.size = traits.size;
|
||||
|
||||
// Mounts
|
||||
traits.mounts.forEach((mount, i) => {
|
||||
let mounts = new Mount(this, mount);
|
||||
this.mounts.push(mount);
|
||||
});
|
||||
|
||||
this.turrets = [];
|
||||
|
||||
this.thrust = {
|
||||
forward: 0,
|
||||
left: 0,
|
||||
|
@ -100,7 +112,7 @@ class Ship extends Body {
|
|||
name: this.player.name,
|
||||
frame: this.frame,
|
||||
power: this.power,
|
||||
mounts: this.mounts,
|
||||
mounts: this.traits.mounts,
|
||||
turrets: this.turrets,
|
||||
size: this.size,
|
||||
delta: this.packDelta()
|
||||
|
|
20
server/game/room/world/body/turret/blaster.js
Normal file
20
server/game/room/world/body/turret/blaster.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
'use strict';
|
||||
|
||||
const Fixture = require('./fixture.js');
|
||||
const Laser = require('./shot/laser.js');
|
||||
|
||||
class Blaster extends Fixture {
|
||||
constructor(hardpoint, data) {
|
||||
super(hardpoint, data);
|
||||
}
|
||||
|
||||
fire() {
|
||||
wingbase.debug('pew pew');
|
||||
let data = {
|
||||
speed: 1
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Blaster;
|
34
server/game/room/world/body/turret/fixture.js
Normal file
34
server/game/room/world/body/turret/fixture.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
'use strict';
|
||||
|
||||
const traits = require('../../traits/turrets.json');
|
||||
|
||||
class Fixture {
|
||||
constructor(hardpoint, data) {
|
||||
this.hardpoint = hardpoint;
|
||||
|
||||
this.projectiles = new WeakSet();
|
||||
|
||||
let turretTraits = traits[data.type];
|
||||
|
||||
this.rof = turretTraits.rateOfFire;
|
||||
|
||||
this.traversal = this.hardpoint.traversal || false;
|
||||
this._angle = this.traversal ? this.traversal.cw : 0;
|
||||
}
|
||||
|
||||
destruct() {
|
||||
this.projectiles.forEach(p => p.world.removeBody(p));
|
||||
}
|
||||
|
||||
get angle() {
|
||||
return this._angle;
|
||||
}
|
||||
|
||||
set angle(angle) {
|
||||
// TODO: Check if within traversal limit if on mount.
|
||||
if (this.type == 'fixed') return;
|
||||
this._angle = angle;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Fixture;
|
24
server/game/room/world/body/turret/mount.js
Normal file
24
server/game/room/world/body/turret/mount.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
'use strict';
|
||||
|
||||
const Blaster = require('./blaster.js');
|
||||
|
||||
class Mount {
|
||||
constructor(ship, data, fixture) {
|
||||
this.ship = ship;
|
||||
|
||||
this.type = data.type || 'turret';
|
||||
this.fixture = false; // TODO: Create fixture.
|
||||
|
||||
this.traversal = data.traversal ? {
|
||||
cw: data.bounds[0],
|
||||
ccw: data.bounds[1]
|
||||
} : false;
|
||||
}
|
||||
|
||||
destruct() {
|
||||
if (!this.fixture) return;
|
||||
this.fixture.destruct();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Mount;
|
11
server/game/room/world/body/turret/shot/laser.js
Normal file
11
server/game/room/world/body/turret/shot/laser.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
const Shot = require('./shot.js');
|
||||
|
||||
class Laser extends Shot {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Laser;
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
class Shot {
|
||||
constructor() {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Beam;
|
||||
module.exports = Shot;
|
|
@ -124,7 +124,7 @@ class World {
|
|||
}
|
||||
|
||||
removeBody(body) {
|
||||
this.physics.remove(body);
|
||||
body.destruct();
|
||||
this.bodies.delete(body);
|
||||
this.ships.delete(body);
|
||||
this.structures.delete(body);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"spawnShip": {
|
||||
"ship": "01",
|
||||
"turrets": ["01", "01"]
|
||||
"fixtures": ["01", "01"]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
"back": 0,
|
||||
"rotation": 0.003
|
||||
},
|
||||
"hull": [
|
||||
"frame": [
|
||||
[
|
||||
[12, 1],
|
||||
[29, 13],
|
||||
|
@ -18,8 +18,11 @@
|
|||
]
|
||||
],
|
||||
"mounts": [
|
||||
[18, 4],
|
||||
[18, 28]
|
||||
{
|
||||
"pos": [18, 4],
|
||||
"type": "fixed",
|
||||
"traversal": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
27
server/game/room/world/traits/turrets.json
Normal file
27
server/game/room/world/traits/turrets.json
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"01": {
|
||||
"name": "Basic Blaster",
|
||||
"type": "blaster",
|
||||
"damage": {
|
||||
"thermal": 5,
|
||||
"kinetic": 1
|
||||
},
|
||||
"speed": 1,
|
||||
"range": 10,
|
||||
"autofire": true,
|
||||
"rateOfFire": 4,
|
||||
"overheat": {
|
||||
"cooldown": 0.01,
|
||||
"heat": 0.1
|
||||
},
|
||||
"cost": {
|
||||
|
||||
},
|
||||
"appearance": {
|
||||
"type": "laser",
|
||||
"color": "#ff5f45",
|
||||
"trail": 3,
|
||||
"size": 2
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,6 +23,10 @@ class ServerInterface {
|
|||
`${pad(('' + d.getUTCMilliseconds()).slice(0, 2), 2, true)}> `;
|
||||
console.log(timestamp.gray, msg);
|
||||
}
|
||||
|
||||
debug(msg) {
|
||||
this.log(msg.cyan);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ServerInterface;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue