Game Design, Programming and running a one-man games business…

Going from BASIC to C++, in understanding game source code

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.

Zero-G Games and casual portal royalties…

EDIT EDIT EDIT

See the comments section below, plus zero-g games have contacted me to resolve the matter and send back payments of royalties. It looks like the real villains of this piece are the casual ‘portals’ who increasingly screw the developers, and guys like zZro-G out of paying on time. I should point out that steam pay within a month, so anyone who is taking a lot longer than that is just hoarding other peoples cash.

Anyway, anyone looking for something newsworthy here should probably look towards the causal games portals rather than the spat between me and zero-G.

EDIT EDIT EDIT

oooh did I really type that?

I guess I did, and it would be a disaster if a well trafficked blog became a prominent search result for the casual games publisher zero-g games wouldn’t it? But then… That’s what happens if you stop replying to your developers emails, and stop paying them, and 3 other fellow developers I’ve spoken to.

If you work for bigfish games, or any other casual portal that stock these titles:

Kudos

Kudos: Rock Legend.

You will want to check your inbox for my email. Basically you are selling a game you don’t have the rights to any more, so I strongly suggest stopping that. As for anyone who wants to buy those games. DO NOT BUY THEM, unelss you buy them direct from me, or from impulse, gamersgate or direct2drive. Everyone else is depriving me of my share, and I made those games, so that hardly seems fair.

Also if you see a game called ‘oval office’ don’t buy it. It’s a cut down bastardised, casualised, americanised version of Democracy 2, which is much much better. Buy that instead.

And lastly, to any of the many publishers who keep spamming me wanting to sell GSB or my older games, and annoyed I’m not replying. Give up now. I’m never replying, I route all your emails to the bin.

Selling direct FTW!

I love making and playing games, I hate the liars and thieves in this industry though…

Radio 4, padlocks and publishers

So Friday was world-of-love conference day for indies. It meant waking at 5.30am and banging my head on a metal railing in the dark. Bah!

The conference itself was worth going to, met a bunch of people from indie development which was cool. Alice taylor and Sophie Houlden gave some great presentations, and tak’s talk was interesting too. I did a sudden ’10 seconds-notice’ interview with radio 4 for a program about indie games which will go out in june at some point. I hope they don’t edit me out :D I probably sounded a bit nervous, and didn’t say anything wildly controversial, but I got through it, and I’m glad I said yes to it.

I had a few of those ‘maybe I should have business cards made?’ moments, but decided maybe not. Afterwards was pub, then pizza. Just like the last world-of-love there was no room in the pub for anyone, and nobody could hear a thing. Surely there is a better way?

The bad news, is when I got home, we realised the next day some scumbag had tried to break into our garage. Very unusual, apparently they tried everyones. It’s not like where I live is high crime. They cut the lock using boltcutters, so I had to go get a new one, and then got bolts that were too short. doh! Still, you learn a few knacks as a boatbuilder, and those screws aren’t coming out in a hurry. Plus, I’ve ordered one of these. Maybe it’s time for me to invest in a night vision attachment for my bow. I already have a night vision scope, but I need both hands to shoot someone. Bah.

Also, a casual game publisher has stopped paying me my royalties. I hate publishers, they are almost all a bunch of criminals. Another lesson learned I guess, and another reason to ALWAYS sell direct to the customer if you can. Maybe they will suddenly appear and pay me, if not, they just go on my list of people to get revenge on when I rule the galaxy.

Contacts

I’m going to london indie conference ‘world of love’ on friday. I’m not speaking this year, but I’ll be there. I’ll probably have a few drinks with some people afterwards too.

I know some indies just never go to stuff like this, and don’t think it’s worth the hassle. I can sympathise, I live a LONG way from London, my alarm clock will go off damned early, even if I’m only aiming to get there for 10amish, and miss the start. I have a major drive, and a tube journey ahead of me, plus the entrance fee. Bah.

But I suspect it is worth it. I know a lot of people think these are good opportunities to meet publishers etc, but I don’t really care about that. I’m already selling my games through every portal I’m interested in, do not want any retail deals, and frankly, if someone wants to work with me, they should email me. I read them all.

I don’t feel more likely to work with someone or trust them because we have ‘pressed flesh’. I’ve never met my mac partner, or the people who do my art or sound. Why do I need to? I treat such relationships as a meritocracy.

My aim is more to meet and chat to fellow developers, and share tips and horror stories and ideas and warnings about how to do what it is we do. We don’t meet up often and there is always something to say. Plus I have to tell Nicholas how wrong he is about freemium :D

If you are a UK indie developer, not sure whether it’s worth going, I humbly suggest it probably is :D

The mental coding stack, and avoiding interruptions

I was coding something in G4 recently, and it was in theory a simple thing. I was trying to work out why a certain unit in my game was not opening fire on another unit when I knew it should be.

When I was looking at the unit onscreen, it was one of several, and stepping through code is frustrating if you aren’t sure who is who. The best solution in this case was for me to overlay a range UI on the screen so I could check it wasn’t a range issue. That meant writing some new code to display the range UI, which is fine. The problem is that meant getting the range for that unit into the GUI code, and there was no simple way to do that yet. That meant writing some new code to make a note of the range for that unit elsewhere…

In an office, this is normally the point where someone taps you on the shoulder or asks you a question… And then it all falls apart. At this point my mental ‘stack’ is this:

Working on G4
...Debugging the firing bug
...Adding a range overlay
...Writing code to access max range

The longer that list gets, the longer it takes to get back into what you are doing. With really bad bugs (I coded a neural newtork once…eeeek) you can be 10-15 layers in. It can take a good 15 minutes to mentally rebuild that stack accurately if it gets lost, and it *will* get lost the moment you lose your train of thought.

Short summary: Make sure nobody interrupts you when you are coding.