add start of ship controls
This commit is contained in:
parent
1027d980c1
commit
fcfe1e8790
10 changed files with 131 additions and 2 deletions
|
@ -5,6 +5,8 @@ const hulls = require('./traits/hulls.json');
|
|||
|
||||
const Body = require('./body.js');
|
||||
|
||||
const b2Vec2 = require('box2d-html5').b2Vec2;
|
||||
|
||||
class Ship extends Body {
|
||||
constructor(world, player, build) {
|
||||
super(world);
|
||||
|
@ -13,6 +15,28 @@ class Ship extends Body {
|
|||
this.player = player;
|
||||
this.structure = hulls[this.build.hull];
|
||||
}
|
||||
|
||||
move(data) {
|
||||
let b = this.b2body;
|
||||
|
||||
for(var i in b) {
|
||||
//if(typeof b[i] == 'function') console.log(i);
|
||||
}
|
||||
|
||||
if (data.forward) {
|
||||
//console.log('forward');
|
||||
b.ApplyLinearImpulse(b2Vec2(0, 500), b.GetWorldCenter());
|
||||
b.ApplyTorque(2000);
|
||||
}
|
||||
|
||||
if (data.left) {
|
||||
b.ApplyTorque(-20);
|
||||
}
|
||||
|
||||
if (data.right) {
|
||||
b.ApplyTorque(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Ship;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue