diff --git a/web/game.js b/web/game.js index c4b09ae..e09b8d8 100644 --- a/web/game.js +++ b/web/game.js @@ -5,8 +5,8 @@ const height = 620; // Menu variables let letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); -let currentIndex = 0; -let name = ''; +let currentIndex = [0, 0, 0]; +let nameHS = ''; let pressed = false; // Player variables @@ -55,6 +55,7 @@ let homescreenOn = true; let chosen = false; let finalPhase = false; let nextWave = []; +let iIndex = 0; let bulletAmount = 5; //let myBullet = new bullet(); @@ -79,6 +80,7 @@ function score() { function gameOver() { if (lives == 0) { //game over screen + iIndex = constrain(iIndex, 0, 2); isDead = true; push(); fill(255, 0, 0); @@ -89,7 +91,10 @@ function gameOver() { push(); fill(255, 255, 255) textSize(32); - text(letters[currentIndex], width / 2, height / 2); + textAlign(CENTER); + text(letters[currentIndex[0]], width / 2 - 30, height / 2); + text(letters[currentIndex[1]], width / 2, height / 2); + text(letters[currentIndex[2]], width / 2 + 30, height / 2); pop(); if (key == ' ') { @@ -133,22 +138,35 @@ async function keyPressed() { } } if (isDead && keyReleasedFlag) { + if ((!(iIndex > 2)) || (!(iIndex < 0))) { + if (keyCode == LEFT_ARROW) { + iIndex -= 1; + keyReleasedFlag = false; + } + if (keyCode == RIGHT_ARROW) { + iIndex += 1; + keyReleasedFlag = false; + } + } if (keyCode == UP_ARROW) { - currentIndex = (currentIndex + 1) % letters.length; + currentIndex[iIndex] = (currentIndex[iIndex] + 1) % letters.length; keyReleasedFlag = false; } if (keyCode == DOWN_ARROW) { - currentIndex = (currentIndex - 1 + letters.length) % letters.length; + currentIndex[iIndex] = (currentIndex[iIndex] - 1 + letters.length) % letters.length; keyReleasedFlag = false; } if (keyCode == ENTER) { - name += letters[currentIndex]; - console.log(name); + nameHS += letters[currentIndex[0]]; + nameHS += letters[currentIndex[1]]; + nameHS += letters[currentIndex[2]]; + console.log(nameHS + ": " + int(time)); + nameHS = ''; keyReleasedFlag = false; } - } } + function keyReleased() { keyReleasedFlag = true; // Set the flag to true when a key is released } @@ -195,9 +213,35 @@ function draw() { if (homescreenOn == false) { game(); } - // keyIsDown(); -} + if (isDead == true) { + if (iIndex == 0) { + push() + stroke(205, 205, 205) + strokeWeight(2) + fill(0, 0, 0, 0) + rect(width / 2 - 45, height / 2 - 30, 30, 40) + pop() + } + if (iIndex == 1) { + push() + stroke(205, 205, 205) + strokeWeight(2) + fill(0, 0, 0, 0) + rect(width / 2 - 15, height / 2 - 30, 30, 40) + pop() + } + if (iIndex == 2) { + push() + stroke(205, 205, 205) + strokeWeight(2) + fill(0, 0, 0, 0) + rect(width / 2 + 15, height / 2 - 30, 30, 40) + pop() + } + // keyIsDown(); + } +} async function randPatern() { patern = random(paternArray); chosen = true; @@ -399,24 +443,7 @@ function spawnRandomBullet() { function homescreen() { - // push() - // fill(0, 0, 0, 200) - // square(0, 0, 1600) - // pop() - - // push() - // fill(255, 0, 0) - // let buttonHeight = height/2 - // rect(width/2-90, buttonHeight, 200, 40 , 20, 20, 20, 20) - // textSize(25) - // fill(0,0,0) - // text("Start Game", width/2+10, buttonHeight+30) - // if (mouseX > width/2-90 && mouseX < width/2+110 && mouseY > height/2 && mouseY < buttonHeight+40) { - // if (mouseIsPressed) { - // homescreenOn = false; - // } - // } - // pop() + textAlign(CENTER); button(0, 0, 0, width / 2 - 90, height / 2, 200, 40, "Start Game") button(0, 0, 0, width / 2 - 90, height / 2 + 50, 200, 40, "Scores")