I'm making an asteroid/spaceship game for my game programming class and I need to make the asteroid disappear after being hit twice. This is the code for my Bullet class:
If I remove the counter and just have the asteroid removed from the world after being shot once, it works. It's only when I add the ifs that it doesn't seem to work.
Thanks for the help.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public void act() { super .act(); Actor asteroid = getOneIntersectingObject(Asteroid. class ); int counter = 0 ; if (asteroid != null ) { counter++; if (counter == 2 ) { SimulationWorld world = (SimulationWorld) getWorld(); // Simulation World is a Class the teacher made for us world.removeObject(asteroid); } } } |