Problem with mouse release and scoring
in
Programming Questions
•
1 year ago
Two questions to ask dealing with my circle game. Pretty much have everything coded but I'm experiencing a crash when I get to my game over screen when it comes to the mouseRelease function. Every time you release the mouse the player moves onto the next level. However, if you come in contact with the black perimeter line the game over screen should appear, but the mouseRelease function is affecting the screen. Any ideas for what to put so the mouseRelease function doesn't affect the game over screen? My other question has to do with the score. How would I get the score from level one to carry over to level two and increase, and then have it carry over from level two to level three? My code is as follows:
int a = 0;
int b = 2;
int c = 3;
int num = 0;
int score = 0;
void setup() {
size(500,500);
smooth();
}
void draw() {
background(120);
switch(num) {
case 0: // Start screen
text("PRESS A KEY ON KEYBOARD TO START",130,250);
if (keyPressed==true) {
num = 1;
a=0;
}
break;
case 1: // Level one
fill(255);
strokeWeight(10);
score = a;
text("Level One", 25, 20);
text("Your score is " + score, 15,40);
ellipse(width/2, height/2,400,400); // white cirlce
fill(0);
ellipse(width/2, height/2,a,a); //black circle
if (a>width) {
a=0;
}
if (mousePressed == true) {
a++;
}
if (a>381) {
num = 5;
}
break;
case 2: // Level two
fill(255);
strokeWeight(5);
//score =
text("Level Two", 25, 20);
//text("Your score is " + score, 15,35);
ellipse(width/2, height/2,250,250); //white circle
fill(0);
ellipse(width/2, height/2,a,a); // Black circle
if (a>width) {
a=0;
}
if (mousePressed == true) {
a+=b;
}
if (a>240) {
num = 5;
}
break;
case 3: //Level three
fill(255);
strokeWeight(2);
//score = a;
text("Level Three", 25, 20);
//text("Your score is " + score, 15,35);
ellipse(width/2, height/2,150,150); // white circle
fill(0);
ellipse(width/2, height/2,a,a); //black circle
if (a>width) {
a=0;
}
if (mousePressed == true) {
a+=c;
}
if (a>141) {
num = 5;
}
break;
case 5: // Game over screen
fill(255);
text("GAMEOVER", 220, 250);
text("Press A Key On Keyboard To Restart", 160, 300);
if (keyPressed == true) {
num = 0;
a=0;
}
break;
}
}
void mousePressed() {
if (a == 0) {
a++;
}else{
a = 0;
}
}
void mouseReleased () {
if (a == a++) {
num++;
a = 0;
}
}
1