Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Making a Main Menu

Author
Message
Evangelion
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: United Kingdom
Posted: 14th Jan 2003 03:51
I am working on a first person shooter which is made up of three levels. Can anyone point me in the direction to find out how i can make a Main Menu? so the player can start the game; and exit the game.
Fluffy Paul
21
Years of Service
User Offline
Joined: 16th Dec 2002
Location: United Kingdom
Posted: 16th Jan 2003 17:56
I really ought to write a menu tutorial.
Here goes:

First you need to work out what options the menu will have.
In this example we'll have Start Game, Exit Game.
I am going to assume you're using the mouse.
And I'm going to assume you're using a bitmap or some other graphic for each option.

Firstly write the code that actually starts and exits the game.
Secondly make an array to store information about these icons.

I like a two dimensional array which stores six integers for each element of the GUI.
Dim GUIarray(n,6) where n is the number of elements (2 in this case).

What I store in the other six integer fields is this:
GUIarray(n,1)=visibilityFlag
GUIarray(n,2)=top y coord
GUIarray(n,3)=left x coord
GUIarray(n,4)=bottom y coord
GUIarray(n,5)=right x coord
GUIarray(n,6)=action code

visibilityFlag is a 0 or 1 telling the program if the icon is visible. If it's not visible you don't bother checking if the user's cliked on it.
The coordinates are 2D coordinates on the screen.
the action code is something you make up yourself based on how many different things you want the menu to do.
Here we'll say an action code of 1 means "Start the game" and a code of 2 means "Exit game".

Next we make a function that takes a 2D x and y screen coordinate and checks all the icons in the GUIarray.



this returns an actionCode for the GUI element clicked on.
An actionCode of 0 does nothing.

No make a fuction that takes the action code and runs the appropriate function or subroutine in reponse:



Now you can write some stuff to control when the GUIarray gets checked.



Don't put the "if action then" bit inside the first IF statement if you think you might also want to check the keyboard for GUI hotkeys being pressed. If you want to use keys to trigger GUI actions then you have to add another element to GUIarray to store the scancode of the key that corresponds to that action. e.g. if you want the "s" key to start the game and the "x" key to exit the game as well as clicking on the icons then Dim GUIarray to be (n,7) and set GUIarray(1,7) to be the scan code for "s" and set GUIarray(2,7) to be the scancode for "e".

Now write a function based on getGUIaction that is given a scancode and returns an action by searching GUIarray(n,7).
Now you can check for keyboard presses by putting another IF statement after the IF mouseclick() one but before the IF action one.

Er... give it a go and look up the proper functions for returning a size and a scan code. When you get it working you can improve it so that it checks for UPPER CASE "E" and "S".

If you want a menu system that uses the arrow keys then that's something else (although you'll still need the array of GUI elements). But it's something else I can tell you how to do, though!
Skyone
21
Years of Service
User Offline
Joined: 30th Dec 2002
Location: United States
Posted: 17th Jan 2003 04:49
Next time write that in english :/

Code of the Week: Moving an object back.
If Downkey()=1 then Move object x,-10
x=Object Number
John H
Retired Moderator
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 17th Jan 2003 14:02
Very nice tut. Skyone, very sarcastic comment. He took the time to post this whole thing and you shouldnt critisize. Very nice tut man.

RPGamer

Current - RPG: Eternal Destiny : Help Wanted!
http://www.halbrosproductions.netfirms.com
Dont ask those questions! Read the help files lazy!
Arrow
21
Years of Service
User Offline
Joined: 1st Jan 2003
Location: United States
Posted: 18th Jan 2003 05:37
Try using the code button next time, I can't understand that at all.

This is Truth!
This is my Belief!
...at least for now.
Arrow
21
Years of Service
User Offline
Joined: 1st Jan 2003
Location: United States
Posted: 19th Jan 2003 18:59
Ok, that helped, :S. If you really want him to learn from your example, use tabs to make your code more orderly, like this.



It helps ya find you way around the code a bit better.

This is Truth!
This is my Belief!
...at least for now.
Richard Davey
Retired Moderator
22
Years of Service
User Offline
Joined: 30th Apr 2002
Location: On the Jupiter Probe
Posted: 21st Jan 2003 19:01
They help structure your code so you can tell what is going on easily. By looking at the depth of a command you can tell where it's nested easily. With your code as it stands there isn't too much actually going on, so it doesn't matter - expand that out to several hundred or thousand lines and you've got a mess waiting to happen. No-one here is likely to bother reading code unless it's at least slightly formatted correctly, trust me.. no-ones got the time!

Cheers,

Rich

"Gentlemen, we are about to short-circuit the Universe!"
DB Team / Atari ST / DarkForge / Retro Gaming

Login to post a reply

Server time is: 2024-11-23 21:56:33
Your offset time is: 2024-11-23 21:56:33