use of objects.Portal in project ultimate-java by pantinor.
the class Context method saveGame.
public void saveGame(float x, float y, float z, Direction orientation, Maps map) {
if (map == Maps.WORLD) {
party.getSaveGame().x = (int) x;
party.getSaveGame().y = (int) y;
party.getSaveGame().dngx = (int) x;
party.getSaveGame().dngy = (int) y;
party.getSaveGame().dnglevel = 0;
party.getSaveGame().orientation = 0;
} else {
Portal p = Maps.WORLD.getMap().getPortal(map.getId());
party.getSaveGame().x = (int) x;
party.getSaveGame().y = (int) y;
party.getSaveGame().dngx = (p == null ? (int) x : p.getX());
party.getSaveGame().dngy = (p == null ? (int) y : p.getY());
party.getSaveGame().dnglevel = (int) z;
party.getSaveGame().orientation = orientation.getVal() - 1;
}
party.getSaveGame().location = map.getId();
Stage surfaceStage = Maps.WORLD.getMap().getSurfaceMapStage();
if (surfaceStage != null) {
party.getSaveGame().resetMonsters();
Drawable[] objects = new Drawable[24];
int count = 0;
for (Actor a : surfaceStage.getActors()) {
if (a instanceof Drawable) {
Drawable d = (Drawable) a;
objects[count] = d;
if (count > 23) {
break;
}
count++;
}
}
for (int i = 0; i < 24; i++) {
if (objects[i] != null) {
party.getSaveGame().objects_save_tileids[i] = (byte) objects[i].getTile().getIndex();
party.getSaveGame().objects_save_x[i] = (byte) objects[i].getCx();
party.getSaveGame().objects_save_y[i] = (byte) objects[i].getCy();
}
}
List<Creature> monsters = Maps.WORLD.getMap().getCreatures();
for (int i = 0; i < 8 && monsters.size() > i; i++) {
Tile tile = Ultima4.baseTileSet.getTileByName(monsters.get(i).getTile().toString());
if (tile == null) {
continue;
}
party.getSaveGame().monster_save_tileids[i] = (byte) tile.getIndex();
party.getSaveGame().monster_save_x[i] = (byte) monsters.get(i).currentX;
party.getSaveGame().monster_save_y[i] = (byte) monsters.get(i).currentY;
}
}
try {
party.getSaveGame().write(PARTY_SAV_BASE_FILENAME);
} catch (Exception e) {
e.printStackTrace();
}
try {
File file = new File("journal.save");
JAXBContext jaxbContext = JAXBContext.newInstance(JournalEntries.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(this.journalEntries, file);
} catch (Exception e) {
e.printStackTrace();
}
}
use of objects.Portal in project ultimate-java by pantinor.
the class GameScreen method preMove.
private boolean preMove(Vector3 currentTile, Direction dir) {
int nx = (int) currentTile.x;
int ny = (int) currentTile.y;
if (context.getParty().getMember(0).getPlayer().status == StatusType.SLEEPING) {
finishTurn(nx, ny);
return false;
}
if (context.getTransportContext() == TransportContext.BALLOON) {
log("Drift only!");
return false;
}
if (dir == Direction.NORTH) {
ny = (int) currentTile.y - 1;
}
if (dir == Direction.SOUTH) {
ny = (int) currentTile.y + 1;
}
if (dir == Direction.WEST) {
nx = (int) currentTile.x - 1;
}
if (dir == Direction.EAST) {
nx = (int) currentTile.x + 1;
}
BaseMap bm = context.getCurrentMap();
if (bm.getBorderbehavior() == MapBorderBehavior.exit) {
if (nx > bm.getWidth() - 1 || nx < 0 || ny > bm.getHeight() - 1 || ny < 0) {
// remove any city/town actors (chests) from the map we are leaving
for (Actor a : mapObjectsStage.getActors()) {
if (a instanceof Drawable) {
Drawable d = (Drawable) a;
if (d.getMapId() != Maps.WORLD.getId() && d.getMapId() == bm.getId()) {
d.remove();
}
}
}
Portal p = Maps.WORLD.getMap().getPortal(bm.getId());
loadNextMap(Maps.WORLD, p.getX(), p.getY());
return false;
}
}
int mask = bm.getValidMovesMask(context, (int) currentTile.x, (int) currentTile.y);
if (!Direction.isDirInMask(dir, mask)) {
Sounds.play(Sound.BLOCKED);
finishTurn((int) currentTile.x, (int) currentTile.y);
return false;
}
return true;
}
use of objects.Portal 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.Portal in project ultimate-java by pantinor.
the class StaticGeneratedDungeonScreen method checkTileAffects.
public void checkTileAffects(DungeonTile tile, int x, int y) throws PartyDeathException {
switch(tile) {
case WIND_TRAP:
log("Wind extinguished your torch!");
Sounds.play(Sound.WIND);
isTorchOn = false;
break;
case PIT_TRAP:
log("Pit!");
context.getParty().applyEffect(TileEffect.LAVA);
Sounds.play(Sound.BOOM);
dungeonTiles[currentLevel][x][y] = DungeonTile.NOTHING;
break;
case ROCK_TRAP:
log("Falling Rocks!");
context.getParty().applyEffect(TileEffect.LAVA);
Sounds.play(Sound.ROCKS);
dungeonTiles[currentLevel][x][y] = DungeonTile.NOTHING;
break;
case MOONGATE:
Portal p = dngMap.getMap().getPortal(x, y, currentLevel);
if (p != null) {
log(p.getMessage());
Sounds.play(Sound.MOONGATE);
mainGame.setScreen(gameScreen);
gameScreen.loadNextMap(Maps.WORLD, p.getStartx(), p.getStarty());
dispose();
}
break;
case FIELD_POISON:
context.getParty().applyEffect(TileEffect.POISONFIELD);
Sounds.play(Sound.POISON_DAMAGE);
break;
case FIELD_SLEEP:
context.getParty().applyEffect(TileEffect.SLEEP);
Sounds.play(Sound.SLEEP);
break;
case FIELD_FIRE:
context.getParty().applyEffect(TileEffect.LAVA);
Sounds.play(Sound.FIREFIELD);
break;
}
}
use of objects.Portal 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");
}
Aggregations