add client side physics

by god did this take a lot of debugging to get working
This commit is contained in:
Asraelite 2016-03-24 00:13:10 +00:00
parent 65f78ec3ac
commit 1412cabbb4
19 changed files with 697 additions and 71 deletions

View file

@ -4,15 +4,20 @@ function World() {
this.bodies = {};
this.playerShip = false;
this.playerShipId = false;
this.physics = new Physics();
var fr = false;
this.getCenter = function() {
if (!this.playerShip) return { x: 0, y: 0 };
var x = this.playerShip.getPos().x;
var y = this.playerShip.getPos().y;
var comx = this.playerShip.com.x;
var comy = this.playerShip.com.y;
var r = this.playerShip.r;
var x = this.playerShip.getPos().x * SCALE;
var y = this.playerShip.getPos().y * SCALE;
var comx = this.playerShip.com.x * SCALE;
var comy = this.playerShip.com.y * SCALE;
comx = 0;
comy = 0;
var r = this.playerShip.getPos().r;
var d = Math.sqrt(comx * comx + comy * comy);
var a = Math.atan2(comy, comx);
@ -28,15 +33,23 @@ function World() {
if (data.type == 'ship') body = new Ship(data);
if (data.type == 'structure') body = new Structure(data);
if(data.type == 'ship') console.log(body);
this.bodies[body.id] = body;
if(data.type == 'ship') console.log(this.bodies);
this.physics.createBody(body);
};
this.remove = function(id) {
console.log(id);
this.physics.removeBody(this.bodies[id]);
delete this.bodies[id];
};
this.clear = function() {
this.bodies = {};
for (var i in this.bodies) {
this.remove(i);
}
this.playerShip = false;
};
@ -57,6 +70,8 @@ function World() {
};
this.tick = function() {
this.physics.step();
for (var i in this.bodies) {
this.bodies[i].tick();
}