game DEV

Hi everybody!

i new here and i just know a little bit of c++.

i have a question .my project is to design a game and i have a few questions.

1) i,m thinking of a game where the user uses the WASD keys to navigate a car .
how to i program in such a way that this works. pls explain step by step.

2)also how to make a program such that unless the user enters a specified key,the loop should not end.

pls inclued the header files,the functions and if possible a small simple example.

thank you.
Hi welcome to the forum. You seem to be new here so I'll point you in a few directions that you're going to be thrown in eventually starting with:
http://www.cplusplus.com/forum/articles/31015/

Keep this in mind as well: http://www.cplusplus.com/forum/articles/28558/
and
http://www.cplusplus.com/forum/articles/31040/

After having read those this is the easily one of the best starting places on the web: http://www.cplusplus.com/doc/tutorial/

After all of that you'll want to choose a library that you are comfortable with so:
http://www.libsdl.org/
and
http://www.sfml-dev.org/
These are two of the most popular. Let us know which one you choose and we'll help you get started. C++ is a very strong language and as such there is a lot to know, don't let yourself get discouraged though as it is very rewarding to write your first game.
Last edited on
Hi!

If we explained to you step-by step how to write the program, that eliminates half the fun of programming! I'm sure it would be a lot more fun (and realistic in terms of what might be programming later) if you worked it out on your own.

You will need a library to deal with the graphics, though. If you'll be using 2D graphics, I'd suggest using SFML. If you're going to use 3D, then probably the easiest (albeit not 100% bug-free) library is Irrlicht.

http://www.sfml-dev.org
http://irrlicht.sourceforge.net

As for making a while loop that terminates when the user enters a key... you do know about sentinel-controlled loops, right?

1
2
3
4
5
6
7
8
9
10
11
//Example:
while(true)
{
    //Insert code here.
    if(condition) //Sentinel.
    {
        //Cleanup.
        break;
    }
    //Insert code here.
}


Good luck!

-Albatross
Last edited on
Presumably it's equally OK to do this:

1
2
3
4
5
while (Running)
{
   // etc
   if (condition) Running = false;
}


Obviously, yours is tidier, but if one had to exit from within a switch or some such thing this way would be necessary, right?
The problem with that is that yours would not immediately quit the loop... I hate to say this, but I think the only options here are to either:
1) Constantly check Running even inside the loop
2) Throw a custom exception that quits the loop
3) Use goto.

Though I might have missed something, and would be glad if anyone knew a cleaner solution.
Does it matter to finish the current loop before quitting? Surely the user is unlikely to notice a delay of 'half a frame', so to speak.

Is there not a performance issue with putting the whole main loop, rendering, physics and everything inside a try block?
@ hanst99: This is one reason that Win32 tells you to use a callback function to handle events, this way as soon as your case is met (ideally) it returns from the function and the rest of the code in the function isn't processed. There is nothing stopping this practice from being main stream on every platform other then people not wanting to deal with passing data structs.
Topic archived. No new replies allowed.