diff --git a/public/img/turrets/01/large.png b/public/img/turrets/01/large.png new file mode 100644 index 0000000..9790e49 Binary files /dev/null and b/public/img/turrets/01/large.png differ diff --git a/public/img/turrets/01/medium.png b/public/img/turrets/01/medium.png new file mode 100644 index 0000000..3d02e9a Binary files /dev/null and b/public/img/turrets/01/medium.png differ diff --git a/public/img/turrets/01/small.png b/public/img/turrets/01/small.png new file mode 100644 index 0000000..419d197 Binary files /dev/null and b/public/img/turrets/01/small.png differ diff --git a/public/img/turrets/01large.png b/public/img/turrets/01large.png deleted file mode 100644 index eb77f5c..0000000 Binary files a/public/img/turrets/01large.png and /dev/null differ diff --git a/public/img/turrets/01medium.png b/public/img/turrets/01medium.png deleted file mode 100644 index 547e227..0000000 Binary files a/public/img/turrets/01medium.png and /dev/null differ diff --git a/public/img/turrets/01small.png b/public/img/turrets/01small.png deleted file mode 100644 index de89bce..0000000 Binary files a/public/img/turrets/01small.png and /dev/null differ diff --git a/public/js/starbugs/assets.js b/public/js/starbugs/assets.js index 3a54a80..1bb5716 100644 --- a/public/js/starbugs/assets.js +++ b/public/js/starbugs/assets.js @@ -10,6 +10,11 @@ function loadAssets() { thrust5: 'img/ships/01/thrust5.png', thrust8: 'img/ships/01/thrust8.png' } + }, + turrets: { + '01': { + small: 'img/turrets/01/small.png' + } } } } @@ -19,7 +24,6 @@ function loadAssets() { // Magical recursive magic. (function r(o, t) { for (var i in o) { - console.log(i); if (typeof o[i] == 'string') { t[i] = new Image(); t[i].src = o[i]; diff --git a/public/js/starbugs/render/ships.js b/public/js/starbugs/render/ships.js index 5ec9533..429195a 100644 --- a/public/js/starbugs/render/ships.js +++ b/public/js/starbugs/render/ships.js @@ -5,6 +5,7 @@ function renderShip(pallet, ship) { var thr0 = game.assets.images.ships[ship.hull].thrust0; var thr5 = game.assets.images.ships[ship.hull].thrust5; var thr8 = game.assets.images.ships[ship.hull].thrust8; + var turr = game.assets.images.turrets['01'].small; //pallet.view(ship.x, ship.y, false, ship.r); var pos = ship.getPos(); var x = pos.x; @@ -13,7 +14,15 @@ function renderShip(pallet, ship) { var vy = -game.world.getCenter().y; pallet.view(x + vx, y + vy, false, ship.r); + + var ts = ship.size / 2; + for (var i = 0; i < ship.mounts.length; i++) { + if (ship.turrets[i]) { + pallet.image(turr, ship.mounts[i][0] - ts, ship.mounts[i][1] - ts, 0); + } + } pallet.image(ship.team == 'a' ? teama : teamb, 0, 0, 0); + pallet.image(ship.move[0] ? thr8 : thr0, 0, 0, 0); pallet.image(img, 0, 0, 0); pallet.image(ship.move[0] ? thr8 : thr0, 0, 0, 0); diff --git a/public/js/starbugs/world/ship.js b/public/js/starbugs/world/ship.js index 54d48d5..6cfa427 100644 --- a/public/js/starbugs/world/ship.js +++ b/public/js/starbugs/world/ship.js @@ -9,6 +9,14 @@ function Ship(data) { this.rvel = data.delta[5]; this.hull = '01'; this.move = []; + this.mounts = data.mounts; + this.turrets = data.turrets; + this.frame = data.frame; + this.size = { + 'small': 8, + 'medium': 16, + 'large': 24 + }[data.size]; this.lastMove = []; this.bodyType = 'ship'; this.com = { diff --git a/server/game/room/world/beam.js b/server/game/room/world/beam.js new file mode 100644 index 0000000..a34f982 --- /dev/null +++ b/server/game/room/world/beam.js @@ -0,0 +1,11 @@ +'use strict'; + +const Discharge = require('./discharge.js'); + +class Beam extends Discharge { + constructor() { + super(); + } +} + +module.exports = Beam; diff --git a/server/game/room/world/body.js b/server/game/room/world/body.js index 5a7efab..0aed937 100644 --- a/server/game/room/world/body.js +++ b/server/game/room/world/body.js @@ -29,6 +29,16 @@ class Body { this.b2body.ApplyTorque(f); } + tick() { + let pos = this.b2body.GetPosition(); + let bounds = this.world.bounds; + + if(pos.x < bounds.left) this.applyForce(0.003, 0); + if(pos.x > bounds.right) this.applyForce(-0.003, 0); + if(pos.y < bounds.top) this.applyForce(0, 0.003); + if(pos.y > bounds.bottom) this.applyForce(-0, -0.003); + } + packDelta() { let pos = this.b2body.GetPosition(); let vel = this.b2body.GetLinearVelocity(); diff --git a/server/game/room/world/discharge.js b/server/game/room/world/discharge.js new file mode 100644 index 0000000..e69de29 diff --git a/server/game/room/world/index.js b/server/game/room/world/index.js index e777415..f49668e 100644 --- a/server/game/room/world/index.js +++ b/server/game/room/world/index.js @@ -13,6 +13,13 @@ class World { this.ships = new Map(); this.players = new Set(); this.room = room; + + this.bounds = { + left: -5, + right: 50, + top: -15, + bottom: 15 + } } addPlayer(player) { @@ -83,7 +90,10 @@ class World { self.physics.step(); if (Math.random() < 0.1) { - self.bodies.forEach(body => body.applyDelta()); + self.bodies.forEach(body => { + body.applyDelta(), + body.tick(); + }); } } } diff --git a/server/game/room/world/missile.js b/server/game/room/world/missile.js new file mode 100644 index 0000000..4f3fb37 --- /dev/null +++ b/server/game/room/world/missile.js @@ -0,0 +1,36 @@ +'use strict'; + +const Body = require('./bodies.js'); + +class Missile extends Body { + constructor(world, source) { + super(world); + + this.source = source; + this.player = source.player; + + this.frame = [[[0, 0], [0, 10], [3, 10], [3, 0]]]; + } + + detonate() { + // Blow up stuff. + this.world.removeBody(this); + } + + packTypeDelta() { + return []; + } + + packFull() { + return { + type: 'missile', + id: this.id, + source: this.source.id, + team: this.player.team, + frame: this.frame, + delta: this.packDelta() + }; + } +} + +module.exports = Projectile; diff --git a/server/game/room/world/projectile.js b/server/game/room/world/projectile.js new file mode 100644 index 0000000..ec784c6 --- /dev/null +++ b/server/game/room/world/projectile.js @@ -0,0 +1,11 @@ +'use strict'; + +const Discharge = require('./discharge.js'); + +class Projectile extends Discharge { + constructor() { + super(); + } +} + +module.exports = Projectile; diff --git a/server/game/room/world/ship.js b/server/game/room/world/ship.js index 6c9e3db..fc03c15 100644 --- a/server/game/room/world/ship.js +++ b/server/game/room/world/ship.js @@ -1,7 +1,7 @@ 'use strict'; const defaults = require('./traits/defaults.json'); -const hulls = require('./traits/hulls.json'); +const shipTraits = require('./traits/ships.json'); const Body = require('./body.js'); @@ -9,9 +9,15 @@ class Ship extends Body { constructor(world, pos, player, build) { super(world); - this.build = build || defaults.spawnShip.build; + build = build || {}; + this.class = build.ship || defaults.spawnShip.ship; + this.turrets = build.turrets || defaults.spawnShip.turrets; + let traits = shipTraits[this.class]; + this.frame = traits.hull; + this.power = traits.power; + this.mounts = traits.mounts; + this.size = traits.size; this.player = player; - this.frame = hulls[this.build.hull]; this.type = 'ship'; this.thrust = { @@ -19,8 +25,6 @@ class Ship extends Body { left: 0, right: 0 } - - this.power = this.build.power; } move(data) { @@ -66,7 +70,10 @@ class Ship extends Body { type: 'ship', id: this.id, team: this.player.team, - build: this.build, + frame: this.frame, + mounts: this.mounts, + turrets: this.turrets, + size: this.size, delta: this.packDelta() }; } diff --git a/server/game/room/world/traits/defaults.json b/server/game/room/world/traits/defaults.json index 2584ea2..1e29708 100644 --- a/server/game/room/world/traits/defaults.json +++ b/server/game/room/world/traits/defaults.json @@ -1,13 +1,6 @@ { "spawnShip": { - "build": { - "hull": "01", - "turrets": [0], - "power": { - "forward": 0.0015, - "back": 0, - "rotation": 0.0001 - } - } + "ship": "01", + "turrets": ["01", "01"] } } diff --git a/server/game/room/world/traits/hulls.json b/server/game/room/world/traits/hulls.json deleted file mode 100644 index 4e027b3..0000000 --- a/server/game/room/world/traits/hulls.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "01": [ - [ - [1, 28], - [31, 28], - [31, 19], - [19, 2], - [13, 2], - [1, 19] - ] - ] -} diff --git a/server/game/room/world/traits/ships.json b/server/game/room/world/traits/ships.json new file mode 100644 index 0000000..874ecbd --- /dev/null +++ b/server/game/room/world/traits/ships.json @@ -0,0 +1,25 @@ +{ + "01": { + "name": "Aiwodge", + "size": "small", + "power": { + "forward": 0.0015, + "back": 0, + "rotation": 0.0001 + }, + "hull": [ + [ + [3, 1], + [3, 30], + [12, 30], + [29, 18], + [29, 13], + [12, 1] + ] + ], + "mounts": [ + [18, 4], + [18, 27] + ] + } +}