Search in sources :

Example 26 with Tile

use of objects.Tile in project ultimate-java by pantinor.

the class WorldMapTmxConvert method create.

@Override
public void create() {
    try {
        File file2 = new File("assets/xml/tileset-base.xml");
        JAXBContext jaxbContext = JAXBContext.newInstance(TileSet.class);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        TileSet ts = (TileSet) jaxbUnmarshaller.unmarshal(file2);
        ts.setMaps();
        File file3 = new File("assets/xml/maps.xml");
        jaxbContext = JAXBContext.newInstance(MapSet.class);
        jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        MapSet ms = (MapSet) jaxbUnmarshaller.unmarshal(file3);
        ms.init(ts);
        BaseMap map = Maps.WORLD.getMap();
        Utils.setMapTiles(map, ts);
        Tile[] tiles = map.getTiles();
        // load the atlas and determine the tile indexes per tilemap position
        FileHandle f = new FileHandle("assets/tilemaps/latest-atlas.txt");
        TextureAtlasData atlas = new 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);
        }
        // map layer
        StringBuilder data = new StringBuilder();
        int count = 1;
        int total = 1;
        for (int i = 0; i < tiles.length; i++) {
            Tile t = tiles[i];
            data.append(findTileId(mapTileIds, t.getName())).append(",");
            count++;
            total++;
            if (count > 256) {
                data.append("\n");
                count = 1;
            }
        }
        String dl = data.toString();
        dl = dl.substring(0, dl.length() - 2);
        // portal layer
        List<Portal> portals = map.getPortals();
        StringBuilder portalBuffer = new StringBuilder();
        // set map tile id per dest map type
        for (Portal p : portals) {
            BaseMap destMap = Maps.get(p.getDestmapid()).getMap();
            p.setName(Constants.Maps.get(p.getDestmapid()).toString());
            String ttype = destMap.getCity() == null ? destMap.getType().toString() : destMap.getCity().getType();
            p.setMapTileId(findTileId(mapTileIds, ttype));
        }
        if (portals != null) {
            for (int y = 0; y < map.getHeight(); y++) {
                for (int x = 0; x < map.getWidth(); x++) {
                    Portal p = findPortalAtCoords(portals, x, y);
                    if (p == null) {
                        portalBuffer.append("0,");
                    } else {
                        portalBuffer.append(p.getMapTileId() + ",");
                    }
                }
                portalBuffer.append("\n");
            }
        }
        String pl = portalBuffer.toString();
        pl = pl.substring(0, pl.length() - 2);
        // moongate layer
        List<Moongate> moongates = map.getMoongates();
        StringBuilder moongateBuffer = new StringBuilder();
        // set map tile id per dest map type
        for (Moongate m : moongates) {
            m.setMapTileId(findTileId(mapTileIds, "moongate"));
        }
        if (moongates != null) {
            for (int y = 0; y < map.getHeight(); y++) {
                for (int x = 0; x < map.getWidth(); x++) {
                    Moongate p = findMoongateAtCoords(moongates, x, y);
                    if (p == null) {
                        moongateBuffer.append("0,");
                    } else {
                        moongateBuffer.append(p.getMapTileId()).append(",");
                    }
                }
                moongateBuffer.append("\n");
            }
        }
        String ml = moongateBuffer.toString();
        ml = ml.substring(0, ml.length() - 2);
        Formatter c = new Formatter(map.getFname(), "latest.png", map.getWidth(), map.getHeight(), Constants.tilePixelWidth, Constants.tilePixelWidth, dl, pl, ml, portals, moongates, map.getLabels());
        FileUtils.writeStringToFile(new File("tmx/map_" + map.getId() + "_World.tmx"), c.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("DONE");
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Tile(objects.Tile) JAXBContext(javax.xml.bind.JAXBContext) TileSet(objects.TileSet) BaseMap(objects.BaseMap) TextureAtlasData(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData) MapSet(objects.MapSet) Region(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region) Portal(objects.Portal) Moongate(objects.Moongate) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Example 27 with Tile

use of objects.Tile 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 28 with Tile

use of objects.Tile in project ultimate-java by pantinor.

the class GameScreen method show.

@Override
public void show() {
    Gdx.input.setInputProcessor(new InputMultiplexer(this, stage));
    gameTimer.active = true;
    // load save game if initializing
    if (context == null) {
        context = new Context();
        SaveGame sg = new SaveGame();
        try {
            sg.read(PARTY_SAV_BASE_FILENAME);
        } catch (Exception e) {
            e.printStackTrace();
        }
        LordBritishConversation.saveGame = sg;
        Party party = new Party(sg);
        context.setParty(party);
        context.loadJournalEntries();
        // party.getMember(0).getPlayer().klass = ClassType.MAGE;
        // party.getMember(0).getPlayer().xp = 899;
        // party.getMember(0).getPlayer().hp = 999;
        // party.getMember(0).getPlayer().hpMax = 999;
        // party.getMember(0).getPlayer().intel = 99;
        // party.getMember(0).getPlayer().mp = 999;
        // sg.reagents = new int[]{90, 93, 94, 90, 90, 90, 90, 90};
        // for (Spell sp : Spell.values()) {
        // party.getSaveGame().mixtures[sp.ordinal()] = 99;
        // }
        // for (Virtue v : Virtue.values()) {
        // sg.karma[v.ordinal()] = 0;
        // }
        // 
        // party.join(NpcDefaults.Geoffrey.name());
        // party.join(NpcDefaults.Shamino.name());
        // party.join(NpcDefaults.Katrina.name());
        // party.join(NpcDefaults.Mariah.name());
        // party.join(NpcDefaults.Dupre.name());
        // party.join(NpcDefaults.Iolo.name());
        // party.join(NpcDefaults.Julia.name());
        // party.join(NpcDefaults.Jaana.name());
        // 
        // sg.food = 30000;
        // sg.gold = 999;
        // sg.keys = 20;
        // sg.gems = 15;
        // sg.moves = 2800;
        // sg.stones = 0xff;
        // sg.runes = 0xff;
        // sg.items = 0xff;
        // sg.sextants = 1;
        // party.getMember(0).getPlayer().status = StatusType.GOOD;
        // party.getMember(0).getPlayer().weapon = WeaponType.MAGICAXE;
        // party.getMember(0).getPlayer().armor = ArmorType.MYSTICROBE;
        // for (int i = 1; i < 16; i++) {
        // party.getSaveGame().weapons[i] = 2;
        // }
        // for (int i = 1; i < 8; i++) {
        // party.getSaveGame().armor[i] = 2;
        // }
        // mainAvatar = shipAnim;
        // sg.transport = 0x10;
        // sg.items |= Constants.Item.IRON_ORE.getLoc();
        // sg.items |= Constants.Item.RUNE_MOLD.getLoc();
        // sg.items |= Constants.Item.BOOK.getLoc();
        // load the surface world first
        loadNextMap(Maps.WORLD, sg.x, sg.y);
        // load the dungeon if save game starts in dungeon
        if (Maps.get(sg.location) != Maps.WORLD) {
            loadNextMap(Maps.get(sg.location), sg.x, sg.y, sg.x, sg.y, sg.dnglevel, Direction.getByValue(sg.orientation + 1), true);
        // loadNextMap(Maps.ABYSS, 0, 0, 5, 5, 0, Direction.SOUTH, true);
        // loadNextMap(Maps.DESTARD, 0, 0, 3, 5, 3, Direction.SOUTH, true);
        // loadNextMap(Maps.DELVE_SORROWS, 0, 0, 3, 19, 1, Direction.EAST, true);
        }
        for (Virtue v : Virtue.values()) {
            v.adjustProgress(sg.karma[v.ordinal()]);
        }
        party.setTransport(Ultima4.baseTileSet.getTileByIndex(sg.transport));
        switch(sg.transport) {
            case 31:
                mainAvatar = avatarAnim;
                break;
            case 16:
            case 17:
            case 18:
            case 19:
                mainAvatar = shipAnim;
                break;
            case 20:
            case 21:
                mainAvatar = horseAnim;
                break;
            case 24:
                mainAvatar = balloonAnim;
                break;
        }
        if (sg.balloonfound == 1 && context.getTransportContext() != TransportContext.BALLOON) {
            addBalloonActor(sg.balloonx, sg.balloony);
        }
        // load objects to surface stage
        for (int i = 0; i < 24; i++) {
            if (sg.objects_save_tileids[i] != 0 && sg.objects_save_x[i] != 0 && sg.objects_save_y[i] != 0) {
                Tile t = Ultima4.baseTileSet.getTileByIndex(sg.objects_save_tileids[i] & 0xff);
                Drawable d = new Drawable(Maps.WORLD.getMap(), sg.objects_save_x[i] & 0xff, sg.objects_save_y[i] & 0xff, t, Ultima4.standardAtlas);
                Vector3 v = getMapPixelCoords(sg.objects_save_x[i] & 0xff, sg.objects_save_y[i] & 0xff);
                d.setX(v.x);
                d.setY(v.y);
                mapObjectsStage.addActor(d);
            }
        }
        // load monsters to surface map
        for (int i = 0; i < 8; i++) {
            if (sg.monster_save_tileids[i] != 0 && sg.monster_save_x[i] != 0 && sg.monster_save_y[i] != 0) {
                Tile t = Ultima4.baseTileSet.getTileByIndex(sg.monster_save_tileids[i] & 0xff);
                Creature cr = Ultima4.creatures.getInstance(CreatureType.get(t.getName()), Ultima4.standardAtlas);
                cr.currentX = sg.monster_save_x[i] & 0xff;
                cr.currentY = sg.monster_save_y[i] & 0xff;
                cr.currentPos = getMapPixelCoords(cr.currentX, cr.currentY);
                Maps.WORLD.getMap().addCreature(cr);
            }
        }
    }
    context.getParty().addObserver(this);
}
Also used : InputMultiplexer(com.badlogic.gdx.InputMultiplexer) Party(objects.Party) Creature(objects.Creature) SaveGame(objects.SaveGame) Drawable(objects.Drawable) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) Tile(objects.Tile) Vector3(com.badlogic.gdx.math.Vector3) PartyDeathException(util.PartyDeathException)

