The Shape of the Code

by Laurie

Onwards and upwards. I now want to talk about my progress in the code. First and foremost, I needed a 2d engine for the iPhone. After a bit of research, I decided to work with Cocos2d – it seems to be fully featured, has fairly deep documentation, and an active community.

So far (at this early stage at least) I haven’t been disappointed.

It is based on multiple Scenes (main menu/level 1/pause menu…), each containing nested Layers and Sprites (think of them as physical transparent sheets behind the screen, with other sheets attached to them).¬†Getting the structure of these scenes, layers, and sprites, correct early on is vital.

I’m working on the in-game action first, and in this scene there needs to be 2 layers – the HUD and the World. These need to be separated at this point because the World layer needs to be scaled and moved to simulate camera movements around the map, while the HUD should remain static.

The World layer is filled with all entities specific to a level (such as Ninjas/walls/lights – who will all manage their own logic), while the HUD will show the score, the thumbstick, and receive the input (which will be passed to the world objects).

Functionality-wise, the point I am up to now is very basic. So far I have:

  • A Thumbstick implementation (I consider this finalized – a post about this will come).
  • A preliminary Gesture Capture layer (currently only handling single taps).
  • A player controlled Ninja, who moves around the world, based on input from the HUD (the movement-model hasn’t been tweaked yet, and the icon is from IconFinder.com).
  • A Level (populated with random, non-colliding squares – to be loaded from a file, and collide-able, in the future).
  • A very basic ‘Camera’, which follows the player ninja, and can zoom in and out (its target and zoom will be set dynamically in the future).

As I’m not yet a fully signed up iOS developer (I’m saving my $99/year till the last minute) I’m unable to test the code on a real iDevice, which is a real pain for testing multitouch input. As a solution I’ve been using iSimulate, and so far it does exactly what it says on the tin – and very well too. By adding a single library to your project it will send touch and accelerometer data wirelessly to the Xcode simulator, so you can multi-tap and gesture with the iPhone in you hands, giving a good feel for how it would be in real life.

Next time: a TODO list.