How to use the rot-js.Path function in rot-js

To help you get started, we’ve selected a few rot-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Larkenx / Rotten-Soup / src / assets / js / game / utils / PlayerController.js View on Github external
setTimeout(() => {
			Game.engine.unlock()
			let ladder = Game.getNearestLadder()
			let levelTransition = Game.getNearestLevelTransition()
			if (ladder !== null && ladder.direction !== 'up') {
				let ladderPath = new ROT.Path.AStar(ladder.x, ladder.y, pathfinding)
				let pathToLadder = []
				ladderPath.compute(Game.player.x, Game.player.y, (x, y) => {
					pathToLadder.push([x, y])
				})
				if (pathToLadder.length > 1) {
					let newPos = pathToLadder[1] // 1 past the current position
					Game.player.commandQueue.push({
						fn: () => {
							Game.player.tryMove(newPos[0], newPos[1])
						}
					})
				} else {
					Game.player.commandQueue.push({
						fn: () => Game.player.climb()
					})
				}
github Larkenx / Rotten-Soup / src / assets / js / game / utils / dialogues / NaniAndBiliRescue.js View on Github external
const moveDwarves = () => {
				const pathfinding = (x, y) => {
					return Game.inbounds(x, y) && !Game.getTile(x, y).blocked()
				}
				let portalToTown = levelTransition[0]
				let pathToExit = new ROT.Path.AStar(portalToTown.x, portalToTown.y, pathfinding)
				const recomputePath = () => {
					pathToExit = new ROT.Path.AStar(portalToTown.x, portalToTown.y, pathfinding)
				}
				let [d1, d2] = dwarves
				// if (!removedSpritesAbove) {
				// 	d1.removeSpriteAbove()
				// 	d2.removeSpriteAbove()
				// 	removedSpritesAbove = true
				// }
				let d1Path = []
				let d2Path = []
				pathToExit.compute(d1.x, d1.y, (x, y) => {
					d1Path.push([x, y])
				})
				pathToExit.compute(d2.x, d2.y, (x, y) => {
					d2Path.push([x, y])
github Larkenx / Rotten-Soup / src / assets / js / game / entities / actors / Player.js View on Github external
recalculatePath() {
		this.path = new ROT.Path.AStar(this.x, this.y, pathfinding)
	}
github Larkenx / Rotten-Soup / src / assets / js / game / utils / HelperFunctions.js View on Github external
export function createFovDijkstraMap(start, notVisibleTiles, blockedPredicate = outOfBoundsOrBlockedByAnything) {
	const reachable = floodFill(start)
	let dijkstraMap = new ROT.Path.Dijkstra(start.x, start.y, (x, y) => !blockedPredicate(x, y) && reachable[key(x, y)])
	let distanceTransform = {}
	for (let { x, y } of notVisibleTiles) {
		let coord = key(x, y)
		distanceTransform[coord] = 0
		let steps = []
		dijkstraMap.compute(x, y, (sx, sy) => {
			steps.push({ x: sx, y: sy })
		})
		let distance = 0
		for (let step of steps) {
			distance += 1
			let stepKey = key(step.x, step.y)
			if (stepKey in distanceTransform && distance > distanceTransform[stepKey]) {
				distance = distanceTransform[stepKey]
			}
			distanceTransform[stepKey] = distance
github Larkenx / Rotten-Soup / src / assets / js / game / utils / dialogues / NaniAndBiliRescue.js View on Github external
const recomputePath = () => {
					pathToExit = new ROT.Path.AStar(portalToTown.x, portalToTown.y, pathfinding)
				}
				let [d1, d2] = dwarves
github Larkenx / Rotten-Soup / src / assets / js / game / utils / Goals.js View on Github external
return actor => {
		let target = data.entity
		let stopCondition = data.stopCondition ? data.stopCondition : (...args) => false
		if (stopCondition(data)) return
		let configuredPathfinding = configurablePathfinding({
			excludeOrigin: true,
			origin: { x: actor.x, y: actor.y },
			excludeTarget: true,
			target
		})
		let path = new ROT.Path.AStar(target.x, target.y, configuredPathfinding)
		let steps = []
		path.compute(actor.x, actor.y, (x, y) => {
			if (actor.x !== x || actor.y !== y) steps.push({ x, y })
		})
		if (steps.length >= 1) {
			let { x, y } = steps[0]
			actor.tryMove(x, y)
			if (data.finalAction) data.finalAction()
		}
		if (steps.length > 1) {
			actor.addGoal(AStarPathingGoal(data))
		}
	}
}
github seiyria / Roguathia / src / js / rogue / definitions / player.js View on Github external
rebuildPathingMap(targetX = this.x, targetY = this.y) {
    const canPass = (x, y) => {
      const entity = GameState.world.getEntity(x, y, this.z);
      const isAttackable = entity && this.canAttack(entity);
      const isMe = this.x === x && this.y === y;
      const isPlayer = entity && entity.constructor.name === 'Player';
      return GameState.world.isTilePassable(x, y, this.z) || isPlayer || isMe || isAttackable;
    };
    
    return new ROT.Path.Dijkstra(targetX, targetY, canPass, { topology: 8 });
  }
github seiyria / Roguathia / src / js / rogue / definitions / attack.js View on Github external
animate(owner, target, callback) {
    if(!this.glyph) return callback();

    const engine = GameState.game.engine;
    engine.lock();

    const canPass = (x, y) => {
      const entity = GameState.world.getEntity(x, y, owner.z);
      const isAttackable = entity && owner.canAttack(entity);
      const isMe = owner.x === x && owner.y === y;
      return GameState.world.isTilePassable(x, y, owner.z, false) || isMe || isAttackable;
    };
    const astar = new ROT.Path.AStar(target.x, target.y, canPass, { topology: 8 });

    let path = [];
    const pathCallback = function(x, y) {
      path.push({ x, y });
    };
    
    astar.compute(owner.x, owner.y, pathCallback);

    path.shift();

    if(!path.length) path = [{ x: owner.x, y: owner.y }];

    const projectile = new Projectile(this.glyph);

    projectile.z = owner.z;
    projectile.x = path[0].x;
github seiyria / Roguathia / src / js / rogue / definitions / character.js View on Github external
getAlternatePathTo(target) {
    const canPass = (x, y) => {
      const entity = GameState.world.getEntity(x, y, this.z);
      const isAttackable = entity && this.canAttack(entity);
      const isMe = this.x === x && this.y === y;
      return GameState.world.isTilePassable(x, y, this.z) || isMe || isAttackable;
    };
    const astar = new ROT.Path.AStar(target.x, target.y, canPass);

    const path = [];
    astar.compute(this.x, this.y, (x, y) => path.push({ x, y }));

    path.shift();
    const step = path.shift();
    if(!step) return null;
    return path;
  }