January 24, 2021, 11:11:41 AM

### Author Topic: [bb] Map Generator from roguebasin by Pakz [ 1+ years ago ]  (Read 780 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] Map Generator from roguebasin by Pakz [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : Map Generator from roguebasin
Author : Pakz
Posted : 1+ years ago

Description : I was reading though the rogue basin map generator descriptions and saw how to do this one.

You could modify the angle step and random draw distance to get other types of maps. I am sure something can be done.

The maps look nice for simple games.

Here is a short video showing a series of maps that get created
<a href="" target="_blank">[/url]

Code :
Code: BlitzBasic
1. Graphics 640,480,32,2
2. SetBuffer BackBuffer()
3. SeedRnd MilliSecs()
4.
5. Const mapwidth = 39
6. Const mapheight = 29
7. Const tilewidth = 16
8. Const tileheight = 16
9. Dim map(mapwidth,mapheight)
10.
11. While KeyDown(1) = False
12.         Cls
13.         makemap()
14.         drawmap()
15.         Flip
16.         For i=0 To 1000
17.                 If KeyDown(1) = True Then End
18.                 Delay 1
19.         Next
20. Wend
21. End
22.
23. Function drawmap()
24.         Color 255,255,255
25.         For y = 0 To 29
26.                 For x = 0 To 39
27.                         If map(x,y) = 1 Then
28.                                 Rect x*tilewidth,y*tileheight,tilewidth,tileheight,True
29.                         End If
30.                 Next
31.         Next
32. End Function
33.
34. Function makemap()
35.         For y=0 To mapheight
36.                 For x=0 To mapwidth
37.                         map(x,y) = 0
38.                 Next
39.         Next
40.         While ang < 359
41.                 d = Rand(60,200)
42.                 For i=0 To d
43.                         x1 = Cos(ang) * i
44.                         y1 = Sin(ang) * i
45.                         x = mapwidth/2*tilewidth + x1
46.                         y = mapheight/2*tileheight + y1
47.                         x = x / tilewidth
48.                         y = y / tileheight
49.                         drawbrush(x,y)
50.                 Next
51.                 ang = ang + Rand(1,50)
52.         Wend
53. End Function
54.
55. Function drawbrush(x,y)
56.         x1 = x
57.         y1 = y - 1
58.         map(x1,y1) = 1
59.         x1 = x - 1
60.         y1 = y
61.         map(x1,y1) = 1
62.         x1 = x + 1
63.         y1 = y
64.         map(x1,y1) = 1
65.         x1 = x
66.         y1 = y + 1
67.         map(x1,y1) = 1
68. End Function