v2.2.0: the ghost now wanders again, but only within the exit room

This commit is contained in:
Evan Debenham
2023-07-23 15:52:20 -04:00
parent b90bd6c735
commit 97b8edd4d6

View File

@@ -51,7 +51,6 @@ import com.watabou.noosa.Game;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
import com.watabou.utils.Callback; import com.watabou.utils.Callback;
import com.watabou.utils.Point;
import com.watabou.utils.Random; import com.watabou.utils.Random;
public class Ghost extends NPC { public class Ghost extends NPC {
@@ -60,8 +59,11 @@ public class Ghost extends NPC {
spriteClass = GhostSprite.class; spriteClass = GhostSprite.class;
flying = true; flying = true;
state = PASSIVE; state = WANDERING;
//not actually large of course, but this makes the ghost stick to the exit room
properties.add(Property.LARGE);
} }
@Override @Override
@@ -272,31 +274,9 @@ public class Ghost extends NPC {
if (!spawned && Dungeon.depth > 1 && Random.Int( 5 - Dungeon.depth ) == 0) { if (!spawned && Dungeon.depth > 1 && Random.Int( 5 - Dungeon.depth ) == 0) {
Ghost ghost = new Ghost(); Ghost ghost = new Ghost();
boolean validPos;
//spawn along the border, but not on the exit, a trap, or in front of a door
do { do {
validPos = true; ghost.pos = level.pointToCell(room.random());
Point point = new Point(); } while (ghost.pos == -1 || ghost.pos == level.exit());
if (Random.Int(2) == 0) {
point.x = Random.Int(2) == 0 ? room.left+1 : room.right-1;
point.y = Random.IntRange(room.top+1, room.bottom-1);
} else {
point.x = Random.IntRange(room.left+1, room.right-1);
point.y = Random.Int(2) == 0 ? room.top+1 : room.bottom-1;
}
ghost.pos = level.pointToCell(point);
if (ghost.pos == level.exit()){
validPos = false;
}
for (Point door : room.connected.values()){
if (level.trueDistance( ghost.pos, level.pointToCell( door ) ) <= 1){
validPos = false;
}
}
if (level.traps.get(ghost.pos) != null){
validPos = false;
}
} while (!validPos);
level.mobs.add( ghost ); level.mobs.add( ghost );
spawned = true; spawned = true;