Commit 9213c393 authored by Terence Martin's avatar Terence Martin

Score for balls at the goal line

When a ball reaches the goal at the bottom of the screen (regardless
of when this happens), score points for that ball.
parent 831ec388
......@@ -11,6 +11,11 @@ var nurdz;
* The number of points that a bonus brick is worth.
*/
game.BONUS_BRICK_SCORE = 10;
/**
* The number of points that it's worth to get a ball all the way to the
* bottom of the screen, where the goal line is.
*/
game.GOAL_BALL_SCORE = 60;
/**
* The number of points the human player has.
*/
......@@ -52,6 +57,16 @@ var nurdz;
adjustScore(ball.player, game.BONUS_BRICK_SCORE);
}
game.bonusBrickScore = bonusBrickScore;
/**
* Score points due to a ball reaching the goal line (the bottom of the
* maze).
*
* @param {Ball} ball the ball that reached the score line
*/
function goalBallScore(ball) {
adjustScore(ball.player, game.GOAL_BALL_SCORE);
}
game.goalBallScore = goalBallScore;
/**
* Render the scores of the two players to the screen. This renders the
* scores to a known position on screen.
......@@ -5117,9 +5132,11 @@ var nurdz;
* drop
*/
GameScene.prototype.ballDropComplete = function (ball, isFinal) {
// Did the ball reach the goal? This is good enough for testing.
if (ball.mapPosition.y == game.MAZE_HEIGHT - 2)
// Did the ball reach the goal?
if (ball.mapPosition.y == game.MAZE_HEIGHT - 2) {
game.goalBallScore(ball);
console.log("GOOOOOAL!");
}
// Now that the ball is done, where we go depends on where we came
// from.
switch (this.priorState) {
......
......@@ -5,6 +5,12 @@ module nurdz.game
*/
export const BONUS_BRICK_SCORE = 10;
/**
* The number of points that it's worth to get a ball all the way to the
* bottom of the screen, where the goal line is.
*/
export const GOAL_BALL_SCORE = 60;
/**
* The number of points the human player has.
*/
......@@ -52,6 +58,17 @@ module nurdz.game
adjustScore (ball.player, BONUS_BRICK_SCORE);
}
/**
* Score points due to a ball reaching the goal line (the bottom of the
* maze).
*
* @param {Ball} ball the ball that reached the score line
*/
export function goalBallScore (ball : Ball) : void
{
adjustScore (ball.player, GOAL_BALL_SCORE);
}
/**
* Render the scores of the two players to the screen. This renders the
* scores to a known position on screen.
......
......@@ -529,9 +529,12 @@ module nurdz.game
*/
ballDropComplete (ball : Ball, isFinal : boolean) : void
{
// Did the ball reach the goal? This is good enough for testing.
// Did the ball reach the goal?
if (ball.mapPosition.y == MAZE_HEIGHT - 2)
{
goalBallScore (ball);
console.log ("GOOOOOAL!");
}
// Now that the ball is done, where we go depends on where we came
// from.
......
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