working writting (one letter)

This commit is contained in:
Mees Roelofsz
2023-12-13 13:33:56 +01:00
parent fcc6924739
commit 95f4ccc890

View File

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