clean client code
This commit is contained in:
parent
f3619ba891
commit
21a30ad212
18 changed files with 294 additions and 268 deletions
57
public/js/starbugs/world/body.js
Normal file
57
public/js/starbugs/world/body.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
//@10
|
||||
|
||||
class Body {
|
||||
constructor(data) {
|
||||
this.x = data.delta[0];
|
||||
this.y = data.delta[1];
|
||||
this.xvel = data.delta[2];
|
||||
this.yvel = data.delta[3];
|
||||
this.r = data.delta[4];
|
||||
this.rvel = data.delta[5];
|
||||
|
||||
this.id = data.id
|
||||
this.frame = data.frame;
|
||||
this.b2body = false;
|
||||
this.updated = 0;
|
||||
|
||||
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) {
|
||||
this.x = data[0];
|
||||
this.y = data[1];
|
||||
this.xvel = data[2]
|
||||
this.yvel = data[3];
|
||||
this.r = data[4];
|
||||
this.rvel = data[5];
|
||||
this.updated = 10;
|
||||
|
||||
this.updateType(data);
|
||||
}
|
||||
|
||||
updateType() {
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue