You need to stop using gosubs! Every time you call a gosub without returning, you are filling up the call stack. Eventually you will cause a stack overflow and your program will crash.
Please, for the love of god, stop using gosubs like this!
You need to learn how to use functions, something like this would be better:
Do
cls
Load Image "/pictures/Title.bmp", 1, 1
` Get middle of screen coordinates
MX = Screen Width()/2
MY = Screen Height()/2
` The main menu loop
Repeat
Paste Image 1,0,0 : But = 0
If Button(MX,MY-20," Start Game ") Then But = 1
If Button(MX,MY ," Instructions ") Then But = 2
If Button(MX,MY+20," Credits ") Then But = 3
If Button(Mx,MY+40," Quit ") Then But = 4
Sync
Until But <> 0
Delete Image 1
If but = 1 Then code()
If but = 2 Then inst()
If but = 3 Then cred()
If but = 4 Then End
Loop
` Button Function
Function Button( X, Y, B$ )
rB as dWord
TH=(Text Height(B$)/2)+1
TW=(Text Width(B$)/2)+1
MX=MouseX() : MY=MouseY()
If MX>X-TW and MX<X+TW and MY>Y-TH and MY<Y+TH
CV = RGBA(128,128,0,128)
rB = MouseClick()
If rB<>0 then CV = RGBA(255,128,0,128)
Else
CV = RGBA(0,0,128,64)
rB = 0
EndIf
Box X-TW,Y-TH,X+TW,Y+TY,CV,CV,CV,CV
Center Text X,Y-(TH-1),B$
EndFunction rB
` RGBA Function
Function RGBA(R,G,B,A)
rB as dWord
rB = (A<<24)||(R<<16)||(G<<8)||(B)
EndFunction rB
Function inst()
cls
print "Use arrow key to move Snuffy the Squirrel"
print "Find the end of the maze where you will receive a chestnut"
print "To complete the game, you must receive 5 chestnuts"
print "Press any key to return to main menu"
wait key
EndFunction
Function cred()
print "Cover art- Imran and Nathan"
print "Title screen- Nathan"
print "Maze design- Imran"
print "Storyboarding- Imran"
print "Coding- Mobiius"
print "Thank you for helping us prevent piracy"
Print "Press any key to return to main menu"
wait key
EndFunction
Function Code()
cls
print "Enter code provided inside the front cover of the case"
input code$
if code$="E856HLQO159" Then intro()
EndFunction
Function Intro()
cls
Print "Thank you for helping us prevent piracy"
wait 3000
cls
Load Bitmap "./pictures/MADOG.jpg"
Wait 3000
cls
Load bitmap "./pictures/Imran.jpg"
wait 3000
cls
Main()
EndFunction
Function Main()
hide mouse : sync on : sync rate 60 : randomize timer()
load image "./pictures/texture.bmp",1
rem controled object
make object cube 1,1 : position object 1,2,1.51,5 : yrotate object 1,90 : color object 1,rgb(255,0,0)
rem walls and ground
make object box 2,1000,1,1000 : texture object 2,1
make object box 3,1,20,40 : position object 3,0,2,30 : texture object 3,1
make object box 4,40,20,1 : position object 4,20,2,0 : texture object 4,1
make object box 5,1,20,40 : position object 5,40,2,30 : texture object 5,1
make object box 6,40,20,1 : position object 6,20,2,50 : texture object 6,1
make object box 7,20,20,1 : position object 7,10,2,40 : texture object 7,1
make object box 8,1,20,20 : position object 8,20,2,30 : texture object 8, 1
make object box 9,1,20,20 : position object 9,10,2,20 : texture object 9,1
make object box 10,1,20,20 : position object 10,20,2,30 : texture object 10,1
make object box 11,20,20,1 : position object 11,20,2,10 : texture object 11,1
make object box 12,1,20,40 : position object 12,30,2,20 : texture object 12,1
make object box 1000,1,5,10 : position object 1000,0,0,5 : hide object 1000
make object box 1001,1,5,10 : position object 1001,40,0,5 : hide object 1001
rem sky
color backdrop 1000
rem collision
set object collision to boxes 2
rem main loop
set text to bold : set text size 30
do
rem level 1 print
center text 320,15,"Level 1"
rem controls
aY# = object angle Y(1)
if upkey()=1 then move object 1,0.4
if downkey()=1 then move object 1,-0.4
if rightkey()=1 then aY# = wrapvalue(aY#+3)
if leftkey()=1 then aY# = wrapvalue(aY#-3)
yrotate object 1,aY#
rem collision stats
if object collision(1,1001)
wait 1500
For Obj = 3 To 12
delete object Obj
Next Obj
endif
if object collision(1,0) then position object 1,X1#,1.51,Z1#
rem camera
X1# = Object position x(1)
Z1# = Object position z(1)
X# = Newxvalue(X1#,aY#-180,5)
Z# = Newzvalue(Z1#,aY#-180,5)
Position Camera X#,4,Z#
Point camera X1#,3,Z1#
if controlkey()=1 then Position Camera X#,64,Z# : Point camera X1#,48,Z1#
inc count
if count = 30
for c = 2 to 12
which=rnd(5)
if which=0 then set object emissive c,RGB(255,0,0)
if which=1 then set object emissive c,RGB(0,255,0)
if which=2 then set object emissive c,RGB(0,0,255)
if which=3 then set object emissive c,RGB(255,255,0)
if which=4 then set object emissive c,RGB(0,255,255)
if which=5 then set object emissive c,RGB(255,0,255)
next c
if count=30 then count=0
ENDIF
sync
loop
EndFunction
Please! Please! Please! Please! Please! Please! Please! Learn from my code and become a better programmer! Stop using Gosub the way you are, it's NOT a replacement for GoTo!
Please INDENT YOUR CODE to make it easier to read!
Please learn to automate tasks! (Like the deletion of 10 objects....)
Please learn to NOT load images with the absolute file path! Use relative paths as I have done in your code.
This is my current project, check it out! [href]forum.thegamecreators.com/?m=forum_view&t=204576&b=8[/href]
This is my website, check it out! [href]http:\\www.TeamDefiant.co.uk[/href]