i have asteroids store in arraylist. i want to check collision between player and asteroids. if player get hit than i want to minus one life and move the asteroid backwards so it look like it bounced in to player.
right now this code is check for collision between player and asteroids and works fine.
the problem is that when asteroid collised with player than the collision say for lil while. bc asteroid moves slower than player and if player hold down up keep than it will keep collision. and the player lifes keep going down.
i want it so that if player bump into astroid than only one life should go down.
/**Collision between player and astroid **/
public void playerAsteroidCollision(ArrayList<asteroid> asteroid, player p)
{
for(int i = 0; i < asteroid.size(); i++){
asteroid asteroid = (asteroid)asteroid.get(i);
if(player.getBounds().intersects(asteroid.getBounds())){
player.setHit(true); //player got hit
player.setLife(player.getLife() -1); //minus one life
//change the direction of asteroid so it goes backwords
asteroid.setDx(-asteroid.getDx());
asteroid.setDy(-asteroid.getDy());
}
}
}/***End of playerAsteroidCollision Method/