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

2015/7/15

need help

sllewis sllewis

2015/7/15

#
Hi all, So I have changed a few things in my code. However, now I am getting an error saying that the getMovement variable isn't right. Can you tell me why it is doing this, and how I can fix it?
import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)
 
/**
 * A rock in space
 * 
 */
public class Asteroid extends SmoothMover
{
    /** Size of this asteroid */
    private int size;
     
    /** When the stability reaches 0 the asteroid will explode */
    private int stability;
     
     
    public Asteroid()
    {
        this(50);
    }
     
    public Asteroid(int size)
    {
        super(new Vector(Greenfoot.getRandomNumber(360), 2));
        setSize(size);
    }
     
    public Asteroid(int size, Vector speed)
    {
        super(speed);
        setSize(size);
    }
     
    public void act()
    {         
        move();
        intersecting();
    }
 
    /**
     * Set the size of this asteroid. Note that stability is directly
     * related to size. Smaller asteroids are less stable.
     */
    public void setSize(int size) 
    {
        stability = size;
        this.size = size;
        GreenfootImage image = getImage();
        image.scale(size, size);
    }
 
    /**
     * Return the current stability of this asteroid. (If it goes down to 
     * zero, it breaks up.)
     */
    public int getStability() 
    {
        return stability;
    }
     
    /**
     * Hit this asteroid dealing the given amount of damage.
     */
    public void hit(int damage) {
        stability = stability - damage;
        if(stability <= 0) 
            breakUp ();         
    }
     
    /**
     * Break up this asteroid. If we are still big enough, this will create two
     * smaller asteroids. If we are small already, just disappear.
     */
    private void breakUp() 
    {
       
        

        Greenfoot.playSound("Explosion.wav");
         
        if(size <= 16) 
        {
            Space space = (Space) getWorld();
            getWorld().removeObject(this);
        }
        else
        {
            int r = getMovement().getDirection() + Greenfoot.getRandomNumber(45);
            double l = getMovement().getLength();
            Vector speed1 = new Vector(r + 60, l * 1.2);
            Vector speed2 = new Vector(r - 60, l * 1.2);        
            Asteroid a1 = new Asteroid(size/2, speed1);
            Asteroid a2 = new Asteroid(size/2, speed2);
            getWorld().addObject(a1, getX(), getY());
            getWorld().addObject(a2, getX(), getY());        
            a1.move();
            a2.move();
         
            getWorld().removeObject(this);
        }
    }
     
    public void intersecting() {
        Actor rocket = getOneIntersectingObject(Rocket.class);
        if(rocket != null) {
            Actor Explosion = new Explosion();
            getWorld().addObject(Explosion,getX(), getY());
            Actor ScoreBoard = new ScoreBoard();
            getWorld().addObject(ScoreBoard,(578),(406));
            Greenfoot.playSound("MetalExplosion.wav");
            getWorld().removeObject(rocket);
            getWorld().removeObject(this);
        }
    }
}

sllewis sllewis

2015/7/15

#
I am referring to line 87 which is giving me the error
danpost danpost

2015/7/15

#
In what class is the 'getMovement' method and what is its code?
sllewis sllewis

2015/7/15

#
@danpost- How would i find out where that is? I told you, i am really bad at this. I am sorry for the dumb question.
danpost danpost

2015/7/15

#
Why would you call a method that you do not know (1) what it does (2) where it is and (3) how to use it? You can search for the string, 'getMovement', and hopefully locate the method with that name within the class editor. Start in the Asteroid class; then, move on to the class it extends (the SmoothMover class); then, the class it extends -- until the class extends the Actor class. If any of those classes implements any other classes, those should be searched for the method also. If you cannot find it, then you need to ask yourself "Why were you trying to call the method to begin with?" or "Where did this line of code come from?"
danpost danpost

2015/7/15

#
I believe the scenario you got the SmoothMover class from also had the Vector class, which you need to also include into your project.
davmac davmac

2015/7/16

#
sllewis wrote...
However, now I am getting an error saying that the getMovement variable isn't right.
I find it hard to believe that the error message is really "getMovement variable isn't right". What is the error really saying? By not telling us the actual error message, you're making it hard for us to tell what is actually wrong.
You need to login to post a reply.