Trying to get have asteroid destroyed on one bullet...any ideas?
public void hit(int damage) {
stability = stability - damage;
if(stability <= 0)
explode();


1 2 3 4 5 6 7 8 9 10 11 12 | public class Bullet ... { public void act() { ... if (getWorld().getOneObjectAtOffset( 0 , 0 , Asteriod. class ).size() != 0 ) { getWorld().removeObject(getWorld().getOneObjectAtOffset( 0 , 0 , Asteroid. class )); //removing the asteroid; getWorld().removeObject( this ); //remove the bullet. return ; //not necessary but if other code follows this there might be Exceptions. } ... } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | // in the Asteroid act method if (seeBullet()) { eatBullet(); explode(); return ; } // methods private boolean seeBullet() { return !getObjectsInRange(getWidth() / 2 , Bullet. class ).isEmpty(); } private eatBullet() { getWorld().removeObject((Bullet) getObjectsInRange(getWidth() / 2 , Bullet. class ).get( 0 )); } |
1 | private void eatBullet() |