Search in sources :

Example 26 with Creature

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

the class StaticGeneratedDungeonScreen 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);
    assets.get("assets/graphics/rock.png", Texture.class).setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    assets.get("assets/graphics/door.png", Texture.class).setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    assets.get("assets/graphics/mortar.png", Texture.class).setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    assets.get("assets/graphics/dirt.png", Texture.class).setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    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"));
    rocksModel = gloader.loadModel(Gdx.files.internal("assets/graphics/rocks.g3db"));
    campfireModel = gloader.loadModel(Gdx.files.internal("assets/graphics/campfire.g3db"));
    font = new BitmapFont();
    font.setColor(Color.WHITE);
    fixedLight = new PointLight().set(1f, 0.8f, 0.6f, 4f, 4f, 4f, 5f);
    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();
    Model fm = builder.createBox(1, 1, 1, new Material(TextureAttribute.createDiffuse(assets.get("assets/graphics/rock.png", Texture.class))), Usage.Position | Usage.TextureCoordinates | Usage.Normal);
    Model cm = builder.createBox(1, 1, 1, new Material(TextureAttribute.createDiffuse(assets.get("assets/graphics/dirt.png", Texture.class))), Usage.Position | Usage.TextureCoordinates | Usage.Normal);
    try {
        int TILE_SIZE = 16;
        FileHandle f = new FileHandle("assets/tilemaps/tiles-vga-atlas.txt");
        TextureAtlasData a = new TextureAtlasData(f, f.parent(), false);
        mapTileIds = new String[a.getRegions().size + 1];
        for (Region r : a.getRegions()) {
            int x = r.left / r.width;
            int y = r.top / r.height;
            int i = y * TILE_SIZE + x + 1;
            mapTileIds[i] = r.name;
        }
        TiledMap map = new TmxMapLoader().load("assets/tilemaps/delveOfSorrows.tmx");
        Iterator<MapLayer> iter = map.getLayers().iterator();
        int level = 0;
        while (iter.hasNext()) {
            environment[level] = new Environment();
            environment[level].set(new ColorAttribute(ColorAttribute.Ambient, 0.5f, 0.5f, 0.5f, 1f));
            environment[level].add(fixedLight);
            layers[level] = (TiledMapTileLayer) iter.next();
            for (int y = 0; y < DUNGEON_MAP; y++) {
                for (int x = 0; x < DUNGEON_MAP; x++) {
                    String val = mapTileIds[layers[level].getCell(x, DUNGEON_MAP - y - 1).getTile().getId()];
                    DungeonTile tile = DungeonTile.getTileByName(val);
                    if (tile == null) {
                        CreatureType ct = CreatureType.get(val);
                        if (ct != null) {
                            Creature creature = Ultima4.creatures.getInstance(ct, Ultima4.standardAtlas);
                            creature.currentX = x;
                            creature.currentY = y;
                            creature.currentLevel = level;
                            creature.getDecal().setPosition(creature.currentX + .5f, .3f, creature.currentY + .5f);
                            dngMap.getMap().addCreature(creature);
                        } else {
                            System.err.println(val);
                        }
                        dungeonTiles[level][x][y] = DungeonTile.NOTHING;
                    } else if (tile == DungeonTile.WATER) {
                        Model w = builder.createBox(1, 1, 1, getMaterial(Color.BLUE, .9f), Usage.Position | Usage.Normal);
                        ModelInstance wi = new ModelInstance(w, x + .5f, -.5f, y + .5f);
                        DungeonTileModelInstance fin = new DungeonTileModelInstance(wi, DungeonTile.WATER, level);
                        modelInstances.add(fin);
                        dungeonTiles[level][x][y] = DungeonTile.NOTHING;
                    } else {
                        dungeonTiles[level][x][y] = tile;
                        addBlock(level, tile, x + .5f, .5f, y + .5f);
                    }
                    if (tile == null || tile != DungeonTile.WATER) {
                        DungeonTileModelInstance fin = new DungeonTileModelInstance(new ModelInstance(fm, new Vector3(x + .5f, -.5f, y + .5f)), DungeonTile.FLOOR, level);
                        modelInstances.add(fin);
                    }
                    DungeonTileModelInstance cin = new DungeonTileModelInstance(new ModelInstance(cm, new Vector3(x + .5f, 1.5f, y + .5f)), DungeonTile.FLOOR, level);
                    modelInstances.add(cin);
                }
            }
            level++;
        }
        setStartPosition();
        camera.position.set(currentPos);
        camera.lookAt(currentPos.x + 1, currentPos.y, currentPos.z);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DecalBatch(com.badlogic.gdx.graphics.g3d.decals.DecalBatch) Creature(objects.Creature) FileHandle(com.badlogic.gdx.files.FileHandle) MapLayer(com.badlogic.gdx.maps.MapLayer) 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) TextureAtlasData(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) UBJsonReader(com.badlogic.gdx.utils.UBJsonReader) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) AssetManager(com.badlogic.gdx.assets.AssetManager) DungeonTileModelInstance(util.DungeonTileModelInstance) Material(com.badlogic.gdx.graphics.g3d.Material) Vector3(com.badlogic.gdx.math.Vector3) 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) Region(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region) Environment(com.badlogic.gdx.graphics.g3d.Environment) PointLight(com.badlogic.gdx.graphics.g3d.environment.PointLight) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Example 27 with Creature

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

