add lasers
This commit is contained in:
parent
cf4e8024af
commit
f87aa1446d
31 changed files with 298 additions and 125 deletions
|
@ -121,6 +121,7 @@ class Body {
|
|||
|
||||
packFull() {
|
||||
let packet = {
|
||||
form: 'body',
|
||||
type: this.type,
|
||||
class: this.class,
|
||||
id: this.id,
|
||||
|
@ -140,6 +141,10 @@ class Body {
|
|||
return {};
|
||||
}
|
||||
|
||||
getWorldPos(pos) {
|
||||
return this.b2body.GetWorldPoint(new b2Vec2(pos.x, pos.y), {});
|
||||
}
|
||||
|
||||
get awake() {
|
||||
if (this.b2body.IsAwake()) {
|
||||
this.sleepTime = 0;
|
||||
|
|
|
@ -58,26 +58,12 @@ class Ship extends Body {
|
|||
this.thrust.right = packet.thrust[2];
|
||||
|
||||
packet.fire.forEach((m, i) => m ? this.mounts[i].fire(m) : 0);
|
||||
|
||||
if (packet.fire[0] && this.grapple) {
|
||||
this.grapple.release();
|
||||
} else if (packet.fire[0] && !this.grapple) {
|
||||
if (this.grapple) {
|
||||
this.grapple.retract();
|
||||
} else {
|
||||
this.launchGrapple(this.aim.x, this.aim.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launchMissile() {
|
||||
this.world.spawner.spawnMissile(this);
|
||||
}
|
||||
|
||||
launchGrapple(x, y) {
|
||||
this.grapple = this.world.spawner.spawnGrapple(this, x, y);
|
||||
}
|
||||
|
||||
tickType() {
|
||||
if (this.thrust.forward) {
|
||||
let power = this.power.forward;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const Fixture = require('./fixture.js');
|
||||
const Laser = require('./shot/laser.js');
|
||||
const Laser = require('./discharge/laser.js');
|
||||
|
||||
class Blaster extends Fixture {
|
||||
constructor(mount, data) {
|
||||
|
@ -9,10 +9,7 @@ class Blaster extends Fixture {
|
|||
}
|
||||
|
||||
fire() {
|
||||
let data = {
|
||||
speed: 1
|
||||
|
||||
};
|
||||
this.body.world.spawner.spawnLaser(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
11
server/game/room/world/body/turret/discharge/beam.js
Normal file
11
server/game/room/world/body/turret/discharge/beam.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
const Discharge = require('./discharge.js');
|
||||
|
||||
class Beam extends Discharge {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Beam;
|
11
server/game/room/world/body/turret/discharge/bullet.js
Normal file
11
server/game/room/world/body/turret/discharge/bullet.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
const Discharge = require('./discharge.js');
|
||||
|
||||
class Bullet extends Discharge {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Bullet;
|
49
server/game/room/world/body/turret/discharge/discharge.js
Normal file
49
server/game/room/world/body/turret/discharge/discharge.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
'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 || 100;
|
||||
this.fixture = fixture;
|
||||
|
||||
// Might just make it this.world later if it turns out I need it more.
|
||||
this.id = this.fixture.body.world.room.generateId();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.fixture.body.world.removeDischarge(this);
|
||||
}
|
||||
|
||||
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() {
|
||||
if (this.lifetime-- <= 0)
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Discharge;
|
11
server/game/room/world/body/turret/discharge/laser.js
Normal file
11
server/game/room/world/body/turret/discharge/laser.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
const Discharge = require('./discharge.js');
|
||||
|
||||
class Laser extends Discharge {
|
||||
constructor(fixture, data) {
|
||||
super(fixture, data);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Laser;
|
|
@ -11,6 +11,7 @@ class Fixture {
|
|||
this._angle = mount.traversal ? mount.traversal.cw : 0;
|
||||
|
||||
this.mount = mount;
|
||||
this.body = this.mount.body;
|
||||
}
|
||||
|
||||
destruct() {
|
||||
|
|
|
@ -5,10 +5,20 @@ const Fixture = require('./fixture.js');
|
|||
class Grapple extends Fixture {
|
||||
constructor(mount, data) {
|
||||
super(mount, data);
|
||||
|
||||
this.grapple = false;
|
||||
}
|
||||
|
||||
fire() {
|
||||
|
||||
fire(value) {
|
||||
if (this.state == 1) {
|
||||
this.grapple.release();
|
||||
this.state = 0;
|
||||
} else {
|
||||
let x = this.body.aim.x;
|
||||
let y = this.body.aim.y;
|
||||
this.state = 1;
|
||||
this.grapple = this.body.world.spawner.spawnGrapple(this, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,13 +6,13 @@ const Grapple = require('./grapple.js');
|
|||
const traits = require('../../traits/fixtures.json');
|
||||
|
||||
class Mount {
|
||||
constructor(ship, data, fixture) {
|
||||
//this.ship = ship;
|
||||
constructor(body, data, fixture) {
|
||||
this.body = body;
|
||||
|
||||
this.type = data.type || 'turret';
|
||||
this.size = data.size || 0;
|
||||
this.hidden = data.hidden || 'false';
|
||||
this.position = {
|
||||
this.pos = {
|
||||
x: data.pos[0],
|
||||
y: data.pos[1]
|
||||
}
|
||||
|
@ -63,8 +63,8 @@ class Mount {
|
|||
|
||||
packFull() {
|
||||
return {
|
||||
x: this.position.x,
|
||||
y: this.position.y,
|
||||
x: this.pos.x,
|
||||
y: this.pos.y,
|
||||
hidden: this.hidden,
|
||||
fixture: this.fixture ? this.fixture.id : 0
|
||||
};
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const Shot = require('./shot.js');
|
||||
|
||||
class Beam extends Shot {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Beam;
|
|
@ -1,11 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const Shot = require('./shot.js');
|
||||
|
||||
class Bullet extends Shot {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Bullet;
|
|
@ -1,11 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const Shot = require('./shot.js');
|
||||
|
||||
class Laser extends Shot {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Laser;
|
|
@ -1,13 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
class Shot {
|
||||
constructor(pos) {
|
||||
|
||||
}
|
||||
|
||||
tick() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Shot;
|
Loading…
Add table
Add a link
Reference in a new issue