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

2019/4/12

Adding acceleration

Notted Notted

2019/4/12

#
I just want to know. The code I have now:
private int astroSpeed = 2;
    public void act() 
    {
        breakApart();
        setLocation(getX() + astroSpeed, getY() - astroSpeed);
    }
danpost danpost

2019/4/12

#
Notted wrote...
Adding acceleration I just want to know. The code I have now: << Code Omitted >>
Acceleration is just a continual (gradual) increase in speed.
Notted Notted

2019/4/12

#
So this?
 public void flyAround ()
    {
        int flyTimer = 10000;
        setLocation(getX() + astroSpeed, getY() + astroSpeed);
        flyTimer -= 1;
        if (astroSpeed == 0) {
            astroSpeed += astroAcc;
            setLocation(getX() + astroSpeed, getY() + astroSpeed);
            flyTimer = 10000;
        }
        if (astroSpeed == 2) {
            setLocation(getX() + astroSpeed, getY() + astroSpeed);
        }
        if (flyTimer == 0) {
            astroSpeed = 0;
        }
    }
Super_Hippo Super_Hippo

2019/4/12

#
Maybe you should comment each line with what you think it does or at least explain why you have it as you have it.
danpost danpost

2019/4/12

#
Line 3 need to be put outside the method.
Super_Hippo wrote...
Maybe you should comment each line with what you think it does or at least explain why you have it as you have it.
-- and describe the flying behavior you want for this actor.
Notted Notted

2019/4/12

#
It's no longer used now. I just removed it. My code:
 public void flyAround ()
    {
        setLocation(getX() + astroSpeed, getY() + astroSpeed);
        if (astroSpeed == 0) {
            astroSpeed += astroAcc;
            setLocation(getX() - astroSpeed, getY() - astroSpeed);
        }
        if (astroSpeed == 2) {
            setLocation(getX() + astroSpeed, getY() + astroSpeed);
        }
    }
danpost danpost

2019/4/12

#
Notted wrote...
It's no longer used now. I just removed it. << Code Omited >>
How is astroAcc declared? and why do you have 3 different setLocation lines (when you can move once according to your fields)? You really need to describe what behavior you want for moving.
You need to login to post a reply.