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);
|
this.spawnPlayer(player, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// FIXME: remove this method
|
||||||
GameController.prototype.onResetLevel = function(userId) {
|
GameController.prototype.onResetLevel = function(userId) {
|
||||||
|
|
||||||
console.log('OH NO!!! ON RESET LEVEL IS CALLED AND RESPAWNES PLAYERS');
|
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() {
|
GameController.prototype.destroy = function() {
|
||||||
console.log("clearTimeout")
|
|
||||||
clearTimeout(this.animationTimeout);
|
clearTimeout(this.animationTimeout);
|
||||||
clearTimeout(this.worldUpdateTimeout);
|
clearTimeout(this.worldUpdateTimeout);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,12 +65,12 @@ function (Parent, Nc) {
|
||||||
|
|
||||||
if(this.stats.health < 0) this.stats.health = 0;
|
if(this.stats.health < 0) this.stats.health = 0;
|
||||||
|
|
||||||
this.broadcastStats();
|
|
||||||
|
|
||||||
if(this.stats.health <= 0) {
|
if(this.stats.health <= 0) {
|
||||||
if(enemy != this) enemy.score();
|
if(enemy != this) enemy.score();
|
||||||
this.kill(enemy, byItem);
|
this.kill(enemy, byItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.broadcastStats();
|
||||||
};
|
};
|
||||||
|
|
||||||
Player.prototype.spawn = function(x, y) {
|
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);
|
throw new Exception("No player with id: " + options.playerId);
|
||||||
}
|
}
|
||||||
player.setStats(options.stats);
|
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) {
|
GameController.prototype.onPlayerKill = function(options) {
|
||||||
|
|
@ -238,23 +255,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
||||||
};
|
};
|
||||||
|
|
||||||
GameController.prototype.toggleGameStats = function(show) {
|
GameController.prototype.toggleGameStats = function(show) {
|
||||||
|
Nc.trigger(Nc.ns.client.view.gameStats.toggle, 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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameController.prototype.destroy = function() {
|
GameController.prototype.destroy = function() {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
define([
|
define([
|
||||||
"Lib/Utilities/Abstract",
|
"Lib/Utilities/Abstract",
|
||||||
|
"Lib/Utilities/NotificationCenter"
|
||||||
],
|
],
|
||||||
|
|
||||||
function (Abstract) {
|
function (Abstract, Nc) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,6 @@ function (PIXI, Nc, Settings, ColorConverter) {
|
||||||
this.container.addChild(this.dialog);
|
this.container.addChild(this.dialog);
|
||||||
|
|
||||||
this.graphics = new PIXI.Graphics();
|
this.graphics = new PIXI.Graphics();
|
||||||
// this.dialog.addChild(this.graphics);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
gameContainer
|
gameContainer
|
||||||
|
|
@ -61,17 +60,37 @@ function (PIXI, Nc, Settings, ColorConverter) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.container.visible = false;
|
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() {
|
GameStats.prototype.getInfoContainer = function() {
|
||||||
return this.container;
|
return this.container;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameStats.prototype.toggle = function(show, sortedPlayers) {
|
GameStats.prototype.toggle = function(show) {
|
||||||
if(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.background.clear();
|
||||||
this.graphics.clear();
|
this.graphics.clear();
|
||||||
this.dialog.removeChildren();
|
this.dialog.removeChildren();
|
||||||
|
|
@ -98,24 +117,14 @@ function (PIXI, Nc, Settings, ColorConverter) {
|
||||||
line.position = new PIXI.Point(0, 0);
|
line.position = new PIXI.Point(0, 0);
|
||||||
this.dialog.addChild(line);
|
this.dialog.addChild(line);
|
||||||
|
|
||||||
this.drawPlayers(sortedPlayers);
|
this.drawPlayers(this.sortedPlayers);
|
||||||
|
|
||||||
var x = Settings.STAGE_WIDTH / 2 - this.dialog.getBounds().width / 2,
|
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.position = new PIXI.Point(x, y);
|
||||||
|
|
||||||
this.dialog.addChild(this.graphics);
|
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) {
|
GameStats.prototype.drawPlayers = function(sortedPlayers) {
|
||||||
sortedPlayers.forEach(function(player, i) {
|
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;
|
return GameStats;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -50,7 +50,7 @@ function (Parent, PIXI, Nc, Settings) {
|
||||||
var self = this;
|
var self = this;
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
self.mainText.visible = false;
|
self.mainText.visible = false;
|
||||||
}, 2000);
|
}, Settings.SCORE_MESSAGE_TIMEOUT);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ function () {
|
||||||
RAGDOLL_DESTRUCTION_TIME: 10,
|
RAGDOLL_DESTRUCTION_TIME: 10,
|
||||||
VIEWPORT_SPEED_FACTOR: 640,
|
VIEWPORT_SPEED_FACTOR: 640,
|
||||||
VIEWPORT_LOOK_AHEAD: 0.1,
|
VIEWPORT_LOOK_AHEAD: 0.1,
|
||||||
|
SCORE_MESSAGE_TIMEOUT: 3500,
|
||||||
|
|
||||||
// restitution: bouncyness, friction: rubbing, density: mass
|
// restitution: bouncyness, friction: rubbing, density: mass
|
||||||
TILE_FRICTION: 0.99,
|
TILE_FRICTION: 0.99,
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,8 @@ function (Exception) {
|
||||||
},
|
},
|
||||||
gameStats: {
|
gameStats: {
|
||||||
toggle: null,
|
toggle: null,
|
||||||
kill: null
|
kill: null,
|
||||||
|
update: null
|
||||||
},
|
},
|
||||||
swiper: {
|
swiper: {
|
||||||
swipe: null,
|
swipe: null,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue