Welcome to DirectX! This first lesson will cover the basic structure of a video game. It will give you some idea of where you are going with DirectX so you don’t dive in blind and unguided, as many rookie game programmers do. As video games can get very long and complex, I suggest that even experienced programmers new to game programming at least skim through this so they know where they’re going.
A video game is, in essence, a continuous loop performing various actions which, when run through once, bring about a single frame of animation. Programmers, when entering the world of game programming, rarely consider all the components required in even a simple animated game like Pong or Asteroids and can easily get overwhelmed. This means no more event-driven programs you're probably used to.
So let’s start out by looking at each phase of a game, in sequence, from beginning to end and then describing each part of it.
The Sequence of a Computer Game
Here is where you start the show. You create a window to display your game, you set up DirectX for use, load graphics, models and other media, allocate memory and so on.
This part is basically setting up your game to be played. This is where you might select a map, set the location of your player (and anyone else in your game world) or set random values, such as random terrain, that are decided at the beginning of the game only. After all of this, you enter the game loop itself for the kickoff.
Here, you get all the information from the keyboard, mouse, touch-screen, accelerometer, controller or whatever device your player is using.
In this part you process what is going on in your world. Where exactly did your player move in the last sixtieth of a second? How much ammo does he have left? Are his enemies coming or going? What about his allies? Did his ship crash into a mountain? Or was that just a cloud he just ran into? All this and more is determined in this phase.
This is where DirectX is mostly used. Here you would process all your 3D (and 2D) graphics and render them to the screen. This will be gone over in the Direct3D tutorials.
Once this is done, we go back to the beginning of Phase 3 and do it all again.
When the player navigates away from your game, Windows will store it in memory and pause everything. At this point, you get a chance to save the player's progress in case the game is fully shut down.
Called for memory? Now is your last chance to clear everything up, because the program is about to end.
Ok, so how does all this fit together? Well, you will notice that most of the above is done in a loop continuously until an exit is called for. The diagram you saw above shows how all the above pieces are put together.
Now, admittedly this is simplified, and more than somewhat, but I just want to give you a quick overview of things. You can (and will need to) add all kinds of details such as networking code, splash screens, an animated menu loop, sound, music, and so on. Some of these are rather easy. For instance, a simple splash screen is a piece of cake, and we'll talk about that soon.
Although some are easy, others can get more complex, such as networking and keeping multiple computers (that run at different speeds) moving through the game at the exact same pace. (I’ll go over this one in a future tutorial).
But let's not concern ourselves with such things yet. We haven't entered in a single line of code and we're already talking about how complex things are. Let's get to the actual programming before we get into such topics.
Next we'll cover how Windows programming works, make a simple app, and program the basic game loop.
So even though we haven’t programmed anything yet, we now know where we’re going. And with that, let’s dive right in!
Next Lesson: Creating a Direct3D App for Windows 8
GO! GO! GO!