the class StaticGeneratedDungeonScreen method moveDungeonCreatures.

private void moveDungeonCreatures(BaseScreen screen, int avatarX, int avatarY) {
    for (Creature cr : dngMap.getMap().getCreatures()) {
        if (cr.currentLevel != this.currentLevel) {
            continue;
        }
        // dont move the creature unless the avatar gets close
        if (Utils.movementDistance(MapBorderBehavior.wrap, DUNGEON_MAP, DUNGEON_MAP, avatarX, avatarY, cr.currentX, cr.currentY) > 3) {
            continue;
        }
        int mask = getValidMovesMask(cr.currentX, cr.currentY, cr, avatarX, avatarY);
        Direction dir = Utils.getPath(MapBorderBehavior.wrap, DUNGEON_MAP, DUNGEON_MAP, avatarX, avatarY, mask, true, cr.currentX, cr.currentY);
        if (dir == null) {
            continue;
        }
        if (dir == Direction.NORTH) {
            cr.currentY = cr.currentY - 1 < 0 ? DUNGEON_MAP - 1 : cr.currentY - 1;
        }
        if (dir == Direction.SOUTH) {
            cr.currentY = cr.currentY + 1 >= DUNGEON_MAP ? 0 : cr.currentY + 1;
        }
        if (dir == Direction.EAST) {
            cr.currentX = cr.currentX + 1 >= DUNGEON_MAP ? 0 : cr.currentX + 1;
        }
        if (dir == Direction.WEST) {
            cr.currentX = cr.currentX - 1 < 0 ? DUNGEON_MAP - 1 : cr.currentX - 1;
        }
        cr.getDecal().setPosition(cr.currentX + .5f, .3f, cr.currentY + .5f);
        // if touches avatar then invoke battle!
        if (Utils.movementDistance(MapBorderBehavior.wrap, DUNGEON_MAP, DUNGEON_MAP, avatarX, avatarY, cr.currentX, cr.currentY) == 0) {
            battleWandering(cr, avatarX, avatarY);
        }
    }
}
Also used : Creature(objects.Creature)

Example 28 with Creature

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

the class StaticGeneratedDungeonScreen method render.

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT);
    lightFactor += Gdx.graphics.getDeltaTime();
    float lightSize = 4.75f + 0.25f * (float) Math.sin(lightFactor) + .2f * MathUtils.random();
    Vector3 ll = isTorchOn ? nll : vdll;
    ll = isTorchOn ? nll2 : vdll;
    fixedLight.set(ll.x, ll.y, ll.z, currentPos.x, currentPos.y + .35f, currentPos.z, lightSize);
    Gdx.gl.glViewport(32, 64, Ultima4.MAP_WIDTH, Ultima4.MAP_HEIGHT);
    camera.update();
    modelBatch.begin(camera);
    for (DungeonTileModelInstance i : modelInstances) {
        if (i.getLevel() == currentLevel) {
            modelBatch.render(i.getInstance(), environment[currentLevel]);
        }
    }
    modelBatch.end();
    for (Creature cr : dngMap.getMap().getCreatures()) {
        if (cr.currentLevel != this.currentLevel) {
            continue;
        }
        decalBatch.add(cr.getDecal());
    }
    decalBatch.flush();
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    batch.begin();
    batch.draw(Ultima4.backGround, 0, 0);
    Ultima4.hud.render(batch, context.getParty());
    Ultima4.font.draw(batch, "Level " + (currentLevel + 1) + " facing " + currentDir, 305, Ultima4.SCREEN_HEIGHT - 7);
    if (showZstats > 0) {
        context.getParty().getSaveGame().renderZstats(showZstats, Ultima4.font, batch, Ultima4.SCREEN_HEIGHT);
    }
    batch.end();
    stage.act();
    stage.draw();
}
Also used : Creature(objects.Creature) DungeonTileModelInstance(util.DungeonTileModelInstance) Vector3(com.badlogic.gdx.math.Vector3)

