I have this code for my DoLogic method. And I'm trying to do a intersection between the shots and the obstacles but I really can't think of nothing.. cause both are different objects.. i tried to do some but it didn't really detect something at all.
for(int i=0; i<shots.length; i++)
{
if(shots[i] != null)
{
shots[i].moveShot(SHOTSPEED);
if(shots[i].getXPos() > 1280)
{
shots[i] = null;
}
}
}
for(int i=0; i<obstacles.length; i++)
{
if(obstacles[i] == null)
{
obstacles[i] = generateObstacle();
break;
}
if(obstacles[i] != null)
{
obstacles[i].moveObstacle();
if(obstacles[i].getXPos() < 10)
{
obstacles[i] = null;
}
else if(obstacles[i].intersects(Player1.character))
{
obstacles[i] = null;
GameSounds.hit("/resources/8bit_bomb_explosion.wav");
lives--;
}
}
}
Can you guys give me an example or at least an advice how to do an intersection between an obstacle and a shot?