Working on Random Map Generation
I just recently made a program that draws a costal atoll style map. it is just ansi art right now and the colours mean that i am using mostly the same char for water and such, anyone who wants to try and make it faster also just fell free to post the faster version in the comments.
Source Code
In the public domain, do what you like with it:
Module Module1
Dim teraindata(,) As Char ‘ Terrain stored Here
Dim mapw As Integer ‘ Dimensions of the map
Dim maph As Integer
Dim rand As New Random
Dim curlocx As Integer
Dim curlocy As Integer
Dim direction As Integer
Dim directionold As Integer
Dim directon1 As Integer
Dim directon2 As Integer
Dim count As Integer
Dim citycount As Integer
Dim watercount As Integer
Sub Main()
Console.Title = "Vbitz’s Map Genorator"
Console.WindowHeight = Console.LargestWindowHeight
Console.WindowWidth = Console.LargestWindowWidth
Console.WindowLeft = 0
Console.WindowTop = 0
ReDim Preserve teraindata(Console.WindowHeight – 4, Console.WindowWidth – 2)
maph = teraindata.GetLength(0) – 1
mapw = teraindata.GetLength(1) – 1
clearmap()
makegrass()
makewater()
‘rendermap()
‘writecitys()
rendermap()
Console.ReadKey()
End Sub
Sub clearmap()
For x = 0 To maph
For y = 0 To mapw
teraindata(x, y) = "0"
Next
Next
End Sub
Sub makegrass()
Console.WriteLine("Grass Genoration Started")
Do Until count > 509
curlocx = rand.Next(1, maph)
curlocy = rand.Next(1, mapw)
For x = 0 To 1000000
teraindata(curlocx, curlocy) = "H"
getdirection()
movepointer()
Next
count = count + 1
writecount()
Loop
End Sub
Sub rendermap()
Console.ForegroundColor = ConsoleColor.White
‘writecount()
Console.WriteLine()
For x = 0 To maph
For y = 0 To mapw
Select Case teraindata(x, y)
Case "H"
Console.ForegroundColor = ConsoleColor.Green
Case "0"
Console.ForegroundColor = ConsoleColor.DarkRed
Case "*"
Console.ForegroundColor = ConsoleColor.White
Case "-"
Console.ForegroundColor = ConsoleColor.Gray
Case "#"
Console.ForegroundColor = ConsoleColor.Blue
End Select
Console.Write(teraindata(x, y))
Next
Console.WriteLine()
Next
End Sub
Sub getdirection()
Do
directon1 = rand.Next(1, 10000)
directon2 = rand.Next(1, 10000)
direction = directon1 / directon2
direction = Math.Round(direction)
Loop Until direction < 5
End Sub
Sub movepointer()
If direction = directionold = False Then
directionold = direction
Select Case direction
Case 1
‘up
If curlocx = 0 = False Then
curlocx = curlocx – 1
End If
Case 2
‘down
If curlocx = maph = False Then
curlocx = curlocx + 1
End If
Case 3
‘left
If curlocy = 0 = False Then
curlocy = curlocy – 1
End If
Case 4
‘right
If curlocy = mapw = False Then
curlocy = curlocy + 1
End If
End Select
End If
End Sub
Sub writecount()
Console.WriteLine("Current Interation : " + count.ToString)
End Sub
Sub writecitys()
Dim trys As Integer = 0
Console.WriteLine("City Genoration Started")
citycount = 0
Do
curlocx = rand.Next(1, maph)
curlocy = rand.Next(1, mapw)
If teraindata(curlocx, curlocy) = "H" Then
If teraindata(curlocx, curlocy) = "#" = False Then
If checkforcity() = False Then
teraindata(curlocx, curlocy) = "*"
citycount = citycount + 1
Else
‘Console.WriteLine("Try: " + trys.ToString)
trys = trys + 1
End If
End If
End If
Loop Until citycount > 63 ‘ Number of Cities Here
End Sub
Function checkforcity() As Boolean
Dim temp1 As Integer
For x = 0 To maph
For y = 0 To mapw
If teraindata(x, y) = "*" Then
temp1 = x – curlocx
temp1 = temp1 + (y – curlocy)
‘Console.WriteLine(x.ToString + ", " + y.ToString)
‘Console.WriteLine(temp1)
‘rendermap()
‘Console.ReadKey()
If temp1 > 8 And temp1 > 0 Then
ElseIf temp1 < -8 And temp1 < 0 Then
Else
Return True
End If
End If
Next
Next
Return False
End Function
Sub buildroads()
For x = 0 To maph
For y = 0 To mapw
If teraindata(x, y) = "*" Then
curlocx = x
curlocy = y
makeroad()
End If
Next
Next
End Sub
Sub makeroad()
End Sub
Sub makewater()
Console.WriteLine("Water Genoration Started")
count = 0
Do Until count > 39
curlocx = rand.Next(1, maph)
curlocy = rand.Next(1, mapw)
For x = 0 To 10000
teraindata(curlocx, curlocy) = "#"
getdirection()
movepointer()
Next
‘Console.WriteLine("Count: " + count.ToString)
count = count + 1
Loop
End Sub
End Module
WARNING: It will take a very long time to run
Active on IRC
Most of the time right now I am on Internet Relay Chat a lot.
For anyone who is interested i am on a lot of Game surge and also i have just set it so i am on a lot of open source related stuff like #ubuntu on Freenode. I am also on #wiremod on GameSurge
Starting with Ubuntu
I just recently installed Ubuntu 9.10 into a virtual machine using virtual box and so far i have managed to get internet working and compiled vlc from source code. All to simple so far.
Next things next, switch my desktop kernel with a server one for better performance, the only reason i have a desktop one is better hardware support.
Testing Post from Windows Live Writer
I am doing this Blog post from Windows Live Writer which I though was a good idea since I do not need to be connected to the internet to make a post like this. Also stuff can be locally stored on my computer and uploaded when I am happy with it.
Working with XNA
I have recently been working with the XNA Framework and have been using the XNA Console. I so far have managed to define a proper rectangle and almost render it, though i need to put it in the Draw Method, I am thinking the best way of doing that would be to use some sort of hook system executing the procedure in the draw method. Another interesting thing is i am able to make a brand new python sub system in game. I can even exit by using a back-end function Game.Exit.
Updated Project Work
A while back I told you about the projects I have been working on and while a couple are finished, the coursework ones. The others are still going strong and most of the networking is going well, the graphics side is falling a bit short, though it is still going well.
Cool games I Looked at
Sorry for the non interesting post title.
I have been looking at a lot of really cool indie games recently, just Google them for the homepage.
N8
It is a really cool construction mmo, it is looking as if it has a lot of potential for times to come. weird thing is it is programmed in Visual Basic.
Toribash
Strange fighting game where you have full control, trust me some of the things done are epic, try looking at the 3 piece tear.
Wiremod.Com Comments Post
Any comments about my posts can be commented here
I am now a Wire Sofaking
This morning i finally became a Wire Sofaking on Wiremod.com
I now have over 400 posts there
Big Update
Sorry i have not posted in a while, had too much to do. There is alot of stuff i have been doing
Wiremod Forums
I have been going on wiremod forums a lot, i am now 10th highest poster on normal users, there are over 50000 users.
Source Mapping
Well i have also been making quite a few maps