I am working on a project for class where we have to create a game where a person avoids robots(Chasers) that explode when they hit each other and move closer to the runner when the runner moves. Every time that I try to run the program, I get a list of errors saying "java.lang.IndexOutOfBoundsException: Index: 0, Size: 0" on Chaser.java:38. Here is my code for the chaser class. Can someone please help me? Thank you!
public void act()
{
this.move(1);
//Remove chaser if chaser is touching explosion
if(isTouching(Explosion.class)){
getWorld().removeObject(this);
}
//remove chaser if chaser is touching another chaser
if(isTouching(Chaser.class)){
getWorld().addObject(new Explosion(),getX(),getY());
removeTouching(Runner.class);
//World().removeObject(Chaser);
}
//have chasers follow the runner if runner is still in the world
Runner runner = (Runner)getWorld().getObjects(Runner.class).get(0);
int RunnerX = runner.getX();
int RunnerY = runner.getY();
{
turnTowards(RunnerX,RunnerY);
move(1);
}
}
}
