diff options
author | Starla Insigna <starla4444@gmail.com> | 2011-11-30 12:57:06 -0500 |
---|---|---|
committer | Starla Insigna <starla4444@gmail.com> | 2011-11-30 12:57:06 -0500 |
commit | 6e96fb2144718722208d22f892716b55548135e1 (patch) | |
tree | 4dd550de787dd370a13039c03969442f54a3a856 /Classes/GameModeSelection.m | |
parent | fd58a0cde1bb5473e39e6cb82d28113da84b9ae0 (diff) | |
download | cartcollect-6e96fb2144718722208d22f892716b55548135e1.tar.gz cartcollect-6e96fb2144718722208d22f892716b55548135e1.tar.bz2 cartcollect-6e96fb2144718722208d22f892716b55548135e1.zip |
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
Diffstat (limited to 'Classes/GameModeSelection.m')
-rw-r--r-- | Classes/GameModeSelection.m | 49 |
1 files changed, 16 insertions, 33 deletions
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 @@ | |||
13 | 13 | ||
14 | @implementation GameModeSelection | 14 | @implementation GameModeSelection |
15 | 15 | ||
16 | @synthesize name, location, unlocked, delegate; | 16 | @synthesize gameMode, delegate; |
17 | 17 | ||
18 | + (id)selectionWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked | 18 | + (id)selectionWithGameModeInfo:(GameModeInfo*)m_gameMode |
19 | { | 19 | { |
20 | return [[[GameModeSelection alloc] initWithName:name location:location filename:filename unlocked:unlocked] autorelease]; | 20 | return [[[GameModeSelection alloc] initWithGameModeInfo:m_gameMode] autorelease]; |
21 | } | 21 | } |
22 | 22 | ||
23 | + (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition | 23 | - (id)initWithGameModeInfo:(GameModeInfo*)m_gameMode |
24 | { | ||
25 | return [[[GameModeSelection alloc] initWithName:name location:location filename:filename unlockCondition:unlockCondition] autorelease]; | ||
26 | } | ||
27 | |||
28 | - (id)initWithName:(NSString*)m_name location:(NSString*)m_location filename:(NSString*)filename unlocked:(BOOL)m_unlocked; | ||
29 | { | 24 | { |
30 | self = [super initWithTarget:nil selector:nil]; | 25 | self = [super initWithTarget:nil selector:nil]; |
31 | 26 | ||
@@ -33,19 +28,19 @@ | |||
33 | { | 28 | { |
34 | self.anchorPoint = CGPointMake(0.5f, 0.5f); | 29 | self.anchorPoint = CGPointMake(0.5f, 0.5f); |
35 | 30 | ||
36 | name = m_name; | 31 | gameMode = m_gameMode; |
37 | location = m_location; | ||
38 | unlocked = m_unlocked; | ||
39 | 32 | ||
40 | contentSize_ = CGSizeMake(128, 320); | 33 | contentSize_ = CGSizeMake(128, 320); |
41 | 34 | ||
35 | NSString* name = gameMode.name; | ||
36 | NSString* location = gameMode.location; | ||
42 | NSString* filenameMod; | 37 | NSString* filenameMod; |
43 | 38 | ||
44 | if (unlocked) | 39 | if (gameMode.unlocked) |
45 | { | 40 | { |
46 | filenameMod = [NSString stringWithFormat:@"%@-unlocked", filename]; | 41 | filenameMod = [NSString stringWithFormat:@"%@-unlocked", name]; |
47 | } else { | 42 | } else { |
48 | filenameMod = [NSString stringWithFormat:@"%@-locked", filename]; | 43 | filenameMod = [NSString stringWithFormat:@"%@-locked", name]; |
49 | name = [@"" stringByPaddingToLength:name.length withString:@"?" startingAtIndex:0]; | 44 | name = [@"" stringByPaddingToLength:name.length withString:@"?" startingAtIndex:0]; |
50 | location = [@"" stringByPaddingToLength:location.length withString:@"?" startingAtIndex:0]; | 45 | location = [@"" stringByPaddingToLength:location.length withString:@"?" startingAtIndex:0]; |
51 | } | 46 | } |
@@ -93,7 +88,7 @@ | |||
93 | UIImage* selectionBackground = UIGraphicsGetImageFromCurrentImageContext(); | 88 | UIImage* selectionBackground = UIGraphicsGetImageFromCurrentImageContext(); |
94 | 89 | ||
95 | // Now we want to put the level image inside the frame without messing up the frame itself | 90 | // Now we want to put the level image inside the frame without messing up the frame itself |
96 | UIImage* innerPicture = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:filename ofType:@"png"]]; | 91 | UIImage* innerPicture = gameMode.image; |
97 | CGContextClipToMask(context, CGRectMake(0, 0, boxSize.width, boxSize.height), [[selectionBackground opaqueMaskFromWhiteImage] CGImage]); | 92 | CGContextClipToMask(context, CGRectMake(0, 0, boxSize.width, boxSize.height), [[selectionBackground opaqueMaskFromWhiteImage] CGImage]); |
98 | [innerPicture drawInRect:CGRectMake(6, 6, 128, 128)]; | 93 | [innerPicture drawInRect:CGRectMake(6, 6, 128, 128)]; |
99 | selectionBackground = UIGraphicsGetImageFromCurrentImageContext(); | 94 | selectionBackground = UIGraphicsGetImageFromCurrentImageContext(); |
@@ -104,7 +99,7 @@ | |||
104 | context = UIGraphicsGetCurrentContext(); | 99 | context = UIGraphicsGetCurrentContext(); |
105 | CGContextSaveGState(context); | 100 | CGContextSaveGState(context); |
106 | 101 | ||
107 | if (unlocked) | 102 | if (gameMode.unlocked) |
108 | { | 103 | { |
109 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); | 104 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); |
110 | [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height)]; | 105 | [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height)]; |
@@ -159,7 +154,7 @@ | |||
159 | titleSprite.position = ccp(-10, (boxSize.height)/2+(combinedTitleSize.height)/2); | 154 | titleSprite.position = ccp(-10, (boxSize.height)/2+(combinedTitleSize.height)/2); |
160 | [self addChild:titleSprite]; | 155 | [self addChild:titleSprite]; |
161 | 156 | ||
162 | if (unlocked) | 157 | if (gameMode.unlocked) |
163 | { | 158 | { |
164 | Highscore* localHighscore = [Highscore localHighscoreForGameMode:name]; | 159 | Highscore* localHighscore = [Highscore localHighscoreForGameMode:name]; |
165 | 160 | ||
@@ -177,7 +172,7 @@ | |||
177 | 172 | ||
178 | CGImageRef highscoreImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; | 173 | CGImageRef highscoreImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; |
179 | UIGraphicsEndImageContext(); | 174 | UIGraphicsEndImageContext(); |
180 | CCSprite* highscoreSprite = [CCSprite spriteWithCGImage:highscoreImage key:[NSString stringWithFormat:@"gms-%@-highscore-%d", filename, localHighscore.score]]; | 175 | CCSprite* highscoreSprite = [CCSprite spriteWithCGImage:highscoreImage key:[NSString stringWithFormat:@"gms-%@-highscore-%d", name, localHighscore.score]]; |
181 | highscoreSprite.position = ccp(-5, 0-64-(highscoreSize.height)/2-10); | 176 | highscoreSprite.position = ccp(-5, 0-64-(highscoreSize.height)/2-10); |
182 | [self addChild:highscoreSprite]; | 177 | [self addChild:highscoreSprite]; |
183 | } | 178 | } |
@@ -187,21 +182,9 @@ | |||
187 | return self; | 182 | return self; |
188 | } | 183 | } |
189 | 184 | ||
190 | - (id)initWithName:(NSString *)m_name location:(NSString *)m_location filename:(NSString *)m_filename unlockCondition:(NSString*)m_unlockCondition | ||
191 | { | ||
192 | self = [self initWithName:m_name location:m_location filename:m_filename unlocked:NO]; | ||
193 | |||
194 | if (nil != self) | ||
195 | { | ||
196 | unlockCondition = m_unlockCondition; | ||
197 | } | ||
198 | |||
199 | return self; | ||
200 | } | ||
201 | |||
202 | - (void)buttonTapped | 185 | - (void)buttonTapped |
203 | { | 186 | { |
204 | if (unlocked) | 187 | if (gameMode.unlocked) |
205 | { | 188 | { |
206 | if (delegate != nil) | 189 | if (delegate != nil) |
207 | { | 190 | { |
@@ -210,7 +193,7 @@ | |||
210 | NSLog(@"I don't have a GameModeSelectionDelegate to call for some reason..."); | 193 | NSLog(@"I don't have a GameModeSelectionDelegate to call for some reason..."); |
211 | } | 194 | } |
212 | } else { | 195 | } else { |
213 | UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"To unlock this game mode:" message:unlockCondition delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; | 196 | UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"To unlock this game mode:" message:gameMode.unlockCondition delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; |
214 | [alertView show]; | 197 | [alertView show]; |
215 | [alertView release]; | 198 | [alertView release]; |
216 | } | 199 | } |