add fixture autofire

This commit is contained in:
Asraelite 2016-03-30 20:40:05 +01:00
parent d9e8e217c6
commit 8e0c4b02e4
9 changed files with 40 additions and 8 deletions

View file

@ -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() {