Hi,
What code do I have to incorporate in my Ladybug class so that it is unable to walk through the Walls? My code is shown below. Possibly a switch statement?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Ladybug extends Actor
{
private static final int EAST = 0;
private static final int SOUTH = 90;
private static final int WEST = 180;
private static final int NORTH = 270;
public Ladybug()
{
setRotation( Greenfoot.getRandomNumber(4) * 90 );
}
public void act()
{
checkKeys();
}
public void checkKeys()
{
if( Greenfoot.isKeyDown("right") ) {
setRotation(EAST);
move(2);
}
if( Greenfoot.isKeyDown("down") ) {
setRotation(SOUTH);
move(2);
}
if( Greenfoot.isKeyDown("left") ) {
setRotation(WEST);
move(2);
}
if( Greenfoot.isKeyDown("up") ) {
setRotation(NORTH);
move(2);
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Wall extends Actor
{
public Wall()
{
GreenfootImage img = new GreenfootImage(35,35);
img.fill();
setImage(img);
}
}
