add fixture autofire
This commit is contained in:
parent
d9e8e217c6
commit
8e0c4b02e4
9 changed files with 40 additions and 8 deletions
|
@ -8,7 +8,7 @@ class Blaster extends Fixture {
|
|||
super(mount, data);
|
||||
}
|
||||
|
||||
fire() {
|
||||
fireType() {
|
||||
this.body.world.spawner.spawnLaser(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,11 @@ class Fixture {
|
|||
constructor(mount, data) {
|
||||
this.type = data.type;
|
||||
this.id = data.id;
|
||||
this.rof = data.rateOfFire;
|
||||
this.rof = 60 / data.rateOfFire | 0;
|
||||
this.autofire = data.autofire || false;
|
||||
|
||||
this.fired = false;
|
||||
this.cooldown = 0;
|
||||
this.state = 0;
|
||||
this.projectiles = new Set();
|
||||
this._angle = mount.traversal ? mount.traversal.cw : 0;
|
||||
|
@ -16,10 +19,25 @@ class Fixture {
|
|||
|
||||
destruct() {
|
||||
this.projectiles.forEach(p => p.world.removeBody(p));
|
||||
if (this.grapple) this.grapple.release();
|
||||
}
|
||||
|
||||
fire() {
|
||||
fire(value) {
|
||||
if (this.cooldown > 0) return;
|
||||
if (this.fired && !this.autofire) return;
|
||||
|
||||
this.fireType(value);
|
||||
this.cooldown = this.rof;
|
||||
this.fired = true;
|
||||
}
|
||||
|
||||
rest() {
|
||||
this.fired = false;
|
||||
}
|
||||
|
||||
tick() {
|
||||
if (this.cooldown > 0)
|
||||
this.cooldown--;
|
||||
}
|
||||
|
||||
packFull() {
|
||||
|
|
|
@ -9,7 +9,7 @@ class Grapple extends Fixture {
|
|||
this.grapple = false;
|
||||
}
|
||||
|
||||
fire(value) {
|
||||
fireType(value) {
|
||||
if (this.state == 1) {
|
||||
this.grapple.release();
|
||||
this.state = 0;
|
||||
|
|
|
@ -38,6 +38,11 @@ class Mount {
|
|||
this.fixture.fire();
|
||||
}
|
||||
|
||||
rest() {
|
||||
if (!this.fixture) return;
|
||||
this.fixture.rest();
|
||||
}
|
||||
|
||||
setFixture(fixture) {
|
||||
if (!(fixture in traits)) return;
|
||||
|
||||
|
@ -53,6 +58,10 @@ class Mount {
|
|||
this.fixture = new fixtureClass(this, data);
|
||||
}
|
||||
|
||||
tick() {
|
||||
this.fixture.tick();
|
||||
}
|
||||
|
||||
packDelta() {
|
||||
return [this.angle || 0, this.fixture.state || 0];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue