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);
}
}
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;
}
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;
}
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;
}
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);
}
}
}
Aggregations