Added spawning gameCommand logic

This commit is contained in:
Logsol 2013-01-05 08:19:49 +01:00
parent 371592f167
commit fb5de522e5
8 changed files with 84 additions and 59 deletions

View file

@ -43,17 +43,6 @@ function (Parent, PhysicsEngine, ViewController, KeyboardController, Notificatio
}
}
GameController.prototype.meJoined = function (user) {
this.me = this.userJoined(user);
this.keyboardController = new KeyboardController(this.me, this);
}
GameController.prototype.userJoined = function (user) {
var player = Parent.prototype.userJoined.call(this, user);
//player.spawn(50, 50);
return player;
}
GameController.prototype.onWorldUpdate = function (updateData) {
var body = this.physicsEngine.world.GetBodyList();
@ -71,8 +60,24 @@ function (Parent, PhysicsEngine, ViewController, KeyboardController, Notificatio
}
GameController.prototype.onPlayerSpawn = function(user) {
GameController.prototype.onJoinMe = function (playerId) {
//this.onSpawnPlayer(options);
this.me = this.players[playerId];
this.keyboardController = new KeyboardController(this.me, this);
}
GameController.prototype.onSpawnPlayer = function(options) {
var playerId = options.id,
x = options.x,
y = options.y;
console.log(this.players, options);
var player = this.players[playerId];
player.spawn(x, y);
};
return GameController;

View file

@ -46,14 +46,12 @@ function (ProtocolHelper, GameController, User, NotificationCenter) {
this.gameController = new GameController();
this.gameController.loadLevel("default.json");
var user = new User(options.userId);
this.gameController.meJoined(user);
console.log("Joined Success", options);
this.onUserJoined(options.userId);
this.gameController.onJoinMe(options.userId);
if (options.others) {
for(var i = 0; i < options.others.length; i++) {
this.users[userId] = new User(options.others[i]);
this.onUserJoined(options.others[i]);
}
}
}
@ -73,10 +71,14 @@ function (ProtocolHelper, GameController, User, NotificationCenter) {
// Commands from server
Networker.prototype.onUserJoined = function (userId) {
this.users[userId] = new User(userId);
var user = new User(userId);
this.users[userId] = user;
this.gameController.userJoined(user);
}
Networker.prototype.onUserLeft = function (userId) {
var user = this.users[userId];
this.gameController.userLeft(user);
delete this.users[userId];
}