Game Development Reference
In-Depth Information
Listing 8-17 . Colliding with the exit object shows the Level Complete popover and un-
locks the next level
-(BOOL) ccPhysicsCollisionBegin:(CCPhysicsCollisionPair
*)pair
player:(CCNode *)player
exit:(CCNode *)exit
{
[[GameState sharedGameState] unlockNextLevel];
[[GameState sharedGameState] synchronize];
[self showPopoverNamed:@"UserInterface/Popovers/
LevelCompleteLayer"];
return NO;
}
This unlocks the next level. Thanks to the checks performed in Listing 8-6 and Listing
8-7 , you can call this method every time a level is completed. Even if you are replaying
level 1 again, it won't reset the highest unlocked level back to level 2. The GameState
is synchronized, and the changes are written back to disk because you really don't want
the player losing an unlocked level even if the app were to crash a second later.
Note that the synchronize method may or may not be defined, depending on whether
you followed my earlier advice to add it to GameState . If it is undefined, you can add it
to GameState.h and GameState.m now or just replace the call to synchronize with the
following line:
[[NSUserDefaults standardUserDefaults] synchronize];
It's the same thing. And, of course, the LevelCompleteLayer is shown as a popup.
Which brings you to the GameMenuLayer class already. In GameMenuLayer.m , add
an import for the GameState header just below the other import lines, as seen in Listing
8-18 .
Listing 8-18 . Adding the GameState header
#import "GameMenuLayer.h"
#import "GameScene.h"
#import "SceneManager.h"
#import "GameState.h"
Search WWH ::




Custom Search