Alguem pode me ajudar, queria colocar uma mascara de colisão no Playerno projeto, mas sou muito noob ainda para fazer isso…
https://scontent.fssa12-1.fna.fbcdn.net/v/t1.6435-0/p235x350/180307563_128555145993566_3590632056211841899_n.jpg?_nc_cat=100&ccb=1-3&_nc_sid=730e14&nc_ohc=T9CSFK0ANmUAX_USux&_nc_ht=scontent.fssa12-1.fna&tp=6&oh=ab2debb96c3da524fe27ea5f477c628e&oe=60B4B694
///
https://scontent.faju11-1.fna.fbcdn.net/v/t1.6435-0/p261x260/179504416_128555132660234_2334900929780015977_n.jpg?_nc_cat=111&ccb=1-3&_nc_sid=730e14&_nc_ohc=G-FMaG7SuSEAX-RrHb4&_nc_ht=scontent.faju11-1.fna&tp=6&oh=da9c7c3b81effe9b7f1ba8e4bf0a055c&oe=60B55D20
Posta o código aqui, fica mais organizado e fácil de ler.
o código e grande;
///
public class Game extends Canvas implements Runnable, KeyListener {
private static final long serialVersionUID = 1L;
public JFrame frame;
public static final int WIDTH = 480;
public static final int HEIGHT = 320;
public static final int SCALE = 2;
public int fps = 0;
private Thread thread;
private boolean isRunning;
private BufferedImage image;
public static List<Entity> entities;
public static SpriteSheet spriteSheet;
public static Player player;
public static World world;
public Game() {
this.addKeyListener(this);
initFrame();
image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
// import Araylist da biblioteca java.util!
entities = new ArrayList<Entity>();
spriteSheet = new SpriteSheet("/Spryte32Pixels.png"); // importante!
player = new Player(0, 0, 32, 32, spriteSheet.getSpriteSheet(0, 0, 32, 32));
entities.add(player);
world = new World("/miniMapa.png");
}
public void initFrame() {
frame = new JFrame("Game RPG");
frame.add(this);
frame.setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
frame.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icone.jpg")));
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
//
public World(String path) {
// vamos criar um BufferedImage local para economizar
// se deixarmos fora do metodo ele ira rodar o tempo todo!
try {
BufferedImage map = ImageIO.read(getClass().getResource(path));
// vamso cariar um para calcular o tamanho de cada pixel!
int pixels[] = new int[map.getWidth() * map.getHeight()];
WIDTH = map.getWidth();
HEIGHT = map.getHeight();
// vamos passar para o arry o tamanho dos pixels!
tiles = new Tiles[map.getWidth() * map.getHeight()];
// vamos pegar os pixels e jogar no array acima!
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++) {
tiles[xx + (yy * WIDTH)] = new FloorTile(xx * 32, yy * 32, Tiles.TILE_FLOOR);
int pixelAtual = pixels[xx + (yy * map.getWidth())];
// Cor preta (Chão)!
if (pixelAtual == 0xff000000) {
tiles[xx + (yy * WIDTH)] = new FloorTile(xx * 32, yy * 32, Tiles.TILE_FLOOR);
}
// Cor branca (Parede)!
else if (pixelAtual == 0xffffffff) {
tiles[xx + (yy * WIDTH)] = new WallTaile(xx * 32, yy * 32, Tiles.TILE_WALL);
}
// Cor azul (Player)!
else if (pixelAtual == 0xff001eff) {
Game.player.setX(xx * 32);
Game.player.setY(yy * 32);
}
// Cor vermelho (Inimigo)!
else if (pixelAtual == 0xffc70009) {
tentei criar a mascara mas sou muito noob ainda kk
public Game() {
public Game() {
this.addKeyListener(this);
initFrame();
image = new BufferedImage( ***WIDTH*** , ***HEIGHT*** , BufferedImage. ***TYPE_INT_RGB*** );
// import Araylist da biblioteca java.util!
*entities* = new ArrayList<Entity>();
*playerMask* = new ArrayList<Entity>();
*playerMask* .add( *player* );
*spriteSheet* = new SpriteSheet("/Spryte32Pixels.png"); // importante!
*player* = new Player(0, 0, 32, 32, *spriteSheet* .getSpriteSheet(0, 0, 32, 32));
*entities* .add( *player* );
*world* = new World("/miniMapa.png");
////
Player playermask = new Player(0, 0, 32, 32, sprt .getSpriteSheet(0, 0, 32, 32));
Game. *entities* .add(playermask);