Helpful Game Functions
gameReset Function
function gameReset() {
gatesCleared = 0;
level = 1;
t = 0;
rocketX = 16;
rocketY = canvas.height / 2 - (rocketHeight/2);
gatesCleared = 0;
backgroundX = 0;
gate1X = 650;
gate2X = 1000;
gameOverOpacity = 0;
}
drawStartScreen Function
function drawStartScreen() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.rect(0, 0, 600, 400);
ctx.fillStyle = "#FF5555";
ctx.fill();
ctx.closePath();
ctx.font = "48px serif";
ctx.fillStyle = "#000000";
ctx.textAlign = "center";
ctx.fillText("Press ENTER", 300, 200);
}
drawGameOver Function
function drawGameOver() {
ctx.globalAlpha = gameOverOpacity;
ctx.beginPath();
ctx.rect(0, 0, 600, 400);
ctx.fillStyle = "#FF5555";
ctx.fill();
ctx.closePath();
ctx.font = "48px serif";
ctx.textAlign = "center";
ctx.fillStyle = "#000000";
ctx.fillText("Score " + gatesCleared, 300, 100);
if (gatesCleared > highScore) {
highScore = gatesCleared;
}
ctx.fillText("High Score " + highScore, 300, 180);
gameOverOpacity = gameOverOpacity + .002;
if(gameOverOpacity > .1) {
gameOverOpacity = gameOverOpacity + .05;
}
}
drawScore Function
function drawScore() {
ctx.font = "22px serif";
ctx.fillStyle = "#00ff00";
ctx.textAlign = "left";
ctx.fillText("Score: " + gatesCleared, 16, 380);
ctx.textAlign = "right";
ctx.fillText("Level: " + level, 584, 380);
}
changeGameSpeed Function
function changeGameSpeed() {
tChange = gameSpeed;
rocketSpeed = gameSpeed;
backgroundSpeed = gameSpeed - 1;
gateSpeed = gameSpeed;
}