use of objects.Creature in project ultimate-java by pantinor.
the class DungeonScreen 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);
((ColorAttribute) pLight.material.get(ColorAttribute.Diffuse)).color.set(fixedLight.color);
pLight.worldTransform.setTranslation(fixedLight.position);
Gdx.gl.glViewport(32, 64, Ultima4.MAP_WIDTH, Ultima4.MAP_HEIGHT);
camera.update();
modelBatch.begin(camera);
modelBatch.render(pLight);
for (ModelInstance i : floor) {
modelBatch.render(i, environment);
}
for (ModelInstance i : ceiling) {
modelBatch.render(i, environment);
}
for (DungeonTileModelInstance i : modelInstances) {
if (i.getLevel() == currentLevel) {
modelBatch.render(i.getInstance(), environment);
}
}
modelBatch.end();
for (Creature cr : dngMap.getMap().getCreatures()) {
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);
if (showMiniMap) {
batch.draw(MINI_MAP_TEXTURE, xalignMM, yalignMM);
batch.draw(miniMap, xalignMM, yalignMM);
}
Ultima4.hud.render(batch, context.getParty());
Ultima4.font.draw(batch, this.dngMap.getLabel(), 315, Ultima4.SCREEN_HEIGHT - 7);
Ultima4.font.draw(batch, "Level " + (currentLevel + 1), 515, Ultima4.SCREEN_HEIGHT - 7);
if (showZstats > 0) {
context.getParty().getSaveGame().renderZstats(showZstats, Ultima4.font, batch, Ultima4.SCREEN_HEIGHT);
}
batch.end();
stage.act();
stage.draw();
}
use of objects.Creature in project ultimate-java by pantinor.
the class GameScreen method checkSpecialCreatures.
private void checkSpecialCreatures(Direction dir, int x, int y) {
/*
* if heading east into pirates cove (O'A" N'N"), generate pirate ships
*/
if (dir == Direction.EAST && x == 0xdd && y == 0xe0) {
for (PirateCoveInfo pci : PirateCoveInfo.values()) {
Creature pirate = Ultima4.creatures.getInstance(CreatureType.pirate_ship, Ultima4.standardAtlas);
pirate.currentX = pci.getX();
pirate.currentY = pci.getY();
pirate.currentPos = getMapPixelCoords(pci.getX(), pci.getY());
pirate.sailDir = pci.getFacing();
context.getCurrentMap().addCreature(pirate);
}
}
/*
* if heading south towards the shrine of humility, generate
* daemons unless horn has been blown
*/
if (dir == Direction.SOUTH && x >= 229 && x < 234 && y >= 212 && y < 217 && context.getAura().getType() != AuraType.HORN) {
for (int i = 0; i < 8; i++) {
Creature daemon = Ultima4.creatures.getInstance(CreatureType.daemon, Ultima4.standardAtlas);
daemon.currentX = 231;
daemon.currentY = y + 1;
daemon.currentPos = getMapPixelCoords(231, y + 1);
context.getCurrentMap().addCreature(daemon);
}
}
}
use of objects.Creature 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.Creature in project ultimate-java by pantinor.
the class GameScreen method getRandomCreatureForTile.
private Creature getRandomCreatureForTile(Tile tile) {
int era = 0;
int randId = 0;
if (tile == null || tile.getRule() == null) {
System.err.println("randomForTile: Tile or rule is null");
return null;
}
if (tile.getRule().has(TileAttrib.creatureunwalkable)) {
return null;
}
if (tile.getRule().has(TileAttrib.sailable)) {
randId = CreatureType.pirate_ship.getValue();
randId += rand.nextInt(7);
Creature cr = Ultima4.creatures.getInstance(CreatureType.get(randId), Ultima4.standardAtlas);
return cr;
} else if (tile.getRule().has(TileAttrib.swimmable)) {
randId = CreatureType.nixie.getValue();
randId += rand.nextInt(5);
Creature cr = Ultima4.creatures.getInstance(CreatureType.get(randId), Ultima4.standardAtlas);
return cr;
}
if (context.getParty().getSaveGame().moves > 30000) {
era = 15;
} else if (context.getParty().getSaveGame().moves > 20000) {
era = 7;
} else {
era = 3;
}
randId = CreatureType.orc.getValue();
randId += era & rand.nextInt(16) & rand.nextInt(16);
Creature cr = Ultima4.creatures.getInstance(CreatureType.get(randId), Ultima4.standardAtlas);
return cr;
}
use of objects.Creature 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);
}
}
Aggregations