add asteroids

This commit is contained in:
Asraelite 2016-03-22 18:34:11 +00:00
parent 0ceea5f4af
commit 0aa259b874
17 changed files with 246 additions and 37 deletions

View file

@ -6,12 +6,21 @@ const hulls = require('./traits/hulls.json');
const Body = require('./body.js');
class Ship extends Body {
constructor(world, player, build) {
constructor(world, pos, player, build) {
super(world);
this.build = build || defaults.spawnShip.build;
this.player = player;
this.structure = hulls[this.build.hull];
this.frame = hulls[this.build.hull];
this.type = 'ship';
this.thrust = {
forward: 0,
left: 0,
right: 0
}
this.power = this.build.power;
}
move(data) {
@ -25,20 +34,36 @@ class Ship extends Body {
}
if (data.forward) {
let power = 0.002;
let power = this.power.forward;
let x = Math.cos(this.b2body.GetAngleRadians()) * power;
let y = Math.sin(this.b2body.GetAngleRadians()) * power;
this.applyForce(x, y);
}
if (data.left) {
this.applyTorque(-0.0001);
this.applyTorque(-this.power.rotation);
}
if (data.right) {
this.applyTorque(0.0001);
this.applyTorque(this.power.rotation);
}
}
packTypeDelta() {
let t = this.thrust;
return [t.forward, t.left, t.right];
}
packFull() {
return {
type: 'ship',
id: this.id,
team: this.player.team,
build: this.build,
delta: this.packDelta()
};
}
}
module.exports = Ship;