Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
updateFOV() {
if (!Game.map.revealed) {
Object.assign(Game.map.seen_tiles, Game.map.visible_tiles)
Game.map.visible_tiles = {}
// FOV calculations
let fov = new ROT.FOV.PreciseShadowcasting((x, y) => {
return Game.inbounds(x, y) && Game.getTile(x, y).visible()
})
fov.compute(Game.player.x, Game.player.y, Game.player.cb.range, (x, y, r, visibility) => {
Game.map.visible_tiles[x + ',' + y] = true
})
for (let y = 0; y < Game.map.height; y++) {
for (let x = 0; x < Game.map.width; x++) {
if (Game.map.visible_tiles[x + ',' + y]) {
this.spriteBox[y][x].visible = false
} else {
// tile is not directly visible
this.spriteBox[y][x].visible = true
if (Game.map.seen_tiles[x + ',' + y]) {
let maxLightingFallOffDistance = Game.player.cb.range + 4
// we can do some special transparency to make tiles closest to visible tiles brighter, giving some illusion of
setupFOV() {
for(let z = 0; z < this.depth; z++) {
this.fov[z] = new ROT.FOV.RecursiveShadowcasting(
(x, y) => {
return !this.getTile(x, y, z).isBlockingLight();
}
);
}
}
// endregion
act() {
super.act()
this.recalculatePath()
this.nearbyEnemies = Game.getNearbyEnemies()
this.currentLevel = Game.currentLevel
Game.engine.lock()
this.cb.turnsTaken++
if (this.cb.turnsTaken % 5 === 0) this.heal(this.cb.hpRecovery)
if (this.cb.turnsTaken % 10 === 0) this.restore(this.cb.manaRecovery)
// updating our vision with the most up to date information
Object.assign(Game.map.seen_tiles, Game.map.visible_tiles)
Game.map.visible_tiles = {}
// FOV calculations
let fov = new ROT.FOV.RecursiveShadowcasting((x, y) => {
return Game.inbounds(x, y) && Game.getTile(x, y).visible()
})
if (Game.map.revealed) this.seenTiles = Game.map.getTiles()
let visibleTiles = getVisibleTiles(this)
for (let t of visibleTiles) {
if (!this.seenTiles.includes(t)) {
this.seenTiles.push(t)
}
}
fov.compute(Game.player.x, Game.player.y, Game.player.cb.range, (x, y, r, visibility) => {
Game.map.visible_tiles[x + ',' + y] = true
})
if (this.commandQueue.length > 0) {
this.player.cb.dungeonsExplored++
}
// before drawing the viewport, we need to clear the screen of whatever was here last
this.display.clear()
this.width = this.map.width < this.displayOptions.width ? this.map.width : this.displayOptions.width
this.height = this.map.height < this.displayOptions.height ? this.map.height : this.displayOptions.height
this.minimapOptions.width = this.map.width < this.minimapOptions.width ? this.map.width : this.minimapOptions.width
this.minimapOptions.height = this.map.height < this.minimapOptions.height ? this.map.height : this.minimapOptions.height
this.player.placeAt(this.playerLocation[0], this.playerLocation[1])
this.scheduleAllActors()
// Clear the last visible tiles that were available to be seen
Object.assign(this.map.seen_tiles, this.map.visible_tiles)
this.map.visible_tiles = {}
// FOV calculations
let fov = new ROT.FOV.PreciseShadowcasting((x, y) => {
return this.inbounds(x, y) && this.getTile(x, y).visible()
})
fov.compute(this.player.x, this.player.y, this.player.cb.range, (x, y, r, visibility) => {
this.map.visible_tiles[x + ',' + y] = true
})
this.minimap.setOptions(this.minimapOptions)
this.minimap.clear()
this.drawMiniMap()
this.renderMap()
},
export const getNearbyCorpses = actor => {
let fov = new ROT.FOV.PreciseShadowcasting(function(x, y) {
return Game.inbounds(x, y) && Game.map.data[y][x].visible()
})
let visibleTiles = []
fov.compute(actor.x, actor.y, actor.cb.range, function(x, y, r, visibility) {
if (Game.inbounds(x, y)) visibleTiles.push(Game.map.data[y][x])
})
let cartOfCorpses = []
for (let tile of visibleTiles) {
let corpses = tile.actors.filter(e => {
return e instanceof Corpse
})
if (corpses.length > 0) cartOfCorpses.push(corpses[0])
}
return cartOfCorpses
export function getVisibleTiles(actor, map = Game.map) {
let { x, y } = actor
let { range } = actor.cb
let fov = new ROT.FOV.RecursiveShadowcasting((x, y) => {
return map.inbounds(x, y) && map.getTile(x, y).visible()
})
let visibleTiles = []
fov.compute(x, y, range, (x, y, r, visibility) => {
if (map.inbounds(x, y)) visibleTiles.push(map.getTile(x, y))
})
return visibleTiles
}