This commit is contained in:
Jeena 2014-03-02 01:15:33 +01:00
parent 810a74a28b
commit 39bdac0d7b
12 changed files with 118 additions and 100 deletions

View file

@ -208,10 +208,12 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
};
var sortedPlayers = playersArray.sort(function(a,b) {
if(a.score > b.score) return 1;
if(a.score < b.score) return -1;
if(a.deaths < b.deaths) return 1;
if(a.deaths > b.deaths) return -1;
if(a.stats.score > b.stats.score) return -1;
if(a.stats.score < b.stats.score) return 1;
if(a.stats.deaths < b.stats.deaths) return -1;
if(a.stats.deaths > b.stats.deaths) return 1;
if(a.stats.health > b.stats.health) return -1;
if(a.stats.health < b.stats.health) return 1;
return 0;
});
@ -236,7 +238,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
var lines = [];
sortedPlayers.forEach(function(player, i) {
var name = player == this.me ? "You" : "Player " + (Object.keys(this.players).indexOf(player.id) + 1);
var name = player.getNickname();
lines.push(
pad("" + (i + 1) + ".", 2, false) + " " +
pad(name, 12, true) +

View file

@ -13,7 +13,6 @@ function (ProtocolHelper, GameController, User, Nc, Settings, DomController) {
this.socketLink = socketLink;
this.gameController = null;
this.users = {};
this.userId = null;
this.socketLink.on('connect', this.onConnect.bind(this));
this.socketLink.on('disconnect', this.onDisconnect.bind(this));
@ -57,12 +56,11 @@ function (ProtocolHelper, GameController, User, Nc, Settings, DomController) {
Networker.prototype.onJoinSuccess = function (options) {
console.log("join success")
this.userId = options.userId;
this.gameController = new GameController();
this.gameController.loadLevel(options.levelUid);
this.onUserJoined(options.userId);
this.onUserJoined(options.user);
if (options.joinedUsers) {
for(var i = 0; i < options.joinedUsers.length; i++) {
@ -114,9 +112,10 @@ function (ProtocolHelper, GameController, User, Nc, Settings, DomController) {
// Commands from server
Networker.prototype.onUserJoined = function (userId) {
var user = new User(userId);
this.users[userId] = user;
Networker.prototype.onUserJoined = function (options) {
var user = new User(options.id, options);
console.log(options.nickname)
this.users[user.id] = user;
if (this.gameController
&& this.gameController.level

View file

@ -6,8 +6,8 @@ define([
function (Parent, Nc, Settings) {
function Player(id, physicsEngine) {
Parent.call(this, id, physicsEngine);
function Player(id, physicsEngine, user) {
Parent.call(this, id, physicsEngine, user);
this.playerInfoView = null;
this.playerInfoViewVisibleTimeout = null;
@ -81,6 +81,10 @@ function (Parent, Nc, Settings) {
}
};
Player.prototype.getNickname = function() {
return this.user.options.nickname;
};
Player.prototype.render = function() {
// dolls are self responsible