I am working on an asteroids game and I would like my asteroid to split, creating two smaller asteroids when it gets hit by a bullet. I am stumped because in my code, the bullet gets destroyed when it hits an asteroid and an asteroid gets destroyed when it gets hit by a bullet. If I put my addObject code into Actor Asteroid, my game gets stuck because it doesn't know where to create it.
In my act method for Bullet class, I have
Any ideas why it isn't working and how I can fix this? Thanks in advance.
if(foundAsteroid()) {
destroyAsteroid();
} public boolean foundAsteroid() {
Actor asteroid = getOneObjectAtOffset(0, 0, Asteroid.class);
if(asteroid != null) {
return true;
}
else {
return false;
}
}
public void destroyAsteroid() {
Actor asteroid = getOneObjectAtOffset(0, 0, Asteroid.class);
if(asteroid != null) {
int x = getX();
int y = getY();
Actor smallAsteroid1 = new SmallAsteroid();
getWorld().addObject(smallAsteroid1, x, y);
Actor smallAsteroid2 = new SmallAsteroid();
getWorld().addObject(smallAsteroid2, x, y);
getWorld().removeObject(asteroid);
}
}