⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 path.vb

📁 一个.Net下用VB编写的用于游戏的人工智能引擎
💻 VB
字号:
Public Class _Path
    Private m_WayPoints As New ArrayList
    Private curWaypoint As Integer

    Dim m_bLooped As Boolean                           '



    Public Sub New()
        m_bLooped = False
        curWaypoint = Nothing
    End Sub

    Public Sub New(ByVal NumWaypoints As Integer, ByVal MinX As Double, ByVal MinY As Double, ByVal MaxX As Double, ByVal MaxY As Double, ByVal looped As Boolean)
        CreateRandomPath(NumWaypoints, MinX, MinY, MaxX, MaxY)
        curWaypoint = 0
    End Sub

    Public Function CurrentWaypoint() As Vector2D
        Return m_WayPoints(curWaypoint)
    End Function

    Public Function Finished() As Boolean
        Return curWaypoint < m_WayPoints.Count - 1
    End Function

    Public Sub SetNextWaypoint()
        curWaypoint += 1
        If curWaypoint = m_WayPoints.Count - 1 Then
            If m_bLooped Then
                curWaypoint = 0
            End If
        End If
    End Sub

    Public Function GetPath() As ArrayList
        Return m_WayPoints
    End Function

    Public Sub Clear()
        m_WayPoints.Clear()
    End Sub

    Public Sub LoopOn()
        m_bLooped = True
    End Sub

    Public Sub LoopOff()
        m_bLooped = False
    End Sub

    Public Sub SetPath(ByVal new_path As ArrayList)
        m_WayPoints = new_path
        curWaypoint = 0
    End Sub

    Public Sub SetPath(ByVal path As _Path)
        m_WayPoints = path.GetPath
        curWaypoint = 0
    End Sub

    Public Sub AddWayPoint(ByVal new_point As Vector2D)
        m_WayPoints.Add(new_point)
    End Sub

    Public Function CreateRandomPath(ByVal NumWaypoints As Integer, ByVal MinX As Double, ByVal MinY As Double, ByVal MaxX As Double, ByVal MaxY As Double) As ArrayList
        m_WayPoints.Clear()

        Dim midX As Double = (MaxX + MinX) / 2.0
        Dim midY As Double = (MaxY + MinY) / 2.0

        Dim smaller As Double = Math.Min(midX, midY)

        Dim spacing As Double = Utils.TwoPi / NumWaypoints

        Dim i As Integer
        For i = 0 To NumWaypoints - 1
            Dim RadialDist As Double = Utils.RandInRange(smaller * 0.2F, smaller)

            Dim temp As New Vector2D(RadialDist, 0.0F)

            Transformations.Vec2DRotateAroundOrigin(temp, i * spacing)

            temp.x += midX
            temp.y += midY

            m_WayPoints.Add(temp)

        Next
        curWaypoint = 0

        Return m_WayPoints

    End Function

    Public Sub Render(ByVal g As Graphics)
        Dim p As Pen = Pens.Orange
        Dim i As Integer
        Dim v1, v2 As Vector2D
        v1 = m_WayPoints(0)
        For i = 1 To m_WayPoints.Count - 1
            v2 = m_WayPoints(i)
            g.DrawLine(p, CSng(v1.x), CSng(v1.y), CSng(v2.x), CSng(v2.y))
        Next
        v2 = m_WayPoints(0)

        If (m_bLooped) Then g.DrawLine(p, CSng(v1.x), CSng(v1.y), CSng(v2.x), CSng(v2.y))

    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -