I am developing a Java game, and am currently writing a map maker. I can make the map and draw tiles, but i need to be able to change the position of those tiles so the character can see different locations of the map. When I try to change it, in the moveMap()
method, It gives me this error:
Exception in thread "Thread-2" java.lang.ArrayIndexOutOfBoundsException: 570
at Base.moveMap(Base.java:88)
at Base.run(Base.java:55)
at java.lang.Thread.run(Unknown Source)
I have no idea why this is happening - could someone please help me understand the problem. Is there any alternate way to move the tiles?
Here is my code...
public class Base extends JPanel implements Runnable {
private static String[] line = {
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwfffffffffffwwwwwwwwwww",
"wwwwwwffwwwwwwwwfwwwwwwwwwwwwwwwwwwwww",
"wwwwwwfffffffwwwfwwwwwwwwwwwwwwwwwwwww",
"wwwwwwffwwwffffffwwwwwwwwwwwwwwwwwwwww",
"wwwwwwffwwwffffffwwwwwwwwwwwwwwwwwwwww",
"wwwwwwfffffffwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwffwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwffwwwwwwwwwwwwwwffffffffwwwwwwww",
"wwwwwwffwwwwwwwwwwwwwwwwwwwwffwwwwwwww",
"wwwwffffffwwwwwwwwwwwwwwwwwwffwwwwwwww",
"wwwwffffffffffffffffffffffffffwwwwwwww",
"wwwwffffffwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",};
private Rectangle[] colRect;
private int tileWidth = 30;
private int tileHeight = 30;
public Base() {
colRect = new Rectangle[line.length * line[0].length()];
for (int i = 0; i < line.length; i++) {
for (int f = 0; f < line[i].length(); f++) {
colRect[counter] = new Rectangle(f * tileWidth, i * tileHeight,tileWidth, tileHeight);
if (counter != colRect.length) {
counter += 1;
}
}
}
}
public void moveMap(){
for(int i = 0; i <= colRect.length; i++){
colRect[i].setLocation(colRect[i].x+1, colRect[i].y+1);
}
}
}