Reset Arraylist of "Enemies" in order to Replay the Game

Hi,
So I’m trying to create a game and I have an Arraylist of enemies. I want upon collision to reset it, in order if chosen by the player to play again from the “lose” screen to take him back and totally restart the game.

Any solutions for that?

This is a sample of my code:

String gameState;

float posX;

//Level 1 (100 secs mode)
ArrayList<Enemies> enemiesRowOne = new ArrayList<Enemies>();

//player Array
ArrayList<Player> player = new ArrayList<Player>();


Player p;
Timer t;
Enemies e;

public void settings() {
  size(699, 700);
}

void setup() {
  //Classes
  e= new Enemies();
  p= new Player();
  t= new Timer(103);
  gameState = "START";
  
  //Player Array List
  player= new ArrayList<Player>();
  for (int i=0; i < 1; i++) {
    player.add(new Player());
  }
  
  //Level 1 (100secs mode)
  enemiesRowOne= new ArrayList<Enemies>();
  for (int i=0; i < 30; i++) {
    enemiesRowOne.add(new Enemies());
  }
}


void draw() {

if (gameState== "START") {
    startGame();
  } else if(gameState == "CREDITS"){
    creditsPage();
  } else if (gameState == "INSTRUCTIONS"){
    instructionsPage();
  }else if (gameState == "CHOOSE") {
    choosePlayer();
  } else if (gameState == "PLAY1") {
    choosePlayer1();
  } else if (gameState == "PLAY2") {
    choosePlayer2();
  } else if (gameState == "PLAY3") {
    choosePlayer3();
  } else if (gameState == "WIN") {
    winGame();
  } else if (gameState == "LOSE") {
    loseGame();
  }
}

void startGame() {
  background(#212121);
  rect(150, 100, 350, 225);



  noStroke();
  fill(#20C4F4);
  rect(210, 405, 225, 50);
  fill(255);
  text("START GAME", 227, 440);


  noStroke();
  fill(#20C4F4);
  rect(210, 480, 225, 50);
  fill(255);
  text("INSTRUCTIONS", 223, 517);

  noStroke();
  fill(#20C4F4);
  rect(210, 555, 225, 50);
  fill(255);
  text("CREDITS", 264, 590);

  if (mousePressed == true) {
    if (mouseX > 210 && mouseX< 210+225 && mouseY> 405 && mouseY< 405+50) {
      gameState="CHOOSE";
    }
  }
}

void choosePlayer() {
  background(#212121);

  fill(255);
  text("CHOOSE YOURMOTORCYCLE'S COLOUR", 75, 250);


  stroke(255);
  strokeWeight(3);
  fill(0, 204, 255);
  rect(100, 300, 100, 100);

  stroke(255);
  strokeWeight(3);
  fill(255, 102, 204);
  rect(300, 300, 100, 100);

  stroke(255);
  strokeWeight(3);
  fill(102, 255, 51);
  rect(500, 300, 100, 100);

  if (mousePressed == true) {
    if (mouseX > 100 && mouseX< 100+100 && mouseY> 300 && mouseY< 300+100) {
      gameState = "PLAY1";
    }
  }
  if (mousePressed == true) {
    if (mouseX > 300 && mouseX< 300+100 && mouseY> 300 && mouseY< 300+100) {
      gameState = "PLAY2";
    }
  }
  if (mousePressed == true) {
    if (mouseX > 500 && mouseX< 500+100 && mouseY> 300 && mouseY< 300+100) {
      gameState = "PLAY3";
    }
  }
}


void choosePlayer1() {
  if (t.getTime()< 0  ) {
    gameState= "WIN";
  }
  background(#212121);
  t.countDown();
  fill(255);
  text(t.getTime(), 615, 50);

  

  //Level 1 for 100 seconds mode
  if (t.getTime()< 102 &&t.getTime()> 80  ) {
     for ( Enemies e : enemiesRowOne) {
      e.displayRowOne();
      e.move();
    }
     //for collision player & obstacles Lvl1
  for ( Enemies e : enemiesRowOne) {
    for ( Player p : player) if (e.crashesRowOne(p)) {
      gameState = "LOSE";
    }
  }
  }
  for ( Player p : player) {
    p.displayGreen();
  }
  
  
}

class Timer{
  float Time;
  
  Timer(float set){
   Time=set; 
  }
  
  float getTime(){
   return(Time); 
  }
  
  void setTime(float set){
   Time = set; 
  }
  
  void countDown(){
   Time-=1/frameRate; 
  }
  
  
  
}

class Enemies {

  int eW;
  int eH;
  int eMW;
  int eMH;
  float speedLvl1;
  float speedLvl2;
  float speedLvl3;
  float speedLvl4;
  float speedLvl5;
  float life=1;




  //row1 Enemies
  float rowOneX= 40;
  float rowOneY= random(-15000, 0);
  
  Enemies() {
    eW=50;
    eH=70;
    speedLvl1=2.8;
    speedLvl2=3.4;
    speedLvl3=4;
    speedLvl4=4.6;
    speedLvl5=5.2;
    eMW=30;
    eMH=70;
  }
  
  void move() {
    //enemies move for Lvl1 for 100 seconds mode
    rowOneY=rowOneY+speedLvl1;
    
  }
  
   //Enemy objects display for 100secs
  void displayRowOne() {
    noStroke();
    fill(255);
    rect(rowOneX, rowOneY, eW, eH);
  }
  
  //booleans used for collision of player and obstacles
  boolean crashesRowOne(Player p) {
    if(50<rowOneX+eW && 50+p.playerW>rowOneX && p.playerY<rowOneY+eH && p.playerY+p.playerH>rowOneY){
    return true;
    }else{
     return false; 
    }
  }
}

class Player{
 float playerX;
 float playerY;
 float playerW;
 float playerH;
 int lives=3;
 
 
  
  
  Player(){
    playerW=30;
    playerH=70;
    playerY=550;
  }
  
  void displayPink(){
    fill(255,102,204);
 rect(50, playerY, playerW,playerH);
  }
  
  void displayGreen(){
    fill(102,255,51);
 rect(50, playerY, playerW,playerH);
  }
  
  void displayBlue(){
    fill(0,204,255);
 rect(50, playerY, playerW,playerH);
  }
  
  
  
}

void instructionsPage() {
}

void creditsPage() {
}

void winGame() {
  background(#212121);
  fill(255);
  text("YOU WIN", 250, 300);
}

void loseGame() {
  background(#212121);
  text("YOU LOST!", 250, 235);

  noStroke();
  fill(#20C4F4);
  rect(215, 335, 245, 50);
  fill(255);
  text("PLAY AGAIN", 248, 370);

  noStroke();
  fill(#20C4F4);
  rect(215, 400, 245, 50);
  fill(255);
  text("BACK TO MENU", 226, 437);


  if (mousePressed == true) {
    if (mouseX > 215 && mouseX< 215+245 && mouseY> 335 && mouseY< 335+50) {
      gameState = "CHOOSE";
    }
  }
}

void choosePlayer2() {
  if (t.getTime()< 0  ) {
    gameState= "WIN";
  }
  background(#212121);
  t.countDown();
  fill(255);
  text(t.getTime(), 615, 50);

  

  //Level 1 for 100 seconds mode
  if (t.getTime()< 102 &&t.getTime()> 80  ) {

    for ( Enemies e : enemiesRowOne) {
      e.displayRowOne();
      e.move();
    }
    
    //for collision player & obstacles Lvl1
  for ( Enemies e : enemiesRowOne) {
    for ( Player p : player) if (e.crashesRowOne(p)) {
      gameState = "LOSE";
    }
  }
  }
  for ( Player p : player) {
    p.displayGreen();
  }
}

void choosePlayer3() {
  if (t.getTime()< 0  ) {
    gameState= "WIN";
  }
  background(#212121);
  t.countDown();
  fill(255);
  text(t.getTime(), 615, 50);

  

  //Level 1 for 100 seconds mode
  if (t.getTime()< 102 &&t.getTime()> 80  ) {

    for ( Enemies e : enemiesRowOne) {
      e.displayRowOne();
      e.move();
    }
    
    //for collision player & obstacles Lvl1
  for ( Enemies e : enemiesRowOne) {
    for ( Player p : player) if (e.crashesRowOne(p)) {
      gameState = "LOSE";
    }
  }
  for ( Player p : player) {
    p.displayGreen();
  }
  }
}
  
  
1 Like

please format your code posting by pasting it into the

</> code button

of the editor header menu ( context name: Preformatted text )
it looks like
```
type or paste code here
```

also can use the ``` manually above and below your code.

thank you.


Sorry for that! There you go

String gameState;

float posX;

//Level 1 (100 secs mode)
ArrayList<Enemies> enemiesRowOne = new ArrayList<Enemies>();

//player Array
ArrayList<Player> player = new ArrayList<Player>();


Player p;
Timer t;
Enemies e;

public void settings() {
  size(699, 700);
}

void setup() {
  //Classes
  e= new Enemies();
  p= new Player();
  t= new Timer(103);
  gameState = "START";
  
  //Player Array List
  player= new ArrayList<Player>();
  for (int i=0; i < 1; i++) {
    player.add(new Player());
  }
  
  //Level 1 (100secs mode)
  enemiesRowOne= new ArrayList<Enemies>();
  for (int i=0; i < 30; i++) {
    enemiesRowOne.add(new Enemies());
  }
}


void draw() {

if (gameState== "START") {
    startGame();
  } else if(gameState == "CREDITS"){
    creditsPage();
  } else if (gameState == "INSTRUCTIONS"){
    instructionsPage();
  }else if (gameState == "CHOOSE") {
    choosePlayer();
  } else if (gameState == "PLAY1") {
    choosePlayer1();
  } else if (gameState == "PLAY2") {
    choosePlayer2();
  } else if (gameState == "PLAY3") {
    choosePlayer3();
  } else if (gameState == "WIN") {
    winGame();
  } else if (gameState == "LOSE") {
    loseGame();
  }
}

void startGame() {
  background(#212121);
  rect(150, 100, 350, 225);



  noStroke();
  fill(#20C4F4);
  rect(210, 405, 225, 50);
  fill(255);
  text("START GAME", 227, 440);


  noStroke();
  fill(#20C4F4);
  rect(210, 480, 225, 50);
  fill(255);
  text("INSTRUCTIONS", 223, 517);

  noStroke();
  fill(#20C4F4);
  rect(210, 555, 225, 50);
  fill(255);
  text("CREDITS", 264, 590);

  if (mousePressed == true) {
    if (mouseX > 210 && mouseX< 210+225 && mouseY> 405 && mouseY< 405+50) {
      gameState="CHOOSE";
    }
  }
}

void choosePlayer() {
  background(#212121);

  fill(255);
  text("CHOOSE YOURMOTORCYCLE'S COLOUR", 75, 250);


  stroke(255);
  strokeWeight(3);
  fill(0, 204, 255);
  rect(100, 300, 100, 100);

  stroke(255);
  strokeWeight(3);
  fill(255, 102, 204);
  rect(300, 300, 100, 100);

  stroke(255);
  strokeWeight(3);
  fill(102, 255, 51);
  rect(500, 300, 100, 100);

  if (mousePressed == true) {
    if (mouseX > 100 && mouseX< 100+100 && mouseY> 300 && mouseY< 300+100) {
      gameState = "PLAY1";
    }
  }
  if (mousePressed == true) {
    if (mouseX > 300 && mouseX< 300+100 && mouseY> 300 && mouseY< 300+100) {
      gameState = "PLAY2";
    }
  }
  if (mousePressed == true) {
    if (mouseX > 500 && mouseX< 500+100 && mouseY> 300 && mouseY< 300+100) {
      gameState = "PLAY3";
    }
  }
}


void choosePlayer1() {
  if (t.getTime()< 0  ) {
    gameState= "WIN";
  }
  background(#212121);
  t.countDown();
  fill(255);
  text(t.getTime(), 615, 50);

  

  //Level 1 for 100 seconds mode
  if (t.getTime()< 102 &&t.getTime()> 80  ) {
     for ( Enemies e : enemiesRowOne) {
      e.displayRowOne();
      e.move();
    }
     //for collision player & obstacles Lvl1
  for ( Enemies e : enemiesRowOne) {
    for ( Player p : player) if (e.crashesRowOne(p)) {
      gameState = "LOSE";
    }
  }
  }
  for ( Player p : player) {
    p.displayGreen();
  }
  
  
}

class Timer{
  float Time;
  
  Timer(float set){
   Time=set; 
  }
  
  float getTime(){
   return(Time); 
  }
  
  void setTime(float set){
   Time = set; 
  }
  
  void countDown(){
   Time-=1/frameRate; 
  }
  
  
  
}

class Enemies {

  int eW;
  int eH;
  int eMW;
  int eMH;
  float speedLvl1;
  float speedLvl2;
  float speedLvl3;
  float speedLvl4;
  float speedLvl5;
  float life=1;




  //row1 Enemies
  float rowOneX= 40;
  float rowOneY= random(-15000, 0);
  
  Enemies() {
    eW=50;
    eH=70;
    speedLvl1=2.8;
    speedLvl2=3.4;
    speedLvl3=4;
    speedLvl4=4.6;
    speedLvl5=5.2;
    eMW=30;
    eMH=70;
  }
  
  void move() {
    //enemies move for Lvl1 for 100 seconds mode
    rowOneY=rowOneY+speedLvl1;
    
  }
  
   //Enemy objects display for 100secs
  void displayRowOne() {
    noStroke();
    fill(255);
    rect(rowOneX, rowOneY, eW, eH);
  }
  
  //booleans used for collision of player and obstacles
  boolean crashesRowOne(Player p) {
    if(50<rowOneX+eW && 50+p.playerW>rowOneX && p.playerY<rowOneY+eH && p.playerY+p.playerH>rowOneY){
    return true;
    }else{
     return false; 
    }
  }
}

class Player{
 float playerX;
 float playerY;
 float playerW;
 float playerH;
 int lives=3;
 
 
  
  
  Player(){
    playerW=30;
    playerH=70;
    playerY=550;
  }
  
  void displayPink(){
    fill(255,102,204);
 rect(50, playerY, playerW,playerH);
  }
  
  void displayGreen(){
    fill(102,255,51);
 rect(50, playerY, playerW,playerH);
  }
  
  void displayBlue(){
    fill(0,204,255);
 rect(50, playerY, playerW,playerH);
  }
  
  
  
}

void instructionsPage() {
}

void creditsPage() {
}

void winGame() {
  background(#212121);
  fill(255);
  text("YOU WIN", 250, 300);
}

void loseGame() {
  background(#212121);
  text("YOU LOST!", 250, 235);

  noStroke();
  fill(#20C4F4);
  rect(215, 335, 245, 50);
  fill(255);
  text("PLAY AGAIN", 248, 370);

  noStroke();
  fill(#20C4F4);
  rect(215, 400, 245, 50);
  fill(255);
  text("BACK TO MENU", 226, 437);


  if (mousePressed == true) {
    if (mouseX > 215 && mouseX< 215+245 && mouseY> 335 && mouseY< 335+50) {
      gameState = "CHOOSE";
    }
  }
}

void choosePlayer2() {
  if (t.getTime()< 0  ) {
    gameState= "WIN";
  }
  background(#212121);
  t.countDown();
  fill(255);
  text(t.getTime(), 615, 50);

  

  //Level 1 for 100 seconds mode
  if (t.getTime()< 102 &&t.getTime()> 80  ) {

    for ( Enemies e : enemiesRowOne) {
      e.displayRowOne();
      e.move();
    }
    
    //for collision player & obstacles Lvl1
  for ( Enemies e : enemiesRowOne) {
    for ( Player p : player) if (e.crashesRowOne(p)) {
      gameState = "LOSE";
    }
  }
  }
  for ( Player p : player) {
    p.displayGreen();
  }
}

void choosePlayer3() {
  if (t.getTime()< 0  ) {
    gameState= "WIN";
  }
  background(#212121);
  t.countDown();
  fill(255);
  text(t.getTime(), 615, 50);

  

  //Level 1 for 100 seconds mode
  if (t.getTime()< 102 &&t.getTime()> 80  ) {

    for ( Enemies e : enemiesRowOne) {
      e.displayRowOne();
      e.move();
    }
    
    //for collision player & obstacles Lvl1
  for ( Enemies e : enemiesRowOne) {
    for ( Player p : player) if (e.crashesRowOne(p)) {
      gameState = "LOSE";
    }
  }
  for ( Player p : player) {
    p.displayGreen();
  }
  }
}
  

I have tried to run this code to no avail. Missing variables (l, font, etc.) and some functions are not available (choosePlayer2, etc.). Note that it’s good to hit ‘command T’ in Processing to format your code nicely before copying and pasting here. All needs fixed and reposting. Hope this helps.

1 Like

now we need you to REPAIR your first CODE POSTING,
not make a other / new /better post.
( just think about the hundred peoples opening your topic in the future )


also i see i asked you already here at your last topic to format your code,
Make text that is drawn, editable ,
resulting that the admin needed later to repair it for you!!!


i see you make a single

Enemies e;

//enemies array
ArrayList enemiesRowOne = new ArrayList();

and later

enemiesRowOne= new ArrayList();
for (int i=0; i < 30; i++) {
    enemiesRowOne.add(new Enemies());
}

so what is your question about reset arraylist?
just do that again ?

The code is fixed now! Thanks for letting me know

So I have updated both posts of my code, now if you load it into processing you will see when the two objects collide it takes you to the “lose scene”. Then when you press “play again” it takes you to the choose colour screen. When selecting a colour the array list is still there on the same position it collided before and keeps colliding with the shape and crashes!

is there a way upon the first collision to make it reset until the colour box is called again?

Ok I took a quick look and there were a couple of issues I could see:

  • The enemies weren’t being reset – separated into a function call
  • The timer wasn’t being reset - set up a function call
  • The buttons mousePressed code was such that it was automatically selecting the pink button underneath – hacked a fix by moving your buttons up 100 pixels, but perhaps needs a more robust fix (use a separate mousePressed() function outside and check against gameState variable – this means only works on click not holding mouse down)

Hope this helps. Here is my quickly adjusted code:

String gameState;

float posX;

//Level 1 (100 secs mode)
ArrayList<Enemies> enemiesRowOne = new ArrayList<Enemies>();

//player Array
ArrayList<Player> player = new ArrayList<Player>();


Player p;
Timer t;
Enemies e;

public void settings() {
  size(699, 700);
}

void setup() {
  //Classes
  resetTimer();
  gameState = "START";

  //Player Array List
  player= new ArrayList<Player>();
  for (int i=0; i < 1; i++) {
    player.add(new Player());
  }

  setUpEnemies();
}


void draw() {

  if (gameState== "START") {
    startGame();
  } else if (gameState == "CREDITS") {
    creditsPage();
  } else if (gameState == "INSTRUCTIONS") {
    instructionsPage();
  } else if (gameState == "CHOOSE") {
    choosePlayer();
  } else if (gameState == "PLAY1") {
    choosePlayer1();
  } else if (gameState == "PLAY2") {
    choosePlayer2();
  } else if (gameState == "PLAY3") {
    choosePlayer3();
  } else if (gameState == "WIN") {
    winGame();
  } else if (gameState == "LOSE") {
    loseGame();
  }
}

void startGame() {
  background(#212121);
  rect(150, 100, 350, 225);



  noStroke();
  fill(#20C4F4);
  rect(210, 405, 225, 50);
  fill(255);
  text("START GAME", 227, 440);


  noStroke();
  fill(#20C4F4);
  rect(210, 480, 225, 50);
  fill(255);
  text("INSTRUCTIONS", 223, 517);

  noStroke();
  fill(#20C4F4);
  rect(210, 555, 225, 50);
  fill(255);
  text("CREDITS", 264, 590);

  if (mousePressed == true) {
    if (mouseX > 210 && mouseX< 210+225 && mouseY> 405 && mouseY< 405+50) {
      gameState="CHOOSE";
    }
  }
}

void choosePlayer() {
  background(#212121);

  fill(255);
  text("CHOOSE YOUR MOTORCYCLE'S COLOUR", 75, 250 - 100);


  stroke(255);
  strokeWeight(3);
  fill(0, 204, 255);
  rect(100, 200, 100, 100);

  stroke(255);
  strokeWeight(3);
  fill(255, 102, 204);
  rect(300, 200, 100, 100);

  stroke(255);
  strokeWeight(3);
  fill(102, 255, 51);
  rect(500, 200, 100, 100);

  if (mousePressed == true) {
    if (mouseX > 100 && mouseX< 100+100 && mouseY> 200 && mouseY< 200+100) {
      setUpEnemies();
      gameState = "PLAY1";
      resetTimer();
    }
  }
  if (mousePressed == true) {
    if (mouseX > 300 && mouseX< 300+100 && mouseY> 200 && mouseY< 200+100) {
      setUpEnemies();
      gameState = "PLAY2";
      resetTimer();
    }
  }
  if (mousePressed == true) {
    if (mouseX > 500 && mouseX< 500+100 && mouseY> 200 && mouseY< 200+100) {
      setUpEnemies();
      gameState = "PLAY3";
      resetTimer();
    }
  }
}


void choosePlayer1() {
  if (t.getTime()< 0  ) {
    gameState= "WIN";
  }
  background(#212121);
  t.countDown();
  fill(255);
  text(t.getTime(), 615, 50);



  //Level 1 for 100 seconds mode
  if (t.getTime()< 102 &&t.getTime()> 80  ) {
    for ( Enemies e : enemiesRowOne) {
      e.displayRowOne();
      e.move();
    }
    //for collision player & obstacles Lvl1
    for ( Enemies e : enemiesRowOne) {
      for ( Player p : player) if (e.crashesRowOne(p)) {
        gameState = "LOSE";
      }
    }
  }
  for ( Player p : player) {
    p.displayGreen();
  }
}

class Timer {
  float Time;

  Timer(float set) {
    Time=set;
  }

  float getTime() {
    return(Time);
  }

  void setTime(float set) {
    Time = set;
  }

  void countDown() {
    Time-=1/frameRate;
  }
}

class Enemies {

  int eW;
  int eH;
  int eMW;
  int eMH;
  float speedLvl1;
  float speedLvl2;
  float speedLvl3;
  float speedLvl4;
  float speedLvl5;
  float life=1;




  //row1 Enemies
  float rowOneX= 40;
  float rowOneY= random(-15000, 0);

  Enemies() {
    eW=50;
    eH=70;
    speedLvl1=2.8;
    speedLvl2=3.4;
    speedLvl3=4;
    speedLvl4=4.6;
    speedLvl5=5.2;
    eMW=30;
    eMH=70;
  }

  void move() {
    //enemies move for Lvl1 for 100 seconds mode
    rowOneY=rowOneY+speedLvl1;
  }

  //Enemy objects display for 100secs
  void displayRowOne() {
    noStroke();
    fill(255);
    rect(rowOneX, rowOneY, eW, eH);
  }

  //booleans used for collision of player and obstacles
  boolean crashesRowOne(Player p) {
    if (50<rowOneX+eW && 50+p.playerW>rowOneX && p.playerY<rowOneY+eH && p.playerY+p.playerH>rowOneY) {
      return true;
    } else {
      return false;
    }
  }
}

class Player {
  float playerX;
  float playerY;
  float playerW;
  float playerH;
  int lives=3;




  Player() {
    playerW=30;
    playerH=70;
    playerY=550;
  }

  void displayPink() {
    fill(255, 102, 204);
    rect(50, playerY, playerW, playerH);
  }

  void displayGreen() {
    fill(102, 255, 51);
    rect(50, playerY, playerW, playerH);
  }

  void displayBlue() {
    fill(0, 204, 255);
    rect(50, playerY, playerW, playerH);
  }
}

void instructionsPage() {
}

void creditsPage() {
}

void winGame() {
  background(#212121);
  fill(255);
  text("YOU WIN", 250, 300);
}

void loseGame() {
  background(#212121);
  text("YOU LOST!", 250, 235);

  noStroke();
  fill(#20C4F4);
  rect(215, 335, 245, 50);
  fill(255);
  text("PLAY AGAIN", 248, 370);

  noStroke();
  fill(#20C4F4);
  rect(215, 400, 245, 50);
  fill(255);
  text("BACK TO MENU", 226, 437);


  if (mousePressed == true) {
    if (mouseX > 215 && mouseX< 215+245 && mouseY> 335 && mouseY< 335+50) {
      gameState = "CHOOSE";
    }
  }
}

void choosePlayer2() {
  if (t.getTime()< 0  ) {
    gameState= "WIN";
  }
  background(#212121);
  t.countDown();
  fill(255);
  text(t.getTime(), 615, 50);



  //Level 1 for 100 seconds mode
  if (t.getTime()< 102 &&t.getTime()> 80  ) {

    for ( Enemies e : enemiesRowOne) {
      e.displayRowOne();
      e.move();
    }

    //for collision player & obstacles Lvl1
    for ( Enemies e : enemiesRowOne) {
      for ( Player p : player) if (e.crashesRowOne(p)) {
        gameState = "LOSE";
      }
    }
  }
  for ( Player p : player) {
    p.displayGreen();
  }
}

void choosePlayer3() {
  if (t.getTime()< 0  ) {
    gameState= "WIN";
  }
  background(#212121);
  t.countDown();
  fill(255);
  text(t.getTime(), 615, 50);



  //Level 1 for 100 seconds mode
  if (t.getTime()< 102 &&t.getTime()> 80  ) {

    for ( Enemies e : enemiesRowOne) {
      e.displayRowOne();
      e.move();
    }

    //for collision player & obstacles Lvl1
    for ( Enemies e : enemiesRowOne) {
      for ( Player p : player) if (e.crashesRowOne(p)) {
        gameState = "LOSE";
      }
    }
    for ( Player p : player) {
      p.displayGreen();
    }
  }
}

void setUpEnemies() {
  //Level 1 (100secs mode)
  enemiesRowOne= new ArrayList<Enemies>();
  for (int i=0; i < 30; i++) {
    enemiesRowOne.add(new Enemies());
  }
}

void resetTimer(){
  t= new Timer(103);
}```
2 Likes

Thank you so much! Works perfectly.

For the buttons I have added a delay so this makes the trick!