I need help figuring out some code to have an actor pick a random direction(1-360) and move that way. I dont want it to turn more than once just pick a direction and go till it touches the edge. I dont have any starting code


1 2 3 | Actor actor = new ActorClassName(); actor.turn(Greenfoot.getRandomNumber( 360 )); addObject(actor, < x, y >); // plug in location coordinates |
1 2 3 4 5 6 7 8 9 10 | public void act() { move(); } private void move(){ Ball ball = new Ball(); ball.turn(Greenfoot.getRandomNumber( 360 )); move( 1 ); } |
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 PongWorld extends World { private Ball ball = new Ball(); public PongWorld() { super ( 600 , 400 , 1 ); addObject( new Paddle(), 300 , 380 ); addObject( new Brick(), 50 , 43 ); addObject( new Brick(), 100 , 43 ); addObject( new Brick(), 150 , 43 ); addObject( new Brick(), 200 , 43 ); addObject( new Brick(), 250 , 43 ); addObject( new Brick(), 300 , 43 ); addObject( new Brick(), 350 , 43 ); addObject( new Brick(), 400 , 43 ); addObject( new Brick(), 450 , 43 ); addObject( new Brick(), 500 , 43 ); addObject( new Brick(), 550 , 43 ); addObject( new Brick(), 600 , 43 ); getBall(); } public getBall(){ addObject(ball, 300 , 200 ); Ball.turn(Greenfoot.getRandomNumber( 360 )); move( 1 ); } } |
1 2 | addObjects(ball, 300 , 200 ); ball.turn(Greenfoot.getRandomNumber( 360 )); |