-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path3d fps rooms and doors.bb
More file actions
380 lines (333 loc) · 7.37 KB
/
Copy path3d fps rooms and doors.bb
File metadata and controls
380 lines (333 loc) · 7.37 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
Global scale1# = 5
Global scale2# = scale1*2
Global scale3# = 20
Global width = 800
Global height = 600
Graphics3D width,height,32,2
SetBuffer BackBuffer()
AppTitle "Map generator"
; mapwidthheight --- needs a beefy pc for large sizes
Global mw=100
Global mh=100
;tilewidthheight --- for the minimap
Global tw=GraphicsWidth()/mw
Global th=GraphicsHeight()/mh
;min/maxroomsizewh - - generator variables
Global minroomsize = 5
Global maxroomsize = 15
Dim map(mw,mh)
; collisions
Const type_scenery=3
Const type_cam=1
Global alt = 0
Global cam=CreateCamera()
EntityRadius cam,1.5
EntityType cam,type_cam
CameraClsColor cam,71,71,71
Global mousespeed#=0.5
Global camspeed#=0.5
Global camsmoothness#=3
SeedRnd MilliSecs()
Dim entmap(mw,mh,2)
Global timer=CreateTimer(30)
;make the textures
Global texw = 256
Global texh = 256
Dim tex(10)
For ii=0 To 10
tex(ii) = CreateTexture(texw,texh)
SetBuffer TextureBuffer(tex(ii))
ClsColor 200,200,200
Cls
num=1000
If ii=2 Then num=3000
For i=0 To num
x = Rand(0,texw)
y = Rand(0,texh)
c = Rand(255)
Color c,c,c
Oval x,y,Rand(1,5),Rand(1,5)
Next
Next
SetBuffer BackBuffer()
remakelevel()
placeplayer
Global minmap = CreateImage(200,200)
makeminimap
Color 255,255,255
While KeyDown(1) = False
WaitTimer timer
If KeyHit(2)=True
remakelevel
makeminimap
placeplayer
End If
UpdateWorld
RenderWorld
gameinput
Text 0,0,"Press 1 - new level - mouse to turn - rmb/cursors move."
DrawBlock minmap,width-200,0
Color 255,255,0
px = EntityX(cam)/(mw/20)
py = EntityZ(cam)/(mh/20)
Rect (width-200+(200-px)-5),(200-py)-5,10,10,False
Flip
Wend
End
Function remakelevel()
For y=0 To mh
For x=0 To mw
FreeEntity entmap(x,y,0)
FreeEntity entmap(x,y,1)
entmap(x,y,0) = 0
entmap(x,y,1) = 0
map(x,y) = 0
Next
Next
makemap()
makeents
Collisions type_cam,type_scenery,2,3
End Function
;
; Here the cube map is made
;
;
Function makeents()
For y=0 To mh
For x=0 To mw
If map(x,y) = 1
entmap(x,y,0) = CreateCube()
ScaleEntity entmap(x,y,0),scale1,1,scale1
PositionEntity entmap(x,y,0),x*scale2,0,y*scale2
EntityColor entmap(x,y,0),155,100,0
EntityType entmap(x,y,0),type_scenery
EntityTexture entmap(x,y,0),tex(0)
entmap(x,y,1) = CreateCube()
ScaleEntity entmap(x,y,1),scale1,1,scale1
PositionEntity entmap(x,y,1),x*scale2,scale3,y*scale2
EntityColor entmap(x,y,1),155,100,0
EntityType entmap(x,y,1),type_scenery
EntityTexture entmap(x,y,1),tex(1)
End If
If map(x,y) = 2
entmap(x,y,0) = CreateCube()
ScaleEntity entmap(x,y,0),scale1,scale3,scale1
PositionEntity entmap(x,y,0),x*scale2,0,y*scale2
EntityColor entmap(x,y,0),255,100,0
EntityType entmap(x,y,0),type_scenery
EntityTexture entmap(x,y,0),tex(2)
End If
If map(x,y) = 3
entmap(x,y,0) = CreateCube()
ScaleEntity entmap(x,y,0),scale1,1,scale1
PositionEntity entmap(x,y,0),x*scale2,0,y*scale2
EntityColor entmap(x,y,0),55,100,0
EntityType entmap(x,y,0),type_scenery
EntityTexture entmap(x,y,0),tex(3)
entmap(x,y,1) = CreateCube()
ScaleEntity entmap(x,y,1),scale1,1,scale1
PositionEntity entmap(x,y,1),x*scale2,scale3,y*scale2
EntityColor entmap(x,y,1),55,100,0
EntityType entmap(x,y,1),type_scenery
EntityTexture entmap(x,y,1),tex(4)
End If
If map(x,y) = 4 ; lava
entmap(x,y,0) = CreateCube()
ScaleEntity entmap(x,y,0),scale1,1,scale1
PositionEntity entmap(x,y,0),x*scale2,0,y*scale2
EntityColor entmap(x,y,0),155,10,1
EntityType entmap(x,y,0),type_scenery
EntityTexture entmap(x,y,0),tex(5)
entmap(x,y,1) = CreateCube()
ScaleEntity entmap(x,y,1),scale1,1,scale1
PositionEntity entmap(x,y,1),x*scale2,scale3,y*scale2
EntityColor entmap(x,y,1),155,100,0
EntityType entmap(x,y,1),type_scenery
EntityTexture entmap(x,y,1),tex(1)
End If
Next
Next
End Function
Function newmap()
For y=0 To mh
For x=0 To mw
map(x,y)=0
Next
Next
makemap
End Function
Function makemap()
map(mw/2,mh/2) = 3
Local total=(mw*mh)*30; Rand(20000,150000)
For i=0 To total
x = Rand(maxroomsize+2,mw-(maxroomsize+2))
y = Rand(maxroomsize+2,mh-(maxroomsize+2))
If map(x,y) = 3
a = Rand(0,4)
w=Rand(minroomsize,maxroomsize)
h=Rand(minroomsize,maxroomsize)
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 y=2 To mh-2
For x=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
cnt=0
; every door if blocked remove
For y1=y-1 To y+1
For x1=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 Function
; makeroom
Function mr(x1,y1,x2,y2,x3,y3,x4,y4)
Local myw = x2-x1
Local myh = y3-y1
For y5=y1 To y3
For x5=x4 To x2
map(x5,y5) = 1
Next
Next
For y5=y1 To y3
map(x4,y5) = 2
map(x2,y5) = 2
Next
For x5=x4 To x2
map(x5,y1) = 2
map(x5,y3) = 2
Next
map(x1,y1) = 3
map(x2,y2) = 3
map(x3,y3) = 3
map(x4,y4) = 3
If Rand(2) = 1
If Rand(2) = 1
For y5 = y1+2 To y3-2
For x5 = x4+2 To x2-2
map(x5,y5) = 4
Next
Next
Else
For y5 = y1+3 To y3-3
For x5 = x4+3 To x2-3
map(x5,y5) = 2
Next
Next
End If
End If
End Function
; Is there anything in the map
Function fits(x,y,w,h)
; if outside
If x<0 Or y<0 Or x+w>mw Or y+h>mh Then Return False
; if inside
For y1=y To y+h
For x1=x To x+w
If map(x1,y1)>0 Then Return False
Next
Next
Return True
End Function
Function gameinput()
;cam controls
mx#=CurveValue(MouseXSpeed()*mousespeed,mx,camsmoothness)
my#=CurveValue(MouseYSpeed()*mousespeed,my,camsmoothness)
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
pitch#=EntityPitch(cam)
yaw#=EntityYaw(cam)
pitch=pitch+my
yaw=yaw-mx
If pitch>89 pitch=89
If pitch<-89 pitch=-89
RotateEntity cam,0,yaw,0
TurnEntity cam,pitch,0,0
cx#=(KeyDown(32)-KeyDown(30))*camspeed
cz#=(KeyDown(17)-KeyDown(31))*camspeed
If MouseDown(2) = True Then cz=camspeed
; Gravity
TranslateEntity cam,0,-1,0
MoveEntity cam,cx,0,cz
Return
End Function
Function placeplayer()
Local exitloop = False
Local cnt2=0
While exitloop = False
x = Rand(0,mw)
y = Rand(0,mh)
cnt=0
For y1=-3 To 3
For x1=-3 To 3
If x+x1>0 And x+x1<mw And y+y1>0 And y+y1<mh
If map(x+x1,y+y1) = 1
cnt=cnt+1
End If
End If
Next
Next
If cnt>48
exitloop = True
End If
cnt2=cnt2+1
If cnt2>10000 Then remakelevel : cnt2=0
Wend
PositionEntity cam,x*scale2,8,y*scale2
ResetEntity cam
End Function
Function makeminimap()
SetBuffer ImageBuffer(minmap)
ClsColor 0,0,0
Cls
For y=0 To mh
For x=0 To mw
If map(x,y)>0
If map(x,y) = 1
Color 150,150,150
End If
If map(x,y) = 2
Color 250,250,250
End If
If map(x,y) = 3
Color 50,50,50
End If
Plot 200-(x*200/mw),200-(y*200/mh)
End If
Next
Next
SetBuffer BackBuffer()
End Function
Function CurveValue#(newvalue#,oldvalue#,increments )
If increments>1 oldvalue#=oldvalue#-(oldvalue#-newvalue#)/increments
If increments<=1 oldvalue=newvalue
Return oldvalue#
End Function