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 --- Cartographic.xcodeproj/project.pbxproj | 24 +++++++ 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 ++++++- Resources/star_1.png | Bin 0 -> 733 bytes Resources/star_2.png | Bin 0 -> 714 bytes Resources/star_3.png | Bin 0 -> 753 bytes 18 files changed, 406 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 create mode 100755 Resources/star_1.png create mode 100755 Resources/star_2.png create mode 100755 Resources/star_3.png diff --git a/Cartographic.xcodeproj/project.pbxproj b/Cartographic.xcodeproj/project.pbxproj index 5aed3f5..464cf44 100755 --- a/Cartographic.xcodeproj/project.pbxproj +++ b/Cartographic.xcodeproj/project.pbxproj @@ -124,6 +124,11 @@ 6CC89DD913F2F4E6003704F7 /* Entitlements.plist in Resources */ = {isa = PBXBuildFile; fileRef = 6CC89DD813F2F4E6003704F7 /* Entitlements.plist */; }; 6CC89DDF13F31413003704F7 /* TutorialMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 6CC89DDE13F31413003704F7 /* TutorialMode.m */; }; 6CDBE80C14092DB00072F287 /* ledge.png in Resources */ = {isa = PBXBuildFile; fileRef = 6CDBE80B14092DB00072F287 /* ledge.png */; }; + 6CE5F7EA1483FAC8008E9ADA /* GameModeInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 6CE5F7E91483FAC8008E9ADA /* GameModeInfo.m */; }; + 6CE5F7EE14855331008E9ADA /* GameModeManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6CE5F7ED14855331008E9ADA /* GameModeManager.m */; }; + 6CE5F7F214869D98008E9ADA /* star_1.png in Resources */ = {isa = PBXBuildFile; fileRef = 6CE5F7EF14869D98008E9ADA /* star_1.png */; }; + 6CE5F7F314869D98008E9ADA /* star_2.png in Resources */ = {isa = PBXBuildFile; fileRef = 6CE5F7F014869D98008E9ADA /* star_2.png */; }; + 6CE5F7F414869D98008E9ADA /* star_3.png in Resources */ = {isa = PBXBuildFile; fileRef = 6CE5F7F114869D98008E9ADA /* star_3.png */; }; 6CF64C0B141BA37000F3B702 /* multiplier.png in Resources */ = {isa = PBXBuildFile; fileRef = 6CF64C0A141BA37000F3B702 /* multiplier.png */; }; 6CF64C11141BA84200F3B702 /* Absorption2.wav in Resources */ = {isa = PBXBuildFile; fileRef = 6CF64C10141BA84200F3B702 /* Absorption2.wav */; }; 6CF64C1D141BFA9600F3B702 /* FallingObjectFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 6CF64C1C141BFA9600F3B702 /* FallingObjectFactory.m */; }; @@ -459,6 +464,13 @@ 6CC89DE013F3197F003704F7 /* FallingObjectDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FallingObjectDelegate.h; sourceTree = ""; }; 6CDBE80B14092DB00072F287 /* ledge.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ledge.png; sourceTree = ""; }; 6CDBE80E140936CF0072F287 /* CartDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CartDelegate.h; sourceTree = ""; }; + 6CE5F7E81483FAC8008E9ADA /* GameModeInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameModeInfo.h; sourceTree = ""; }; + 6CE5F7E91483FAC8008E9ADA /* GameModeInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameModeInfo.m; sourceTree = ""; }; + 6CE5F7EC14855331008E9ADA /* GameModeManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameModeManager.h; sourceTree = ""; }; + 6CE5F7ED14855331008E9ADA /* GameModeManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameModeManager.m; sourceTree = ""; }; + 6CE5F7EF14869D98008E9ADA /* star_1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = star_1.png; sourceTree = ""; }; + 6CE5F7F014869D98008E9ADA /* star_2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = star_2.png; sourceTree = ""; }; + 6CE5F7F114869D98008E9ADA /* star_3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = star_3.png; sourceTree = ""; }; 6CF64C0A141BA37000F3B702 /* multiplier.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = multiplier.png; sourceTree = ""; }; 6CF64C10141BA84200F3B702 /* Absorption2.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = Absorption2.wav; sourceTree = ""; }; 6CF64C1B141BFA9600F3B702 /* FallingObjectFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FallingObjectFactory.h; sourceTree = ""; }; @@ -780,6 +792,9 @@ 3F6C7F4D13D647B600C038FE /* Sprites */ = { isa = PBXGroup; children = ( + 6CE5F7EF14869D98008E9ADA /* star_1.png */, + 6CE5F7F014869D98008E9ADA /* star_2.png */, + 6CE5F7F114869D98008E9ADA /* star_3.png */, 6CF64C0A141BA37000F3B702 /* multiplier.png */, 6CDBE80B14092DB00072F287 /* ledge.png */, 6C39CFE613FC46CD002B21AF /* water.png */, @@ -934,6 +949,10 @@ 6CC89DDE13F31413003704F7 /* TutorialMode.m */, 6C39CFE313FC4635002B21AF /* JumpGameMode.h */, 6C39CFE413FC4635002B21AF /* JumpGameMode.m */, + 6CE5F7E81483FAC8008E9ADA /* GameModeInfo.h */, + 6CE5F7E91483FAC8008E9ADA /* GameModeInfo.m */, + 6CE5F7EC14855331008E9ADA /* GameModeManager.h */, + 6CE5F7ED14855331008E9ADA /* GameModeManager.m */, ); name = "Game Modes"; sourceTree = ""; @@ -1467,6 +1486,9 @@ 6CDBE80C14092DB00072F287 /* ledge.png in Resources */, 6CF64C0B141BA37000F3B702 /* multiplier.png in Resources */, 6CF64C11141BA84200F3B702 /* Absorption2.wav in Resources */, + 6CE5F7F214869D98008E9ADA /* star_1.png in Resources */, + 6CE5F7F314869D98008E9ADA /* star_2.png in Resources */, + 6CE5F7F414869D98008E9ADA /* star_3.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1517,6 +1539,8 @@ 6C85834414055B2E009EF100 /* notificationDesign.m in Sources */, 6C4400041415080800A9E1D7 /* ZoomFadeTransition.m in Sources */, 6CF64C1D141BFA9600F3B702 /* FallingObjectFactory.m in Sources */, + 6CE5F7EA1483FAC8008E9ADA /* GameModeInfo.m in Sources */, + 6CE5F7EE14855331008E9ADA /* GameModeManager.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; 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 { diff --git a/Resources/star_1.png b/Resources/star_1.png new file mode 100755 index 0000000..658c711 Binary files /dev/null and b/Resources/star_1.png differ diff --git a/Resources/star_2.png b/Resources/star_2.png new file mode 100755 index 0000000..028a546 Binary files /dev/null and b/Resources/star_2.png differ diff --git a/Resources/star_3.png b/Resources/star_3.png new file mode 100755 index 0000000..97a22b7 Binary files /dev/null and b/Resources/star_3.png differ -- cgit 1.4.1