So I've tried and tried and tried, but can't get a successful cpu with some basic AI for my lightBike game...For 3.0 thats what I'm trying to do...Those of you who havent seen my lightbike game its at <http://greenfootgallery.org/scenarios/2538> ....My grid for 3.0 is (100,100,5) and Here's my code that won't seem to work:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
import java.util.ArrayList;
/**
* Cpu guy that tries to avoid your bike.
*
* @author (Michael Legere)
* @version (3.0)
*/
public class RedEnemy extends Mover
{
private static final int EAST = 0;
private static final int WEST = 1;
private static final int NORTH = 2;
private static final int SOUTH = 3;
private int direction;
public RedEnemy()
{
setDirection(WEST);
}
public boolean canMove()
{
World myWorld = getWorld();
int x = getX();
int y = getY();
switch(direction) {
case SOUTH :
y -= 1;
break;
case EAST :
x -= 1;
break;
case NORTH :
y += 1;
break;
case WEST :
x += 1;
break;
}
List line = myWorld.getObjectsAt(x, y, BlueLine.class);
if(line.isEmpty()) {
return true;
}
else {
return false;
}
}
public void setDirection(int direction)
{
this.direction = direction;
}
public void turnLeft()
{
setRotation(getRotation() + 90);
}
public void turnRight()
{
setRotation(getRotation() - 90);
}
public void think()
{
if(!canMove())
{
turnRight();
}
}
public void act()
{
think();
wrap();
generateRedLine();
move(-1);
}
}
If anyone was able to trudge through this could you give me some tips? The Cpu just runs straight and crashes into the player's line when its in front of it.