cleaned up code and added documentation

This commit is contained in:
Sam
2023-12-12 21:45:19 +01:00
parent fbe19ba35e
commit a0c916cafe

View File

@@ -75,8 +75,8 @@ function score() {
} }
function gameOver() { function gameOver() {
if (lives == 0) { if (lives == 0) {
//game over screen
isDead = true; isDead = true;
push(); push();
fill(255, 0, 0); fill(255, 0, 0);
@@ -91,6 +91,7 @@ function gameOver() {
pop(); pop();
if (key == ' ') { if (key == ' ') {
//reset all the variables so the game can be played again
lives = 1; lives = 1;
time = 0; time = 0;
bounceX = bossPosX; bounceX = bossPosX;
@@ -105,19 +106,15 @@ function gameOver() {
isDead = false; isDead = false;
} }
} }
} }
function movementCheck() { function movementCheck() {
//check if the player has moved
if (playerPosX != initialPlayerPosX || playerPosY != initialPlayerPosY) { if (playerPosX != initialPlayerPosX || playerPosY != initialPlayerPosY) {
hasMoved = true; hasMoved = true;
} }
} }
function keyDown() {
}
async function keyPressed() { async function keyPressed() {
if (!isDead) { if (!isDead) {
if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) { if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) {
@@ -157,10 +154,9 @@ function wait(waitTime) {
} }
async function Movementloop() { async function Movementloop() {
//get info from controller and use it to move the player
window.addEventListener('booleanArrayUpdated', function (event) { window.addEventListener('booleanArrayUpdated', function (event) {
// event.detail contains the booleanArray
let booleanArray = event.detail; let booleanArray = event.detail;
// Use booleanArray here...
if (booleanArray[1]) { if (booleanArray[1]) {
playerPosX += playerSpeed; playerPosX += playerSpeed;