I'm new to programming and I'm trying to figure find some code to stop a randomly moving object. Then for me to be able to control that object using the arrow keys. I already know how to make a object move with the arrow keys but I can't figure out how to gain control after that. This is what I have already:
{
randomMove();
if(isTouching(person.class))
{
removeTouching(person.class);
if (Greenfoot.isKeyDown("up"))
{
move (2);
}
if (Greenfoot.isKeyDown("down"))
{
move (2);
}
if (Greenfoot.isKeyDown("left"))
{
setLocation(getX()-2,getY());
}
if (Greenfoot.isKeyDown("right"))
{
setLocation(getX()+2,getY());
}
if (isAtEdge())
{
Greenfoot.stop();
}
}
}
private void randomMove()
{
move (Greenfoot.getRandomNumber(4));
turn (Greenfoot.getRandomNumber(10)-5);
if(isAtEdge())
{
turn(180);
}
}
