diff options
Diffstat (limited to 'Classes/TutorialMode.m')
| -rw-r--r-- | Classes/TutorialMode.m | 114 |
1 files changed, 82 insertions, 32 deletions
| diff --git a/Classes/TutorialMode.m b/Classes/TutorialMode.m index 3c70a46..3f37505 100644 --- a/Classes/TutorialMode.m +++ b/Classes/TutorialMode.m | |||
| @@ -8,11 +8,10 @@ | |||
| 8 | 8 | ||
| 9 | #import "TutorialMode.h" | 9 | #import "TutorialMode.h" |
| 10 | #import "FallingObject.h" | 10 | #import "FallingObject.h" |
| 11 | #import "Cherry.h" | ||
| 12 | #import "Bottle.h" | ||
| 13 | #import "OneUp.h" | ||
| 14 | #import "Rock.h" | ||
| 15 | #import "GameModeSelectionLayer.h" | 11 | #import "GameModeSelectionLayer.h" |
| 12 | #import "SimpleAudioEngine.h" | ||
| 13 | #import "ClassicGameMode.h" | ||
| 14 | #import "JumpGameMode.h" | ||
| 16 | 15 | ||
| 17 | // Item tags: | 16 | // Item tags: |
| 18 | // 2000 - first dropped item | 17 | // 2000 - first dropped item |
| @@ -22,10 +21,35 @@ | |||
| 22 | // 2009 - rock | 21 | // 2009 - rock |
| 23 | // 2010 - random item dropped after death from first rock | 22 | // 2010 - random item dropped after death from first rock |
| 24 | 23 | ||
| 24 | typedef enum { | ||
| 25 | kCherryObject = 0, | ||
| 26 | kEnergyDrinkObject, | ||
| 27 | kOneUpObject, | ||
| 28 | kRockObject | ||
| 29 | } FallingObjects; | ||
| 30 | |||
| 25 | @implementation TutorialMode | 31 | @implementation TutorialMode |
| 26 | 32 | ||
| 27 | @synthesize currentTutorial; | 33 | @synthesize currentTutorial; |
| 28 | 34 | ||
| 35 | static GameModeInfo* info; | ||
| 36 | |||
| 37 | + (GameModeInfo*)info | ||
| 38 | { | ||
| 39 | if (info == nil) | ||
| 40 | { | ||
| 41 | info = [[GameModeInfo alloc] initWithName:@"Tutorial" | ||
| 42 | location:@"Florence" | ||
| 43 | numOfStars:0 | ||
| 44 | imageFilename:[[NSBundle mainBundle] pathForResource:@"florence" ofType:@"png"] | ||
| 45 | unlocked:YES | ||
| 46 | gameClass:[TutorialMode class] | ||
| 47 | globalHighscoreKey:nil]; | ||
| 48 | } | ||
| 49 | |||
| 50 | return info; | ||
| 51 | } | ||
| 52 | |||
| 29 | - (id)init | 53 | - (id)init |
| 30 | { | 54 | { |
| 31 | self = [super init]; | 55 | self = [super init]; |
| @@ -38,6 +62,11 @@ | |||
| 38 | 62 | ||
| 39 | showedDeathBubble = NO; | 63 | showedDeathBubble = NO; |
| 40 | randomItemsDropped = 0; | 64 | randomItemsDropped = 0; |
| 65 | |||
| 66 | [objectFactory createRecipeWithIdentifier:kCherryObject spriteFilename:@"cherry.png" weight:5]; | ||
| 67 | [objectFactory createRecipeWithIdentifier:kEnergyDrinkObject spriteFilename:@"bottle.png" weight:6]; | ||
| 68 | [objectFactory createRecipeWithIdentifier:kOneUpObject spriteFilename:@"oneup.png" weight:10]; | ||
| 69 | [objectFactory createRecipeWithIdentifier:kRockObject spriteFilename:@"rock.png" weight:7]; | ||
| 41 | } | 70 | } |
| 42 | 71 | ||
| 43 | return self; | 72 | return self; |
| @@ -79,6 +108,24 @@ | |||
| 79 | 108 | ||
| 80 | - (void)didCatchItem:(FallingObject *)item | 109 | - (void)didCatchItem:(FallingObject *)item |
| 81 | { | 110 | { |
| 111 | if (item.objectType == kCherryObject) | ||
| 112 | { | ||
| 113 | [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]]; | ||
| 114 | self.score += 10; | ||
| 115 | } else if (item.objectType == kEnergyDrinkObject) | ||
| 116 | { | ||
| 117 | [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]]; | ||
| 118 | self.score += 25; | ||
| 119 | } else if (item.objectType == kOneUpObject) | ||
| 120 | { | ||
| 121 | [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]]; | ||
| 122 | self.lives++; | ||
| 123 | } else if (item.objectType == kRockObject) | ||
| 124 | { | ||
| 125 | [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]]; | ||
| 126 | self.lives--; | ||
| 127 | } | ||
| 128 | |||
| 82 | if (item.sprite.tag == 2000) | 129 | if (item.sprite.tag == 2000) |
| 83 | { | 130 | { |
| 84 | TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"Congratulations! If you look at your score, you'll see it increased. Catching items is good. Now, let's see what happens when you don't catch an item." name:@"caught-first"]; | 131 | TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"Congratulations! If you look at your score, you'll see it increased. Catching items is good. Now, let's see what happens when you don't catch an item." name:@"caught-first"]; |
| @@ -94,6 +141,12 @@ | |||
| 94 | 141 | ||
| 95 | - (void)didMissItem:(FallingObject *)item | 142 | - (void)didMissItem:(FallingObject *)item |
| 96 | { | 143 | { |
| 144 | if ((item.objectType == kCherryObject) || (item.objectType == kEnergyDrinkObject)) | ||
| 145 | { | ||
| 146 | [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]]; | ||
| 147 | self.lives--; | ||
| 148 | } | ||
| 149 | |||
| 97 | if (item.sprite.tag == 2000) | 150 | if (item.sprite.tag == 2000) |
| 98 | { | 151 | { |
| 99 | TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"Whoops, you missed it! Look at your lives counter--you lost one! If you lose all of your lives, you lose the game. Try catching the item again." name:@"missed-first"]; | 152 | TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"Whoops, you missed it! Look at your lives counter--you lost one! If you lose all of your lives, you lose the game. Try catching the item again." name:@"missed-first"]; |
| @@ -111,7 +164,6 @@ | |||
| 111 | [self scheduleDelayedAction:^{ | 164 | [self scheduleDelayedAction:^{ |
| 112 | FallingObject* object = [self dropRandomItem]; | 165 | FallingObject* object = [self dropRandomItem]; |
| 113 | object.sprite.tag = 2002; | 166 | object.sprite.tag = 2002; |
| 114 | [object release]; | ||
| 115 | } delay:1.0f]; | 167 | } delay:1.0f]; |
| 116 | } | 168 | } |
| 117 | } | 169 | } |
| @@ -181,7 +233,6 @@ | |||
| 181 | [self scheduleDelayedAction:^{ | 233 | [self scheduleDelayedAction:^{ |
| 182 | FallingObject* object = [self dropRandomItem]; | 234 | FallingObject* object = [self dropRandomItem]; |
| 183 | object.sprite.tag = 2000; | 235 | object.sprite.tag = 2000; |
| 184 | [object release]; | ||
| 185 | } delay:3.0f]; | 236 | } delay:3.0f]; |
| 186 | } else if ([currentTutorial.name isEqual:@"caught-first"]) | 237 | } else if ([currentTutorial.name isEqual:@"caught-first"]) |
| 187 | { | 238 | { |
| @@ -198,29 +249,24 @@ | |||
| 198 | } | 249 | } |
| 199 | 250 | ||
| 200 | object.sprite.tag = 2001; | 251 | object.sprite.tag = 2001; |
| 201 | |||
| 202 | [object release]; | ||
| 203 | } delay:1.0f]; | 252 | } delay:1.0f]; |
| 204 | } else if ([currentTutorial.name isEqual:@"missed-first"]) | 253 | } else if ([currentTutorial.name isEqual:@"missed-first"]) |
| 205 | { | 254 | { |
| 206 | [self scheduleDelayedAction:^{ | 255 | [self scheduleDelayedAction:^{ |
| 207 | FallingObject* object = [self dropRandomItem]; | 256 | FallingObject* object = [self dropRandomItem]; |
| 208 | object.sprite.tag = 2002; | 257 | object.sprite.tag = 2002; |
| 209 | [object release]; | ||
| 210 | } delay:1.0f]; | 258 | } delay:1.0f]; |
| 211 | } else if (([currentTutorial.name isEqual:@"caught-second"]) || ([currentTutorial.name isEqual:@"missed-second"])) | 259 | } else if (([currentTutorial.name isEqual:@"caught-second"]) || ([currentTutorial.name isEqual:@"missed-second"])) |
| 212 | { | 260 | { |
| 213 | [self scheduleDelayedAction:^{ | 261 | [self scheduleDelayedAction:^{ |
| 214 | FallingObject* object = [self dropSpecificItem:[[OneUp alloc] init]]; | 262 | FallingObject* object = [self dropSpecificItem:kOneUpObject]; |
| 215 | object.sprite.tag = 2003; | 263 | object.sprite.tag = 2003; |
| 216 | [object release]; | ||
| 217 | } delay:2.0f]; | 264 | } delay:2.0f]; |
| 218 | } else if ([currentTutorial.name isEqual:@"gameover-rock"]) | 265 | } else if ([currentTutorial.name isEqual:@"gameover-rock"]) |
| 219 | { | 266 | { |
| 220 | [self scheduleDelayedAction:^{ | 267 | [self scheduleDelayedAction:^{ |
| 221 | FallingObject* object = [self dropRandomItem]; | 268 | FallingObject* object = [self dropRandomItem]; |
| 222 | object.sprite.tag = 2010; | 269 | object.sprite.tag = 2010; |
| 223 | [object release]; | ||
| 224 | } delay:1.0f]; | 270 | } delay:1.0f]; |
| 225 | } else if ([currentTutorial.name isEqual:@"intense"]) | 271 | } else if ([currentTutorial.name isEqual:@"intense"]) |
| 226 | { | 272 | { |
| @@ -254,8 +300,9 @@ | |||
| 254 | } | 300 | } |
| 255 | } | 301 | } |
| 256 | 302 | ||
| 257 | - (FallingObject*)dropSpecificItem:(FallingObject*)object | 303 | - (FallingObject*)dropSpecificItem:(int)objectType |
| 258 | { | 304 | { |
| 305 | FallingObject* object = [[objectFactory buildFallingObjectWithRecipeIdentifier:objectType] retain]; | ||
| 259 | int objectX = arc4random()%448+16; | 306 | int objectX = arc4random()%448+16; |
| 260 | object.sprite.position = ccp(objectX, 360); | 307 | object.sprite.position = ccp(objectX, 360); |
| 261 | object.sprite.scale = 1; | 308 | object.sprite.scale = 1; |
| @@ -265,27 +312,27 @@ | |||
| 265 | 312 | ||
| 266 | [objects addObject:object]; | 313 | [objects addObject:object]; |
| 267 | 314 | ||
| 268 | return object; | 315 | return [object autorelease]; |
| 269 | } | 316 | } |
| 270 | 317 | ||
| 271 | - (FallingObject*)dropRandomItem | 318 | - (FallingObject*)dropRandomItem |
| 272 | { | 319 | { |
| 273 | FallingObject* object; | ||
| 274 | int randomval = arc4random()%100; | 320 | int randomval = arc4random()%100; |
| 321 | int recipeIdentifier; | ||
| 275 | 322 | ||
| 276 | if (randomval < 65) | 323 | if (randomval < 65) |
| 277 | { | 324 | { |
| 278 | object = [[Cherry alloc] init]; | 325 | recipeIdentifier = kCherryObject; |
| 279 | } else { | 326 | } else { |
| 280 | object = [[Bottle alloc] init]; | 327 | recipeIdentifier = kEnergyDrinkObject; |
| 281 | } | 328 | } |
| 282 | 329 | ||
| 283 | return [self dropSpecificItem:object]; | 330 | return [self dropSpecificItem:recipeIdentifier]; |
| 284 | } | 331 | } |
| 285 | 332 | ||
| 286 | - (void)randomlyAddObject:(ccTime)dt | 333 | - (void)randomlyAddObject:(ccTime)dt |
| 287 | { | 334 | { |
| 288 | FallingObject* object; | 335 | int recipeIdentifier; |
| 289 | 336 | ||
| 290 | if (randomItemsDropped < 5) | 337 | if (randomItemsDropped < 5) |
| 291 | { | 338 | { |
| @@ -293,17 +340,16 @@ | |||
| 293 | 340 | ||
| 294 | if (randomval < 65) | 341 | if (randomval < 65) |
| 295 | { | 342 | { |
| 296 | object = [[Cherry alloc] init]; | 343 | recipeIdentifier = kCherryObject; |
| 297 | } else if (randomval < 98) | 344 | } else if (randomval < 98) |
| 298 | { | 345 | { |
| 299 | object = [[Bottle alloc] init]; | 346 | recipeIdentifier = kEnergyDrinkObject; |
| 300 | } else { | 347 | } else { |
| 301 | object = [[OneUp alloc] init]; | 348 | recipeIdentifier = kOneUpObject; |
| 302 | } | 349 | } |
| 303 | } else if (randomItemsDropped == 5) | 350 | } else if (randomItemsDropped == 5) |
| 304 | { | 351 | { |
| 305 | object = [[Rock alloc] init]; | 352 | recipeIdentifier = kRockObject; |
| 306 | object.sprite.tag = 2009; | ||
| 307 | 353 | ||
| 308 | [self unschedule:@selector(randomlyAddObject:)]; | 354 | [self unschedule:@selector(randomlyAddObject:)]; |
| 309 | } else if (randomItemsDropped < 15) { | 355 | } else if (randomItemsDropped < 15) { |
| @@ -311,15 +357,15 @@ | |||
| 311 | 357 | ||
| 312 | if (randomval < 40) | 358 | if (randomval < 40) |
| 313 | { | 359 | { |
| 314 | object = [[Cherry alloc] init]; | 360 | recipeIdentifier = kCherryObject; |
| 315 | } else if (randomval < 70) | 361 | } else if (randomval < 70) |
| 316 | { | 362 | { |
| 317 | object = [[Rock alloc] init]; | 363 | recipeIdentifier = kRockObject; |
| 318 | } else if (randomval < 98) | 364 | } else if (randomval < 98) |
| 319 | { | 365 | { |
| 320 | object = [[Bottle alloc] init]; | 366 | recipeIdentifier = kEnergyDrinkObject; |
| 321 | } else { | 367 | } else { |
| 322 | object = [[OneUp alloc] init]; | 368 | recipeIdentifier = kOneUpObject; |
| 323 | } | 369 | } |
| 324 | } else if (randomItemsDropped == 15) | 370 | } else if (randomItemsDropped == 15) |
| 325 | { | 371 | { |
| @@ -331,8 +377,8 @@ | |||
| 331 | 377 | ||
| 332 | [self unschedule:@selector(randomlyAddObject:)]; | 378 | [self unschedule:@selector(randomlyAddObject:)]; |
| 333 | 379 | ||
| 334 | NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | 380 | [[ClassicGameMode info] unlock]; |
| 335 | [defaults setBool:YES forKey:@"hasDoneTutorial"]; | 381 | [[JumpGameMode info] unlock]; |
| 336 | 382 | ||
| 337 | return; | 383 | return; |
| 338 | } else { | 384 | } else { |
| @@ -341,8 +387,12 @@ | |||
| 341 | return; | 387 | return; |
| 342 | } | 388 | } |
| 343 | 389 | ||
| 344 | [self dropSpecificItem:object]; | 390 | FallingObject* object = [self dropSpecificItem:recipeIdentifier]; |
| 345 | [object release]; | 391 | |
| 392 | if (randomItemsDropped == 5) | ||
| 393 | { | ||
| 394 | object.sprite.tag = 2009; | ||
| 395 | } | ||
| 346 | 396 | ||
| 347 | randomItemsDropped++; | 397 | randomItemsDropped++; |
| 348 | } | 398 | } |
