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
Actor actor = new ActorClassName(); actor.turn(Greenfoot.getRandomNumber(360)); addObject(actor, < x, y >); // plug in location coordinates
public void act()
{
move();
}
private void move(){
Ball ball = new Ball();
ball.turn(Greenfoot.getRandomNumber(360));
move(1);
}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);
}
}addObjects(ball,300,200); ball.turn(Greenfoot.getRandomNumber(360));