Adventures in Swift: Playing with CMMotionManager and gravity

I recently added an iOS game embryo to GitHub: https://github.com/LarsBergqvist/GravityBall

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!

Advertisements

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: https://github.com/LarsBergqvist/BlasterMaster.git

BlasterMaster1

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 →