diff --git a/chapter-4/example-2-first-monster/monster.js b/chapter-4/example-2-first-monster/monster.js index ade636d..f5a0868 100644 --- a/chapter-4/example-2-first-monster/monster.js +++ b/chapter-4/example-2-first-monster/monster.js @@ -6,6 +6,7 @@ export default class BasicMonster { this.x = x this.y = y this.tile = 26 + this.moving = false dungeon.initializeEntity(this) } @@ -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 @@ -36,4 +37,4 @@ export default class BasicMonster { over() { return this.movementPoints == 0 && !this.moving } -} \ No newline at end of file +} diff --git a/chapter-4/example-3-basic-combat/monster.js b/chapter-4/example-3-basic-combat/monster.js index 313629d..b4f20d2 100644 --- a/chapter-4/example-3-basic-combat/monster.js +++ b/chapter-4/example-3-basic-combat/monster.js @@ -9,6 +9,7 @@ export default class BasicMonster { this.x = x this.y = y this.tile = 26 + this.moving = false dungeon.initializeEntity(this) } @@ -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]) } @@ -56,4 +57,4 @@ export default class BasicMonster { onDestroy() { console.log(`${this.name} was killed`) } -} \ No newline at end of file +}