Search in sources :

Example 1 with Moongate

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

the class GameScreen method render.

@Override
public void render(float delta) {
    time += delta;
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    if (renderer == null) {
        return;
    }
    camera.position.set(newMapPixelCoords.x + 5 * tilePixelWidth, newMapPixelCoords.y, 0);
    camera.update();
    renderer.setView(camera.combined, // this is voodoo
    camera.position.x - tilePixelWidth * 15, camera.position.y - tilePixelHeight * 10, Ultima4.MAP_WIDTH, Ultima4.MAP_HEIGHT);
    renderer.render();
    mapBatch.begin();
    if (context.getCurrentMap().getMoongates() != null) {
        for (Moongate g : context.getCurrentMap().getMoongates()) {
            TextureRegion t = g.getCurrentTexture();
            if (t != null) {
                Vector3 v = getMapPixelCoords(g.getX(), g.getY());
                mapBatch.draw(t, v.x, v.y);
            }
        }
    }
    mapBatch.end();
    mapObjectsStage.act();
    mapObjectsStage.draw();
    batch.begin();
    batch.draw(Ultima4.backGround, 0, 0);
    batch.draw(mainAvatar.getKeyFrames()[avatarDirection], tilePixelWidth * 11, tilePixelHeight * 12);
    // Vector3 v = getCurrentMapCoords();
    // font.draw(batch, String.format("newMapPixelCoords: %d, %d", (int)newMapPixelCoords.x, (int)newMapPixelCoords.y), 10, 500);
    // font.draw(batch, String.format("current map coords: %d, %d", (int)v.x, (int)v.y), 10, 480);
    // font.draw(batch, "fps: " + Gdx.graphics.getFramesPerSecond(), 10, 460);
    Ultima4.hud.render(batch, context.getParty());
    Ultima4.font.setColor(Color.WHITE);
    if (showZstats > 0) {
        context.getParty().getSaveGame().renderZstats(showZstats, Ultima4.font, batch, Ultima4.SCREEN_HEIGHT);
    }
    if (context.getCurrentMap().getId() == Maps.WORLD.getId()) {
        batch.draw(moonAtlas.findRegion("phase_" + trammelphase), 360, Ultima4.SCREEN_HEIGHT - 25, 25, 25);
        batch.draw(moonAtlas.findRegion("phase_" + feluccaphase), 380, Ultima4.SCREEN_HEIGHT - 25, 25, 25);
        Ultima4.font.draw(batch, "Wind " + context.getWindDirection().toString(), 415, Ultima4.SCREEN_HEIGHT - 7);
    }
    if (context.getAura().getType() != AuraType.NONE) {
        Ultima4.font.draw(batch, context.getAura().getType().toString(), 200, Ultima4.SCREEN_HEIGHT - 32);
    }
    batch.end();
    projectilesStage.act();
    projectilesStage.draw();
    stage.act();
    stage.draw();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Moongate(objects.Moongate) Vector3(com.badlogic.gdx.math.Vector3)

Example 2 with Moongate

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

the class GameScreen method postMove.

private void postMove(Direction dir, int newx, int newy) {
    if (context.getCurrentMap().getId() == Maps.WORLD.getId()) {
        // check for active moongate portal
        for (Moongate g : context.getCurrentMap().getMoongates()) {
            if (g.getCurrentTexture() != null && newx == g.getX() && newy == g.getY()) {
                Sounds.play(Sound.MOONGATE);
                Vector3 d = getDestinationForMoongate(g);
                if (d != null) {
                    newMapPixelCoords = getMapPixelCoords((int) d.x, (int) d.y);
                }
            }
        }
        /* things that happen while not on board the balloon */
        if (context.getTransportContext() != TransportContext.BALLOON) {
            checkSpecialCreatures(dir, newx, newy);
            checkBridgeTrolls(newx, newy);
        }
    }
    renderer.getFOV().calculateFOV(context.getCurrentMap().getShadownMap(), newx, newy, 17f);
    log(dir.toString());
}
Also used : Moongate(objects.Moongate) Vector3(com.badlogic.gdx.math.Vector3)

Example 3 with Moongate

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

the class SpellUtil method spellGate.

public static void spellGate(BaseScreen screen, int phase) {
    if (screen.scType == ScreenType.MAIN) {
        GameScreen gsc = (GameScreen) screen;
        for (Moongate g : gsc.context.getCurrentMap().getMoongates()) {
            if (g.getPhase() == phase) {
                Vector3 dest = new Vector3(g.getX(), g.getY(), 0);
                gsc.newMapPixelCoords = gsc.getMapPixelCoords((int) dest.x, (int) dest.y);
                BaseMap bm = gsc.context.getCurrentMap();
                gsc.recalcFOV(bm, (int) dest.x, (int) dest.y);
                break;
            }
        }
    }
}
Also used : Moongate(objects.Moongate) Vector3(com.badlogic.gdx.math.Vector3) BaseMap(objects.BaseMap)

Example 4 with Moongate

use of objects.Moongate 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 5 with Moongate

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

the class GameScreen method updateMoons.

private void updateMoons(boolean showmoongates) {
    // world map only
    if (context.getCurrentMap().getId() == 0) {
        if (context.incrementWindCounter() >= MOON_SECONDS_PER_PHASE * 4) {
            if (rand.nextInt(4) == 1) {
                context.setWindDirection(Direction.getRandomValidDirection(0xff));
            }
            context.setWindCounter(0);
        }
        if (context.incrementBalloonCounter() >= 2) {
            if (context.getParty().getSaveGame().balloonstate == 1) {
                driftBalloon(context.getWindDirection());
            }
            context.setBalloonCounter(0);
        }
        context.setMoonPhase(context.getMoonPhase() + 1);
        if (context.getMoonPhase() >= MOON_PHASES * MOON_SECONDS_PER_PHASE * 4) {
            context.setMoonPhase(0);
        }
        phase = (context.getMoonPhase() / (4 * MOON_SECONDS_PER_PHASE));
        feluccaphase = phase % 8;
        trammelphase = phase / 3;
        if (trammelphase > 7) {
            trammelphase = 7;
        }
        trammelSubphase = context.getMoonPhase() % (MOON_SECONDS_PER_PHASE * 4 * 3);
        for (Moongate g : context.getCurrentMap().getMoongates()) {
            g.setCurrentTexture(null);
        }
        if (showmoongates) {
            Moongate gate = context.getCurrentMap().getMoongate(trammelphase);
            AtlasRegion texture = null;
            if (trammelSubphase == 0) {
                texture = moongateTextures.get(0);
            } else if (trammelSubphase == 1) {
                texture = moongateTextures.get(1);
            } else if (trammelSubphase == 2) {
                texture = moongateTextures.get(2);
            } else if (trammelSubphase == 3) {
                texture = moongateTextures.get(3);
            } else if ((trammelSubphase > 3) && (trammelSubphase < (MOON_SECONDS_PER_PHASE * 4 * 3) - 3)) {
                texture = moongateTextures.get(3);
            } else if (trammelSubphase == (MOON_SECONDS_PER_PHASE * 4 * 3) - 3) {
                texture = moongateTextures.get(2);
            } else if (trammelSubphase == (MOON_SECONDS_PER_PHASE * 4 * 3) - 2) {
                texture = moongateTextures.get(1);
            } else if (trammelSubphase == (MOON_SECONDS_PER_PHASE * 4 * 3) - 1) {
                texture = moongateTextures.get(0);
            }
            gate.setCurrentTexture(texture);
        }
    }
}
Also used : Moongate(objects.Moongate) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)

Aggregations

Moongate (objects.Moongate)6 Vector3 (com.badlogic.gdx.math.Vector3)4 BaseMap (objects.BaseMap)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)1 TextureAtlasData (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData)1 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 File (java.io.File)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 MapSet (objects.MapSet)1 Portal (objects.Portal)1 Tile (objects.Tile)1 TileSet (objects.TileSet)1