In my game, I need to instance a certain number of sprites depending on my game's level. That number of sprites is stored in a .plist file. The way my game works is that it selects a random type of enemy for that one particular level. Then, it goes and finds the level number, and then it finds the amount of sprites it need to instance for that level. This is what my plist looks like:
What I need is a way to instance that amount of sprites, no more, no less. I have some ideas on how the code could work, but as I am new to Objective C, I don't know what the code itself would look like.
You can find the number of sprites for a given level like this:
- (int)numberOfSpritesForLevel:(int)level
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"plistFileName" ofType:@"plist"];
NSDictionary *plist = [NSDictionary dictionaryWithContentsOfFile:path];
NSDictionary *levels = [plist objectForKey:@"Mosquito"];
NSString *levelKey = [NSString stringWithFormat:@"L - %d", level]; // Or "L-%d" if there is no space in the keys
return [[levels objectForKey:levelKey] intValue];
}
Then you can create the sprites like this:
int level = 3; // Or whatever value you need.
int numberOfSprites = [self numberOfSpritesForLevel:level];
for (int i = 0; i < numberOfSprites; i++) {
// Create a sprite here
}