Hello,
I am creating a little game, the world is 15x12 big with a pixsize of 60. I want to use this multidimensional array, it's like a plan for my level:
and I am using this code here to place the actors (0 == nothing, 1 == Tree):
And everytime I compiled it, everything was ok. But if I click at the start button, the game stops and this appears:
java.lang.ArrayIndexOutOfBoundsException: 12
private int [][] lvlData = {
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
};
public void init_map()
{
for (int y = 0; y < getHeight() ; y++) {
for(int x = 0; x < getWidth(); x++) {
int ID = lvlData[x][y];
if (ID == 1)
{
addObject(new Tree(),x,y);
}
}
}
}
