I have an object named leviathan, how do i get it to move randomly without letting it go through the walls of the maze?
I posted yesterday asking how to get my rocket to not go through walls when controlling it, so I'm basing my code off of that.
Help would be greatly appreciated!
/**
* Using the code below the Rogue will turn at random.
* Right or left.
*/
public void randomTurn()
{
if ( Greenfoot.getRandomNumber (100) < 10)
{
turn( Greenfoot.getRandomNumber (90)-45);
}
if (canSee(Wall.class))
{
move(1);
}
}public void checkKeyPressed()
{
setRotation(90);
if (Greenfoot.isKeyDown("up"))
{move(-1); }
if (canSee(Wall.class))
{
move(1);
}
if (Greenfoot.isKeyDown("down"))
{move(1); }
if (canSee(Wall.class))
{
move(-1);
}
setRotation(0);
if (Greenfoot.isKeyDown("left"))
{move(-1); }
if (canSee(Wall.class))
{
move(1);
}
if (Greenfoot.isKeyDown("right"))
{move(1); }
if (canSee(Wall.class))
{
move(-1);
}
}

