mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
Prevents adding damage after round has ended
Because it created double round endings, which led to crashes. Also moved inBetweenRound state from PlayerController to GameController.
This commit is contained in:
parent
c068592915
commit
3a5af058ef
7 changed files with 36 additions and 26 deletions
|
|
@ -60,7 +60,11 @@ function (Parent, PhysicsEngine, Settings, requestAnimFrame, Nc, Box2D, Player,
|
|||
}
|
||||
|
||||
GameController.prototype.createPlayer = function(user) {
|
||||
var player = Parent.prototype.createPlayer.call(this, user);
|
||||
|
||||
var revealedGameController = {
|
||||
isInBetweenRounds: this.isInBetweenRounds.bind(this)
|
||||
};
|
||||
var player = Parent.prototype.createPlayer.call(this, user, revealedGameController);
|
||||
user.setPlayer(player);
|
||||
};
|
||||
|
||||
|
|
@ -232,6 +236,10 @@ function (Parent, PhysicsEngine, Settings, requestAnimFrame, Nc, Box2D, Player,
|
|||
}
|
||||
};
|
||||
|
||||
GameController.prototype.isInBetweenRounds = function() {
|
||||
return this.roundHasEnded;
|
||||
};
|
||||
|
||||
// FIXME: remove this method
|
||||
GameController.prototype.onResetLevel = function(userId) {
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ function (Parent, Nc, PlayerController) {
|
|||
|
||||
"use strict";
|
||||
|
||||
function Player(id, physicsEngine, user) {
|
||||
Parent.call(this, id, physicsEngine, user);
|
||||
function Player(id, physicsEngine, user, revealedGameController) {
|
||||
Parent.call(this, id, physicsEngine, user, revealedGameController);
|
||||
|
||||
this.playerController = new PlayerController(this);
|
||||
}
|
||||
|
|
@ -64,6 +64,12 @@ function (Parent, Nc, PlayerController) {
|
|||
};
|
||||
|
||||
Player.prototype.addDamage = function(damage, enemy, byItem) {
|
||||
|
||||
// Prevent stats change (kills) after round has ended
|
||||
if (this.revealedGameController.isInBetweenRounds()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.stats.health -= damage;
|
||||
|
||||
if(this.stats.health < 0) this.stats.health = 0;
|
||||
|
|
@ -118,7 +124,6 @@ function (Parent, Nc, PlayerController) {
|
|||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return Player;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue