Search in sources :

Example 16 with Tile

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;
}
Also used : AnimatedTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile) AnimatedTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) Tile(objects.Tile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) MapProperties(com.badlogic.gdx.maps.MapProperties) Array(com.badlogic.gdx.utils.Array) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) AnimatedTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)

Example 17 with Tile

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;
}
Also used : ArrayList(java.util.ArrayList) DungeonTile(ultima.Constants.DungeonTile) Tile(objects.Tile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)

Example 18 with Tile

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));
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Color(com.badlogic.gdx.graphics.Color) Tile(objects.Tile) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) IOException(java.io.IOException) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ArrayList(java.util.ArrayList) List(com.badlogic.gdx.scenes.scene2d.ui.List) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 19 with Tile

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;
}
Also used : AnimatedTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile) MapProperties(com.badlogic.gdx.maps.MapProperties) AnimatedTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) Tile(objects.Tile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) Array(com.badlogic.gdx.utils.Array) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) AnimatedTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)

Example 20 with Tile

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;
}
Also used : Image(java.awt.Image) DungeonTile(ultima.Constants.DungeonTile) Tile(objects.Tile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) FileTextureData(com.badlogic.gdx.graphics.glutils.FileTextureData) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) Texture(com.badlogic.gdx.graphics.Texture) BufferedImage(java.awt.image.BufferedImage) Pixmap(com.badlogic.gdx.graphics.Pixmap)

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