Balls wait problem

Hello, now I am making a game of hunting a ball, what happens is that the balls do not stay on the screen, but new ones are written continuously, I wanted to do it by myself but I have not succeeded, the objective is that the balls wait for you to click for them to change

The code has images and I don’t know how to upload them, sorry

Code:

int Jugar = 1;
int Repinta = 1;
int Tamano = 70; 
int Puntos = 0;
int PosX = 0; 
int PosY = 0;
PImage INICIO, Demon, Angel;
boolean click, lclick, inicio;

void setup() {
  
 size(1000,600);
 background (0,0,0);
 cursor (HAND);
 INICIO = loadImage("INICIO.png");
 Demon = loadImage("Demon.png");
 Angel = loadImage("Angel.png");
}

void draw() {

   inicio();
}

void inicio() {
  
image(INICIO,0,0);  
INICIO.resize(width,height);
inicio = true;

if (click == true){
  DibujarFormas();
 }
 
if (lclick == true){
  How_to_play();
 } 
}

void How_to_play(){

  
}

void DibujarFormas() {
{  
background(0,0,0);

for (int i= 0; i <= Puntos; i++)
 {
 Angel.resize(Tamano,Tamano);
 image(Angel,floor(random(50,750)),floor(random(100,550)));
 
 }
 PosX = floor(random(50,750));
 PosY = floor(random(100,550));
 fill(255,0,0);
 Demon.resize(Tamano,Tamano);
 image(Demon,PosX,PosY);
 
 fill(255,0,0);
 textAlign(CENTER);
 textSize(18);
 text("Puntos:"+(Puntos), 250, 30);
 
 fill(255,0,0);
 textAlign(LEFT);
 textSize(18);
 text("Tiempo:"+millis()/1000, 250, 30);
 
 Repinta=0;
}
}

void mouseClicked(){

if(Jugar == 1)
 {
  if(Repinta == 0)
  {
  Repinta = 1;
  }
  if ((mouseX > PosX-Tamano) && (mouseX < PosX+Tamano) && (mouseY > PosY-Tamano) && (mouseY < PosY+Tamano))
  {
  Puntos+=1;
  }  
  else
  {
    Jugar=0;
    //game over
  }
 }
}

void mousePressed() {
 
println("click en X=" + mouseX + ", Y=" + mouseY);

println(click);
 
if (mouseX>170 && mouseX<330 && mouseY>5 && mouseY<70 && inicio == true) {
 click = true;
  }
  
if (mouseX>170 && mouseX<550 && mouseY>95 && mouseY<155 && inicio == true ) {
 lclick = true;
 }
}

To help isolate the problem and make it easier to understand, it would be helpful if you could create a minimal version of your sketch that shows the issue you are having. This will make it easier for others to understand the problem and offer suggestions on how to fix it. And who knows, you may even find the solution yourself in the process :wink:

PS: I formatted your code. In the future please use code formatting to make it easier for people to help. See the example below:

2 Likes