Okay. I got it working. I had to replace rnd min max with my own homemade version of the process. Hmm.
Thanks for the help.
rem Requires Matrix1 plugin (for random(), min, max, save current bitmap)
remstart
Adapted from dungeon.py for Blender, included in dungeon_generator_v0.2.blend.zip
-----Original author's statement:-----
# Dungeon creation script
# Alt-p to execute
#
# author: Arnaud Couturier (piiichan)
# location: New Caledonia (Pacific island)
# date: March 2009 (Blender 2.48)
# version: 0.2
# license: free for any use
# rationale:
# This script allows you to create dungeon-like levels
---------------------------------------
Defaults
width = 300
length = 300
minsize = 2
maxsize = 20
totrooms = 20
probturn# = 0.1
probroom# = 0.01
remend
sync on: sync rate 60
Set display mode 1024, 768, 32
gosub _init_generator_vars
ink rgb(255,255,255),rgb(0,0,0)
map_drawn = 0
set current bitmap 0
do
box (width+2)*dispsize, 0, (width+3)*dispsize, (length+3)*dispsize
box 0, (length+2)*dispsize, (width+3)*dispsize, (length+3)*dispsize
set cursor 0,(length+10)*dispsize
print "Random Dungeon Generator - adapted from a Blender script by piiichan."
print "Press 'r' to draw random dungeon"
print "Press 's' to save drawn dungeon to "+filename$
print "Press 'w' to write "+filename$+" without drawing to screen."
if inkey$() = "r"
repeat until inkey$() <> "r"
generate(width,length,minsize,maxsize,totrooms,probturn#,probroom#,colors,filename$,usecolor,dispsize,0)
map_drawn = 1
endif
if inkey$() = "s" and map_drawn = 1 and dispsize = 1
repeat until inkey$() <> "s"
saveLevel2(width,length,filename$)
endif
if inkey$() = "w"
repeat until inkey$() <> "w"
generate(width,length,minsize,maxsize,totrooms,probturn#,probroom#,colors,filename$,usecolor,dispsize,1)
map_drawn = 0
endif
if inkey$() = "z" and map_drawn = 1
repeat until inkey$() <> "z"
dispsize = (1 - (dispsize-1))+1
generate(width,length,minsize,maxsize,totrooms,probturn#,probroom#,colors,filename$,usecolor,dispsize,2)
endif
sync
loop
end
_init_generator_vars:
rem ===== Begin user-configurable variables =====
filename$ = "dungeontest.bmp"
usecolor = 1
dispsize = 1
width = 200
length = 200
minsize = 5
maxsize = 20
totrooms = 10
probturn# = 0.1
probroom# = 0.01
dim colors(9,3)
colors(1,1) = 0 `black
colors(1,2) = 0
colors(1,3) = 0
colors(2,1) = 255 `white
colors(2,2) = 255
colors(2,3) = 255
colors(3,1) = 255 `red
colors(3,2) = 0
colors(3,3) = 0
colors(4,1) = 0 `green
colors(4,2) = 255
colors(4,3) = 0
colors(5,1) = 0 `blue
colors(5,2) = 0
colors(5,3) = 255
colors(6,1) = 255 `yellow
colors(6,2) = 255
colors(6,3) = 0
colors(7,1) = 192 `purple
colors(7,2) = 0
colors(7,3) = 192
colors(8,1) = 255 `orange
colors(8,2) = 128
colors(8,3) = 0
colors(9,1) = 128 `gray
colors(9,2) = 128
colors(9,3) = 128
rem ===== End user vars =====
return
function generate(width,length,minsize,maxsize,totrooms,probturn#,probroom#,colors,filename$,usecolor,dispsize,use)
cls
if use < 2
pixels = DungeonGenerator(width,length,minsize,maxsize,totrooms,probturn#,probroom#,colors,usecolor)
endif
if use = 0 or use = 2 then drawLevel(pixels,width,length,colors,dispsize)
if use = 1 then saveLevel1(pixels,width,length,filename$,colors)
endfunction
function DungeonGenerator(width,length,minsize,maxsize,totrooms,probturn#,probroom#,colors,usecolor)
rem Carves the dungeon like a worm.
rem Returns a list of positions (x,y) inside the dungeon where rooms are to be created later.
dim pixels(width,length)
dim direx(2)
dim roomdims(4)
dim rooms(totrooms,3)
if usecolor = 1
color = 1 + rnd(7) `Random color from the palette
else
color = 1
endif
for i=1 to width `Fill the array background with black
for j=1 to length
pixels(i,j) = 0
next j
next i
halfmin = (minsize/2)+1
halmax = (maxsize/2)+1
wormX = (width/2)+1
wormY = (length/2)+1
lvlRooms = 1
direx(1) = 1
direx(2) = 0
rem carve first room at starting point
rooms(1,1) = wormX : rooms(1,2) = wormY : rooms(1,3) = color
rem carve current dungeon level
while lvlRooms < totrooms
nextX = wormX + direx(1)
nextY = wormY + direx(2)
rem if next move is not valid or if the worm decides to change its direction: change direction
if nextX <= 1 or width <= nextX or nextY <= 1 or length <= nextY or random() < probturn#
if direx(1) <> 0 `was along x
direx(1) = 0
if rnd(10) >= 5
direx(2) = -1
else
direx(2) = 1
endif
else ` was along y
direx(2) = 0
if rnd(10) >= 5
direx(1) = -1
else
direx(1) = 1
endif
endif
nextX = wormX + direx(1)
nextY = wormY + direx(2)
if usecolor = 1 and random() < 0.2 then color = 1 + rnd(7)
endif
rem if after changing the direction, the next move is still not valid, the worm must face the opposite direction
if nextX <= 1 or width <= nextX or nextY <= 1 or length <= nextY
direx(1) = -direx(1)
direx(2) = -direx(2)
nextX = wormX + direx(1)
nextY = wormY + direx(2)
if usecolor = 1 and random() < 0.2 then color = 1 + rnd(7)
endif
rem move + carve
wormX = nextX
wormY = nextY
pixels(wormX,wormY) = color
rem place room
if random() < probroom#
lvlRooms = lvlRooms + 1
rooms(lvlRooms,1) = wormX : rooms(lvlRooms,2) = wormY : rooms(lvlRooms,3) = color
endif
endwhile
for room=1 to totrooms `Create the rooms
color = rooms(room,3)
if usecolor = 1 and random() < 0.2 then color = 1 + rnd(7)
roomdims = carveRoom(roomdims,halfmin,halfmax,width,length,rooms(room,1),rooms(room,2))
for i=roomdims(1) to roomdims(3)
for j=roomdims(2) to roomdims(4)
pixels(i,j) = color
next j
next i
next room
endfunction pixels
function carveRoom(roomdims,halfmin,halfmax,width,length,wormX,wormY):
rem "Carve" out the rooms
dim roomvals(4,2)
roomvals(1,1) = max(1, (wormX - halfmin)) `min x
roomvals(1,2) = max(1, (wormX - halfmax))
roomvals(2,1) = max(1, (wormY - halfmin)) `min y
roomvals(2,2) = max(1, (wormY - halfmax))
roomvals(3,1) = min(width, (wormX + halfmin)) `max x
roomvals(3,2) = min(width, (wormX + halfmax))
roomvals(4,1) = min(length, (wormY + halfmin)) `max y
roomvals(4,2) = min(length, (wormY + halfmax))
for i=1 to 4
rem use home-made random min max - Community funcs version kept crashing us.
roomdims(i) = roomvals(i,1) + rnd(roomvals(i,2)-roomvals(i,1))
next i
endfunction roomdims
function drawLevel(pixels,width,length,colors,dispsize)
rem Draw the pixels array to the screen
set current bitmap 0
for i=1 to length
for j=1 to width
pixel = pixels(i,j)
r = colors(pixel+1,1)
g = colors(pixel+1,2)
b = colors(pixel+1,3)
dot (i-1)*dispsize,(j-1)*dispsize,rgb(r,g,b)
next j
next i
endfunction
function saveLevel1(pixels,width,length,filename$,colors)
rem Save bitmap using Matrix1 plugin's save current bitmap
cls
map = 1
create bitmap map,width,length
for i=1 to length
for j=1 to width
pixel = pixels(i,j)
r = colors(pixel+1,1)
g = colors(pixel+1,2)
b = colors(pixel+1,3)
dot i-1,j-1,rgb(r,g,b)
next j
next i
save current bitmap filename$
set current bitmap 0
endfunction
function saveLevel2(width,length,filename$)
rem Save bitmap using get image & save image
map = 1
get image map,1,1,width+1,length+1,3
save image filename$,map
endfunction