Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions chapter-4/example-2-first-monster/monster.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default class BasicMonster {
this.x = x
this.y = y
this.tile = 26
this.moving = false
dungeon.initializeEntity(this)
}

Expand All @@ -17,7 +18,7 @@ export default class BasicMonster {
let oldX = this.x
let oldY = this.y

if (this.movementPoints > 0) {
if (this.movementPoints > 0 && !this.moving) {
// https://github.com/qiao/PathFinding.js
let pX = dungeon.player.x
let pY = dungeon.player.y
Expand All @@ -36,4 +37,4 @@ export default class BasicMonster {
over() {
return this.movementPoints == 0 && !this.moving
}
}
}
5 changes: 3 additions & 2 deletions chapter-4/example-3-basic-combat/monster.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class BasicMonster {
this.x = x
this.y = y
this.tile = 26
this.moving = false
dungeon.initializeEntity(this)
}

Expand All @@ -32,7 +33,7 @@ export default class BasicMonster {
let finder = new PF.AStarFinder()
let path = finder.findPath(oldX, oldY, pX, pY, grid)

if (this.movementPoints > 0) {
if (this.movementPoints > 0 && !this.moving) {
if (path.length > 2) {
dungeon.moveEntityTo(this, path[1][0], path[1][1])
}
Expand All @@ -56,4 +57,4 @@ export default class BasicMonster {
onDestroy() {
console.log(`${this.name} was killed`)
}
}
}