Added Lakes into the mix.
Const XSize
= 200, YSize
= 200
DisplayScreen = MaxScreen
InitializeMap
Lakes Lakecount, 400 - Lakecount * 100, 1000 - Lakecount * 300
GenerateTerrain
DrawMap
Grid(x, y) = -999 'default blank part of map
Case -3: kolor
= DarkBlue
'Deep Water Case -2: kolor
= Blue
'Water Case -1: kolor
= SkyBlue
'Shallow Water Case 0: kolor
= Tann
'beach/sand Case 1: kolor
= Green
'grassland Case 2: kolor
= DarkGreen
'forest Case 3: kolor
= Gold
'hills Case 4: kolor
= Purple
'mountains Line (x
* xscale
, y
* yscale
)-Step(xscale
, yscale
), kolor
, BF
Height = -3
finished = -1
If Grid
(x
, y
) = Height
Then Fill x
, y
, Height
+ 1: finished
= 0 Height = Height + 1
Case Is = -2: RepeatChance
= 50 'water repeat Case Is = -1: RepeatChance
= 30 'shallow water repeat Case Is = 0: RepeatChance
= 25 'beach repeat Case Is = 1: RepeatChance
= 55 'grassland Case Is = 2: RepeatChance
= 55 'forest Case Is = 3: RepeatChance
= 50 ' hills Case Is = 4: RepeatChance
= 50 'mountains RepeatChance = 50 - 3 * height
If RepeatChance
< 10 Then RepeatChance
= 10 CurrentX = x
If Grid
(CurrentX
- 1, y
) = -999 Then Grid(CurrentX - 1, y) = height
If Int(Rnd * 100) < RepeatChance
Then Fill CurrentX
- 1, y
, height
CurrentX = x
If Grid
(CurrentX
+ 1, y
) = -999 Then Grid(CurrentX + 1, y) = height
If Int(Rnd * 100) < RepeatChance
Then Fill CurrentX
+ 1, y
, height
CurrentY = y
If Grid
(x
, CurrentY
- 1) = -999 Then Grid(x, CurrentY - 1) = height
If Int(Rnd * 100) < RepeatChance
Then Fill x
, CurrentY
- 1, height
CurrentY = y
If Grid
(x
, CurrentY
+ 1) = -999 Then Grid(x, y + 1) = height
If Int(Rnd * 100) < RepeatChance
Then Fill x
, CurrentY
+ 1, height
Sub Lakes
(Number
, MinSize
, MaxSize
) LakeSize
= Int(Rnd * (MaxSize
- MinSize
)) + MinSize
LakeBuilt = 0
xchange = 0: ychange = 0
repeat:
If x
+ xchange
< 0 Or x
+ xchange
> XSize
Then xchange
= -xchange
If y
+ ychange
< 0 Or y
+ ychange
> YSize
Then ychange
= -ychange
If Grid
(x
+ xchange
, y
+ ychange
) = -999 Then Grid(x + xchange, y + ychange) = -3
LakeBuilt = LakeBuilt + 1
x = x + xchange: y = y + ychange
If flip
Then xchange
= xchange
* 2 Else ychange
= ychange
* 2
Sub Rivers
(Number
, Meander
, Deep
) If flip1
Then 'entry point is on top Else 'entry point is on left If flip2
Then 'exit point is on bottom x2
= Int(Rnd * XSize
): y2
= YSize
Else 'exit point is on right x2
= XSize: y2
= Int(Rnd * YSize
)
Grid(x1, y1) = Deep: Grid(x2, y2) = Deep
StartX = x1: StartY = y1: EndX = x2: EndY = y2 'just to preserve our original values, if needed.
CoinToss
= Int(Rnd * 100) 'Coin toss to move left/right or up/down, to go towards exit, or wander a bit. Meander = 10
If CoinToss
Mod 2 Then 'even or odd, so we only walk vertical or hortizontal and not diagional If CoinToss
< 100 - Meander
Then 'Lower values meander less and go directly to the target. XChange
= Sgn(EndX
- StartX
) '-1,0,1, drawn always towards the mouse Ychange = 0
XChange
= Int(Rnd * 3) - 1 '-1, 0, or 1, drawn in a random direction to let the lightning wander Ychange = 0
If CoinToss
< 100 - Meander
Then 'Lower values meander less and go directly to the target. Ychange
= Sgn(EndY
- StartY
) XChange = 0
XChange = 0
StartX = StartX + XChange
StartY = StartY + Ychange
If StartX
< 0 Then StartX
= 0 'Make certain we move inside the bounds of our map dimensions If StartX
> XSize
Then StartX
= XSize
If StartY
> YSize
Then StartY
= YSize
Grid(StartX, StartY) = Deep 'place a river where we moved to
TBH = TaskbarHeight: TBW = TaskbarWidth
TH = TitleBarHeight: BW = BorderWidth
If TBH
= DH
Then TBH
= 0 'Users taskbar is configured vertical, not hortizonal. MaxScreen
= _NewImage(DW
- TBW
- 2 * BW
, DH
- TBH
- TH
- BW
* 2, 32)
_ScreenMove x
- BorderWidth
, y
- BorderWidth
- TitleBarHeight
TaskbarHeight = taskbar_height&
TaskbarHeight = 0 'no function to get the value for Linux/Mac, so return 0 instead of an error
TaskbarWidth = taskbar_width&
TaskbarWidth = 0 'no function to get the value for Linux/Mac, so return 0 instead of an error
TitleBarHeight = glutGet(507)
BorderWidth = glutGet(506)
[ You are not allowed to view this attachment ]
[ You are not allowed to view this attachment ]
I've got to admit, I think some of these end up looking rather nice. (Of course, since almost everything is random here, some of these end up looking like complete garbage to me as well.)
Keep in mind, I'm creating massive 200 x 200 world maps with the settings the way I currently have them. Also note, the actual game would probably be at a much larger scale with only small portions of it viewable by the player at a time. I also don't know if I'd bother to use so many colors for water... Probably just shallow water (where you can wade in it) and deep water (where a boat travels) would be good enough. My thinking behind 3 levels of water here was basically ocean ship, canoe/raft/shallow drag boat, and then wading/shallow water.
Anywho... I'd call this a decent shot at a random terrain generator. It doesn't follow any basic rules of logic, but it's decent enough I'm not ashamed to share it. :P
If I was serious about this thing, I'd probably start at my mountains and then flow down to my oceans and not backwards like I did in this attempt, as that seems like it'd generate a more natural water flow from high to low. I'd also try to work in things like temperature zones for the polar regions, and deserts for places which are too far away from any major source of water and would normally be plains instead.
Enough to showcase the basic idea behind things here, but it can definitely be expanded on if someone was wanting to. ;D