mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fixes the sending and rendering of game stats
This commit is contained in:
parent
cad112419d
commit
a66a327386
8 changed files with 81 additions and 62 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
define([
|
||||
"Lib/Utilities/Abstract",
|
||||
"Lib/Utilities/NotificationCenter"
|
||||
],
|
||||
|
||||
function (Abstract) {
|
||||
function (Abstract, Nc) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
|
|
|||
|
|
@ -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,17 +60,37 @@ 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.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();
|
||||
|
|
@ -98,24 +117,14 @@ function (PIXI, Nc, Settings, ColorConverter) {
|
|||
line.position = new PIXI.Point(0, 0);
|
||||
this.dialog.addChild(line);
|
||||
|
||||
this.drawPlayers(sortedPlayers);
|
||||
this.drawPlayers(this.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;
|
||||
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);
|
||||
|
||||
// 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.drawPlayers = function(sortedPlayers) {
|
||||
sortedPlayers.forEach(function(player, i) {
|
||||
|
|
@ -185,6 +194,12 @@ function (PIXI, Nc, Settings, ColorConverter) {
|
|||
}
|
||||
};
|
||||
|
||||
GameStats.prototype.destroy = function() {
|
||||
for (var i = 0; i < this.ncTokens.length; i++) {
|
||||
Nc.off(this.ncTokens[i]);
|
||||
};
|
||||
};
|
||||
|
||||
return GameStats;
|
||||
|
||||
});
|
||||
|
|
@ -50,7 +50,7 @@ function (Parent, PIXI, Nc, Settings) {
|
|||
var self = this;
|
||||
setTimeout(function(){
|
||||
self.mainText.visible = false;
|
||||
}, 2000);
|
||||
}, Settings.SCORE_MESSAGE_TIMEOUT);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -66,7 +66,8 @@ function (Exception) {
|
|||
},
|
||||
gameStats: {
|
||||
toggle: null,
|
||||
kill: null
|
||||
kill: null,
|
||||
update: null
|
||||
},
|
||||
swiper: {
|
||||
swipe: null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue