mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
preliminary spawning of other players
This commit is contained in:
parent
c4c48ab821
commit
a10a7a7319
3 changed files with 30 additions and 20 deletions
|
|
@ -48,6 +48,16 @@ function (Parent, PhysicsEngine, ViewController, KeyboardController, Notificatio
|
||||||
this.keyboardController = new KeyboardController(this.me, this);
|
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.userLeft = function (user) {
|
||||||
|
Parent.prototype.userLeft.call(user);
|
||||||
|
}
|
||||||
|
*/
|
||||||
GameController.prototype.processGameCommand = function (command, options) {
|
GameController.prototype.processGameCommand = function (command, options) {
|
||||||
|
|
||||||
if (command == "worldUpdate") {
|
if (command == "worldUpdate") {
|
||||||
|
|
|
||||||
|
|
@ -58,16 +58,15 @@ function (ProtocolHelper, GameController, User, NotificationCenter) {
|
||||||
var user = new User(options.userId);
|
var user = new User(options.userId);
|
||||||
this.gameController.meJoined(user);
|
this.gameController.meJoined(user);
|
||||||
|
|
||||||
console.log("Joined " + options.channelName);
|
console.log("Joined ", options);
|
||||||
|
|
||||||
|
// -> replace with decent command
|
||||||
/*
|
if (options.others && options.others.length > 0) {
|
||||||
if (options.userIds && options.userIds.length > 0) {
|
for(var i = 0; i < options.others.length; i++) {
|
||||||
for(var i = 0; i < options.userIds.length; i++) {
|
var user = {id: options.others[i]};
|
||||||
this.gameController.userJoined(options.userIds[i])
|
this.gameController.userJoined(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Networker.prototype.sendCommand = function (command, options) {
|
Networker.prototype.sendCommand = function (command, options) {
|
||||||
|
|
@ -75,6 +74,10 @@ function (ProtocolHelper, GameController, User, NotificationCenter) {
|
||||||
this.socketLink.send(message);
|
this.socketLink.send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Networker.prototype.sendGameCommand = function(command, options) {
|
||||||
|
var message = ProtocolHelper.encodeCommand(command, options);
|
||||||
|
this.sendCommand('gameCommand', message);
|
||||||
|
}
|
||||||
|
|
||||||
Networker.prototype.onMessage = function (message) {
|
Networker.prototype.onMessage = function (message) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
@ -86,16 +89,16 @@ function (ProtocolHelper, GameController, User, NotificationCenter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Networker.prototype.onUserJoined = function (userId) {
|
Networker.prototype.onUserJoined = function (userId) {
|
||||||
//this.gameController.userJoined(userId); -> replace with game command
|
// -> replace with game command
|
||||||
|
var user = {id: userId};
|
||||||
|
this.gameController.userJoined(user);
|
||||||
console.log("User " + userId + " joined");
|
console.log("User " + userId + " joined");
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
Networker.prototype.sendGameCommand = function (command, options) {
|
|
||||||
this.sendCommand('gameCommand', ProtocolHelper.assemble(command, options));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
Networker.prototype.onUserLeft = function (userId) {
|
Networker.prototype.onUserLeft = function (userId) {
|
||||||
//this.gameController.userLeft(userId); -> replace with game command
|
// -> replace with game command
|
||||||
|
var user = {id: userId};
|
||||||
|
this.gameController.userLeft(user);
|
||||||
console.log("User " + userId + " left");
|
console.log("User " + userId + " left");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,11 +128,6 @@ function (ProtocolHelper, GameController, User, NotificationCenter) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Networker.prototype.sendGameCommand = function(command, options) {
|
|
||||||
var message = ProtocolHelper.encodeCommand(command, options);
|
|
||||||
this.sendCommand('gameCommand', message);
|
|
||||||
};
|
|
||||||
|
|
||||||
return Networker;
|
return Networker;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -45,8 +45,10 @@
|
||||||
|
|
||||||
Channel.prototype.addUser = function (userId) {
|
Channel.prototype.addUser = function (userId) {
|
||||||
var user = new User(userId, this);
|
var user = new User(userId, this);
|
||||||
|
var others = Object.keys(this.users);
|
||||||
|
|
||||||
this.users[user.id] = user;
|
this.users[user.id] = user;
|
||||||
NotificationCenter.trigger('user/' + user.id + "/joinSuccess", {userId: user.id, channelName: this.name});
|
NotificationCenter.trigger('user/' + user.id + "/joinSuccess", {userId: user.id, channelName: this.name, others: others});
|
||||||
NotificationCenter.trigger('user/joined', user);
|
NotificationCenter.trigger('user/joined', user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue