wingbase/public/static/js/wingbase/world/body.js
2016-03-29 01:14:32 +01:00

65 lines
1 KiB
JavaScript

//@10
class Body {
constructor(data) {
console.log(data);
this.interface = data.interface;
let s = this.interface.order.length + this.interface.fixtures;
this.interface.size = s;
this.id = data.id
this.frame = data.frame;
this.fixtures = data.fixtures;
this.b2body = false;
this.updated = 0;
game.world.update(data.delta);
this.com = {
x: 0,
y: 0
};
}
getPos() {
var pos = this.b2body.GetPosition();
var angle = this.b2body.GetAngle();
return {
x: pos.x,
y: pos.y,
r: angle
};
}
applyForce(x, y) {
var b = this.b2body;
b.ApplyForce(new b2Vec2(x, y), b.GetWorldCenter());
}
applyTorque(f) {
this.b2body.ApplyTorque(f);
}
update(data) {
let values = {};
Array.from(data).map((v, i) => {
values[this.interface.order[i]] = v
});
this.x = values.x;
this.y = values.y;
this.xvel = values.xvel;
this.yvel = values.yvel;
this.r = values.r;
this.rvel = values.rvel;
this.updated = 10;
this.updateType(values);
}
updateType() {
}
tick() {
}
}