Here's my first shot at this:
Const XSize
= 200, YSize
= 200
DisplayScreen = MaxScreen
InitializeMap
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
= Pink
'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 < 0: RepeatChance
= 33 '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
= 40 ' hills Case Is = 4: RepeatChance
= 33 '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 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)
We start by building some rivers across the screen, which would be the lowest point on the map, and then we rise up to build terrain from that point outwards... beach, plain, forest, hill, mountain, impassable mountains!
Some things to play around with here:
Rivers Int(Rnd * 10) + 1, Int(Rnd * 100) - 100, -3 -- First value is the number of rivers, second is how much they meander across the map, and the third is their starting depth. Note that I haven't set any colors for a depth < -3.
In the fill sub, there's a section which you can play around with to increase density of various features:
Select Case height
Case Is < 0: RepeatChance = 33 '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 = 40 ' hills
Case Is = 4: RepeatChance = 33 'mountains
Case Else
RepeatChance = 50 - 3 * height
If RepeatChance < 10 Then RepeatChance = 10
End Select
The higher the numbers here, the more of the feature your map is going to have...
There's no Ocean on these maps, nor is there any lakes (I think lakes would be a nice addition, rather than just forcing multiple rivers to define the low points of the map), but I think this goes to show how I'd work on generating a map like this. I'd start at the lowest point and then just expand outwards and upwards to my mountains. ;)
[ You are not allowed to view this attachment ]
NOTE: Grab the taskbar header file for proper sizing from here:
https://www.qb64.org/forum/index.php?topic=1020.msg138058#msg138058