-
Notifications
You must be signed in to change notification settings - Fork 8
/
Map Gep generator 2.monkey
186 lines (178 loc) · 3.82 KB
/
Map Gep generator 2.monkey
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
Import mojo
Class map
Field tw:Float,th:Float
Field mw:Int,mh:Int
Field map:Int[][]
Field maxroomsize:Int=15
Field minroomsize:Int=5
Method New(mapwidth,mapheight)
map = New Int[mapwidth][]
For Local i = 0 Until mapwidth
map[i] = New Int[mapheight]
Next
tw = 640/mapwidth
th = 480/mapheight
Self.mw = mapwidth
Self.mh = mapheight
makemap()
End Method
Method makemap()
map[mw/2][mh/2] = 3
Local total:Int=Rnd(20000,150000)
For Local i=0 To total
Local x:Int = Rnd(maxroomsize+2,mw-(maxroomsize+2))
Local y:Int = Rnd(maxroomsize+2,mh-(maxroomsize+2))
If map[x][y] = 3
Local a:Int = Rnd(0,4)
Local w:Int=Rnd(minroomsize,maxroomsize)
Local h:Int=Rnd(minroomsize,maxroomsize)
If Rnd(10)<4
w=Rnd(maxroomsize-2,maxroomsize)
h=Rnd(maxroomsize-2,maxroomsize)
End If
Select a
Case 0'nroom
If fits(x-w/2,y-h,w,h-1) = True
mr(x,y-h,x+w/2,y-h/2,x,y,x-w/2,y-h/2)
Endif
Case 1'eroom
If fits(x+1,y-h/2,w,h) = True
mr(x+w/2,y-h/2,x+w,y,x+w/2,y+h/2,x,y)
Endif
Case 2'sroom
If fits(x-w/2,y+1,w,h) = True
mr(x,y,x+w/2,y+h/2,x,y+h,x-w/2,y+h/2)
Endif
Case 3'wroom
If fits(x-w-1,y-h/2,w,h) = True
mr(x-w/2,y-h/2,x,y,x-w/2,y+h/2,x-w,y)
Endif
End Select
End If
Next
' here we remove left over doors
For Local y:Int=2 To mh-2
For Local x:Int=2 To mw-2
If map[x][y] = 3
' If into darkness Then remove
If map[x-1][y] = 0 Or map[x+1][y] = 0
map[x][y] = 2
End If
If map[x][y-1] = 0 Or map[x][y+1] = 0
map[x][y] = 2
End If
Local cnt:Int=0
' every door If blocked remove
For Local y1:Int=y-1 To y+1
For Local x1:Int=x-1 To x+1
If map[x1][y1] = 2 Then cnt=cnt+1
Next
Next
If cnt>2 Then map[x][y]=2
End If
Next
Next
End Method
' makeroom
Method mr(x1:Int,y1:Int,x2:Int,y2:Int,x3:Int,y3:Int,x4:Int,y4:Int)
Local w:Int=x2-x4
Local h:Int=y3-y1
For Local y5=y1 To y3
For Local x5=x4 To x2
map[x5][y5] = 1
Next
Next
For Local y5=y1 To y3
map[x4][y5] = 2
map[x2][y5] = 2
Next
For Local x5=x4 To x2
map[x5][y1] = 2
map[x5][y3] = 2
Next
If w>6 And h>6
If Rnd(10)<2
map[x4+1][y1+1] = 2
map[x4+1][y3-1] = 2
End If
If Rnd(10)<2
map[x2-1][y1+1] = 2
map[x2-1][y3-1] = 2
End If
End if
'for the water
If w>10 And h>10
If Rnd(10)<2
For Local y5=y1+3 To y3-3
For Local x5=x4+3 To x2-3
map[x5][y5] = 4
Next
Next
For Local y5=y1+6 To y3-6
For Local x5=x4+6 To x2-6
map[x5][y5] = 1
Next
Next
End If
If Rnd(10)<2
For Local y5=y1+5 To y3-5
For Local x5=x4+5 To x2-5
map[x5][y5] = 2
Next
Next
End If
End If
map[x1][y1] = 3
map[x2][y2] = 3
map[x3][y3] = 3
map[x4][y4] = 3
End Method
' Is there anything in the map
Method fits(x:Int,y:Int,w:Int,h:Int)
' If outside
If x<0 Or y<0 Or x+w>mw Or y+h>mh Then Return False
' If inside
For Local y1=y To y+h
For Local x1=x To x+w
If map[x1][y1]>0 Then Return False
Next
Next
Return True
End Method
Method draw()
For Local y1=0 Until mh
For Local x1=0 Until mw
Select map[x1][y1]
Case 0;SetColor 0,0,0
Case 1;SetColor 100,100,100
Case 2;SetColor 200,200,200
Case 3;SetColor 255,0,0
Case 4;SetColor 0,0,200'water
End Select
DrawRect x1*tw,y1*th,tw,th
Next
Next
End Method
End Class
Global m:map = New map(100,100)
Class MyGame Extends App
Field cnt:Int
Method OnCreate()
SetUpdateRate(60)
End Method
Method OnUpdate()
cnt+=1
If cnt>160
m = New map(100,100)
cnt=0
End If
End Method
Method OnRender()
Cls 0,0,0
SetColor 255,255,255
m.draw
End Method
End Class
Function Main()
New MyGame()
End function