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

2013/11/3

help

KevinWelch2001 KevinWelch2001

2013/11/3

#
i have it so when the rocket hits a asteroid it plays a noise and the asteroid disappears. I tried making it able to remove the rocket ship and the asteroid at the same time but when i try to compile it says cannot find symbol- variable rocketship1.here is rocketship1 code
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * the main spaceship for the game.
 * 
 * @author (Kevin Welch) 
 * @version (2.0)
 */
public class rocketship1 extends Actor
{
    /**
     * Act - do whatever the rocketship1 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
 
        checkKeys();
        foundasteroid();
        hitasteriod();
    }    

    /**
     * check's what key is pressed
     */
    public void checkKeys()
    {
        if ( Greenfoot.isKeyDown("d") )
        {
            turn(5);
        }    
        if ( Greenfoot.isKeyDown("a") )
        {
            turn(-5);
        }    
        if ( Greenfoot.isKeyDown("w") )
        {
            move(4);
        } 
        if ( Greenfoot.isKeyDown("s") )
        {
            move(-1);
        } 
    }

    /**
     * Check whether there is a asteroid in the same cell as we are.
     */
    public boolean foundasteroid()
    {
        Actor asteroid = getOneObjectAtOffset(2, 2, asteroid.class);
        if(asteroid != null) 
        {
            return true; 

        }
        else {
            return false;
        }
    }

    /**
     * destroy's asteroid and ship.
     */
    public void hitasteriod()
    {
        Actor asteroid = getOneObjectAtOffset(2, 2, asteroid.class);
        if(asteroid != null) {
            Greenfoot.playSound("Explosion.mp3");
            getWorld().removeObject(asteroid);
            getWorld().removeobject(rocketship1);
        }
    }
}
erdelf erdelf

2013/11/3

#
well, u need a reference to remove something, here the reference this would be enough
getWorld().removeObject(this);
KevinWelch2001 KevinWelch2001

2013/11/3

#
thank you
You need to login to post a reply.