🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

combining 2 tutorials

Started by
5 comments, last by tjisgnarly 17 years, 1 month ago
how can i make tutorial 43 (truetype fonts) show up before tutorial 41 (3d world)? something like a option like will be showed, but how do I do it? Please help!! Thanks
Advertisement
Hi, if you really want to be helped, you'd better add as much as usefull information as you can and explain yourself clearly.
You're post is very ambiguous and could be understood as just slideshow, website tutorials list display or code execution sequence, or ...
sorry!! When i start the game i would like it to come to a screen that says, New Game, Load Game, Options, Exit. when you click on new game, it starts you in a room like the 3d tutorial. I need to know how to get the text to show up before the room, then when you click something, it takes you to the correct screen.
This kind of stuffes are completely not linked to tutorials, it's just program designing.

little idea: (pseudo code)

init_font ()
init_world ()

loop:
index = display_menu () => draw some items with selected color/font on screen + read user input
display_world (world_index) => like while loop with DrawGLscene of tutorials, process also user input (so better to have dedicated sub for this)

endloop

clean ()
how would i do this with C++ code?
You need a few pieces to get this to do what you want, and you're going to want to tackle them one at a time. The order you take them on might not matter, though.

One piece is a "game state", which helps your main loop decide which rendering function to call, and helps your input code (keys[...]) figure out how it should work w/ the rest of the program. In real computer science, this is called a "Finite State Machine". Unfortunately, trying to google that up will leave you scratching your head unless you are a few years into a CS degree, or have a few years steady programming experience under your belt.

A tidbit to get you started with an extremely simple, and non-robust state machine:
enum GameState
{
GameState_MainMenu,
GameState_InGame,
GameState_OptionsMenu,
GameState_Quitting
};

GameState g_GameState; // a global variable, so multiple functions can see it

switch(g_GameState)
{
case GameState_MainMenu:
RenderMainMenu();
GetMainMenuInput();
break;
// ... the rest of the states
}


The second piece you need is a way to handle and interpret those mouse clicks in a different way on each screen. It's easy for the keyboard, since you already have that keys[...] array made for you, you just stuff the if(keys[...]) junk in a differnt GetInput() function for each screen. It's a bit harder for mouse clicks, though.

Here's an idea on how to solve this, though it's going to be completely different if you're not doing win32 programming. You might want to make a coordinate variable, like int g_MouseClickX and int g_MouseClickY (global, just like keys[...]), and have a variable to determine if there was a click, like bool g_MouseGotClicked. In each GetInput function, check if g_MouseGotClicked == true, and if so, do something special (part 3). In the WndProc, have it handle mouse clicks, and set those variables appropriately, and after each call to GetInput, set g_MouseGotClicked to false. The message you need to handle is probably WM_LBUTTONDOWN, but I haven't actually tried it out, myself =)


The third piece you're going to need is a selection mechanism. If you're drawing 2D quads to the screen, like you are w/ the text drawing tutorial, this may be easy. You basically have to handle click events, see if the 2D coordinates are inside the menu item's rectangle. If the click is inside that object's 2D rectangle, the the user clicked it. When a user clicks an object, switch the game state.

There are ways to do this in true 3D, too, but it's more complicated. If you can simplify this to be a 2D rectangle (i.e., you get lucky and ignore the Z coordinate), then your code will end up being quite a bit simpler.

For a menu, you might want keyboard control, too. If so, you'll need a sub-state for that menu, to show which item is highlighted by the keyboard, and when you press space bar, have it do different stuff, depending on which menu item is highlighted.


This should be enough to get you unblocked, and you should research the rest, or and try to get it working before asking for more help. If you do get stuck, let us know what you've tried and where you're stuck. 9/10ths of programming is experience. If you don't have that experience, you can substitute research =) Google is your friend!
Is their any way to make this easier, or mabye explain it more? Thank you for everything so far though!!

This topic is closed to new replies.

Advertisement