Making an object appear multiple times when required

I am trying to make a game about consuming balls and I have yet to find a solution for these two problems.
1- Making collision a one time thing without using a flag
2-Making my redorbs spawn exponantially after consuming one

for(int i = 0;i<redorb.length;i++){
redorb[i] = new Redorb();
.......
for(int i = 0;i<redorb.length;i++){
if(collide(redorb[i].redx,redorb[i].redy,posx,posy)==true){
//todo flag
  health --;
  mult++;
  redorb[i].redorb();
}
 }
......

class Redorb{
  int redx = int(random(30,750));
  int redy = int(random(30,750));
  void redorb(){
reds.background(255,0);
reds.fill(255,0,0);
reds.ellipse(redx,redy,10,10);  
}}
1 Like

maybe in your case instead of using an array, use an ArrayList since you can more easily add and remove items.

before setup()

ArrayList listOrbs = new ArrayList();

why not use a flag? Or you can remove them, which is a bit tricky with an ArrayList (for loop backwards)

OK, you can use add() to add 2 new orbs to the list. Use the pos of the initial one and also the direction with a small deviation

Chrisir

1 Like