add asteroids
This commit is contained in:
parent
0ceea5f4af
commit
0aa259b874
17 changed files with 246 additions and 37 deletions
|
@ -1,3 +0,0 @@
|
|||
function Body() {
|
||||
|
||||
}
|
21
public/js/starbugs/world/asteroid.js
Normal file
21
public/js/starbugs/world/asteroid.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
function Asteroid(data) {
|
||||
this.id = data.id;
|
||||
this.x = data.delta[0];
|
||||
this.y = data.delta[1];
|
||||
this.r = data.delta[2];
|
||||
this.bodyType = 'asteroid';
|
||||
this.frame = data.frame;
|
||||
|
||||
this.getPos = function() {
|
||||
return {
|
||||
x: this.x,
|
||||
y: this.y
|
||||
};
|
||||
}
|
||||
|
||||
this.update = function(data) {
|
||||
this.x = data[0];
|
||||
this.y = data[1];
|
||||
this.r = data[4];
|
||||
}
|
||||
}
|
|
@ -1,8 +1,11 @@
|
|||
function Ship(id) {
|
||||
this.id = id;
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.r = 0;
|
||||
function Ship(data) {
|
||||
this.id = data.id;
|
||||
this.x = data.delta[0];
|
||||
this.y = data.delta[1];
|
||||
this.r = data.delta[4];
|
||||
this.xvel = data.delta[2];
|
||||
this.yvel = data.delta[3];
|
||||
this.rvel = data.delta[5];
|
||||
this.hull = '01';
|
||||
this.move = [];
|
||||
this.lastMove = [];
|
||||
|
@ -21,6 +24,14 @@ function Ship(id) {
|
|||
}
|
||||
}
|
||||
|
||||
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.updateMove = function() {
|
||||
if (JSON.stringify(this.move) != JSON.stringify(this.lastMove) || true) {
|
||||
game.net.update(this.move);
|
||||
|
|
|
@ -22,6 +22,19 @@ function World() {
|
|||
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;
|
||||
|
@ -32,15 +45,14 @@ function World() {
|
|||
|
||||
for (var id in data) {
|
||||
if (!this.bodies[id]) {
|
||||
this.bodies[id] = new Ship(id);
|
||||
game.net.send('requestBodyData', id);
|
||||
continue;
|
||||
}
|
||||
|
||||
var body = this.bodies[id];
|
||||
body.x = data[id][0];
|
||||
body.y = data[id][1];
|
||||
body.r = data[id][2];
|
||||
|
||||
body.update(data[id]);
|
||||
|
||||
if (data[id].destroy) delete this.bodies[id];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue