mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +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) {
|
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);
|
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
|
// FIXME: remove this method
|
||||||
GameController.prototype.onResetLevel = function(userId) {
|
GameController.prototype.onResetLevel = function(userId) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ function (Parent, Nc, PlayerController) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function Player(id, physicsEngine, user) {
|
function Player(id, physicsEngine, user, revealedGameController) {
|
||||||
Parent.call(this, id, physicsEngine, user);
|
Parent.call(this, id, physicsEngine, user, revealedGameController);
|
||||||
|
|
||||||
this.playerController = new PlayerController(this);
|
this.playerController = new PlayerController(this);
|
||||||
}
|
}
|
||||||
|
|
@ -64,6 +64,12 @@ function (Parent, Nc, PlayerController) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Player.prototype.addDamage = function(damage, enemy, byItem) {
|
Player.prototype.addDamage = function(damage, enemy, byItem) {
|
||||||
|
|
||||||
|
// Prevent stats change (kills) after round has ended
|
||||||
|
if (this.revealedGameController.isInBetweenRounds()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.stats.health -= damage;
|
this.stats.health -= damage;
|
||||||
|
|
||||||
if(this.stats.health < 0) this.stats.health = 0;
|
if(this.stats.health < 0) this.stats.health = 0;
|
||||||
|
|
@ -119,7 +125,6 @@ function (Parent, Nc, PlayerController) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return Player;
|
return Player;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -16,9 +16,9 @@ function (Parent, Nc, Settings) {
|
||||||
this.healthBarViewVisible = false;
|
this.healthBarViewVisible = false;
|
||||||
this.initHealthBar();
|
this.initHealthBar();
|
||||||
|
|
||||||
this.ncTokens = [
|
this.ncTokens = (this.ncTokens || []).concat([
|
||||||
Nc.on(Nc.ns.client.game.events.render, this.render, this)
|
Nc.on(Nc.ns.client.game.events.render, this.render, this)
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Player.prototype = Object.create(Parent.prototype);
|
Player.prototype = Object.create(Parent.prototype);
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,6 @@ function () {
|
||||||
this._shift;
|
this._shift;
|
||||||
this._isJumping;
|
this._isJumping;
|
||||||
this._walkingDirectionStatus = 0;
|
this._walkingDirectionStatus = 0;
|
||||||
|
|
||||||
this.inBetweenRounds = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerController.prototype.moveLeft = function () {
|
PlayerController.prototype.moveLeft = function () {
|
||||||
|
|
@ -46,20 +44,17 @@ function () {
|
||||||
if(options) this.player.lookAt(options.x, options.y);
|
if(options) this.player.lookAt(options.x, options.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerController.prototype.setInBetweenRounds = function(inBetweenRounds) {
|
|
||||||
this.inBetweenRounds = !!inBetweenRounds;
|
|
||||||
};
|
|
||||||
|
|
||||||
PlayerController.prototype.isPlayerInputAllowed = function() {
|
|
||||||
return !this.inBetweenRounds;
|
|
||||||
};
|
|
||||||
|
|
||||||
PlayerController.prototype.update = function () {
|
PlayerController.prototype.update = function () {
|
||||||
if(this._walkingDirectionStatus != 0) {
|
if(this._walkingDirectionStatus != 0) {
|
||||||
this.player.move(this._walkingDirectionStatus);
|
this.player.move(this._walkingDirectionStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default behaviour - may be needed later?
|
||||||
|
PlayerController.prototype.isPlayerInputAllowed = function() {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
PlayerController.prototype.destroy = function() {
|
PlayerController.prototype.destroy = function() {
|
||||||
// extend if necessary
|
// extend if necessary
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -111,8 +111,8 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll, GameObject, Item, Assert)
|
||||||
delete this.players[userId];
|
delete this.players[userId];
|
||||||
};
|
};
|
||||||
|
|
||||||
GameController.prototype.createPlayer = function(user) {
|
GameController.prototype.createPlayer = function(user, revealedGameController) {
|
||||||
var player = new Player(user.id, this.physicsEngine, user);
|
var player = new Player(user.id, this.physicsEngine, user, revealedGameController);
|
||||||
this.players[user.id] = player;
|
this.players[user.id] = player;
|
||||||
return player;
|
return player;
|
||||||
};
|
};
|
||||||
|
|
@ -132,8 +132,6 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll, GameObject, Item, Assert)
|
||||||
};
|
};
|
||||||
|
|
||||||
GameController.prototype.destroy = function () {
|
GameController.prototype.destroy = function () {
|
||||||
var i = 0;
|
|
||||||
|
|
||||||
for(var player in this.players) {
|
for(var player in this.players) {
|
||||||
this.players[player].destroy();
|
this.players[player].destroy();
|
||||||
}
|
}
|
||||||
|
|
@ -150,7 +148,6 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll, GameObject, Item, Assert)
|
||||||
this.worldUpdateObjects = null;
|
this.worldUpdateObjects = null;
|
||||||
|
|
||||||
Nc.off(this.ncTokens);
|
Nc.off(this.ncTokens);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return GameController;
|
return GameController;
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,12 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, Matrix, RubeDollJson)
|
||||||
this.limits = [];
|
this.limits = [];
|
||||||
|
|
||||||
var chest = null;
|
var chest = null;
|
||||||
var world = physicsEngine.getWorld();
|
this.rubeLoader = new RubeLoader(RubeDollJson, physicsEngine.getWorldForRubeLoader());
|
||||||
this.rubeLoader = new RubeLoader(RubeDollJson, world);
|
|
||||||
|
|
||||||
this.loadRubeDollFromScene(options);
|
this.loadRubeDollFromScene(options);
|
||||||
|
|
||||||
Parent.call(this, physicsEngine, uid, options);
|
Parent.call(this, physicsEngine, uid, options);
|
||||||
world.DestroyBody(this.body);
|
physicsEngine.destroyBody(this.body);
|
||||||
this.body = this.limbs.chest;
|
this.body = this.limbs.chest;
|
||||||
delete this.limbs.chest;
|
delete this.limbs.chest;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ function (Doll, PlayerController, Settings, Nc, Exception, ColorConverter, Spect
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function Player (id, physicsEngine, user) {
|
function Player (id, physicsEngine, user, revealedGameController) {
|
||||||
this.stats = {
|
this.stats = {
|
||||||
health: 100,
|
health: 100,
|
||||||
deaths: 0,
|
deaths: 0,
|
||||||
|
|
@ -27,7 +27,9 @@ function (Doll, PlayerController, Settings, Nc, Exception, ColorConverter, Spect
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.spawned = false;
|
this.spawned = false;
|
||||||
this.holdingItem = null;
|
this.holdingItem = null;
|
||||||
|
this.inBetweenRounds = true;
|
||||||
this.spectatorDoll = new SpectatorDoll(this.physicsEngine, "spectatorDoll-" + this.id, this);
|
this.spectatorDoll = new SpectatorDoll(this.physicsEngine, "spectatorDoll-" + this.id, this);
|
||||||
|
this.revealedGameController = revealedGameController;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player.prototype.getNickname = function() {
|
Player.prototype.getNickname = function() {
|
||||||
|
|
@ -185,7 +187,11 @@ function (Doll, PlayerController, Settings, Nc, Exception, ColorConverter, Spect
|
||||||
}
|
}
|
||||||
|
|
||||||
Player.prototype.setInBetweenRounds = function(inBetweenRounds) {
|
Player.prototype.setInBetweenRounds = function(inBetweenRounds) {
|
||||||
return this.playerController.setInBetweenRounds(inBetweenRounds);
|
this.inBetweenRounds = inBetweenRounds;
|
||||||
|
};
|
||||||
|
|
||||||
|
Player.prototype.isInBetweenRounds = function() {
|
||||||
|
return this.inBetweenRounds;
|
||||||
};
|
};
|
||||||
|
|
||||||
return Player;
|
return Player;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue