Today's christmas festivities were celebrated in the form of a bit of hacktastic skullduggery, in the form of an overdue get together of Bournemouth's finest coders, hosted by our friends at RedWeb.

I decided, given the festive season, to take some time to get acquainted with SpriteKit and build out the game idea that I had been conceptualising with my little 3 year old son Rudi.

The game, a Disney Cars inspired shoot em up, where Rudi, the games main protagonist, gets to fire his warchest of cars toys at the oncoming Tyger (Rudi's one year old brother). The premise of the game, to provide a virtualised outlet for Rudi to satisfy his insatiable urge to throw things, whilst teaching him the appropriateness of his actions in real world and virtual settings.

I set the game scene up quickly, based on a fairly generic xcode SpriteKit game template and the very entry level tutorial from Ray Wenderlich.

The main customisations I made, aside from the graphical components, were features driven by requests from my son.

1. "Daddy, can I throw different Cars?" 

The initial game setup just had a single projectile type, the obvious Lightning McQueen. So one of the first orders of business, was to create a full armoury of projectiles, of our favourite Cars characters.  First request was for Professor Z, and not content for long, I added 9 different options. 

I setup a UIVIew container, and placed the UIButton outlets inside it. I created a UIButton *menuButton which would have a background image that reflected the currently selected image. When the menuButton is pressed the weapon drawer will toggle open and closed.

2. Unlocking Weapons

It would be all too boring to just put all the projectile types in the tray from the start. Instead, I setup a simple game mechanic that involved unlocking the projectile types when a certain number of hits had been achieved. Whenever 

projectile:(SKSpriteNode *)projectile didCollideWithMonster:(SKSpriteNode *)monster

is called, the int pointsCounter is incremented and the score label text updated. We also save the score to the NSUserDefaults.

- (void)projectile:(SKSpriteNode *)projectile didCollideWithMonster:(SKSpriteNode *)monster {

[projectile removeFromParent];
[monster removeFromParent];
if (updateLabel == NO) {
updateLabel = YES;
[self updateUserDefaults];
[self loadProjectiles];

3. "Daddy, can I move myself?"

I enabled Core Motion, to access the accelerometer to enable using the tilt of the device to move the Rudi character up and down, whilst firing at the on coming baddies.

I found this tutorial to be quite helpful here:

What next?

There's still much to do before the game will be accepted by its harshest critic. Some of the next things will be:

  • Fix some bugs with current physicsBody affecting the Player node.
  • Use SKParticleEmitter to create collision explosions, projectile trails, and smoke.
  • Create levels
  • Give projectiles different properties and behaviours.
  • Parallax for background scene to provide some depth

Thanks to the internet for providing the images and other such assets.