prepared for UI changes and added reset function
This commit is contained in:
89
web/game.js
89
web/game.js
@@ -57,7 +57,9 @@ let chosen = false;
|
||||
let finalPhase = false;
|
||||
let nextWave = [];
|
||||
let iIndex = 0;
|
||||
let buttonSelect = 0;
|
||||
let buttonSelectDead = 0;
|
||||
let buttonSelectHome = 0;
|
||||
let buttonSelectPause = 0;
|
||||
let entered = false;
|
||||
let submitted = false;
|
||||
|
||||
@@ -83,11 +85,29 @@ function score() {
|
||||
time += 3 / framerate;
|
||||
}
|
||||
|
||||
function reset() {
|
||||
lives = 1;
|
||||
time = 0;
|
||||
bounceX = bossPosX;
|
||||
bounceY = bossPosY;
|
||||
initialPlayerPosX = playerPosX;
|
||||
initialPlayerPosY = playerPosY;
|
||||
hasMoved = false;
|
||||
bullets = [];
|
||||
shot = false;
|
||||
chosen = false;
|
||||
finalPhase = false;
|
||||
isDead = false;
|
||||
entered = false;
|
||||
buttonSelectDead = 0;
|
||||
submitted = false;
|
||||
}
|
||||
|
||||
function gameOver() {
|
||||
if (lives == 0) {
|
||||
//game over screen
|
||||
iIndex = constrain(iIndex, 0, 2);
|
||||
buttonSelect = constrain(buttonSelect, 0, 2);
|
||||
buttonSelectDead = constrain(buttonSelectDead, 0, 2);
|
||||
isDead = true;
|
||||
push();
|
||||
fill(255, 0, 0);
|
||||
@@ -163,14 +183,14 @@ async function keyPressed() {
|
||||
}
|
||||
if (isDead && keyReleasedFlag && entered) {
|
||||
if (keyCode == UP_ARROW) {
|
||||
buttonSelect -= 1;
|
||||
buttonSelectDead -= 1;
|
||||
keyReleasedFlag = false;
|
||||
}
|
||||
if (keyCode == DOWN_ARROW) {
|
||||
buttonSelect += 1;
|
||||
buttonSelectDead += 1;
|
||||
keyReleasedFlag = false;
|
||||
}
|
||||
if (buttonSelect == 0) {
|
||||
if (buttonSelectDead == 0) {
|
||||
if (keyCode == RIGHT_ARROW && !submitted) {
|
||||
entered = false;
|
||||
nameHS = '';
|
||||
@@ -181,45 +201,16 @@ async function keyPressed() {
|
||||
keyReleasedFlag = false;
|
||||
}
|
||||
}
|
||||
if (buttonSelect == 1) {
|
||||
if (buttonSelectDead == 1) {
|
||||
if (keyCode == ENTER) {
|
||||
//reset all the variables so the game can be played again
|
||||
lives = 1;
|
||||
time = 0;
|
||||
bounceX = bossPosX;
|
||||
bounceY = bossPosY;
|
||||
initialPlayerPosX = playerPosX;
|
||||
initialPlayerPosY = playerPosY;
|
||||
hasMoved = false;
|
||||
bullets = [];
|
||||
shot = false;
|
||||
chosen = false;
|
||||
finalPhase = false;
|
||||
isDead = false;
|
||||
entered = false;
|
||||
buttonSelect = 0;
|
||||
submitted = false;
|
||||
reset();
|
||||
}
|
||||
}
|
||||
if (buttonSelect == 2) {
|
||||
if (buttonSelectDead == 2) {
|
||||
if (keyCode == ENTER) {
|
||||
homescreenOn = true;
|
||||
|
||||
lives = 1;
|
||||
time = 0;
|
||||
bounceX = bossPosX;
|
||||
bounceY = bossPosY;
|
||||
initialPlayerPosX = playerPosX;
|
||||
initialPlayerPosY = playerPosY;
|
||||
hasMoved = false;
|
||||
bullets = [];
|
||||
shot = false;
|
||||
chosen = false;
|
||||
finalPhase = false;
|
||||
isDead = false;
|
||||
entered = false;
|
||||
buttonSelect = 0;
|
||||
submitted = false;
|
||||
reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,7 +272,7 @@ function draw() {
|
||||
}
|
||||
if (isDead == true) {
|
||||
if (entered == true) {
|
||||
if (buttonSelect == 0) {
|
||||
if (buttonSelectDead == 0) {
|
||||
push()
|
||||
stroke(205, 205, 205)
|
||||
strokeWeight(2)
|
||||
@@ -289,7 +280,7 @@ function draw() {
|
||||
rect(width / 2 - 45, height / 2 - 30, 90, 40)
|
||||
pop()
|
||||
}
|
||||
if (buttonSelect == 1) {
|
||||
if (buttonSelectDead == 1) {
|
||||
push()
|
||||
stroke(205, 205, 205)
|
||||
strokeWeight(2)
|
||||
@@ -297,7 +288,7 @@ function draw() {
|
||||
rect(width / 2 - 55, height / 2 + 15, 110, 40)
|
||||
pop()
|
||||
}
|
||||
if (buttonSelect == 2) {
|
||||
if (buttonSelectDead == 2) {
|
||||
push()
|
||||
stroke(205, 205, 205)
|
||||
strokeWeight(2)
|
||||
@@ -558,11 +549,11 @@ function spawnRandomBullet() {
|
||||
|
||||
function homescreen() {
|
||||
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")
|
||||
button(255, 255, 255, width / 2 - 90, height / 2, 200, 40, "Start Game")
|
||||
button(255, 255, 255, width / 2 - 90, height / 2 + 50, 200, 40, "Scores")
|
||||
|
||||
push()
|
||||
stroke(255, 0, 0)
|
||||
stroke(255, 255, 255)
|
||||
strokeWeight(5)
|
||||
fill(0, 255, 0, 0)
|
||||
rect(100, 150, 300, 400)
|
||||
@@ -570,12 +561,12 @@ function homescreen() {
|
||||
|
||||
push()
|
||||
textSize(50)
|
||||
fill(255, 0, 0)
|
||||
fill(255, 255, 255)
|
||||
text("Highscores", 250, 200)
|
||||
pop()
|
||||
|
||||
push()
|
||||
stroke(255, 0, 0)
|
||||
stroke(255, 255, 255)
|
||||
strokeWeight(5)
|
||||
fill(0, 255, 0, 0)
|
||||
rect(860, 150, 300, 400)
|
||||
@@ -583,7 +574,7 @@ function homescreen() {
|
||||
|
||||
push()
|
||||
textSize(50)
|
||||
fill(255, 0, 0)
|
||||
fill(255, 255, 255)
|
||||
text("Controls", 1000, 200)
|
||||
pop()
|
||||
}
|
||||
@@ -592,8 +583,8 @@ function homescreen() {
|
||||
|
||||
function button(r, g, b, buttonX, buttonY, buttonWidth, buttonHeight, buttonText) {
|
||||
push()
|
||||
fill(255, 0, 0)
|
||||
rect(buttonX, buttonY, buttonWidth, buttonHeight, 20, 20, 20, 20)
|
||||
fill(0, 0, 50)
|
||||
rect(buttonX, buttonY, buttonWidth, buttonHeight)
|
||||
textSize(25)
|
||||
fill(r, g, b)
|
||||
text(buttonText, buttonX + 100, buttonY + 30)
|
||||
|
Reference in New Issue
Block a user