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

2013/2/25

Repeat Until?

saskekun95 saskekun95

2013/2/25

#
Please excuse me, I am new to Greenfoot and still learning on the Wombat Scenario. I googled everywhere but i cant find the code i need. So it should be Repeat until a certain condition is met. Lets say i have a method downwards() and it should execute this until getWorld.getWidth() == getX() then it should execute method upwards() until getY() == 0 && getX() == 0. Then it should execute downwards again. How do i create this Loop?
danpost danpost

2013/2/25

#
You do not need seperate methods for 'downwards' and 'upwards'. All you need is to 'turn' the actor when the proper conditions are met. The conditions to turn around at the top of the screen are (1) the y-coordinate of the actor is zero and (2) the rotation of the actor is 270. The conditions to turn around at the bottom of the screen are (1) the y-coordinate of the actor is one less than the width of the world and (2) the rotation of the actor is 90. When either set of conditions is true, turn the actor around 180 degrees.
You need to login to post a reply.