Permalink
Browse files

another attempt to fix multiplayer

  • Loading branch information...
1 parent 8c58558 commit 453e94ee425b1bae9601b34d1890e383ee42816d @lauxley committed Oct 28, 2011
Showing with 16 additions and 8 deletions.
  1. +11 −4 client/js/Game.js
  2. +2 −1 client/js/Mesh.js
  3. +3 −3 client/js/Player.js
View
@@ -54,13 +54,16 @@ var Game = function() {
this.addPlayer = function(data) {
this.info('New player '+data.id+' Spawn point: x='+data.x+' y='+data.y);
- this.playerMap[data.id] = this.players.push(new Player(data));
+ this.playerMap[data.id] = this.players.push(new Player(data))-1;
+
};
this.removePlayer = function(id) {
this.info('player leaving '+id);
//TODO: what about existing shoots, bombs, etc ?
- _getPlayerById(id).destroy(); //clean destructor
+ //update the id->index map
+ for(i=this.playerMap[id]+1;i<this.players.length;i++) this.playerMap[this.player[i]] -= 1; //lol?
+ this._getPlayerById(id).destroy(); //clean destructor
this.players.splice(this.playerMap[id]);
delete this.playerMap[id];
};
@@ -70,8 +73,12 @@ var Game = function() {
{
if(data[i].id != this.me.id)
{
- if(this.playerMap[id] == undefined) this.addPlayer(data[i]);
- else this.players[playerMap[id]].updatePosition(data[i]);
+ if(this.playerMap[data[i].id] == undefined) {
+ this.addPlayer(data[i]);
+ }
+ else {
+ this.players[this.playerMap[data[i].id]].updateFromServer(data[i]);
+ }
}
}
};
View
@@ -116,7 +116,8 @@ var PlayerModel = function(player)
//update the position from datas received by the server, don't call this for the user
this.mesh.position.x = data.x;
this.mesh.position.y = data.y;
- this.mesh.rotation.x = data.r;
+ this.mesh.rotation.y = data.r;
+ this.mesh.updateMatrix();
};
}
View
@@ -23,9 +23,9 @@ var Player = function(data) {
this.updateFromServer = function(data) {
- this.position.x = data[i]['x'];
- this.position.y = data[i]['y'];
- this.position.r = data[i]['r'];
+ this.position.x = data.x;
+ this.position.y = data.y;
+ this.position.r = data.r;
this.model.updatePositions(data);
};

0 comments on commit 453e94e

Please sign in to comment.