Here is my 18 line labyrinth game...
sync on : sync rate 45 : set display mode 800, 600, 32 : set window on : set window position 100,100 : autocam off : set text size 32
global ball as integer : ball = 2 : global board as integer : board = 1 : global back as integer : back = 3 : global wall as integer : wall = 4 : global hole as integer : hole = 5 : global xspd as float : xspd = 0 : global zspd as float : zspd = 0 : global bx as float : global bz as float : global fall as integer : fall = 0 : global level as integer : level = 1 : global holes as integer : holes = 35 : texture(1,2,3,4)
createboard(500,500) : createball(15) : createback(-1000) : camera() : set camera range 1,1,1000 : createholes(holes) : falls = 0 : gosub run
run: randomize timer() : placeholes(holes) : makeflag() : createfinish(holes) : do : text 0,0, "Level: "+str$(level) : text 0,40,"Lives: "+str$(5-falls) : text 0,70,"Best: "+str$(best) : if leftkey() = 1 then xspd = xspd - 0.1 : if leftkey() = 0 and rightkey() = 0 and xspd < -0.9 then xspd = xspd + 0.1 : if rightkey() = 1 then xspd = xspd + 0.1 : if leftkey() = 0 and rightkey() = 0 and xspd > 0.9 then xspd = xspd - 0.1
if upkey() = 1 then zspd = zspd + 0.1 : if upkey() = 0 and downkey() = 0 and zspd > -0.9 then zspd = zspd - 0.1 : if downkey() = 1 then zspd = zspd - 0.1 : if upkey() = 0 and downkey() = 0 and zspd < 0.9 then zspd = zspd + 0.1 : moveball(1) : xrotate object board, zspd : zrotate object board, -xspd : if xspd > 4 then xspd = 3.9 : if zspd > 4 then zspd = 3.9 ; if xspd < -4 then xspd = -3.9 : if zspd < -4 then zspd = -3.9
checkiffall(holes) : checkiffinish(6) : sync : loop
function texture(board,ball,back,wall) : create bitmap 1,800,800 : ink rgb(111,98,32),0: box 0,0,200,200 : ink rgb(173,169,163),0 : box 200,0,400,200 : ink rgb(13,24,132),0 : box 400,0,600,200 : ink rgb(107,84,39),0 : box 600,0,800,200 : get image board,0,0,200,200 : get image ball,200,0,400,200 : get image back,400,0,600,200 : get image wall,600,0,800,200 : get image hole,100,500,200,600 : delete bitmap 1 : endfunction
function createboard(w,h) : make object box board,h,5,w : position object board,250,0,250 : texture object board,board : endfunction : function createball(rad) : make object sphere ball,rad : position object ball, 10,10+rad/2,10 : texture object ball,ball : endfunction : function createback(size) : make object sphere back, size : position object back,250,0,250 : texture object back,back : endfunction :
function camera() : make camera 1 : position camera 1, 250,500,250 : point camera 1, 250,0,250 : endfunction : function moveball(spd) : bx = object position x(ball) : by = object position y(ball) : bz = object position z(ball) : ox = object angle x(board) : oz = object angle z(board) : x = xspd : z = zspd : position object ball, bx+x ,20+ox+oz ,bz+z : if bx > 480 then position object ball, 479,by,bz : if bx < 20 then position object ball, 21,by,bz
if bz > 480 then position object ball, bx,by,479 : if bz < 20 then position object ball, bx,by,21 : endfunction : function createfinish(holes) : position object 6, rnd(450)+30,20,rnd(450)+30 : for h = 10 to 10+holes : if object position x(6) < object position x(h)+10 : if object position x(6) > object position x(h)-10 : if object position z(6) < object position z(h)+10 : if object position z(6) > object position z(h)-10
position object 6, object position x(6)+rnd(50),20,object position z(6)+rnd(50) : if object position x(6) > 480 then position object 6, object position x(6)-100,object position y(6), object position z(6) : if object position z(6) > 480 then position object 6, object position x(6),object position y(6), object position z(6)-100 : endif : endif : endif : endif : next h : endfunction : function createholes(holes) : for h = 10 to 10+holes
hx = rnd(450)+30 : if hx < 0 then hx = hx - 20 : if hx >= 0 then hx = hx + 20 : hz = rnd(450)+30 : if hz < 0 then hz = hz - 20 : if hz >= 0 then hz = hz + 20 : make object cube h, 20 : texture object h, hole : position object h, hx,20,hz : if object position x(h) < 20 : if object position x(h) > -20 : if object position z(h) < 20 : if object position z(h) > -20 : position object h, object position x(h)+20,20,object position z(h)+20
if object position x(h) > 480 then position object h, object position x(h)-100,object position y(h), object position z(h) : if object position z(h) > 480 then position object h, object position x(h),object position y(h), object position z(h)-100 : endif : endif : endif : endif : next h : endfunction : function checkiffall(holes) : for h = 10 to 10+holes : if object position x(ball) < object position x(h)+10 : if object position x(ball) > object position x(h)-10
if object position z(ball) < object position z(h)+10 : if object position z(ball) > object position z(h)-10 : fall = 1 : position object ball, object position x(h),0,object position z(h) : wait 300 : position object ball,object position x(h),-20,object position z(h) : endif : endif : endif : endif : next h : if fall = 1 : repeat : ink 65535,65535 : text 200,200,"You Fell! - Press Space" : sync : until spacekey() =1 : fall = 0
gosub reset : endif : endfunction : function checkiffinish(flag) : if object position x(ball) < object position x(flag)+10 : if object position x(ball) > object position x(flag)-10 : if object position z(ball) < object position z(flag)+10 : if object position z(ball) > object position z(flag)-10 : finish = 1 : endif : endif : endif : endif : if finish = 1 : repeat : ink 65535,65535 : text 200,200,"Congratulations! - Level "+str$(level)+" complete!"
text 200,300,"Press Space to go to next level" : sync : until spacekey() =1 : finish = 0 : xrotate object board, 0 : zrotate object board, 0 : position object ball,10,0,10 : xspd = 0 : zspd = 0 : level = level + 1 : holes = holes + 5 : placeholes(holes) : createfinish(holes) : endif : endfunction : function makeflag() : if object exist(6) = 0 : make object box 6, 10,25,10 : position object 6, rnd(450)+30,20,rnd(450)+30 : endif
endfunction : function placeholes(holes) : for h = 10 to 10+(holes) : if object exist(h) = 1 then delete object h : next h : for h = 10 to 10+holes : make object cube h, 20 : texture object h, hole : position object h, rnd(450)+30,20,rnd(450)+30 : next h : endfunction : reset: xrotate object board, 0 : zrotate object board, 0 : randomize timer() : position object ball,10,0,10 : xspd = 0 : zspd = 0 : falls = falls + 1 : If falls = 5 then gosub restart
placeholes(holes) : return : restart: : best = level - 1 : level = 1 : fall = 0 : falls = 0 : holes = 35 : repeat : text 200,200,"You have fallen 5 times!" : text 200,300,"Game Over!" : text 200,400,"Press r to restart" : sync : until inkey$() = "r" : gosub run : return : return
and here is my full expanded code...
sync on
sync rate 45
set display mode 800, 600, 32
set window on
set window position 100,100
autocam off
set text size 32
global ball as integer : ball = 2
global board as integer : board = 1
global back as integer : back = 3
global wall as integer : wall = 4
global hole as integer : hole = 5
global xspd as float : xspd = 0
global zspd as float : zspd = 0
global bx as float
global bz as float
global fall as integer : fall = 0
global level as integer : level = 1
global holes as integer : holes = 35
texture(1,2,3,4)
createboard(500,500)
createball(15)
createback(-1000)
camera()
set camera range 1,1,1000
createholes(holes)
falls = 0
gosub run
run:
randomize timer()
placeholes(holes)
makeflag()
createfinish(holes)
do
text 0,0, "Level: "+str$(level)
`text 0,100,"Holes: "+str$(holes)
text 0,40,"Lives: "+str$(5-falls)
text 0,70,"Best: "+str$(best)
if leftkey() = 1 then xspd = xspd - 0.1
if leftkey() = 0 and rightkey() = 0 and xspd < -0.9 then xspd = xspd + 0.1
if rightkey() = 1 then xspd = xspd + 0.1
if leftkey() = 0 and rightkey() = 0 and xspd > 0.9 then xspd = xspd - 0.1
if upkey() = 1 then zspd = zspd + 0.1
if upkey() = 0 and downkey() = 0 and zspd > -0.9 then zspd = zspd - 0.1
if downkey() = 1 then zspd = zspd - 0.1
if upkey() = 0 and downkey() = 0 and zspd < 0.9 then zspd = zspd + 0.1
moveball(1)
xrotate object board, zspd
zrotate object board, -xspd
if xspd > 4 then xspd = 3.9
if zspd > 4 then zspd = 3.9
if xspd < -4 then xspd = -3.9
if zspd < -4 then zspd = -3.9
checkiffall(holes)
checkiffinish(6)
sync
loop
function texture(board,ball,back,wall)
create bitmap 1,800,800
ink rgb(111,98,32),rgb(255,255,255)`board
box 0,0,200,200
ink rgb(173,169,163),rgb(255,255,255)`ball
box 200,0,400,200
ink rgb(13,24,132),rgb(255,255,255)`back
box 400,0,600,200
ink rgb(107,84,39),rgb(255,255,255)`wall
box 600,0,800,200
get image board,0,0,200,200
get image ball,200,0,400,200
get image back,400,0,600,200
get image wall,600,0,800,200
get image hole,100,500,200,600
delete bitmap 1
endfunction
function createboard(w,h)
make object box board,h,5,w
position object board,250,0,250
texture object board,board
endfunction
function createball(rad)
make object sphere ball,rad
position object ball, 10,10+rad/2,10
texture object ball,ball
endfunction
function createback(size)
make object sphere back, size
position object back,250,0,250
texture object back,back
endfunction
function camera()
make camera 1
position camera 1, 250,500,250
point camera 1, 250,0,250
endfunction
function moveball(spd)
bx = object position x(ball)
by = object position y(ball)
bz = object position z(ball)
ox = object angle x(board)
oz = object angle z(board)
x = xspd
z = zspd
position object ball, bx+x ,20+ox+oz ,bz+z
if bx > 480 then position object ball, 479,by,bz
if bx < 20 then position object ball, 21,by,bz
if bz > 480 then position object ball, bx,by,479
if bz < 20 then position object ball, bx,by,21
endfunction
function createfinish(holes)
position object 6, rnd(450)+30,20,rnd(450)+30
for h = 10 to 10+holes
if object position x(6) < object position x(h)+10
if object position x(6) > object position x(h)-10
if object position z(6) < object position z(h)+10
if object position z(6) > object position z(h)-10
position object 6, object position x(6)+rnd(50),20,object position z(6)+rnd(50)
if object position x(6) > 480 then position object 6, object position x(6)-100,object position y(6), object position z(6)
if object position z(6) > 480 then position object 6, object position x(6),object position y(6), object position z(6)-100
endif
endif
endif
endif
next h
endfunction
function createholes(holes)
for h = 10 to 10+holes
hx = rnd(450)+30
if hx < 0 then hx = hx - 20
if hx >= 0 then hx = hx + 20
hz = rnd(450)+30
if hz < 0 then hz = hz - 20
if hz >= 0 then hz = hz + 20
make object cube h, 20
texture object h, hole
position object h, hx,20,hz
if object position x(h) < 20
if object position x(h) > -20
if object position z(h) < 20
if object position z(h) > -20
position object h, object position x(h)+20,20,object position z(h)+20
if object position x(h) > 480 then position object h, object position x(h)-100,object position y(h), object position z(h)
if object position z(h) > 480 then position object h, object position x(h),object position y(h), object position z(h)-100
endif
endif
endif
endif
next h
endfunction
function checkiffall(holes)
for h = 10 to 10+holes
if object position x(ball) < object position x(h)+10
if object position x(ball) > object position x(h)-10
if object position z(ball) < object position z(h)+10
if object position z(ball) > object position z(h)-10
fall = 1
position object ball, object position x(h),0,object position z(h)
wait 300
position object ball,object position x(h),-20,object position z(h)
endif
endif
endif
endif
next h
if fall = 1
repeat
ink 65535,65535
text 200,200,"You Fell! - Press Space"
sync
until spacekey() =1
fall = 0
gosub reset
endif
endfunction
function checkiffinish(flag)
if object position x(ball) < object position x(flag)+10
if object position x(ball) > object position x(flag)-10
if object position z(ball) < object position z(flag)+10
if object position z(ball) > object position z(flag)-10
finish = 1
endif
endif
endif
endif
if finish = 1
repeat
ink 65535,65535
text 200,200,"Congratulations! - Level "+str$(level)+" complete!"
text 200,300,"Press Space to go to next level"
sync
until spacekey() =1
finish = 0
xrotate object board, 0
zrotate object board, 0
position object ball,10,0,10
xspd = 0 : zspd = 0
level = level + 1
holes = holes + 5
placeholes(holes)
createfinish(holes)
endif
endfunction
function makeflag()
if object exist(6) = 0
make object box 6, 10,25,10
position object 6, rnd(450)+30,20,rnd(450)+30
endif
endfunction
function placeholes(holes)
for h = 10 to 10+(holes)
if object exist(h) = 1 then delete object h
next h
for h = 10 to 10+holes
make object cube h, 20
texture object h, hole
position object h, rnd(450)+30,20,rnd(450)+30
next h
endfunction
reset:
xrotate object board, 0
zrotate object board, 0
randomize timer()
position object ball,10,0,10
xspd = 0 : zspd = 0
falls = falls + 1
If falls = 5 then gosub restart
placeholes(holes)
return
restart:
best = level - 1
level = 1
fall = 0
falls = 0
holes = 35
repeat
text 200,200,"You have fallen 5 times!"
text 200,300,"Game Over!"
text 200,400,"Press r to restart"
sync
until inkey$() = "r"
gosub run
return
return `run
Feel free to try either and please let me know what you think