I was chatting to someone about a year ago, who was embarking, for research purposes, on how to code a game in C++. They were familiar with the rudimentary concepts of coding, and with games, but had never looked at C++ before, or the source to any modern game. They had enormous problems going from the programming they leanred briefly as a kid which was this:
10 PRINT "I AM L33T!"
20 GOTO 10
And modern game source code. The main difference is that a C++ game is ‘object-oriented’ and the languages people start with are just simple lists of instructions, executed in order. This is a 30 second guide to helping newbie coders cope with the difference. The biggest problem you have, is the question “Yes but where does the code actually START?”. And the answer is, a function called WinMain. Basically, the structure of any game is this:
WinMain()
{
Create A Window();
InitialiseGameStuff()
while(true)
{
CheckGameNotQuit()
GameLoop()
}
}
That’s basically, Kudos, Democracy, Starship Tycoon, GSB… etc. It’s all there. that is the whole game. The real stuff happens inside GameLoop(). That is basically this:
GameLoop()
{
BeginFrame()
DoAIStuff()
DrawStuff()
EndFrame()
}
And that obviously splits out into a billion other functions. Now already, it might look scarily nothing like 10 PRINT SCREEN, but just imagine that GameLoop() is a GOTO that jumps to the start of GameLoop() and imagine a RETURN statement at the end of that section. The weird bit, for new coders, is that the code will jump back and forth all over the place, between different source files, in different orders, up and down and all over like a ping pong ball, but, ultimately, when the chips are down, it’s not really *that* different from old BASIC programs. Until you multithread it, anyway :D.