Ir ao conteúdo
  • Cadastre-se

Java Erro em código Java Eclipse


Posts recomendados

Este meu código está me dando erro em 3 linhas mas não consigo resolvé-lo se algúem puder me ajudar agradeço muito.

Estes são os erros que estão me dando: 

at com.sunnystudios.main.Game.tick(Game.java:93)
    at com.sunnystudios.main.Game.run(Game.java:139)
    at java.base/java.lang.Thread.run(Thread.java:832)
 

package com.sunnystudios.world;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.sunnystudios.entities.*;
import com.sunnystudios.main.Game;

public class World {
    
    public static Tile[] tiles;
    public static int WIDTH, HEIGHT;
    public static final int TILE_SIZE = 16;
    
    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){
                        //Floor
                        tiles[xx +(yy * WIDTH)] = new FloorTile(xx*16,yy*16,Tile.TILE_FLOOR);
                    }else if( pixelAtual == 0xFFFFFFFF) {
                        //Parede
                        tiles[xx +(yy * WIDTH)] = new WallTile(xx*16,yy*16,Tile.TILE_WALL);
                    }else if(pixelAtual == 0xFF382DFF) {
                        //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 == 0xFF57007F) {
                        //Weapon
                        Game.entities.add(new Weapon(xx*16, yy*16, 16, 16, Entity.WEAPON_EN));
                    }else if(pixelAtual == 0xFF00FF21) {
                        //Life Pack
                        Game.entities.add(new Lifepack(xx*16, yy*16, 16, 16, Entity.LIFEPACK_EN));
                    }else if(pixelAtual == 0xFFFF6A00) {
                        //Bullet
                        Game.entities.add(new Bullet(xx*16, yy*16, 16, 16, Entity.BULLET_EN));
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    public static boolean isFree(int xnext, int ynext) {
        int x1 = xnext / TILE_SIZE;
        int y1 = ynext / TILE_SIZE;
        
        int x2 = (xnext+ TILE_SIZE) - 1 / TILE_SIZE;
        int y2 = ynext / TILE_SIZE;
        
        int x3 = xnext/ TILE_SIZE;
        int y3 = (ynext + TILE_SIZE) - 1 / TILE_SIZE;
        
        int x4 = (xnext + TILE_SIZE) - 1 / TILE_SIZE;
        int y4 = (ynext + TILE_SIZE) - 1 / TILE_SIZE;
        
        return !((tiles[x1 +(y1*World.WIDTH)] instanceof WallTile) ||
                (tiles[x2 +(y2*World.WIDTH)] instanceof WallTile) ||
                (tiles[x3 +(y3*World.WIDTH)] instanceof WallTile) ||
                (tiles[x4 +(y4*World.WIDTH)] instanceof WallTile));
    }
    
    public void render(Graphics g) {
        int xstart = Camera.x >> 4;
        int ystart = Camera.y >> 4;
        
        int xfinal = xstart + (Game.WIDHT >> 4);
        int yfinal = ystart + (Game.HEIGHT >> 4);
        
        for(int xx = xstart; xx <= xfinal; xx++) {
            for(int yy = ystart; yy <= yfinal; yy++) {
                if(xx < 0 || yy < 0 || xx >= WIDTH || yy >= HEIGHT)
                    continue;
                Tile tile = tiles[xx +(yy*WIDTH)];
                tile.render(g);
            }
            
        }
    }

}

  • Amei 1
Link para o comentário
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!