summary refs log tree commit diff stats
path: root/Classes/JumpGameMode.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-09-10 17:07:13 -0400
committerStarla Insigna <starla4444@gmail.com>2011-09-10 17:07:13 -0400
commitfd58a0cde1bb5473e39e6cb82d28113da84b9ae0 (patch)
tree8d36b2fedc3c056c002a881e78340c7b56bbabea /Classes/JumpGameMode.m
parent5ccc4fc305f502a552b1ac7e815e576c93a8159a (diff)
downloadcartcollect-fd58a0cde1bb5473e39e6cb82d28113da84b9ae0.tar.gz
cartcollect-fd58a0cde1bb5473e39e6cb82d28113da84b9ae0.tar.bz2
cartcollect-fd58a0cde1bb5473e39e6cb82d28113da84b9ae0.zip
Reworked falling objects
Previously, every type of falling object had to have its own class that defined the object type's sprite, weight, and reaction to the cart/floor. This was pretty messy considering how many object types may only be used in one game mode--for instance, the many power ups in Power mode, once it's created, will never be used outside of Power mode. So, to increase customizability and decrease class clutter, game modes now use a FallingObjectFactory to define recipes (basically a sprite filename, a weight and an identifier) that can easily be built throughout the game mode using the identifier. FallingObjectDelegate is now used for all reactions to the cart/floor, rather than defining a standard reaction in the FallingObject subclass and then putting extra stuff in FallingObjectDelegate.
Diffstat (limited to 'Classes/JumpGameMode.m')
-rw-r--r--Classes/JumpGameMode.m58
1 files changed, 41 insertions, 17 deletions
diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index 15b0e16..a5c2b8f 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
@@ -34,6 +29,12 @@
34 29
35@implementation JumpGameMode 30@implementation JumpGameMode
36 31
32typedef enum {
33 kRockObject = 0,
34 kOneUpObject,
35 kPointMultiplierObject
36} FallingObjects;
37
37- (id)init 38- (id)init
38{ 39{
39 self = [super init]; 40 self = [super init];
@@ -57,9 +58,9 @@
57 waterTick = 0; 58 waterTick = 0;
58 wave = NO; 59 wave = NO;
59 60
60 factory = [[LedgeFactory alloc] init]; 61 ledgeFactory = [[LedgeFactory alloc] init];
61 ledges = [[NSMutableSet alloc] init]; 62 ledges = [[NSMutableSet alloc] init];
62 CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:6 height:2]]; 63 CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[ledgeFactory createLedgeWithWidth:6 height:2]];
63 CCSprite* ledge = [CCSprite spriteWithTexture:texture]; 64 CCSprite* ledge = [CCSprite spriteWithTexture:texture];
64 ledge.position = ccp(80, 32); 65 ledge.position = ccp(80, 32);
65 [self addChild:ledge]; 66 [self addChild:ledge];
@@ -67,7 +68,7 @@
67 [texture release]; 68 [texture release];
68 69
69 CCSprite* firstLedge = ledge; 70 CCSprite* firstLedge = ledge;
70 texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:10 height:2]]; 71 texture = [[CCTexture2D alloc] initWithImage:[ledgeFactory createLedgeWithWidth:10 height:2]];
71 ledge = [CCSprite spriteWithTexture:texture]; 72 ledge = [CCSprite spriteWithTexture:texture];
72 ledge.position = ccp(80 + firstLedge.boundingBox.size.width/2 + ledge.boundingBox.size.width/2+64, 32); 73 ledge.position = ccp(80 + firstLedge.boundingBox.size.width/2 + ledge.boundingBox.size.width/2+64, 32);
73 [self addChild:ledge]; 74 [self addChild:ledge];
@@ -77,6 +78,10 @@
77 ledgeScrollSpeed = 0; 78 ledgeScrollSpeed = 0;
78 ledgeAccelerationRate = 20.0f; 79 ledgeAccelerationRate = 20.0f;
79 addSpeed = 2.5f; 80 addSpeed = 2.5f;
81
82 [objectFactory createRecipeWithIdentifier:kRockObject spriteFilename:@"rock.png" weight:7];
83 [objectFactory createRecipeWithIdentifier:kOneUpObject spriteFilename:@"oneup.png" weight:10];
84 [objectFactory createRecipeWithIdentifier:kPointMultiplierObject spriteFilename:@"multiplier.png" weight:8];
80 } 85 }
81 86
82 return self; 87 return self;
@@ -164,7 +169,7 @@
164 { 169 {
165 int ledgeWidth = arc4random() % 9 + 1; 170 int ledgeWidth = arc4random() % 9 + 1;
166 int ledgeDistance = arc4random() % (ledgeScrollSpeed*ledgeScrollSpeed+1)*3/2; 171 int ledgeDistance = arc4random() % (ledgeScrollSpeed*ledgeScrollSpeed+1)*3/2;
167 CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:ledgeWidth height:2]]; 172 CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[ledgeFactory createLedgeWithWidth:ledgeWidth height:2]];
168 CCSprite* ledge = [CCSprite spriteWithTexture:texture]; 173 CCSprite* ledge = [CCSprite spriteWithTexture:texture];
169 ledge.position = ccp(rightmost + rightwidth + ledge.boundingBox.size.width/2+64+ledgeDistance, 32); 174 ledge.position = ccp(rightmost + rightwidth + ledge.boundingBox.size.width/2+64+ledgeDistance, 32);
170 [self addChild:ledge]; 175 [self addChild:ledge];
@@ -351,23 +356,22 @@
351 356
352- (void)randomlyAddObject:(ccTime)dt 357- (void)randomlyAddObject:(ccTime)dt
353{ 358{
354 FallingObject* object; 359 int recipeIdentifier;
355
356 int randomval = arc4random()%100; 360 int randomval = arc4random()%100;
357 int pmChance = (5-pointMultiplier)*5 + 30; 361 int pmChance = (5-pointMultiplier)*5 + 30;
358 362
359 if (randomval < 30) 363 if (randomval < 30)
360 { 364 {
361 object = [[OneUp alloc] init]; 365 recipeIdentifier = kOneUpObject;
362 } else if (randomval < pmChance) 366 } else if (randomval < pmChance)
363 { 367 {
364 object = [[PointMultiplier alloc] init]; 368 recipeIdentifier = kPointMultiplierObject;
365 } else { 369 } else {
366 object = [[Rock alloc] init]; 370 recipeIdentifier = kRockObject;
367 } 371 }
368 372
373 FallingObject* object = [[objectFactory buildFallingObjectWithRecipeIdentifier:recipeIdentifier] retain];
369 int objectX; 374 int objectX;
370
371 CGSize first = [cart.sprite boundingBox].size; 375 CGSize first = [cart.sprite boundingBox].size;
372 CGSize second = [object.sprite boundingBox].size; 376 CGSize second = [object.sprite boundingBox].size;
373 377
@@ -391,6 +395,7 @@
391 break; 395 break;
392 } 396 }
393 397
398 object.delegate = self;
394 object.sprite.position = ccp(objectX, 360); 399 object.sprite.position = ccp(objectX, 360);
395 object.sprite.scale = 1; 400 object.sprite.scale = 1;
396 [self addChild:object.sprite]; 401 [self addChild:object.sprite];
@@ -402,7 +407,7 @@
402 { 407 {
403 if (arc4random() % 100 > 80) 408 if (arc4random() % 100 > 80)
404 { 409 {
405 object = [[Rock alloc] init]; 410 object = [[objectFactory buildFallingObjectWithRecipeIdentifier:kRockObject] retain];
406 411
407 for (;;) 412 for (;;)
408 { 413 {
@@ -424,6 +429,7 @@
424 break; 429 break;
425 } 430 }
426 431
432 object.delegate = self;
427 object.sprite.position = ccp(objectX, 360); 433 object.sprite.position = ccp(objectX, 360);
428 object.sprite.scale = 1; 434 object.sprite.scale = 1;
429 [self addChild:object.sprite]; 435 [self addChild:object.sprite];
@@ -437,7 +443,7 @@
437 { 443 {
438 if (arc4random() % 100 > 80) 444 if (arc4random() % 100 > 80)
439 { 445 {
440 object = [[Rock alloc] init]; 446 object = [[objectFactory buildFallingObjectWithRecipeIdentifier:kRockObject] retain];
441 447
442 for (;;) 448 for (;;)
443 { 449 {
@@ -459,6 +465,7 @@
459 break; 465 break;
460 } 466 }
461 467
468 object.delegate = self;
462 object.sprite.position = ccp(objectX, 360); 469 object.sprite.position = ccp(objectX, 360);
463 object.sprite.scale = 1; 470 object.sprite.scale = 1;
464 [self addChild:object.sprite]; 471 [self addChild:object.sprite];
@@ -486,6 +493,23 @@
486 } 493 }
487} 494}
488 495
496- (void)didCatchItem:(FallingObject *)item
497{
498 if (item.objectType == kRockObject)
499 {
500 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]];
501 self.lives--;
502 } else if (item.objectType == kOneUpObject)
503 {
504 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]];
505 self.lives++;
506 } else if (item.objectType == kPointMultiplierObject)
507 {
508 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Absorption2" ofType:@"wav"]];
509 self.pointMultiplier++;
510 }
511}
512
489@end 513@end
490 514
491@implementation LedgeFactory 515@implementation LedgeFactory