ou99孽缘 发表于 2010-12-14 20:59:33

随机迷宫系统

globals
integer array udg_Labyrinth //二进制0~7位为4个方向(下1、右下2、右4、右上8,上16,左上32,左64,左下128)是否相通,8~11位为四角(右下256、右上512、左上1024、左下2048)是否被对角连接占用,12位为是否为始点4096,13位为是否是终点8192,14位为是否为末端16384,15位为是否使用32768.(临时数据)
integer array udg_UsedGrid //已使用格子(临时数据)
integer array udg_UnableGrid //不可用格子(临时数据)
integer array udg_EndWay //支路尽头点记录(临时数据)
integer array udg_DestructableArray //可破坏物类型组(自定义数据)
integer array udg_DestructableType //可破坏物类型对应的式样数目(固定数据)
integer udg_UsedGridNum //已用格子总数(临时数据)
integer udg_UnableGridNum //不可用格子总数(临时数据)
integer udg_EndWayNum //支路尽头总数(临时数据)
integer udg_DestructableNum //可破坏物类型总数(固定数据)
integer udg_Length_X //X方向格子数,小于90(自定义数据)
integer udg_Length_Y //Y方向格子数,小于90 (自定义数据)
integer udg_Start //起始点的位置,值为对应的Y*udg_Length_X+X-1(自定义数据)
integer udg_End //终点的位置,值为对应的Y*udg_Length_X+X-1(自定义数据)
integer udg_FirstTimer //格子对应的timer数组的第一个timer的handle值(临时数据)
integer udg_GridID //路径创建位置(临时数据)
integer udg_WayLength //当前路线长度(临时数据)
integer udg_WayLengthMin //当路线最小长度(自定义数据)
integer udg_WayLengthMax //当路线最大长度(自定义数据)
integer udg_NewGroundType //可通行处的地面纹理类型(自定义数据)
integer udg_OldGroundType //不可通行处的地面纹理类型 (固定数据)
integer udg_DoingOverNum //格子处理执行完毕数量(临时数据)
real udg_DestructableRate //允许使用可破坏物上限(自定义数据)
real udg_TopLeftCorner_X //左上角点X轴坐标(自定义数据)
real udg_TopLeftCorner_Y //左上角点Y轴坐标(自定义数据)
real udg_Density //迷宫最小使用密度(自定义数据)
boolean udg_ReachEnd //已到达终点(临时数据)
endglobals
return h
return 0
endfunction
return i
endfunction
local integer TempGrid = udg_Labyrinth [ GridID ]
loop
exitwhen I == 0
set I = I - 1
set TempGrid = TempGrid / 2
endloop
return TempGrid - TempGrid / 2 * 2
endfunction
function Direction_0 takes nothing returns nothing //对下方向的处理
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 1
set udg_GridID = udg_GridID - udg_Length_X
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 32784
endfunction
function Direction_1 takes nothing returns nothing //对右下方向的处理
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 2
set udg_Labyrinth [ udg_GridID - udg_Length_X ] = udg_Labyrinth [ udg_GridID - udg_Length_X ] + 512
set udg_Labyrinth [ udg_GridID + 1 ] = udg_Labyrinth [ udg_GridID + 1 ] + 2048
set udg_GridID = udg_GridID - udg_Length_X + 1
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 32800
endfunction
function Direction_2 takes nothing returns nothing //对右方向的处理
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 4
set udg_GridID = udg_GridID + 1
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 32832
endfunction
function Direction_3 takes nothing returns nothing //对右上方向的处理
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 8
set udg_Labyrinth [ udg_GridID + udg_Length_X ] = udg_Labyrinth [ udg_GridID + udg_Length_X ] + 256
set udg_Labyrinth [ udg_GridID + 1 ] = udg_Labyrinth [ udg_GridID + 1 ] + 1024
set udg_GridID = udg_GridID + udg_Length_X + 1
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 32896
endfunction
function Direction_4 takes nothing returns nothing //对上方向的处理
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 16
set udg_GridID = udg_GridID + udg_Length_X
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 32769
endfunction
function Direction_5 takes nothing returns nothing //对左上方向的处理
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 32
set udg_Labyrinth [ udg_GridID + udg_Length_X ] = udg_Labyrinth [ udg_GridID + udg_Length_X ] + 2048
set udg_Labyrinth [ udg_GridID - 1 ] = udg_Labyrinth [ udg_GridID - 1 ] + 512
set udg_GridID = udg_GridID + udg_Length_X - 1
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 32770
endfunction
function Direction_6 takes nothing returns nothing //对左方向的处理
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 64
set udg_GridID = udg_GridID - 1
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 32772
endfunction
function Direction_7 takes nothing returns nothing //对左下方向的处理
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 128
set udg_Labyrinth [ udg_GridID - udg_Length_X ] = udg_Labyrinth [ udg_GridID - udg_Length_X ] + 1024
set udg_Labyrinth [ udg_GridID - 1 ] = udg_Labyrinth [ udg_GridID - 1 ] + 256
set udg_GridID = udg_GridID - udg_Length_X - 1
set udg_Labyrinth [ udg_GridID ] = udg_Labyrinth [ udg_GridID ] + 32776
endfunction
function GetRandomDirection takes nothing returns integer //获得随机方向
if udg_GridID == udg_End then //当前点为终点
return - 1
endif
if udg_GridID > = udg_Length_X then
if udg_Labyrinth [ udg_GridID - udg_Length_X ] - 32768 < 0 then
set Random [ RandomNum ] = 0
set RandomNum = RandomNum + 1
endif
endif
if Get01 ( udg_GridID, 8 ) == 0 and udg_GridID > = udg_Length_X and udg_GridID - udg_GridID / udg_Length_X * udg_Length_X != udg_Length_X - 1 then
if udg_Labyrinth [ udg_GridID - udg_Length_X + 1 ] - 32768 < 0 then
set Random [ RandomNum ] = 1
set RandomNum = RandomNum + 1
endif
endif
if udg_GridID - udg_GridID / udg_Length_X * udg_Length_X != udg_Length_X - 1 then
if udg_Labyrinth [ udg_GridID + 1 ] - 32768 < 0 then
set Random [ RandomNum ] = 2
set RandomNum = RandomNum + 1
endif
endif
if Get01 ( udg_GridID, 9 ) == 0 and udg_GridID - udg_GridID / udg_Length_X * udg_Length_X != udg_Length_X - 1 and udg_GridID < = udg_Length_X * ( udg_Length_Y - 1 ) - 1 then
if udg_Labyrinth [ udg_GridID + udg_Length_X + 1 ] - 32768 < 0 then
set Random [ RandomNum ] = 3
set RandomNum = RandomNum + 1
endif
endif
if udg_GridID < = udg_Length_X * ( udg_Length_Y - 1 ) - 1 then
if udg_Labyrinth [ udg_GridID + udg_Length_X ] - 32768 < 0 then
set Random [ RandomNum ] = 4
set RandomNum = RandomNum + 1
endif
endif
if Get01 ( udg_GridID, 10 ) == 0 and udg_GridID < = udg_Length_X * ( udg_Length_Y - 1 ) - 1 and udg_GridID - udg_GridID / udg_Length_X * udg_Length_X != 0 then
if udg_Labyrinth [ udg_GridID + udg_Length_X - 1 ] - 32768 < 0 then
set Random [ RandomNum ] = 5
set RandomNum = RandomNum + 1
endif
endif
if udg_GridID - udg_GridID / udg_Length_X * udg_Length_X != 0 then
if udg_Labyrinth [ udg_GridID - 1 ] - 32768 < 0 then
set Random [ RandomNum ] = 6
set RandomNum = RandomNum + 1
endif
endif
if Get01 ( udg_GridID, 11 ) == 0 and udg_GridID - udg_GridID / udg_Length_X * udg_Length_X != 0 and udg_GridID > = udg_Length_X then
if udg_Labyrinth [ udg_GridID - udg_Length_X - 1 ] - 32768 < 0 then
set Random [ RandomNum ] = 7
set RandomNum = RandomNum + 1
endif
endif
if RandomNum == 0 then
set udg_UnableGrid [ udg_UnableGridNum ] = udg_GridID
set udg_UnableGridNum = udg_UnableGridNum + 1
loop
if udg_UsedGrid [ i ] == udg_GridID then
set udg_UsedGridNum = udg_UsedGridNum - 1
set udg_UsedGrid [ i ] = udg_UsedGrid [ udg_UsedGridNum ]
else
set i = i + 1
endif
exitwhen i > = udg_UsedGridNum
endloop
return - 1
else
set udg_WayLength = udg_WayLength + 1
endif
endfunction
function TerrainPathable takes real X, real Y, integer ID returns nothing // 地面通行状态处理
set X = X + I2R ( ( ID - ID / 9 * 9 ) * 128 - 560 )
endif
endif
endif
endif
endif
endfunction
function GroundMade takes nothing returns nothing //地面类型处理
local real Center_X = udg_TopLeftCorner_X + I2R ( ( GridID - GridID / udg_Length_X * udg_Length_X ) * 1152 + 576 )
local real Center_Y = udg_TopLeftCorner_Y + I2R ( GridID / udg_Length_X * 1152 + 576 )
local integer Labyrinth = udg_Labyrinth [ GridID ]
if udg_Labyrinth [ GridID ] - 32768 > 0 then
if Labyrinth - Labyrinth / 2 * 2 == 1 then //下endif
if Labyrinth - Labyrinth / 4 * 4 > = 2 then //右下
endif
if Labyrinth - Labyrinth / 8 * 8 > = 4 then //右endif
if Labyrinth - Labyrinth / 16 * 16 > = 8 then //右上
endif
if Labyrinth - Labyrinth / 32 * 32 > = 16 then //上endif
if Labyrinth - Labyrinth / 64 * 64 > = 32 then //左上
endif
if Labyrinth - Labyrinth / 128 * 128 > = 64 then //左endif
if Labyrinth - Labyrinth / 256 * 256 > = 128 then //左下
endif
else
//未使用
endif
set udg_DoingOverNum = udg_DoingOverNum + 1
endfunction
function TerrainPathableMake takes nothing returns nothing //单格地面通行处理
local real Center_X = udg_TopLeftCorner_X + I2R ( ( GridID - GridID / udg_Length_X * udg_Length_X ) * 1152 + 576 )
local real Center_Y = udg_TopLeftCorner_Y + I2R ( GridID / udg_Length_X * 1152 + 576 )
loop
call TerrainPathable ( Center_X,Center_Y,i )
set i = i + 1
exitwhen i == 81
endloop
set udg_DoingOverNum = udg_DoingOverNum + 1
endfunction
function Main_StartF takes nothing returns nothing //全部完成提示
if udg_DoingOverNum > = udg_Length_X * udg_Length_Y then
else
return
endif
endfunction
function Main_StartE takes nothing returns nothing //地面通行处理
if udg_DoingOverNum > = udg_Length_X * udg_Length_Y then
else
return
endif
call BJDebugMsg ( "地面纹理处理完成" )
set udg_DoingOverNum = 0
loop
call TimerStart ( I2T ( udg_FirstTimer + GridID ) , 0 , false , function TerrainPathableMake )
set GridID = GridID + 1
exitwhen GridID > = udg_Length_X * udg_Length_Y
endloop
endfunction
function Main_StartD takes nothing returns nothing //地面纹理处理
loop
if Get01 ( GridID, 14 ) == 1 then
set udg_EndWay [ udg_EndWayNum ] = GridID
set udg_EndWayNum = udg_EndWayNum + 1
endif
call TimerStart ( I2T ( udg_FirstTimer + GridID ) , 0 , false , function GroundMade )
set GridID = GridID + 1
exitwhen GridID > = udg_Length_X * udg_Length_Y
endloop
set udg_EndWayNum = udg_EndWayNum - 1
endfunction
fun

greatcw22 发表于 2012-1-3 16:10:28

虽然看不懂,但还是要感谢前辈给我一个嘲讽的机会:Tinker算啥呀...

lizy 发表于 2012-4-26 18:56:35

eeeeeeeeeeeee

q1430058202 发表于 2012-5-19 00:18:48

感谢楼主正好研究研究

w614172125 发表于 2012-7-29 09:11:28

= =。。。。

薛仁贵 发表于 2012-9-6 13:30:12

qq244109924 发表于 2011-4-19 19:45 static/image/common/back.gif
火星语么?

{:4_139:}
页: [1]
查看完整版本: 随机迷宫系统