Search in sources :

Example 81 with Texture

use of com.badlogic.gdx.graphics.Texture in project ultimate-java by pantinor.

the class DungeonScreen method init.

public void init() {
    assets = new AssetManager();
    assets.load("assets/graphics/dirt.png", Texture.class);
    assets.load("assets/graphics/map.png", Texture.class);
    assets.load("assets/graphics/Stone_Masonry.jpg", Texture.class);
    assets.load("assets/graphics/door.png", Texture.class);
    assets.load("assets/graphics/mortar.png", Texture.class);
    assets.load("assets/graphics/rock.png", Texture.class);
    assets.update(2000);
    // convert the collada dae format to the g3db format (do not use the obj format)
    // C:\Users\Paul\Desktop\blender>fbx-conv-win32.exe -o G3DB ./Chess/pawn.dae ./pawn.g3db
    ModelLoader<?> gloader = new G3dModelLoader(new UBJsonReader());
    fountainModel = gloader.loadModel(Gdx.files.internal("assets/graphics/fountain2.g3db"));
    ladderModel = gloader.loadModel(Gdx.files.internal("assets/graphics/ladder.g3db"));
    chestModel = gloader.loadModel(Gdx.files.internal("assets/graphics/chest.g3db"));
    orbModel = gloader.loadModel(Gdx.files.internal("assets/graphics/orb.g3db"));
    altarModel = gloader.loadModel(Gdx.files.internal("assets/graphics/altar.g3db"));
    // blocksModel = gloader.loadModel(Gdx.files.internal("assets/graphics/box.g3db"));
    Pixmap pixmap = new Pixmap(MM_BKGRND_DIM, MM_BKGRND_DIM, Format.RGBA8888);
    pixmap.setColor(0.8f, 0.7f, 0.5f, .8f);
    pixmap.fillRectangle(0, 0, MM_BKGRND_DIM, MM_BKGRND_DIM);
    MINI_MAP_TEXTURE = new Texture(pixmap);
    pixmap.dispose();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.05f, 0.05f, 0.05f, 1f));
    // environment.set(new ColorAttribute(ColorAttribute.Fog, 0.13f, 0.13f, 0.13f, 1f));
    fixedLight = new PointLight().set(1f, 0.8f, 0.6f, 4f, 4f, 4f, 5f);
    environment.add(fixedLight);
    modelBatch = new ModelBatch();
    batch = new SpriteBatch();
    camera = new PerspectiveCamera(67, Ultima4.MAP_WIDTH, Ultima4.MAP_HEIGHT);
    camera.near = 0.1f;
    camera.far = 1000f;
    decalBatch = new DecalBatch(new CameraGroupStrategy(camera));
    // inputController = new CameraInputController(camera);
    // inputController.rotateLeftKey = inputController.rotateRightKey = inputController.forwardKey = inputController.backwardKey = 0;
    // inputController.translateUnits = 30f;
    ModelBuilder builder = new ModelBuilder();
    lightModel = builder.createSphere(.1f, .1f, .1f, 10, 10, new Material(ColorAttribute.createDiffuse(1, 1, 1, 1)), Usage.Position);
    lightModel.nodes.get(0).parts.get(0).setRenderable(pLight = new Renderable());
    for (int x = 0; x < 12; x++) {
        for (int y = 0; y < 12; y++) {
            Model sf = builder.createBox(1, 1, 1, new Material(TextureAttribute.createDiffuse(assets.get("assets/graphics/rock.png", Texture.class))), Usage.Position | Usage.TextureCoordinates | Usage.Normal);
            floor.add(new ModelInstance(sf, new Vector3(x - 1.5f, -.5f, y - 1.5f)));
        }
    }
    for (int x = 0; x < 12; x++) {
        for (int y = 0; y < 12; y++) {
            Model sf = builder.createBox(1, 1, 1, new Material(TextureAttribute.createDiffuse(assets.get("assets/graphics/dirt.png", Texture.class))), Usage.Position | Usage.TextureCoordinates | Usage.Normal);
            ceiling.add(new ModelInstance(sf, new Vector3(x - 1.5f, 1.5f, y - 1.5f)));
        }
    }
    try {
        InputStream is = new FileInputStream("assets/data/" + dungeonFileName.toLowerCase());
        byte[] bytes = IOUtils.toByteArray(is);
        int pos = 0;
        for (int i = 0; i < DUNGEON_MAP; i++) {
            for (int y = 0; y < DUNGEON_MAP; y++) {
                for (int x = 0; x < DUNGEON_MAP; x++) {
                    int index = bytes[pos] & 0xff;
                    pos++;
                    DungeonTile tile = DungeonTile.getTileByValue(index);
                    dungeonTiles[i][x][y] = tile;
                    addBlock(i, tile, x + .5f, .5f, y + .5f);
                }
            }
        }
        // rooms
        pos = 0x200;
        for (int i = 0; i < rooms.length; i++) {
            if (pos >= bytes.length) {
                continue;
            }
            rooms[i] = new DungeonRoom(bytes, pos);
            pos = pos + 256;
        }
        for (int i = 0; i < DUNGEON_MAP; i++) {
            for (int y = 0; y < DUNGEON_MAP; y++) {
                for (int x = 0; x < DUNGEON_MAP; x++) {
                    DungeonTile tile = dungeonTiles[i][x][y];
                    if (tile.getValue() >= 208 && tile.getValue() <= 223) {
                        DungeonRoom room = rooms[tile.getValue() - 207 - 1];
                        if (dngMap == Maps.ABYSS) {
                            if (i == 0 || i == 1) {
                            // nothing
                            } else if (i == 2 || i == 3) {
                                room = rooms[tile.getValue() - 207 + 16 - 1];
                            } else if (i == 4 || i == 5) {
                                room = rooms[tile.getValue() - 207 + 32 - 1];
                            } else if (i == 6 || i == 7) {
                                room = rooms[tile.getValue() - 207 + 48 - 1];
                            }
                        }
                        // for (int j=0;j<4;j++) if (room.triggers[j].tile.getIndex() != 0) System.out.println(room.triggers[j].toString());
                        if (room.hasAltar) {
                            if (x == 1) {
                                room.altarRoomVirtue = BaseVirtue.TRUTH;
                            } else if (x == 7) {
                                room.altarRoomVirtue = BaseVirtue.COURAGE;
                            } else {
                                room.altarRoomVirtue = BaseVirtue.LOVE;
                            }
                        }
                        RoomLocater loc = new RoomLocater(x, y, i, room);
                        locaters.add(loc);
                    }
                }
            }
        }
        miniMapIcon = new MiniMapIcon();
        miniMapIcon.setOrigin(5, 5);
        stage.addActor(miniMapIcon);
        setStartPosition();
        camera.position.set(currentPos);
        camera.lookAt(currentPos.x + 1, currentPos.y, currentPos.z);
        // i went 2 layers duplicated on each edges + the corners
        for (int i = 0; i < DUNGEON_MAP; i++) {
            {
                int y = 0;
                for (int x = 0; x < DUNGEON_MAP; x++) {
                    // bottom across the top
                    DungeonTile tile = dungeonTiles[i][x][y + DUNGEON_MAP - 1];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x + .5f, .5f, y - .5f);
                    tile = dungeonTiles[i][x][y + DUNGEON_MAP - 2];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x + .5f, .5f, y - 1.5f);
                }
                for (int x = 0; x < DUNGEON_MAP; x++) {
                    // top across the bottom
                    DungeonTile tile = dungeonTiles[i][x][y];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x + .5f, .5f, y + .5f + DUNGEON_MAP);
                    tile = dungeonTiles[i][x][y + 1];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x + .5f, .5f, y + .5f + DUNGEON_MAP + 1);
                }
            }
            {
                int x = 0;
                for (int y = 0; y < DUNGEON_MAP; y++) {
                    DungeonTile tile = dungeonTiles[i][x][y];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x + .5f + DUNGEON_MAP, .5f, y + .5f);
                    tile = dungeonTiles[i][x + 1][y];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x + .5f + DUNGEON_MAP + 1, .5f, y + .5f);
                }
                for (int y = 0; y < DUNGEON_MAP; y++) {
                    DungeonTile tile = dungeonTiles[i][x + DUNGEON_MAP - 1][y];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x - .5f, .5f, y + .5f);
                    tile = dungeonTiles[i][x + DUNGEON_MAP - 2][y];
                    if (tile == DungeonTile.CHEST)
                        tile = DungeonTile.FLOOR;
                    addBlock(i, tile, x - 1.5f, .5f, y + .5f);
                }
            }
            {
                // copy bottom right corner to the top left corner
                DungeonTile tile = dungeonTiles[i][DUNGEON_MAP - 1][DUNGEON_MAP - 1];
                addBlock(i, tile, -.5f, .5f, -.5f);
            }
            {
                // copy bottom left corner to the top right corner
                DungeonTile tile = dungeonTiles[i][0][DUNGEON_MAP - 1];
                addBlock(i, tile, DUNGEON_MAP + .5f, .5f, -.5f);
            }
            {
                // copy top right corner to the bottom left corner
                DungeonTile tile = dungeonTiles[i][DUNGEON_MAP - 1][0];
                addBlock(i, tile, -.5f, .5f, DUNGEON_MAP + .5f);
            }
            {
                // copy top left corner to the bottom right corner
                DungeonTile tile = dungeonTiles[i][0][0];
                addBlock(i, tile, DUNGEON_MAP + .5f, .5f, DUNGEON_MAP + .5f);
            }
        }
        createMiniMap();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DecalBatch(com.badlogic.gdx.graphics.g3d.decals.DecalBatch) CameraGroupStrategy(com.badlogic.gdx.graphics.g3d.decals.CameraGroupStrategy) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) Renderable(com.badlogic.gdx.graphics.g3d.Renderable) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) UBJsonReader(com.badlogic.gdx.utils.UBJsonReader) AssetManager(com.badlogic.gdx.assets.AssetManager) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Material(com.badlogic.gdx.graphics.g3d.Material) Vector3(com.badlogic.gdx.math.Vector3) FileInputStream(java.io.FileInputStream) PartyDeathException(util.PartyDeathException) DungeonTileModelInstance(util.DungeonTileModelInstance) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) G3dModelLoader(com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader) Model(com.badlogic.gdx.graphics.g3d.Model) Environment(com.badlogic.gdx.graphics.g3d.Environment) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) PointLight(com.badlogic.gdx.graphics.g3d.environment.PointLight) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 82 with Texture

