From 801b50bf16a3f3eb236cf52d6da0981f391af9d9 Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Sun, 22 Jun 2014 13:26:29 -0700 Subject: [PATCH] Pathfind AROUND AISprites instead of through them --- moonlight/src/AISprite.js | 2 +- moonlight/src/Util.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/moonlight/src/AISprite.js b/moonlight/src/AISprite.js index a2fae35..e2fb9bf 100644 --- a/moonlight/src/AISprite.js +++ b/moonlight/src/AISprite.js @@ -244,7 +244,7 @@ var AISprite = function(game, x, y, key, frame) { parseInt(this.y/32), pos[0], pos[1], - pathfinder_grid.clone() + gridWithAISprites() ); prevpoint = [this.x, this.y]; console.log("New path has at most " + maxsteps + " steps in it"); diff --git a/moonlight/src/Util.js b/moonlight/src/Util.js index 151ad96..d4b2923 100644 --- a/moonlight/src/Util.js +++ b/moonlight/src/Util.js @@ -247,3 +247,18 @@ function setSpriteMovement(spr, velocity) } } +function genericGridClone() +{ + return pathfinder_grid.clone(); +} + +function gridWithAISprites() +{ + var grid = pathfinder_grid.clone(); + var aiSprites = game.state.states.game.aiSprites; + for ( var i = 0 ; i < aiSprites.length ; i++ ) { + var spr = aiSprites.getChildAt(i); + grid.nodes[parseInt(spr.y/32)][parseInt(spr.x/32)].walkable = false; + } + return grid; +}