Skip to content

Commit

Permalink
Added drawing of scores below grid
Browse files Browse the repository at this point in the history
  • Loading branch information
ab2163 committed Feb 25, 2025
1 parent 5d0cebc commit 3a89fe4
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions docs/GameState.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GameState{
isGameOver;
CANVAS_WIDTH = 960;
GRID_HEIGHT = 480;
LOWER_PANEL_HT = 200
LOWER_PANEL_HT = 50;
CANVAS_HEIGHT = this.GRID_HEIGHT + this.LOWER_PANEL_HT;
gameMap;
TANK1X = 200;
Expand Down Expand Up @@ -70,7 +70,9 @@ class GameState{
for(let collCnt = 0; collCnt < this.collectibleList.length; collCnt++){
this.collectibleList[collCnt].draw();
}


//draw scores of players
this.drawScores();
}

update(){
Expand Down Expand Up @@ -176,4 +178,22 @@ class GameState{
checkProjectileWallOverlaps(){
}

drawScores(){
//obtain strings for scores
let scoreString1 = "Player 1 Score : ";
let scoreString2 = "Player 2 Score : ";
scoreString1 = scoreString1.concat(this.player1Score.toString());
scoreString2 = scoreString2.concat(this.player2Score.toString());

//display scores below the grid
let xMargin = 25;
let yMargin = 25;
textFont('Courier New');
textStyle(BOLD);
textSize(this.LOWER_PANEL_HT - yMargin);
textAlign(LEFT, TOP);
text(scoreString1, xMargin, this.GRID_HEIGHT + yMargin);
textAlign(RIGHT, TOP);
text(scoreString2, this.CANVAS_WIDTH - xMargin, this.GRID_HEIGHT + yMargin);
}
}

0 comments on commit 3a89fe4

Please sign in to comment.