I have a game where the player controls a spaceship. I want the player to be able to press a button to release small fighters. These fighters should wander around the ships area however when i try to grab the coordinates from the ship i get a null pointer exception.
// in world
// in ship
//in Fighter Class
i think this is all that is needed to correct this.
Ship ship = new Ship(); addObject(ship,350,350);
public void launchFighter()
{
Fighter fighter = new Fighter();
if(Greenfoot.isKeyDown("Q"))
{
getWorld().addObject(fighter,getX(),getY());
}
}/**
* returns distance from ship
*/
public double getDistanceFromShip(Ship ship)
{
//Fix This
return Math.sqrt(Math.pow(getX()-ship.getX(),2)+Math.pow(getY()-ship.getY(),2));
}


