use of objects.Tile in project ultimate-java by pantinor.
the class UltimaTiledMapLoader method load.
// for intro map
public TiledMap load(byte[] bytes, int width, int height, TileSet ts, int tileDim) {
this.mapWidth = width;
this.mapHeight = height;
Tile[] tiles = new Tile[width * height];
int pos = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
// convert a byte to an unsigned int value
int index = bytes[pos] & 0xff;
pos++;
Tile tile = ts.getTileByIndex(index);
if (tile == null) {
System.out.println("Tile index cannot be found: " + index + " using index 129 for black space.");
tile = ts.getTileByIndex(129);
}
tiles[x + y * width] = tile;
}
}
TiledMap map = new TiledMap();
MapProperties mapProperties = map.getProperties();
mapProperties.put("name", "none");
mapProperties.put("id", "none");
mapProperties.put("orientation", "orthogonal");
mapProperties.put("width", mapWidth);
mapProperties.put("height", mapHeight);
mapProperties.put("tilewidth", tileDim);
mapProperties.put("tileheight", tileDim);
mapProperties.put("backgroundcolor", "#000000");
TiledMapTileLayer layer = new TiledMapTileLayer(mapWidth, mapHeight, tileWidth, tileHeight);
layer.setName("Map Layer");
layer.setVisible(true);
int dx = 0, dy = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
Tile ct = tiles[x + y * width];
Cell cell = new Cell();
Array<TextureAtlas.AtlasRegion> tileRegions = atlas.findRegions(ct.getName());
Array<StaticTiledMapTile> ar = new Array<>();
for (TextureAtlas.AtlasRegion r : tileRegions) {
ar.add(new StaticTiledMapTile(r));
}
if (ar.size == 0) {
System.out.println(ct.getName());
}
TiledMapTile tmt = null;
if (tileRegions.size > 1) {
tmt = new AnimatedTiledMapTile(.7f, ar);
} else {
tmt = ar.first();
}
tmt.setId(dy * mapWidth + dx);
cell.setTile(tmt);
layer.setCell(dx, mapHeight - 1 - dy, cell);
dx++;
}
dx = 0;
dy++;
}
map.getLayers().add(layer);
return map;
}
use of objects.Tile in project ultimate-java by pantinor.
the class Utils method getDirectionalActionPath.
public static List<AttackVector> getDirectionalActionPath(BaseMap combatMap, int dirmask, int x, int y, int minDistance, int maxDistance, boolean weaponCanAttackThroughObjects, boolean checkForCreatures, boolean isCannonBall) {
List<AttackVector> path = new ArrayList<>();
/*
* try every tile in the given direction, up to the given range.
* Stop when the the range is exceeded, or the action is blocked.
*/
int nx = x;
int ny = y;
for (int distance = minDistance; distance <= maxDistance; distance++) {
/* make sure our action isn't taking us off the map */
if (nx > combatMap.getWidth() - 1 || nx < 0 || ny > combatMap.getHeight() - 1 || ny < 0) {
break;
}
boolean blocked = combatMap.isTileBlockedForRangedAttack(nx, ny, checkForCreatures);
Tile tile = combatMap.getTile(nx, ny);
boolean canAttackOverSolid = (tile != null && tile.getRule() != null && tile.getRule().has(TileAttrib.halberdattackover) && weaponCanAttackThroughObjects);
if (!blocked || canAttackOverSolid || isCannonBall) {
path.add(new AttackVector(nx, ny));
} else {
path.add(new AttackVector(nx, ny));
break;
}
if (Direction.isDirInMask(Direction.NORTH, dirmask)) {
ny--;
}
if (Direction.isDirInMask(Direction.SOUTH, dirmask)) {
ny++;
}
if (Direction.isDirInMask(Direction.EAST, dirmask)) {
nx++;
}
if (Direction.isDirInMask(Direction.WEST, dirmask)) {
nx--;
}
}
return path;
}
use of objects.Tile in project ultimate-java by pantinor.
the class SpriteAtlasTool method create.
@Override
public void create() {
Pixmap pixmap = new Pixmap(dim, dim, Format.RGBA8888);
pixmap.setColor(new Color(1, 1, 0, .8f));
int w = 1;
pixmap.fillRectangle(0, 0, w, dim);
pixmap.fillRectangle(dim - w, 0, w, dim);
pixmap.fillRectangle(w, 0, dim - 2 * w, w);
pixmap.fillRectangle(w, dim - w, dim - 2 * w, w);
box = new Texture(pixmap);
Texture tx = new Texture(Gdx.files.absolute("D:\\work\\gdx-andius\\src\\main\\resources\\assets\\data\\uf_heroes.png"));
canvasGridWidth = tx.getWidth() / dim;
canvasGridHeight = tx.getHeight() / dim;
sprBg = new Sprite(tx, 0, 0, tx.getWidth(), tx.getHeight());
gridItems = new ArrayList<>();
font = new BitmapFont();
font.setColor(Color.WHITE);
batch = new SpriteBatch();
skin = new Skin(Gdx.files.internal("assets/skin/uiskin.json"));
stage = new Stage();
readAtlas();
final List<MyListItem> list = new List<>(skin);
try {
MyListItem[] tileNames = new MyListItem[Tile.values().length];
int x = 0;
for (Tile t : Tile.values()) {
tileNames[x] = new MyListItem(t.toString(), 0, 0);
x++;
}
list.setItems(tileNames);
} catch (Exception ex) {
}
list.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
selectedTileName = list.getSelected();
}
});
ScrollPane scrollPane = new ScrollPane(list, skin);
scrollPane.setScrollingDisabled(true, false);
TextButton makeButton = new TextButton("Make Atlas", skin, "default");
makeButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
makeAtlas();
}
});
Table table = new Table(skin);
table.defaults().pad(2);
table.add(makeButton).expandX().left().width(175);
table.row();
table.add(scrollPane).expandX().left().width(175).maxHeight(screenHeight);
table.setPosition(screenWidth - 175, 0);
table.setFillParent(true);
stage.addActor(table);
Gdx.input.setInputProcessor(new InputMultiplexer(stage, this));
}
use of objects.Tile in project ultimate-java by pantinor.
the class UltimaTiledMapLoader method load.
public TiledMap load() {
TiledMap map = new TiledMap();
MapProperties mapProperties = map.getProperties();
mapProperties.put("name", gameMap.toString());
mapProperties.put("id", gameMap.getId());
mapProperties.put("orientation", "orthogonal");
mapProperties.put("width", mapWidth);
mapProperties.put("height", mapHeight);
mapProperties.put("tilewidth", tileWidth);
mapProperties.put("tileheight", tileHeight);
mapProperties.put("backgroundcolor", "#000000");
TiledMapTileLayer layer = new TiledMapTileLayer(mapWidth, mapHeight, tileWidth, tileHeight);
layer.setName("Map Layer");
layer.setVisible(true);
for (int y = 0; y < mapHeight; y++) {
for (int x = 0; x < mapWidth; x++) {
Tile ct = gameMap.getMap().getTile(x, y);
Cell cell = new Cell();
Array<TextureAtlas.AtlasRegion> tileRegions = atlas.findRegions(ct.getName());
Array<StaticTiledMapTile> ar = new Array<>();
for (TextureAtlas.AtlasRegion r : tileRegions) {
ar.add(new StaticTiledMapTile(r));
}
if (ar.size == 0) {
System.out.println(ct.getName());
}
TiledMapTile tmt = null;
if (tileRegions.size > 1) {
tmt = new AnimatedTiledMapTile(.7f, ar);
} else {
tmt = ar.first();
}
tmt.setId(y * mapWidth + x);
cell.setTile(tmt);
layer.setCell(x, mapHeight - 1 - y, cell);
}
}
map.getLayers().add(layer);
if (gameMap.getMap().getType() == MapType.combat) {
try {
loadCombatPositions(map);
} catch (Exception e) {
e.printStackTrace();
}
}
return map;
}
use of objects.Tile in project ultimate-java by pantinor.
the class Utils method peerGem.
// used for telescope viewing
public static Texture peerGem(Maps map, TextureAtlas atlas) throws Exception {
Texture t = null;
if (map.getMap().getType() == MapType.city) {
FileTextureData d = (FileTextureData) (atlas.getRegions().first().getTexture().getTextureData());
BufferedImage sheet = ImageIO.read(d.getFileHandle().file());
BufferedImage canvas = new BufferedImage(32 * 32, 32 * 32, BufferedImage.TYPE_INT_ARGB);
for (int y = 0; y < 32; y++) {
for (int x = 0; x < 32; x++) {
Tile ct = map.getMap().getTile(x, y);
AtlasRegion ar = (AtlasRegion) atlas.findRegion(ct.getName());
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 = createPixmap(Ultima4.SCREEN_WIDTH, Ultima4.SCREEN_HEIGHT, scaledCanvas, (Ultima4.SCREEN_WIDTH - scaledCanvas.getWidth()) / 2, (Ultima4.SCREEN_HEIGHT - scaledCanvas.getHeight()) / 2);
t = new Texture(p);
p.dispose();
} else if (map.getMap().getType() == MapType.dungeon) {
// NO OP not needed since I added the minimap already on the HUD
}
return t;
}
Aggregations