Setvirtualresolution(640,480)
ResetTimer()
type room
roomx as integer
roomz as integer
roomy as integer
ObjIDx as integer
ObjIDy as integer
ObjIDz as integer
endtype
type corridor
corridorx as integer
corridorz as integer
corridory as integer
ObjIDx as integer
ObjIDy as integer
ObjIDz as integer
distance as integer
endtype
dim roomGPS[20] as room
dim roomCloneIDs[100] as room
dim corridorGPS[200] as corridor
dim corridorCloneIDs[200] as corridor
dim rmdistance[20] as corridor
floorObjID = CreateObjectBox(1, 1, 1)
SetObjectPosition( floorObjID, 1000, 1000, 1000 )
global floorObjID
global rooms
rooms = 12
function room ()
t = 1
i = 0
For t = 1 to rooms
roomGPS[t].roomz = Random2(0,40)
roomGPS[t].roomy = 0
roomGPS[t].roomx = Random2(0,40)
For i = 0 to t
if t = i+1
exit
endif
distance = sqrt(Pow((roomGPS[t].roomx - roomGPS[i+1].roomx),2) + Pow((roomGPS[t].roomz - roomGPS[i+1].roomz),2))
if distance < 10
t=t-1
endif
Next i
Next t
For t = 1 to rooms
For x = 0 to 3
roomCloneIDs[t].ObjIDx = CloneObject( floorObjID )
SetObjectPosition( roomCloneIDs[t].ObjIDx, roomGPS[t].roomx+x, roomGPS[t].roomy, roomGPS[t].roomz )
For z = 1 to 3
roomCloneIDs[t].ObjIDz = CloneObject( floorObjID )
SetObjectPosition( roomCloneIDs[t].ObjIDz, roomGPS[t].roomx+x, roomGPS[t].roomy, roomGPS[t].roomz+z )
Next z
Next x
Next t
endfunction
function corridor()
t = 1
For t = 1 to rooms
i = 0
For i = 0 to 4
rmdistance[i].distance = sqrt(Pow((roomGPS[t].roomx - roomGPS[i+1].roomx),2) + Pow((roomGPS[t].roomz - roomGPS[i+1].roomz),2))
if rmdistance[i].distance = 0 then rmdistance[i].distance = 300
Next i
u = 0
v# = rmdistance[0].distance
For u = 0 to 4
if rmdistance[u].distance < v#
v# = rmdistance[u].distance
endif
Next u
x = 0
For x = 0 to 4
if v# = rmdistance[x].distance
tilex = roomGPS[t].roomx - roomGPS[x+1].roomx
tilez = roomGPS[t].roomz - roomGPS[x+1].roomz
dirx = tilex/abs(tilex)
dirz = tilez/abs(tilez)
xx = 1
For xx = 1 to abs(tilex)
corridorCloneIDs[xx].ObjIDx = CloneObject( floorObjID )
SetObjectPosition( corridorCloneIDs[xx].ObjIDx, roomGPS[t].roomx-(xx*dirx), roomGPS[t].roomy, roomGPS[t].roomz )
Next xx
For zz = 1 to abs(tilez)
corridorCloneIDs[xx].ObjIDx = CloneObject( floorObjID )
SetObjectPosition( corridorCloneIDs[xx].ObjIDx, roomGPS[t].roomx-tilex, roomGPS[t].roomy, roomGPS[t].roomz-(zz*dirz) )
Next zz
endif
Next x
Next t
endfunction
room()
corridor()
do
SetCameraPosition( 1, roomGPS[1].roomx, 125, roomGPS[1].roomz)
SetCameraLookAt( 1, roomGPS[1].roomx, 0, roomGPS[1].roomz, 0 )
Sync()
loop
Rooms are not always connected, and I get double corridors on occasion. I'm afraid I will have to start over, and think of another way.
I got really lost on creating the corridors, and it got pretty ugly. I was not able to store the OBJIDs or new map coords in an array like I had done with the rooms.
The biggest issues are I don't know how to test if a section of the maze is not connected, and how to not double up on corridors(one beside the other).