GLBasic forum

Main forum => GLBasic - en => Topic started by: Sev on 2013-Aug-16

Title: How to make a Main Menu?
Post by: Sev on 2013-Aug-16
I am fairly new to GLBasic and for my assignment for school we need to create a simple game.

How would i create main menu for the game with a Start and Exit option?
Title: Re: How to make a Main Menu?
Post by: mentalthink on 2013-Aug-16
Hi Sev, Welcome, well for make a simple menu, you can choose:

Use the librarie for make buttons of GLBasic   or simply use your own buttons:

I put a simple code of a only one button (You have to  read this commands , loadsprite, sprcoll, boxcoll , mousestate)

Code (glbasic) Select

Loadsprite "my_Btn.png", 1000

global mx,my,b1,b2  //mouse variables
while true
mousestate mx,my,b1,b2   //This it's for look and get the mouse when you move over your windows app

drawsprite 1000, 100,100 //This draw your image my_Btn.png in the x=100 and y=100 , you have to change this for your resolutions

//now the important part, the collision

if b1 and boxcoll(mx,my, 50, 50 ,  _
                          100,100,50,50)
 
     print "Collision"   //Here you have to make something to jump another part of the code, in example a function or sub
else
   print "No collision"
endif

showscreen
wend




I don't test the code but I think have to works, anything please ask again...
Welcome.
Title: Re: How to make a Main Menu?
Post by: Hark0 on 2013-Aug-16
Another main menu, with keys...

global mainloop=true

while mainloop=true

print "main menu",0,0
print "1- play",0,30
print "2- info",0,60
print "0- exit",0,90

if key(code key 1 see help)
//goto routine play
endif

if key(code key 2 see help)
//goto routine info
endif

if key(code key 0 see help)
mainloop=false
endif

wend
Title: Re: How to make a Main Menu?
Post by: Ian Price on 2013-Aug-17
Sorry chaps, I've removed the Spanish text - the OP requested GLBasic assistance in English.

Code (glbasic) Select

SETSCREEN 640,480,0

LOCAL x=70, y=100, press

WHILE TRUE

// Show game options
PRINT "START GAME",100,100
PRINT "OPTIONS",100,120
PRINT "EXIT",100,140

PRINT "USE UP & DOWN CURSORS TO MOVE -+- PRESS SPACE TO SELECT OPTION",20,460

// Show cursor at X,Y co-ordinates
PRINT "-+-",x,y
PRINT "-+-",x+120,y
 
  // Move cursor up with UP cursor key
  IF KEY(200) AND press=0 AND y>100
   y=y-20 // Move cursor up 20 pixels
   press=10 // Delay repeated keypress
  ENDIF
 
  // Move cursor down with DOWN cursor key
  IF KEY(208) AND press=0 AND y<140
   y=y+20 // Move cursor down 20 pixels
   press=10 // Delay repeated keypress
  ENDIF
 
  // Delay multiple keypresses
  IF press>0 THEN press=press-1
 
  // Select option with SPACE 
  IF KEY(57)
   IF y=100 THEN game()
   IF y=120 THEN options()
   IF y=140 THEN END
  ENDIF
 
  SHOWSCREEN

WEND


// Game
FUNCTION game:

WHILE TRUE

  PRINT "GAME",100,10

  SHOWSCREEN
 
WEND

ENDFUNCTION


// Options
FUNCTION options:

WHILE TRUE

  PRINT "OPTIONS",100,10
 
  SHOWSCREEN
 
WEND

ENDFUNCTION


And Sev, welcome to the forum. It would have been nice to introduce yourself to us. BTW, you'll learn more if you try to work these things out for yourself, although we are always willing to give assistance when users get stuck.
Title: Re: How to make a Main Menu?
Post by: mentalthink on 2013-Aug-18
No problem Ian  :good:
Title: Re: How to make a Main Menu?
Post by: Hark0 on 2013-Aug-18
Hi @Ian, no problem... but, make the same in spanish forums, please...  :whistle:

;)
Title: Re: How to make a Main Menu?
Post by: Ian Price on 2013-Aug-18
I can't possibly begin to moderate the Spanish forums. It's also a shame that some of the topics brought up in the Spanish, German and French forums don't come across to the English forum, even when their OP can speak English. I know a lot of stuff is just babble, but there are some really good articles in the (non-English) forums.

However, what I can say is that the OP asked for assistance in ENGLISH about GLBASIC in the English section (although with a name like Sev, he may well be Spanish) and didn't mention C++ or whatever. The responses were not in line with the original question. I know we all go off at tangents, but the responses added nothing to help.

BTW - in case anyone shouts - it wasn't anything to do with elitism or racism, as I'm REALLY proud to be part of this multi-cultural forum. It's my fave site on the net and I love all you guys.

Not that it really matters at the end of the day, because I think we scared him off! :P :(

None of us Mods are too heavy handed and I don't like removing or editing posts and if I do, I always give a valid reason, as that's what I'd want.

Anyway, back on topic... Sev? Are you there Sev?
Title: Re: How to make a Main Menu?
Post by: Sev on 2013-Aug-19
Thanks for the replies. I am not Spanish, i am Australian :).

Thanks for the welcome and I may use this forum regulary for the assignment i am working on.