Search in sources :

Example 16 with Creature

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

the class TestJaxb method testCreatures.

// @Test
public void testCreatures() throws Exception {
    File file = new File("target/classes/xml/creatures.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(CreatureSet.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    CreatureSet ts = (CreatureSet) jaxbUnmarshaller.unmarshal(file);
    for (Creature t : ts.getCreatures()) {
        System.out.println(t);
    }
}
Also used : CreatureSet(objects.CreatureSet) Creature(objects.Creature) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Example 17 with Creature

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

the class Utils method fireAt.

private static AttackResult fireAt(Context context, Stage stage, BaseMap combatMap, AttackVector target, boolean avatarAttack, int avatarX, int avatarY) throws PartyDeathException {
    AttackResult res = AttackResult.NONE;
    // check for ship
    Drawable ship = null;
    for (Actor a : stage.getActors()) {
        if (a instanceof Drawable) {
            Drawable d = (Drawable) a;
            if (d.getTile().getName().equals("ship") && d.getCx() == target.x && d.getCy() == target.y) {
                ship = d;
            }
        }
    }
    if (ship != null) {
        ship.damageShip(-1, 10);
        target.impactedDrawable = ship;
        return AttackResult.HIT;
    }
    if (avatarAttack) {
        Creature creature = null;
        for (Creature c : combatMap.getCreatures()) {
            if (c.currentX == target.x && c.currentY == target.y) {
                creature = c;
                break;
            }
        }
        if (creature == null) {
            return res;
        }
        if (rand.nextInt(4) == 0) {
            res = AttackResult.HIT;
            target.impactedCreature = creature;
        } else {
            res = AttackResult.MISS;
        }
    } else if (target.x == avatarX && target.y == avatarY) {
        if (context.getTransportContext() == TransportContext.SHIP) {
            context.damageShip(-1, 10);
        } else {
            context.getParty().damageParty(10, 25);
        }
        res = AttackResult.HIT;
    }
    return res;
}
Also used : Creature(objects.Creature) Actions.removeActor(com.badlogic.gdx.scenes.scene2d.actions.Actions.removeActor) ProjectileActor(objects.ProjectileActor) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Drawable(objects.Drawable)

Example 18 with Creature

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

the class Utils method peerGem.

// used for view gem on the world map only
public static Texture peerGem(BaseMap worldMap, int avatarX, int avatarY, TextureAtlas atlas) throws Exception {
    FileTextureData d = (FileTextureData) (atlas.getRegions().first().getTexture().getTextureData());
    BufferedImage sheet = ImageIO.read(d.getFileHandle().file());
    BufferedImage canvas = new BufferedImage(32 * 64, 32 * 64, BufferedImage.TYPE_INT_ARGB);
    int startX = avatarX - 32;
    int startY = avatarY - 32;
    int endX = avatarX + 32;
    int endY = avatarY + 32;
    int indexX = 0;
    int indexY = 0;
    for (int y = startY; y < endY; y++) {
        for (int x = startX; x < endX; x++) {
            int cx = x;
            if (x < 0) {
                cx = 256 + x;
            } else if (x >= 256) {
                cx = x - 256;
            }
            int cy = y;
            if (y < 0) {
                cy = 256 + y;
            } else if (y >= 256) {
                cy = y - 256;
            }
            Tile ct = worldMap.getTile(cx, cy);
            AtlasRegion ar = (AtlasRegion) atlas.findRegion(ct.getName());
            BufferedImage sub = sheet.getSubimage(ar.getRegionX(), ar.getRegionY(), 32, 32);
            canvas.getGraphics().drawImage(sub, indexX * 32, indexY * 32, 32, 32, null);
            Creature cr = worldMap.getCreatureAt(cx, cy);
            if (cr != null) {
                canvas.getGraphics().fillRect(indexX * 32, indexY * 32, 32, 32);
            }
            indexX++;
        }
        indexX = 0;
        indexY++;
    }
    // add avatar in the middle
    canvas.getGraphics().fillRect((32 * 64) / 2, (32 * 64) / 2, 32, 32);
    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);
    Texture t = new Texture(p);
    p.dispose();
    return t;
}
Also used : Creature(objects.Creature) 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)

Example 19 with Creature

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

the class HorseService method nextDialog.

@Override
public boolean nextDialog() {
    switch(state) {
        case WAIT_BUY_INPUT:
            displayToScreen(String.format(welcomeMessage, vendor.getName(), vendor.getOwner()));
            displayToScreen("Can I interest thee in horses?");
            break;
        case WAIT_BUY_ONE:
            displayToScreen("For only 200g.p thou can have the best. Wilt thou buy?");
            break;
        case BUY_ITEM:
            party.adjustGold(-currentSelectedItem.getPrice());
            displayToScreen("Here, a better breed thou shalt not find ever!");
            if (screen != null) {
                Creature cr = Ultima4.creatures.getInstance(CreatureType.horse, Ultima4.standardAtlas);
                Vector3 v = screen.getCurrentMapCoords();
                cr.currentX = (int) v.x;
                cr.currentY = (int) v.y;
                party.getContext().getCurrentMap().addCreature(cr);
                ((GameScreen) screen).board((int) v.x, (int) v.y);
            }
            return false;
        case DECLINE_BUY:
            displayToScreen("A shame, thou looks like thou could use a good horse!");
            return false;
        case FAREWELL:
            displayToScreen("Fare thee well!");
            return false;
        default:
            displayToScreen("I cannot help thee with that.");
            state = ConvState.WAIT_BUY_INPUT;
            break;
    }
    return true;
}
Also used : GameScreen(ultima.GameScreen) Creature(objects.Creature) Vector3(com.badlogic.gdx.math.Vector3)

Example 20 with Creature

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

the class DungeonScreen method moveDungeonCreatures.

private void moveDungeonCreatures(BaseScreen screen, int avatarX, int avatarY) {
    for (Creature cr : dngMap.getMap().getCreatures()) {
        int mask = getValidMovesMask(cr.currentX, cr.currentY, cr, avatarX, avatarY);
        // dont use wrap border behavior with the dungeon maps
        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)

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