Preciso de ajuda pra resolver isso aqui toda vez tento iniciar acontece esse erro
Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 420
at com.gcstudios.world.World.(World.java:25)
at com.gcstudios.main.Game.(Game.java:49)
at com.gcstudios.main.Game.main(Game.java:108)
World
package com.gcstudios.world;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
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())];
if (pixelAtual == 0xFF000000){
//Chão
tiles[xx = (yy*WIDTH)] = new FloorTile(xx*32,yy*32,Tile.TILE_FLOOR);
}else if(pixelAtual == 0xFFFFFFFF){
//Parede
tiles[xx = (yy*WIDTH)] = new FloorTile(xx*32,yy*32,Tile.TILE_WALL);
}else if(pixelAtual == 0xFF0026FF){
//Player
tiles[xx = (yy*WIDTH)] = new FloorTile(xx*32,yy*32,Tile.TILE_FLOOR);
}else {
tiles[xx = (yy*WIDTH)] = new FloorTile(xx*32,yy*32,Tile.TILE_FLOOR);
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void render(Graphics g){
for (int xx =0;xx < WIDTH; xx++){
for (int yy =0;yy < HEIGHT; yy++){
Tile tile =tiles [xx +(yy*WIDTH)];
tile.render(g);
}
}
}
}
Main
package com.gcstudios.main;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import com.gcstudios.entidades.Entity;
import com.gcstudios.entidades.Player;
import com.gcstudios.graficos.Spritesheet;
import com.gcstudios.world.World;
public class Game extends Canvas implements Runnable,KeyListener{
private static final long serialVersionUID = 1L;
public static JFrame frame;
private Thread thread;
private boolean isRunning = true;
private final int WIDTH = 240;
private final int HEIGHT = 120;
private final int SCALE = 4;
private BufferedImage image;
public List<Entity> entities;
public static Spritesheet spritesheet;
public World world;
private Player player;
public Game ( ) {
addKeyListener(this);
setPreferredSize(new Dimension (WIDTH*SCALE,HEIGHT*SCALE));
initFrame();
//Inicializando Objeto
image = new BufferedImage(160,120,BufferedImage.TYPE_INT_RGB);
entities = new ArrayList<Entity>();
spritesheet = new Spritesheet("/wFRJj.png");
world = new World("/map.png");
player = new Player(0,0,32,32,spritesheet.getSprite(0,0,32,32) );
entities.add(player);
}
public void initFrame(){
frame = new JFrame ("Game #1");
frame.add(this);
frame.setResizable(false);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public synchronized void start(){
thread = new Thread(this);
isRunning = true;
thread.start();
}
public void tick (){
for (int i = 0; i < entities.size(); i++){
Entity e = entities.get(i);
if(e instanceof Player){
e.tick();
}
}
}
public void render(){
BufferStrategy bs = this.getBufferStrategy();
if (bs == null) {
this.createBufferStrategy(3);
return;
}
Graphics g = image.getGraphics();
g.setColor(new Color (0,0,255) );
g.fillRect(0, 0, WIDTH, HEIGHT);
//rederiazaçao
//Graphics2D 2g =(Graphics2D) g;
for (int i = 0; i < entities.size(); i++){
Entity e = entities.get(i);
e.render(g);
}
g.dispose();
g = bs.getDrawGraphics();
g.drawImage(image,0,0,WIDTH*SCALE,HEIGHT*SCALE,null);
bs.show();
}
public synchronized void stop(){
}
public static void main (String agrs [ ] ) {
Game game = new Game();
game.start();
}
public void run() {
long lastTime = System.nanoTime();
double amountOfTicks = 60.0;
double ns = 1000000000 / amountOfTicks;
double delta = 0;
int frames = 0;
double timer =System.currentTimeMillis();
while(isRunning){
long now = System.nanoTime();
delta+= (now - lastTime) / ns;
lastTime= now;
if(delta >= 1){
tick();
render();
frames++;
delta --;
}
if(System.currentTimeMillis() - timer >= 1000 ){
System.out.println("FPS: "+ frames );
frames = 0;
timer+=1000;
}
}
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_D){
player.right =true;
}else if(e.getKeyCode()== KeyEvent.VK_A){
player.left =true;
}
if (e.getKeyCode() == KeyEvent.VK_W){
player.up =true;
}else if(e.getKeyCode()== KeyEvent.VK_S){
player.down =true;
}
}
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_D){
player.right =false;
}else if(e.getKeyCode()== KeyEvent.VK_A){
player.left =false;
}
if (e.getKeyCode() == KeyEvent.VK_W){
player.up =false;
}else if(e.getKeyCode()== KeyEvent.VK_S){
player.down =false;
}
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
}