If you want to make games, you probably want to look for some library that will allow you to use graphics, sounds, handle keyboard events, etc.
I am currently using SDL.
Direct answer to your question(how to game loop) is:
1 2 3 4 5 6 7 8 9 10 11 12
|
bool gameRunning;
while( gameRunning)
{
//Handle events
// Logic of game
// Drawing on screen
}
|
Everything should look clear to you.
There are few things that you should know when it comes to creating games.
First is: start simple. You will never make Quake 4 if you start it at the beggining. You simply don't have proper skills/knowledge/experience, and you will fail quickly.
Second is: don't try to make Best Game Ever. Many times you think that your game will be super-best if you add this and this and that and eventually you just lose yourself in many details. Sometimes these are hard to do, so you get annoyed and resign. Start simple - if you want to make tic-tac-toe game, make tic-tac-toe game. Want to add simple bot? Okay, but mind that it may not help you too much in learning how to create games.
Which brings us to third advice: Always try to learn. If you make tic-tac-toe, make sure you learned something, or gained some experience that will help you in future games that you will make.
If you make some game and it's not perfect, it's okay. You are learning. It can be bugged. It can be imperfect. But you must learn from it. Otherwise you just lost your time.
So, before learning how to make 'games' like this(with many if statements in main code, and so on), I encourage you to:
- work hard and look for resources by yourself( really! People tend to be polite if they see that you made research on topic but didn't find anything).
- try to learn by yourself(if you want, for example, to check some pointers behavior, you can simply make small program that will check this thing, instead of asking it on forum).
- If you want to write games with GUI, you may try SDL. Google SDL and Lazy Foo's SDL lessons. These can help you understand writing games, and other useful stuff.
Good luck!
PS. Before you even start writing games, please, go and humbly complete tutorial for C++ on this site. If you want to create games, you need to know C++ basics. This tutorial got it. If you don't, you will struggle, and later will have to come back and learn it anyway.