Hi -
I came across a path finding example and got it implanted into my project and I think that part is working. It finds the path, (column/row ) to the player object . That part I haven’t been able to figure is how to get how to get the enemy to actually follow the path.
I’ve tried using the values from lastNode.mCol and lastNode.mRow in FoundSolution but haven’t been able to get it to work right.
I think I’m close but can’t get my head wrapped around the coding for this.
So in the canvas paint event I have (yeah some of the code is old )
if enemy.Ubound > 0 then // right now just 1 enemy.
UpdateEnemy(g)
end if
now in updateEnemy(g)
dim hitPlayer as Boolean
dim i as Integer
for i = 1 to Enemy.Ubound
hitPlayer = Enemy(i).hitPlayer(HeroObject)
if hitPlayer then
pixeldeath.Play
PlayerDied = true
Return
end if
Enemy(i).DoOneSearchStep(HeroObject) // start path finding. This is part of the path finding example.
// ***************** Dumb AI **************************
// bad guys are really dumb, just wonder around aimlessly... not using path finding here yet.
if Enemy(i).PathCheck(enemy(1)) then
Enemy(i).Move
else
Enemy(i).PickNewDirection
end if
// *******************************************************
Enemy(i).DirectionCheck // check for correct directional picture are used for animation.
Enemy(i).Draw(g)
As part of the enemy class the path finding is part of it and when a solution is found it calls
FoundSolution(node)
FoundSolution(node As GridSearchNode)
Dim node, lastNode As GridSearchNode
Dim cw, ch As Integer // cell width/height
cw =32
ch = 32
//enemy x,y
'x=
'y=
lastNode = endNode
while lastNode.mParent <> nil
node = lastNode.mParent
'g.DrawLine node.mCol*cw+cw\2, node.mRow*ch+ch\2, lastNode.mCol*cw+cw\2, lastNode.mRow*ch+ch\2 // left over from example.
lastNode = node
app.DoEvents
wend
Thanks.