Time for action – enemy AI methods
Add movement-related methods to the
Enemy
class:#Region "AI Methods" Private Function determineMoveDirection() As Vector2 If reachedTargetSquare() Then CurrentTargetSquare = getNewTargetSquare() End If Dim squareCenter As Vector2 = TileMap.GetSquareCenter( currentTargetSquare) Return squareCenter - EnemyBase.WorldCenter End Function Private Function reachedTargetSquare() As Boolean Return Vector2.Distance(EnemyBase.WorldCenter, TileMap.GetSquareCenter(currentTargetSquare)) <= 2 End Function Private Function getNewTargetSquare() As Vector2 Dim path As List(Of Vector2) = PathFinder.FindPath( TileMap.GetSquareAtPixel(EnemyBase.WorldCenter), TileMap.GetSquareAtPixel(Player.BaseSprite.WorldCenter)) If path.Count > 1 Then Return New Vector2(path(1).X, path(1).Y) Else Return TileMap.GetSquareAtPixel( Player.BaseSprite.WorldCenter) End If End Function...