diff --git a/public/static/js/wingbase/assets.js b/public/static/js/wingbase/assets.js index 544a5db..ce094da 100644 --- a/public/static/js/wingbase/assets.js +++ b/public/static/js/wingbase/assets.js @@ -14,6 +14,9 @@ Game.prototype.loadAssets = _ => { turrets: { '01': { small: 'img/turrets/01/normal.png' + }, + '02': { + small: 'img/turrets/02/normal.png' } }, projectiles: { diff --git a/public/static/js/wingbase/render/body.js b/public/static/js/wingbase/render/body.js index b47b1ef..30d318f 100644 --- a/public/static/js/wingbase/render/body.js +++ b/public/static/js/wingbase/render/body.js @@ -19,9 +19,9 @@ class BodyRenderer { pallet.view(x, y, false, pos.r); for (let f of body.fixtures) { - if (!f.type) continue; - let img = game.assets.images.turrets[f.type].small; - this.pallet.image(img, f.x - 32, f.y - 32, 0); + if (!f.fixture || !f.hidden) continue; + let img = game.assets.images.turrets[f.fixture].small; + this.pallet.image(img, f.x - 32, f.y - 32, f.angle); } if (body.bodyType == 'ship') { @@ -34,6 +34,13 @@ class BodyRenderer { this.renderBody(body); } + for (let f of body.fixtures) { + if (!f.fixture || f.hidden) continue; + let img = game.assets.images.turrets[f.fixture].small; + this.pallet.image(img, f.x - 32, f.y - 32, f.angle); + } + + pallet.restore(); pallet.restore(); } @@ -62,7 +69,7 @@ class BodyRenderer { context.stroke(); } - this.pallet.restore(); + //this.pallet.restore(); } renderBody(body) { @@ -83,7 +90,7 @@ class BodyRenderer { context.stroke(); } - this.pallet.restore(); + //this.pallet.restore(); } renderShip(ship) { @@ -103,7 +110,7 @@ class BodyRenderer { this.pallet.square('#f00', ship.debug.x * SCALE, ship.debug.y * SCALE, 2); } - this.pallet.restore(); + //this.pallet.restore(); } renderShipNameplate(ship) { @@ -122,6 +129,6 @@ class BodyRenderer { let img = game.assets.images.projectiles['02']; let pos = body.pos; this.pallet.image(img, -32, -32, 0); - this.pallet.restore(); + //this.pallet.restore(); } }; diff --git a/public/static/js/wingbase/world/asteroid.js b/public/static/js/wingbase/world/asteroid.js index b2286d4..8243ed8 100644 --- a/public/static/js/wingbase/world/asteroid.js +++ b/public/static/js/wingbase/world/asteroid.js @@ -6,10 +6,10 @@ class Asteroid extends Body { } updateType(data) { - //this.debug = data.debug; + this.debug = data.debug; } tickType() { - + } } diff --git a/public/static/js/wingbase/world/body.js b/public/static/js/wingbase/world/body.js index 032b0d1..3f77737 100644 --- a/public/static/js/wingbase/world/body.js +++ b/public/static/js/wingbase/world/body.js @@ -3,7 +3,8 @@ class Body { constructor(data) { this.interface = data.interface; - let s = this.interface.order.length + this.interface.fixtures; + let s = this.interface.order.length; + s += this.interface.fixtures.order.length * this.interface.fixtures.num; this.interface.size = s; this.id = data.id this.frame = data.frame; @@ -36,9 +37,7 @@ class Body { update(data) { let values = {}; - Array.from(data).map((v, i) => { - values[this.interface.order[i]] = v - }); + this.interface.order.forEach(v => values[v] = data.shift()); this.x = values.x; this.y = values.y; this.xvel = values.xvel; @@ -46,7 +45,14 @@ class Body { this.r = values.r; this.rvel = values.rvel; this.updated = 10; - this.debug = values.debug; + + this.fixtures.forEach(fixture => { + let obj = {}; + this.interface.fixtures.order.forEach(v => obj[v] = data.shift()); + + fixture.angle = obj.angle; + fixture.state = obj.state; + }); this.updateType(values); } diff --git a/server/game/player.js b/server/game/player.js index 86e2912..2d73247 100644 --- a/server/game/player.js +++ b/server/game/player.js @@ -32,9 +32,7 @@ class Player { updateInputs(data) { let input = {}; - let sanitize = v => { - return v.length ? v.map(a => sanitize(a)) : +v || 0; - } + let sanitize = v => v.length ? v.map(a => sanitize(a)) : +v || 0; data.forEach((v, i) => input[this.inputInterface[i]] = sanitize(v)); this.ship.updateInputs(input); this.lastAction = Date.now(); diff --git a/server/game/room/world/body/body.js b/server/game/room/world/body/body.js index 5a4ca1a..d521c1d 100644 --- a/server/game/room/world/body/body.js +++ b/server/game/room/world/body/body.js @@ -39,7 +39,13 @@ class Body { 'rvel' ], type: 'body', - fixtures: this.mounts.length + fixtures: { + order: [ + 'angle', + 'state' + ], + num: this.mounts.length + } }; this.sleepTime = 0; @@ -99,16 +105,12 @@ class Body { } packDelta() { - let pos = this.b2body.GetPosition(); - let vel = this.b2body.GetLinearVelocity(); - let rot = this.b2body.GetAngleRadians(); - let rvel = this.b2body.GetAngularVelocity(); + let pos = this.pos; + let vel = this.vel; - let values = [this.id, pos.x, pos.y, vel.x, vel.y, rot, rvel]; + let values = [this.id, pos.x, pos.y, vel.x, vel.y, pos.r, vel.r]; values = values.concat(this.packTypeDelta()); - this.mounts.forEach(m => { - values = values.concat(m.packDelta()); - }); + this.mounts.forEach(m => [].push.apply(values, m.packDelta())); return values; } @@ -128,9 +130,8 @@ class Body { interface: this.interface }; - let typePacket = this.packTypeFull(); - for (let i in typePacket) - packet[i] = typePacket[i]; + // Merge default and type-specific packets. + packet = Object.assign(packet, this.packTypeFull()); return packet; } @@ -173,7 +174,8 @@ class Body { get vel() { return { x: this.b2body.GetLinearVelocity().x, - y: this.b2body.GetLinearVelocity().y + y: this.b2body.GetLinearVelocity().y, + r: this.b2body.GetAngularVelocity() } } } diff --git a/server/game/room/world/body/turret/blaster.js b/server/game/room/world/body/turret/blaster.js index 816a190..c825caa 100644 --- a/server/game/room/world/body/turret/blaster.js +++ b/server/game/room/world/body/turret/blaster.js @@ -9,7 +9,6 @@ class Blaster extends Fixture { } fire() { - wingbase.debug('pew pew'); let data = { speed: 1 diff --git a/server/game/room/world/body/turret/fixture.js b/server/game/room/world/body/turret/fixture.js index 7cd1c4d..26168e8 100644 --- a/server/game/room/world/body/turret/fixture.js +++ b/server/game/room/world/body/turret/fixture.js @@ -1,36 +1,35 @@ 'use strict'; -const traits = require('../../traits/fixtures.json'); - class Fixture { constructor(mount, data) { + this.type = data.type; + this.id = data.id; + this.rof = data.rateOfFire; + + this.state = 0; + this.projectiles = new Set(); + this._angle = mount.traversal ? mount.traversal.cw : 0; + this.mount = mount; - - this.projectiles = new WeakSet(); - - let turretTraits = traits[data.type]; - - console.log(turretTraits); - - this.rof = turretTraits.rateOfFire; - - this.traversal = this.mount.traversal || false; - this.fired = false; - this._angle = this.traversal ? this.traversal.cw : 0; } destruct() { this.projectiles.forEach(p => p.world.removeBody(p)); } + fire() { + + } + packFull() { return { - traversal: this.traversal + traversal: this.traversal, + angle: this.angle } } packDelta() { - return [this.traversal]; + } get angle() { @@ -39,7 +38,7 @@ class Fixture { set angle(angle) { // TODO: Check if within traversal limit if on mount. - if (this.type == 'fixed') return; + if (this.mount.type == 'fixed') return; this._angle = angle; } } diff --git a/server/game/room/world/body/turret/grapple.js b/server/game/room/world/body/turret/grapple.js new file mode 100644 index 0000000..ea2cfbe --- /dev/null +++ b/server/game/room/world/body/turret/grapple.js @@ -0,0 +1,15 @@ +'use strict'; + +const Fixture = require('./fixture.js'); + +class Grapple extends Fixture { + constructor(mount, data) { + super(mount, data); + } + + fire() { + + } +} + +module.exports = Grapple; diff --git a/server/game/room/world/body/turret/mount.js b/server/game/room/world/body/turret/mount.js index d7d4fdc..89a08a1 100644 --- a/server/game/room/world/body/turret/mount.js +++ b/server/game/room/world/body/turret/mount.js @@ -1,51 +1,78 @@ 'use strict'; const Blaster = require('./blaster.js'); +const Grapple = require('./grapple.js'); + +const traits = require('../../traits/fixtures.json'); class Mount { constructor(ship, data, fixture) { - this.ship = ship; + //this.ship = ship; this.type = data.type || 'turret'; - this.fixture = fixture || false//new Fixture(fixture); this.size = data.size || 0; + this.hidden = data.hidden || 'false'; this.position = { x: data.pos[0], y: data.pos[1] } this.traversal = data.traversal ? { - cw: data.bounds[0], - ccw: data.bounds[1] + cw: data.traversal[0], + ccw: data.traversal[1] } : 0; - this.updateDeltaInterface(); + this.deltaInterface = ['traversal']; + + this.fixture = false; + this.setFixture(fixture); } destruct() { if (!this.fixture) return; - //this.fixture.destruct(); + this.fixture.destruct(); } fire() { - console.log(this.fixture); + if (!this.fixture) return; + this.fixture.fire(); + } + + setFixture(fixture) { + if (!(fixture in traits)) return; + + let fixtureClass = { + 'blaster': Blaster, + 'grapple': Grapple + }[traits[fixture].type]; + + if (!fixtureClass) return; + + let data = traits[fixture]; + data.id = fixture; + this.fixture = new fixtureClass(this, data); } packDelta() { - return [this.traversal || 0]; + return [this.angle || 0, this.fixture.state || 0]; } - updateDeltaInterface() { - this.deltaInterface = ['traversal']; + packTypeDelta() { + return [0]; } packFull() { return { x: this.position.x, y: this.position.y, - type: this.fixture ? this.fixture : 0 + hidden: this.hidden, + fixture: this.fixture ? this.fixture.id : 0 }; } + + get angle() { + return this.fixture ? this.fixture.angle : 0; + } } module.exports = Mount; diff --git a/server/game/room/world/traits/defaults.json b/server/game/room/world/traits/defaults.json index 28ad906..7927e2f 100644 --- a/server/game/room/world/traits/defaults.json +++ b/server/game/room/world/traits/defaults.json @@ -1,6 +1,6 @@ { "spawnShip": { "ship": "01", - "fixtures": ["01", "01"] + "fixtures": ["01", "01", "02"] } } diff --git a/server/game/room/world/traits/fixtures.json b/server/game/room/world/traits/fixtures.json index 031e9c2..2b9aff4 100644 --- a/server/game/room/world/traits/fixtures.json +++ b/server/game/room/world/traits/fixtures.json @@ -1,12 +1,14 @@ { "01": { "name": "Basic Blaster", + "class": "gun", "type": "blaster", "damage": { "thermal": 5, "kinetic": 1 }, "speed": 1, + "acceleration": 0, "range": 10, "autofire": true, "rateOfFire": 4, @@ -23,5 +25,20 @@ "trail": 3, "size": 2 } + }, + "02": { + "name": "Grappling Hook", + "class": "launcher", + "type": "grapple", + "speed": 0.1, + "range": 8, + "cost": { + + }, + "appearance": { + "type": "projectile", + "sprite": "grapple", + "size": 1 + } } } diff --git a/server/game/room/world/traits/ships.json b/server/game/room/world/traits/ships.json index 3c9c093..e4255af 100644 --- a/server/game/room/world/traits/ships.json +++ b/server/game/room/world/traits/ships.json @@ -22,19 +22,22 @@ "pos": [18, 4], "type": "fixed", "size": 0, - "traversal": false + "traversal": [0, 0], + "hidden": true }, { "pos": [18, 28], "type": "fixed", "size": 0, - "traversal": false + "traversal": [0, 0], + "hidden": true }, { - "pos": [1, 16], + "pos": [6, 16], "type": "fixed", "size": 1, - "traversal": false + "traversal": [3.14, 0], + "hidden": true } ] }