use of com.badlogic.gdx.graphics.Texture in project ultimate-java by pantinor.

the class Ultima4 method fillRectangle.

private static Texture fillRectangle(int width, int height, Color color) {
    Pixmap pix = new Pixmap(width, height, Pixmap.Format.RGBA8888);
    pix.setColor(color);
    pix.fillRectangle(0, 0, width, height);
    Texture t = new Texture(pix);
    pix.dispose();
    return t;
}
Also used : Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 83 with Texture

use of com.badlogic.gdx.graphics.Texture in project ultimate-java by pantinor.

the class Ultima4 method create.

@Override
public void create() {
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("assets/fonts/lindberg.ttf"));
    FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
    parameter.size = 16;
    font = generator.generateFont(parameter);
    parameter.size = 10;
    smallFont = generator.generateFont(parameter);
    parameter.size = 24;
    BitmapFont fontLarger = generator.generateFont(parameter);
    generator.dispose();
    skin = new Skin(Gdx.files.internal("assets/skin/uiskin.json"));
    skin.remove("default-font", BitmapFont.class);
    skin.add("default-font", font, BitmapFont.class);
    skin.add("journal", font, BitmapFont.class);
    skin.add("death-screen", fontLarger, BitmapFont.class);
    Label.LabelStyle ls = Ultima4.skin.get("default", Label.LabelStyle.class);
    ls.font = font;
    TextButton.TextButtonStyle tbs = Ultima4.skin.get("default", TextButton.TextButtonStyle.class);
    tbs.font = font;
    TextButton.TextButtonStyle tbswood = Ultima4.skin.get("wood", TextButton.TextButtonStyle.class);
    tbswood.font = font;
    SelectBox.SelectBoxStyle sbs = Ultima4.skin.get("default", SelectBox.SelectBoxStyle.class);
    sbs.font = font;
    sbs.listStyle.font = font;
    CheckBox.CheckBoxStyle cbs = Ultima4.skin.get("default", CheckBox.CheckBoxStyle.class);
    cbs.font = font;
    List.ListStyle lis = Ultima4.skin.get("default", List.ListStyle.class);
    lis.font = font;
    TextField.TextFieldStyle tfs = Ultima4.skin.get("default", TextField.TextFieldStyle.class);
    tfs.font = font;
    hud = new LogDisplay(font);
    try {
        backGround = new Texture(Gdx.files.internal("assets/graphics/frame.png"));
        standardAtlas = new TextureAtlas(Gdx.files.internal("assets/tilemaps/latest-atlas.txt"));
        hitTile = Ultima4.standardAtlas.findRegion("hit_flash");
        magicHitTile = Ultima4.standardAtlas.findRegion("magic_flash");
        missTile = Ultima4.standardAtlas.findRegion("miss_flash");
        corpse = Ultima4.standardAtlas.findRegion("corpse");
        TextureAtlas tmp = new TextureAtlas(Gdx.files.internal("assets/graphics/explosion-atlas.txt"));
        Array<TextureAtlas.AtlasRegion> ar = tmp.findRegions("expl");
        explosion = new Animation<>(.2f, ar);
        tmp = new TextureAtlas(Gdx.files.internal("assets/graphics/Exp_type_B.atlas"));
        ar = tmp.findRegions("im");
        explosionLarge = new Animation<>(.1f, ar);
        tmp = new TextureAtlas(Gdx.files.internal("assets/graphics/cloud-atlas.txt"));
        ar = tmp.findRegions("cloud");
        cloud = new Animation<>(.2f, ar);
        baseTileSet = (TileSet) Utils.loadXml("tileset-base.xml", TileSet.class);
        baseTileSet.setMaps();
        maps = (MapSet) Utils.loadXml("maps.xml", MapSet.class);
        maps.init(baseTileSet);
        vendorClassSet = (VendorClassSet) Utils.loadXml("vendor.xml", VendorClassSet.class);
        vendorClassSet.init();
        weapons = (WeaponSet) Utils.loadXml("weapons.xml", WeaponSet.class);
        armors = (ArmorSet) Utils.loadXml("armors.xml", ArmorSet.class);
        creatures = (CreatureSet) Utils.loadXml("creatures.xml", CreatureSet.class);
        creatures.init();
        weapons.init();
        armors.init();
        Constants.Virtue.HONESTY.setBar(new TextureRegion(fillRectangle(200, 9, Color.CYAN)));
        Constants.Virtue.COMPASSION.setBar(new TextureRegion(fillRectangle(200, 9, Color.ORANGE)));
        Constants.Virtue.VALOR.setBar(new TextureRegion(fillRectangle(200, 9, Color.FIREBRICK)));
        Constants.Virtue.JUSTICE.setBar(new TextureRegion(fillRectangle(200, 9, Color.BLUE)));
        Constants.Virtue.SACRIFICE.setBar(new TextureRegion(fillRectangle(200, 9, Color.RED)));
        Constants.Virtue.HONOR.setBar(new TextureRegion(fillRectangle(200, 9, Color.PURPLE)));
        Constants.Virtue.SPIRITUALITY.setBar(new TextureRegion(fillRectangle(200, 9, Color.YELLOW)));
        Constants.Virtue.HUMILITY.setBar(new TextureRegion(fillRectangle(200, 9, Color.OLIVE)));
    } catch (Exception e) {
        e.printStackTrace();
    }
    startScreen = new StartScreen(this);
    setScreen(startScreen);
}
Also used : Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Texture(com.badlogic.gdx.graphics.Texture) LogDisplay(util.LogDisplay) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) List(com.badlogic.gdx.scenes.scene2d.ui.List) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 84 with Texture

