Bedroom Coder Rebooted

In which a lapsed developer of 16-bit freeware attempts to rekindle his game dev 'skillz' after half a lifetime away. Backstory here.

Posts tagged C

Dec 6

Sound and vision

So, having swotted up on the nuts and bolts of C++ it’s time to make a start on my first game.

Before I get that far, though, there’s the small matter of making the leap from command-line based, text-only programs to all-singing, all-dancing (literally) games programming.

It’s a bigger leap than it might sound to the non-programmers out there. There are many things a game needs to do that aren’t covered in the standard C++ libraries or taught in the core tutorials, and that would be hugely complicated for a beginner to write from scratch.

Things like drawing things on the screen, moving sprites around, playing sounds and music, loading graphics and sound files from disk, checking for input from a joypad… that sort of thing.

Fortunately for the beginner, there are various free libraries out there that essentially provide extra commands to use in programs to do all that sort of thing for you.

Allegro, the library I used during my brief foray into C, is still doing the rounds and seems quite a popular choice for my fellow newbies. But although it works with C++, it isn’t built from the ground up for the language (it isn’t “object-oriented”, which I gather is quite important - although I’m not quite sure why).

Another popular choice is SDL, which has also been around for a fair old while and has many devotees. This, it seems, is the more “hardcore” option and has made its way into several commercial titles.

But I’m going with the new kid on the block. SFML (it stands for Simple Fast Multimedia Library) is in its relative infancy compared to the other two libraries mentioned but gets my vote due in no small part to the noob-friendly tutorial section on its website. It’s completely free, even if used to make commercial software. And, from the quick play about with it that I’ve had tonight, it’s pretty damn impressive.

After following the first couple of tutorials I’ve managed to plonk a big space invader on the screen and get it moving around according to keyboard presses. I can even rotate it, something I couldn’t have done in my wildest dreams back in the Amiga days. Life is good.


Dec 3

Hello again, world

One thing that’s changed since my youthful coding excursions: back in the days of BASIC and its variants, you used to just be able to type in your code and run it on the fly - the computer had time to interpret the lines of human-readable code into machine-readable instructions while it was actually running.

This is mainly because 8-bit BASIC programs ran very slowly indeed, although it was also possible to run a program like this in AMOS provided the person who wanted to run your program also owned the AMOS disk.

That’s a spectacularly inefficient way of working, though, so “proper” programming languages need to be translated into something a computer can run (e.g. an .exe file) before you try to run them.

To do this you need something called a compiler which, back when I briefly tried learning C, used to be an unfriendly, command-line only beast unless you had the cash to pay for a development environment that ran under Windows (in my case I was lucky enough to pick up a slightly outdated one free on a magazine coverdisc).

Fortunately these days it’s far easier to pick up a free and user-friendly development environment thanks to the internet and the growth of the open source movement. Me, I’m going to be using Code::Blocks, a completely free program that on first glance appears more than good enough for my needs.

I particularly like the way it colour-codes your code as you write and helps to keep track of the various brackets and braces so you can see at a glance if they all tally together.

It’s little things like that which make all the difference for a complete novice. As with learning any language, the most common stumbling blocks in a new computer language are grammar problems - my commonest errors in C++ so far have been forgetting to put a semicolon at the end of each instruction, and messing up with the brackets. Always the brackets.

But that said, I’ve now managed to compile and run my first program. In time-honoured fashion, it prints the phrase “Hello world” on the screen.

Baby steps and all that, but so far this doesn’t seem too complicated…


Dec 2

Back in business

I did have one final foray into coding after the AMOS days when, as a student, I taught myself just enough C to program a frankly awful Operation Wolf style shooting gallery game that was basically an elaborate in-joke for a few mates. Hey, I had too much time on my hands.

That was 13 years ago, and I’ve not coded in anger since. I remember virtually nothing about C, except that I taught myself by downloading an in-depth tutorial in PDF format.

Well, if it worked for me once…

As luck would have it, a similar thing exists for C++, over at cplusplus.com, so that’s going to be my starting point.

And so, tutorial in hand, I press on.