Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class map
- Public Structure Points
- Public ID As Integer
- Public X As Integer
- Public Y As Integer
- Public height As Short
- End Structure
- Public Structure Objects
- Public ID As Integer
- Public X As Integer
- Public Y As Integer
- Public height As Short
- End Structure
- Public Structure NoAccessBlocks
- Public ID As Integer
- Public X As Integer
- Public Y As Integer
- Public disabled As Integer
- End Structure
- Public Structure SunLightBlocks
- Public ID As Integer
- Public X As Integer
- Public Y As Integer
- Public disabled As Integer
- End Structure
- Public Structure SavePlayerInfo
- Public ID As Integer
- Public X As Integer
- Public Y As Integer
- Public tribe As Populous.Populous.tribe
- End Structure
- Private MapSize As Size = New Size(128, 128)
- Public Map_Loaded(MapSize.Height * MapSize.Width) As Points
- Public NoAccess(MapSize.Height * MapSize.Width) As NoAccessBlocks
- Public SunLight(MapSize.Height * MapSize.Width) As SunLightBlocks
- Public SavePlayer(64) As SavePlayerInfo
- Public Obj(2000 - 1) As Objects
- Public Enum MapType
- DAT
- XML
- CSV
- BITMAP
- End Enum
- Public Sub Load(ByVal filepath As String, ByVal filetypep As MapType)
- If filetypep = MapType.DAT Then
- Dim reader As New BinaryReader(File.Open(filepath, FileMode.Open))
- Dim Point = 0
- For x As Integer = 0 To MapSize.Height - 1
- For y As Integer = 0 To MapSize.Width - 1
- ' Load height UShort is unsigned Word, and Short is signed word
- Dim Height As Short = reader.ReadUInt16()
- If Point > 0 Then
- Map_Loaded(Point).ID = Point + 1
- End If
- Map_Loaded(Point).X = x
- Map_Loaded(Point).Y = y
- Map_Loaded(Point).height = Height
- Point = Point + 1
- Next
- Next
- GenHeightMap()
- reader.Close()
- ElseIf filetypep = MapType.XML Then
- ElseIf filetypep = MapType.CSV Then
- ElseIf filetypep = MapType.BITMAP Then
- End If
- End Sub
- Public Function GenHeightMap() As Bitmap
- Dim HeightMap As New Bitmap(128, 128)
- For Each Point In Map_Loaded
- HeightMap.SetPixel(Point.X, Point.Y, Color.FromArgb(Point.height / 4, Point.height / 4, Point.height / 4))
- Next
- OpenGL_Render.PictureBox1.Image = HeightMap
- Return Nothing
- End Function
- Public Sub Save(ByVal filepath As String, ByVal filetypep As MapType)
- If filetypep = MapType.DAT Then
- If Not My.Computer.FileSystem.FileExists(filepath) Then
- File.Create(filepath).Dispose()
- End If
- Dim writer As New BinaryWriter(File.Open(filepath, FileMode.Open))
- For x As Integer = 0 To MapSize.Width - 1
- For y As Integer = 0 To MapSize.Height - 1
- For Point = 0 To Map_Loaded.Length - 1
- If (Map_Loaded(Point).X = x And Map_Loaded(Point).Y = y) Then
- writer.Write(Map_Loaded(Point).height)
- Exit For
- End If
- Next
- Next
- Next
- ' Unused Data, 0 byte it
- Do Until (writer.BaseStream.Position >= 65535)
- writer.Write(0)
- Loop
- ' No Access Blocks 1 = No Access 0 = Free Roam
- Do Until (writer.BaseStream.Position >= 81983)
- writer.Write(0)
- Loop
- ' Save Player Info
- Do Until (writer.BaseStream.Position >= 81919)
- writer.Write(0)
- Loop
- ' Sunlight Info
- Do Until (writer.BaseStream.Position >= 81986)
- writer.Write(0)
- Loop
- ' Objects
- Do Until (writer.BaseStream.Position >= 191986)
- writer.Write(0)
- Loop
- ' End Padding
- Do Until (writer.BaseStream.Position >= 192136)
- writer.Write(0)
- Loop
- writer.Close()
- ElseIf filetypep = MapType.XML Then
- ElseIf filetypep = MapType.CSV Then
- ElseIf filetypep = MapType.BITMAP Then
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement