|
(Renkum, Saturday 18th of August 2012) Displaying the score Well, it took some time before I continued working on my game experiment. But since someone ecouraged me to go on with the game, I'm adding a new step, I'm going to isplay the score. I'm doing a quick start of that by adding text to the output . <!DOCTYPE html> <html> <header> <title>Heart Hunter Game</title> </header> <body> <form><label>Score: <label><label id="score">0</label></form> <canvas border=0 id="gameCanvas" width="1600" height=1000>Your browser does not support the canvas tag.</canvas> <script src="hearthunter.js"></script> </body> </html> In the code I will add calls to update the score, which is called when the score increases.
function setScore(newValue){
score.innerHTML = newValue;
}
When we display the score, we don't need the alert message anymore. So we'll write that one in from of the canvas.
function initialScreen(gameover){
ctx.font="30px Verdana";
// Create gradient
var gradient=ctx.createLinearGradient(0,0,canvas.width,0);
gradient.addColorStop("0","green");
gradient.addColorStop("0.5","blue");
gradient.addColorStop("1.0","red");
// Fill with gradient
ctx.fillStyle=gradient;
if (gameover)
{
ctx.fillText("Game over!!!",10,50);
ctx.fillText("Click to Restart the Game",10,90);
}
else
{
ctx.fillText("Click to Start the Game",10,90);
}
}
Further I did some restyling by adding a gradient in the background:
var ctx=canvas.getContext('2d');
var fields = new Array(numFields);
var backGroundFillStyle=ctx.createLinearGradient(0,0,scrWidth,scrHeight);
backGroundFillStyle.addColorStop("0",'#4444FF');
backGroundFillStyle.addColorStop("0.5",'#DDDDDF');
backGroundFillStyle.addColorStop("1.0",'#4444FF');
So after extra 2 hours, we are facing a nice game with score that can be started by a mouse click. To check the result, click here.
Day1 Day2 Day3 Day4 Day5 Day6 Day7 back to index |