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; 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.Camera;
import com.watabou.noosa.Scene; import com.watabou.noosa.Scene;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
@ -120,19 +122,13 @@ public class CavesBossLevel extends Level {
map[exit] = Terrain.LOCKED_EXIT; 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, Painter.fill( this, ROOM_LEFT - 1, ROOM_TOP - 1,
ROOM_RIGHT - ROOM_LEFT + 3, ROOM_BOTTOM - ROOM_TOP + 3, Terrain.WALL ); ROOM_RIGHT - ROOM_LEFT + 3, ROOM_BOTTOM - ROOM_TOP + 3, Terrain.WALL );
Painter.fill( this, ROOM_LEFT, ROOM_TOP + 1, Painter.fill( this, ROOM_LEFT, ROOM_TOP + 1,
ROOM_RIGHT - ROOM_LEFT + 1, ROOM_BOTTOM - ROOM_TOP, Terrain.EMPTY ); ROOM_RIGHT - ROOM_LEFT + 1, ROOM_BOTTOM - ROOM_TOP, Terrain.EMPTY );
Painter.fill( this, ROOM_LEFT, ROOM_TOP, 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; arenaDoor = Random.Int( ROOM_LEFT, ROOM_RIGHT ) + (ROOM_BOTTOM + 1) * WIDTH;
map[arenaDoor] = Terrain.DOOR; 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; return true;
} }

View File

@ -345,6 +345,18 @@ public abstract class Level implements Bundlable {
traps.put( trap.pos, trap ); 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 ); collection = bundle.getCollection( MOBS );
for (Bundlable m : collection) { for (Bundlable m : collection) {
Mob mob = (Mob)m; Mob mob = (Mob)m;
@ -638,7 +650,7 @@ public abstract class Level implements Bundlable {
public static void set( int cell, int terrain ) { public static void set( int cell, int terrain ) {
Painter.set( Dungeon.level, cell, 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 ); 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. //effectively nullifies whatever the logic calling this wants to do, including dropping items.
Heap heap = new Heap(); Heap heap = new Heap();
ItemSprite sprite = heap.sprite = new ItemSprite(); ItemSprite sprite = heap.sprite = new ItemSprite();
sprite.link( heap ); sprite.link(heap);
return heap; return heap;
} }
@ -707,7 +719,7 @@ public abstract class Level implements Bundlable {
return drop( item, n ); return drop( item, n );
} }
heap.drop( item ); heap.drop(item);
if (Dungeon.level != null) { if (Dungeon.level != null) {
press( cell, null ); press( cell, null );
@ -741,10 +753,15 @@ public abstract class Level implements Bundlable {
} }
public void uproot( int pos ) { public void uproot( int pos ) {
plants.delete( pos ); plants.delete(pos);
} }
public Trap setTrap( Trap trap, int 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 ); trap.set( pos );
traps.put( pos, trap ); traps.put( pos, trap );
GameScene.add(trap); GameScene.add(trap);
@ -752,7 +769,6 @@ public abstract class Level implements Bundlable {
} }
public void disarmTrap( int pos ) { public void disarmTrap( int pos ) {
traps.delete(pos);
set(pos, Terrain.INACTIVE_TRAP); set(pos, Terrain.INACTIVE_TRAP);
GameScene.updateMap(pos); 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.Room.Type;
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter; import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.PoisonTrap; import com.shatteredpixel.shatteredpixeldungeon.levels.traps.PoisonTrap;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.watabou.noosa.Scene; import com.watabou.noosa.Scene;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
@ -271,6 +272,14 @@ public class PrisonBossLevel extends RegularLevel {
roomExit.width() - 3, roomExit.width() - 3,
roomExit.height() - 3, roomExit.height() - 3,
Terrain.INACTIVE_TRAP ); 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 @Override

View File

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

View File

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

View File

@ -28,7 +28,9 @@ public class WndInfoTrap extends WndTitledMessage {
public WndInfoTrap(Trap trap) { 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());
} }