use of com.badlogic.gdx.graphics.Texture in project ultimate-java by pantinor.

the class Utils method peerGem.

public static Texture peerGem(TiledMapTileLayer layer, String[] ids, TextureAtlas atlas, int cx, int cy) throws Exception {
    FileTextureData d = (FileTextureData) (atlas.getRegions().first().getTexture().getTextureData());
    BufferedImage sheet = ImageIO.read(d.getFileHandle().file());
    BufferedImage canvas = new BufferedImage(32 * layer.getWidth(), 32 * layer.getHeight(), BufferedImage.TYPE_INT_ARGB);
    for (int y = 0; y < layer.getHeight(); y++) {
        for (int x = 0; x < layer.getWidth(); x++) {
            String val = ids[layer.getCell(x, layer.getHeight() - y - 1).getTile().getId()];
            DungeonTile tile = DungeonTile.getTileByName(val);
            if (tile == null) {
                val = "brick_floor";
            }
            if (x == cx && y == cy) {
                val = "avatar";
            }
            AtlasRegion ar = (AtlasRegion) atlas.findRegion(val);
            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 = Utils.createPixmap(scaledCanvas.getWidth(), scaledCanvas.getHeight(), scaledCanvas, 0, 0);
    Texture t = new Texture(p);
    p.dispose();
    return t;
}
Also used : Image(java.awt.Image) 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) DungeonTile(ultima.Constants.DungeonTile) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 85 with Texture

use of com.badlogic.gdx.graphics.Texture in project ultimate-java by pantinor.

the class ProjectileActor method getBall.

private static Texture getBall(Color color) {
    Pixmap red = new Pixmap(32, 32, Format.RGBA8888);
    red.setColor(color);
    red.fillCircle(16, 16, 4);
    Texture t = new Texture(red);
    red.dispose();
    return t;
}
Also used : Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Aggregations

Texture (com.badlogic.gdx.graphics.Texture)235 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)78 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)62 Pixmap (com.badlogic.gdx.graphics.Pixmap)56 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)35 Stage (com.badlogic.gdx.scenes.scene2d.Stage)35 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)26 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)21 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)20 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)19 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)17 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)16 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)16 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)16 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)14 Material (com.badlogic.gdx.graphics.g3d.Material)12 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)12 Actor (com.badlogic.gdx.scenes.scene2d.Actor)11 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)11 FileHandle (com.badlogic.gdx.files.FileHandle)10