I need help destroying two enemies in a galaga-like game i coded. In my bullet class, i can shoot and hit enemy1 and have it disappear no problem, but when my bullet hits the asteroid, i get an error saying the actor isnt in the code. I dont know how to make them both disappear with no errors.
[Disallowed URL]
public class Bullet extends Actor
{
private int speed=-5;
/**
* Act - do whatever the Beeper wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(),getY()+speed);
destroyAsteroids();
destroyEnemy1();
//checkBoundaries();
}
public void destroyAsteroids()
{
Actor asteroid=getOneIntersectingObject(Asteroid.class);
if(asteroid !=null)
{
getWorld().removeObject(asteroid);
getWorld().removeObject(this);
}
}
public void destroyEnemy1()
{
Actor enemy1=getOneIntersectingObject(Enemy1.class);
if(enemy1 !=null)
{
getWorld().removeObject(enemy1);
getWorld().removeObject(this);
}
}
