Mouse Release Question
in
Programming Questions
•
1 year ago
Okay...so I'm in the process of creating this simple circle game for a class assignment. When you click the mouse a black circle starts to expand. The objective is to expand the black circle as close as one can to the black perimeter line. If one comes in contact with the black perimeter line a game over screen appears. My question revolves around the mouse triggers. I only want the player to be able to press the mouse once and once they release it they move on to case 2 (or the second level) if they haven't touched the perimeter line. Does anyone have suggestions about how I might get this to work? My code is as follows:
int a = 0;
int num = 0;
int score =0;
void setup() {
size(500,500);
smooth();
}
void draw() {
background(120);
switch(num) {
case 0:
text("PRESS A KEY ON KEYBOARD TO START",130,250);
if (keyPressed==true) {
num = 1;
a=0;
}
break;
case 1:
fill(255);
strokeWeight(10);
score = a;
text("Your score is " + score, 15,35);
ellipse(width/2, height/2,400,400);
fill(0);
ellipse(width/2, height/2,a,a);
if (a>width) {
a=0;
}
if (mousePressed == true) { // Once mouse is released I want the player to move to case 2.
a++;
}
if (a>381) {
num = 3;
}
break;
//case 2:
//fill(255);
//strokeWeight(5);
//score =
//text("Your score is " + score, 15,35);
//ellipse(width/2, height/2,200,200);
//fill(0);
//ellipse(width/2, height/2,a,a);
case 3:
fill(255);
text("GAMEOVER", 220, 250);
text("Press A Key On Keyboard To Restart", 160, 300);
if (keyPressed ==true) {
num = 0;
a=0;
}
break;
}
}
int num = 0;
int score =0;
void setup() {
size(500,500);
smooth();
}
void draw() {
background(120);
switch(num) {
case 0:
text("PRESS A KEY ON KEYBOARD TO START",130,250);
if (keyPressed==true) {
num = 1;
a=0;
}
break;
case 1:
fill(255);
strokeWeight(10);
score = a;
text("Your score is " + score, 15,35);
ellipse(width/2, height/2,400,400);
fill(0);
ellipse(width/2, height/2,a,a);
if (a>width) {
a=0;
}
if (mousePressed == true) { // Once mouse is released I want the player to move to case 2.
a++;
}
if (a>381) {
num = 3;
}
break;
//case 2:
//fill(255);
//strokeWeight(5);
//score =
//text("Your score is " + score, 15,35);
//ellipse(width/2, height/2,200,200);
//fill(0);
//ellipse(width/2, height/2,a,a);
case 3:
fill(255);
text("GAMEOVER", 220, 250);
text("Press A Key On Keyboard To Restart", 160, 300);
if (keyPressed ==true) {
num = 0;
a=0;
}
break;
}
}
Thanks!
1