Commit 52d8f9d0 authored by Terence Martin's avatar Terence Martin

Fix a bug; do not reap balls that are hidden

Yesterday's woes are caused by the fact that the update loop is
constantly trying to reap hidden balls by marking them as dead.

This is an issue because a dead ball will not render or update, which
means that any computer balls that are hidden are almost immediately
killed, causing them to no longer update even though they're still in
the maze.

Since we render all balls that are alive, this means that once the
scene is set up with a set of live balls, it always looks like this
even when the balls are swapped into the maze, because they won't
overwrite themselves. Grrr.
parent 249f7e6e
......@@ -4138,6 +4138,30 @@ var nurdz;
}
return retVal;
};
/**
* Scan the maze to find all entities that are ball entities that are
* currently marked as hidden, and remove them from the maze by setting
* that position in the maze to null.
*
* The return value indicates how many such balls were removed from the
* maze during this call.
*
* @returns {number} the number of removed balls during this call, which
* may be 0.
*/
Maze.prototype.clearHiddenBalls = function () {
var retVal = 0;
for (var row = 0; row < game.MAZE_HEIGHT - 1; row++) {
for (var col = 1; col < game.MAZE_WIDTH - 2; col++) {
var ball = this._contents.getCellAt(col, row);
if (ball != null && ball.name == "ball" && ball.isHidden) {
this._contents.clearCellAt(col, row);
retVal++;
}
}
}
return retVal;
};
/**
* Select the next ball on the screen that should start it's final
* descent through the maze.
......@@ -4190,7 +4214,7 @@ var nurdz;
// When this happens, we can set the flag that indicates that the
// ball move is finalized, so that the update code can trigger a
// check to see if all balls have been played or not.
if (this.reapHiddenEntitiesFromPool(this._balls) > 0)
if (this.clearHiddenBalls() > 0)
this._ballMoveFinalized = true;
// Reap any dead gray bricks; these are the gray bricks that have
// been vanished out of the level because all of the balls have been
......
......@@ -735,6 +735,37 @@ module nurdz.game
return retVal;
}
/**
* Scan the maze to find all entities that are ball entities that are
* currently marked as hidden, and remove them from the maze by setting
* that position in the maze to null.
*
* The return value indicates how many such balls were removed from the
* maze during this call.
*
* @returns {number} the number of removed balls during this call, which
* may be 0.
*/
private clearHiddenBalls () : number
{
let retVal = 0;
for (let row = 0 ; row < MAZE_HEIGHT - 1 ; row++)
{
for (let col = 1 ; col < MAZE_WIDTH - 2 ; col++)
{
let ball = <Ball> this._contents.getCellAt (col, row);
if (ball != null && ball.name == "ball" && ball.isHidden)
{
this._contents.clearCellAt (col, row);
retVal++;
}
}
}
return retVal;
}
/**
* Select the next ball on the screen that should start it's final
* descent through the maze.
......@@ -797,7 +828,7 @@ module nurdz.game
// When this happens, we can set the flag that indicates that the
// ball move is finalized, so that the update code can trigger a
// check to see if all balls have been played or not.
if (this.reapHiddenEntitiesFromPool (this._balls) > 0)
if (this.clearHiddenBalls () > 0)
this._ballMoveFinalized = true;
// Reap any dead gray bricks; these are the gray bricks that have
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment