Finishing map-graphics

This commit is contained in:
Urban Modig
2025-08-15 11:26:50 +02:00
parent 80cd0c242f
commit fe2eb8cb48
9 changed files with 149 additions and 55 deletions

View File

@ -1,19 +1,38 @@
package se.urmo.game.map;
import se.urmo.game.util.MiscUtil;
import java.awt.*;
import java.awt.image.BufferedImage;
public class MapTile {
private final int value;
private final BufferedImage image;
private final boolean solid;
private final boolean[][] collisionMask;
public MapTile(int value) {
public MapTile(BufferedImage image, int value) {
this.value = value;
this.image = value != 0 ? MiscUtil.createOutlinedBox(16, 16, Color.blue, 2) : null;
this.image = image;
// this.image = value != 0 ? MiscUtil.createOutlinedBox(16, 16, Color.blue, 2) : null;
this.solid = value != 0;
this.collisionMask = createCollisionMask(image);
}
public boolean[][] getCollisionMask() {
return collisionMask;
}
private boolean[][] createCollisionMask(BufferedImage img) {
if(img == null) return null;
int w = img.getWidth();
int h = img.getHeight();
boolean[][] mask = new boolean[h][w];
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int alpha = (img.getRGB(x, y) >> 24) & 0xff;
mask[y][x] = alpha > 0; // solid if any pixel is visible
}
}
return mask;
}
public BufferedImage getImage() {