use of com.watabou.pixeldungeon.items.Item in project pixel-dungeon by watabou.
the class GameScene method create.
@Override
public void create() {
Music.INSTANCE.play(Assets.TUNE, true);
Music.INSTANCE.volume(1f);
PixelDungeon.lastClass(Dungeon.hero.heroClass.ordinal());
super.create();
Camera.main.zoom(defaultZoom + PixelDungeon.zoom());
scene = this;
terrain = new Group();
add(terrain);
water = new SkinnedBlock(Level.WIDTH * DungeonTilemap.SIZE, Level.HEIGHT * DungeonTilemap.SIZE, Dungeon.level.waterTex());
terrain.add(water);
ripples = new Group();
terrain.add(ripples);
tiles = new DungeonTilemap();
terrain.add(tiles);
Dungeon.level.addVisuals(this);
plants = new Group();
add(plants);
int size = Dungeon.level.plants.size();
for (int i = 0; i < size; i++) {
addPlantSprite(Dungeon.level.plants.valueAt(i));
}
heaps = new Group();
add(heaps);
size = Dungeon.level.heaps.size();
for (int i = 0; i < size; i++) {
addHeapSprite(Dungeon.level.heaps.valueAt(i));
}
emitters = new Group();
effects = new Group();
emoicons = new Group();
mobs = new Group();
add(mobs);
for (Mob mob : Dungeon.level.mobs) {
addMobSprite(mob);
if (Statistics.amuletObtained) {
mob.beckon(Dungeon.hero.pos);
}
}
add(emitters);
add(effects);
gases = new Group();
add(gases);
for (Blob blob : Dungeon.level.blobs.values()) {
blob.emitter = null;
addBlobSprite(blob);
}
fog = new FogOfWar(Level.WIDTH, Level.HEIGHT);
fog.updateVisibility(Dungeon.visible, Dungeon.level.visited, Dungeon.level.mapped);
add(fog);
brightness(PixelDungeon.brightness());
spells = new Group();
add(spells);
statuses = new Group();
add(statuses);
add(emoicons);
hero = new HeroSprite();
hero.place(Dungeon.hero.pos);
hero.updateArmor();
mobs.add(hero);
add(new HealthIndicator());
add(cellSelector = new CellSelector(tiles));
StatusPane sb = new StatusPane();
sb.camera = uiCamera;
sb.setSize(uiCamera.width, 0);
add(sb);
toolbar = new Toolbar();
toolbar.camera = uiCamera;
toolbar.setRect(0, uiCamera.height - toolbar.height(), uiCamera.width, toolbar.height());
add(toolbar);
AttackIndicator attack = new AttackIndicator();
attack.camera = uiCamera;
attack.setPos(uiCamera.width - attack.width(), toolbar.top() - attack.height());
add(attack);
log = new GameLog();
log.camera = uiCamera;
log.setRect(0, toolbar.top(), attack.left(), 0);
add(log);
busy = new BusyIndicator();
busy.camera = uiCamera;
busy.x = 1;
busy.y = sb.bottom() + 1;
add(busy);
switch(InterlevelScene.mode) {
case RESURRECT:
WandOfBlink.appear(Dungeon.hero, Dungeon.level.entrance);
new Flare(8, 32).color(0xFFFF66, true).show(hero, 2f);
break;
case RETURN:
WandOfBlink.appear(Dungeon.hero, Dungeon.hero.pos);
break;
case FALL:
Chasm.heroLand();
break;
case DESCEND:
switch(Dungeon.depth) {
case 1:
WndStory.showChapter(WndStory.ID_SEWERS);
break;
case 6:
WndStory.showChapter(WndStory.ID_PRISON);
break;
case 11:
WndStory.showChapter(WndStory.ID_CAVES);
break;
case 16:
WndStory.showChapter(WndStory.ID_METROPOLIS);
break;
case 22:
WndStory.showChapter(WndStory.ID_HALLS);
break;
}
if (Dungeon.hero.isAlive() && Dungeon.depth != 22) {
Badges.validateNoKilling();
}
break;
default:
}
ArrayList<Item> dropped = Dungeon.droppedItems.get(Dungeon.depth);
if (dropped != null) {
for (Item item : dropped) {
int pos = Dungeon.level.randomRespawnCell();
if (item instanceof Potion) {
((Potion) item).shatter(pos);
} else if (item instanceof Plant.Seed) {
Dungeon.level.plant((Plant.Seed) item, pos);
} else {
Dungeon.level.drop(item, pos);
}
}
Dungeon.droppedItems.remove(Dungeon.depth);
}
Camera.main.target = hero;
if (InterlevelScene.mode != InterlevelScene.Mode.NONE) {
if (Dungeon.depth < Statistics.deepestFloor) {
GLog.h(TXT_WELCOME_BACK, Dungeon.depth);
} else {
GLog.h(TXT_WELCOME, Dungeon.depth);
Sample.INSTANCE.play(Assets.SND_DESCEND);
}
switch(Dungeon.level.feeling) {
case CHASM:
GLog.w(TXT_CHASM);
break;
case WATER:
GLog.w(TXT_WATER);
break;
case GRASS:
GLog.w(TXT_GRASS);
break;
default:
}
if (Dungeon.level instanceof RegularLevel && ((RegularLevel) Dungeon.level).secretDoors > Random.IntRange(3, 4)) {
GLog.w(TXT_SECRETS);
}
if (Dungeon.nightMode && !Dungeon.bossLevel()) {
GLog.w(TXT_NIGHT_MODE);
}
InterlevelScene.mode = InterlevelScene.Mode.NONE;
fadeIn();
}
}
use of com.watabou.pixeldungeon.items.Item in project pixel-dungeon by watabou.
the class WndSadGhost method onSelect.
@Override
protected void onSelect(int index) {
if (questItem != null) {
questItem.detach(Dungeon.hero.belongings.backpack);
}
Item reward = index == 0 ? Ghost.Quest.weapon : Ghost.Quest.armor;
if (reward.doPickUp(Dungeon.hero)) {
GLog.i(Hero.TXT_YOU_NOW_HAVE, reward.name());
} else {
Dungeon.level.drop(reward, ghost.pos).sprite.drop();
}
ghost.yell("Farewell, adventurer!");
ghost.die(null);
Ghost.Quest.complete();
}
use of com.watabou.pixeldungeon.items.Item in project pixel-dungeon by watabou.
the class VaultPainter method paint.
public static void paint(Level level, Room room) {
fill(level, room, Terrain.WALL);
fill(level, room, 1, Terrain.EMPTY_SP);
fill(level, room, 2, Terrain.EMPTY);
int cx = (room.left + room.right) / 2;
int cy = (room.top + room.bottom) / 2;
int c = cx + cy * Level.WIDTH;
switch(Random.Int(3)) {
case 0:
level.drop(prize(level), c).type = Type.LOCKED_CHEST;
level.addItemToSpawn(new GoldenKey());
break;
case 1:
Item i1, i2;
do {
i1 = prize(level);
i2 = prize(level);
} while (i1.getClass() == i2.getClass());
level.drop(i1, c).type = Type.CRYSTAL_CHEST;
level.drop(i2, c + Level.NEIGHBOURS8[Random.Int(8)]).type = Type.CRYSTAL_CHEST;
level.addItemToSpawn(new GoldenKey());
break;
case 2:
level.drop(prize(level), c);
set(level, c, Terrain.PEDESTAL);
break;
}
room.entrance().set(Room.Door.Type.LOCKED);
level.addItemToSpawn(new IronKey());
}
use of com.watabou.pixeldungeon.items.Item in project pixel-dungeon by watabou.
the class Hero method reallyDie.
public static void reallyDie(Object cause) {
int length = Level.LENGTH;
int[] map = Dungeon.level.map;
boolean[] visited = Dungeon.level.visited;
boolean[] discoverable = Level.discoverable;
for (int i = 0; i < length; i++) {
int terr = map[i];
if (discoverable[i]) {
visited[i] = true;
if ((Terrain.flags[terr] & Terrain.SECRET) != 0) {
Level.set(i, Terrain.discover(terr));
GameScene.updateMap(i);
}
}
}
Bones.leave();
Dungeon.observe();
Dungeon.hero.belongings.identify();
int pos = Dungeon.hero.pos;
ArrayList<Integer> passable = new ArrayList<Integer>();
for (Integer ofs : Level.NEIGHBOURS8) {
int cell = pos + ofs;
if ((Level.passable[cell] || Level.avoid[cell]) && Dungeon.level.heaps.get(cell) == null) {
passable.add(cell);
}
}
Collections.shuffle(passable);
ArrayList<Item> items = new ArrayList<Item>(Dungeon.hero.belongings.backpack.items);
for (Integer cell : passable) {
if (items.isEmpty()) {
break;
}
Item item = Random.element(items);
Dungeon.level.drop(item, cell).sprite.drop(pos);
items.remove(item);
}
GameScene.gameOver();
if (cause instanceof Hero.Doom) {
((Hero.Doom) cause).onDeath();
}
Dungeon.deleteGame(Dungeon.hero.heroClass, true);
}
use of com.watabou.pixeldungeon.items.Item in project pixel-dungeon by watabou.
the class Dungeon method loadGame.
public static void loadGame(String fileName, boolean fullLoad) throws IOException {
Bundle bundle = gameBundle(fileName);
Dungeon.challenges = bundle.getInt(CHALLENGES);
Dungeon.level = null;
Dungeon.depth = -1;
if (fullLoad) {
PathFinder.setMapSize(Level.WIDTH, Level.HEIGHT);
}
Scroll.restore(bundle);
Potion.restore(bundle);
Wand.restore(bundle);
Ring.restore(bundle);
potionOfStrength = bundle.getInt(POS);
scrollsOfUpgrade = bundle.getInt(SOU);
scrollsOfEnchantment = bundle.getInt(SOE);
dewVial = bundle.getBoolean(DV);
if (fullLoad) {
chapters = new HashSet<Integer>();
int[] ids = bundle.getIntArray(CHAPTERS);
if (ids != null) {
for (int id : ids) {
chapters.add(id);
}
}
Bundle quests = bundle.getBundle(QUESTS);
if (!quests.isNull()) {
Ghost.Quest.restoreFromBundle(quests);
Wandmaker.Quest.restoreFromBundle(quests);
Blacksmith.Quest.restoreFromBundle(quests);
Imp.Quest.restoreFromBundle(quests);
} else {
Ghost.Quest.reset();
Wandmaker.Quest.reset();
Blacksmith.Quest.reset();
Imp.Quest.reset();
}
Room.restoreRoomsFromBundle(bundle);
}
Bundle badges = bundle.getBundle(BADGES);
if (!badges.isNull()) {
Badges.loadLocal(badges);
} else {
Badges.reset();
}
QuickSlot.restore(bundle);
@SuppressWarnings("unused") String version = bundle.getString(VERSION);
hero = null;
hero = (Hero) bundle.get(HERO);
QuickSlot.compress();
gold = bundle.getInt(GOLD);
depth = bundle.getInt(DEPTH);
Statistics.restoreFromBundle(bundle);
Journal.restoreFromBundle(bundle);
droppedItems = new SparseArray<ArrayList<Item>>();
for (int i = 2; i <= Statistics.deepestFloor + 1; i++) {
ArrayList<Item> dropped = new ArrayList<Item>();
for (Bundlable b : bundle.getCollection(String.format(DROPPED, i))) {
dropped.add((Item) b);
}
if (!dropped.isEmpty()) {
droppedItems.put(i, dropped);
}
}
}
Aggregations