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/ClassicGameMode.m | 42 ++++++++----- Classes/GameMode.h | 3 +- Classes/GameMode.m | 20 +++--- Classes/GameModeInfo.h | 41 +++++++++++++ Classes/GameModeInfo.m | 128 +++++++++++++++++++++++++++++++++++++++ Classes/GameModeManager.h | 20 ++++++ Classes/GameModeManager.m | 74 ++++++++++++++++++++++ Classes/GameModeSelection.h | 16 ++--- Classes/GameModeSelection.m | 49 +++++---------- Classes/GameModeSelectionLayer.m | 45 +++----------- Classes/GameOverScene.h | 7 ++- Classes/GameOverScene.m | 31 +++------- Classes/JumpGameMode.m | 22 ++++++- Classes/TutorialMode.m | 24 +++++++- 14 files changed, 382 insertions(+), 140 deletions(-) create mode 100644 Classes/GameModeInfo.h create mode 100644 Classes/GameModeInfo.m create mode 100644 Classes/GameModeManager.h create mode 100644 Classes/GameModeManager.m (limited to 'Classes') diff --git a/Classes/ClassicGameMode.m b/Classes/ClassicGameMode.m index 306c1d1..9356fea 100755 --- a/Classes/ClassicGameMode.m +++ b/Classes/ClassicGameMode.m @@ -10,8 +10,6 @@ #import "FallingObject.h" #import "GameOverScene.h" #import "SimpleAudioEngine.h" -#import "CCNotifications.h" -#import "TestFlight.h" @implementation ClassicGameMode @@ -22,6 +20,26 @@ typedef enum { kRockObject } FallingObjects; +static GameModeInfo* info; + ++ (GameModeInfo*)info +{ + if (info == nil) + { + info = [[GameModeInfo alloc] initWithName:@"Collect" + location:@"Paris" + numOfStars:3 + imageFilename:[[NSBundle mainBundle] pathForResource:@"paris" ofType:@"png"] + unlocked:NO + unlockCondition:@"Beat the tutorial!" + gameClass:[ClassicGameMode class] + globalHighscoreKey:@"Classic" + starsToUnlock:0]; + } + + return info; +} + - (void)tick:(ccTime)dt { int lastScore = score; @@ -32,7 +50,7 @@ typedef enum { { [self unscheduleAllSelectors]; - [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverScene sceneWithScore:score gameMode:@"Collect"]]]; + [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverScene sceneWithScore:score gameMode:[ClassicGameMode info]]]]; } else if (score > lastScore) { if ((lastScore < 6500) && (score >= 6500)) @@ -45,24 +63,14 @@ typedef enum { [self unschedule:@selector(randomlyAddObject:)]; [self schedule:@selector(randomlyAddObject:) interval:0.7f]; addSpeed = 0.7f; - } else if ((lastScore < 3000) && (score >= 3000)) - { - NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; - - if (![defaults boolForKey:@"unlockedJumpMode"]) - { - [[CCNotifications sharedManager] addWithTitle:@"Jump" message:@"You've unlocked a new game mode!" image:@"venice.png"]; - - [defaults setBool:YES forKey:@"unlockedJumpMode"]; - [defaults synchronize]; - - [TestFlight passCheckpoint:@"Unlocked Jump Mode"]; - } } else if ((lastScore < 2500) && (score >= 2500)) { [self unschedule:@selector(randomlyAddObject:)]; [self schedule:@selector(randomlyAddObject:) interval:0.8f]; addSpeed = 0.8f; + } else if ((lastScore < 2000) && (score >= 2000)) + { + [[ClassicGameMode info] setStar:1 withMessage:@"Get 2000 points"]; } else if ((lastScore < 1500) && (score >= 1500)) { [self unschedule:@selector(randomlyAddObject:)]; @@ -73,6 +81,8 @@ typedef enum { [self unschedule:@selector(randomlyAddObject:)]; [self schedule:@selector(randomlyAddObject:) interval:1.0f]; addSpeed = 1.0f; + + [[ClassicGameMode info] setStar:0 withMessage:@"Get 500 points"]; } else if ((lastScore < 150) && (score >= 150)) { [self unschedule:@selector(randomlyAddObject:)]; diff --git a/Classes/GameMode.h b/Classes/GameMode.h index cd0359d..cd41884 100644 --- a/Classes/GameMode.h +++ b/Classes/GameMode.h @@ -9,6 +9,7 @@ #import "CCLayer.h" #import "Cart.h" #import "FallingObjectFactory.h" +#import "GameModeInfo.h" #define GAME_SCENE 436 #define GAME_LAYER 437 @@ -37,7 +38,6 @@ @property (nonatomic,assign) int lives; @property (nonatomic,assign) int pointMultiplier; @property (readonly) BOOL isPaused; -+ (CCScene*)scene; - (void)tick:(ccTime)dt; - (BOOL)canPause; - (void)pause; @@ -45,5 +45,6 @@ - (void)mainmenu; - (void)scheduleDelayedAction:(void(^)(void))delayedAction delay:(float)delay; - (void)runDelayedAction; ++ (GameModeInfo*)info; @end diff --git a/Classes/GameMode.m b/Classes/GameMode.m index 1f2451d..3e2f3ee 100644 --- a/Classes/GameMode.m +++ b/Classes/GameMode.m @@ -14,19 +14,6 @@ @synthesize cart, score, lives, isPaused, pointMultiplier; -+ (CCScene*)scene -{ - CCScene* scene = [CCScene node]; - - GameMode* layer = [self node]; - layer.tag = GAME_LAYER; - [scene addChild:layer]; - - scene.tag = GAME_SCENE; - - return scene; -} - - (id)init { self = [super init]; @@ -213,6 +200,13 @@ } } ++ (GameModeInfo*)info +{ + [NSException raise:@"Unimplemented method" format:@"Method -info of GameMode subclasses must be overridden"]; + + return nil; +} + - (void)dealloc { [objects release]; diff --git a/Classes/GameModeInfo.h b/Classes/GameModeInfo.h new file mode 100644 index 0000000..2262526 --- /dev/null +++ b/Classes/GameModeInfo.h @@ -0,0 +1,41 @@ +// +// GameModeInfo.h +// Cartographic +// +// Created by Starla Insigna on 11/28/11. +// Copyright (c) 2011 Four Island. All rights reserved. +// + +#import +#import "cocos2d.h" + +@interface GameModeInfo : NSObject { + NSString* name; + NSString* location; + BOOL* stars; + int numOfStars; + BOOL unlocked; + UIImage* image; + NSString* unlockCondition; + Class gameClass; + NSString* globalHighscoreKey; + int starsToUnlock; +} + +@property (readonly) NSString* name; +@property (readonly) NSString* location; +@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; +- (void)setStar:(int)star_id withMessage:(NSString*)message; +- (BOOL)star:(int)star_id; +- (int)starsCollected; +- (CCScene*)scene; +- (void)unlock; +- (void)dealloc; + +@end diff --git a/Classes/GameModeInfo.m b/Classes/GameModeInfo.m new file mode 100644 index 0000000..8b33fd8 --- /dev/null +++ b/Classes/GameModeInfo.m @@ -0,0 +1,128 @@ +// +// GameModeInfo.m +// Cartographic +// +// Created by Starla Insigna on 11/28/11. +// Copyright (c) 2011 Four Island. All rights reserved. +// + +#import "GameModeInfo.h" +#import "CCNotifications.h" +#import "GameMode.h" +#import "GameModeManager.h" +#import "TestFlight.h" + +@implementation GameModeInfo + +@synthesize name, location, numOfStars, image, unlocked, unlockCondition, globalHighscoreKey, 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 +{ + self = [super init]; + + if (nil != self) + { + name = m_name; + 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]]; + if (!unlocked) + { + unlocked = m_unlocked; + } + + stars = (BOOL*) calloc(numOfStars, sizeof(BOOL)); + for (int i=0; i + +@interface GameModeManager : NSObject { + NSArray* gameModes; + int stars; +} + +@property (readonly) NSArray* gameModes; +@property (assign) int stars; ++ (GameModeManager*)sharedInstance; + +@end diff --git a/Classes/GameModeManager.m b/Classes/GameModeManager.m new file mode 100644 index 0000000..5a6e109 --- /dev/null +++ b/Classes/GameModeManager.m @@ -0,0 +1,74 @@ +// +// GameModeManager.m +// Cartographic +// +// Created by Starla Insigna on 11/29/11. +// Copyright (c) 2011 Four Island. All rights reserved. +// + +#import "GameModeManager.h" +#import "GameModeInfo.h" +#import "TutorialMode.h" +#import "ClassicGameMode.h" +#import "JumpGameMode.h" + +@implementation GameModeManager + +@synthesize gameModes; + +static GameModeManager* sharedInstance = nil; + ++ (GameModeManager*)sharedInstance +{ + if (sharedInstance == nil) + { + sharedInstance = [[GameModeManager alloc] init]; + } + + return sharedInstance; +} + +- (id)init +{ + self = [super init]; + + if (nil != self) + { + gameModes = [[NSArray alloc] initWithObjects: + [TutorialMode info], + [ClassicGameMode info], + [JumpGameMode info], + nil]; + + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; + stars = [defaults integerForKey:@"stars"]; + } + + return self; +} + +- (void)setStars:(int)m_stars +{ + if (stars != m_stars) + { + stars = m_stars; + + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; + [defaults setInteger:m_stars forKey:@"stars"]; + + for (GameModeInfo* gameMode in gameModes) + { + if ((!gameMode.unlocked) && (stars >= gameMode.starsToUnlock)) + { + [gameMode unlock]; + } + } + } +} + +- (int)stars +{ + return stars; +} + +@end diff --git a/Classes/GameModeSelection.h b/Classes/GameModeSelection.h index bdb38fb..ec6d5ad 100644 --- a/Classes/GameModeSelection.h +++ b/Classes/GameModeSelection.h @@ -8,23 +8,17 @@ #import "cocos2d.h" #import "GameModeSelectionDelegate.h" +#import "GameModeInfo.h" @interface GameModeSelection : CCMenuItem { - NSString* name; - NSString* location; - BOOL unlocked; - NSString* unlockCondition; + GameModeInfo* gameMode; id delegate; } -@property (readonly) NSString* name; -@property (readonly) NSString* location; -@property (readonly) BOOL unlocked; +@property (readonly) GameModeInfo* gameMode; @property (nonatomic,retain) id delegate; -+ (id)selectionWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked; -+ (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition; -- (id)initWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked; -- (id)initWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition; ++ (id)selectionWithGameModeInfo:(GameModeInfo*)m_gameMode; +- (id)initWithGameModeInfo:(GameModeInfo*)m_gameMode; - (void)buttonTapped; @end 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]; } diff --git a/Classes/GameModeSelectionLayer.m b/Classes/GameModeSelectionLayer.m index e7b6966..e5a83f1 100644 --- a/Classes/GameModeSelectionLayer.m +++ b/Classes/GameModeSelectionLayer.m @@ -11,11 +11,10 @@ #import #import "Cart_CollectAppDelegate.h" #import "MainMenuLayer.h" -#import "TutorialMode.h" -#import "ClassicGameMode.h" #import "NMPanelMenu.h" -#import "JumpGameMode.h" #import "ZoomFadeTransition.h" +#import "GameModeInfo.h" +#import "GameModeManager.h" @implementation GameModeSelectionLayer @@ -44,31 +43,12 @@ NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; gameModes = [[NSMutableArray alloc] init]; - GameModeSelection* tutorialSelection = [GameModeSelection selectionWithName:@"Tutorial" location:@"Florence" filename:@"florence" unlocked:YES]; - [gameModes addObject:tutorialSelection]; - - GameModeSelection* collectSelection; - - if ([defaults boolForKey:@"hasDoneTutorial"]) - { - collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" unlocked:YES]; - } else { - collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" unlockCondition:@"Beat the tutorial!"]; - } - - [gameModes addObject:collectSelection]; - - GameModeSelection* jumpSelection; - - if ([defaults boolForKey:@"unlockedJumpMode"]) + for (GameModeInfo* info in [[GameModeManager sharedInstance] gameModes]) { - jumpSelection = [GameModeSelection selectionWithName:@"Jump" location:@"Venice" filename:@"venice" unlocked:YES]; - } else { - jumpSelection = [GameModeSelection selectionWithName:@"Jump" location:@"Venice" filename:@"venice" unlockCondition:@"Get 3000 points in Collect!"]; + GameModeSelection* selection = [GameModeSelection selectionWithGameModeInfo:info]; + [gameModes addObject:selection]; } - [gameModes addObject:jumpSelection]; - CCMenu* menu = [CCMenu menuWithItems:nil]; float onePanelWide = 128; float padding = 15; @@ -131,24 +111,15 @@ [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; } -- (void)didSelectGameMode:(GameModeSelection *)gameMode +- (void)didSelectGameMode:(GameModeSelection *)selection { [scrollView setScrollEnabled:NO]; [pageControl removeFromSuperview]; - CGPoint opp = [scrollView convertPoint:gameMode.position toView:[[CCDirector sharedDirector] openGLView]]; + CGPoint opp = [scrollView convertPoint:selection.position toView:[[CCDirector sharedDirector] openGLView]]; CGPoint endPosition = ccp(0-(opp.x+158), opp.y); - if ([gameMode.name isEqual:@"Tutorial"]) - { - [[CCDirector sharedDirector] replaceScene:[ZoomFadeTransition transitionWithDuration:5.0f scene:[TutorialMode scene] position:endPosition]]; - } else if ([gameMode.name isEqual:@"Collect"]) - { - [[CCDirector sharedDirector] replaceScene:[ZoomFadeTransition transitionWithDuration:5.0f scene:[ClassicGameMode scene] position:endPosition]]; - } else if ([gameMode.name isEqual:@"Jump"]) - { - [[CCDirector sharedDirector] replaceScene:[ZoomFadeTransition transitionWithDuration:5.0f scene:[JumpGameMode scene] position:endPosition]]; - } + [[CCDirector sharedDirector] replaceScene:[ZoomFadeTransition transitionWithDuration:5.0f scene:[selection.gameMode scene] position:endPosition]]; } @end diff --git a/Classes/GameOverScene.h b/Classes/GameOverScene.h index f596211..5987c20 100755 --- a/Classes/GameOverScene.h +++ b/Classes/GameOverScene.h @@ -8,6 +8,7 @@ #import #import "cocos2d.h" +#import "GameModeInfo.h" @interface GameOverScene : CCScene { CCLayer* theLayer; @@ -19,12 +20,12 @@ UIButton* backButton; UIButton* playButton; int score; - NSString* gameMode; + GameModeInfo* gameMode; BOOL playAgain; } -+ (GameOverScene*)sceneWithScore:(int)score gameMode:(NSString*)gameMode; -- (id)initWithScore:(int)score gameMode:(NSString*)gameMode; ++ (GameOverScene*)sceneWithScore:(int)score gameMode:(GameModeInfo*)gameMode; +- (id)initWithScore:(int)score gameMode:(GameModeInfo*)gameMode; - (void)newgame:(id)sender; - (void)submitScore; - (void)exit; diff --git a/Classes/GameOverScene.m b/Classes/GameOverScene.m index a56aeac..07186c2 100755 --- a/Classes/GameOverScene.m +++ b/Classes/GameOverScene.m @@ -11,17 +11,15 @@ #import #import "cocoslive.h" #import "MainMenuLayer.h" -#import "ClassicGameMode.h" -#import "JumpGameMode.h" @implementation GameOverScene -+ (GameOverScene*)sceneWithScore:(int)score gameMode:(NSString*)gameMode ++ (GameOverScene*)sceneWithScore:(int)score gameMode:(GameModeInfo*)gameMode { return [[[GameOverScene alloc] initWithScore:score gameMode:gameMode] autorelease]; } -- (id)initWithScore:(int)score2 gameMode:(NSString*)gameMode2 +- (id)initWithScore:(int)m_score gameMode:(GameModeInfo*)m_gameMode { self = [super init]; @@ -37,8 +35,8 @@ backgroundImage.position = ccp(240, 160); [theLayer addChild:backgroundImage z:0]; - score = score2; - gameMode = gameMode2; + score = m_score; + gameMode = m_gameMode; movingLayer = [[UIView alloc] initWithFrame:CGRectMake(0, -320, 480, 320)]; movingLayer.backgroundColor = [UIColor clearColor]; @@ -47,7 +45,7 @@ scoreField = [[UILabel alloc] initWithFrame:CGRectMake(205, 320-200, 0, 0)]; [scoreField setFont:[UIFont systemFontOfSize:20.0f]]; [scoreField setBackgroundColor:[UIColor clearColor]]; - [scoreField setText:[NSString stringWithFormat:@"%d", score2]]; + [scoreField setText:[NSString stringWithFormat:@"%d", score]]; CGSize labelSize = [scoreField.text sizeWithFont:scoreField.font constrainedToSize:CGSizeMake(160, 31) lineBreakMode:UILineBreakModeClip]; [scoreField setFrame:CGRectMake(scoreField.frame.origin.x, scoreField.frame.origin.y, labelSize.width, labelSize.height)]; [movingLayer addSubview:scoreField]; @@ -103,7 +101,7 @@ textField.enabled = NO; submitSwitch.enabled = NO; - const char* sqlQuery = [[NSString stringWithFormat:@"INSERT INTO highscores (name, score, gameMode) VALUES (\"%@\",%d,\"%@\")", [textField text], score, gameMode] UTF8String]; + const char* sqlQuery = [[NSString stringWithFormat:@"INSERT INTO highscores (name, score, gameMode) VALUES (\"%@\",%d,\"%@\")", [textField text], score, gameMode.name] UTF8String]; sqlite3_stmt* compiled_statement; if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) @@ -128,14 +126,7 @@ CLScoreServerPost* server = [[CLScoreServerPost alloc] initWithGameName:@"Cart Collect" gameKey:@"38f440a074b3264386455a36b2706d8f" delegate:self]; NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; - - if ([gameMode isEqual:@"Collect"]) - { - [dict setObject:@"Classic" forKey:@"cc_category"]; - } else { - [dict setObject:gameMode forKey:@"cc_category"]; - } - + [dict setObject:gameMode.globalHighscoreKey forKey:@"cc_category"]; [dict setObject:[textField text] forKey:@"cc_playername"]; [dict setObject:[NSNumber numberWithInt:score] forKey:@"cc_score"]; [server sendScore:dict]; @@ -224,13 +215,7 @@ if (playAgain) { - if ([gameMode isEqual:@"Collect"]) - { - [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:3.0f scene:[ClassicGameMode scene] withColor:ccc3(0, 0, 0)]]; - } else if ([gameMode isEqual:@"Jump"]) - { - [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:3.0f scene:[JumpGameMode scene] withColor:ccc3(0, 0, 0)]]; - } + [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:3.0f scene:[gameMode scene] withColor:ccc3(0, 0, 0)]]; } else { [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; } diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index a5c2b8f..b1c5989 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m @@ -35,6 +35,26 @@ typedef enum { kPointMultiplierObject } FallingObjects; +static GameModeInfo* info; + ++ (GameModeInfo*)info +{ + if (info == nil) + { + info = [[GameModeInfo alloc] initWithName:@"Jump" + location:@"Venice" + numOfStars:3 + imageFilename:[[NSBundle mainBundle] pathForResource:@"venice" ofType:@"png"] + unlocked:NO + unlockCondition:@"Get 2000 points in Collect!" + gameClass:[JumpGameMode class] + globalHighscoreKey:@"Jump" + starsToUnlock:2]; + } + + return info; +} + - (id)init { self = [super init]; @@ -208,7 +228,7 @@ typedef enum { { [self unscheduleAllSelectors]; - [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverScene sceneWithScore:score gameMode:@"Jump"]]]; + [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverScene sceneWithScore:score gameMode:[JumpGameMode info]]]]; } if (wave) diff --git a/Classes/TutorialMode.m b/Classes/TutorialMode.m index 156b939..54f4e16 100644 --- a/Classes/TutorialMode.m +++ b/Classes/TutorialMode.m @@ -10,6 +10,7 @@ #import "FallingObject.h" #import "GameModeSelectionLayer.h" #import "SimpleAudioEngine.h" +#import "ClassicGameMode.h" // Item tags: // 2000 - first dropped item @@ -30,6 +31,26 @@ typedef enum { @synthesize currentTutorial; +static GameModeInfo* info; + ++ (GameModeInfo*)info +{ + if (info == nil) + { + info = [[GameModeInfo alloc] initWithName:@"Tutorial" + location:@"Florence" + numOfStars:0 + imageFilename:[[NSBundle mainBundle] pathForResource:@"florence" ofType:@"png"] + unlocked:YES + unlockCondition:nil + gameClass:[TutorialMode class] + globalHighscoreKey:nil + starsToUnlock:0]; + } + + return info; +} + - (id)init { self = [super init]; @@ -357,8 +378,7 @@ typedef enum { [self unschedule:@selector(randomlyAddObject:)]; - NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; - [defaults setBool:YES forKey:@"hasDoneTutorial"]; + [[ClassicGameMode info] unlock]; return; } else { -- cgit 1.4.1