improve multiplayer

This commit is contained in:
Asraelite 2016-03-22 19:20:50 +00:00
parent 0aa259b874
commit 2fffe574c1
10 changed files with 76 additions and 19 deletions

View file

@ -1,8 +1,8 @@
function Asteroid(data) {
this.id = data.id;
this.x = data.delta[0];
this.y = data.delta[1];
this.r = data.delta[2];
this.x = data[0];
this.y = data[1];
this.r = data[2];
this.bodyType = 'asteroid';
this.frame = data.frame;
@ -16,6 +16,17 @@ function Asteroid(data) {
this.update = function(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.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;
}
}

View file

@ -1,5 +1,6 @@
function Ship(data) {
this.id = data.id;
this.team = data.team;
this.x = data.delta[0];
this.y = data.delta[1];
this.r = data.delta[4];
@ -30,6 +31,8 @@ function Ship(data) {
this.xvel = data[2];
this.yvel = data[3];
this.r = data[4];
this.rvel = data[5];
if(this != game.world.playerShip) this.move[0] = data[6];
}
this.updateMove = function() {
@ -38,4 +41,15 @@ function Ship(data) {
this.lastMove = Array.apply(0, this.move); // Bloody Javascript.
}
}
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;
if (this.move[1]) this.rvel -= 0.01;
if (this.move[2]) this.rvel += 0.01;
}
}

View file

@ -20,25 +20,25 @@ function World() {
y += Math.sin(a + r) * d;
return { x: x, y: y };
}
};
this.add = function(data) {
var body;
if (data.type == 'asteroid') body = new Asteroid(data);
if (data.type == 'ship') body = new Ship(data);
if (data.type == 'structure') body = new Structure(data);
this.bodies[body.id] = body;
}
};
this.remove = function(id) {
delete this.bodies[id];
}
};
this.clear = function() {
this.bodies = {};
this.playerShip = false;
}
};
this.update = function(data) {
this.playerShip = this.bodies[this.playerShipId];
@ -54,5 +54,11 @@ function World() {
if (data[id].destroy) delete this.bodies[id];
}
}
};
this.tick = function() {
for (var i in this.bodies) {
this.bodies[i].tick();
}
};
}