Hello!
I know that I can just get some code from the challenges, but I want to code it myself.
anyway, why isn't this working?
rem setup screen
sync on
sync rate 60
backdrop on
color backdrop 0
hide mouse
randomize timer()
rem dimensions
rooms=2
dim maze_width(60)
dim maze_height(60)
dim roomx(rooms)
dim roomy(rooms)
rem create random sized rooms
roomlength=4
roomheight=4
room_min=2
for t=1 to rooms
rem define random space
repeat
startx=rnd(59)
starty=rnd(59)
length=rnd(roomlength)+room_min
height=rnd(roomheight)+room_min
endx=startx+length
endy=starty+height
if endx>59 then endx=59
if endy>59 then endy=59
rem check if it doesn`t already exist
success=1
for x=startx to endx
for y=starty to endy
if maze_width(x)=1 and maze_height(y)=1 then success=0
next y
next x
until success=1
rem store start of room
roomx(t)=startx
roomy(t)=starty
rem store the random space in arrays
for x=startx to endx
for y=starty to endy
maze_width(x)=1
maze_height(y)=1
next y
next x
next t
rem make paths from each room
for t=1 to rooms-1
startx=roomx(t)+rnd(room_min)
starty=roomy(t)+rnd(room_min)
endx=roomx(t+1)+rnd(room_min)
endy=roomy(t+1)+rnd(room_min)
rem set arrays for x axis
if startx>endx
for x=endx to startx
maze_width(x)=1
maze_height(starty)=1
next x
else
for x=startx to endx
maze_width(x)=1
maze_height(starty)=1
next x
endif
rem set arrays for y axis
if starty>endy
for y=endy to starty
maze_width(endx)=1
maze_height(y)=1
next y
else
for y=starty to endy
maze_width(endx)=1
maze_height(y)=1
next y
endif
next t
rem draw map
create bitmap 1,300,300
for x=0 to 59
for y=0 to 59
if maze_width(x)=1 and maze_height(y)=1
ink rgb(255,0,0),0
box x*5,y*5,(x*5)+5,(y*5)+5
endif
next y
next x
get image 1,0,0,300,300
delete bitmap 1
sprite 1,0,0,1
wait key
end
It is supposed to generate random, non-overlapping rooms, and make paths between them.
But, the rooms are all screwed up, they appear always perfectly aligned and not random, and the paths just fill the space between the rooms, not creating a path at all...
Please, please help!
TheComet
Peachy, and the Chaos of the Gems
