For the past few days, I have been struggling to get all the objects in my arraylist to be able to collide with the player object, but I am just struggling to get it to work. Im just not sure how to reference the array in the collision detection itself.
This is the collision im using, and where the “spaceRock1.x, spaceRock1.y” is, Thats where im trying to referecne the arrayList of objects but im pretty sure i am doing it wrong.
//collision between player and enemy
for (int i = 0; i < spaceRock1.size() - 15; i++)
{
if (dist(player_1.x, player_1.y, spaceRock1.x, spaceRock1.y) < enemyRad + playerRad)
{
//if collision, game lost and set game state to "LOSE"
lives--;
if (lives <=0)
{
gameState = "LOSE";
}
}
}
This is the arraylist i have created. I just followed the coding train arraylist tutorial and altered it from there
ArrayList<enemy> spaceRock1;
spaceRock1 = new ArrayList<enemy>();
for (int i = 0; i < 10; i++)
{
spaceRock1.add(new enemy());
}
for (enemy e : spaceRock1)
{
e.update();
}
Any help would be greatful
Many thanks