xxxxxxxxxx
83
// 4 prompts
// 1 fail screen (try again)
// 1 success screen
var choice = 0; // 0 if nothing is chosen yet, 1 if left 2 if right
var state = 1; // 1 if alive, 0 if dead
var qnum = 1; // what question you're on
let choice_1, choice_2, choice_3, choice_4;
function setup() {
createCanvas(500, 500);
background(220);
}
function mousePressed() {
if(mouseY>=300&&mouseX >= 250) {
choice = 1
} else if(mouseY>=300&&mouseX <250) {
choice = 2
} else choice = 0;
}
function draw() {
//console.log(choice);
console.log(qnum);
if(qnum == 1) {
//q1 and two buttons
fill('yellow');
rect(0, 0, 500, 300);
fill(255);
rect(0, 300, 250, 200);
rect(250, 300, 250, 200);
if(choice == 1) {qnum++}
else if(choice == 2){state = 0}
}
if(qnum == 2) {
choice = 0;
//q2 and two buttons
background(220);
fill('green');
rect(0, 0, 500, 300);
fill(255);
rect(0, 300, 250, 200);
rect(250, 300, 250, 200);
if(choice == 1) {qnum++}
else if(choice == 2){state = 0}
}
if(qnum == 3) {
choice = 0;
//q3 and two buttons
background(220);
fill('blue');
rect(0, 0, 500, 300);
fill(255);
rect(0, 300, 250, 200);
rect(250, 300, 250, 200);
if(choice == 1) {qnum++}
else if(choice == 2){state = 0}
}
if(qnum == 4) {
choice = 0;
//q4 and two buttons
background(220);
fill('purple');
rect(0, 0, 500, 300);
fill(255);
rect(0, 300, 250, 200);
rect(250, 300, 250, 200);
if(choice == 1) {qnum++}
else if(choice == 2){state = 0}
}
if(qnum > 4) {
// success screen
background(220);
fill(255);
circle(mouseX, mouseY, 25);
}
if(state == 0) {
// fail screen
background(220);
line(200, 200, 300, 300);
line(200, 300, 300, 200);
}
}