Based on your comments above it sounds like an if
condition will do the job and there's no need for the do/while
loop.
You have this boolean expression: (mouseX > 800) && (mouseX < 1000) && (mouseY > 400) && (mouseY < 700)
.
You want moonLanding()
to be called only when this condition is not(!
) met:
void draw() {
boolean onTheMoon = false;
drawGrid(); // Old overlay animation.
if ((mouseX > 50) && (mouseX < 150) && (mouseY > 50) && (mouseY < 150)) {
onTheMoon = true;
}
if (onTheMoon)
{
if (!((mouseX > 800) && (mouseX < 1000) && (mouseY > 400) && (mouseY < 700))){
moonLanding(); // New overlay method
}
rocketShip(); // Calling my rocketship method. Rocket made of shapes using mouseX and mouseY
}
this is equivalent to:
if (((mouseX > 800) && (mouseX < 1000) && (mouseY > 400) && (mouseY < 700)) == false){
moonLanding(); // New overlay method
}
One suggestion I have, if your program will require more mouse/bounding conditions is to encapsulate the conditions in a re-usable function.
for example:
void draw() {
boolean onTheMoon = false;
drawGrid(); // Old overlay animation.
if (isMouseOverTopLeft()) {
onTheMoon = true;
}
if (onTheMoon)
{
if (!isMouseOverBottomRight()){
moonLanding(); // New overlay method
}
rocketShip(); // Calling my rocketship method. Rocket made of shapes using mouseX and mouseY
}
boolean isMouseOverTopLeft(){
return isMouseOverRect(50, 50, 150, 150);
}
boolean isMouseOverBottomRight(){
return isMouseOverRect(800, 400, 1000, 700);
}
boolean isMouseOverRect(float x1, float y1, float x2, float y2){
return (mouseX >= x1 && mouseX <= x2) && (mouseY >= y1 && mouseY <= y2);
}
I can easily see getting ridiculous with many isOverX methods, but by then you could start storing making a data structure to hold bounds an a list of bounds, etc.
The idea is to make the code easier to read.
do/while
part looks suspicious. Remember you're calling this indraw()
sorocketShip()
won't be called (and rendering can't continue) until the while loop completes execution. What should happen when the mouse is within 50,150 bounding box ? – George Profenza