Search in sources :

Example 6 with MapObject

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;
}
Also used : TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) Vector2(com.badlogic.gdx.math.Vector2) MapLayer(com.badlogic.gdx.maps.MapLayer) Level(net.catacombsnatch.game.world.level.Level) GeneratorStringOption(net.catacombsnatch.game.world.level.generator.options.GeneratorStringOption) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) MapObjects(com.badlogic.gdx.maps.MapObjects) MapObject(com.badlogic.gdx.maps.MapObject)

Example 7 with MapObject

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);
    }
}
Also used : TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) MapObjects(com.badlogic.gdx.maps.MapObjects) MapObject(com.badlogic.gdx.maps.MapObject)

Example 8 with MapObject

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);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) MapLayer(com.badlogic.gdx.maps.MapLayer) ArrayList(java.util.ArrayList) Conversation(objects.Conversation) HawkwindConversation(objects.HawkwindConversation) LordBritishConversation(objects.LordBritishConversation) PersonRole(objects.PersonRole) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) MapObject(com.badlogic.gdx.maps.MapObject) TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) DungeonTile(ultima.Constants.DungeonTile) Tile(objects.Tile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Region(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) Person(objects.Person)

Example 9 with MapObject

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);
}
Also used : DungeonRoomTiledMapLoader(util.DungeonRoomTiledMapLoader) Creature(objects.Creature) MapLayer(com.badlogic.gdx.maps.MapLayer) Tile(objects.Tile) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) MapObject(com.badlogic.gdx.maps.MapObject) BaseMap(objects.BaseMap)

Example 10 with MapObject

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);
}
Also used : MapLayer(com.badlogic.gdx.maps.MapLayer) MapObject(com.badlogic.gdx.maps.MapObject)

Aggregations

MapObject (com.badlogic.gdx.maps.MapObject)12 MapLayer (com.badlogic.gdx.maps.MapLayer)7 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)3 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)3 MapObjects (com.badlogic.gdx.maps.MapObjects)2 EllipseMapObject (com.badlogic.gdx.maps.objects.EllipseMapObject)2 PolygonMapObject (com.badlogic.gdx.maps.objects.PolygonMapObject)2 RectangleMapObject (com.badlogic.gdx.maps.objects.RectangleMapObject)2 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)2 TiledMapTileMapObject (com.badlogic.gdx.maps.tiled.objects.TiledMapTileMapObject)2 Polygon (com.badlogic.gdx.math.Polygon)2 Creature (objects.Creature)2 Tile (objects.Tile)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)1 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)1 MapProperties (com.badlogic.gdx.maps.MapProperties)1 PolylineMapObject (com.badlogic.gdx.maps.objects.PolylineMapObject)1 TextureMapObject (com.badlogic.gdx.maps.objects.TextureMapObject)1