use of com.badlogic.gdx.maps.MapObject in project Catacomb-Snatch by Catacomb-Snatch.
the class TmxLevelGenerator method generate.
@Override
public Level generate(Campaign campaign) {
Level level = null;
final GeneratorStringOption empty = (GeneratorStringOption) getOption("emptyTile");
final boolean fill = empty.value != null && Tiles.isRegistered(empty.value);
for (MapLayer layer : map.getLayers()) {
if (layer instanceof TiledMapTileLayer) {
// Tile layer - the first one always decides the map size
final TiledMapTileLayer tileLayer = (TiledMapTileLayer) layer;
if (level == null) {
level = new Level(campaign, this, tileLayer.getWidth(), tileLayer.getHeight());
}
for (int x = 0; x < tileLayer.getWidth(); x++) {
for (int y = 0; y < tileLayer.getHeight(); y++) {
final Cell cell = tileLayer.getCell(x, y);
final String type = (cell == null || cell.getTile() == null) ? (fill ? empty.value : null) : (String) cell.getTile().getProperties().get("type");
if (type != null) {
Tiles.createAndAdd(type, level, x, y);
}
}
}
} else {
// Object layer for additional entities (monsters, spawn points, triggers)
final MapObjects objects = layer.getObjects();
for (int i = 0; i < objects.getCount(); i++) {
MapObject obj = objects.get(i);
String type = obj.getProperties().get("type", String.class);
if ("spawnPoint".equalsIgnoreCase(type)) {
float x = obj.getProperties().get("x", Float.class);
float y = obj.getProperties().get("y", Float.class);
spawns.add(new Vector2(x, y).add(0.5f, 0.5f));
}
}
}
}
// Safety check
if (level == null) {
return null;
}
return level;
}
use of com.badlogic.gdx.maps.MapObject in project Entitas-Java by Rubentxu.
the class MapEntityParser method load.
public void load(String scene) {
TiledMap map = loader.load(scene);
MapObjects characters = map.getLayers().get("Characters").getObjects();
MapObjects statics = map.getLayers().get("Statics").getObjects();
for (MapObject object : characters) {
String type = object.getProperties().get(aliases.Character, "", String.class);
if (type != null)
baseSceneManager.createEntity(type);
}
for (MapObject object : statics) {
String type = object.getProperties().get(aliases.Statics, "", String.class);
if (type != null)
baseSceneManager.createEntity(type);
}
}
use of com.badlogic.gdx.maps.MapObject in project ultimate-java by pantinor.
the class Utils method setTMXMap.
public static void setTMXMap(BaseMap map, Maps id, String tmxFile, TileSet ts) {
List<Person> people = new ArrayList<>();
Tile[] tiles = new Tile[map.getWidth() * map.getHeight()];
TmxMapLoader loader = new TmxMapLoader();
TiledMap tm = loader.load("assets/tilemaps/" + tmxFile);
TiledMapTileLayer ml = (TiledMapTileLayer) tm.getLayers().get(map.getId() + "-map");
if (ml != null) {
FileHandle f = new FileHandle("assets/tilemaps/latest-atlas.txt");
TextureAtlas.TextureAtlasData atlas = new TextureAtlas.TextureAtlasData(f, f.parent(), false);
int png_grid_width = 24;
Tile[] mapTileIds = new Tile[png_grid_width * Constants.tilePixelWidth + 1];
for (Region r : atlas.getRegions()) {
int x = r.left / r.width;
int y = r.top / r.height;
int i = x + (y * png_grid_width) + 1;
mapTileIds[i] = ts.getTileByName(r.name);
}
for (int y = 0; y < map.getHeight(); y++) {
for (int x = 0; x < map.getWidth(); x++) {
StaticTiledMapTile tr = (StaticTiledMapTile) ml.getCell(x, map.getWidth() - 1 - y).getTile();
Tile tile = mapTileIds[tr.getId()];
if (tile == null) {
tile = ts.getTileByIndex(127);
}
tiles[x + (y * map.getWidth())] = tile;
}
}
}
MapLayer objectsLayer = tm.getLayers().get(map.getId() + "-people");
if (objectsLayer != null) {
Iterator<MapObject> iter = objectsLayer.getObjects().iterator();
while (iter.hasNext()) {
MapObject obj = iter.next();
Person p = new Person();
Conversation conv = new Conversation();
conv.setName(obj.getName());
conv.setMap(id);
p.setConversation(conv);
people.add(p);
Iterator<String> keys = obj.getProperties().getKeys();
while (keys.hasNext()) {
String key = keys.next();
String value = obj.getProperties().get(key).toString();
if (key.equals("tileType")) {
Tile tile = ts.getTileByName(value);
p.setTileIndex(tile.getIndex());
p.setTile(tile);
} else if (key.equals("startX")) {
p.setStart_x(new Float(value).intValue());
} else if (key.equals("startY")) {
p.setStart_y(new Float(value).intValue());
} else if (key.equals("role")) {
PersonRole role = new PersonRole();
role.setInventoryType(InventoryType.valueOf(value));
p.setRole(role);
} else if (key.equals("movement")) {
p.setMovement(ObjectMovementBehavior.valueOf(value));
} else if (key.startsWith("description")) {
conv.setDescription(value);
conv.getTopics().add(conv.new Topic(standardQuery[2], value, null, null, null));
} else if (key.startsWith("topic")) {
String[] splits = value.split(",");
if (splits.length == 5) {
conv.getTopics().add(conv.new Topic(splits[0], splits[1], splits[2], splits[3], splits[4]));
} else {
conv.getTopics().add(conv.new Topic(splits[0], splits[1], null, null, null));
}
}
}
}
}
map.getCity().setPeople(people);
map.setTiles(tiles);
}
use of com.badlogic.gdx.maps.MapObject in project ultimate-java by pantinor.
the class DungeonScreen method enterRoom.
public void enterRoom(RoomLocater loc, Direction entryDir) {
if (loc == null) {
return;
}
Maps contextMap = Maps.get(dngMap.getId());
TiledMap tiledMap = new DungeonRoomTiledMapLoader(loc.room, entryDir, Ultima4.standardAtlas).load();
BaseMap baseMap = new BaseMap();
baseMap.setTiles(loc.room.tiles);
baseMap.setWidth(11);
baseMap.setHeight(11);
baseMap.setType(MapType.dungeon);
baseMap.setPortals(dngMap.getMap().getPortals(loc.x, loc.y, loc.z));
CombatScreen sc = new CombatScreen(this, context, contextMap, baseMap, tiledMap, null, Ultima4.creatures, Ultima4.standardAtlas);
if (loc.room.hasAltar) {
sc.log("The Altar Room of " + loc.room.altarRoomVirtue.toString());
}
MapLayer mLayer = tiledMap.getLayers().get("Monster Positions");
Iterator<MapObject> iter = mLayer.getObjects().iterator();
while (iter.hasNext()) {
MapObject obj = iter.next();
int tile = (Integer) obj.getProperties().get("tile");
int startX = (Integer) obj.getProperties().get("startX");
int startY = (Integer) obj.getProperties().get("startY");
if (tile == 0) {
continue;
}
Tile t = Ultima4.baseTileSet.getTileByIndex(tile);
Creature c = Ultima4.creatures.getInstance(CreatureType.get(t.getName()), Ultima4.standardAtlas);
c.currentX = startX;
c.currentY = startY;
c.currentPos = sc.getMapPixelCoords(startX, startY);
baseMap.addCreature(c);
}
mainGame.setScreen(sc);
}
use of com.badlogic.gdx.maps.MapObject in project ultimate-java by pantinor.
the class DungeonRoomTiledMapLoader method loadCombatPositions.
private void loadCombatPositions(TiledMap map) throws Exception {
// 0x0 16 start_x for monsters 0-15
// 0x10 16 start_y for monsters 0-15
// 0x20 8 start_x for party members 0-7
// 0x28 8 start_y for party members 0-7
MapLayer mlayer = new MapLayer();
mlayer.setName("Monster Positions");
for (int i = 0; i < 16; i++) {
MapObject object = new MapObject();
object.getProperties().put("index", 0);
object.getProperties().put("tile", (int) room.monsters[i] & 0xff);
object.getProperties().put("startX", (int) room.monStartX[i] & 0xff);
object.getProperties().put("startY", (int) room.monStartY[i] & 0xff);
mlayer.getObjects().add(object);
}
map.getLayers().add(mlayer);
MapLayer player = new MapLayer();
player.setName("Player Positions");
byte[] px = null;
byte[] py = null;
switch(entryDir) {
case EAST:
px = room.plStartXEast;
py = room.plStartYEast;
break;
case NORTH:
px = room.plStartXNorth;
py = room.plStartYNorth;
break;
case SOUTH:
px = room.plStartXSouth;
py = room.plStartYSouth;
break;
case WEST:
px = room.plStartXWest;
py = room.plStartYWest;
break;
}
Position[] playerPos = new Position[8];
for (int i = 0; i < 8; i++) {
playerPos[i] = new Position(i, (int) px[i], 0);
playerPos[i].startY = (int) py[i];
}
for (int i = 0; i < 8; i++) {
MapObject object = new MapObject();
object.getProperties().put("index", playerPos[i].index & 0xff);
object.getProperties().put("startX", playerPos[i].startX & 0xff);
object.getProperties().put("startY", playerPos[i].startY & 0xff);
player.getObjects().add(object);
}
map.getLayers().add(player);
}
Aggregations