Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add High Score Functionality #50

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
21 changes: 21 additions & 0 deletions game/src/hud.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var score = 0;
var scoreText;
var highScoreText2;
var highScore = 0;

var createHud = function() {
var hudTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
Expand All @@ -14,19 +16,38 @@ var createHud = function() {
scoreText.width = .5;
scoreText.height = .15;

// Create a High Score Text Block
highScoreText2 = new BABYLON.GUI.TextBlock();
highScoreText2.fontFamily = "Helvetica, sans-serif";
highScoreText2.color = "white";
highScoreText2.fontSize = 48;
highScoreText2.verticalAlignment = BABYLON.GUI.TextBlock.VERTICAL_ALIGNMENT_TOP;
highScoreText2.horizontalAlignment = BABYLON.GUI.TextBlock.HORIZONTAL_ALIGNMENT_LEFT;
highScoreText2.width = .5;
highScoreText2.height = .15;

updateScoreText();

hudTexture.addControl(scoreText);

}

var updateScoreText = function() {
scoreText.text = "Score: " + score;
if(score > highScore){
highScore = score;
}
highScoreText2.text = "High Score: " + highScore;

hudTexture.addControl(highScoreText2);
}

var resetScore = function() {
console.log("Score reset at: " + score);
score = 0;
updateScoreText();

hudTexture.removeControl(highScoreText2);
}

var addScore = function(points) {
Expand Down
14 changes: 13 additions & 1 deletion game/src/mainmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,32 @@ class MainMenu extends GameObject {
this.instructionsText.horizontalAlignment = BABYLON.GUI.TextBlock.HORIZONTAL_ALIGNMENT_CENTER;
this.instructionsText.width = .5;
this.instructionsText.height = .9;

this.highScoreText = new BABYLON.GUI.TextBlock();
this.highScoreText.text = highScore;
this.highScoreText.fontFamily = "Impact";
this.highScoreText.color = "white";
this.highScoreText.fontSize = 28;
this.highScoreText.verticalAlignment = BABYLON.GUI.TextBlock.VERTICAL_ALIGNMENT_TOP;
this.highScoreText.horizontalAlignment = BABYLON.GUI.TextBlock.HORIZONTAL_ALIGNMENT_CENTER;
this.highScoreText.width = .5;
this.highScoreText.height = .8;

this.hudTexture.addControl(this.welcomeText);
this.hudTexture.addControl(this.greetingText);
this.hudTexture.addControl(this.instructionsText);
this.hudTexture.addControl(this.highScoreText);
}


hideUI() {
this.hudTexture.removeControl(this.welcomeText);
this.hudTexture.removeControl(this.greetingText);
this.hudTexture.removeControl(this.instructionsText);
this.hudTexture.addControl(this.highScoreText);
}
}

var mainMenu = new MainMenu();
createObject(mainMenu);
mainMenu.visible = true;
mainMenu.visible = true;