This site requires JavaScript, please enable it in your browser!
Greenfoot back
crinno
crinno wrote ...

2014/11/9

Move error occurs when the bullet object is removed,this class extends the Mover class!! HELP PLEASE!!

crinno crinno

2014/11/9

#
public class bullet extends Mover
{
    /**
     * Act - do whatever the bullet wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        exitWorld();
        move(10.0);
        Actor bee = this.getOneIntersectingObject(bee.class);
        Actor plane = this.getOneIntersectingObject(airplane.class);
     
    }
    
     /**
         * If the bullet hits the plane, or bee it disappears along with that object
         * or if it hits the edge,it is removed also!! 
         */
    public void exitWorld()
    {   
        Actor bee = this.getOneIntersectingObject(bee.class);
        Actor plane = this.getOneIntersectingObject(airplane.class);
        
       if(atWorldEdge())
       {
            getWorld().removeObject(this);
       }
        
        if(bee != null)
       {         
           field f = (field)getWorld();
           f.countHit(50);
           World myWorld = getWorld();
           myWorld.removeObject(bee);
           myWorld.removeObject(this);
       }
        
        
           
        if(plane != null)
       {
             field f = (field)getWorld();
             World myWorld = getWorld();
             myWorld.removeObject(plane);
             myWorld.removeObject(this);
             f.gameOver();
       }
           
        
    }
    
}
Super_Hippo Super_Hippo

2014/11/9

#
You can't call 'getWorld()' after you removed the object. You could add a line like 'if (getWorld != null)' in line 29 and 40.
You need to login to post a reply.