How to Make a Turn-Based Strategy Game – Part 2

This is a post by iOS Tutorial Team Member Pablo Ruiz, an iOS game developer, and co-founder and COO at InfinixSoft. Check out his blog, or follow him on Twitter. Welcome to the second half of the tutorial series that walks you through a basic turn-based strategy game for the iPhone! In the first part […] By .

5 (1) · 1 Review

Save for later
You are currently viewing page 5 of 5 of this article. Click here to view the first page.

Music and Sounds

You're almost done with the project. Let's add some music and sound effects to jazz things up and you're set! In case you're curious, I got the music from and made the sound effects with CXFR.

First, import SimpleAudioEngine at the top of HelloWorldLayer.m:

#import "SimpleAudioEngine.h"

Now we can use SimpleAudioEngine to play the background music. Add the following line at the end of init (after [self addMenu]):

// Play background music
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"Five Armies.mp3" loop:YES];

Finally, let's add some sound effects for various events such as units being attacked or buttons getting pressed.

The first event we want to handle is the button click when you select "End Turn". Add the following line inside doEndTurn, after the first if statement:

// Play sound
[[SimpleAudioEngine sharedEngine] playEffect:@"btn.wav"];

Now, let's switch over to Unit.m and add several sound effects. But first, we need to import SimpleAudioEngine at the top of the file:

#import "SimpleAudioEngine.h"

Then, add a move sound effect for every tile a unit moves through by adding the following line to popStepAndAnimate just before section #2:

// Play move sound
[[SimpleAudioEngine sharedEngine] playEffect:@"move.wav"];

Next, add a sound effect for damage sustained by adding the following code to attackedBy:firstAttack: before the last line where you play the explosion animation:

// Play damage sound
[[SimpleAudioEngine sharedEngine] playEffect:@"hurt.wav"];

Add a sound effect for a unit being destroyed by adding the following to dealDamage:, as the first line in section #4:

// Unit destroyed sound
[[SimpleAudioEngine sharedEngine] playEffect:@"explosion.wav"];

Finally, add sound effects for a menu selection by adding the following line at the top of doStay, doAttack, and doCancel:

// Play menu selection sound
[[SimpleAudioEngine sharedEngine] playEffect:@"btn.wav"];

And that's it - we're done! Build and run the game now, and you should be able to hear all of the music and sound effects.

Where to Go From Here?

Mission Accomplished! Looks like you now have a working turn-based strategy game. Here is the final sample project with everything this tutorial has covered.

But, it's not time to rest on your glory. Even if you laid the foundations for the game, there are a lot of things you can add to make it even better. Here are a few suggestions:

  • How about adding new, more interesting units? For example, ships that can only move in water, units that can carry soldiers, and medics/mechanics that can heal other units?
  • You could add other types of buildings, like a factory that can build new tanks using some currency, or a hospital.
  • Why have just one map? How about creating new maps players can choose from with other terrain types, or with things like traps, destroyable obstacles, etc.?
  • You could completely change the theme. How about going medieval? Or using a sci-fi theme with alien units?

I'd like to hear about any other ideas you have to improve or modify the game, and your experiences working with this tutorial, so head over to the forums to leave your comments. And happy coding!

This is a post by iOS Tutorial Team Member Pablo Ruiz, an iOS game developer, and co-founder and COO at InfinixSoft. Check out his blog, or follow him on Twitter.