From 6e96fb2144718722208d22f892716b55548135e1 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Wed, 30 Nov 2011 12:57:06 -0500 Subject: Created a game mode manager There is now one location for information relating to each GameMode instead of several places, so that info can be easily updated and propagated to, for instance, GameModeSelectionLayer. GameModes can also be specified by an info instance each owns. There's also a way to get an ordered list of game modes. The three star game mode unlocking system has also been added. Closes #213 --- Classes/GameModeSelection.m | 49 +++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 33 deletions(-) (limited to 'Classes/GameModeSelection.m') diff --git a/Classes/GameModeSelection.m b/Classes/GameModeSelection.m index 40981b1..61004fa 100644 --- a/Classes/GameModeSelection.m +++ b/Classes/GameModeSelection.m @@ -13,19 +13,14 @@ @implementation GameModeSelection -@synthesize name, location, unlocked, delegate; +@synthesize gameMode, delegate; -+ (id)selectionWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked ++ (id)selectionWithGameModeInfo:(GameModeInfo*)m_gameMode { - return [[[GameModeSelection alloc] initWithName:name location:location filename:filename unlocked:unlocked] autorelease]; + return [[[GameModeSelection alloc] initWithGameModeInfo:m_gameMode] autorelease]; } -+ (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition -{ - return [[[GameModeSelection alloc] initWithName:name location:location filename:filename unlockCondition:unlockCondition] autorelease]; -} - -- (id)initWithName:(NSString*)m_name location:(NSString*)m_location filename:(NSString*)filename unlocked:(BOOL)m_unlocked; +- (id)initWithGameModeInfo:(GameModeInfo*)m_gameMode { self = [super initWithTarget:nil selector:nil]; @@ -33,19 +28,19 @@ { self.anchorPoint = CGPointMake(0.5f, 0.5f); - name = m_name; - location = m_location; - unlocked = m_unlocked; + gameMode = m_gameMode; contentSize_ = CGSizeMake(128, 320); + NSString* name = gameMode.name; + NSString* location = gameMode.location; NSString* filenameMod; - if (unlocked) + if (gameMode.unlocked) { - filenameMod = [NSString stringWithFormat:@"%@-unlocked", filename]; + filenameMod = [NSString stringWithFormat:@"%@-unlocked", name]; } else { - filenameMod = [NSString stringWithFormat:@"%@-locked", filename]; + filenameMod = [NSString stringWithFormat:@"%@-locked", name]; name = [@"" stringByPaddingToLength:name.length withString:@"?" startingAtIndex:0]; location = [@"" stringByPaddingToLength:location.length withString:@"?" startingAtIndex:0]; } @@ -93,7 +88,7 @@ UIImage* selectionBackground = UIGraphicsGetImageFromCurrentImageContext(); // Now we want to put the level image inside the frame without messing up the frame itself - UIImage* innerPicture = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:filename ofType:@"png"]]; + UIImage* innerPicture = gameMode.image; CGContextClipToMask(context, CGRectMake(0, 0, boxSize.width, boxSize.height), [[selectionBackground opaqueMaskFromWhiteImage] CGImage]); [innerPicture drawInRect:CGRectMake(6, 6, 128, 128)]; selectionBackground = UIGraphicsGetImageFromCurrentImageContext(); @@ -104,7 +99,7 @@ context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); - if (unlocked) + if (gameMode.unlocked) { CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height)]; @@ -159,7 +154,7 @@ titleSprite.position = ccp(-10, (boxSize.height)/2+(combinedTitleSize.height)/2); [self addChild:titleSprite]; - if (unlocked) + if (gameMode.unlocked) { Highscore* localHighscore = [Highscore localHighscoreForGameMode:name]; @@ -177,7 +172,7 @@ CGImageRef highscoreImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; UIGraphicsEndImageContext(); - CCSprite* highscoreSprite = [CCSprite spriteWithCGImage:highscoreImage key:[NSString stringWithFormat:@"gms-%@-highscore-%d", filename, localHighscore.score]]; + 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]; } @@ -187,21 +182,9 @@ return self; } -- (id)initWithName:(NSString *)m_name location:(NSString *)m_location filename:(NSString *)m_filename unlockCondition:(NSString*)m_unlockCondition -{ - self = [self initWithName:m_name location:m_location filename:m_filename unlocked:NO]; - - if (nil != self) - { - unlockCondition = m_unlockCondition; - } - - return self; -} - - (void)buttonTapped { - if (unlocked) + if (gameMode.unlocked) { if (delegate != nil) { @@ -210,7 +193,7 @@ NSLog(@"I don't have a GameModeSelectionDelegate to call for some reason..."); } } else { - UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"To unlock this game mode:" message:unlockCondition delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; + UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"To unlock this game mode:" message:gameMode.unlockCondition delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; [alertView show]; [alertView release]; } -- cgit 1.4.1