use of com.nyrds.pixeldungeon.levels.objects.LevelObject in project pixel-dungeon-remix by NYRDS.
the class Level method press.
public void press(int cell, Presser actor) {
Char chr = null;
if (actor != null) {
if (actor instanceof Char) {
chr = (Char) actor;
if (pit[cell] && !chr.isFlying()) {
Chasm.charFall(chr.getPos(), chr);
return;
}
if (actor instanceof Hero) {
pressHero(cell, (Hero) chr);
}
}
if (actor instanceof LevelObject) {
if (pit[cell]) {
((LevelObject) actor).fall();
return;
}
}
if (actor instanceof Item || actor instanceof LevelObject) {
set(cell, Terrain.discover(map[cell]));
}
if (actor.affectLevelObjects()) {
LevelObject levelObject = getTopLevelObject(cell);
if (levelObject != null && levelObject != actor) {
levelObject.bump(actor);
}
}
}
switch(map[cell]) {
case Terrain.TOXIC_TRAP:
ToxicTrap.trigger(cell, chr);
break;
case Terrain.FIRE_TRAP:
FireTrap.trigger(cell, chr);
break;
case Terrain.PARALYTIC_TRAP:
ParalyticTrap.trigger(cell, chr);
break;
case Terrain.POISON_TRAP:
PoisonTrap.trigger(cell, chr);
break;
case Terrain.ALARM_TRAP:
AlarmTrap.trigger(cell, chr);
break;
case Terrain.LIGHTNING_TRAP:
LightningTrap.trigger(cell, chr);
break;
case Terrain.GRIPPING_TRAP:
GrippingTrap.trigger(cell, chr);
break;
case Terrain.SUMMONING_TRAP:
SummoningTrap.trigger(cell, chr);
break;
case Terrain.DOOR:
Door.enter(cell);
break;
}
if (!(actor instanceof Mob)) {
switch(map[cell]) {
case Terrain.HIGH_GRASS:
HighGrass.trample(this, cell, chr);
break;
case Terrain.WELL:
WellWater.affectCell(cell);
break;
case Terrain.ALCHEMY:
Alchemy.transmute(cell);
break;
}
}
if (TerrainFlags.is(map[cell], TerrainFlags.TRAP)) {
if (Dungeon.visible[cell]) {
Sample.INSTANCE.play(Assets.SND_TRAP);
}
if (actor instanceof Hero) {
((Hero) actor).interrupt();
}
set(cell, Terrain.INACTIVE_TRAP);
GameScene.updateMap(cell);
}
Plant plant = plants.get(cell);
if (plant != null) {
plant.activate(chr);
}
}
use of com.nyrds.pixeldungeon.levels.objects.LevelObject in project pixel-dungeon-remix by NYRDS.
the class Level method restoreFromBundle.
@Override
public void restoreFromBundle(Bundle bundle) {
scripts = new HashSet<>();
mobs = new HashSet<>();
heaps = new SparseArray<>();
blobs = new HashMap<>();
plants = new SparseArray<>();
// old levels compat
width = bundle.optInt(WIDTH, 32);
height = bundle.optInt(HEIGHT, 32);
initSizeDependentStuff();
map = bundle.getIntArray(MAP);
for (LayerId layerId : LayerId.values()) {
int[] layer = bundle.getIntArray(layerId.name());
if (layer.length == map.length) {
customLayers.put(layerId, layer);
}
}
visited = bundle.getBooleanArray(VISITED);
mapped = bundle.getBooleanArray(MAPPED);
entrance = bundle.getInt(ENTRANCE);
compassTarget = bundle.optInt(COMPASS_TARGET, INVALID_CELL);
int[] exits = bundle.getIntArray(EXIT);
if (exits.length > 0) {
for (int i = 0; i < exits.length; ++i) {
setExit(exits[i], i);
}
} else {
setExit(bundle.getInt(EXIT), 0);
int secondaryExit = bundle.optInt(SECONDARY_EXIT, INVALID_CELL);
if (cellValid(secondaryExit)) {
setExit(secondaryExit, 1);
}
}
weakFloorCreated = false;
for (Heap heap : bundle.getCollection(HEAPS, Heap.class)) {
heaps.put(heap.pos, heap);
}
for (Plant plant : bundle.getCollection(PLANTS, Plant.class)) {
plants.put(plant.pos, plant);
}
for (LevelObject object : bundle.getCollection(OBJECTS, LevelObject.class)) {
putLevelObject(object);
}
for (Mob mob : bundle.getCollection(MOBS, Mob.class)) {
if (mob != null && mob.getPos() != INVALID_CELL) {
mobs.add(mob);
}
}
for (Blob blob : bundle.getCollection(BLOBS, Blob.class)) {
blobs.put(blob.getClass(), blob);
}
for (ScriptedActor actor : bundle.getCollection(SCRIPTS, ScriptedActor.class)) {
addScriptedActor(actor);
}
buildFlagMaps();
cleanWalls();
}
use of com.nyrds.pixeldungeon.levels.objects.LevelObject in project pixel-dungeon-remix by NYRDS.
the class GameScene method create.
@Override
public void create() {
playLevelMusic();
Level level = Dungeon.level;
PixelDungeon.lastClass(Dungeon.hero.heroClass.ordinal());
super.create();
Camera.main.zoom((float) (defaultZoom + PixelDungeon.zoom()));
scene = this;
Group terrain = new Group();
add(terrain);
water = new SkinnedBlock(level.getWidth() * DungeonTilemap.SIZE, level.getHeight() * DungeonTilemap.SIZE, level.getWaterTex());
waterSx = DungeonGenerator.getLevelProperty(level.levelId, "waterSx", waterSx);
waterSy = DungeonGenerator.getLevelProperty(level.levelId, "waterSy", waterSy);
terrain.add(water);
ripples = new Group();
terrain.add(ripples);
String logicTilesAtlas = level.getProperty("tiles_logic", null);
if (logicTilesAtlas != null) {
logicTiles = new ClassicDungeonTilemap(level, logicTilesAtlas);
terrain.add(logicTiles);
}
if (!level.customTiles()) {
baseTiles = DungeonTilemap.factory(level, level.getTilesetForLayer(Level.LayerId.Base));
} else {
CustomLayerTilemap tiles = new CustomLayerTilemap(level, Level.LayerId.Base);
tiles.addLayer(Level.LayerId.Deco);
tiles.addLayer(Level.LayerId.Deco2);
baseTiles = tiles;
tiles = new CustomLayerTilemap(level, Level.LayerId.Roof_Base);
tiles.addLayer(Level.LayerId.Roof_Deco);
tiles.setTransparent(true);
roofTiles = tiles;
}
terrain.add(baseTiles);
objects = new Group();
add(objects);
for (int i = 0; i < level.objects.size(); i++) {
SparseArray<LevelObject> objectLayer = level.objects.valueAt(i);
for (int j = 0; j < objectLayer.size(); j++) {
addLevelObjectSprite(objectLayer.valueAt(j));
}
}
level.addVisuals(this);
plants = new Group();
add(plants);
for (int i = 0; i < level.plants.size(); i++) {
addPlantSprite(level.plants.valueAt(i));
}
heaps = new Group();
add(heaps);
for (Heap heap : level.allHeaps()) {
addHeapSprite(heap);
}
emitters = new Group();
effects = new Group();
emoicons = new Group();
mobs = new Group();
add(mobs);
// hack to save bugged saves...
boolean buggedSave = false;
HashSet<Mob> filteredMobs = new HashSet<>();
for (Mob mob : level.mobs) {
if (level.cellValid(mob.getPos())) {
filteredMobs.add(mob);
} else {
buggedSave = true;
}
}
if (buggedSave) {
EventCollector.logEvent(EventCollector.BUG, "bugged save", "mob.pos==-1");
}
level.mobs = filteredMobs;
for (Mob mob : level.mobs) {
if (Statistics.amuletObtained) {
mob.beckon(Dungeon.hero.getPos());
}
}
Dungeon.hero.updateSprite();
add(emitters);
add(effects);
gases = new Group();
add(gases);
for (Blob blob : level.blobs.values()) {
blob.emitter = null;
addBlobSprite(blob);
}
fog = new FogOfWar(level.getWidth(), level.getHeight());
if (level.noFogOfWar()) {
level.reveal();
}
if (roofTiles != null) {
add(roofTiles);
}
fog.updateVisibility(Dungeon.visible, level.visited, level.mapped);
add(fog);
brightness(PixelDungeon.brightness());
spells = new Group();
add(spells);
statuses = new Group();
add(statuses);
add(emoicons);
add(new HealthIndicator());
add(cellSelector = new CellSelector(baseTiles));
Dungeon.hero.updateLook();
sb = new StatusPane(Dungeon.hero, level);
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);
attack = new AttackIndicator();
attack.camera = uiCamera;
attack.setPos(uiCamera.width - attack.width(), toolbar.top() - attack.height());
add(attack);
resume = new ResumeIndicator();
resume.camera = uiCamera;
resume.setPos(uiCamera.width - resume.width(), attack.top() - resume.height());
add(resume);
log = new GameLog();
log.camera = uiCamera;
log.setRect(0, toolbar.top(), attack.left(), 0);
add(log);
if (Dungeon.depth < Statistics.deepestFloor) {
GLog.i(TXT_WELCOME_BACK, Dungeon.depth);
} else {
GLog.i(TXT_WELCOME, Dungeon.depth);
Sample.INSTANCE.play(Assets.SND_DESCEND);
}
switch(level.getFeeling()) {
case CHASM:
GLog.w(TXT_CHASM);
break;
case WATER:
GLog.w(TXT_WATER);
break;
case GRASS:
GLog.w(TXT_GRASS);
break;
default:
}
if (level instanceof RegularLevel && ((RegularLevel) level).secretDoors > Random.IntRange(3, 4)) {
GLog.w(TXT_SECRETS);
}
if (Dungeon.nightMode && !Dungeon.bossLevel()) {
GLog.w(TXT_NIGHT_MODE);
}
busy = new BusyIndicator();
busy.camera = uiCamera;
busy.x = 1;
busy.y = sb.bottom() + 18;
add(busy);
sceneCreated = true;
switch(InterlevelScene.mode) {
case RESURRECT:
WandOfBlink.appear(Dungeon.hero, level.entrance);
new Flare(8, 32).color(0xFFFF66, true).show(Dungeon.hero.getHeroSprite(), 2f);
break;
case RETURN:
WandOfBlink.appear(Dungeon.hero, Dungeon.hero.getPos());
break;
case FALL:
Chasm.heroLand();
break;
case DESCEND:
DungeonGenerator.showStory(level);
if (Dungeon.hero.isAlive() && !level.isSafe() && Dungeon.depth != 22 && Dungeon.depth != 1) {
Badges.validateNoKilling();
}
break;
default:
}
Camera.main.target = Dungeon.hero.getHeroSprite();
level.activateScripts();
fadeIn();
Dungeon.observe();
}
use of com.nyrds.pixeldungeon.levels.objects.LevelObject in project pixel-dungeon-remix by NYRDS.
the class Level method getTopLevelObject.
@Nullable
public LevelObject getTopLevelObject(int pos) {
LevelObject top = null;
for (int i = 0; i < objects.size(); i++) {
SparseArray<LevelObject> objectLayer = objects.valueAt(i);
LevelObject candidate = objectLayer.get(pos);
if (top == null) {
top = candidate;
} else {
if (candidate != null && candidate.getLayer() > top.getLayer()) {
top = candidate;
}
}
}
return top;
}
use of com.nyrds.pixeldungeon.levels.objects.LevelObject in project pixel-dungeon-remix by NYRDS.
the class WandOfTelekinesis method onZap.
@Override
protected void onZap(int cell) {
boolean mapUpdated = false;
int maxDistance = effectiveLevel() + 4;
Ballistica.distance = Math.min(Ballistica.distance, maxDistance);
Char ch;
Heap heap = null;
Level level = Dungeon.level;
for (int i = 1; i < Ballistica.distance; i++) {
int c = Ballistica.trace[i];
int before = level.map[c];
if ((ch = Actor.findChar(c)) != null) {
if (i == Ballistica.distance - 1) {
ch.damage(maxDistance - 1 - i, this);
} else {
int next = Ballistica.trace[i + 1];
if (ch.isMovable() && (level.passable[next] || level.avoid[next]) && Actor.findChar(next) == null) {
Actor.addDelayed(new Pushing(ch, ch.getPos(), next), -1);
ch.setPos(next);
Actor.freeCell(next);
level.press(ch.getPos(), ch);
} else {
ch.damage(maxDistance - 1 - i, this);
}
}
}
if (heap == null && (heap = level.getHeap(c)) != null) {
switch(heap.type) {
case HEAP:
transport(heap);
break;
case CHEST:
case MIMIC:
heap.open(getCurUser());
break;
default:
}
}
level.press(c, new Effect());
if (before == Terrain.OPEN_DOOR && Actor.findChar(c) == null) {
level.set(c, Terrain.DOOR);
GameScene.updateMap(c);
} else if (level.water[c]) {
GameScene.ripple(c);
}
if (!mapUpdated && level.map[c] != before) {
mapUpdated = true;
}
LevelObject levelObject = null;
if ((levelObject = level.getTopLevelObject(c)) != null) {
if (levelObject.pushable(getCurUser())) {
levelObject.push(getCurUser());
}
}
}
if (mapUpdated) {
Dungeon.observe();
}
}
Aggregations