I am a Comp sci 30 student and I am looking to finish my little project on increasing the Cloud's speed to go up gradually over time.
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 29 30 31 32 33 34 35 36 37 38 39 40 41 | public class Cloud extends Actor { private int speed = 4 ; //speed of the cloud private int rightTurn = 525 ; //right side change direction private int leftTurn = 240 ; //left side change direction /** * Move in the direction we are currently moving in. Turn if we reach a turning point. */ public void act() { setLocation (getX() + speed, getY()); Actor actor = getOneIntersectingObject( null ); //check whether we are not intersecting with an actor if (actor != null ) { actor.setLocation ( actor.getX() + speed, actor.getY() ); //pengu will move with the cloud } if (atTurningPoint()) { speed = -speed; //changes the direction of the cloud } } public boolean atTurningPoint() { if (getX()<= leftTurn || getX()>= 525 ) { return true ; } else { return false ; } } } |