eray,
After all this time, you have not figured this out? Even after what all I have shown you? Its not that hard, just put some thought into it. I will not code everything for you. Below is my code including your code, showing you a method in linkng the two. It is messy, however, I am not working for perfection right now. I have also included two neat sounds for the menu. I have attached the sounds to this post in zip format. Simply, unzip this file to within the same location that the code below will be.
set display mode 800,600,32
sync on
sync rate 60
REM <<<<<<<< preparations >>>>>>>>>
REM << create menu options text array
dim menutext$(5)
menutext$(1) = "New Game"
menutext$(2) = "Load Game"
menutext$(3) = "Options"
menutext$(4) = "Instructions"
menutext$(5) = "Quit"
REM << set the text options
set text font "Copperplate Gothic"
set text to bold
set text size 20
REM << the images do not cover the screen, so we will blend the main color of them with the background
backdrop on
color backdrop rgb(103,153,128)
REM << load images
load image "mainmenu_bg1.jpg",1
load image "mainmenu_bg2.jpg",2
load image "mmenu_button_off.jpg",3
load image "mmenu_button_on.jpg",4
REM << make and place option button image sprites
for t = 300 to 500 step 50
inc count
sprite count,50,t,3
next t
REM << load sounds
load sound "sounds/msover.wav",1
load sound "sounds/select.wav",2
REM << load 3D objects
load object "vrspnglogo.x",1
REM << make red texture as image to texture surface logo with
ink rgb(255,0,0),0
box 0,0,1,1
get image 5,0,0,1,1
cls
REM << texture logo with created red image
texture object 1,5
REM << set camera to show logo at top-right corner of screen
position camera -2.5,-1,-9
REM <<<<<<<<<<<<<<<<<<<< MAIN LOOP(nest all code inside this loop) >>>>>>>>>>>>>>>>>>>>>>>>>
repeat
REM <<<<<<<< main menu setup >>>>>>>>>
if frmfocus = 0
REM << main menu will need to be setup after gameplay to make menu objects visible again
if setup$ = "true"
for t = 1 to 5
show sprite t
next t
show object 1
position camera -2.5,-1,-9
point camera 0,0,0
show mouse
setup$ = "false"
endif
REM <<<<<<<<< main menu loop >>>>>>>>>>
repeat
REM << paste main menu backgrounds to screen, behind any 3d objects
paste image 1,0,94
paste image 2,464,358
REM << check for mouseover options buttons, on/off effect, also type related option text next to sprite image
space = 300
for t = 1 to 5
REM << check if mouse is within sprite 'box' area
mx = mousex()
my = mousey()
if mx => sprite x(t) and mx =< sprite x(t) + 50 and my => sprite y(t) and my =< sprite y(t) + 49
REM << if mouseover then turn text bright red, use 'on' button image
imgnum = 4
ink rgb(255,0,0),0
REM << compare last sprite mouse was over to current sprite mouseover,if different the play beep sound
if t <> spritenum then play sound 1
REM << record current sprite the mouse is over for comparison on next loop
spritenum = t
REM << check for mouseclick and change frmfocus to equal the current sprite number and play select sound
if mouseclick() = 1
frmfocus = spritenum
play sound 2
REM << clear the screen of all objects
for s = 1 to 5
hide sprite s
next s
hide object 1
cls
REM << the variable below will tell the program that the next form needs to be setup to be playable
setup$ = "true"
endif
else
REM << if mouse not over then turn text dull red, us 'off' button image
imgnum = 3
ink rgb(150,0,0),0
REM << increment spritecheck each time mouse is not over a sprite
inc spritecheck
REM << set spritenum to 0 if spritecheck equals 5, this allows for the last sprite touched to play sound if mouseovered first next
if spritecheck = 5 then spritenum = 0
endif
REM << initialize spritcheck for next loop
if t = 5 then spritecheck = 0
sprite t,50,space,imgnum
REM << print text to right side of image
text 105,space + 12,menutext$(t)
inc space,50
next t
REM << indefinitely spin logo
yrotate object 1,angle
angle = wrapvalue(angle + 1)
sync
REM << when frmfocus is given any new value other than 0, this repeat until loop will end and the rest of the code will be checked
until frmfocus > 0
hide mouse
endif
REM <<<<<<<< end of main menu loop >>>>>>>>
REM <<<<<<<< setup main gameplay >>>>>>>>>
if frmfocus = 1
REM << here is where the program will create your objects before running the repeat loop inside this IF statement
if setup$ = "true" and nosetup$ <> "true"
REM << make gameplay objects
make object box 2,1,1,3:color object 2,rgb(255,0,0)
make object box 3,1,1,3:color object 3,rgb(0,0,255)
make object sphere 4,1:color object 4,rgb(0,255,0)
make object box 5,20,0.1,10:position object 5,0,-0.55,0:color object 4,rgb(0,0,0)
REM << initialize some variables
balla#=90
player1score# = 0
player2score# = 0
REM << reset setup$
setup$ = "false"
REM << this variable keeps the program from trying to create already created objects after the first game
nosetup$ = "true"
endif
REM <<<<<<<<< main gameplay loop >>>>>>>>>>>
repeat
REM << scoring
if ballx#>6 then player2score#=player2score#+1:ballx#=0:ballz#=0:balla#=270
if ballx#<-6 then player1score#=player1score#+1:ballx#=0:ballz#=0:balla#=90
set cursor 300,50:print player2score#
set cursor 320,50:print "-"
set cursor 340,50:print player1score#
ballx#=newxvalue(ballx#,balla#,0.3):ballz#=newzvalue(ballz#,balla#,0.3)
REM << basic controls
IF upkey()=1 and player1pos#<3.5 then player1pos#=player1pos#+0.5
IF downkey()=1 and player1pos#>-3.5 then player1pos#=player1pos#-0.5
If ballz#>player2pos# then player2pos#=player2pos#+0.11
If ballz#<player2pos# then player2pos#=player2pos#-0.11
REM << main maths
IF keystate(17)=1 and player2pos#<3.5 then player2pos#=player2pos#+0.5
IF keystate(31)=1 and player2pos#>-3.5 then player2pos#=player2pos#-0.5
if keystate(17)=1 and ballx#<-4 and ballx#>-4.5 then balla#=balla#+8
if keystate(31)=1 and ballx#<-4 and ballx#>-4.5 then balla#=balla#-8
if ballx#>4 and ballx#<4.5 and ABS(player1pos#-ballz#)<1.5 then balla#=360-balla#
if ballx#<-4 and ballx#>-4.5 and ABS(player2pos#-ballz#)<1.5 then balla#=360-balla#
if ballz#>4 or ballz#<-4 then balla#=180-balla#
balla#=wrapvalue(balla#)
REM << camera postion
position object 1,5,0,player1pos#:position object 2,-5,0,player2pos#
position object 3,ballx#,0,ballz#:yrotate object 3,balla#
position camera 0,10,-10:point camera 0,0,0
REM << end game and return back to main menu
if player1score# > 10
for t = 2 to 5
hide object t
next t
cls
text 0,0,"you have won"
wait 3000
cls
frmfocus = 0
setup$ = "true"
endif
if player2score# > 10
for t = 2 to 5
hide object t
next t
cls
text 0,0,"you lose"
wait 3000
cls
frmfocus = 0
setup$ = "true"
endif
sync
until frmfocus <> 1
endif
REM <<<<<<<<<<<<<<<< END OF MAIN LOOP >>>>>>>>>>>>>>>>>
until frmfocus = 10
Below are a few code snippets showing the extra code thrown in.
The lines of code below are within the if statement, that if there has been collision with the mouse and a sprite button image.
if mouseclick() = 1
frmfocus = spritenum
play sound 2
REM << clear the screen of all objects
for s = 1 to 5
hide sprite s
next s
hide object 1
cls
REM << the variable below will tell the program that the next form needs to be setup to be playable
setup$ = "true"
endif
The lines of code below show what happens to prepare the menu. One variable is used to determine if the menu needs to be setup(setup$). This section of code will unhide the button sprites and the logo, which are hidden when an option is selected from the menu.
REM <<<<<<<<<<<<<<<<<<<< MAIN LOOP(nest all code inside this loop) >>>>>>>>>>>>>>>>>>>>>>>>>
repeat
REM <<<<<<<< main menu setup >>>>>>>>>
if frmfocus = 0
REM << main menu will need to be setup after gameplay to make menu objects visible again
if setup$ = "true"
for t = 1 to 5
show sprite t
next t
show object 1
position camera -2.5,-1,-9
point camera 0,0,0
show mouse
setup$ = "false"
endif
REM <<<<<<<<< main menu loop >>>>>>>>>>
repeat
There are a few things you should notice. I am using the
focus method I tried to teach you. First, all of the code, excluding the intitial setups(look below(1)), are placed within a single
repeat until loop. Then, each group of code(in this case we have two, one to run the menu and one to run the gameplay) is placed within repeat until loops. Then, frmfocus is used to enwrap those individual groups and their repeat loops. The frmfocus if statement is placed right before the setup$ if statement in each group(look below for a pusedo code example(2)).
1.)set display mode 800,600,32
sync on
sync rate 60
REM <<<<<<<< preparations >>>>>>>>>
REM << create menu options text array
dim menutext$(5)
menutext$(1) = "New Game"
menutext$(2) = "Load Game"
menutext$(3) = "Options"
menutext$(4) = "Instructions"
menutext$(5) = "Quit"
REM << set the text options
set text font "Copperplate Gothic"
set text to bold
set text size 20
REM << the images do not cover the screen, so we will blend the main color of them with the background
backdrop on
color backdrop rgb(103,153,128)
REM << load images
load image "mainmenu_bg1.jpg",1
load image "mainmenu_bg2.jpg",2
load image "mmenu_button_off.jpg",3
load image "mmenu_button_on.jpg",4
REM << make and place option button image sprites
for t = 300 to 500 step 50
inc count
sprite count,50,t,3
next t
REM << load sounds
load sound "sounds/msover.wav",1
load sound "sounds/select.wav",2
REM << load 3D objects
load object "vrspnglogo.x",1
REM << make red texture as image to texture surface logo with
ink rgb(255,0,0),0
box 0,0,1,1
get image 5,0,0,1,1
cls
REM << texture logo with created red image
texture object 1,5
REM << set camera to show logo at top-right corner of screen
position camera -2.5,-1,-9
2.)<<<<< main program loop >>>>>
repeat
<<< first form(main menu) >>>
if frmfocus = 0
<<< setup for first form(main menu) >>>>
if setup$ = "true"
runsetup code
endif
<<<< main menu repeat loop >>>>
repeat
code to run main menu(my code) goes here
until frmfocus > 0
<<<< end of main menu focus
endif
<<<< second form(gameplay)
if frmfocus = 1
<<<< setup for second form >>>>>
if setup$ = "true"
run setup code
endif
<<<<< second form repeat loop(gameplay)
repeat
code to run gameplay(your code) goes here
until frmfocus <> 1
<<<< end of gameplay focus and return to main menu focus
<<<< end of entire program loop >>>>>>>>
until frmfocus = 10
end
Maybe with the code directly above, you will understand this method. Enjoy, and don't forget to get the attached sounds.
+NanoBrain+