v0.3.1: added in logic for the proper display of inactive traps

This commit is contained in:
Evan Debenham 2015-08-14 03:29:45 -04:00 committed by Evan Debenham
parent 5fd3d94ca2
commit 9b13c3f01e
11 changed files with 60 additions and 19 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

@ -20,6 +20,8 @@
*/
package com.shatteredpixel.shatteredpixeldungeon.levels;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.ToxicTrap;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Scene;
import com.watabou.noosa.audio.Sample;
@ -120,19 +122,13 @@ public class CavesBossLevel extends Level {
map[exit] = Terrain.LOCKED_EXIT;
for (int i=0; i < LENGTH; i++) {
if (map[i] == Terrain.EMPTY && Random.Int( 6 ) == 0) {
map[i] = Terrain.INACTIVE_TRAP;
}
}
Painter.fill( this, ROOM_LEFT - 1, ROOM_TOP - 1,
ROOM_RIGHT - ROOM_LEFT + 3, ROOM_BOTTOM - ROOM_TOP + 3, Terrain.WALL );
Painter.fill( this, ROOM_LEFT, ROOM_TOP + 1,
ROOM_RIGHT - ROOM_LEFT + 1, ROOM_BOTTOM - ROOM_TOP, Terrain.EMPTY );
Painter.fill( this, ROOM_LEFT, ROOM_TOP,
ROOM_RIGHT - ROOM_LEFT + 1, 1, Terrain.INACTIVE_TRAP );
ROOM_RIGHT - ROOM_LEFT + 1, 1, Terrain.EMPTY_DECO );
arenaDoor = Random.Int( ROOM_LEFT, ROOM_RIGHT ) + (ROOM_BOTTOM + 1) * WIDTH;
map[arenaDoor] = Terrain.DOOR;
@ -148,6 +144,15 @@ public class CavesBossLevel extends Level {
}
}
for (int i=0; i < LENGTH; i++) {
if (map[i] == Terrain.EMPTY && Random.Int( 6 ) == 0) {
map[i] = Terrain.INACTIVE_TRAP;
Trap t = new ToxicTrap().reveal();
t.active = false;
setTrap(t, i);
}
}
return true;
}

View File

@ -345,6 +345,18 @@ public abstract class Level implements Bundlable {
traps.put( trap.pos, trap );
}
//for pre-0.3.1 saves
if (version < 52){
for (int i=0; i < map.length; i++){
if (map[i] == Terrain.INACTIVE_TRAP){
Trap t = new WornTrap().reveal();
t.active = false;
t.pos = i;
traps.put( i, t);
}
}
}
collection = bundle.getCollection( MOBS );
for (Bundlable m : collection) {
Mob mob = (Mob)m;
@ -638,7 +650,7 @@ public abstract class Level implements Bundlable {
public static void set( int cell, int terrain ) {
Painter.set( Dungeon.level, cell, terrain );
if (terrain != Terrain.TRAP && terrain != Terrain.SECRET_TRAP){
if (terrain != Terrain.TRAP && terrain != Terrain.SECRET_TRAP && terrain != Terrain.INACTIVE_TRAP){
Dungeon.level.traps.remove( cell );
}
@ -667,7 +679,7 @@ public abstract class Level implements Bundlable {
//effectively nullifies whatever the logic calling this wants to do, including dropping items.
Heap heap = new Heap();
ItemSprite sprite = heap.sprite = new ItemSprite();
sprite.link( heap );
sprite.link(heap);
return heap;
}
@ -707,7 +719,7 @@ public abstract class Level implements Bundlable {
return drop( item, n );
}
heap.drop( item );
heap.drop(item);
if (Dungeon.level != null) {
press( cell, null );
@ -741,10 +753,15 @@ public abstract class Level implements Bundlable {
}
public void uproot( int pos ) {
plants.delete( pos );
plants.delete(pos);
}
public Trap setTrap( Trap trap, int pos ){
Trap existingTrap = traps.get(pos);
if (existingTrap != null){
traps.delete( pos );
if(existingTrap.sprite != null) existingTrap.sprite.kill();
}
trap.set( pos );
traps.put( pos, trap );
GameScene.add(trap);
@ -752,7 +769,6 @@ public abstract class Level implements Bundlable {
}
public void disarmTrap( int pos ) {
traps.delete(pos);
set(pos, Terrain.INACTIVE_TRAP);
GameScene.updateMap(pos);
}

View File

@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.keys.SkeletonKey;
import com.shatteredpixel.shatteredpixeldungeon.levels.Room.Type;
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.PoisonTrap;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.watabou.noosa.Scene;
import com.watabou.utils.Bundle;
@ -271,6 +272,14 @@ public class PrisonBossLevel extends RegularLevel {
roomExit.width() - 3,
roomExit.height() - 3,
Terrain.INACTIVE_TRAP );
for (int cell : roomExit.getCells()){
if (map[cell] == Terrain.INACTIVE_TRAP){
Trap t = new PoisonTrap().reveal();
t.active = false;
setTrap(t, cell);
}
}
}
@Override

View File

@ -42,6 +42,7 @@ public abstract class Trap implements Bundlable {
public TrapSprite sprite;
public boolean visible;
public boolean active = true;
public Trap set(int pos){
this.pos = pos;
@ -66,33 +67,41 @@ public abstract class Trap implements Bundlable {
}
public void trigger() {
if (Dungeon.visible[pos]){
if (active) {
if (Dungeon.visible[pos]) {
Sample.INSTANCE.play(Assets.SND_TRAP);
}
disarm();
activate();
}
}
public abstract void activate();
protected void disarm(){
Dungeon.level.disarmTrap(pos);
if (sprite != null) sprite.kill();
active = false;
if (sprite != null) sprite.reset( this );
}
private static final String POS = "pos";
private static final String VISIBLE = "visible";
private static final String ACTIVE = "active";
@Override
public void restoreFromBundle( Bundle bundle ) {
pos = bundle.getInt( POS );
visible = bundle.getBoolean( VISIBLE );
if (bundle.contains(ACTIVE)){
active = bundle.getBoolean(ACTIVE);
}
}
@Override
public void storeInBundle( Bundle bundle ) {
bundle.put( POS, pos );
bundle.put( VISIBLE, visible );
bundle.put( ACTIVE, active );
}
public String desc() {

View File

@ -74,7 +74,7 @@ public class TrapSprite extends Image {
revive();
reset( trap.color + (trap.shape * 16) );
reset( (trap.active ? trap.color : BLACK) + (trap.shape * 16) );
alpha( 1f );
pos = trap.pos;

View File

@ -28,7 +28,9 @@ public class WndInfoTrap extends WndTitledMessage {
public WndInfoTrap(Trap trap) {
super(new TrapSprite( trap.color + (trap.shape * 16) ), trap.name, trap.desc());
super(new TrapSprite( trap.color + (trap.shape * 16) ),
(!trap.active ? "Inactive " : "") + trap.name,
(!trap.active ? "This trap is inactive, and can no longer be triggered.\n\n" : "") + trap.desc());
}