summary refs log tree commit diff stats
path: root/Classes/TutorialMode.m
diff options
context:
space:
mode:
Diffstat (limited to 'Classes/TutorialMode.m')
-rw-r--r--Classes/TutorialMode.m90
1 files changed, 60 insertions, 30 deletions
diff --git a/Classes/TutorialMode.m b/Classes/TutorialMode.m index 3c70a46..156b939 100644 --- a/Classes/TutorialMode.m +++ b/Classes/TutorialMode.m
@@ -8,11 +8,8 @@
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"
16 13
17// Item tags: 14// Item tags:
18// 2000 - first dropped item 15// 2000 - first dropped item
@@ -22,6 +19,13 @@
22// 2009 - rock 19// 2009 - rock
23// 2010 - random item dropped after death from first rock 20// 2010 - random item dropped after death from first rock
24 21
22typedef enum {
23 kCherryObject = 0,
24 kEnergyDrinkObject,
25 kOneUpObject,
26 kRockObject
27} FallingObjects;
28
25@implementation TutorialMode 29@implementation TutorialMode
26 30
27@synthesize currentTutorial; 31@synthesize currentTutorial;
@@ -38,6 +42,11 @@
38 42
39 showedDeathBubble = NO; 43 showedDeathBubble = NO;
40 randomItemsDropped = 0; 44 randomItemsDropped = 0;
45
46 [objectFactory createRecipeWithIdentifier:kCherryObject spriteFilename:@"cherry.png" weight:5];
47 [objectFactory createRecipeWithIdentifier:kEnergyDrinkObject spriteFilename:@"bottle.png" weight:6];
48 [objectFactory createRecipeWithIdentifier:kOneUpObject spriteFilename:@"oneup.png" weight:10];
49 [objectFactory createRecipeWithIdentifier:kRockObject spriteFilename:@"rock.png" weight:7];
41 } 50 }
42 51
43 return self; 52 return self;
@@ -79,6 +88,24 @@
79 88
80- (void)didCatchItem:(FallingObject *)item 89- (void)didCatchItem:(FallingObject *)item
81{ 90{
91 if (item.objectType == kCherryObject)
92 {
93 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]];
94 self.score += 10;
95 } else if (item.objectType == kEnergyDrinkObject)
96 {
97 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]];
98 self.score += 25;
99 } else if (item.objectType == kOneUpObject)
100 {
101 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]];
102 self.lives++;
103 } else if (item.objectType == kRockObject)
104 {
105 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]];
106 self.lives--;
107 }
108
82 if (item.sprite.tag == 2000) 109 if (item.sprite.tag == 2000)
83 { 110 {
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"]; 111 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 +121,12 @@
94 121
95- (void)didMissItem:(FallingObject *)item 122- (void)didMissItem:(FallingObject *)item
96{ 123{
124 if ((item.objectType == kCherryObject) || (item.objectType == kEnergyDrinkObject))
125 {
126 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]];
127 self.lives--;
128 }
129
97 if (item.sprite.tag == 2000) 130 if (item.sprite.tag == 2000)
98 { 131 {
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"]; 132 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 +144,6 @@
111 [self scheduleDelayedAction:^{ 144 [self scheduleDelayedAction:^{
112 FallingObject* object = [self dropRandomItem]; 145 FallingObject* object = [self dropRandomItem];
113 object.sprite.tag = 2002; 146 object.sprite.tag = 2002;
114 [object release];
115 } delay:1.0f]; 147 } delay:1.0f];
116 } 148 }
117} 149}
@@ -181,7 +213,6 @@
181 [self scheduleDelayedAction:^{ 213 [self scheduleDelayedAction:^{
182 FallingObject* object = [self dropRandomItem]; 214 FallingObject* object = [self dropRandomItem];
183 object.sprite.tag = 2000; 215 object.sprite.tag = 2000;
184 [object release];
185 } delay:3.0f]; 216 } delay:3.0f];
186 } else if ([currentTutorial.name isEqual:@"caught-first"]) 217 } else if ([currentTutorial.name isEqual:@"caught-first"])
187 { 218 {
@@ -198,29 +229,24 @@
198 } 229 }
199 230
200 object.sprite.tag = 2001; 231 object.sprite.tag = 2001;
201
202 [object release];
203 } delay:1.0f]; 232 } delay:1.0f];
204 } else if ([currentTutorial.name isEqual:@"missed-first"]) 233 } else if ([currentTutorial.name isEqual:@"missed-first"])
205 { 234 {
206 [self scheduleDelayedAction:^{ 235 [self scheduleDelayedAction:^{
207 FallingObject* object = [self dropRandomItem]; 236 FallingObject* object = [self dropRandomItem];
208 object.sprite.tag = 2002; 237 object.sprite.tag = 2002;
209 [object release];
210 } delay:1.0f]; 238 } delay:1.0f];
211 } else if (([currentTutorial.name isEqual:@"caught-second"]) || ([currentTutorial.name isEqual:@"missed-second"])) 239 } else if (([currentTutorial.name isEqual:@"caught-second"]) || ([currentTutorial.name isEqual:@"missed-second"]))
212 { 240 {
213 [self scheduleDelayedAction:^{ 241 [self scheduleDelayedAction:^{
214 FallingObject* object = [self dropSpecificItem:[[OneUp alloc] init]]; 242 FallingObject* object = [self dropSpecificItem:kOneUpObject];
215 object.sprite.tag = 2003; 243 object.sprite.tag = 2003;
216 [object release];
217 } delay:2.0f]; 244 } delay:2.0f];
218 } else if ([currentTutorial.name isEqual:@"gameover-rock"]) 245 } else if ([currentTutorial.name isEqual:@"gameover-rock"])
219 { 246 {
220 [self scheduleDelayedAction:^{ 247 [self scheduleDelayedAction:^{
221 FallingObject* object = [self dropRandomItem]; 248 FallingObject* object = [self dropRandomItem];
222 object.sprite.tag = 2010; 249 object.sprite.tag = 2010;
223 [object release];
224 } delay:1.0f]; 250 } delay:1.0f];
225 } else if ([currentTutorial.name isEqual:@"intense"]) 251 } else if ([currentTutorial.name isEqual:@"intense"])
226 { 252 {
@@ -254,8 +280,9 @@
254 } 280 }
255} 281}
256 282
257- (FallingObject*)dropSpecificItem:(FallingObject*)object 283- (FallingObject*)dropSpecificItem:(int)objectType
258{ 284{
285 FallingObject* object = [[objectFactory buildFallingObjectWithRecipeIdentifier:objectType] retain];
259 int objectX = arc4random()%448+16; 286 int objectX = arc4random()%448+16;
260 object.sprite.position = ccp(objectX, 360); 287 object.sprite.position = ccp(objectX, 360);
261 object.sprite.scale = 1; 288 object.sprite.scale = 1;
@@ -265,27 +292,27 @@
265 292
266 [objects addObject:object]; 293 [objects addObject:object];
267 294
268 return object; 295 return [object autorelease];
269} 296}
270 297
271- (FallingObject*)dropRandomItem 298- (FallingObject*)dropRandomItem
272{ 299{
273 FallingObject* object;
274 int randomval = arc4random()%100; 300 int randomval = arc4random()%100;
301 int recipeIdentifier;
275 302
276 if (randomval < 65) 303 if (randomval < 65)
277 { 304 {
278 object = [[Cherry alloc] init]; 305 recipeIdentifier = kCherryObject;
279 } else { 306 } else {
280 object = [[Bottle alloc] init]; 307 recipeIdentifier = kEnergyDrinkObject;
281 } 308 }
282 309
283 return [self dropSpecificItem:object]; 310 return [self dropSpecificItem:recipeIdentifier];
284} 311}
285 312
286- (void)randomlyAddObject:(ccTime)dt 313- (void)randomlyAddObject:(ccTime)dt
287{ 314{
288 FallingObject* object; 315 int recipeIdentifier;
289 316
290 if (randomItemsDropped < 5) 317 if (randomItemsDropped < 5)
291 { 318 {
@@ -293,17 +320,16 @@
293 320
294 if (randomval < 65) 321 if (randomval < 65)
295 { 322 {
296 object = [[Cherry alloc] init]; 323 recipeIdentifier = kCherryObject;
297 } else if (randomval < 98) 324 } else if (randomval < 98)
298 { 325 {
299 object = [[Bottle alloc] init]; 326 recipeIdentifier = kEnergyDrinkObject;
300 } else { 327 } else {
301 object = [[OneUp alloc] init]; 328 recipeIdentifier = kOneUpObject;
302 } 329 }
303 } else if (randomItemsDropped == 5) 330 } else if (randomItemsDropped == 5)
304 { 331 {
305 object = [[Rock alloc] init]; 332 recipeIdentifier = kRockObject;
306 object.sprite.tag = 2009;
307 333
308 [self unschedule:@selector(randomlyAddObject:)]; 334 [self unschedule:@selector(randomlyAddObject:)];
309 } else if (randomItemsDropped < 15) { 335 } else if (randomItemsDropped < 15) {
@@ -311,15 +337,15 @@
311 337
312 if (randomval < 40) 338 if (randomval < 40)
313 { 339 {
314 object = [[Cherry alloc] init]; 340 recipeIdentifier = kCherryObject;
315 } else if (randomval < 70) 341 } else if (randomval < 70)
316 { 342 {
317 object = [[Rock alloc] init]; 343 recipeIdentifier = kRockObject;
318 } else if (randomval < 98) 344 } else if (randomval < 98)
319 { 345 {
320 object = [[Bottle alloc] init]; 346 recipeIdentifier = kEnergyDrinkObject;
321 } else { 347 } else {
322 object = [[OneUp alloc] init]; 348 recipeIdentifier = kOneUpObject;
323 } 349 }
324 } else if (randomItemsDropped == 15) 350 } else if (randomItemsDropped == 15)
325 { 351 {
@@ -341,8 +367,12 @@
341 return; 367 return;
342 } 368 }
343 369
344 [self dropSpecificItem:object]; 370 FallingObject* object = [self dropSpecificItem:recipeIdentifier];
345 [object release]; 371
372 if (randomItemsDropped == 5)
373 {
374 object.sprite.tag = 2009;
375 }
346 376
347 randomItemsDropped++; 377 randomItemsDropped++;
348} 378}