You could store a list of Ninjas that have collided with the ball once - and then loop through the list and ignore any of the additional collisions with Ninjas that were already hit.
You could then reset the list every time the ball is thrown again - or reset the list every 1 or 2 seconds so that each ninja will wait a short time before allowing another collision.
The objective of my game is to defeat all ninjas, so when the ball hits the ninja this ninja would be excused.
First was making the collision work, and then make the process of exclusion (still do not know how to do).
So if the collision is working normally if I delete the ninja there will be no more repeated collisions, right?
If you do not lose too much, would you tell me how to do the exclusion part?
Yes if the Ninja is no longer alive in the game, you could just remove it from the physics space and the collisions should no longer register.
In the case that your enemies have a health bar and can be hit more than once, you can exclude them from being hit again by storing them in a list after they are hit.
If that is what you mean by exclusion, then here is an example of the code that you could use to exclude an Enemy that is still alive (the Agent object in this example) from being hit a second time by the same projectile.
public class Projectile(){
...
...
private ArrayList hitAgents<Agent>;
public void agentCollisionDetected(Agent hitAgent){ //you would call this method when a collision occurs between the Ninja and the Ball from your game
boolean agentHasBeenHitYet = false;
for(int x = 0;x < hitAgents.size();x++){
Agent agentToCheck = hitAgents.get(x);
if(hitAgent== agentToCheck) {
agentHasBeenHitYet = true;
}
}
if(agentHasBeenHitYet != true){
hitAgent.takeDamage();
hitAgents.add(hitAgent); //add the Agent to the list of hitAgents so it isn't hit by this projectile again
}
}
}