From 28497668761472e085d0c9955aa8077d11bf353c Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Wed, 2 Jan 2013 23:08:46 -0500 Subject: Removed locked game modes from selection screen Also removed cluttering attributes "unlockCondition" and "starsToUnlock" from GameModeInfo because they're really not that generalized (and unlockCondition doesn't really make sense if locked game modes are invisible anyway). starsToUnlock can be replaced by simply putting if statements in to GameModeManager's setStars: and then unlocking modes based off that. Completing the tutorial also now unlocks both Collect AND Jump. The idea is that we should make more than just Collect available at the start, and have only a few super hidden game modes that are unlockable; hence locked game modes being invisible. --- Classes/ClassicGameMode.m | 6 +-- Classes/GameModeInfo.h | 5 +-- Classes/GameModeInfo.m | 6 +-- Classes/GameModeManager.m | 8 +--- Classes/GameModeSelection.m | 90 ++++++++++++++-------------------------- Classes/GameModeSelectionLayer.m | 7 +++- Classes/JumpGameMode.m | 6 +-- Classes/TutorialMode.m | 6 +-- 8 files changed, 48 insertions(+), 86 deletions(-) diff --git a/Classes/ClassicGameMode.m b/Classes/ClassicGameMode.m index 9356fea..00bf049 100755 --- a/Classes/ClassicGameMode.m +++ b/Classes/ClassicGameMode.m @@ -30,11 +30,9 @@ static GameModeInfo* info; location:@"Paris" numOfStars:3 imageFilename:[[NSBundle mainBundle] pathForResource:@"paris" ofType:@"png"] - unlocked:NO - unlockCondition:@"Beat the tutorial!" + unlocked:YES gameClass:[ClassicGameMode class] - globalHighscoreKey:@"Classic" - starsToUnlock:0]; + globalHighscoreKey:@"Classic"]; } return info; diff --git a/Classes/GameModeInfo.h b/Classes/GameModeInfo.h index 2262526..7d60645 100644 --- a/Classes/GameModeInfo.h +++ b/Classes/GameModeInfo.h @@ -19,7 +19,6 @@ NSString* unlockCondition; Class gameClass; NSString* globalHighscoreKey; - int starsToUnlock; } @property (readonly) NSString* name; @@ -27,10 +26,8 @@ @property (readonly) int numOfStars; @property (readonly) UIImage* image; @property (readonly) BOOL unlocked; -@property (readonly) NSString* unlockCondition; @property (readonly) NSString* globalHighscoreKey; -@property (readonly) int starsToUnlock; -- (id)initWithName:(NSString*)m_name location:(NSString*)m_location numOfStars:(int)m_numOfStars imageFilename:(NSString*)m_imageFilename unlocked:(BOOL)m_unlocked unlockCondition:(NSString*)m_unlockCondition gameClass:(Class)m_gameClass globalHighscoreKey:(NSString*)m_globalHighscoreKey starsToUnlock:(int)m_starsToUnlock; +- (id)initWithName:(NSString*)m_name location:(NSString*)m_location numOfStars:(int)m_numOfStars imageFilename:(NSString*)m_imageFilename unlocked:(BOOL)m_unlocked gameClass:(Class)m_gameClass globalHighscoreKey:(NSString*)m_globalHighscoreKey; - (void)setStar:(int)star_id withMessage:(NSString*)message; - (BOOL)star:(int)star_id; - (int)starsCollected; diff --git a/Classes/GameModeInfo.m b/Classes/GameModeInfo.m index 8b33fd8..1f85978 100644 --- a/Classes/GameModeInfo.m +++ b/Classes/GameModeInfo.m @@ -14,9 +14,9 @@ @implementation GameModeInfo -@synthesize name, location, numOfStars, image, unlocked, unlockCondition, globalHighscoreKey, starsToUnlock; +@synthesize name, location, numOfStars, image, unlocked, globalHighscoreKey; -- (id)initWithName:(NSString*)m_name location:(NSString*)m_location numOfStars:(int)m_numOfStars imageFilename:(NSString*)m_imageFilename unlocked:(BOOL)m_unlocked unlockCondition:(NSString*)m_unlockCondition gameClass:(Class)m_gameClass globalHighscoreKey:(NSString*)m_globalHighscoreKey starsToUnlock:(int)m_starsToUnlock +- (id)initWithName:(NSString*)m_name location:(NSString*)m_location numOfStars:(int)m_numOfStars imageFilename:(NSString*)m_imageFilename unlocked:(BOOL)m_unlocked gameClass:(Class)m_gameClass globalHighscoreKey:(NSString*)m_globalHighscoreKey { self = [super init]; @@ -26,9 +26,7 @@ location = m_location; numOfStars = m_numOfStars; image = [[UIImage alloc] initWithContentsOfFile:m_imageFilename]; - unlockCondition = m_unlockCondition; globalHighscoreKey = m_globalHighscoreKey; - starsToUnlock = m_starsToUnlock; NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; unlocked = [defaults boolForKey:[NSString stringWithFormat:@"gameModeUnlocked-%@", name]]; diff --git a/Classes/GameModeManager.m b/Classes/GameModeManager.m index 5a6e109..d7cd21e 100644 --- a/Classes/GameModeManager.m +++ b/Classes/GameModeManager.m @@ -56,13 +56,7 @@ static GameModeManager* sharedInstance = nil; NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; [defaults setInteger:m_stars forKey:@"stars"]; - for (GameModeInfo* gameMode in gameModes) - { - if ((!gameMode.unlocked) && (stars >= gameMode.starsToUnlock)) - { - [gameMode unlock]; - } - } + // Here, unlock game modes that have reached enough stars } } diff --git a/Classes/GameModeSelection.m b/Classes/GameModeSelection.m index 61004fa..ea5f45b 100644 --- a/Classes/GameModeSelection.m +++ b/Classes/GameModeSelection.m @@ -26,6 +26,13 @@ if (nil != self) { + if (!m_gameMode.unlocked) + { + @throw [NSException exceptionWithName:NSInvalidArgumentException + reason:@"Game mode must be unlocked to appear on selection screen" + userInfo:nil]; + } + self.anchorPoint = CGPointMake(0.5f, 0.5f); gameMode = m_gameMode; @@ -34,16 +41,6 @@ NSString* name = gameMode.name; NSString* location = gameMode.location; - NSString* filenameMod; - - if (gameMode.unlocked) - { - filenameMod = [NSString stringWithFormat:@"%@-unlocked", name]; - } else { - filenameMod = [NSString stringWithFormat:@"%@-locked", name]; - name = [@"" stringByPaddingToLength:name.length withString:@"?" startingAtIndex:0]; - location = [@"" stringByPaddingToLength:location.length withString:@"?" startingAtIndex:0]; - } // First, create the frame that we will put the level picture inside CGImageRef framestuff = [[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"framestuff" ofType:@"png"]] CGImage]; @@ -99,26 +96,13 @@ context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); - if (gameMode.unlocked) - { - CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); - [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height)]; - } else { - // Draw the picture in grayscale if the level has not yet been unlocked - CGContextClipToMask(context, CGRectMake(10, 0, boxSize.width, boxSize.height), [selectionBackground CGImage]); - CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]); - CGContextFillRect(context, CGRectMake(10, 0, boxSize.width, boxSize.height)); - CGContextRestoreGState(context); - - CGContextSaveGState(context); - CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); - [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height) blendMode:kCGBlendModeLuminosity alpha:1.0]; - } + CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); + [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height)]; CGContextRestoreGState(context); CGImageRef pictureRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; - CCSprite* picture = [CCSprite spriteWithCGImage:pictureRef key:[NSString stringWithFormat:@"gms-%@", filenameMod]]; + CCSprite* picture = [CCSprite spriteWithCGImage:pictureRef key:[NSString stringWithFormat:@"gms-%@", name]]; // We're also going to need a "selected" image state for the button CGContextSaveGState(context); @@ -128,7 +112,7 @@ CGContextRestoreGState(context); CGImageRef selectedButtonRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; UIGraphicsEndImageContext(); - CCSprite* selectedButton = [CCSprite spriteWithCGImage:selectedButtonRef key:[NSString stringWithFormat:@"gms-%@-selected", filenameMod]]; + CCSprite* selectedButton = [CCSprite spriteWithCGImage:selectedButtonRef key:[NSString stringWithFormat:@"gms-%@-selected", name]]; CCMenuItemSprite* pictureMenuItem = [CCMenuItemSprite itemFromNormalSprite:picture selectedSprite:selectedButton target:self selector:@selector(buttonTapped)]; NMPanelMenu* theMenu = [NMPanelMenu menuWithItems:pictureMenuItem, nil]; @@ -150,32 +134,29 @@ CGImageRef titleImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; UIGraphicsEndImageContext(); - CCSprite* titleSprite = [CCSprite spriteWithCGImage:titleImage key:[NSString stringWithFormat:@"gms-%@-title", filenameMod]]; + CCSprite* titleSprite = [CCSprite spriteWithCGImage:titleImage key:[NSString stringWithFormat:@"gms-%@-title", name]]; titleSprite.position = ccp(-10, (boxSize.height)/2+(combinedTitleSize.height)/2); [self addChild:titleSprite]; - if (gameMode.unlocked) + Highscore* localHighscore = [Highscore localHighscoreForGameMode:name]; + + if (localHighscore != nil) { - Highscore* localHighscore = [Highscore localHighscoreForGameMode:name]; + // Render the highscore label + NSString* highscoreString = [NSString stringWithFormat:@"Highscore: %d", localHighscore.score]; + UIFont* highscoreFont = [UIFont fontWithName:@"AmericanTypewriter" size:16.0f]; + CGSize highscoreSize = [highscoreString sizeWithFont:highscoreFont]; - if (localHighscore != nil) - { - // Render the highscore label - NSString* highscoreString = [NSString stringWithFormat:@"Highscore: %d", localHighscore.score]; - UIFont* highscoreFont = [UIFont fontWithName:@"AmericanTypewriter" size:16.0f]; - CGSize highscoreSize = [highscoreString sizeWithFont:highscoreFont]; - - UIGraphicsBeginImageContext(CGSizeMake(highscoreSize.width+10, highscoreSize.height+10)); - CGContextRef context = UIGraphicsGetCurrentContext(); - CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); - [highscoreString drawInRect:CGRectMake(10, 0, highscoreSize.width, highscoreSize.height) withFont:highscoreFont]; - - CGImageRef highscoreImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; - UIGraphicsEndImageContext(); - CCSprite* highscoreSprite = [CCSprite spriteWithCGImage:highscoreImage key:[NSString stringWithFormat:@"gms-%@-highscore-%d", name, localHighscore.score]]; - highscoreSprite.position = ccp(-5, 0-64-(highscoreSize.height)/2-10); - [self addChild:highscoreSprite]; - } + UIGraphicsBeginImageContext(CGSizeMake(highscoreSize.width+10, highscoreSize.height+10)); + CGContextRef context = UIGraphicsGetCurrentContext(); + CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); + [highscoreString drawInRect:CGRectMake(10, 0, highscoreSize.width, highscoreSize.height) withFont:highscoreFont]; + + CGImageRef highscoreImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; + UIGraphicsEndImageContext(); + CCSprite* highscoreSprite = [CCSprite spriteWithCGImage:highscoreImage key:[NSString stringWithFormat:@"gms-%@-highscore-%d", name, localHighscore.score]]; + highscoreSprite.position = ccp(-5, 0-64-(highscoreSize.height)/2-10); + [self addChild:highscoreSprite]; } } @@ -184,18 +165,11 @@ - (void)buttonTapped { - if (gameMode.unlocked) + if (delegate != nil) { - if (delegate != nil) - { - [delegate didSelectGameMode:self]; - } else { - NSLog(@"I don't have a GameModeSelectionDelegate to call for some reason..."); - } + [delegate didSelectGameMode:self]; } else { - UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"To unlock this game mode:" message:gameMode.unlockCondition delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; - [alertView show]; - [alertView release]; + NSLog(@"I don't have a GameModeSelectionDelegate to call for some reason..."); } } diff --git a/Classes/GameModeSelectionLayer.m b/Classes/GameModeSelectionLayer.m index e5a83f1..4e51357 100644 --- a/Classes/GameModeSelectionLayer.m +++ b/Classes/GameModeSelectionLayer.m @@ -45,8 +45,11 @@ for (GameModeInfo* info in [[GameModeManager sharedInstance] gameModes]) { - GameModeSelection* selection = [GameModeSelection selectionWithGameModeInfo:info]; - [gameModes addObject:selection]; + if (info.unlocked) + { + GameModeSelection* selection = [GameModeSelection selectionWithGameModeInfo:info]; + [gameModes addObject:selection]; + } } CCMenu* menu = [CCMenu menuWithItems:nil]; diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index b1c5989..3788c97 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m @@ -45,11 +45,9 @@ static GameModeInfo* info; location:@"Venice" numOfStars:3 imageFilename:[[NSBundle mainBundle] pathForResource:@"venice" ofType:@"png"] - unlocked:NO - unlockCondition:@"Get 2000 points in Collect!" + unlocked:YES gameClass:[JumpGameMode class] - globalHighscoreKey:@"Jump" - starsToUnlock:2]; + globalHighscoreKey:@"Jump"]; } return info; diff --git a/Classes/TutorialMode.m b/Classes/TutorialMode.m index 54f4e16..3f37505 100644 --- a/Classes/TutorialMode.m +++ b/Classes/TutorialMode.m @@ -11,6 +11,7 @@ #import "GameModeSelectionLayer.h" #import "SimpleAudioEngine.h" #import "ClassicGameMode.h" +#import "JumpGameMode.h" // Item tags: // 2000 - first dropped item @@ -42,10 +43,8 @@ static GameModeInfo* info; numOfStars:0 imageFilename:[[NSBundle mainBundle] pathForResource:@"florence" ofType:@"png"] unlocked:YES - unlockCondition:nil gameClass:[TutorialMode class] - globalHighscoreKey:nil - starsToUnlock:0]; + globalHighscoreKey:nil]; } return info; @@ -379,6 +378,7 @@ static GameModeInfo* info; [self unschedule:@selector(randomlyAddObject:)]; [[ClassicGameMode info] unlock]; + [[JumpGameMode info] unlock]; return; } else { -- cgit 1.4.1