changed all buttonselects to a single one + constrained based on screen
This commit is contained in:
93
web/game.js
93
web/game.js
@@ -24,9 +24,8 @@ function reset() {
|
|||||||
finalPhase = false;
|
finalPhase = false;
|
||||||
isDead = false;
|
isDead = false;
|
||||||
entered = false;
|
entered = false;
|
||||||
buttonSelectDead = 0;
|
buttonSelect = 0;
|
||||||
buttonSelectHome = 0;
|
|
||||||
buttonSelectPause = 0;
|
|
||||||
submitted = false;
|
submitted = false;
|
||||||
escaped = false;
|
escaped = false;
|
||||||
bossPosX = width / 2;
|
bossPosX = width / 2;
|
||||||
@@ -60,21 +59,22 @@ async function keyPressed() {
|
|||||||
nameSubmit();
|
nameSubmit();
|
||||||
}
|
}
|
||||||
if (isDead && keyReleasedFlag && entered) {
|
if (isDead && keyReleasedFlag && entered) {
|
||||||
|
buttonSelect = constrain(buttonSelect, 0, 2);
|
||||||
if (keyCode == UP_ARROW) {
|
if (keyCode == UP_ARROW) {
|
||||||
buttonSelectDead -= 1;
|
buttonSelect -= 1;
|
||||||
keyReleasedFlag = false;
|
keyReleasedFlag = false;
|
||||||
}
|
}
|
||||||
if (keyCode == DOWN_ARROW) {
|
if (keyCode == DOWN_ARROW) {
|
||||||
buttonSelectDead += 1;
|
buttonSelect += 1;
|
||||||
keyReleasedFlag = false;
|
keyReleasedFlag = false;
|
||||||
}
|
}
|
||||||
if (buttonSelectDead == 1) {
|
if (buttonSelect == 1) {
|
||||||
if (keyCode == ENTER) {
|
if (keyCode == ENTER) {
|
||||||
//reset all the variables so the game can be played again
|
//reset all the variables so the game can be played again
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (buttonSelectDead == 2) {
|
if (buttonSelect == 2) {
|
||||||
if (keyCode == ENTER) {
|
if (keyCode == ENTER) {
|
||||||
homescreenOn = true;
|
homescreenOn = true;
|
||||||
reset();
|
reset();
|
||||||
@@ -85,22 +85,24 @@ async function keyPressed() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (homescreenOn && keyReleasedFlag) {
|
if (homescreenOn && keyReleasedFlag) {
|
||||||
|
buttonSelect = constrain(buttonSelect, 0, 1);
|
||||||
if (keyCode == UP_ARROW) {
|
if (keyCode == UP_ARROW) {
|
||||||
buttonSelectHome -= 1;
|
buttonSelect -= 1;
|
||||||
keyReleasedFlag = false;
|
keyReleasedFlag = false;
|
||||||
}
|
}
|
||||||
if (keyCode == DOWN_ARROW) {
|
if (keyCode == DOWN_ARROW) {
|
||||||
buttonSelectHome += 1;
|
buttonSelect += 1;
|
||||||
keyReleasedFlag = false;
|
keyReleasedFlag = false;
|
||||||
}
|
}
|
||||||
if (buttonSelectHome == 0) {
|
if (buttonSelect == 0) {
|
||||||
if (keyCode == ENTER) {
|
if (keyCode == ENTER) {
|
||||||
console.log("start game");
|
console.log("start game");
|
||||||
homescreenOn = false;
|
homescreenOn = false;
|
||||||
|
gamescreenOn = true;
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (buttonSelectHome == 1) {
|
if (buttonSelect == 1) {
|
||||||
if (keyCode == ENTER) {
|
if (keyCode == ENTER) {
|
||||||
homescreenOn = false;
|
homescreenOn = false;
|
||||||
scorescreenOn = true;
|
scorescreenOn = true;
|
||||||
@@ -109,7 +111,27 @@ async function keyPressed() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!homescreenOn && !isDead && keyReleasedFlag) {
|
if (scorescreenOn && keyReleasedFlag) {
|
||||||
|
buttonSelect = constrain(buttonSelect, 0, 1);
|
||||||
|
if (keyCode == UP_ARROW) {
|
||||||
|
buttonSelect -= 1;
|
||||||
|
keyReleasedFlag = false;
|
||||||
|
}
|
||||||
|
if (keyCode == DOWN_ARROW) {
|
||||||
|
buttonSelect += 1;
|
||||||
|
keyReleasedFlag = false;
|
||||||
|
}
|
||||||
|
if (buttonSelect == 1 && entered) {
|
||||||
|
if (keyCode == ENTER) {
|
||||||
|
homescreenOn = true;
|
||||||
|
scorescreenOn = false;
|
||||||
|
reset();
|
||||||
|
keyReleasedFlag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!homescreenOn && !isDead && !scorescreenOn && keyReleasedFlag) {
|
||||||
|
buttonSelect = constrain(buttonSelect, 0, 1);
|
||||||
if (keyCode == 27 && !escaped) {
|
if (keyCode == 27 && !escaped) {
|
||||||
escaped = true;
|
escaped = true;
|
||||||
console.log("pause");
|
console.log("pause");
|
||||||
@@ -118,16 +140,16 @@ async function keyPressed() {
|
|||||||
}
|
}
|
||||||
if (escaped) {
|
if (escaped) {
|
||||||
if (keyCode == UP_ARROW) {
|
if (keyCode == UP_ARROW) {
|
||||||
buttonSelectPause -= 1;
|
buttonSelect -= 1;
|
||||||
keyReleasedFlag = false;
|
keyReleasedFlag = false;
|
||||||
console.log(buttonSelectPause)
|
console.log(buttonSelect)
|
||||||
}
|
}
|
||||||
if (keyCode == DOWN_ARROW) {
|
if (keyCode == DOWN_ARROW) {
|
||||||
buttonSelectPause += 1;
|
buttonSelect += 1;
|
||||||
keyReleasedFlag = false;
|
keyReleasedFlag = false;
|
||||||
console.log(buttonSelectPause)
|
console.log(buttonSelect)
|
||||||
}
|
}
|
||||||
if (buttonSelectPause == 0) {
|
if (buttonSelect == 0) {
|
||||||
if (keyCode == ENTER) {
|
if (keyCode == ENTER) {
|
||||||
console.log("resume");
|
console.log("resume");
|
||||||
pausescreenOn = false;
|
pausescreenOn = false;
|
||||||
@@ -135,7 +157,7 @@ async function keyPressed() {
|
|||||||
escaped = false;
|
escaped = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (buttonSelectPause == 1) {
|
if (buttonSelect == 1) {
|
||||||
if (keyCode == ENTER) {
|
if (keyCode == ENTER) {
|
||||||
console.log("main menu");
|
console.log("main menu");
|
||||||
homescreenOn = true;
|
homescreenOn = true;
|
||||||
@@ -231,13 +253,11 @@ function draw() {
|
|||||||
gameOver();
|
gameOver();
|
||||||
// draw background
|
// draw background
|
||||||
background(0, 0, 0, 100);
|
background(0, 0, 0, 100);
|
||||||
buttonSelectDead = constrain(buttonSelectDead, 0, 2);
|
|
||||||
buttonSelectHome = constrain(buttonSelectHome, 0, 1);
|
|
||||||
buttonSelectPause = constrain(buttonSelectPause, 0, 1);
|
|
||||||
|
|
||||||
if (homescreenOn == true && scorescreenOn == false) {
|
if (homescreenOn) {
|
||||||
homescreen();
|
homescreen();
|
||||||
if (buttonSelectHome == 0) {
|
buttonSelect = constrain(buttonSelect, 0, 1);
|
||||||
|
if (buttonSelect == 0) {
|
||||||
push()
|
push()
|
||||||
stroke(205, 205, 205)
|
stroke(205, 205, 205)
|
||||||
strokeWeight(2)
|
strokeWeight(2)
|
||||||
@@ -245,7 +265,7 @@ function draw() {
|
|||||||
rect(width / 2, height / 2, buttonWidth, buttonHeight)
|
rect(width / 2, height / 2, buttonWidth, buttonHeight)
|
||||||
pop()
|
pop()
|
||||||
}
|
}
|
||||||
if (buttonSelectHome == 1) {
|
if (buttonSelect == 1) {
|
||||||
push()
|
push()
|
||||||
stroke(205, 205, 205)
|
stroke(205, 205, 205)
|
||||||
strokeWeight(2)
|
strokeWeight(2)
|
||||||
@@ -254,17 +274,25 @@ function draw() {
|
|||||||
pop()
|
pop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!homescreenOn && !scorescreenOn) {
|
if (!homescreenOn && !scorescreenOn && !isDead) {
|
||||||
game();
|
game();
|
||||||
}
|
}
|
||||||
if (scorescreenOn) {
|
if (scorescreenOn) {
|
||||||
scoremenu();
|
scoremenu();
|
||||||
|
buttonSelect = constrain(buttonSelect, 0, 1);
|
||||||
|
if (buttonSelect == 1 && entered) {
|
||||||
|
push()
|
||||||
|
stroke(205, 205, 205)
|
||||||
|
strokeWeight(2)
|
||||||
|
fill(0, 0, 0, 0)
|
||||||
|
rect(width / 2, height / 2, buttonWidth, buttonHeight)
|
||||||
|
pop()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (pausescreenOn) {
|
if (pausescreenOn) {
|
||||||
pauseMenu();
|
pauseMenu();
|
||||||
}
|
buttonSelect = constrain(buttonSelect, 0, 1);
|
||||||
if (pausescreenOn) {
|
if (buttonSelect == 0) {
|
||||||
if (buttonSelectPause == 0) {
|
|
||||||
push()
|
push()
|
||||||
stroke(205, 205, 205)
|
stroke(205, 205, 205)
|
||||||
strokeWeight(2)
|
strokeWeight(2)
|
||||||
@@ -273,7 +301,7 @@ function draw() {
|
|||||||
rect(width / 2, height / 2, buttonWidth, buttonHeight)
|
rect(width / 2, height / 2, buttonWidth, buttonHeight)
|
||||||
pop()
|
pop()
|
||||||
}
|
}
|
||||||
if (buttonSelectPause == 1) {
|
if (buttonSelect == 1) {
|
||||||
push()
|
push()
|
||||||
stroke(205, 205, 205)
|
stroke(205, 205, 205)
|
||||||
strokeWeight(2)
|
strokeWeight(2)
|
||||||
@@ -284,8 +312,9 @@ function draw() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isDead) {
|
if (isDead) {
|
||||||
|
buttonSelect = constrain(buttonSelect, 0, 2);
|
||||||
if (entered) {
|
if (entered) {
|
||||||
if (buttonSelectDead == 0) {
|
if (buttonSelect == 0) {
|
||||||
push()
|
push()
|
||||||
stroke(205, 205, 205)
|
stroke(205, 205, 205)
|
||||||
strokeWeight(2)
|
strokeWeight(2)
|
||||||
@@ -293,7 +322,7 @@ function draw() {
|
|||||||
rect(width / 2, height / 2, 90, 40)
|
rect(width / 2, height / 2, 90, 40)
|
||||||
pop()
|
pop()
|
||||||
}
|
}
|
||||||
if (buttonSelectDead == 1) {
|
if (buttonSelect == 1) {
|
||||||
push()
|
push()
|
||||||
stroke(205, 205, 205)
|
stroke(205, 205, 205)
|
||||||
strokeWeight(2)
|
strokeWeight(2)
|
||||||
@@ -301,7 +330,7 @@ function draw() {
|
|||||||
rect(width / 2, height / 2 + height / 12, 110, 40)
|
rect(width / 2, height / 2 + height / 12, 110, 40)
|
||||||
pop()
|
pop()
|
||||||
}
|
}
|
||||||
if (buttonSelectDead == 2) {
|
if (buttonSelect == 2) {
|
||||||
push()
|
push()
|
||||||
stroke(205, 205, 205)
|
stroke(205, 205, 205)
|
||||||
strokeWeight(2)
|
strokeWeight(2)
|
||||||
|
Reference in New Issue
Block a user