Example 29 with Creature

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

the class CombatScreen method render.

@Override
public void render(float delta) {
    time += delta;
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.position.set(newMapPixelCoords.x + 5 * tilePixelWidth, newMapPixelCoords.y, 0);
    camera.update();
    renderer.setView(camera.combined, // this is voodoo
    camera.position.x - tilePixelWidth * 10, camera.position.y - tilePixelHeight * 10, Ultima4.MAP_WIDTH, Ultima4.MAP_HEIGHT);
    renderer.render();
    renderer.getBatch().begin();
    for (Creature cr : combatMap.getCreatures()) {
        if (cr.currentPos == null || !cr.getVisible()) {
            continue;
        }
        renderer.getBatch().draw(cr.getAnim().getKeyFrame(time, true), cr.currentPos.x, cr.currentPos.y);
    }
    for (PartyMember p : party.getMembers()) {
        if (p.combatCr == null || p.combatCr.currentPos == null || p.fled) {
            continue;
        }
        if (p.getPlayer().status != StatusType.DEAD && p.getPlayer().status != StatusType.SLEEPING) {
            renderer.getBatch().draw(p.combatCr.getAnim().getKeyFrame(time, true), p.combatCr.currentPos.x, p.combatCr.currentPos.y);
        } else {
            renderer.getBatch().draw(Ultima4.corpse, p.combatCr.currentPos.x, p.combatCr.currentPos.y);
        }
    }
    renderer.getBatch().end();
    batch.begin();
    batch.draw(Ultima4.backGround, 0, 0);
    Ultima4.hud.render(batch, party);
    Ultima4.font.setColor(Color.WHITE);
    if (showZstats > 0) {
        party.getSaveGame().renderZstats(showZstats, Ultima4.font, batch, Ultima4.SCREEN_HEIGHT);
    }
    if (context.getAura().getType() != AuraType.NONE) {
        Ultima4.font.draw(batch, context.getAura().getType().toString(), 430, Ultima4.SCREEN_HEIGHT - 7);
    }
    batch.end();
    stage.act();
    stage.draw();
}
Also used : Creature(objects.Creature) PartyMember(objects.Party.PartyMember)

Example 30 with Creature

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

the class CombatScreen method finishTurn.

@Override
public void finishTurn(int currentX, int currentY) {
    try {
        party.endTurn(combatMap.getType());
        context.getAura().passTurn();
        if (combatMap.getCreatures().isEmpty() && combatMap.getType() == MapType.combat) {
            end();
            return;
        }
        boolean quick = context.getAura().getType() == AuraType.QUICKNESS && (rand.nextInt(2) == 0);
        if (!quick) {
            SequenceAction seq = Actions.action(SequenceAction.class);
            for (Creature cr : combatMap.getCreatures()) {
                seq.addAction(Actions.run(new CreatureActionsAction(cr)));
                seq.addAction(Actions.delay(.04f));
            }
            seq.addAction(Actions.run(new FinishCreatureAction()));
            stage.addAction(seq);
        }
    } catch (PartyDeathException e) {
        this.returnScreen.partyDeath();
    }
}
Also used : Creature(objects.Creature) PartyDeathException(util.PartyDeathException) SequenceAction(com.badlogic.gdx.scenes.scene2d.actions.SequenceAction)

Aggregations

Creature (objects.Creature)32 Tile (objects.Tile)12 Drawable (objects.Drawable)8 TiledMapTile (com.badlogic.gdx.maps.tiled.TiledMapTile)6 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)6 Vector3 (com.badlogic.gdx.math.Vector3)6 SequenceAction (com.badlogic.gdx.scenes.scene2d.actions.SequenceAction)6 Actor (com.badlogic.gdx.scenes.scene2d.Actor)5 PartyMember (objects.Party.PartyMember)5 PartyDeathException (util.PartyDeathException)5 MapLayer (com.badlogic.gdx.maps.MapLayer)3 DungeonTileModelInstance (util.DungeonTileModelInstance)3 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)2 Texture (com.badlogic.gdx.graphics.Texture)2 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)2 MapObject (com.badlogic.gdx.maps.MapObject)2 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)2 Portal (objects.Portal)2 AssetManager (com.badlogic.gdx.assets.AssetManager)1 FileHandle (com.badlogic.gdx.files.FileHandle)1