diff --git a/app/Game/Channel/GameController.js b/app/Game/Channel/GameController.js index a977d08..571b088 100755 --- a/app/Game/Channel/GameController.js +++ b/app/Game/Channel/GameController.js @@ -202,6 +202,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N this.spawnPlayer(player, 0); }; + // FIXME: remove this method GameController.prototype.onResetLevel = function(userId) { console.log('OH NO!!! ON RESET LEVEL IS CALLED AND RESPAWNES PLAYERS'); @@ -214,7 +215,6 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N }; GameController.prototype.destroy = function() { - console.log("clearTimeout") clearTimeout(this.animationTimeout); clearTimeout(this.worldUpdateTimeout); diff --git a/app/Game/Channel/Player.js b/app/Game/Channel/Player.js index 26e5c51..5d4245f 100755 --- a/app/Game/Channel/Player.js +++ b/app/Game/Channel/Player.js @@ -65,12 +65,12 @@ function (Parent, Nc) { if(this.stats.health < 0) this.stats.health = 0; - this.broadcastStats(); - if(this.stats.health <= 0) { if(enemy != this) enemy.score(); this.kill(enemy, byItem); } + + this.broadcastStats(); }; Player.prototype.spawn = function(x, y) { diff --git a/app/Game/Client/GameController.js b/app/Game/Client/GameController.js index 9a06d95..8b01659 100755 --- a/app/Game/Client/GameController.js +++ b/app/Game/Client/GameController.js @@ -189,6 +189,23 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque throw new Exception("No player with id: " + options.playerId); } player.setStats(options.stats); + + var playersArray = []; + for (var key in this.players) { + playersArray.push(this.players[key]); + } + + var sortedPlayers = playersArray.sort(function(a,b) { + 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; + }); + + Nc.trigger(Nc.ns.client.view.gameStats.update, sortedPlayers); }; GameController.prototype.onPlayerKill = function(options) { @@ -238,23 +255,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque }; GameController.prototype.toggleGameStats = function(show) { - - var playersArray = []; - for (var key in this.players) { - playersArray.push(this.players[key]); - } - - var sortedPlayers = playersArray.sort(function(a,b) { - 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; - }); - - Nc.trigger(Nc.ns.client.view.gameStats.toggle, show, sortedPlayers); + Nc.trigger(Nc.ns.client.view.gameStats.toggle, show); }; GameController.prototype.destroy = function() { diff --git a/app/Game/Client/View/Abstract/Layer.js b/app/Game/Client/View/Abstract/Layer.js index 5952402..435e3a3 100644 --- a/app/Game/Client/View/Abstract/Layer.js +++ b/app/Game/Client/View/Abstract/Layer.js @@ -1,8 +1,9 @@ define([ "Lib/Utilities/Abstract", + "Lib/Utilities/NotificationCenter" ], -function (Abstract) { +function (Abstract, Nc) { "use strict"; diff --git a/app/Game/Client/View/Pixi/GameStats.js b/app/Game/Client/View/Pixi/GameStats.js index 8ef26dd..d1842e0 100644 --- a/app/Game/Client/View/Pixi/GameStats.js +++ b/app/Game/Client/View/Pixi/GameStats.js @@ -46,7 +46,6 @@ function (PIXI, Nc, Settings, ColorConverter) { this.container.addChild(this.dialog); this.graphics = new PIXI.Graphics(); - // this.dialog.addChild(this.graphics); /* gameContainer @@ -61,62 +60,72 @@ function (PIXI, Nc, Settings, ColorConverter) { */ this.container.visible = false; + this.sortedPlayers = []; - Nc.on(Nc.ns.client.view.gameStats.toggle, this.toggle, this); + this.ncTokens = [ + Nc.on(Nc.ns.client.view.gameStats.toggle, this.toggle, this), + Nc.on(Nc.ns.client.view.gameStats.update, this.update, this) + ]; } GameStats.prototype.getInfoContainer = function() { return this.container; }; - GameStats.prototype.toggle = function(show, sortedPlayers) { + GameStats.prototype.toggle = function(show) { if(show) { - - this.background.clear(); - this.graphics.clear(); - this.dialog.removeChildren(); - - // redraw background - this.background.beginFill(this.style.colors.background); - this.background.drawRect(0, 0, Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT); - this.background.endFill(); - - // redraw text and graphics - - var string = "" + - " #".pad(7, true) + " " + - "Name".pad(12, true) + - "Score".pad(6, false) + - "Deaths".pad(7, false) + - "Health".pad(9, false) + " "; - - var line = new PIXI.Text(string, { - font: "normal " + this.style.fontSize + "px 'Joystix'", - fill: this.style.colors.headline - }); - - line.position = new PIXI.Point(0, 0); - this.dialog.addChild(line); - - this.drawPlayers(sortedPlayers); - - var x = Settings.STAGE_WIDTH / 2 - this.dialog.getBounds().width / 2, - y = Settings.STAGE_HEIGHT / 2 - (sortedPlayers.length + 1) * (this.style.line.height + this.style.line.spacing) / 2; - this.dialog.position = new PIXI.Point(x, y); - - this.dialog.addChild(this.graphics); - + this.redraw(); // show stats with filters this.container.visible = true; this.gameContainer.filters = this.filters; this.filters.forEach(function(filter) { filter.dirty = true; }); - } else { this.container.visible = false; this.gameContainer.filters = null; } } + GameStats.prototype.update = function(sortedPlayers) { + this.sortedPlayers = sortedPlayers; + this.redraw(); + }; + + GameStats.prototype.redraw = function() { + this.background.clear(); + this.graphics.clear(); + this.dialog.removeChildren(); + + // redraw background + this.background.beginFill(this.style.colors.background); + this.background.drawRect(0, 0, Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT); + this.background.endFill(); + + // redraw text and graphics + + var string = "" + + " #".pad(7, true) + " " + + "Name".pad(12, true) + + "Score".pad(6, false) + + "Deaths".pad(7, false) + + "Health".pad(9, false) + " "; + + var line = new PIXI.Text(string, { + font: "normal " + this.style.fontSize + "px 'Joystix'", + fill: this.style.colors.headline + }); + + line.position = new PIXI.Point(0, 0); + this.dialog.addChild(line); + + this.drawPlayers(this.sortedPlayers); + + var x = Settings.STAGE_WIDTH / 2 - this.dialog.getBounds().width / 2, + y = Settings.STAGE_HEIGHT / 2 - (this.sortedPlayers.length + 1) * (this.style.line.height + this.style.line.spacing) / 2; + this.dialog.position = new PIXI.Point(x, y); + + this.dialog.addChild(this.graphics); + }; + GameStats.prototype.drawPlayers = function(sortedPlayers) { sortedPlayers.forEach(function(player, i) { @@ -184,6 +193,12 @@ function (PIXI, Nc, Settings, ColorConverter) { this.graphics.endFill(); } }; + + GameStats.prototype.destroy = function() { + for (var i = 0; i < this.ncTokens.length; i++) { + Nc.off(this.ncTokens[i]); + }; + }; return GameStats; diff --git a/app/Game/Client/View/Pixi/Layers/Messages.js b/app/Game/Client/View/Pixi/Layers/Messages.js index 3007c8f..08c4f99 100644 --- a/app/Game/Client/View/Pixi/Layers/Messages.js +++ b/app/Game/Client/View/Pixi/Layers/Messages.js @@ -50,7 +50,7 @@ function (Parent, PIXI, Nc, Settings) { var self = this; setTimeout(function(){ self.mainText.visible = false; - }, 2000); + }, Settings.SCORE_MESSAGE_TIMEOUT); } diff --git a/app/Game/Config/Settings.js b/app/Game/Config/Settings.js index 52602ee..a13491a 100755 --- a/app/Game/Config/Settings.js +++ b/app/Game/Config/Settings.js @@ -55,6 +55,7 @@ function () { RAGDOLL_DESTRUCTION_TIME: 10, VIEWPORT_SPEED_FACTOR: 640, VIEWPORT_LOOK_AHEAD: 0.1, + SCORE_MESSAGE_TIMEOUT: 3500, // restitution: bouncyness, friction: rubbing, density: mass TILE_FRICTION: 0.99, diff --git a/app/Lib/Utilities/NotificationCenter.js b/app/Lib/Utilities/NotificationCenter.js index fb4967e..33f8eb7 100755 --- a/app/Lib/Utilities/NotificationCenter.js +++ b/app/Lib/Utilities/NotificationCenter.js @@ -66,7 +66,8 @@ function (Exception) { }, gameStats: { toggle: null, - kill: null + kill: null, + update: null }, swiper: { swipe: null,