diff --git a/web/game.js b/web/game.js index d92e8c0..c4b09ae 100644 --- a/web/game.js +++ b/web/game.js @@ -87,7 +87,7 @@ function gameOver() { text("Game Over", width / 2, height / 2 - 80); pop(); push(); - fill(255,255,255) + fill(255, 255, 255) textSize(32); text(letters[currentIndex], width / 2, height / 2); pop(); @@ -119,32 +119,38 @@ function movementCheck() { async function keyPressed() { if (!isDead) { - if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) { - playerPosX -= playerSpeed; + if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) { + playerPosX -= playerSpeed; + } + if (keyIsDown(RIGHT_ARROW) && playerPosX < width - radius) { + playerPosX += playerSpeed; + } + if (keyIsDown(UP_ARROW) && playerPosY > 0 + radius) { + playerPosY -= playerSpeed; + } + if (keyIsDown(DOWN_ARROW) && playerPosY < height - radius) { + playerPosY += playerSpeed; + } } - if (keyIsDown(RIGHT_ARROW) && playerPosX < width - radius) { - playerPosX += playerSpeed; - } - if (keyIsDown(UP_ARROW) && playerPosY > 0 + radius) { - playerPosY -= playerSpeed; - } - if (keyIsDown(DOWN_ARROW) && playerPosY < height - radius) { - playerPosY += playerSpeed; - } -} - if (isDead) { - if (keyCode === UP_ARROW) { + if (isDead && keyReleasedFlag) { + if (keyCode == UP_ARROW) { currentIndex = (currentIndex + 1) % letters.length; - } - if (keyCode === DOWN_ARROW) { + keyReleasedFlag = false; + } + if (keyCode == DOWN_ARROW) { currentIndex = (currentIndex - 1 + letters.length) % letters.length; - } - if (keyCode === ENTER) { + keyReleasedFlag = false; + } + if (keyCode == ENTER) { name += letters[currentIndex]; console.log(name); + keyReleasedFlag = false; } + } } +function keyReleased() { + keyReleasedFlag = true; // Set the flag to true when a key is released } function wait(waitTime) { @@ -189,6 +195,7 @@ function draw() { if (homescreenOn == false) { game(); } + // keyIsDown(); } async function randPatern() {