• Advertisement
Sign in to follow this  

Game Menu

This topic is 4249 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Anyone know where to get sample code on game menu ? the game menu here means the page where the player get to choose to start game or quit game?

Share this post


Link to post
Share on other sites
Advertisement
i personally don't know how to make one. but, i have seen plenty of places that talk about picking using opengl and i was thinking maybe you could make a 3d menu system using opengl picking.

however 2d i don't know how to do unless you translate the mouse movement into locations on the screen. if that made any sense. or you could use a totally text based system and only have opengl print text to the screen and the user just uses keystrokes to start/load/exit.

hope that gives you some ideas, but again i haven't ever done something like that myself.

here is a tutorial on picking

Share this post


Link to post
Share on other sites
I have no idea why my original post didn't go through last night, but here it is!!

There really is no specific way to do this - it all depends on how you have set up your game...

For instance, in my START (or TITLE) game-state, I have the following code...

unsigned int GS_StartCursor = 0;
const float WHITE[3] = { 1.0f, 1.0f, 1.0f };
const float GREY[3] = { 0.5f, 0.5f, 0.5f };

/* Handles user input during the START state */
bool StartInput()
{
// Process directional input (UP and DOWN arrow keys)
if((KEY->LUP()) && (!KEY->DOWN()) && (GS_StartCursor > 0)) { --GS_StartCursor; }
else if((KEY->LDOWN()) && (!KEY->UP()) && (GS_StartCursor < 2)) { ++GS_StartCursor; }

// Process NEW GAME option (ENTER or SPACE was pressed)
if(((KEY->RETURN()) || (KEY->SPACE())) && (GS_StartCursor == 0))
{
// Play sound - stop music
SOUND->PlaySound(1);
FadeOut(g_FadeTime, StartRender);
MUSIC->StopMusic();

// Clear RPG lists - initialize RPG
RPG::Free(CLEAR_ALL);
if(!RPG::CreateNew()) { return(false); }

// Proceed to FIELD state
if(!GAME_APP->PushState(FieldInit, FieldInput, FieldRender)) { return(false); }
}

// Process CONTINUE option (ENTER or SPACE was pressed)
else if(((KEY->RETURN()) || (KEY->SPACE())) && (GS_StartCursor == 1))
{
// Proceed to LOAD state
SOUND->PlaySound(1);
FadeOut(g_FadeTime, StartRender, false);
if(!GAME_APP->PushState(LoadInit, LoadInput, LoadRender)) { return(false); }
}

// Process QUIT option (ENTER or SPACE was pressed)
else if(((KEY->RETURN()) || (KEY->SPACE())) && (GS_StartCursor == 2))
{
// Quit game
SOUND->PlaySound(1);
FadeOut(g_FadeTime, StartRender);
return(false);
}

return(true);
}

/* Handles graphics rendering during the START state */
void StartRender()
{
// Update camera and frustum
CAMERA->SetPosition(0.0f, 0.0f, 0.0f);
FRUSTUM->ExtractFrustum();

// Begin rendering HUD
GRAPHICS->StartHUD();

// Render title box (from an OpenGL display list)
DSPL->Use(0);

// Render cursor - print text
if(GS_StartCursor == 0) { DrawCursor(353, 455); glColor3fv(WHITE); }
else { glColor3fv(GREY); }
FONT->Print(0, 369, 454, "NEW GAME");

// Render cursor - print text
if(GS_StartCursor == 1) { DrawCursor(353, 477); glColor3fv(WHITE); }
else { glColor3fv(GREY); }
FONT->Print(0, 369, 476, "CONTINUE");

// Render cursor - print text
if(GS_StartCursor == 2) { DrawCursor(353, 499); glColor3fv(WHITE); }
else { glColor3fv(GREY); }
FONT->Print(0, 369, 498, "QUIT");

// Finish rendering HUD
GRAPHICS->EndHUD();
}



Mind you that if you were to copy and paste this code into your own, it will not compile because there are a bunch of singleton classes (classes where there can only ever be one instance, such as my KEY and FONT classes) and other routines that are specific to my own code.

This should only be viewed as a means to get you started. In order to have a fully working game menu, all you really need is some sort of a cursor (whose position can be easily tracked by means of a variable, like in my code), and a set of functions that are executed upon selecting an option (such as pushing or removing a game state from a stack, like in my code).

Hope this helps!!

Share this post


Link to post
Share on other sites
Well the way I would go about is making a 2D GUI, cause 2D coordinates are in my opinion the best for any GUI type stuff such as a game menu. What I do is make a class for the game menu and with the GUI elements. This is some psuedo code on how it might look

#include "Mainmenu.h"
#include "Game.h"
...

void init()
{
Game game;
Mainmenu menu; // itll have something with id's telling it which state it is // // in such as if you clicked Option, PlayGame, Quit
}
...

void render()
{
if(menu.state != GAME_START) // while you didnt click on play game render // // the main menu gui
{
menu.render();
}
else
{
game.render();
}
}

anyhow if you need the code to turn OpenGL into a 2D Renderer here it is



void Init2D(int wid, int hei)
{
glViewport(0, 0, wid, hei);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D( 0, wid, 0, hei );
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
}

void End2D()
{
glPopMatrix();
glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
}




and just place that in between of any 2D stuff you want to draw on screen, just make sure you use glVertex2i, or glVertex2f so you wont accidently put in a 3D z coordinate. Itll look something like this

Init2D(800, 600);
renderSquare(64, 64);
End2D();

thats pseudo code and if you had a method called renderSquare itll render a square thats 64x64 pixels long and wide and you can continue to render 3D Context when you call End2D().

Hope this helps

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement