How do I detect the collision between the bullet and the enemy? [duplicate]

"bullet" with lowercase b is an array of Bullets, but isShot() expects a single Bullet object. And "Bullet" with capital B is not a variable, but a class (I suppose).

So, you either need to create another object of Bullet or use one of the Bullet object in your "bullet" ArrayList.


You are almost there. I suggest you use more meaningful names for your parameters. First of all, you have to populate the ArrayList bullet in your setup() or elsewhere you want in your code.

After this, if you want to check that condition using isShot function you should pass to it an instance of an Object, not the class Object itself.

This can be easily achieved by including the function in your for loop.

While it is always good to practice, I suggest you to first understand the basics of the language and then move to more complex examples (custom classes, arrays iterations and so on).

void setup()
{
  size (1000, 1000);
  p1= new Player(500,5, 40);
  e[1]= new Enemy(100,1000,3);
   e[2]= new Enemy(500,800,3);
    e[3]= new Enemy(700,700,3);
    bullet.add(new Bullet(500,500,-5)); // e.g. to populate array
}

void draw()
{
  background(255);
  p1.render();
  e[1].render();
  e[1].move();
  e[2].render();
  e[2].move();
  e[3].render();
  e[3].move();
  text("Score:" + score,50,50);
  
  for (Bullet b: bullet)
  {
    b.render();
    b.move();

    if (e[1].isShot(b)) // now you can use b which is an instance of Bullet
    {
     e[1]=null;
    }
  }