diff options
Diffstat (limited to 'Classes/JumpGameMode.m')
-rw-r--r-- | Classes/JumpGameMode.m | 84 |
1 files changed, 63 insertions, 21 deletions
diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index eb552a2..f3e690c 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m | |||
@@ -9,12 +9,7 @@ | |||
9 | #import "JumpGameMode.h" | 9 | #import "JumpGameMode.h" |
10 | #import "SimpleAudioEngine.h" | 10 | #import "SimpleAudioEngine.h" |
11 | #import "FallingObject.h" | 11 | #import "FallingObject.h" |
12 | #import "Cherry.h" | ||
13 | #import "Bottle.h" | ||
14 | #import "OneUp.h" | ||
15 | #import "Rock.h" | ||
16 | #import "GameOverScene.h" | 12 | #import "GameOverScene.h" |
17 | #import "PointMultiplier.h" | ||
18 | 13 | ||
19 | #define kMinimumGestureLength 25 | 14 | #define kMinimumGestureLength 25 |
20 | 15 | ||
@@ -46,6 +41,30 @@ | |||
46 | 41 | ||
47 | @implementation JumpGameMode | 42 | @implementation JumpGameMode |
48 | 43 | ||
44 | typedef enum { | ||
45 | kRockObject = 0, | ||
46 | kOneUpObject, | ||
47 | kPointMultiplierObject | ||
48 | } FallingObjects; | ||
49 | |||
50 | static GameModeInfo* info; | ||
51 | |||
52 | + (GameModeInfo*)info | ||
53 | { | ||
54 | if (info == nil) | ||
55 | { | ||
56 | info = [[GameModeInfo alloc] initWithName:@"Jump" | ||
57 | location:@"Venice" | ||
58 | numOfStars:3 | ||
59 | imageFilename:[[NSBundle mainBundle] pathForResource:@"venice" ofType:@"png"] | ||
60 | unlocked:YES | ||
61 | gameClass:[JumpGameMode class] | ||
62 | globalHighscoreKey:@"Jump"]; | ||
63 | } | ||
64 | |||
65 | return info; | ||
66 | } | ||
67 | |||
49 | - (id)init | 68 | - (id)init |
50 | { | 69 | { |
51 | self = [super init]; | 70 | self = [super init]; |
@@ -69,9 +88,9 @@ | |||
69 | waterTick = 0; | 88 | waterTick = 0; |
70 | wave = NO; | 89 | wave = NO; |
71 | 90 | ||
72 | factory = [[LedgeFactory alloc] init]; | 91 | ledgeFactory = [[LedgeFactory alloc] init]; |
73 | ledges = [[NSMutableSet alloc] init]; | 92 | ledges = [[NSMutableSet alloc] init]; |
74 | CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:6 height:2]]; | 93 | CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[ledgeFactory createLedgeWithWidth:6 height:2]]; |
75 | CCSprite* ledge = [CCSprite spriteWithTexture:texture]; | 94 | CCSprite* ledge = [CCSprite spriteWithTexture:texture]; |
76 | ledge.position = ccp(80, 32); | 95 | ledge.position = ccp(80, 32); |
77 | [self addChild:ledge]; | 96 | [self addChild:ledge]; |
@@ -79,7 +98,7 @@ | |||
79 | [texture release]; | 98 | [texture release]; |
80 | 99 | ||
81 | CCSprite* firstLedge = ledge; | 100 | CCSprite* firstLedge = ledge; |
82 | texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:10 height:2]]; | 101 | texture = [[CCTexture2D alloc] initWithImage:[ledgeFactory createLedgeWithWidth:10 height:2]]; |
83 | ledge = [CCSprite spriteWithTexture:texture]; | 102 | ledge = [CCSprite spriteWithTexture:texture]; |
84 | ledge.position = ccp(80 + firstLedge.boundingBox.size.width/2 + ledge.boundingBox.size.width/2+64, 32); | 103 | ledge.position = ccp(80 + firstLedge.boundingBox.size.width/2 + ledge.boundingBox.size.width/2+64, 32); |
85 | [self addChild:ledge]; | 104 | [self addChild:ledge]; |
@@ -89,6 +108,10 @@ | |||
89 | ledgeScrollSpeed = 0; | 108 | ledgeScrollSpeed = 0; |
90 | ledgeAccelerationRate = 20.0f; | 109 | ledgeAccelerationRate = 20.0f; |
91 | addSpeed = 2.5f; | 110 | addSpeed = 2.5f; |
111 | |||
112 | [objectFactory createRecipeWithIdentifier:kRockObject spriteFilename:@"rock.png" weight:7]; | ||
113 | [objectFactory createRecipeWithIdentifier:kOneUpObject spriteFilename:@"oneup.png" weight:10]; | ||
114 | [objectFactory createRecipeWithIdentifier:kPointMultiplierObject spriteFilename:@"multiplier.png" weight:8]; | ||
92 | } | 115 | } |
93 | 116 | ||
94 | return self; | 117 | return self; |
@@ -172,7 +195,7 @@ | |||
172 | { | 195 | { |
173 | int ledgeWidth = arc4random() % 9 + 1; | 196 | int ledgeWidth = arc4random() % 9 + 1; |
174 | int ledgeDistance = arc4random() % (ledgeScrollSpeed*ledgeScrollSpeed+1)*3/2; | 197 | int ledgeDistance = arc4random() % (ledgeScrollSpeed*ledgeScrollSpeed+1)*3/2; |
175 | CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:ledgeWidth height:2]]; | 198 | CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[ledgeFactory createLedgeWithWidth:ledgeWidth height:2]]; |
176 | CCSprite* ledge = [CCSprite spriteWithTexture:texture]; | 199 | CCSprite* ledge = [CCSprite spriteWithTexture:texture]; |
177 | ledge.position = ccp(rightmost + rightwidth + ledge.boundingBox.size.width/2+64+ledgeDistance, 32); | 200 | ledge.position = ccp(rightmost + rightwidth + ledge.boundingBox.size.width/2+64+ledgeDistance, 32); |
178 | [self addChild:ledge]; | 201 | [self addChild:ledge]; |
@@ -214,7 +237,7 @@ | |||
214 | { | 237 | { |
215 | [self unscheduleAllSelectors]; | 238 | [self unscheduleAllSelectors]; |
216 | 239 | ||
217 | [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverScene sceneWithScore:score gameMode:@"Jump"]]]; | 240 | [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverScene sceneWithScore:score gameMode:[JumpGameMode info]]]]; |
218 | } | 241 | } |
219 | 242 | ||
220 | if (wave) | 243 | if (wave) |
@@ -355,23 +378,22 @@ | |||
355 | 378 | ||
356 | - (void)randomlyAddObject:(ccTime)dt | 379 | - (void)randomlyAddObject:(ccTime)dt |
357 | { | 380 | { |
358 | FallingObject* object; | 381 | int recipeIdentifier; |
359 | |||
360 | int randomval = arc4random()%100; | 382 | int randomval = arc4random()%100; |
361 | int pmChance = (5-pointMultiplier)*5 + 30; | 383 | int pmChance = (5-pointMultiplier)*5 + 30; |
362 | 384 | ||
363 | if (randomval < 30) | 385 | if (randomval < 30) |
364 | { | 386 | { |
365 | object = [[OneUp alloc] init]; | 387 | recipeIdentifier = kOneUpObject; |
366 | } else if (randomval < pmChance) | 388 | } else if (randomval < pmChance) |
367 | { | 389 | { |
368 | object = [[PointMultiplier alloc] init]; | 390 | recipeIdentifier = kPointMultiplierObject; |
369 | } else { | 391 | } else { |
370 | object = [[Rock alloc] init]; | 392 | recipeIdentifier = kRockObject; |
371 | } | 393 | } |
372 | 394 | ||
395 | FallingObject* object = [[objectFactory buildFallingObjectWithRecipeIdentifier:recipeIdentifier] retain]; | ||
373 | int objectX; | 396 | int objectX; |
374 | |||
375 | CGSize first = [cart.sprite boundingBox].size; | 397 | CGSize first = [cart.sprite boundingBox].size; |
376 | CGSize second = [object.sprite boundingBox].size; | 398 | CGSize second = [object.sprite boundingBox].size; |
377 | 399 | ||
@@ -395,6 +417,7 @@ | |||
395 | break; | 417 | break; |
396 | } | 418 | } |
397 | 419 | ||
420 | object.delegate = self; | ||
398 | object.sprite.position = ccp(objectX, 360); | 421 | object.sprite.position = ccp(objectX, 360); |
399 | object.sprite.scale = 1; | 422 | object.sprite.scale = 1; |
400 | object.fellDuringWave = waterTick > 0; | 423 | object.fellDuringWave = waterTick > 0; |
@@ -407,7 +430,7 @@ | |||
407 | { | 430 | { |
408 | if (arc4random() % 100 > 80) | 431 | if (arc4random() % 100 > 80) |
409 | { | 432 | { |
410 | object = [[Rock alloc] init]; | 433 | object = [[objectFactory buildFallingObjectWithRecipeIdentifier:kRockObject] retain]; |
411 | 434 | ||
412 | for (;;) | 435 | for (;;) |
413 | { | 436 | { |
@@ -429,6 +452,7 @@ | |||
429 | break; | 452 | break; |
430 | } | 453 | } |
431 | 454 | ||
455 | object.delegate = self; | ||
432 | object.sprite.position = ccp(objectX, 360); | 456 | object.sprite.position = ccp(objectX, 360); |
433 | object.sprite.scale = 1; | 457 | object.sprite.scale = 1; |
434 | object.fellDuringWave = waterTick > 0; | 458 | object.fellDuringWave = waterTick > 0; |
@@ -443,7 +467,7 @@ | |||
443 | { | 467 | { |
444 | if (arc4random() % 100 > 80) | 468 | if (arc4random() % 100 > 80) |
445 | { | 469 | { |
446 | object = [[Rock alloc] init]; | 470 | object = [[objectFactory buildFallingObjectWithRecipeIdentifier:kRockObject] retain]; |
447 | 471 | ||
448 | for (;;) | 472 | for (;;) |
449 | { | 473 | { |
@@ -465,6 +489,7 @@ | |||
465 | break; | 489 | break; |
466 | } | 490 | } |
467 | 491 | ||
492 | object.delegate = self; | ||
468 | object.sprite.position = ccp(objectX, 360); | 493 | object.sprite.position = ccp(objectX, 360); |
469 | object.sprite.scale = 1; | 494 | object.sprite.scale = 1; |
470 | object.fellDuringWave = waterTick > 0; | 495 | object.fellDuringWave = waterTick > 0; |
@@ -493,11 +518,28 @@ | |||
493 | } | 518 | } |
494 | } | 519 | } |
495 | 520 | ||
521 | - (void)didCatchItem:(FallingObject *)item | ||
522 | { | ||
523 | if (item.objectType == kRockObject) | ||
524 | { | ||
525 | [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]]; | ||
526 | self.lives--; | ||
527 | } else if (item.objectType == kOneUpObject) | ||
528 | { | ||
529 | [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]]; | ||
530 | self.lives++; | ||
531 | } else if (item.objectType == kPointMultiplierObject) | ||
532 | { | ||
533 | [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Absorption2" ofType:@"wav"]]; | ||
534 | self.pointMultiplier++; | ||
535 | } | ||
536 | } | ||
537 | |||
496 | - (void)setPitch:(double)m_pitch | 538 | - (void)setPitch:(double)m_pitch |
497 | { | 539 | { |
498 | [super setPitch:m_pitch]; | 540 | [super setPitch:m_pitch]; |
499 | 541 | ||
500 | expectedAngle = pitch*M_PI_2; | 542 | expectedAngle = pitch*M_PI_2; |
501 | } | 543 | } |
502 | 544 | ||
503 | @end | 545 | @end |