Advertisement
VBTyp

2D Trace

Jan 14th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.63 KB | None | 0 0
  1. Function checkTrace(ByVal enemiePosition As Point, ByVal playerPosition As Point, ByVal playerYaw As Single, ByRef fraction As Single) As Boolean
  2.         For radius As Integer = 0 To 50
  3.             Dim punkt As Point = RotatePoint(playerPosition, New Point(playerPosition.X, playerPosition.Y - radius), playerYaw + 180)
  4.             If (enemiePosition.X = punkt.X) And (enemiePosition.Y = punkt.Y) Then
  5.                 Return True
  6.             End If
  7.             For Each building In buildings
  8.                 If (building.x = punkt.X) Or (building.x + building.width = punkt.X) Or (building.x < punkt.X And building.x + building.width <= punkt.X) Then
  9.                     If (building.y = punkt.Y) Or (building.y + building.height = punkt.Y) Or (building.y < punkt.Y And building.y + building.height <= punkt.Y) Then
  10.                         fraction -= building.fraction
  11.                         If fraction <= 0 Then
  12.                             Return False
  13.                         Else
  14.                             Continue For
  15.                         End If
  16.                     End If
  17.                 End If
  18.             Next
  19.         Next
  20.         Return False
  21.     End Function
  22.     Shared Function RotatePoint(ByVal Point1 As Point, ByVal Point2 As Point, ByVal Rotation As Integer) As Point
  23.         Dim LineLenght As Integer = CInt(Math.Sqrt((Point1.X - Point2.X) * (Point1.X - Point2.X) + (Point1.Y - Point2.Y) * (Point1.Y - Point2.Y)))
  24.         Point2.X = CInt(Math.Sin(Rotation * (Math.PI / 180)) * LineLenght + Point1.X)
  25.         Point2.Y = CInt(Math.Cos(Rotation * (Math.PI / 180)) * LineLenght + Point1.Y)
  26.         Return Point2
  27.     End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement