Whenever I try to run my game, the game crashes when I remove both the bomb, and the cannonball. If I take the out get.World.removeObject(this); the game works fine, however the projectile cannonball is still present and keeps on going. I only want to get rid of the bomb and the cannonball together.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class CannonBall here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class CannonBall extends Mover
{
/**
* Act - do whatever the CannonBall wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move (20);
checkBomb();
if (this.atWorldEdge()==true)
{World world;
world = getWorld();
world.removeObject(this);
return;
}
}
public void checkBomb()
{
if (getWorld() != null) {
Actor Bomb = getOneIntersectingObject(Bomb.class);
if (Bomb != null)
{
getWorld().removeObject(Bomb);
getWorld().removeObject(this);
return;
}
}
}
}
