Hi, I'm a new greenfoot user. This class creates a target that goes up, and then goes down after it reaches a random y-location. How can I have the instantiation of the class decelerate as it goes up, and the accelerate as it goes down?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import greenfoot.*; public class Target extends Actor { private int stopLocation; private boolean hasStop; public Target() { stopLocation = Greenfoot.getRandomNumber( 200 ); hasStop = false ; } public void act() { if (hasStop) setLocation(getX(), getY() + 1 ); //moveup if (getY() == (stopLocation + 100 )) { //the object stops at (stopLocation + 100) setLocation(getX(), getY()); //stop hasStop = true ; } if (!hasStop) setLocation(getX(), getY() - 1 ); //moves up if (getY() == 399 ) { //if it reaches the bottom again, game over. ((CannonWorld) getWorld()).gameOver(); } } |