Advertisement
Brandan

Map Class

Mar 11th, 2014
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.62 KB | None | 0 0
  1. Public Class map
  2.     Public Structure Points
  3.         Public ID As Integer
  4.         Public X As Integer
  5.         Public Y As Integer
  6.         Public height As Short
  7.     End Structure
  8.  
  9.     Public Structure Objects
  10.         Public ID As Integer
  11.         Public X As Integer
  12.         Public Y As Integer
  13.         Public height As Short
  14.     End Structure
  15.  
  16.     Public Structure NoAccessBlocks
  17.         Public ID As Integer
  18.         Public X As Integer
  19.         Public Y As Integer
  20.         Public disabled As Integer
  21.     End Structure
  22.  
  23.     Public Structure SunLightBlocks
  24.         Public ID As Integer
  25.         Public X As Integer
  26.         Public Y As Integer
  27.         Public disabled As Integer
  28.     End Structure
  29.  
  30.     Public Structure SavePlayerInfo
  31.         Public ID As Integer
  32.         Public X As Integer
  33.         Public Y As Integer
  34.         Public tribe As Populous.Populous.tribe
  35.     End Structure
  36.  
  37.     Private MapSize As Size = New Size(128, 128)
  38.     Public Map_Loaded(MapSize.Height * MapSize.Width) As Points
  39.     Public NoAccess(MapSize.Height * MapSize.Width) As NoAccessBlocks
  40.     Public SunLight(MapSize.Height * MapSize.Width) As SunLightBlocks
  41.     Public SavePlayer(64) As SavePlayerInfo
  42.     Public Obj(2000 - 1) As Objects
  43.  
  44.     Public Enum MapType
  45.         DAT
  46.         XML
  47.         CSV
  48.         BITMAP
  49.     End Enum
  50.  
  51.     Public Sub Load(ByVal filepath As String, ByVal filetypep As MapType)
  52.  
  53.         If filetypep = MapType.DAT Then
  54.             Dim reader As New BinaryReader(File.Open(filepath, FileMode.Open))
  55.  
  56.             Dim Point = 0
  57.             For x As Integer = 0 To MapSize.Height - 1
  58.                 For y As Integer = 0 To MapSize.Width - 1
  59.  
  60.                     ' Load height UShort is unsigned Word, and Short is signed word
  61.                     Dim Height As Short = reader.ReadUInt16()
  62.  
  63.  
  64.                     If Point > 0 Then
  65.                         Map_Loaded(Point).ID = Point + 1
  66.                     End If
  67.                     Map_Loaded(Point).X = x
  68.                     Map_Loaded(Point).Y = y
  69.                     Map_Loaded(Point).height = Height
  70.  
  71.                     Point = Point + 1
  72.                 Next
  73.             Next
  74.             GenHeightMap()
  75.             reader.Close()
  76.  
  77.         ElseIf filetypep = MapType.XML Then
  78.  
  79.         ElseIf filetypep = MapType.CSV Then
  80.  
  81.         ElseIf filetypep = MapType.BITMAP Then
  82.  
  83.         End If
  84.  
  85.     End Sub
  86.  
  87.     Public Function GenHeightMap() As Bitmap
  88.         Dim HeightMap As New Bitmap(128, 128)
  89.  
  90.         For Each Point In Map_Loaded
  91.             HeightMap.SetPixel(Point.X, Point.Y, Color.FromArgb(Point.height / 4, Point.height / 4, Point.height / 4))
  92.         Next
  93.  
  94.         OpenGL_Render.PictureBox1.Image = HeightMap
  95.         Return Nothing
  96.     End Function
  97.  
  98.     Public Sub Save(ByVal filepath As String, ByVal filetypep As MapType)
  99.  
  100.         If filetypep = MapType.DAT Then
  101.  
  102.             If Not My.Computer.FileSystem.FileExists(filepath) Then
  103.                 File.Create(filepath).Dispose()
  104.             End If
  105.  
  106.             Dim writer As New BinaryWriter(File.Open(filepath, FileMode.Open))
  107.  
  108.             For x As Integer = 0 To MapSize.Width - 1
  109.                 For y As Integer = 0 To MapSize.Height - 1
  110.  
  111.                     For Point = 0 To Map_Loaded.Length - 1
  112.                         If (Map_Loaded(Point).X = x And Map_Loaded(Point).Y = y) Then
  113.                             writer.Write(Map_Loaded(Point).height)
  114.                             Exit For
  115.                         End If
  116.                     Next
  117.  
  118.  
  119.                 Next
  120.             Next
  121.  
  122.             ' Unused Data, 0 byte it
  123.             Do Until (writer.BaseStream.Position >= 65535)
  124.                 writer.Write(0)
  125.             Loop
  126.  
  127.             ' No Access Blocks 1 = No Access 0 = Free Roam
  128.             Do Until (writer.BaseStream.Position >= 81983)
  129.                 writer.Write(0)
  130.             Loop
  131.  
  132.             ' Save Player Info
  133.             Do Until (writer.BaseStream.Position >= 81919)
  134.                 writer.Write(0)
  135.             Loop
  136.  
  137.             ' Sunlight Info
  138.             Do Until (writer.BaseStream.Position >= 81986)
  139.                 writer.Write(0)
  140.             Loop
  141.  
  142.             ' Objects
  143.             Do Until (writer.BaseStream.Position >= 191986)
  144.                 writer.Write(0)
  145.             Loop
  146.  
  147.             ' End Padding
  148.             Do Until (writer.BaseStream.Position >= 192136)
  149.                 writer.Write(0)
  150.             Loop
  151.  
  152.  
  153.             writer.Close()
  154.         ElseIf filetypep = MapType.XML Then
  155.  
  156.         ElseIf filetypep = MapType.CSV Then
  157.  
  158.         ElseIf filetypep = MapType.BITMAP Then
  159.  
  160.         End If
  161.  
  162.     End Sub
  163.  
  164.  
  165. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement