diff --git a/server/game/room/world/beam.js b/server/game/room/world/beam.js deleted file mode 100644 index a34f982..0000000 --- a/server/game/room/world/beam.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -const Discharge = require('./discharge.js'); - -class Beam extends Discharge { - constructor() { - super(); - } -} - -module.exports = Beam; diff --git a/server/game/room/world/asteroid.js b/server/game/room/world/body/asteroid.js similarity index 100% rename from server/game/room/world/asteroid.js rename to server/game/room/world/body/asteroid.js diff --git a/server/game/room/world/body.js b/server/game/room/world/body/body.js similarity index 100% rename from server/game/room/world/body.js rename to server/game/room/world/body/body.js diff --git a/server/game/room/world/body/projectile/grapple.js b/server/game/room/world/body/projectile/grapple.js new file mode 100644 index 0000000..c026a4c --- /dev/null +++ b/server/game/room/world/body/projectile/grapple.js @@ -0,0 +1,69 @@ +'use strict'; + +const Projectile = require('./projectile.js'); +const Rope = require('../copula/rope.js'); + +class Grapple extends Projectile { + constructor(world, pos, source) { + super(world); + + this.x = pos.x * 32; + this.y = pos.y * 32; + this.xvel = pos.xvel; + this.yvel = pos.yvel; + this.r = pos.r; + this.xvel += Math.cos(this.r) * 0.2; + this.yvel += Math.sin(this.r) * 0.2; + + this.source = source; + this.player = source.player; + this.rope = new Rope(this, this); + + this.type = 'grapple'; + this.frame = [ + [[0, -8], [5, -12], [4, 0], [0, 0]], + [[0, 0], [4, 0], [5, 12], [0, 8]] + ]; + } + + contact(body) { + this.detonate(); + } + + detonate() { + this.world.explosion(this.center, 10); + this.world.room.broadcast('effect', { + type: 'explosion', + size: 10, + pos: this.center + }); + this.world.removeBody(this); + } + + tickType() { + let power = 0.004; + let x = Math.cos(this.b2body.GetAngleRadians()) * power; + let y = Math.sin(this.b2body.GetAngleRadians()) * power; + this.applyForce(x, y); + + if(this.fuel-- <= 0) { + this.detonate(); + } + } + + packTypeDelta() { + return []; + } + + packFull() { + return { + type: 'missile', + id: this.id, + source: this.source.id, + frame: this.frame, + delta: this.packDelta() + }; + } +} + +module.exports = Missile; diff --git a/server/game/room/world/missile.js b/server/game/room/world/body/projectile/missile.js similarity index 92% rename from server/game/room/world/missile.js rename to server/game/room/world/body/projectile/missile.js index 1146456..b03ac89 100644 --- a/server/game/room/world/missile.js +++ b/server/game/room/world/body/projectile/missile.js @@ -1,8 +1,8 @@ 'use strict'; -const Body = require('./body.js'); +const Projectile = require('./projectile.js'); -class Missile extends Body { +class Missile extends Projectile { constructor(world, pos, source) { super(world); diff --git a/server/game/room/world/body/projectile/projectile.js b/server/game/room/world/body/projectile/projectile.js new file mode 100644 index 0000000..09e63c3 --- /dev/null +++ b/server/game/room/world/body/projectile/projectile.js @@ -0,0 +1,11 @@ +'use strict'; + +const Body = require('../body.js'); + +class Projectile extends Body { + constructor(world) { + super(world); + } +} + +module.exports = Projectile; diff --git a/server/game/room/world/discharge.js b/server/game/room/world/body/rope.js similarity index 100% rename from server/game/room/world/discharge.js rename to server/game/room/world/body/rope.js diff --git a/server/game/room/world/ship.js b/server/game/room/world/body/ship.js similarity index 94% rename from server/game/room/world/ship.js rename to server/game/room/world/body/ship.js index b087b80..8447264 100644 --- a/server/game/room/world/ship.js +++ b/server/game/room/world/body/ship.js @@ -1,7 +1,7 @@ 'use strict'; -const defaults = require('./traits/defaults.json'); -const shipTraits = require('./traits/ships.json'); +const defaults = require('../traits/defaults.json'); +const shipTraits = require('../traits/ships.json'); const Body = require('./body.js'); diff --git a/server/game/room/world/structure.js b/server/game/room/world/body/structure.js similarity index 100% rename from server/game/room/world/structure.js rename to server/game/room/world/body/structure.js diff --git a/server/game/room/world/copula/copula.js b/server/game/room/world/copula/copula.js new file mode 100644 index 0000000..e9751bc --- /dev/null +++ b/server/game/room/world/copula/copula.js @@ -0,0 +1,10 @@ +'use strict'; + +class Copula { + constructor(b1, b2) { + this.b1 = b1; + this.b2 = b2; + } +} + +module.exports = Copula; diff --git a/server/game/room/world/copula/rope.js b/server/game/room/world/copula/rope.js new file mode 100644 index 0000000..0ebd0c4 --- /dev/null +++ b/server/game/room/world/copula/rope.js @@ -0,0 +1,11 @@ +'use strict'; + +const Copula = require('./copula.js'); + +class Rope extends Copula { + constructor(p1, p2) { + super(); + } +} + +module.exports = Rope; diff --git a/server/game/room/world/index.js b/server/game/room/world/index.js index ed5fbcc..c276b20 100644 --- a/server/game/room/world/index.js +++ b/server/game/room/world/index.js @@ -1,7 +1,7 @@ 'use strict'; const Physics = require('./physics.js'); -const Ship = require('./ship.js'); +const Ship = require('./body/ship.js'); const Spawner = require('./spawner.js'); const b2Vec2 = require('box2d-html5').b2Vec2; @@ -11,6 +11,7 @@ class World { this.physics = new Physics(); this.spawner = new Spawner(this); this.bodies = new Set(); + this.copulae = new Set(); this.structures = new Set(); this.asteroids = new Set(); this.missiles = new Set(); @@ -63,6 +64,12 @@ class World { this.room.broadcast('create', body.packFull()); } + addCopula(copula) { + this.copulae.add(copula); + this.physics.createCopula(copula); + this.room.broadcast('create', copula.packFull()); + } + applyDelta(body, data) { this.players.forEach(player => player.delta[body] = data); } @@ -93,6 +100,14 @@ class World { }; this.spawner.spawnAsteroid(pos.x, pos.y,Math.random() * 50 + 10); } + + let a1 = Array.from(this.asteroids)[Math.random() * this.asteroids.size]; + let a2 = Array.from(this.asteroids)[Math.random() * this.asteroids.size]; + + let copula = new (require('./copula/copula.js'))(a1, a2); + if (a1 != a2) { + this.physics.createCopula(copula); + } } removePlayer(player) { @@ -111,6 +126,11 @@ class World { this.room.broadcast('destroy', body.id); } + removeCopula(copula) { + this.copulae.delete(body); + this.room.broadcast('destroy', copula.id); + } + start() { this.interval = setInterval(_ => this.tick(this), 1000 / 60); } diff --git a/server/game/room/world/physics.js b/server/game/room/world/physics.js index 5723310..8ad0466 100644 --- a/server/game/room/world/physics.js +++ b/server/game/room/world/physics.js @@ -69,6 +69,10 @@ class Physics { //if (body.type == 'ship') console.log(b2body.GetLocalCenter()); } + createCopula(copula) { + + } + raycast(start, end) { let p1 = new b2Vec2(start.x, start.y); let p2 = new b2Vec2(end.x, end.y); diff --git a/server/game/room/world/projectile.js b/server/game/room/world/projectile.js deleted file mode 100644 index ec784c6..0000000 --- a/server/game/room/world/projectile.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -const Discharge = require('./discharge.js'); - -class Projectile extends Discharge { - constructor() { - super(); - } -} - -module.exports = Projectile; diff --git a/server/game/room/world/shot/beam.js b/server/game/room/world/shot/beam.js new file mode 100644 index 0000000..ae055de --- /dev/null +++ b/server/game/room/world/shot/beam.js @@ -0,0 +1,11 @@ +'use strict'; + +const Shot = require('./shot.js'); + +class Beam extends Shot { + constructor() { + super(); + } +} + +module.exports = Beam; diff --git a/server/game/room/world/shot/bullet.js b/server/game/room/world/shot/bullet.js new file mode 100644 index 0000000..0ce0886 --- /dev/null +++ b/server/game/room/world/shot/bullet.js @@ -0,0 +1,11 @@ +'use strict'; + +const Shot = require('./shot.js'); + +class Bullet extends Shot { + constructor() { + super(); + } +} + +module.exports = Bullet; diff --git a/server/game/room/world/shot/shot.js b/server/game/room/world/shot/shot.js new file mode 100644 index 0000000..4acd7d7 --- /dev/null +++ b/server/game/room/world/shot/shot.js @@ -0,0 +1,9 @@ +'use strict'; + +class Shot { + constructor() { + + } +} + +module.exports = Beam; diff --git a/server/game/room/world/spawner.js b/server/game/room/world/spawner.js index 18bce36..2f6f78a 100644 --- a/server/game/room/world/spawner.js +++ b/server/game/room/world/spawner.js @@ -1,7 +1,7 @@ 'use strict'; -const Asteroid = require('./asteroid.js'); -const Missile = require('./missile.js'); +const Asteroid = require('./body/asteroid.js'); +const Missile = require('./body/projectile/missile.js'); class Spawner { constructor(world) {