KySoto

WorldMap class

Apr 10th, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.88 KB | None | 0 0
  1. Option Explicit On
  2. Option Infer Off
  3. Option Strict On
  4. Imports Project3.main
  5. Public Class WorldMap
  6.     Private _map As Image
  7.     Private _name As String
  8.     Private _movementGrid(23, 23) As Point
  9.     Private _obsticleGrid(23, 23) As Integer
  10.     Private _DestList(23, 23) As globalCordinate
  11.     Private _spritePosition(12) As Point
  12.     Private _counter As Integer = 0
  13.     Public Sub New(ByVal argDestList() As globalCordinate, ByVal argMovementGrid(,) As Point, ByVal argname As String)
  14.         'argdestlist will be a list of global cords that will corospond with 2's in the obsticle grid. if somehow we get errors then they are in the database.
  15.         _name = argname
  16.         _movementGrid = argMovementGrid
  17.  
  18.         Dim count As Integer = 0
  19.         For i As Integer = 0 To 23 Step 1
  20.             For j As Integer = 0 To 23 Step 1
  21.                 If _obsticleGrid(i, j) = 2 Then
  22.                     _DestList(i, j) = argDestList(count)
  23.  
  24.                 End If
  25.             Next
  26.         Next
  27.  
  28.         For i As Integer = 0 To 12 Step 1
  29.             _spritePosition(i) = New Point(-1, -1)
  30.         Next
  31.  
  32.         _map = Image.FromFile("art\maps\" & _name & ".png")
  33.         _obsticleGrid = GetDefaultObsticleGrid()
  34.     End Sub
  35.     Private Function GetDefaultObsticleGrid() As Integer(,)
  36.         Dim CollisionMap As New Bitmap("art\maps\" & _name & "_COLLISION.png")
  37.         Dim obsticlegrid(23, 23) As Integer
  38.         For i As Integer = 0 To 23 Step 1
  39.             For j As Integer = 0 To 23 Step 1
  40.                 If CollisionMap.GetPixel(_movementGrid(i, j).X, _movementGrid(i, j).Y) = Color.FromArgb(237, 28, 36) Then
  41.                     obsticlegrid(i, j) = 1
  42.                 ElseIf CollisionMap.GetPixel(_movementGrid(i, j).X, _movementGrid(i, j).Y) = Color.FromArgb(255, 242, 0) Then
  43.                     obsticlegrid(i, j) = 2
  44.                 ElseIf CollisionMap.GetPixel(_movementGrid(i, j).X, _movementGrid(i, j).Y) = Color.FromArgb(237, 28, 36) Or CollisionMap.GetPixel(_movementGrid(i, j).X, _movementGrid(i, j).Y) = Color.FromArgb(237, 28, 36) Then
  45.                     obsticlegrid(i, j) = 0
  46.                 Else
  47.                     obsticlegrid(i, j) = 0
  48.                 End If
  49.             Next
  50.         Next
  51.         Return obsticlegrid
  52.     End Function
  53.     Public Function AddPlayer(ByVal argPoint As Point) As Boolean
  54.         If _obsticleGrid(argPoint.X, argPoint.Y) = 0 Then
  55.             _spritePosition(0) = _movementGrid(argPoint.X, argPoint.Y)
  56.             Return True
  57.         Else
  58.             Return False
  59.         End If
  60.     End Function
  61.     Public Function AddMob(ByVal argPoint As Point) As Boolean
  62.         If _obsticleGrid(argPoint.X, argPoint.Y) = 0 Then
  63.             _counter += 1
  64.             If _counter <= _spritePosition.GetUpperBound(0) Then
  65.                 _spritePosition(_counter) = _movementGrid(argPoint.X, argPoint.Y)
  66.                 Return True
  67.             Else
  68.                 Return False
  69.             End If
  70.         Else
  71.             Return False
  72.         End If
  73.     End Function
  74.     Public Function getDest(ByVal argPoint As Point, ByRef argDest As globalCordinate) As Boolean
  75.         If Not _DestList(argPoint.X, argPoint.Y) Is Nothing Then
  76.             argDest = _DestList(argPoint.X, argPoint.Y)
  77.             Return True
  78.         Else
  79.             Return False
  80.         End If
  81.     End Function
  82.     Public Function Move(ByVal argDestination As Point, ByVal argSprite As Integer) As Integer ' 0= worked -1=failed 1=battle 2=npc talk 3 = move to new location
  83.         If argSprite >= 0 And argSprite <= _spritePosition.GetUpperBound(0) Then 'proper sprite integer
  84.             If _spritePosition(argSprite).X > -1 And _spritePosition(argSprite).Y > -1 Then 'checks if the sprite is in play or not.
  85.                 If argDestination.X >= 0 And argDestination.Y >= 0 And argDestination.X >= 23 And argDestination.Y >= 23 Then ' checks total bounds
  86.                     If _obsticleGrid(argDestination.X, argDestination.Y) = 0 Then 'clear spot
  87.                         If argSprite = 0 Then
  88.                             _obsticleGrid(argDestination.X, argDestination.Y) = 5 'sets new position to player
  89.                         Else
  90.                             _obsticleGrid(argDestination.X, argDestination.Y) = 4 'sets new position to mob
  91.                         End If
  92.                         _obsticleGrid(_spritePosition(argSprite).X, _spritePosition(argSprite).Y) = 0 'sets old position as clear
  93.                         Return 0
  94.                     ElseIf _obsticleGrid(argDestination.X, argDestination.Y) = 1 Then 'obsticle
  95.                         Return -1
  96.                     ElseIf _obsticleGrid(argDestination.X, argDestination.Y) = 2 Then 'leave the zone
  97.                         If argSprite = 0 Then 'PC check
  98.                             Return 3
  99.                         Else
  100.                             Return -1
  101.                         End If
  102.                     ElseIf _obsticleGrid(argDestination.X, argDestination.Y) = 4 Then 'monster
  103.                         If argSprite > 0 Then
  104.                             Return 1
  105.                         Else
  106.                             Return -1
  107.                         End If
  108.                     ElseIf _obsticleGrid(argDestination.X, argDestination.Y) = 3 Then 'npc
  109.                         If argSprite > 0 Then
  110.                             Return 2
  111.                         Else
  112.                             Return -1
  113.                         End If
  114.                     ElseIf _obsticleGrid(argDestination.X, argDestination.Y) = 5 Then 'player
  115.                         Return 1
  116.                     End If
  117.                     Return -1 'just incase shit goes wrong somehow.
  118.                 Else
  119.                     Return -1
  120.                 End If
  121.             Else
  122.                 Return -1
  123.             End If
  124.         Else
  125.             Return -1
  126.         End If
  127.  
  128.  
  129.     End Function
  130.     Private Sub AnimatePC()
  131.  
  132.     End Sub
  133. End Class
Advertisement
Add Comment
Please, Sign In to add comment