add start of gun support
This commit is contained in:
parent
444533ce85
commit
65f78ec3ac
19 changed files with 141 additions and 29 deletions
11
server/game/room/world/beam.js
Normal file
11
server/game/room/world/beam.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
const Discharge = require('./discharge.js');
|
||||
|
||||
class Beam extends Discharge {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Beam;
|
|
@ -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();
|
||||
|
|
0
server/game/room/world/discharge.js
Normal file
0
server/game/room/world/discharge.js
Normal file
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
36
server/game/room/world/missile.js
Normal file
36
server/game/room/world/missile.js
Normal file
|
@ -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;
|
11
server/game/room/world/projectile.js
Normal file
11
server/game/room/world/projectile.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
const Discharge = require('./discharge.js');
|
||||
|
||||
class Projectile extends Discharge {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Projectile;
|
|
@ -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()
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
{
|
||||
"spawnShip": {
|
||||
"build": {
|
||||
"hull": "01",
|
||||
"turrets": [0],
|
||||
"power": {
|
||||
"forward": 0.0015,
|
||||
"back": 0,
|
||||
"rotation": 0.0001
|
||||
}
|
||||
}
|
||||
"ship": "01",
|
||||
"turrets": ["01", "01"]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"01": [
|
||||
[
|
||||
[1, 28],
|
||||
[31, 28],
|
||||
[31, 19],
|
||||
[19, 2],
|
||||
[13, 2],
|
||||
[1, 19]
|
||||
]
|
||||
]
|
||||
}
|
25
server/game/room/world/traits/ships.json
Normal file
25
server/game/room/world/traits/ships.json
Normal file
|
@ -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]
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue