Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Public Class PopMapViewer
- Private Sub PopMapViewer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Dim drawnimg As Bitmap = GenerateMap(128, 128)
- PictureBox1.Image = drawnimg
- Me.Size = PictureBox1.Image.Size
- drawnimg.Save("map.PNG")
- SaveBitmap2Level("\levels\levl2001.dat", drawnimg)
- '"\levels\levl2007.dat"
- End Sub
- Public Function GenerateMap(ByVal size As Integer, ByVal passes As Integer)
- Dim img As New Bitmap(size, size)
- For x = 0 To img.Width - 1
- For y = 0 To img.Height - 1
- img.SetPixel(x, y, Color.FromArgb(0, 0, 100))
- Next
- Next
- For pass As Integer = 0 To passes
- Dim i = 0
- While i < img.Height - 1
- Dim rn As New Random
- Dim x = rn.Next(0, size)
- Dim y = rn.Next(0, size)
- Do Until img.GetPixel(x, y).G = 0
- x = rn.Next(0, size)
- y = rn.Next(0, size)
- Loop
- Dim landheight As Integer
- landheight = rn.Next(0, 255)
- img.SetPixel(x, y, Color.FromArgb(0, landheight, 0))
- i = i + 1
- End While
- Next
- Return img
- End Function
- Public Function CreateBitMap(ByVal file As String, ByVal size As Integer, ByVal AA As Boolean)
- Dim a = Convert2Point(Populous.Info.InstallPath & file)
- Dim img As New Bitmap(size, size)
- Dim Scale = (size / 128)
- For x = 0 To img.Width - 1
- For y = 0 To img.Height - 1
- img.SetPixel(x, y, Color.FromArgb(0, 0, 100))
- Next
- Next
- For Each p In a
- On Error Resume Next
- If p.Height > 5 Then
- If p.Height < 225 Then
- img.SetPixel(p.X * Scale, p.Y * Scale, Color.FromArgb(0, 255 - p.Height, 10))
- For x As Integer = 0 To Scale
- For y As Integer = 0 To Scale
- img.SetPixel(p.X * Scale + x, p.Y * Scale + y, Color.FromArgb(0, 255 - p.Height, 10))
- img.SetPixel(p.X * Scale, p.Y * Scale + y, Color.FromArgb(0, 255 - p.Height, 10))
- img.SetPixel(p.X * Scale + x, p.Y * Scale, Color.FromArgb(0, 255 - p.Height, 10))
- Next
- Next
- ElseIf p.Height < 255 Then
- img.SetPixel(p.X * Scale, p.Y * Scale, Color.FromArgb(255, 255, 0))
- For x As Integer = 0 To Scale
- For y As Integer = 0 To Scale
- img.SetPixel(p.X * Scale + x, p.Y * Scale + y, Color.FromArgb(255, 255, 0))
- img.SetPixel(p.X * Scale, p.Y * Scale + y, Color.FromArgb(255, 255, 0))
- img.SetPixel(p.X * Scale + x, p.Y * Scale, Color.FromArgb(255, 255, 0))
- Next
- Next
- ElseIf p.Height > 255 Then
- img.SetPixel(p.X * Scale, p.Y * Scale, Color.FromArgb(150, 0, 0))
- For x As Integer = 0 To Scale
- For y As Integer = 0 To Scale
- img.SetPixel(p.X * Scale + x, p.Y * Scale + y, Color.FromArgb(150, 0, 0))
- img.SetPixel(p.X * Scale, p.Y * Scale + y, Color.FromArgb(150, 0, 0))
- img.SetPixel(p.X * Scale + x, p.Y * Scale, Color.FromArgb(150, 0, 0))
- Next
- Next
- End If
- End If
- Next
- ' Anti Alias
- Dim pass = Scale
- If AA = False Then
- pass = 0
- End If
- Dim i = 0
- Do Until i = pass
- For x = 0 To img.Width - 1
- For y = 0 To img.Height - 1
- If img.GetPixel(x, y).B = 100 = False And img.GetPixel(x, y).G = 0 = False Then
- If img.GetPixel(x + 1, y + 1).B = 100 Then
- img.SetPixel(x + 1, y + 1, Color.FromArgb(255, 0, 0))
- End If
- End If
- Next
- Next
- For x = 0 To img.Width - 1
- For y = 0 To img.Height - 1
- If img.GetPixel(x, y).R = 255 Then
- If img.GetPixel(x - 1, y - 1).B = 100 = False Then
- img.SetPixel(x, y, Color.FromArgb(img.GetPixel(x - 1, y - 1).R, img.GetPixel(x - 1, y - 1).G, img.GetPixel(x - 1, y - 1).B))
- End If
- End If
- Next
- Next
- i = i + 1
- Loop
- img.RotateFlip(RotateFlipType.Rotate90FlipXY)
- Return img
- End Function
- Private Function Convert2Point(filename As String) As LandPoint()
- Try
- Dim MyLand As LandPoint() = New LandPoint(-1) {}
- Dim reader As New BinaryReader(File.Open(filename, FileMode.Open))
- For x As Integer = 0 To 127
- For y As Integer = 0 To 127
- Dim cur As UShort = reader.ReadUInt16()
- If cur > 0 Then
- Array.Resize(MyLand, MyLand.Length + 1)
- MyLand(MyLand.Length - 1) = New LandPoint(x, y, cur / 4, 1)
- End If
- Next
- Next
- reader.Close()
- Return MyLand
- Catch
- End Try
- Return New LandPoint(-1) {}
- End Function
- Public Sub SaveBitmap2Level(ByVal filename As String, ByVal img As Bitmap)
- Dim MyLand As LandPoint() = New LandPoint(-1) {}
- Dim writer As New BinaryWriter(File.Open(Populous.Info.InstallPath & filename, FileMode.Open))
- For x As Integer = 0 To img.Width - 1
- For y As Integer = 0 To img.Height - 1
- Dim landheight As Short = Convert.ToInt16(1500)
- writer.Write(landheight)
- ' If img.GetPixel(x, y).G > 0 Then
- '' Dim landheight As Short = Convert.ToInt16(1050)
- ' writer.Write(landheight)
- ' Else
- ' Dim landheight As Short = Convert.ToInt16(0)
- ' writer.Write(landheight)
- ' End If
- Next
- Next
- writer.Close()
- End Sub
- End Class
- Public Class LandPoint
- Public X As Integer
- Public Y As Integer
- Public Property Height() As Integer
- Get
- Return TheHeight
- End Get
- Set(value As Integer)
- TheHeight = value
- End Set
- End Property
- Private TheHeight As Integer
- Public Size As Integer
- Public Sub New(_X As Integer, _Y As Integer, _Height As Integer, _Size As Integer)
- X = _X
- Y = _Y
- Height = _Height
- Size = _Size
- End Sub
- Public Sub Render(g As Graphics)
- If Not (TheHeight <= 0) Then
- g.FillRectangle(New SolidBrush(Color.FromArgb(0, TheHeight * 4, 0)), New Rectangle(X, Y, Size, Size))
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement