added player health action view

This commit is contained in:
logsol 2014-02-17 16:30:59 +01:00
parent c3aee14f23
commit aa6fdaa2df
8 changed files with 214 additions and 44 deletions

View file

@ -58,10 +58,12 @@ function (Parent, NotificationCenter) {
Player.prototype.addDamage = function(damage, enemy) {
this.stats.health -= damage;
if(this.stats.health < 0) this.stats.health = 0;
if(this.stats.health <= 0) {
enemy.score();
this.kill();
this.kill(enemy);
} else {
this.broadcastStats();
}
@ -73,11 +75,14 @@ function (Parent, NotificationCenter) {
this.broadcastStats();
};
Player.prototype.kill = function() {
Parent.prototype.kill.call(this);
Player.prototype.kill = function(killedByPlayer) {
Parent.prototype.kill.call(this, killedByPlayer);
this.stats.deaths++;
this.broadcastStats();
NotificationCenter.trigger("broadcastGameCommand", "playerKill", this.id);
NotificationCenter.trigger("broadcastGameCommand", "playerKill", {
playerId: this.id,
killedByPlayerId: killedByPlayer.id
});
};
Player.prototype.score = function() {