Click here to Skip to main content
15,891,687 members
Articles / Game Development

FirstWins Pathfinding Algorithm

Rate me:
Please Sign up or sign in to vote.
4.95/5 (16 votes)
7 Feb 2017CPOL4 min read 40.8K   1.5K   45  
Pathfinding algorithm based on a direction priority
Public Class WorldBrush

    Private intStartPosF As Integer
    Private intEndPosF As Integer

    REM: Filling the playground with impassable or passable areas:
    Sub Fill(ptrPoint As Point, intFill As Integer)
        Try
            If OutOfField(ptrPoint) <> True Then
                intStartPosF = ptrPoint.X + intStartNum(ptrPoint.Y)
                intEndPosF = (ptrPoint.X + 39) + intStartNum(ptrPoint.Y)

                For i = 0 To 40
                    For i2 = intStartPosF To intEndPosF
                        intWorldArr(i2) = intFill
                    Next
                    intStartPosF += szeWorldSize.Width
                    intEndPosF += szeWorldSize.Width
                Next
            End If
        Catch ex As Exception
        End Try
    End Sub

    Private Function OutOfField(ptrPoint As Point) As Boolean
        Dim booReturn As Boolean = False
        If ptrPoint.X < 5 Then Return True
        If ptrPoint.Y < 5 Then Return True
        If ptrPoint.X > (szeWorldSize.Width - 5) Then Return True
        If ptrPoint.Y > (szeWorldSize.Height - 5) Then Return True
        Return booReturn
    End Function

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Bulgaria Bulgaria
Name: Ognian Gantchev Ivanov

Current Age: 27

Country: Bulgaria

City: Stara Zagora

Professional skills: fine arts, sculpture

Hobbies: Programming();

Computer Languages: VB, C#, C++

Human Languages: Bulgarian, English

About me:
I'm an enthusiast game developer. I love computers, art and science.

Comments and Discussions