iSpacies – Beginning iPhone game development.

iSpacies

iSpacies

When I first start to work on a new piece of hardware, almost inevitably my first attempt at getting something up and running is a version of Space Invaders – I consider it  the extended version ‘Hello World’ for games programming, If you stop and think about it for a minute, getting something like Space Invaders running involves not only gaining a reasonable understanding of the underlying hardware (including graphics / input / memory / sound etc), plus a grounding in basic game logic function and flow, but also a chance to get to grips with the less obvious side of development where sometimes people come unstuck – the IDE, compilers, linkers, and associated tools.

Other machines I’ve done this on are the PC (when Direct X first appeared), Playstation One (on the Net Yaroze home development kit), Gameboy Advance, Nintendo DS, and finally here we are on the iPhone.

This time around there were a few more things to consider. First of all, aswell as needing an iPhone or iPod Touch if you want to test on real hardware (no different there to any of the other machines mentioned, luckily I already had a Touch), you need a Mac to develop on (at least without jumping through flaming hoops – Google is your friend if you want more info). You’ll also need to be ready to learn Objective-C, which is the language used to develop with. Basically it’s an object-oriented superset of C (but different to C++). If, like me, you’re coming from a C background, and are prepared to spend some time playing around with the dev kit, and going through various tutorials on the internet, then you’ll eventually get used to it.

Enough babble – on to the project. Even though this is a 2D game, I made an early decision to go the Open GL route (I’ve got a little bit of past experience).

There are a few websites I want to mention as excellent examples of iPhone tutorials:

www.71squared.co.uk – The particle system I’m using here is almost completely theirs (small change to use my texture class), as is the particle.png, and the Singleton class. Absolutely excellent site with amazing tutorials.

Iphone Development – Fantastic info on all things iPhone (and co-author of the best iPhone book I’ve read)

Simon Maurice’s Coding Heaven – A great series of iPhone specific OpenGL tutorials.

There are lots of things missing from this at the moment: In no particular order Sounds, High scores, Difficulty curve, Extra lives.

I’m running the latest version of Xcode (3.1.3) and iPhone SDK (3.0). Let me know if you have any problems with it (I’m far from being an expert but will try my best to help).

Also, this is probably not the finest example of Objective C (or iPhone) code, but I’m offering it up for beginners like me. Any suggestions / criticisms / improvements please let me know. Maybe we can all learn and improve together…

Here’s the project:   (removed)

Game Controls: Press to the left or right of ship to move left or right (has to be near the bottom of the screen). Anywhere in middle of screen to fire. Press anywhere near the top of the screen to Pause / Unpause (controls aren’t perfect either!)