diff --git a/public/static/js/wingbase/player.js b/public/static/js/wingbase/player.js index a4ef47e..c9de74b 100644 --- a/public/static/js/wingbase/player.js +++ b/public/static/js/wingbase/player.js @@ -15,7 +15,7 @@ class Player { let packet = {}; packet.thrust = ['w', 'a', 'd', 's'].map(k => +input.keys.held[k] || 0); - packet.fire = [1, 1, 3].map(k => +input.mouse.pressed[k] || 0); + packet.fire = [1, 1, 3].map(k => +input.mouse.held[k] || 0); packet.aim = [ +input.mouse.wx.toFixed(2), +input.mouse.wy.toFixed(2) diff --git a/server/game/room/world/body/body.js b/server/game/room/world/body/body.js index a0f1261..aaabfd9 100644 --- a/server/game/room/world/body/body.js +++ b/server/game/room/world/body/body.js @@ -113,6 +113,8 @@ 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.sleepTime++; this.tickType(); diff --git a/server/game/room/world/body/ship.js b/server/game/room/world/body/ship.js index 10c61a6..2aeaa06 100644 --- a/server/game/room/world/body/ship.js +++ b/server/game/room/world/body/ship.js @@ -61,7 +61,9 @@ class Ship extends Body { this.thrust.left = packet.thrust[1]; this.thrust.right = packet.thrust[2]; - packet.fire.forEach((m, i) => m ? this.mounts[i].fire(m) : 0); + packet.fire.forEach((m, i) => { + m ? this.mounts[i].fire(m) : this.mounts[i].rest(); + }); } launchMissile() { diff --git a/server/game/room/world/body/turret/blaster.js b/server/game/room/world/body/turret/blaster.js index c666cb5..edec002 100644 --- a/server/game/room/world/body/turret/blaster.js +++ b/server/game/room/world/body/turret/blaster.js @@ -8,7 +8,7 @@ class Blaster extends Fixture { super(mount, data); } - fire() { + fireType() { this.body.world.spawner.spawnLaser(this); } } diff --git a/server/game/room/world/body/turret/fixture.js b/server/game/room/world/body/turret/fixture.js index fdabb39..7d1d8f1 100644 --- a/server/game/room/world/body/turret/fixture.js +++ b/server/game/room/world/body/turret/fixture.js @@ -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() { diff --git a/server/game/room/world/body/turret/grapple.js b/server/game/room/world/body/turret/grapple.js index 16c43ef..afb1c05 100644 --- a/server/game/room/world/body/turret/grapple.js +++ b/server/game/room/world/body/turret/grapple.js @@ -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; diff --git a/server/game/room/world/body/turret/mount.js b/server/game/room/world/body/turret/mount.js index 5e275c1..6cf1be6 100644 --- a/server/game/room/world/body/turret/mount.js +++ b/server/game/room/world/body/turret/mount.js @@ -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]; } diff --git a/server/game/room/world/index.js b/server/game/room/world/index.js index 999ec86..b7b2b8f 100644 --- a/server/game/room/world/index.js +++ b/server/game/room/world/index.js @@ -29,7 +29,7 @@ class World { this.bounds = { left: 0, - right: 150, + right: 60, top: 0, bottom: 30 } @@ -115,7 +115,7 @@ class World { } populate() { - for (var i = 0; i < 50; i++) { + for (var i = 0; i < 30; i++) { let pos = { x: Math.random() * this.bounds.right, y: Math.random() * this.bounds.bottom diff --git a/server/game/room/world/traits/fixtures.json b/server/game/room/world/traits/fixtures.json index 2b9aff4..6f23012 100644 --- a/server/game/room/world/traits/fixtures.json +++ b/server/game/room/world/traits/fixtures.json @@ -32,6 +32,7 @@ "type": "grapple", "speed": 0.1, "range": 8, + "autofire": false, "cost": { },