vendredi 25 mai 2018

How to reset a for loop and also simplify it?

say i have 4 variables:

int counter = 0;
int counter2 = -6;
int counter3 = -12;
int counter4 = -18;

These 4 variables increase in a certain if statement that fires from time to time as such:

if (such and such)
{
    counter++
    counter2++
    counter3++
    counter4++;
}

and in order these draw circles around the screen in rows, so counter draws circles in the first row, and once that row is filled, counter2 fills the second row and so on:

for (int i = 0; i < counter; i++) {
    ellipse(ScoreX+ i * 80, 40, BallSize, BallSize);
  }
  for (int j = 0; j < counter2; j++)
  {
    ellipse(ScoreX + j * 80, 120, BallSize, BallSize);
  }
for (int k = 0; k < counter3; k++)
  {
    ellipse(ScoreX + k * 80, 200, BallSize, BallSize);
  }
for (int l = 0; l < counter4; l++)
  {
    ellipse(ScoreX + l * 80, 280, BallSize, BallSize);
  }

My problem is that once the circles have been drawn all over the screen, I want this whole process to reset and keep happening until the program has been manually closed by me. Also, is there a way that this loop can be simplified?

Aucun commentaire:

Enregistrer un commentaire