Doodads now affect the passability of terrain.
This commit is contained in:
@@ -19,6 +19,11 @@ class GameMap(val width: Int, val height: Int, val tileset: Tileset) {
|
||||
|
||||
def tileInfo(index: Int) = tileset.infoOf(tiles(index))
|
||||
def tileInfo(pos: Position) = tileset.infoOf(this(pos))
|
||||
def compositeInfo(pos: Position) = {
|
||||
val gi = tileset.infoOf(this(pos))
|
||||
val di = tileset.infoOf(doodad(pos))
|
||||
if (di.doesOverwrite) di else gi
|
||||
}
|
||||
|
||||
def saveTo(file: File): Unit = {
|
||||
val ostream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)))
|
||||
@@ -59,7 +64,8 @@ class GameMap(val width: Int, val height: Int, val tileset: Tileset) {
|
||||
tiles(index).build(dirs.toSet).croppedImage()
|
||||
}
|
||||
|
||||
def pt2index(x: Int, y: Int) = y * width + x
|
||||
def pt2index(x: Int, y: Int): Int = y * width + x
|
||||
def pt2index(pos: Position): Int = pt2index(pos.x, pos.y)
|
||||
def index2x(i: Int) = i % width
|
||||
def index2y(i: Int) = i / width
|
||||
|
||||
|
||||
@@ -12,13 +12,31 @@ class Tileset(val groundTiles: IndexedSeq[AutoTile], val doodadTiles: IndexedSeq
|
||||
val infoOf = (groundTiles.zipWithIndex.map{case (t, i) => (t, groundInfo(i))} ++ doodadTiles.zipWithIndex.map{case (t, i) => (t, doodadInfo(i))}).toMap
|
||||
}
|
||||
|
||||
case class TileInfo(
|
||||
val doesPassNorth: Boolean,
|
||||
val doesPassEast: Boolean,
|
||||
val doesPassSouth: Boolean,
|
||||
val doesPassWest: Boolean,
|
||||
val isCounter: Boolean) {
|
||||
case class TileInfo(val flags: Int = TileInfo.PassAll) {
|
||||
def doesPassNorth = (flags & TileInfo.PassNorth) != 0
|
||||
def doesPassEast = (flags & TileInfo.PassEast) != 0
|
||||
def doesPassSouth = (flags & TileInfo.PassSouth) != 0
|
||||
def doesPassWest = (flags & TileInfo.PassWest) != 0
|
||||
|
||||
def doesOverwrite = (flags & TileInfo.Overwrite) != 0
|
||||
|
||||
def isCounter = (flags & TileInfo.IsCounter) != 0
|
||||
}
|
||||
|
||||
|
||||
object TileInfo {
|
||||
val PassNorth = 0x0001
|
||||
val PassEast = 0x0002
|
||||
val PassSouth = 0x0004
|
||||
val PassWest = 0x0008
|
||||
val PassAll = PassNorth | PassEast | PassSouth | PassWest
|
||||
val NoPass = 0
|
||||
|
||||
val Overwrite = 0x0010
|
||||
val Underfoot = 0x0020
|
||||
val Overhead = 0x0040
|
||||
|
||||
val IsCounter = 0x0100
|
||||
}
|
||||
|
||||
case class TilesetToken(
|
||||
|
||||
@@ -124,7 +124,7 @@ class GameView {
|
||||
if (hero.pose != dir.toString()) {
|
||||
hero.pose = dir.toString()
|
||||
} else {
|
||||
val info = level.tileInfo(hero.pos + dir)
|
||||
val info = level.compositeInfo(hero.pos + dir)
|
||||
val canPass = (dir.x < 0 && info.doesPassEast) || (dir.x > 0 && info.doesPassWest) ||
|
||||
(dir.y < 0 && info.doesPassSouth) || (dir.y > 0 && info.doesPassNorth)
|
||||
if (canPass) {
|
||||
|
||||
Reference in New Issue
Block a user