use of ultima.Constants.DungeonTile in project ultimate-java by pantinor.
the class TestJaxb method testDungSpawn.
// @Test
public void testDungSpawn() throws Exception {
int dx = 0;
int dy = 0;
int tmp = 0;
int currentX = 1;
int currentY = 1;
int DUNGEON_MAP = 8;
Random rand = new Random();
DungeonTile[][] dungeonTiles = new DungeonTile[8][8];
for (int i = 0; i < DUNGEON_MAP; i++) {
for (int j = 0; j < DUNGEON_MAP; j++) {
dungeonTiles[i][j] = DungeonTile.NOTHING;
}
}
for (int i = 0; i < 20; i++) {
dx = 8;
dy = rand.nextInt(8);
if (rand.nextInt(2) > 0) {
dx = -dx;
}
if (rand.nextInt(2) > 0) {
dy = -dy;
}
if (rand.nextInt(2) > 0) {
tmp = dx;
dx = dy;
dy = tmp;
}
dx = currentX + dx;
dy = currentY + dy;
if (dx < 0) {
dx = DUNGEON_MAP + dx;
} else if (dx > DUNGEON_MAP - 1) {
dx = dx - DUNGEON_MAP;
}
if (dy < 0) {
dy = DUNGEON_MAP + dy;
} else if (dy > DUNGEON_MAP - 1) {
dy = dy - DUNGEON_MAP;
}
DungeonTile tile = dungeonTiles[dx][dy];
if (tile.getCreatureWalkable()) {
System.out.println("ok");
} else {
System.out.println("bad");
}
}
}
use of ultima.Constants.DungeonTile in project ultimate-java by pantinor.
the class Utils method peerGem.
public static Texture peerGem(TiledMapTileLayer layer, String[] ids, TextureAtlas atlas, int cx, int cy) throws Exception {
FileTextureData d = (FileTextureData) (atlas.getRegions().first().getTexture().getTextureData());
BufferedImage sheet = ImageIO.read(d.getFileHandle().file());
BufferedImage canvas = new BufferedImage(32 * layer.getWidth(), 32 * layer.getHeight(), BufferedImage.TYPE_INT_ARGB);
for (int y = 0; y < layer.getHeight(); y++) {
for (int x = 0; x < layer.getWidth(); x++) {
String val = ids[layer.getCell(x, layer.getHeight() - y - 1).getTile().getId()];
DungeonTile tile = DungeonTile.getTileByName(val);
if (tile == null) {
val = "brick_floor";
}
if (x == cx && y == cy) {
val = "avatar";
}
AtlasRegion ar = (AtlasRegion) atlas.findRegion(val);
BufferedImage sub = sheet.getSubimage(ar.getRegionX(), ar.getRegionY(), 32, 32);
canvas.getGraphics().drawImage(sub, x * 32, y * 32, 32, 32, null);
}
}
java.awt.Image tmp = canvas.getScaledInstance(20 * 32, 20 * 32, Image.SCALE_AREA_AVERAGING);
BufferedImage scaledCanvas = new BufferedImage(20 * 32, 20 * 32, BufferedImage.TYPE_INT_ARGB);
scaledCanvas.getGraphics().drawImage(tmp, 0, 0, null);
Pixmap p = Utils.createPixmap(scaledCanvas.getWidth(), scaledCanvas.getHeight(), scaledCanvas, 0, 0);
Texture t = new Texture(p);
p.dispose();
return t;
}
use of ultima.Constants.DungeonTile in project ultimate-java by pantinor.
the class TestJaxb method findStartsForDungeons.
// @Test
public void findStartsForDungeons() throws Exception {
TileSet baseTileSet = (TileSet) Utils.loadXml("tileset-base.xml", TileSet.class);
baseTileSet.setMaps();
MapSet maps = (MapSet) Utils.loadXml("maps.xml", MapSet.class);
maps.init(baseTileSet);
for (BaseMap map : maps.getMaps()) {
if (map.getType() != MapType.dungeon) {
continue;
}
InputStream is = new FileInputStream("assets/data/" + map.getFname());
byte[] bytes = IOUtils.toByteArray(is);
int pos = 0;
int i = 0;
for (int y = 0; y < DUNGEON_MAP; y++) {
for (int x = 0; x < DUNGEON_MAP; x++) {
int index = bytes[pos] & 0xff;
pos++;
DungeonTile tile = DungeonTile.getTileByValue(index);
if (tile == DungeonTile.LADDER_UP || tile == DungeonTile.LADDER_UP_DOWN) {
System.out.println(map.getFname() + " x=" + x + " y=" + y);
}
}
}
}
}
Aggregations