Example 29 with Tile

use of objects.Tile in project ultimate-java by pantinor.

the class GameScreen method board.

public void board(int x, int y) {
    if (context.getTransportContext() != TransportContext.FOOT) {
        log("Board: Can't!");
        return;
    }
    Tile tile = null;
    // check for ship
    Drawable ship = null;
    for (Actor a : mapObjectsStage.getActors()) {
        if (a instanceof Drawable) {
            Drawable d = (Drawable) a;
            if (d.getTile().getName().equals("ship") && d.getCx() == x && d.getCy() == y) {
                ship = d;
                tile = d.getTile();
            }
        }
    }
    // check for horse
    Creature horse = context.getCurrentMap().getCreatureAt(x, y);
    if (horse != null && (horse.getTile() == CreatureType.horse)) {
        tile = Ultima4.baseTileSet.getTileByName("horse");
    }
    // check for balloon
    Drawable balloon = null;
    for (Actor a : mapObjectsStage.getActors()) {
        if (a instanceof Drawable) {
            Drawable d = (Drawable) a;
            if (d.getTile().getName().equals("balloon") && d.getCx() == x && d.getCy() == y) {
                balloon = d;
                tile = d.getTile();
            }
        }
    }
    if (tile == null) {
        log("Board What?");
        return;
    }
    if (tile.getRule().has(TileAttrib.ship)) {
        log("Board Frigate!");
        if (context.getLastShip() != ship) {
            context.getParty().adjustShipHull(50);
        }
        context.setCurrentShip(ship);
        ship.remove();
        mainAvatar = shipAnim;
    } else if (tile.getRule().has(TileAttrib.horse)) {
        log("Mount Horse!");
        context.getCurrentMap().removeCreature(horse);
        mainAvatar = horseAnim;
    } else if (tile.getRule().has(TileAttrib.balloon)) {
        log("Board Balloon!");
        balloon.remove();
        mainAvatar = balloonAnim;
    } else {
        log("Board What?");
        return;
    }
    context.getParty().setTransport(tile);
}
Also used : Creature(objects.Creature) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Drawable(objects.Drawable) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) Tile(objects.Tile)

