Adventures in Swift: Playing with CMMotionManager and gravity

I recently added an iOS game embryo to GitHub:

It’s a SpriteKit-based game in Swift 2.0 where you tilt the device to roll a spike ball around with the aim of smashing an infinite number of balloons.

Yes, it’s an endless game with no more purpose than destroying balloons for pure pleasure. But the major stakeholder for this piece of code likes to play it (my 4-year old son that currently has an obsession with physical balloon annihilation – with an app there’s much less to tidy up afterwards).

The code illustrates usage of accelerator data and multiple gravity fields. The physic’s world has a normal vertical gravity field, but there is also a SpringField in the middle of the scene that interacts with the balloons so reaching the balloons gets a bit harder.

I will use this game template for a complete maze ball game in the near future (do you remember those wooden games from BRIO in a not so distant past when there were no computer games around?) – perhaps with some Pac-Man ghost as enemies in the labyrinth.

Game on!


Adventures in Swift: Making a blasting shoot’em up

For further fun and learning with Swift and game design, I decided to make a space shoot’em up in classic style for iOS. The code for the game can be fetched from this repository in GitHub:


Game idea

The player commands a ship at the lower part of the screen and can move to the left and right to aim at enemies and upwards to trigger a thrust at the aliens spawning ground. The background moves slowly downwards which creates an illusion of constant upward movement. Evil invading aliens ships appear from the top of the screen and moves downwards, sometimes shooting red deadly laser beams. The player’s task is to laser-blast the aliens to infinity and beyond without being hit by the aliens ships or lasers.

Continue reading →

Adventures in Swift: simplifying platform game level design with SpriteKit

Since my formative Commodore days (and even before with Colecovision), I’ve always loved platform games, and now I’ve found a fun programming exercise in making one for iOS. I have already explored the basics of Swift, Xcode and SpriteKit in my previous post, and now I am going further with the game level design.

Continue reading →

Adventures in Swift: exploring SpriteKit

I decided to have a go at Apple’s programming language Swift, and for some extra fun I opted for making a simple SpriteKit game for OS X. I have made the code available at GitHub in this repository.

Game play

One Knight, lots of soccer balls and a black hole that eats objects that comes close enough. The Knight scores 1 point for each ball that he can get into the black hole. There is a time limit of 1 minute to get as many soccer balls as possible into the black hole. If the Knight gets too close to the black hole, he will be devoured and it is game over.

Continue reading →