From a0c916cafecad074cfd12cd744005cbfd3a8e3da Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 12 Dec 2023 21:45:19 +0100 Subject: [PATCH] cleaned up code and added documentation --- web/game.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/web/game.js b/web/game.js index 708f7d4..6267eea 100644 --- a/web/game.js +++ b/web/game.js @@ -75,8 +75,8 @@ function score() { } function gameOver() { - if (lives == 0) { + //game over screen isDead = true; push(); fill(255, 0, 0); @@ -91,6 +91,7 @@ function gameOver() { pop(); if (key == ' ') { + //reset all the variables so the game can be played again lives = 1; time = 0; bounceX = bossPosX; @@ -105,19 +106,15 @@ function gameOver() { isDead = false; } } - } function movementCheck() { + //check if the player has moved if (playerPosX != initialPlayerPosX || playerPosY != initialPlayerPosY) { hasMoved = true; } } -function keyDown() { - -} - async function keyPressed() { if (!isDead) { if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) { @@ -157,10 +154,9 @@ function wait(waitTime) { } async function Movementloop() { + //get info from controller and use it to move the player window.addEventListener('booleanArrayUpdated', function (event) { - // event.detail contains the booleanArray let booleanArray = event.detail; - // Use booleanArray here... if (booleanArray[1]) { playerPosX += playerSpeed;