Geeks With Blogs
Create Fun Things - Samer's Developer Blog Development Blog for C#, .NET and Obj-C

Since "Doodle Fighter" (working title) is the first game I've ever worked on, a lot of the code started off as you might expect: tons of things cobbled together, none of it properly encapsulated, and a lot of it hard coded. 

The last week I've been focused on pulling a lot of this data out and I decided that one thing I wanted to do (after reading that others recommended doing this) is put a lot of the game logic and design choices into a plist that comes loaded with the app. This lets me do a couple of cool things:

1. It lets me create different plists for shipping, testing, and experimental versions of the game without changing a single line of code.

2. It lets me tweak game settings quickly. In fact, depending on how motivated you are, you can program the game to live-update settings without doing a rebuild of your code. For example, every time you un-pause (in testing mode), your app could re-read the plist and get the updated values. That gives you great testing speed and power to tweak all those details that will make or break your game.

The actual code to read a plist is trivial stuff:

NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:@"GameDesignInformation" ofType:@"plist"];

NSDictionary *plistDictionary = [NSDictionary dictionaryWithContentsOfFile:plistPath];

Then you can enumerate the dictionary using blocks:

    [plistDictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 
// Do things here


How you decide to design your plist is up to you. I created a few arrays for ship types, levels, and then a dictionary defining general game modifiers. I read them into a singleton called LevelManager that stores them in memory while the app is open, so that I don't have to constantly read off the disk. 

When I started with this plist, I first used it to create the game modifiers dictionary as well as a basic array of enemy ship types. Then I expanded it to include things like starting default values, costs for upgrades for my ships, developer only things (like putting on invincibility mode), and other useful testing things like multipliers on speed of enemies, laser firings, and so on. 

It was several hours of doing this work, but because of that I can tweak and modify my game with great ease now!

Posted on Saturday, June 1, 2013 6:22 PM cocos2d , ios development , iOS games | Back to top

Comments on this post: Putting Game logic in a plist file

# re: Putting Game logic in a plist file
Requesting Gravatar...
I like you post.
Left by Tan on May 29, 2015 12:02 AM

Your comment:
 (will show your gravatar)

Copyright © samerpaul | Powered by: