Code: Select all
SCREEN 800,600
SetWindow "Maastogeneraattori by. Kumiankka"
SW = ScreenWidth()
SH = ScreenHeight()
Const RUOHO = 0
Const KALLIO = 1
Const HIEKKA = 2
Const VESI = 3
Const KORKEUS = 0
Const TYYPPI = 1
MAXKORKEUS = 200
MINKORKEUS = -1
Const ruoho_colR = 1
Const ruoho_colG = 95
Const ruoho_coB = 1
Const kallio_colR = 0
Const kallio_colG = 0
Const kallio_colB = 0
Const hiekka_colR = 150
Const hiekka_colG = 150
Const hiekka_colB = 1
Const vesi_colR = 5
Const vesi_colG = 5
Const vesi_colB = 200
Global vesi_min, vesi_max, hiekka_min, hiekka_max, ruoho_min, ruoho_max, kallio_min, kallio_max
vesi_min = -1
vesi_max = 19
hiekka_min = 20
hiekka_max = 40
ruoho_min = 41
ruoho_max = 120
kallio_min = 121
kallio_max = MAXKORKEUS
korkeus_max_muutos = 50
korkeus_min_muutos = -50
debugHeight = False
Randomize Timer()
_img = MakeImage(SW,SH)
AddText "Generating..."
DrawScreen
Dim maasto(ScreenWidth(),ScreenHeight(),1)
Gosub LuoMaasto
ClearText
Repeat
Gosub PiirräMaasto
If KeyHit(28) Then SaveImage _img, CurrentDir()+"mappi.bmp"
DrawScreen
Until EscapeKey()
LuoMaasto:
For xx = 1 To SW
For yy = 1 To SH
If xx = 1 Or yy = 1 Then
maasto(xx, yy,KORKEUS) = Rand(MINKORKEUS,MAXKORKEUS)
maasto(xx, yy,TYYPPI) = GroundtypeFromHeight(maasto(xx, yy,KORKEUS))
ElseIf xx > 1 And yy > 1 And xx < SW - 1 And yy < SH - 1 Then
_korkeus1 = (maasto(xx, yy - 1,KORKEUS) + Rand(korkeus_min_muutos, korkeus_max_muutos))
_korkeus2 = (maasto(xx - 1, yy,KORKEUS) + Rand(korkeus_min_muutos, korkeus_max_muutos))
_uusikorkeus = (_korkeus1 + _korkeus2) / 2
maasto( xx, yy,KORKEUS) = Max(Min(_uusikorkeus,MAXKORKEUS),MINKORKEUS)
maasto( xx, yy,TYYPPI) = GroundtypeFromHeight(maasto(xx, yy,KORKEUS))
EndIf
Next yy
Next xx
For xx = 1 To SW
For yy = 1 To SH
DrawToImage _img
If maasto(xx,yy,TYYPPI) = RUOHO Then
Color (Ruoho_colR + maasto(xx,yy,KORKEUS)), (Ruoho_colG + maasto(xx,yy,KORKEUS)), (Ruoho_colB + maasto(xx,yy,KORKEUS))
Dot xx,yy
ElseIf maasto(xx,yy,TYYPPI) = KALLIO Then
Color (Kallio_colR + maasto(xx,yy,KORKEUS)), (Kallio_colG + maasto(xx,yy,KORKEUS)), (Kallio_colB + maasto(xx,yy,KORKEUS))
Dot xx,yy
ElseIf maasto(xx,yy,TYYPPI) = HIEKKA Then
Color (hiekka_colR + maasto(xx,yy,KORKEUS)), (hiekka_colG + maasto(xx,yy,KORKEUS)), (hiekka_colB + maasto(xx,yy,KORKEUS))
Dot xx,yy
ElseIf maasto(xx,yy,TYYPPI) = VESI Then
Color (vesi_colR + maasto(xx,yy,KORKEUS)), (vesi_colG + maasto(xx,yy,KORKEUS)), (vesi_colB + maasto(xx,yy,KORKEUS))
Dot xx,yy
EndIf
DrawToScreen
Next yy
Next xx
Return
PiirräMaasto:
DrawImage _img, 0, 0
If debugHeight = True
For xx = 1 To SW Step 50
For yy = 1 To SH Step 50
Color cbBlack
Text xx,yy,""+Int(maasto(xx,yy,KORKEUS))
Next yy
Next xx
EndIf
Return
Function GroundtypeFromHeight(_height)
If _height >= kallio_min Then
Return KALLIO
ElseIf _height >= ruoho_min Then
Return RUOHO
ElseIf _height >= hiekka_min Then
Return HIEKKA
ElseIf _height >= vesi_min Then
Return VESI
EndIf
EndFunction