o erro: (Exception in thread “Thread-0” java.lang.ArrayIndexOutOfBoundsException: Index -80 out of bounds for length 400
at com.AStudios.world.World.render(World.java:90)
at com.AStudios.main.Game.render(Game.java:110)
at com.AStudios.main.Game.run(Game.java:134)
at java.base/java.lang.Thread.run(Thread.java:830))
"package com.AStudios.world;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.AStudios.entities.*;
import com.AStudios.main.Game;
public class World {
private Tile[] tiles;
public static int WIDTH, HEIGHT;
public World(String path) {
try {
BufferedImage map = ImageIO.read(getClass().getResource(path));
int[] pixels = new int[map.getWidth()*map.getHeight()];
WIDTH = map.getWidth();
HEIGHT = map.getHeight();
tiles = new Tile[map.getWidth()*map.getHeight()];
map.getRGB(0, 0, map.getWidth(), map.getHeight(), pixels, 0,map.getWidth());
for(int xx = 0; xx < map.getWidth(); xx++) {
for(int yy = 0; yy < map.getHeight(); yy++) {
int pixelAtual = pixels [xx + (yy*map.getWidth())];
tiles[xx + (yy*WIDTH)] = new FloorTile(xx*16,yy*16,Tile.TILE_FLOOR);
if(pixelAtual == 0xFF000000 ) {
//Chão
tiles[xx + (yy*WIDTH)] = new FloorTile(xx*16,yy*16,Tile.TILE_FLOOR);
}else if( pixelAtual == 0xFFFFFFFF ) {
//Parede
tiles[xx + (yy*WIDTH)] = new FloorTile(xx*16,yy*16,Tile.TILE_WALL);
}else if (pixelAtual== 0xFF0026FF) {
//Player
Game.player.setX(xx*16);
Game.player.setY(yy*16);
}else if(pixelAtual == 0xFFFF0000) {
//Enemy
Game.entities.add(new Enemy(xx*16,yy*16, 16,16,Entity.ENEMY_EN));
}else if(pixelAtual == 0xFFFF6A00) {
//Arma
Game.entities.add(new Weapon(xx*16,yy*16, 16,16,Entity.WEAPON_EN));
}else if(pixelAtual == 0xFFFFEBD6) {
//Vida
Game.entities.add(new Lifepack(xx*16,yy*16, 16,16,Entity.LIFEPACK_EN));
}else if (pixelAtual == 0xFFFFD800){
//Balas
Game.entities.add(new Bullet(xx*16,yy*16, 16,16,Entity.BULLET_EN));
}
}
}
}
catch (IOException e) {
e.printStackTrace();}
}
public void render(Graphics g) {
int xstart = Camera.x/16;
int ystart = Camera.y/16;
int xfinal = xstart + (Game.WIDTH/16);
int yfinal = ystart + (Game.HEIGHT/16);
for (int xx = xstart; xx <= xfinal; xx++){
for (int yy = ystart; yy <= yfinal; yy++){
Tile tile = tiles[xx + (yy*WIDTH)];
tile.render(g);}
}
}
}
"