Thanks for the positive comments.
Okay, final version:
It now has a pointer to help you to find the end marker. The walls are much taller than before; just something I liked better. There are more enemies, twice as many in fact. It also generates a random maze now.
` LBFN DBC CHALLENGE - MAZE GAME
set display mode 800,600,32
sync on : sync rate 60
randomize timer()
hide mouse
sw = screen width()
sh = screen height()
backdrop on
color backdrop rgb(18,18,18)
autocam off
MapWidth = 32
MapHeight = 32
UnitSize = 200
maxw = Mapwidth-3
maxh = MapHeight-3
pointer = 49900
TotalWalls = 0 : TotalFloors = 0 : TotalEnemies = 40
fog on
fog color rgb(18,18,18)
fog distance 1500
set camera range 1,2000
set ambient light 55
cls
dim map$(mapwidth,mapheight) : dim EnemySpeed(TotalEnemies)
`gosub StoreMap
gosub MakeMaze
MakeImages()
gosub PickFinal
`gosub MakeCeiling
player = 1
make object sphere player,10
set object collision on player
make object collision box player,-5,-5,-5,5,5,5,0
hide object player
okay = 0
gosub GetPlayerXY
gosub MakeEnemies
gosub FixMaze
gosub ShowMap
make object cone pointer,30
texture object pointer,2319
xrotate object pointer,90.0
fix object pivot pointer
cls
get image 999,0,0,170,45
draw to front
ty#=camera position y()
ink rgb(255,0,0),0
StartTime#=timer()
u#=.1
rem Main Loop ______________________________________________________________________________________________
do
text 100,10,"FPS = "+str$(screen fps() )
` center text sw/2,10,"Time:"+str$(int(timer()-StartTime#)/1000)
camx#=camera position x() : oldx#=camx#
camy#=camera position y() : oldy#=camy#
camz#=camera position z() : oldz#=camz#
position object player,camx#,camy#,camz#
set object to camera orientation player
move object player,10
position object pointer,camx#,camy#+42.0,camz#
set object to camera orientation pointer
move object pointer,100
if u#<3.0
u#=u#+.0000001
else
u#=0.001
endif
scroll object texture pointer,0.0,u#
point object pointer,tx#,ty#,tz#
y#=camera angle y()
yrotate camera wrapvalue(y#+mousemovex() )
camx#=camera position x()
camy#=camera position y()
camz#=camera position z()
position object player,camx#,camy#,camz#
set object to camera orientation player
move object player,10
y#=object angle y(20)
yrotate object 20,wrapvalue(y#+6.0)
mc=mouseclick()
if mc=1
move camera 10 : move object player,10
gosub CheckCollision
if hit = 1 then move camera -10 : move object player,-10
endif
if mc=2
move camera -10 : move object player,-10
gosub CheckCollision
if hit = 1 then move camera 10 : move object player,10
` gosub DP_Map
endif
` if upkey()=1
` camy#=camy#+5.0
` position camera camx#,camy#,camz#
` endif
` if downkey()=1
` camy#=camy#-5.0
` position camera camx#,camy#,camz#
` endif
if spacekey()=1 then exit
gosub CheckWinner
gosub MoveEnemies
gosub CheckEnemyCollision : if hit = 1 then gosub P1Died
sync
loop
rem Main Loop ______________________________________________________________________________________________
show mouse
end
Restart:
gosub MakeMaze
gosub PickFinal
gosub GetPlayerXY
gosub FixMaze
gosub ShowMap
gosub MakeEnemies
StartTime#=timer()
if object exist(9000)=1 then hide object 9000
return
P1Died:
if object exist(9000)=0
make object plain 9000,screen width()+100,screen height()+100
endif
show object 9000
position object 9000,camx#,camy#,camz#
set object to camera orientation 9000
move object 9000,50
rg = 255
color object 9000,rgb(rg,rg,rg)
OldTime#=timer()
time# = timer()+3000.0
repeat
t#=timer()
if (t#-OldTime#)>59.0
dec rg,5
color object 9000,rgb(rg,rg,rg)
OldTime#=timer()
endif
sync
until timer()>time#
color backdrop rgb(18,18,18)
gosub Restart
return
MakeEnemies:
EnemyObj=25000
while EnemyObj<(25000 + TotalEnemies)
for z=1 to MapHeight
for x=1 to MapWidth
if map$(x,z)="_" and rnd(1000)>970 and EnemyObj<(25000 + TotalEnemies)
` make enemy
x# = (x*UnitSize)
z# = (z*UnitSize)
camx#=camera position x()
camy#=camera position y()
camz#=camera position z()
c# = (camx# - x#) : c# = c# * c#
d# = (camz# - z#) : d# = d# * d#
dist# = sqrt(c# + d#)
if dist#>750.0
if object exist(EnemyObj)=0
make object sphere EnemyObj,50
yrotate object EnemyObj,145.0
fix object pivot EnemyObj
endif
position object EnemyObj,x#,25.0,z#
texture object EnemyObj,12
set object collision on EnemyObj
make object collision box EnemyObj,-25,-25,-25,25,25,25,0
EnemySpeed(EnemyObj-24999)=rnd(3)+3
inc EnemyObj,1
endif
endif
next x
next z
endwhile
return
MoveEnemies:
For enemy = 25000 to (25000 + TotalEnemies-1)
point object enemy,camx#,camy#,camz#
e=enemy-24999
move object enemy,EnemySpeed(e)
for f = 200 to TotalWalls
if object collision(enemy,f)=1 then move object enemy,0-EnemySpeed(e) : exit
next f
next enemy
return
CheckCollision:
hit = 0
oldcamx#=camera position x()
oldcamy#=camera position y()
oldcamz#=camera position z()
for f = 200 to TotalWalls
if object collision(player,f)=1 then hit = 1
next f
return
CheckEnemyCollision:
hit = 0
for e = 25000 to (25000 + TotalEnemies)
if object collision(player,e)=1 then hit = 1 : P1Died = 1
next e
return
StoreMap:
restore MapData
for y=1 to mapheight
read a$
for x=1 to len(a$)
map$(x,y)=mid$(a$,x)
next x
next y
gosub PickFinal
return
PickFinal:
` pick random spot for the final
x=rnd(mapWidth-10)+6
z=rnd(MapHeight-10)+6
map$(x-1,z)="_" : map$(x,z)="_" : map$(x+1,z)="_"
map$(x-1,z+1)="_" : map$(x,z+1)="_" : map$(x+1,z+1)="_"
map$(x-1,z-1)="_" : map$(x,z-1)="_" : map$(x+1,z-1)="_"
map$(x,z)="F"
tx# = (x*UnitSize) : ty# = 50.0 : tz# = (z*UnitSize)
a = rnd(3)
if a = 0 then map$(x-2,z)="_" : map$(x-3,z)="_"
if a = 1 then map$(x,z-2)="_" : map$(x,z-3)="_"
if a = 2 then map$(x+2,z)="_" : map$(x+3,z)="_"
if a = 3 then map$(x,z+2)="_" : map$(x,z+3)="_"
rem make light at the end of the zone
if object exist(20)=0
make object cone 20,100
zrotate object 20,180.0
scale object 20,200.0,500.0,200.0
endif
position object 20,tx#,ty#+200.0,tz#
color object 20,rgb(0,0,225)
ghost object on 20
return
GetPlayerXY:
okay = 0
tries = 0
repeat
x = rnd(20)+6 : z = rnd(20)+6
x# = (x*UnitSize)
z# = (z*UnitSize)
c# = abs(tx# - x#) : c# = c# * c#
d# = abs(tz# - z#) : d# = d# * d#
dist# = sqrt(c# + d#)
if dist#>3000.0 or tries>100
okay = 1
map$(x-1,z-1)="_" : map$(x,z-1)="_" : map$(x+1,z-1)="_"
map$(x-1,z)="_" : map$(x,z)="_" : map$(x+1,z)="_"
map$(x-1,z+1)="_" : map$(x,z+1)="_" : map$(x+1,z+1)="_"
playerX=x
playerZ=z
position camera playerX*UnitSize,50.0,playerZ*UnitSize
a = rnd(3)
if a = 0 then map$(x-2,z)="_"
if a = 1 then map$(x,z-2)="_"
if a = 2 then map$(x+2,z)="_"
if a = 3 then map$(x,z+2)="_"
endif
inc tries,1
until okay = 1
return
function MakeImages()
` wall
create bitmap 2,256,256
ink rgb(119,41,9),0
box 0,0,255,255
ink rgb(190,190,190),0
box 0,0,255,5 : box 62,0,67,57
box 190,0,195,57
box 0,54,255,57 : box 0,54,4,108
box 128,54,133,108
box 0,104,255,108 : box 40,104,45,157
box 101,104,106,157 : box 200,104,205,157
box 0,155,255,159 : box 12,155,17,208
box 133,155,138,208 : box 0,204,255,208
box 68,204,73,255 : box 195,204,200,255
box 0,251,255,255
get image 43,0,0,255,255
` floor
cls
ink rgb(130,116,71),0
box 0,0,255,255
ink rgb(0,98,197),0
box 3,3,250,250
ink rgb(130,116,71),0
box 64,64,190,190
ink rgb(0,98,197),0
box 96,96,157,157
get image 53,0,0,255,255
` mad face
cls
ink rgb(255,255,0),0
box 0,0,255,255
ink rgb(18,18,18),0
box 67,77,82,100
line 71,73,78,73 : line 70,74,79,74
line 69,75,80,75 : line 68,76,81,76
line 68,101,81,101 : line 69,102,80,102
line 70,103,79,103 : line 71,104,78,104
get image 19000,67,73,83,105
paste image 19000,117,73
delete image 19000
line 84,137,118,137 : line 81,138,121,138 : line 79,139,123,139
line 77,140,125,140 : line 76,141,126,141 : line 75,142,127,142
line 74,143,128,143 : line 73,144,89,144 : line 112,144,129,144
line 73,145,85,145 : line 117,145,129,145 : line 72,146,80,146
line 122,146,130,146 : line 71,147,79,147 : line 123,147,131,147
line 71,148,78,148 : line 124,148,131,148 : line 70,149,77,149
line 125,149,132,149 : line 70,150,76,150 : line 126,150,132,150
line 69,151,75,151 : line 127,151,133,151 : line 69,152,74,152
line 128,152,133,152 : line 69,153,74,153 : line 128,153,133,153
line 69,154,73,154 : line 129,154,133,154
get image 12,0,0,255,255
` pointer texture
cls
ink rgb(255,0,0),0
box 0,0,127,21
ink rgb(0,183,91),0
box 0,22,127,127
get image 2319,0,0,128,128
delete bitmap 2
set current bitmap 0
endfunction
MakeMaze:
cls
set text size 26
backdrop off
t# = timer()
center text sw/2,sh/2,"Generating maze...." : sync
` set all of map to "W"
sync rate 0
for z=1 to mapheight
for x=1 to mapwidth
map$(x,z)="W"
next x
next z
for g=1 to 8
Column=rnd(28)+2
for z=2 to mapheight-1
map$(column,z)="_"
a=rnd(2)+1
if a=1 and column>2 then dec column,1 : map$(column,z)="_"
if a=2 and column<(mapwidth-2) then inc column,1 : map$(column,z)="_"
next z
next g
for g=1 to 8
Row=rnd(28)+2
for x=2 to mapwidth-1
map$(x,row)="_"
a=rnd(2)+1
if a=1 and row>2 then dec row,1 : map$(x,row)="_"
if a=2 and row<(mapheight-2) then inc row,1 : map$(x,row)="_"
next x
next g
repeat
ink rgb(rnd(255),rnd(255),rnd(255)),0
center text sw/2,sh/2,"Generating maze...."
sync
until timer()>t#+1000.0
sync rate 60
backdrop on
return
FixMaze:
repeat
resolved = 0
for z=3 to mapheight-2
for x=3 to mapwidth-2
if map$(x,z)="_"
num = 0 : left = 0 : up = 0 : right = 0 : down = 0
if map$(x-1,z)="_" then left = 1 : inc num,1
if map$(x,z-1)="_" then up = 1 : inc num,1
if map$(x+1,z)="_" then right = 1 : inc num,1
if map$(x,z+1)="_" then down = 1 : inc num,1
if num<=1
okeydokey = 0 : resolved = 1
repeat
a = rnd(3)
if a = 0 and left = 0 then map$(x-1,z) = "_" : okeydokey = 1
if a = 1 and up = 0 then map$(x,z-1) = "_" : okeydokey = 1
if a = 2 and right = 0 then map$(x+1,z) = "_" : okeydokey = 1
if a = 3 and down = 0 then map$(x,z+1) = "_" : okeydokey = 1
until okeydokey = 1
endif
endif
next x
next z
until resolved = 0
return
CheckWinner:
c# = (camx# - tx#) : c# = c# * c#
d# = (camz# - tz#) : d# = d# * d#
dist# = sqrt(c# + d#)
` text 200,10,str$(dist#)
if dist#<=150.0
t#=int((timer()-StartTime#)/1000)
ink rgb(255,255,0),0
repeat
center text sw/2,200,"You are the Winner!!!"
` center text sw/2,220,"You made it in "+str$(t#)+" seconds!"
center text sw/2,400,"Press [Return] to play again."
center text sw/2,420,"Press [ESC] to quit."
sync
rt = returnkey()
until rt=1 or escapekey()=1
if rt = 1
rt = 0 : gosub RESTART
repeat
sync
until keystate(28)=0
endif
endif
return
MakeCeiling:
` make image
create bitmap 2,512,512
ink rgb(96,96,96),0
box 0,0,511,511
get image 7,0,0,512,512
set current bitmap 0
delete bitmap 2
make object plain 11000,6400,6400
texture object 11000,7
rotate object 11000,90.0,0.0,0.0
set object collision off 11000
position object 11000,3200.0,498.0,3200.0
return
DP_Map:
for f = 200 to TotalWalls
hide object f
next f
for f = 1000 to TotalFloors
hide object f
next f
hide object pointer
backdrop off
cls
sync
cx=int((camx#+100)/200)
cz=int((camz#+100)/200)
for z=1 to mapheight
for x=1 to mapwidth
if x=cx and z=cz
ink rgb(0,255,0),0
else
ink rgb(255,255,0),0
endif
a$=map$(x,z)
text x*16,z*16,a$
next x
next z
sync
wait key
backdrop on
for f = 200 to TotalWalls
show object f
next f
for f = 1000 to TotalFloors
show object f
next f
show object pointer
return
ShowMap:
if TotalWalls>0
for i = 200 to TotalWalls
if object exist(i)=1 then delete object i
next i
endif
if TotalFloors>0
for i = 1000 to TotalFloors
if object exist(i)=1 then delete object i
next i
endif
WallObj=200
FloorObj=15000
EnemyObj=25000
for z=1 to MapHeight
for x=1 to MapWidth
if map$(x,z)="W"
xsize#=(x*UnitSize)
zsize#=(z*UnitSize)
make object box WallObj,UnitSize,500.0,UnitSize
set object WallObj,1,1,1
texture object WallObj,43
position object WallObj,xsize#,248.0,zsize#
set object collision on WallObj
make object collision box WallObj,-100,-250,-100,100,250,100,0
inc WallObj,1
endif
if map$(x,z)="_" or map$(x,z)="S" or map$(x,z)="F"
xsize#=(x*UnitSize)
zsize#=(z*UnitSize)
make object plain FloorObj,UnitSize,UnitSize
set object FloorObj,1,1,1
xrotate object FloorObj,90
texture object FloorObj,53
position object FloorObj,xsize#,0.0,zsize#
set object collision off FloorObj
inc FloorObj,1
endif
next x
next z
TotalWalls = (WallObj-1)
TotalFloors= (FloorObj-1)
return
MapData:
data "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW"
data "W______________________________W"
data "W______________WWWWWWWWWWWWWWWWW"
data "WWWWWW_________W_W_____WWWWW_WWW"
data "W____W_________W_W_____W______WW"
data "W____WWWWWWWWW_W_W_____WWWWW_WWW"
data "W______________W_W________WW___W"
data "W_WWWWWWWW_____W_W________WW___W"
DATA "W_W____________W_________WWW___W"
DATA "W_WWWWW__________________WWW___W"
DATA "W__WWWW________________________W"
DATA "W__WWWWWW______________________W"
DATA "W_____WWW_________WWWWW________W"
DATA "W_____WWW_________W___W________W"
DATA "W_____WWW_________W___W________W"
DATA "WWWW__WWW_________W____WW______W"
DATA "W_____WWW_________W____________W"
DATA "W_________________WWWWWWW______W"
DATA "W_____WWWWWWW__________________W"
DATA "W_____W_____WWW______________WWW"
DATA "W___WWW_________WW_________WWWWW"
DATA "WWWWWWW_____WWW_________WWWW___W"
DATA "W____WWWW___WWW_________WWW____W"
DATA "W____WWWW___WWW_________WWW____W"
DATA "W_________WWWWW________________W"
DATA "W_________WWWWWWWWW________WWWWW"
DATA "W_________W_______W________W___W"
DATA "W_________W________________W___W"
DATA "WWWW______W_______W________W___W"
DATA "WWWW______________W________W__WW"
DATA "WWWW__S___________W___________WW"
DATA "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW"
LBFN