I'm creating a remake of plants vz zombies game and I want my plants to shoot at the zombies only when they're present in the same row. Right now I currently, can make the plants shoot but the bullets shoot even when the zombies are not on the screen. How do I get the bullets to shoot only when there is a zombie in the same row as the plant?
this is my current code:
public void shoot()
{
long current = System.currentTimeMillis();
if (current >= lastAdded + 2000)
{
lastAdded = current;
seed Seed = new seed();
// seeds are bullets
World world = getWorld();
if(world.getObjectsAt(getX() +10, getY()+0, seed.class).isEmpty())
// inserts bullet
{
world.addObject(Seed, getX() + 10, getY());
}
}
}
