use of objects.Tile in project ultimate-java by pantinor.
the class GameScreen method keyUp.
@Override
public boolean keyUp(int keycode) {
context.setLastCommandTime(System.currentTimeMillis());
Vector3 v = getCurrentMapCoords();
Tile ct = context.getCurrentMap().getTile(v);
if (keycode == Keys.UP) {
if (context.getTransportContext() == TransportContext.SHIP && avatarDirection + 1 != Direction.NORTH.getVal()) {
avatarDirection = Direction.NORTH.getVal() - 1;
finishTurn((int) v.x, (int) v.y);
return false;
}
if (!preMove(v, Direction.NORTH)) {
return false;
}
if (newMapPixelCoords.y + tilePixelHeight >= context.getCurrentMap().getHeight() * tilePixelHeight) {
newMapPixelCoords.y = 0;
postMove(Direction.NORTH, (int) v.x, context.getCurrentMap().getHeight() - 1);
} else {
newMapPixelCoords.y = newMapPixelCoords.y + tilePixelHeight;
postMove(Direction.NORTH, (int) v.x, (int) v.y - 1);
}
avatarDirection = Direction.NORTH.getVal() - 1;
} else if (keycode == Keys.RIGHT) {
if (context.getTransportContext() == TransportContext.SHIP && avatarDirection + 1 != Direction.EAST.getVal()) {
avatarDirection = Direction.EAST.getVal() - 1;
finishTurn((int) v.x, (int) v.y);
return false;
}
if (!preMove(v, Direction.EAST)) {
return false;
}
if (newMapPixelCoords.x + tilePixelWidth >= context.getCurrentMap().getWidth() * tilePixelWidth) {
newMapPixelCoords.x = 0;
postMove(Direction.EAST, 0, (int) v.y);
} else {
newMapPixelCoords.x = newMapPixelCoords.x + tilePixelWidth;
postMove(Direction.EAST, (int) v.x + 1, (int) v.y);
}
avatarDirection = Direction.EAST.getVal() - 1;
} else if (keycode == Keys.LEFT) {
if (context.getTransportContext() == TransportContext.SHIP && avatarDirection + 1 != Direction.WEST.getVal()) {
avatarDirection = Direction.WEST.getVal() - 1;
finishTurn((int) v.x, (int) v.y);
return false;
}
if (!preMove(v, Direction.WEST)) {
return false;
}
if (newMapPixelCoords.x - tilePixelWidth < 0) {
newMapPixelCoords.x = (context.getCurrentMap().getWidth() - 1) * tilePixelWidth;
postMove(Direction.WEST, context.getCurrentMap().getWidth() - 1, (int) v.y);
} else {
newMapPixelCoords.x = newMapPixelCoords.x - tilePixelWidth;
postMove(Direction.WEST, (int) v.x - 1, (int) v.y);
}
avatarDirection = Direction.WEST.getVal() - 1;
} else if (keycode == Keys.DOWN) {
if (context.getTransportContext() == TransportContext.SHIP && avatarDirection + 1 != Direction.SOUTH.getVal()) {
avatarDirection = Direction.SOUTH.getVal() - 1;
finishTurn((int) v.x, (int) v.y);
return false;
}
if (!preMove(v, Direction.SOUTH)) {
return false;
}
if (newMapPixelCoords.y - tilePixelHeight < 0) {
newMapPixelCoords.y = (context.getCurrentMap().getHeight() - 1) * tilePixelHeight;
postMove(Direction.SOUTH, (int) v.x, 0);
} else {
newMapPixelCoords.y = newMapPixelCoords.y - tilePixelHeight;
postMove(Direction.SOUTH, (int) v.x, (int) v.y + 1);
}
avatarDirection = Direction.SOUTH.getVal() - 1;
} else if (keycode == Keys.F && context.getTransportContext() == TransportContext.SHIP) {
log("Fire Cannon > ");
ShipInputAdapter sia = new ShipInputAdapter(v);
Gdx.input.setInputProcessor(sia);
return false;
} else if (keycode == Keys.H) {
CombatScreen.holeUp(Maps.WORLD, (int) v.x, (int) v.y, this, context, Ultima4.creatures, Ultima4.standardAtlas, false);
return false;
} else if (keycode == Keys.K || keycode == Keys.D) {
if (context.getCurrentMap().getId() == Maps.WORLD.getId()) {
if (keycode == Keys.K && context.getTransportContext() == TransportContext.BALLOON) {
context.getParty().getSaveGame().balloonstate = 1;
log("Klimb altitude");
} else if (keycode == Keys.D && context.getTransportContext() == TransportContext.BALLOON) {
if (ct.getRule().has(TileAttrib.canlandballoon)) {
context.getParty().getSaveGame().balloonstate = 0;
renderer.getFOV().calculateFOV(context.getCurrentMap().getShadownMap(), (int) v.x, (int) v.y, 17f);
log("Land balloon");
} else {
log("Not here!");
}
}
} else {
Portal p = context.getCurrentMap().getPortal(v.x, v.y, 0);
if (p != null) {
loadNextMap(Maps.get(p.getDestmapid()), p.getStartx(), p.getStarty());
log(p.getMessage());
return false;
}
}
} else if (keycode == Keys.E) {
if (context.getTransportContext() == TransportContext.BALLOON) {
log("Only on foot!");
return false;
}
Portal p = context.getCurrentMap().getPortal(v.x, v.y, 0);
if (p != null) {
if (Maps.get(p.getDestmapid()).getMap().getType() == MapType.shrine) {
Virtue virtue = Virtue.get(Maps.get(p.getDestmapid()).getId() - 25);
if (context.getParty().canEnterShrine(virtue)) {
loadNextMap(Maps.get(p.getDestmapid()), p.getStartx(), p.getStarty());
} else {
log("Thou dost not bear the rune of entry!");
log("A strange force keeps you out!");
}
} else {
Maps dest = Maps.get(p.getDestmapid());
if (dest == Maps.ABYSS) {
if ((context.getParty().getSaveGame().items & Item.CANDLE_USED.getLoc()) == 0 || (context.getParty().getSaveGame().items & Item.BELL_USED.getLoc()) == 0 || (context.getParty().getSaveGame().items & Item.BOOK_USED.getLoc()) == 0) {
log("A strange force keeps you out!");
return false;
}
}
if (p.getDestmapid() != context.getCurrentMap().getId()) {
loadNextMap(dest, p.getStartx(), p.getStarty());
} else {
newMapPixelCoords = getMapPixelCoords(p.getStartx(), p.getStarty());
recalcFOV(context.getCurrentMap(), p.getStartx(), p.getStarty());
}
return false;
}
}
} else if (keycode == Keys.Q) {
if (context.getCurrentMap().getId() == Maps.WORLD.getId() && context.getParty().getSaveGame().balloonstate == 0) {
context.saveGame(v.x, v.y, 0, null, Maps.WORLD);
log("Saved Game.");
} else {
log("Cannot save here!");
}
} else if (keycode == Keys.L) {
if (context.getCurrentMap().getId() == Maps.WORLD.getId()) {
if (context.getParty().getSaveGame().sextants >= 1) {
log("Locate position with sextant");
log(String.format("Latitude: %s' %s\"", (char) ((int) v.y / 16 + 'A'), (char) ((int) v.y % 16 + 'A')));
log(String.format("Longitude: %s' %s\"", (char) ((int) v.x / 16 + 'A'), (char) ((int) v.x % 16 + 'A')));
} else {
log("Locate position with what?");
}
} else {
log("Not here!");
}
} else if (keycode == Keys.N) {
log("New Order:");
log("exhange #:");
NewOrderInputAdapter noia = new NewOrderInputAdapter(this);
Gdx.input.setInputProcessor(noia);
return false;
} else if (keycode == Keys.S) {
BaseMap bm = context.getCurrentMap();
ItemMapLabels l = bm.searchLocation(this, context.getParty(), (int) v.x, (int) v.y, 0);
if (l != null) {
log("You found " + l.getDesc() + ".");
} else {
log("Nothing here!");
}
} else if (keycode == Keys.M) {
mainGame.setScreen(new MixtureScreen(mainGame, this, Ultima4.skin, context.getParty()));
} else if (keycode == Keys.B) {
board((int) v.x, (int) v.y);
} else if (keycode == Keys.X) {
if (context.getTransportContext() == TransportContext.SHIP) {
Tile st = Ultima4.baseTileSet.getTileByName("ship");
Drawable ship = new Drawable(context.getCurrentMap(), (int) v.x, (int) v.y, st, Ultima4.standardAtlas);
ship.setX(newMapPixelCoords.x);
ship.setY(newMapPixelCoords.y);
mapObjectsStage.addActor(ship);
} else if (context.getTransportContext() == TransportContext.HORSE) {
Creature cr = Ultima4.creatures.getInstance(CreatureType.horse, Ultima4.standardAtlas);
cr.currentX = (int) v.x;
cr.currentY = (int) v.y;
context.getCurrentMap().addCreature(cr);
} else if (context.getTransportContext() == TransportContext.BALLOON) {
if (context.getParty().getSaveGame().balloonstate == 0) {
addBalloonActor((int) v.x, (int) v.y);
context.getParty().getSaveGame().balloonx = (int) v.x;
context.getParty().getSaveGame().balloony = (int) v.y;
} else {
log("Thou must land first!");
return false;
}
}
context.getParty().setTransport(Ultima4.baseTileSet.getTileByIndex(0x1f));
mainAvatar = avatarAnim;
} else if (keycode == Keys.P) {
peerGem();
} else if (keycode == Keys.U) {
log("Use Item:");
log("");
ItemInputAdapter iia = new ItemInputAdapter(this);
Gdx.input.setInputProcessor(iia);
return false;
} else if (keycode == Keys.T || keycode == Keys.O || keycode == Keys.J || keycode == Keys.L || keycode == Keys.A || keycode == Keys.G || keycode == Keys.R || keycode == Keys.W) {
Gdx.input.setInputProcessor(sip);
sip.setinitialKeyCode(keycode, context.getCurrentMap(), (int) v.x, (int) v.y);
return false;
} else if (keycode == Keys.C) {
log("Cast Spell: ");
log("Who casts (1-8): ");
Gdx.input.setInputProcessor(new SpellInputProcessor(this, context, stage, (int) v.x, (int) v.y, null));
return false;
} else if (keycode == Keys.Z) {
showZstats = showZstats + 1;
if (showZstats >= STATS_PLAYER1 && showZstats <= STATS_PLAYER8) {
if (showZstats > context.getParty().getMembers().size()) {
showZstats = STATS_WEAPONS;
}
}
if (showZstats > STATS_SPELLS) {
showZstats = STATS_NONE;
}
} else if (keycode == Keys.ESCAPE) {
mainGame.setScreen(new BookScreen(mainGame, this, Ultima4.skin));
} else if (keycode == Keys.SPACE) {
log("Pass");
}
finishTurn((int) v.x, (int) v.y);
return false;
}
use of objects.Tile in project ultimate-java by pantinor.
the class GameScreen method getChest.
public void getChest(int index, int x, int y) {
if (context.getParty().isFlying()) {
log("Not in a ballon!");
return;
}
boolean found = false;
Drawable chest = null;
Array<Actor> as = mapObjectsStage.getActors();
for (Actor a : as) {
if (a instanceof Drawable) {
Drawable d = (Drawable) a;
if (StringUtils.equals("chest", d.getTile().getName()) && d.getCx() == x && d.getCy() == y) {
chest = (Drawable) a;
found = true;
chest.remove();
break;
}
}
}
if (chest == null) {
// check tile too, ie in cities
Tile tile = context.getCurrentMap().getTile(x, y);
if (tile.getRule() == TileRule.chest) {
replaceTile("brick_floor", x, y);
found = true;
}
}
try {
if (found) {
PartyMember pm = context.getParty().getMember(index);
if (pm == null) {
System.err.println("member is null " + index);
}
if (pm.getPlayer() == null) {
System.err.println("player is null " + index);
}
context.getChestTrapHandler(pm);
log(String.format("The Chest Holds: %d Gold", context.getParty().getChestGold()));
if (context.getCurrentMap().getType() == MapType.city) {
context.getParty().adjustKarma(KarmaAction.STOLE_CHEST);
}
} else {
log("Not Here!");
}
} catch (PartyDeathException e) {
partyDeath();
}
}
use of objects.Tile in project ultimate-java by pantinor.
the class SpellUtil method spellUndead.
public static void spellUndead(BaseScreen screen, PartyMember caster) {
if (screen.scType == ScreenType.COMBAT) {
SequenceAction seq = Actions.action(SequenceAction.class);
final CombatScreen combatScreen = (CombatScreen) screen;
int level = caster.getPlayer().getLevel();
// from the AD&D dungeon masters guide page 75 :)
boolean turn = Utils.rand.nextInt(100) >= 50;
if (level > 1) {
turn = Utils.rand.nextInt(100) >= 35;
}
if (level > 2) {
turn = Utils.rand.nextInt(100) >= 20;
}
if (level > 3) {
turn = true;
}
for (Creature cr : combatScreen.combatMap.getCreatures()) {
if (cr.getUndead() && turn) {
Tile tile = Ultima4.baseTileSet.getTileByName("hit_flash");
Drawable d = new Drawable(combatScreen.combatMap, cr.currentX, cr.currentY, tile, Ultima4.standardAtlas);
d.setX(cr.currentPos.x);
d.setY(cr.currentPos.y);
d.addAction(Actions.sequence(Actions.delay(.4f), Actions.fadeOut(.2f), Actions.removeActor()));
seq.addAction(Actions.run(new AddActorAction(combatScreen.getStage(), d)));
seq.addAction(Actions.run(new PlaySoundAction(Sound.NPC_STRUCK)));
Utils.dealDamage(caster, cr, 23);
} else {
seq.addAction(Actions.run(new PlaySoundAction(Sound.EVADE)));
}
if (cr.getDamageStatus() == CreatureStatus.DEAD) {
seq.addAction(Actions.run(combatScreen.new RemoveCreatureAction(cr)));
}
}
seq.addAction(Actions.run(new Runnable() {
@Override
public void run() {
combatScreen.finishPlayerTurn();
}
}));
combatScreen.getStage().addAction(seq);
}
}
use of objects.Tile in project ultimate-java by pantinor.
the class SpellUtil method destoryAllCreatures.
/**
* Used with skull of mondain on world map
*/
public static void destoryAllCreatures(BaseScreen screen, PartyMember caster) {
if (screen.scType == ScreenType.MAIN) {
final GameScreen gameScreen = (GameScreen) screen;
SequenceAction seq = Actions.action(SequenceAction.class);
for (final Creature cr : screen.context.getCurrentMap().getCreatures()) {
/* Deal maximum damage to creature */
Utils.dealDamage(caster, cr, 0xFF);
Tile tile = Ultima4.baseTileSet.getTileByName("hit_flash");
Drawable d = new Drawable(screen.context.getCurrentMap(), cr.currentX, cr.currentY, tile, Ultima4.standardAtlas);
d.setX(cr.currentPos.x);
d.setY(cr.currentPos.y);
d.addAction(Actions.sequence(Actions.delay(.4f), Actions.fadeOut(.2f), Actions.removeActor()));
seq.addAction(Actions.run(new AddActorAction(gameScreen.getStage(), d)));
seq.addAction(Actions.run(new PlaySoundAction(Sound.NPC_STRUCK)));
seq.addAction(Actions.run(new Runnable() {
@Override
public void run() {
screen.context.getCurrentMap().getCreatures().remove(cr);
}
}));
}
gameScreen.getStage().addAction(seq);
}
}
use of objects.Tile in project ultimate-java by pantinor.
the class DungeonRoomTiledMapLoader method load.
public TiledMap load() {
TiledMap map = new TiledMap();
MapProperties mapProperties = map.getProperties();
mapProperties.put("dungeonRoom", room);
mapProperties.put("orientation", "orthogonal");
mapProperties.put("width", mapWidth);
mapProperties.put("height", mapHeight);
mapProperties.put("tilewidth", tileWidth);
mapProperties.put("tileheight", tileHeight);
mapProperties.put("backgroundcolor", "#000000");
TiledMapTileLayer layer = new TiledMapTileLayer(mapWidth, mapHeight, tileWidth, tileHeight);
layer.setName("Map Layer");
layer.setVisible(true);
for (int y = 0; y < mapHeight; y++) {
for (int x = 0; x < mapWidth; x++) {
Tile ct = room.getTile(x, y);
// if (room.getTriggerAt(x, y) != null) ct = GameScreen.baseTileSet.getTileByIndex(3); //temp debugging triggers
Cell cell = new Cell();
TextureRegion tileRegion = atlas.findRegion(ct.getName());
TiledMapTile tmt = new StaticTiledMapTile(tileRegion);
tmt.setId(y * mapWidth + x);
cell.setTile(tmt);
layer.setCell(x, mapHeight - 1 - y, cell);
}
}
map.getLayers().add(layer);
try {
loadCombatPositions(map);
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
Aggregations