Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion game/src/hud.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
var score = 0;
var scoreText;
var highScoreText2;
var highScore = 0;
var hudTexture;

var createHud = function() {
var hudTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
hudTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");

// Create a Text Block that can display the current score
scoreText = new BABYLON.GUI.TextBlock();
Expand All @@ -14,19 +17,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);
hudTexture.addControl(highScoreText2);

}

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


}

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;