add ship rendering and damping

This commit is contained in:
Asraelite 2016-03-22 13:18:43 +00:00
parent 05ad81ed8d
commit 80bd84230d
22 changed files with 66 additions and 6 deletions

View file

@ -25,6 +25,8 @@ class Physics {
bodyDef.active = true;
bodyDef.linearVelocity = new b2Vec2(body.xvel / s || 0, body.yvel / s || 0);
bodyDef.angularVelocity = body.rvel || 0;
bodyDef.linearDamping = 0.001;
bodyDef.angularDamping = 0.001;
bodyDef.type = body.type == 'static' ?
Box2D.b2BodyType.b2_staticBody : Box2D.b2BodyType.b2_dynamicBody;
if (body.player) bodyDef.allowSleep = false;

View file

@ -22,18 +22,18 @@ class Ship extends Body {
}
if (data.forward) {
let power = 0.02;
let power = 0.05;
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.02);
this.applyTorque(-0.0001);
}
if (data.right) {
this.applyTorque(0.02);
this.applyTorque(0.0001);
}
}
}