From fd58a0cde1bb5473e39e6cb82d28113da84b9ae0 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sat, 10 Sep 2011 17:07:13 -0400 Subject: 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. --- Classes/Bottle.h | 18 --------- Classes/Bottle.m | 32 --------------- Classes/Cherry.h | 18 --------- Classes/Cherry.m | 32 --------------- Classes/ClassicGameMode.h | 3 +- Classes/ClassicGameMode.m | 71 ++++++++++++++++++++++++++------- Classes/FallingObject.h | 6 +-- Classes/FallingObject.m | 22 +++-------- Classes/FallingObjectFactory.h | 20 ++++++++++ Classes/FallingObjectFactory.m | 70 ++++++++++++++++++++++++++++++++ Classes/GameMode.h | 2 + Classes/GameMode.m | 2 + Classes/JumpGameMode.h | 5 ++- Classes/JumpGameMode.m | 58 +++++++++++++++++++-------- Classes/OneUp.h | 18 --------- Classes/OneUp.m | 36 ----------------- Classes/PointMultiplier.h | 15 ------- Classes/PointMultiplier.m | 36 ----------------- Classes/Rock.h | 18 --------- Classes/Rock.m | 37 ----------------- Classes/TutorialMode.h | 2 +- Classes/TutorialMode.m | 90 ++++++++++++++++++++++++++++-------------- Classes/ValuableObject.h | 15 ------- Classes/ValuableObject.m | 46 --------------------- 24 files changed, 265 insertions(+), 407 deletions(-) delete mode 100755 Classes/Bottle.h delete mode 100755 Classes/Bottle.m delete mode 100755 Classes/Cherry.h delete mode 100755 Classes/Cherry.m create mode 100644 Classes/FallingObjectFactory.h create mode 100644 Classes/FallingObjectFactory.m delete mode 100755 Classes/OneUp.h delete mode 100755 Classes/OneUp.m delete mode 100644 Classes/PointMultiplier.h delete mode 100644 Classes/PointMultiplier.m delete mode 100755 Classes/Rock.h delete mode 100755 Classes/Rock.m delete mode 100644 Classes/ValuableObject.h delete mode 100644 Classes/ValuableObject.m (limited to 'Classes') diff --git a/Classes/Bottle.h b/Classes/Bottle.h deleted file mode 100755 index 71e94e9..0000000 --- a/Classes/Bottle.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// Bottle.h -// Cart Collect -// -// Created by iD Student Account on 7/19/11. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import -#import "ValuableObject.h" - -@interface Bottle : ValuableObject { - -} - -- (id)init; - -@end diff --git a/Classes/Bottle.m b/Classes/Bottle.m deleted file mode 100755 index bae2716..0000000 --- a/Classes/Bottle.m +++ /dev/null @@ -1,32 +0,0 @@ -// -// Bottle.m -// Cart Collect -// -// Created by iD Student Account on 7/19/11. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import "Bottle.h" - - -@implementation Bottle - -- (id)init -{ - self = [super init]; - - if (nil != self) - { - sprite = [CCSprite spriteWithFile:@"bottle.png"]; - weight = 6; - } - - return self; -} - -- (int)pointValue -{ - return 25; -} - -@end diff --git a/Classes/Cherry.h b/Classes/Cherry.h deleted file mode 100755 index 0a7e450..0000000 --- a/Classes/Cherry.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// Cherry.h -// Cart Collect -// -// Created by iD Student Account on 7/19/11. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import -#import "ValuableObject.h" - -@interface Cherry : ValuableObject { - -} - -- (id)init; - -@end diff --git a/Classes/Cherry.m b/Classes/Cherry.m deleted file mode 100755 index f53c86e..0000000 --- a/Classes/Cherry.m +++ /dev/null @@ -1,32 +0,0 @@ -// -// Cherry.m -// Cart Collect -// -// Created by iD Student Account on 7/19/11. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import "Cherry.h" - - -@implementation Cherry - -- (id)init -{ - self = [super init]; - - if (nil != self) - { - sprite = [CCSprite spriteWithFile:@"cherry.png"]; - weight = 5; - } - - return self; -} - -- (int)pointValue -{ - return 10; -} - -@end diff --git a/Classes/ClassicGameMode.h b/Classes/ClassicGameMode.h index bbce029..898a5e7 100755 --- a/Classes/ClassicGameMode.h +++ b/Classes/ClassicGameMode.h @@ -9,8 +9,9 @@ #import #import "cocos2d.h" #import "GameMode.h" +#import "FallingObjectDelegate.h" -@interface ClassicGameMode : GameMode { +@interface ClassicGameMode : GameMode { float addSpeed; } diff --git a/Classes/ClassicGameMode.m b/Classes/ClassicGameMode.m index 46ad337..306c1d1 100755 --- a/Classes/ClassicGameMode.m +++ b/Classes/ClassicGameMode.m @@ -8,10 +8,6 @@ #import "ClassicGameMode.h" #import "FallingObject.h" -#import "Cherry.h" -#import "Bottle.h" -#import "OneUp.h" -#import "Rock.h" #import "GameOverScene.h" #import "SimpleAudioEngine.h" #import "CCNotifications.h" @@ -19,6 +15,13 @@ @implementation ClassicGameMode +typedef enum { + kCherryObject = 0, + kEnergyDrinkObject, + kOneUpObject, + kRockObject +} FallingObjects; + - (void)tick:(ccTime)dt { int lastScore = score; @@ -83,6 +86,7 @@ { FallingObject* object; int oneuppercent = 98 - (lives == 1 ? 1 : 0); + int recipeIdentifier; if (score < 1000) { @@ -90,31 +94,33 @@ if (randomval < 65) { - object = [[Cherry alloc] init]; + recipeIdentifier = kCherryObject; } else if (randomval < oneuppercent) { - object = [[Bottle alloc] init]; + recipeIdentifier = kEnergyDrinkObject; } else { - object = [[OneUp alloc] init]; + recipeIdentifier = kOneUpObject; } } else { int randomval = arc4random()%100; if (randomval < 40) { - object = [[Cherry alloc] init]; + recipeIdentifier = kCherryObject; } else if (randomval < 70) { - object = [[Rock alloc] init]; + recipeIdentifier = kRockObject; } else if (randomval < oneuppercent) { - object = [[Bottle alloc] init]; + recipeIdentifier = kEnergyDrinkObject; } else { - object = [[OneUp alloc] init]; + recipeIdentifier = kOneUpObject; } } int objectX = arc4random()%448+16; + object = [[objectFactory buildFallingObjectWithRecipeIdentifier:recipeIdentifier] retain]; + object.delegate = self; object.sprite.position = ccp(objectX, 360); object.sprite.scale = 1; [self addChild:object.sprite]; @@ -126,8 +132,8 @@ { if (arc4random() % 100 > 80) { - object = [[Rock alloc] init]; - + object = [[objectFactory buildFallingObjectWithRecipeIdentifier:kRockObject] retain]; + object.delegate = self; objectX = arc4random()%448+16; object.sprite.position = ccp(objectX, 360); object.sprite.scale = 1; @@ -142,8 +148,8 @@ { if (arc4random() % 100 > 80) { - object = [[Rock alloc] init]; - + object = [[objectFactory buildFallingObjectWithRecipeIdentifier:kRockObject] retain]; + object.delegate = self; objectX = arc4random()%448+16; object.sprite.position = ccp(objectX, 360); object.sprite.scale = 1; @@ -166,6 +172,11 @@ [self addChild:backgroundImage z:-1]; addSpeed = 2.5f; + + [objectFactory createRecipeWithIdentifier:kCherryObject spriteFilename:@"cherry.png" weight:5]; + [objectFactory createRecipeWithIdentifier:kEnergyDrinkObject spriteFilename:@"bottle.png" weight:6]; + [objectFactory createRecipeWithIdentifier:kOneUpObject spriteFilename:@"oneup.png" weight:10]; + [objectFactory createRecipeWithIdentifier:kRockObject spriteFilename:@"rock.png" weight:7]; } return self; @@ -178,4 +189,34 @@ [self schedule:@selector(randomlyAddObject:) interval:addSpeed]; } +- (void)didCatchItem:(FallingObject *)item +{ + if (item.objectType == kCherryObject) + { + [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]]; + self.score += 10; + } else if (item.objectType == kEnergyDrinkObject) + { + [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]]; + self.score += 25; + } else if (item.objectType == kOneUpObject) + { + [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]]; + self.lives++; + } else if (item.objectType == kRockObject) + { + [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]]; + self.lives--; + } +} + +- (void)didMissItem:(FallingObject *)item +{ + if ((item.objectType == kCherryObject) || (item.objectType == kEnergyDrinkObject)) + { + [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]]; + self.lives--; + } +} + @end diff --git a/Classes/FallingObject.h b/Classes/FallingObject.h index d3ac638..d9406d5 100755 --- a/Classes/FallingObject.h +++ b/Classes/FallingObject.h @@ -15,15 +15,15 @@ int weight; id delegate; BOOL flags[4]; + int objectType; } @property (readonly) CCSprite* sprite; @property (readonly) int weight; +@property (readonly) int objectType; @property (nonatomic,retain) id delegate; -- (id)init; +- (id)initWithSpriteFilename:(NSString*)filename weight:(int)weight objectType:(int)objectType; - (BOOL)tick; -- (void)collideWithCart; -- (void)collideWithFloor; - (BOOL)flag:(int)flag; - (void)setFlag:(int)flag withValue:(BOOL)value; diff --git a/Classes/FallingObject.m b/Classes/FallingObject.m index 86edd15..460372e 100755 --- a/Classes/FallingObject.m +++ b/Classes/FallingObject.m @@ -11,15 +11,17 @@ @implementation FallingObject -@synthesize sprite, weight, delegate; +@synthesize sprite, weight, objectType, delegate; -- (id)init +- (id)initWithSpriteFilename:(NSString*)filename weight:(int)m_weight objectType:(int)m_objectType { self = [super init]; if (nil != self) { - + sprite = [CCSprite spriteWithFile:filename]; + weight = m_weight; + objectType = m_objectType; } return self; @@ -44,8 +46,6 @@ { if (gameLayer.cart.sprite.position.y < (sprite.position.y + second.height/2 + first.height/2)) { - [self collideWithCart]; - if ((delegate != nil) && ([delegate respondsToSelector:@selector(didCatchItem:)])) { [delegate didCatchItem:self]; @@ -65,8 +65,6 @@ // Collision detection with floor if (sprite.position.y - (sprite.contentSize.height/2) < 0) { - [self collideWithFloor]; - if ((delegate != nil) && ([delegate respondsToSelector:@selector(didMissItem:)])) { [delegate didMissItem:self]; @@ -83,16 +81,6 @@ return NO; } -- (void)collideWithCart -{ - -} - -- (void)collideWithFloor -{ - -} - - (BOOL)flag:(int)flag { return flags[flag]; diff --git a/Classes/FallingObjectFactory.h b/Classes/FallingObjectFactory.h new file mode 100644 index 0000000..a861d06 --- /dev/null +++ b/Classes/FallingObjectFactory.h @@ -0,0 +1,20 @@ +// +// FallingObjectFactory.h +// Cartographic +// +// Created by Starla Insigna on 9/10/11. +// Copyright (c) 2011 Four Island. All rights reserved. +// + +#import +#import "FallingObject.h" + +@interface FallingObjectFactory : NSObject { + NSMutableDictionary* recipes; +} + +- (id)init; +- (void)createRecipeWithIdentifier:(int)identifier spriteFilename:(NSString*)filename weight:(int)weight; +- (FallingObject*)buildFallingObjectWithRecipeIdentifier:(int)identifier; + +@end diff --git a/Classes/FallingObjectFactory.m b/Classes/FallingObjectFactory.m new file mode 100644 index 0000000..dfd6424 --- /dev/null +++ b/Classes/FallingObjectFactory.m @@ -0,0 +1,70 @@ +// +// FallingObjectFactory.m +// Cartographic +// +// Created by Starla Insigna on 9/10/11. +// Copyright (c) 2011 Four Island. All rights reserved. +// + +#import "FallingObjectFactory.h" + +@interface FallingObjectRecipe : NSObject { + NSString* spriteFilename; + int weight; +} + +@property (readonly) NSString* spriteFilename; +@property (readonly) int weight; +- (id)initWithSpriteFilename:(NSString*)filename weight:(int)m_weight; + +@end + +@implementation FallingObjectRecipe + +@synthesize spriteFilename, weight; + +- (id)initWithSpriteFilename:(NSString*)filename weight:(int)m_weight +{ + self = [super init]; + + if (nil != self) + { + spriteFilename = [filename retain]; + weight = m_weight; + } + + return self; +} + +@end + +@implementation FallingObjectFactory + +- (id)init +{ + self = [super init]; + + if (nil != self) + { + recipes = [[NSMutableDictionary alloc] init]; + } + + return self; +} + +- (void)createRecipeWithIdentifier:(int)identifier spriteFilename:(NSString*)filename weight:(int)weight +{ + FallingObjectRecipe* recipe = [[FallingObjectRecipe alloc] initWithSpriteFilename:filename weight:weight]; + [recipes setObject:recipe forKey:[NSNumber numberWithInt:identifier]]; + [recipe release]; +} + +- (FallingObject*)buildFallingObjectWithRecipeIdentifier:(int)identifier +{ + FallingObjectRecipe* recipe = [recipes objectForKey:[NSNumber numberWithInt:identifier]]; + FallingObject* object = [[FallingObject alloc] initWithSpriteFilename:recipe.spriteFilename weight:recipe.weight objectType:identifier]; + + return [object autorelease]; +} + +@end diff --git a/Classes/GameMode.h b/Classes/GameMode.h index e82ad10..cd0359d 100644 --- a/Classes/GameMode.h +++ b/Classes/GameMode.h @@ -8,6 +8,7 @@ #import "CCLayer.h" #import "Cart.h" +#import "FallingObjectFactory.h" #define GAME_SCENE 436 #define GAME_LAYER 437 @@ -18,6 +19,7 @@ int lives; int pointMultiplier; Cart* cart; + FallingObjectFactory* objectFactory; CCLayerColor* shadedLayer; CCLayer* pauseLayer; diff --git a/Classes/GameMode.m b/Classes/GameMode.m index 1e80237..1f2451d 100644 --- a/Classes/GameMode.m +++ b/Classes/GameMode.m @@ -54,6 +54,8 @@ score = 0; lives = 3; pointMultiplier = 1; + + objectFactory = [[FallingObjectFactory alloc] init]; if ([self canPause]) { diff --git a/Classes/JumpGameMode.h b/Classes/JumpGameMode.h index 0b6c5d2..b18fd5a 100644 --- a/Classes/JumpGameMode.h +++ b/Classes/JumpGameMode.h @@ -7,10 +7,11 @@ // #import "GameMode.h" +#import "FallingObjectDelegate.h" @class LedgeFactory; -@interface JumpGameMode : GameMode { +@interface JumpGameMode : GameMode { CCSprite* water; int waterTick; BOOL wave; @@ -20,7 +21,7 @@ BOOL jump; float expectedAngle; NSMutableSet* ledges; - LedgeFactory* factory; + LedgeFactory* ledgeFactory; int ledgeScrollSpeed; float ledgeAccelerationRate; float addSpeed; 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 @@ #import "JumpGameMode.h" #import "SimpleAudioEngine.h" #import "FallingObject.h" -#import "Cherry.h" -#import "Bottle.h" -#import "OneUp.h" -#import "Rock.h" #import "GameOverScene.h" -#import "PointMultiplier.h" #define kMinimumGestureLength 25 @@ -34,6 +29,12 @@ @implementation JumpGameMode +typedef enum { + kRockObject = 0, + kOneUpObject, + kPointMultiplierObject +} FallingObjects; + - (id)init { self = [super init]; @@ -57,9 +58,9 @@ waterTick = 0; wave = NO; - factory = [[LedgeFactory alloc] init]; + ledgeFactory = [[LedgeFactory alloc] init]; ledges = [[NSMutableSet alloc] init]; - CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:6 height:2]]; + CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[ledgeFactory createLedgeWithWidth:6 height:2]]; CCSprite* ledge = [CCSprite spriteWithTexture:texture]; ledge.position = ccp(80, 32); [self addChild:ledge]; @@ -67,7 +68,7 @@ [texture release]; CCSprite* firstLedge = ledge; - texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:10 height:2]]; + texture = [[CCTexture2D alloc] initWithImage:[ledgeFactory createLedgeWithWidth:10 height:2]]; ledge = [CCSprite spriteWithTexture:texture]; ledge.position = ccp(80 + firstLedge.boundingBox.size.width/2 + ledge.boundingBox.size.width/2+64, 32); [self addChild:ledge]; @@ -77,6 +78,10 @@ ledgeScrollSpeed = 0; ledgeAccelerationRate = 20.0f; addSpeed = 2.5f; + + [objectFactory createRecipeWithIdentifier:kRockObject spriteFilename:@"rock.png" weight:7]; + [objectFactory createRecipeWithIdentifier:kOneUpObject spriteFilename:@"oneup.png" weight:10]; + [objectFactory createRecipeWithIdentifier:kPointMultiplierObject spriteFilename:@"multiplier.png" weight:8]; } return self; @@ -164,7 +169,7 @@ { int ledgeWidth = arc4random() % 9 + 1; int ledgeDistance = arc4random() % (ledgeScrollSpeed*ledgeScrollSpeed+1)*3/2; - CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:ledgeWidth height:2]]; + CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[ledgeFactory createLedgeWithWidth:ledgeWidth height:2]]; CCSprite* ledge = [CCSprite spriteWithTexture:texture]; ledge.position = ccp(rightmost + rightwidth + ledge.boundingBox.size.width/2+64+ledgeDistance, 32); [self addChild:ledge]; @@ -351,23 +356,22 @@ - (void)randomlyAddObject:(ccTime)dt { - FallingObject* object; - + int recipeIdentifier; int randomval = arc4random()%100; int pmChance = (5-pointMultiplier)*5 + 30; if (randomval < 30) { - object = [[OneUp alloc] init]; + recipeIdentifier = kOneUpObject; } else if (randomval < pmChance) { - object = [[PointMultiplier alloc] init]; + recipeIdentifier = kPointMultiplierObject; } else { - object = [[Rock alloc] init]; + recipeIdentifier = kRockObject; } + FallingObject* object = [[objectFactory buildFallingObjectWithRecipeIdentifier:recipeIdentifier] retain]; int objectX; - CGSize first = [cart.sprite boundingBox].size; CGSize second = [object.sprite boundingBox].size; @@ -391,6 +395,7 @@ break; } + object.delegate = self; object.sprite.position = ccp(objectX, 360); object.sprite.scale = 1; [self addChild:object.sprite]; @@ -402,7 +407,7 @@ { if (arc4random() % 100 > 80) { - object = [[Rock alloc] init]; + object = [[objectFactory buildFallingObjectWithRecipeIdentifier:kRockObject] retain]; for (;;) { @@ -424,6 +429,7 @@ break; } + object.delegate = self; object.sprite.position = ccp(objectX, 360); object.sprite.scale = 1; [self addChild:object.sprite]; @@ -437,7 +443,7 @@ { if (arc4random() % 100 > 80) { - object = [[Rock alloc] init]; + object = [[objectFactory buildFallingObjectWithRecipeIdentifier:kRockObject] retain]; for (;;) { @@ -459,6 +465,7 @@ break; } + object.delegate = self; object.sprite.position = ccp(objectX, 360); object.sprite.scale = 1; [self addChild:object.sprite]; @@ -486,6 +493,23 @@ } } +- (void)didCatchItem:(FallingObject *)item +{ + if (item.objectType == kRockObject) + { + [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]]; + self.lives--; + } else if (item.objectType == kOneUpObject) + { + [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]]; + self.lives++; + } else if (item.objectType == kPointMultiplierObject) + { + [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Absorption2" ofType:@"wav"]]; + self.pointMultiplier++; + } +} + @end @implementation LedgeFactory diff --git a/Classes/OneUp.h b/Classes/OneUp.h deleted file mode 100755 index 8bd4c66..0000000 --- a/Classes/OneUp.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// OneUp.h -// Cart Collect -// -// Created by iD Student Account on 7/19/11. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import -#import "FallingObject.h" - -@interface OneUp : FallingObject { - -} - -- (id)init; - -@end diff --git a/Classes/OneUp.m b/Classes/OneUp.m deleted file mode 100755 index 9e0d4f0..0000000 --- a/Classes/OneUp.m +++ /dev/null @@ -1,36 +0,0 @@ -// -// OneUp.m -// Cart Collect -// -// Created by iD Student Account on 7/19/11. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import "OneUp.h" -#import "GameMode.h" -#import "SimpleAudioEngine.h" - -@implementation OneUp - -- (id)init -{ - self = [super init]; - - if (nil != self) - { - sprite = [CCSprite spriteWithFile:@"oneup.png"]; - weight = 10; - } - - return self; -} - -- (void)collideWithCart -{ - GameMode* gameLayer = ((GameMode*) sprite.parent); - [gameLayer setLives:gameLayer.lives+1]; - - [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]]; -} - -@end diff --git a/Classes/PointMultiplier.h b/Classes/PointMultiplier.h deleted file mode 100644 index 9d009cb..0000000 --- a/Classes/PointMultiplier.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// PointMultiplier.h -// Cartographic -// -// Created by Starla Insigna on 9/10/11. -// Copyright (c) 2011 Four Island. All rights reserved. -// - -#import "FallingObject.h" - -@interface PointMultiplier : FallingObject - -- (id)init; - -@end diff --git a/Classes/PointMultiplier.m b/Classes/PointMultiplier.m deleted file mode 100644 index 0a9649d..0000000 --- a/Classes/PointMultiplier.m +++ /dev/null @@ -1,36 +0,0 @@ -// -// PointMultiplier.m -// Cartographic -// -// Created by Starla Insigna on 9/10/11. -// Copyright (c) 2011 Four Island. All rights reserved. -// - -#import "PointMultiplier.h" -#import "GameMode.h" -#import "SimpleAudioEngine.h" - -@implementation PointMultiplier - -- (id)init -{ - self = [super init]; - - if (nil != self) - { - sprite = [CCSprite spriteWithFile:@"multiplier.png"]; - weight = 8; - } - - return self; -} - -- (void)collideWithCart -{ - GameMode* gameLayer = ((GameMode*) sprite.parent); - [gameLayer setPointMultiplier:gameLayer.pointMultiplier+1]; - - [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Absorption2" ofType:@"wav"]]; -} - -@end diff --git a/Classes/Rock.h b/Classes/Rock.h deleted file mode 100755 index 7382d99..0000000 --- a/Classes/Rock.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// Rock.h -// Cart Collect -// -// Created by iD Student Account on 7/19/11. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import -#import "FallingObject.h" - -@interface Rock : FallingObject { - -} - -- (id)init; - -@end diff --git a/Classes/Rock.m b/Classes/Rock.m deleted file mode 100755 index aac1aaf..0000000 --- a/Classes/Rock.m +++ /dev/null @@ -1,37 +0,0 @@ -// -// Rock.m -// Cart Collect -// -// Created by iD Student Account on 7/19/11. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import "Rock.h" -#import "GameMode.h" -#import "SimpleAudioEngine.h" - -@implementation Rock - -- (id)init -{ - self = [super init]; - - if (nil != self) - { - sprite = [CCSprite spriteWithFile:@"rock.png"]; - weight = 7; - } - - return self; -} - -- (void)collideWithCart -{ - GameMode* gameLayer = ((GameMode*) sprite.parent); - [gameLayer setLives:gameLayer.lives-1]; - - [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]]; -} - - -@end diff --git a/Classes/TutorialMode.h b/Classes/TutorialMode.h index 6380483..697c688 100644 --- a/Classes/TutorialMode.h +++ b/Classes/TutorialMode.h @@ -18,7 +18,7 @@ @property (nonatomic,retain) TutorialBubble* currentTutorial; - (void)endTutorial; -- (FallingObject*)dropSpecificItem:(FallingObject*)item; +- (FallingObject*)dropSpecificItem:(int)objectType; - (FallingObject*)dropRandomItem; - (void)randomlyAddObject:(ccTime)dt; 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 @@ #import "TutorialMode.h" #import "FallingObject.h" -#import "Cherry.h" -#import "Bottle.h" -#import "OneUp.h" -#import "Rock.h" #import "GameModeSelectionLayer.h" +#import "SimpleAudioEngine.h" // Item tags: // 2000 - first dropped item @@ -22,6 +19,13 @@ // 2009 - rock // 2010 - random item dropped after death from first rock +typedef enum { + kCherryObject = 0, + kEnergyDrinkObject, + kOneUpObject, + kRockObject +} FallingObjects; + @implementation TutorialMode @synthesize currentTutorial; @@ -38,6 +42,11 @@ showedDeathBubble = NO; randomItemsDropped = 0; + + [objectFactory createRecipeWithIdentifier:kCherryObject spriteFilename:@"cherry.png" weight:5]; + [objectFactory createRecipeWithIdentifier:kEnergyDrinkObject spriteFilename:@"bottle.png" weight:6]; + [objectFactory createRecipeWithIdentifier:kOneUpObject spriteFilename:@"oneup.png" weight:10]; + [objectFactory createRecipeWithIdentifier:kRockObject spriteFilename:@"rock.png" weight:7]; } return self; @@ -79,6 +88,24 @@ - (void)didCatchItem:(FallingObject *)item { + if (item.objectType == kCherryObject) + { + [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]]; + self.score += 10; + } else if (item.objectType == kEnergyDrinkObject) + { + [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]]; + self.score += 25; + } else if (item.objectType == kOneUpObject) + { + [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]]; + self.lives++; + } else if (item.objectType == kRockObject) + { + [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]]; + self.lives--; + } + if (item.sprite.tag == 2000) { 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 @@ - (void)didMissItem:(FallingObject *)item { + if ((item.objectType == kCherryObject) || (item.objectType == kEnergyDrinkObject)) + { + [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]]; + self.lives--; + } + if (item.sprite.tag == 2000) { 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 @@ [self scheduleDelayedAction:^{ FallingObject* object = [self dropRandomItem]; object.sprite.tag = 2002; - [object release]; } delay:1.0f]; } } @@ -181,7 +213,6 @@ [self scheduleDelayedAction:^{ FallingObject* object = [self dropRandomItem]; object.sprite.tag = 2000; - [object release]; } delay:3.0f]; } else if ([currentTutorial.name isEqual:@"caught-first"]) { @@ -198,29 +229,24 @@ } object.sprite.tag = 2001; - - [object release]; } delay:1.0f]; } else if ([currentTutorial.name isEqual:@"missed-first"]) { [self scheduleDelayedAction:^{ FallingObject* object = [self dropRandomItem]; object.sprite.tag = 2002; - [object release]; } delay:1.0f]; } else if (([currentTutorial.name isEqual:@"caught-second"]) || ([currentTutorial.name isEqual:@"missed-second"])) { [self scheduleDelayedAction:^{ - FallingObject* object = [self dropSpecificItem:[[OneUp alloc] init]]; + FallingObject* object = [self dropSpecificItem:kOneUpObject]; object.sprite.tag = 2003; - [object release]; } delay:2.0f]; } else if ([currentTutorial.name isEqual:@"gameover-rock"]) { [self scheduleDelayedAction:^{ FallingObject* object = [self dropRandomItem]; object.sprite.tag = 2010; - [object release]; } delay:1.0f]; } else if ([currentTutorial.name isEqual:@"intense"]) { @@ -254,8 +280,9 @@ } } -- (FallingObject*)dropSpecificItem:(FallingObject*)object +- (FallingObject*)dropSpecificItem:(int)objectType { + FallingObject* object = [[objectFactory buildFallingObjectWithRecipeIdentifier:objectType] retain]; int objectX = arc4random()%448+16; object.sprite.position = ccp(objectX, 360); object.sprite.scale = 1; @@ -265,27 +292,27 @@ [objects addObject:object]; - return object; + return [object autorelease]; } - (FallingObject*)dropRandomItem { - FallingObject* object; int randomval = arc4random()%100; + int recipeIdentifier; if (randomval < 65) { - object = [[Cherry alloc] init]; + recipeIdentifier = kCherryObject; } else { - object = [[Bottle alloc] init]; + recipeIdentifier = kEnergyDrinkObject; } - return [self dropSpecificItem:object]; + return [self dropSpecificItem:recipeIdentifier]; } - (void)randomlyAddObject:(ccTime)dt { - FallingObject* object; + int recipeIdentifier; if (randomItemsDropped < 5) { @@ -293,17 +320,16 @@ if (randomval < 65) { - object = [[Cherry alloc] init]; + recipeIdentifier = kCherryObject; } else if (randomval < 98) { - object = [[Bottle alloc] init]; + recipeIdentifier = kEnergyDrinkObject; } else { - object = [[OneUp alloc] init]; + recipeIdentifier = kOneUpObject; } } else if (randomItemsDropped == 5) { - object = [[Rock alloc] init]; - object.sprite.tag = 2009; + recipeIdentifier = kRockObject; [self unschedule:@selector(randomlyAddObject:)]; } else if (randomItemsDropped < 15) { @@ -311,15 +337,15 @@ if (randomval < 40) { - object = [[Cherry alloc] init]; + recipeIdentifier = kCherryObject; } else if (randomval < 70) { - object = [[Rock alloc] init]; + recipeIdentifier = kRockObject; } else if (randomval < 98) { - object = [[Bottle alloc] init]; + recipeIdentifier = kEnergyDrinkObject; } else { - object = [[OneUp alloc] init]; + recipeIdentifier = kOneUpObject; } } else if (randomItemsDropped == 15) { @@ -341,8 +367,12 @@ return; } - [self dropSpecificItem:object]; - [object release]; + FallingObject* object = [self dropSpecificItem:recipeIdentifier]; + + if (randomItemsDropped == 5) + { + object.sprite.tag = 2009; + } randomItemsDropped++; } diff --git a/Classes/ValuableObject.h b/Classes/ValuableObject.h deleted file mode 100644 index 7b484d9..0000000 --- a/Classes/ValuableObject.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// ValuableObject.h -// Cart Collect -// -// Created by Starla Insigna on 8/9/11. -// Copyright 2011 Four Island. All rights reserved. -// - -#import "FallingObject.h" - -@interface ValuableObject : FallingObject - -- (int)pointValue; - -@end diff --git a/Classes/ValuableObject.m b/Classes/ValuableObject.m deleted file mode 100644 index f1a036f..0000000 --- a/Classes/ValuableObject.m +++ /dev/null @@ -1,46 +0,0 @@ -// -// ValuableObject.m -// Cart Collect -// -// Created by Starla Insigna on 8/9/11. -// Copyright 2011 Four Island. All rights reserved. -// - -#import "ValuableObject.h" -#import "GameMode.h" -#import "SimpleAudioEngine.h" - -@implementation ValuableObject - -- (id)init -{ - self = [super init]; - if (self) { - // Initialization code here. - } - - return self; -} - -- (void)collideWithCart -{ - GameMode* gameLayer = ((GameMode*) sprite.parent); - [gameLayer setScore:gameLayer.score+self.pointValue]; - - [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]]; -} - -- (void)collideWithFloor -{ - GameMode* gameLayer = ((GameMode*) sprite.parent); - [gameLayer setLives:gameLayer.lives-1]; - - [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]]; -} - -- (int)pointValue -{ - @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] userInfo:nil]; -} - -@end -- cgit 1.4.1