For some reason when I use the getObjects for the Plane class, after a new plane is added, a Index out of bounds error occurs. Can someone please help me?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Bomb here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bomb extends Actor
{
int timer = 0;
int starttimer = 0;
int i = 0;
/**
* Act - do whatever the Bomb wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
Bombing();
setRotation(60);
move(4);
}
public void Bombing()
{
Plane plane = (Plane)getWorld().getObjects(Plane.class).get(0+i);
int PlaneY = plane.getY();
int PlaneX = plane.getX();
if(i<=5)
{
if(PlaneX >= 200)
{
timer++;
if(PlaneX >= 600)
{
i++;
}
if (timer >= 100)
{
getWorld().addObject(new Bomb(),PlaneX, PlaneY);
timer = 0;
}
}
edgeHit();
}
}
public void edgeHit()
{
if(isAtEdge())
{
getWorld().removeObject(this);
}
}
}
