LBFN if you look closely at the loadroom() function in the snippet i posted (which i will post again here because i have slightly improved it), it stores image numbers in a 36x24x24 "coord" array. in fact, collision detection in the moveplayer() function relies on information from this array. thats the same as the method you want to use no? about sprites vs images, i see what you mean, using sprites would require a lot of cleanup. the only reason i was suggesting it was that the collision detection code would be less clunky, but i realise that images are probably a better option. the burnroom() function you are using is the same thing as the loadroom() one i am using, except for different variables. would it be acceptable if i just added 18 room designs to the loadroom() one? the image numbers for inside wall tiles are, again, stored in the format coord(room,x,y) in an array. if i start working on the other format i would have to scrap all my work on maze generation and write it again for yours, with different arrays and a different system.
` DNG - Berzerk! Began 23/8/2011
sync on : sync rate 60
randomize timer()
#constant false 0
#constant true 1
global ScrWid, ScrHgt, GameState, GameOver, score, CurrSprite, CurrImage, StackNum, RoomNumber, NumberVisited, Roomchange
GameState = false : GameOver = false : score = false : CurrSprite = 99 : CurrImage = 99
RezOkay = CheckRez()
if RezOkay = false
a$ = "Sorry, screen resolution for this game not available."
b$ = "Press any key to exit."
repeat
center text ScrWid / 2,ScrHgt / 2, a$
center text ScrWid / 2, ScrHgt - 100,b$
sync
until scancode() > false
end
endif
set display mode 1024,768,32
ScrWid = screen width() : ScrHgt = screen height()
set window on
set window title " DNG - BerZerk!"
dw = desktop width() : dh = desktop height()
set window position (dw - ScrWid) / 2, (dh - ScrHgt) / 2
//setup room TYPE variable
type direction
n as integer
s as integer
e as integer
w as integer
endtype
type RoomData
door as direction
exitflag as boolean
visited as boolean
design as integer
corner as direction
endtype
dim maze(48) as RoomData
dim done(36) as integer
dim coord(36,24,24) as integer
// setup player TYPE variable
type PlayerData
lives, image, EnterX, EnterY, XSpeed, YSpeed, AnimDelay
LowImage, HighImage, Room, X, Y
endtype
player as PlayerData
// setup robot TYPE variable. We don't know how many robots we will need
// so we set it up with zero and add to it at SetupRobots()
type RobotData
status, image, XSpeed, YSpeed, AnimDelay, LowImage, HighImage
endtype
dim robot(0) as RobotData
Init()
LoadImages()
SetupMaze()
DrawMaze()
sync
sync
wait key
cls
SetupPlayer()
SetupRobots()
roomchange=1
player.room=rnd(36)+6
// Main Game loop
repeat
GameState = MainMenu()
select GameState
case 1
cls
// play game
remstart
input "what room do you want to know about?", roomnum
print "exits:"
if maze(roomnum+6).door.n=1 then print "up"
if maze(roomnum+6).door.s=1 then print "down"
if maze(roomnum+6).door.e=1 then print "right"
if maze(roomnum+6).door.w=1 then print "left"
remend
LoadRoom()
if roomchange=1
Setplayer()
endif
MovePlayer()
MoveRobots()
MoveEvilOtto()
MoveShots()
text 800,0,"You are in Room "+STR$(player.room-6)
text 800,50,"Co-ordinates"+STR$(player.x)+","+STR$(player.y)
sync
endcase
case 2
// device input
endcase
case 3
//difficulty
endcase
case 4
// sound FX options
endcase
case 5
// high scores
endcase
case 6
// quit
GameOver = true
endcase
endselect
if mouseclick() > false then GameOver = true
until GameOver = true
DeleteAll()
end
function MovePlayer()
circle player.x,player.y,10
if upkey()
dec player.y,3
if coord(player.room-6,int(player.x/32)+1,int(player.y/32)+1)>0
inc player.y,3
endif
endif
if leftkey()
dec player.x,3
if coord(player.room-6,int(player.x/32)+1,int(player.y/32)+1)>0
inc player.x,3
endif
endif
if downkey()
inc player.y,3
if coord(player.room-6,int(player.x/32)+1,int(player.y/32)+1)>0
dec player.y,3
endif
endif
if rightkey()
inc player.x,3
if coord(player.room-6,int(player.x/32)+1,int(player.y/32)+1)>0
dec player.x,3
endif
endif
if player.x>764 then roomchange=1: inc player.room
if player.x<4 then roomchange=1: dec player.room
if player.y>764 then roomchange=1: player.room=player.room+6
if player.y<4 then roomchange=1: player.room=player.room-6
endfunction
function MoveRobots()
endfunction
function MoveEvilOtto()
endfunction
function MoveShots()
endfunction
function CheckRez()
if check display mode(1024,768,32) = false then exitfunction 0
endfunction 1
function Init()
endfunction
function LoadImages()
endfunction
function SetupMaze()
//provide corner information before starting
for i=1 to 6
maze(i+6).corner.n=1
next i
for i= 1 to 31 step 6
maze(i+6).corner.w=1
next i
for i = 6 to 36 step 6
maze(i+6).corner.e=1
next i
for i=31 to 36
maze(i+6).corner.s=1
next i
//choose random cell
stacknum=1
roomnumber=1+rnd(35)
numbervisited=1
maze(roomnumber+6).visited=1
done(stacknum)=roomnumber
//generate maze
while numbervisited<36
moved=0 `variable to establish whether the generator has moved to another cell in this cycle
badbearing=0 `variable to establish what directions the generator should not move in
bearing=rnd(4) `randomize initial direction
repeat
if bearing=1 and maze(roomnumber+6).corner.n=0 `(all the plus 6s are because darkbasic is annoying and checks nested ifs even if the outside one is false)
if maze(roomnumber-6+6).visited=0
maze(roomnumber-6+6).door.s=2+rnd(21)
maze(roomnumber+6).door.n=maze(roomnumber-6+6).door.s
roomnumber=roomnumber-6
done(stacknum)=roomnumber
stacknum=stacknum+1
maze(roomnumber+6).visited=1
moved=1
inc numbervisited
endif
endif
if bearing=2 and maze(roomnumber+6).corner.e=0 `as an example, if the direction determined is east, it checks if the room is on the eastern wall...
if maze(roomnumber+1+6).visited=0 `then checks if it hasn't already visited and adjusted that cell...
maze(roomnumber+1+6).door.w=2+rnd(21) `then makes a door in that cell pointing where you came from...
maze(roomnumber+6).door.e=maze(roomnumber+1+6).door.w `and a door in the cell you came from pointing to where you've come...
roomnumber=roomnumber+1 `then updates what room number you're in...
done(stacknum)=roomnumber `and stores it in a stack.
stacknum=stacknum+1 `increment stack index
maze(roomnumber+6).visited=1 `set the visited flag to one for the room you're in
moved=1 `tell the loop you've moved to an adjacent room.
inc numbervisited `increment the number of cells that have already been adjusted
endif
endif
if bearing=3 and maze(roomnumber+6).corner.s=0
if maze(roomnumber+6+6).visited=0
maze(roomnumber+6+6).door.n=2+rnd(21)
maze(roomnumber+6).door.s=maze(roomnumber+6+6).door.n
roomnumber=roomnumber+6
done(stacknum)=roomnumber
stacknum=stacknum+1
maze(roomnumber+6).visited=1
moved=1
inc numbervisited
endif
endif
if bearing=4 and maze(roomnumber+6).corner.w=0
if maze(roomnumber-1+6).visited=0
maze(roomnumber-1+6).door.e=2+rnd(21)
maze(roomnumber+6).door.w=maze(roomnumber-1+6).door.e
roomnumber=roomnumber-1
done(stacknum)=roomnumber
stacknum=stacknum+1
maze(roomnumber+6).visited=1
moved=1
inc numbervisited
endif
endif
if moved=0 `if you haven't moved,
inc bearing `it could be because the direction was blocked, check another
if bearing=5 then bearing=1 `bearing should be modulo4
inc badbearing `tells the loop how many directions you've tried
endif
until moved=1 or badbearing=3 `the generator has either moved or
if moved = 0 `it didnt move and it has walked into a dead end
done(stacknum)=0 `it goes back till it finds a room with available neighbors
stacknum=stacknum-1
roomnumber=done(stacknum)
endif
endwhile `do it again till all rooms have been visited
maze(42).door.e=2+rnd(21)
maze(42).exitflag=1
endfunction
function SetupPlayer()
endfunction
function SetupRobots()
endfunction
function MainMenu()
// paste the graphic up
GameState = 1 : // play game - allows the game code to run
//show mouse
endfunction GameState
function DeleteAll()
// deletes all images and sprites prior to exiting the game
endfunction
function GetFreeSprite()
repeat
inc CurrSprite
until sprite exist(CurrSprite) = false
endfunction CurrSprite
function GetFreeImage()
repeat
inc CurrImage
until image exist(CurrImage) = false
endfunction CurrImage
function Debug()
// shows info needed during development
endfunction
function LoadRoom()
ink rgb(0,0,255),0
box 0,0,32,32
walltile=getfreeimage()
get image walltile,0,0,32,32
cls
for i = 1 to 24
if maze(player.room).door.n=i
else
paste image walltile,(i-1)*32,0
coord(player.room-6,i,1)=walltile
endif
if maze(player.room).door.w=i
else
paste image walltile,0,(i-1)*32
coord(player.room-6,1,i)=walltile
endif
if maze(player.room).door.e=i
else
paste image walltile,736,(i-1)*32
coord(player.room-6,24,i)=walltile
endif
if maze(player.room).door.s=i
else
paste image walltile,(i-1)*32,736
coord(player.room-6,i,24)=walltile
endif
next i
endfunction
//temporary function
function DrawMaze()
for i=1 to 6
if maze(i+6).door.s=0 then line ((i-1)*106), 80, i*106, 80
if maze(i+6).door.e=0 then line i*106,0,i*106,80
next i
for i=1 to 6
if maze(i+12).door.s=0 then line ((i-1)*106), 160, i*106, 160
if maze(i+12).door.e=0 then line i*106,80,i*106,160
next i
for i=1 to 6
if maze(i+18).door.s=0 then line ((i-1)*106), 240, i*106, 240
if maze(i+18).door.e=0 then line i*106,160,i*106,240
next i
for i=1 to 6
if maze(i+24).door.s=0 then line ((i-1)*106), 320, i*106, 320
if maze(i+24).door.e=0 then line i*106,240,i*106,320
next i
for i=1 to 6
if maze(i+30).door.s=0 then line ((i-1)*106), 400, i*106, 400
if maze(i+30).door.e=0 then line i*106,320,i*106,400
next i
for i=1 to 6
if maze(i+36).door.s=0 then line ((i-1)*106), 480, i*106, 480
if maze(i+36).door.e=0 then line i*106,400,i*106,480
next i
line 0,0,0,480
line 0,0,640,0
endfunction
function DesignRoom()
for i=1 to 36
if maze(i).corner.n and maze(i).corner.e then maze(i).design = rnd(6)
if maze(i).corner.s and maze(i).corner.n then maze(i).design = 6 + rnd(6)
next i
//you get the picture, check doors then choose from available designs that fit room's specs. designs 1 to 6 for instance are for rooms that have north and right doors.
endfunction
function SetPlayer()
player.x=32+rnd(704)
player.y=32+rnd(704)
roomchange=0
endfunction
EDIT: YAY IM OFF POST APPROVAL
Darkseid?