reduce update packets sent
This commit is contained in:
parent
d6daed2e9b
commit
ef2d067b38
15 changed files with 67 additions and 14 deletions
|
@ -41,6 +41,8 @@ class Body {
|
|||
type: 'body',
|
||||
fixtures: this.mounts.length
|
||||
};
|
||||
|
||||
this.sleepTime = 0;
|
||||
}
|
||||
|
||||
destruct() {
|
||||
|
@ -88,6 +90,8 @@ class Body {
|
|||
if(pos.y < bounds.top) this.applyForce(0, 0.03);
|
||||
if(pos.y > bounds.bottom) this.applyForce(-0, -0.03);
|
||||
|
||||
this.sleepTime++;
|
||||
|
||||
this.tickType();
|
||||
}
|
||||
|
||||
|
@ -135,6 +139,15 @@ class Body {
|
|||
return {};
|
||||
}
|
||||
|
||||
get awake() {
|
||||
if (this.b2body.IsAwake()) {
|
||||
this.sleepTime = 0;
|
||||
return true;
|
||||
} else {
|
||||
return this.sleepTime < 50;
|
||||
}
|
||||
}
|
||||
|
||||
get com() {
|
||||
return {
|
||||
x: this.b2body.GetLocalCenter().x,
|
||||
|
|
|
@ -57,7 +57,8 @@ class Ship extends Body {
|
|||
this.thrust.left = packet.thrust[1];
|
||||
this.thrust.right = packet.thrust[2];
|
||||
|
||||
if (packet.fire[1]) this.launchMissile();
|
||||
packet.fire.forEach((m, i) => m ? this.mounts[i].fire(m) : 0);
|
||||
|
||||
if (packet.fire[0] && this.grapple) {
|
||||
this.grapple.release();
|
||||
} else if (packet.fire[0] && !this.grapple) {
|
||||
|
|
|
@ -4,8 +4,8 @@ const Fixture = require('./fixture.js');
|
|||
const Laser = require('./shot/laser.js');
|
||||
|
||||
class Blaster extends Fixture {
|
||||
constructor(hardpoint, data) {
|
||||
super(hardpoint, data);
|
||||
constructor(mount, data) {
|
||||
super(mount, data);
|
||||
}
|
||||
|
||||
fire() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const traits = require('../../traits/turrets.json');
|
||||
const traits = require('../../traits/fixtures.json');
|
||||
|
||||
class Fixture {
|
||||
constructor(mount, data) {
|
||||
|
@ -10,6 +10,8 @@ class Fixture {
|
|||
|
||||
let turretTraits = traits[data.type];
|
||||
|
||||
console.log(turretTraits);
|
||||
|
||||
this.rof = turretTraits.rateOfFire;
|
||||
|
||||
this.traversal = this.mount.traversal || false;
|
||||
|
|
|
@ -7,7 +7,7 @@ class Mount {
|
|||
this.ship = ship;
|
||||
|
||||
this.type = data.type || 'turret';
|
||||
this.fixture = fixture || false;
|
||||
this.fixture = fixture || false//new Fixture(fixture);
|
||||
this.size = data.size || 0;
|
||||
this.position = {
|
||||
x: data.pos[0],
|
||||
|
@ -27,6 +27,10 @@ class Mount {
|
|||
//this.fixture.destruct();
|
||||
}
|
||||
|
||||
fire() {
|
||||
console.log(this.fixture);
|
||||
}
|
||||
|
||||
packDelta() {
|
||||
return [this.traversal || 0];
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
class Shot {
|
||||
constructor() {
|
||||
constructor(pos) {
|
||||
|
||||
}
|
||||
|
||||
tick() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Shot;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue