I'm building a game that has dozens of dynamically generated mini-levels. To simplify, let's say I've got three types of levels, A, B, and C, and each one can take an integer difficulty. LevelA, LevelB, and LevelC are subclasses of CCLayer, and I've been loading them into a GameScene that's a subclass of CCScene, one at a time. I'm not married to this method; it's just what's been working.
What I can't figure out is how to control the flow of levels in an overarching way.
The simple way to load a new level seems to be replicate the [[CCDirector sharedDirector] replaceScene:[newScene node]]
model - so something like: [[GameScene sharedScene] replaceGameplayLayer:[LevelA newLevelWithDifficulty:5]]]
.
This works fine, but only if the call to the next level comes within the code for the current level. So if I'm in an A-level, I can load up a corresponding B-level every time I hit 10 points - something like:
-(void)checkScore {
if (score >= 10) {
[[GameScene sharedScene] replaceGameplayLayer:[LevelB newLevelWithDifficulty:currentLevelDifficulty]];
}
}
And then do the same in the LevelB class to load up C-levels, or some other configuration.
But what if I want to plan out a level order? A1, B1, C1, C2, C3, C4, C5, A2, etc? I'd like to be able to treat each level as a synchronous line in a function. Like:
-(void)playGame {
[LevelA newLevelWithDifficulty:1];
[LevelB newLevelWithDifficulty:1];
for (int i = 0; i < 5; i++) {
[LevelC newLevelWithDifficulty:i];
}
// ...etc...
}
I'm not sure how to tackle the problem though. Is it even possible? It's easy enough to make that checkScore method just kill the current Level at 10 points, but how would I keep LevelB from happening until it did?
I hope this question makes sense. Any help you could offer would be appreciated.