add client side physics
by god did this take a lot of debugging to get working
This commit is contained in:
parent
65f78ec3ac
commit
1412cabbb4
19 changed files with 697 additions and 71 deletions
|
@ -1,32 +1,36 @@
|
|||
function Asteroid(data) {
|
||||
this.id = data.id;
|
||||
this.x = data[0];
|
||||
this.y = data[1];
|
||||
this.r = data[2];
|
||||
this.x = data.delta[0];
|
||||
this.y = data.delta[1];
|
||||
this.r = data.delta[2];
|
||||
this.bodyType = 'asteroid';
|
||||
this.frame = data.frame;
|
||||
this.updated = false;
|
||||
|
||||
var b2Vec2 = Box2D.Common.Math.b2Vec2;
|
||||
var s = SCALE;
|
||||
|
||||
this.getPos = function() {
|
||||
var pos = this.b2body.GetPosition();
|
||||
var angle = this.b2body.GetAngle();
|
||||
return {
|
||||
x: this.x,
|
||||
y: this.y
|
||||
x: pos.x,
|
||||
y: pos.y,
|
||||
r: angle
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
this.update = function(data) {
|
||||
this.x = data[0];
|
||||
this.y = data[1];
|
||||
this.xvel = data[2];
|
||||
this.xvel = data[2]
|
||||
this.yvel = data[3];
|
||||
this.r = data[4];
|
||||
this.rvel = data[5];
|
||||
}
|
||||
this.updated = true;
|
||||
};
|
||||
|
||||
this.tick = function() {
|
||||
this.x += this.xvel * 10;
|
||||
this.y += this.yvel * 10;
|
||||
this.r += this.rvel * 10;
|
||||
this.xvel *= 0.98;
|
||||
this.yvel *= 0.98;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue