Mouse clicked issue with arrays

Hi! I have this school assignment. I basically made a game where you have to find a wolf in a pack of sheep. Once you click the wolf, it restarts and you just have to get more points until the timer runs out. The thing is, my teacher asked me to make more than 1 wolf appear using an array. And so I did, but I can’t get the mouse clicked function work with the array!

I don’t know what I’m doing wrong, as I’ve tried with different methods and none of them work. I don’t really understand how arrays work 100%, and there’s just so many things that come into play.

Here’s the complete code, I’d really appreciate some help :frowning:

Sorry if it’s messy or something, I’m really doing the best i can :cry:

PImage lobo;
PImage oveja;
PImage fondo;
PImage caja;
PImage gameover;


int GameOver=1; //cuándo termina la partida
int Restart=1;
int Puntos=0;

//variables lobo
int nlobo=5;

int loboX[]=new int[nlobo];
int loboY[]=new int[nlobo];

//variables ovejas
//aumenta el valor de n para subir la dificultad
int n=3;
int ovejasX[]=new int[n];
int ovejasY[]=new int[n];


int ms=10; //milisegundos

//cambiar tiempo aquí
int s=90; //segundos


void setup(){
  size(800,800);


  //gráficos
  lobo = loadImage("lobo.png");
  oveja = loadImage("oveja.png");
  fondo = loadImage("fondo.png");  
  caja = loadImage("fondo2.png");
  gameover = loadImage("gameover.png");



  
  for(int contador=0;contador<n;contador++){
    ovejasX[contador]=int(random(0,677));
    ovejasY[contador]=int(random(100,654)); //el random es así para que no se salgan de la pantalla
}

for(int contadorL=0;contadorL<nlobo;contadorL++){
   loboX[contadorL]=int(random(0,677));
   loboY[contadorL]=int(random(100,677));
}

}
    


  
void draw(){
  
  //tiempo  //lo pongo aquí porque se solapaban los números
  
  image(caja, 0, 0);
  textAlign(CENTER);
  textSize(30);
  text(s,630,50);

   if(ms<=100 && ms>0){
    ms=ms-1;
   }
   
   if(ms==0){

     s=s-1;
     ms=100;
     
     if(s<=0){
    
      noLoop();
      fill(255,0,0);
      GameOver=0;
    
      //desaparecen las ovejas y se revela la posición del lobo
      background(255,255,255);
    
      textAlign(CENTER);
      textSize(100);
      image(gameover, 0, 0);
      textSize(30);
      text("¡Se acabó el tiempo!",400,500);
      text("Lobos cazados: " + (Puntos),400,550);
      }
   }  

  
  
  //juego
  
  if((GameOver==1) && (Restart==1)){
    DibujarFormas();
  }
}
  
  
void DibujarFormas(){
  
  image(fondo, 0, 0);
  
  //caja de texto
  fill(0,0,0);
  rect(0,0,800,70);
  
 //objeto principal (lobo). Lo pongo delante para que los las ovejas lo pisen. Porque se está escondiendo
  
  for(int contadorL=0;contadorL<nlobo;contadorL++){
   image(lobo, loboX[contadorL], loboY[contadorL]);
  
 //ovejas
 fill(255,255,255);
  for(int contador=0;contador<n;contador++){
   image(oveja, ovejasX[contador], ovejasY[contador]);

  }
  
 //tiempo
  fill(255,255,255);
  textAlign(CENTER);
  textSize(30);
  text("Tiempo: ",560,50);
  
  
 //puntos
  fill(255,255,255);
  textAlign(CENTER);
  textSize(30);
  text("Puntos: " + (Puntos),230,50);
   
  
 //nueva pantalla
  Restart=0;
    
}
}



//para que salga la mano sobre el lobo
void mouseMoved(){
  
  for(int contadorL=0;contadorL<nlobo;contadorL++){
   loboX[contadorL]=int(random(0,677));
   loboY[contadorL]=int(random(100,677));
   
  if((mouseX > loboX[n]) && (mouseX < loboX[n]+123) && (mouseY > loboY[n]) && (mouseY < loboY[n]+160))
   {
    cursor(HAND);
   }

   else{
    cursor(ARROW); 
   }
}
}



void mouseClicked(){
  
 if(GameOver==1) //si la partida está iniciada
 {
  if(Restart==0) //y no está reiniciado
    {
   Restart=1;  //se reinicia cuando le das click
     }
     
   
  if((mouseX > loboX[n]) && (mouseX < loboX[n]) && (mouseY > loboY[n]) && (mouseY < loboY[n])) //si haces click en el lobo ganas puntos
   {
     
    Puntos++;  

   }
   
   
   else{  //si haces click en cualquier otro sitio, y la partida está iniciada, game over
   
   noLoop();
     fill(255,0,0);
     GameOver=0;
    
    //desaparecen las ovejas y se revela la posición del lobo
    background(255,255,255);
    
    for(int contadorLI=0;contadorLI<nlobo;contadorLI++){
      
    image(lobo, loboX[contadorLI], loboY[contadorLI]);
    }
    
    textAlign(CENTER);
    textSize(30);
    image(gameover, 0, 0);
    text("¡El lobo se ha escapado!",400,500);
    text("Lobos cazados: " + (Puntos),400,550);

   }   
 }  
}

@andprocessing hi and welcome

In order to get help from others and help them to use your code format your code

To format your code use preformatted text