Example 30 with Tile

use of objects.Tile in project ultimate-java by pantinor.

the class GameScreen method spawnCreature.

private boolean spawnCreature(Creature creature, int currentX, int currentY) {
    int dx = 0;
    int dy = 0;
    int tmp = 0;
    boolean ok = false;
    int tries = 0;
    int MAX_TRIES = 10;
    while (!ok && (tries < MAX_TRIES)) {
        dx = 15;
        dy = rand.nextInt(15);
        if (rand.nextInt(100) > 50) {
            dx = -dx;
        }
        if (rand.nextInt(100) > 50) {
            dy = -dy;
        }
        if (rand.nextInt(100) > 50) {
            tmp = dx;
            dx = dy;
            dy = tmp;
        }
        dx = currentX + dx;
        dy = currentY + dy;
        /* make sure we can spawn the creature there */
        if (creature != null) {
            Tile tile = context.getCurrentMap().getTile(dx, dy);
            TileRule rule = tile.getRule();
            if ((creature.getSails() && rule.has(TileAttrib.sailable)) || (creature.getSwims() && rule.has(TileAttrib.swimmable)) || (creature.getFlies() && !rule.has(TileAttrib.unflyable))) {
                ok = true;
            } else {
                tries++;
            }
        } else {
            ok = true;
        }
    }
    if (!ok) {
        return false;
    }
    if (creature != null) {
    } else {
        Tile tile = context.getCurrentMap().getTile(dx, dy);
        creature = getRandomCreatureForTile(tile);
    }
    if (creature != null) {
        creature.currentX = dx;
        creature.currentY = dy;
        context.getCurrentMap().addCreature(creature);
    } else {
        return false;
    }
    return true;
}
Also used : StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) Tile(objects.Tile)

Aggregations

Tile (objects.Tile)39 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)22 TiledMapTile (com.badlogic.gdx.maps.tiled.TiledMapTile)16 Creature (objects.Creature)12 Drawable (objects.Drawable)10 File (java.io.File)8 JAXBContext (javax.xml.bind.JAXBContext)8 DungeonTile (ultima.Constants.DungeonTile)8 Unmarshaller (javax.xml.bind.Unmarshaller)7 BaseMap (objects.BaseMap)7 TileSet (objects.TileSet)7 FileHandle (com.badlogic.gdx.files.FileHandle)6 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)6 TextureAtlasData (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData)5 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)5 Vector3 (com.badlogic.gdx.math.Vector3)5 FileInputStream (java.io.FileInputStream)5 ArrayList (java.util.ArrayList)5 MapSet (objects.MapSet)5 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)4