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. --- Cartographic.xcodeproj/project.pbxproj | 44 +++-------------- 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 ----------------- 25 files changed, 272 insertions(+), 444 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 diff --git a/Cartographic.xcodeproj/project.pbxproj b/Cartographic.xcodeproj/project.pbxproj index 75343b3..5aed3f5 100755 --- a/Cartographic.xcodeproj/project.pbxproj +++ b/Cartographic.xcodeproj/project.pbxproj @@ -31,14 +31,10 @@ 3F6C7C3413D5DEB100C038FE /* Damage1.wav in Resources */ = {isa = PBXBuildFile; fileRef = 3F6C7C3313D5DEB100C038FE /* Damage1.wav */; }; 3F6C7C4913D5DEDB00C038FE /* Item1.wav in Resources */ = {isa = PBXBuildFile; fileRef = 3F6C7C4813D5DEDB00C038FE /* Item1.wav */; }; 3F6C7C4F13D5E1B600C038FE /* FallingObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F6C7C4E13D5E1B600C038FE /* FallingObject.m */; }; - 3F6C7C6D13D5E51800C038FE /* Cherry.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F6C7C6C13D5E51800C038FE /* Cherry.m */; }; - 3F6C7C7013D5E54E00C038FE /* Bottle.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F6C7C6F13D5E54E00C038FE /* Bottle.m */; }; - 3F6C7C7313D5E57100C038FE /* OneUp.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F6C7C7213D5E57100C038FE /* OneUp.m */; }; 3F6C7E9C13D6315D00C038FE /* helvetica.fnt in Resources */ = {isa = PBXBuildFile; fileRef = 3F6C7E9B13D6315D00C038FE /* helvetica.fnt */; }; 3F6C7EAD13D6323600C038FE /* helvetica.png in Resources */ = {isa = PBXBuildFile; fileRef = 3F6C7EAC13D6323600C038FE /* helvetica.png */; }; 3F6C7EC613D6335A00C038FE /* 1up.wav in Resources */ = {isa = PBXBuildFile; fileRef = 3F6C7EC513D6335A00C038FE /* 1up.wav */; }; 3F6C7EE113D636BE00C038FE /* rock.png in Resources */ = {isa = PBXBuildFile; fileRef = 3F6C7EE013D636BE00C038FE /* rock.png */; }; - 3F6C7EE413D636CF00C038FE /* Rock.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F6C7EE313D636CF00C038FE /* Rock.m */; }; 3F6C7EE913D6377D00C038FE /* GameOverScene.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F6C7EE813D6377D00C038FE /* GameOverScene.m */; }; 3F6C7F2413D63E6500C038FE /* SeaBeach.png in Resources */ = {isa = PBXBuildFile; fileRef = 3F6C7F2313D63E6500C038FE /* SeaBeach.png */; }; 3F6C7F4B13D647A600C038FE /* GameOver.png in Resources */ = {isa = PBXBuildFile; fileRef = 3F6C7F4A13D647A600C038FE /* GameOver.png */; }; @@ -98,7 +94,6 @@ 50F4144910692EE7002A0D5E /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 50F4144410692EE7002A0D5E /* Default.png */; }; 50F4144A10692EE7002A0D5E /* fps_images.png in Resources */ = {isa = PBXBuildFile; fileRef = 50F4144510692EE7002A0D5E /* fps_images.png */; }; 50F4144B10692EE7002A0D5E /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 50F4144610692EE7002A0D5E /* Icon.png */; }; - 6C0C140E13F1C3EC003A31B2 /* ValuableObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C0C140D13F1C3EC003A31B2 /* ValuableObject.m */; }; 6C0C141113F2099B003A31B2 /* Cart.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C0C141013F2099B003A31B2 /* Cart.m */; }; 6C0C141413F20E98003A31B2 /* GameMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C0C141313F20E98003A31B2 /* GameMode.m */; }; 6C18C3CA1402AD9C0005AA4C /* UIImage+ColorMasking.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C18C3C91402AD9C0005AA4C /* UIImage+ColorMasking.m */; }; @@ -129,9 +124,9 @@ 6CC89DD913F2F4E6003704F7 /* Entitlements.plist in Resources */ = {isa = PBXBuildFile; fileRef = 6CC89DD813F2F4E6003704F7 /* Entitlements.plist */; }; 6CC89DDF13F31413003704F7 /* TutorialMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 6CC89DDE13F31413003704F7 /* TutorialMode.m */; }; 6CDBE80C14092DB00072F287 /* ledge.png in Resources */ = {isa = PBXBuildFile; fileRef = 6CDBE80B14092DB00072F287 /* ledge.png */; }; - 6CF64C09141B9FA300F3B702 /* PointMultiplier.m in Sources */ = {isa = PBXBuildFile; fileRef = 6CF64C08141B9FA300F3B702 /* PointMultiplier.m */; }; 6CF64C0B141BA37000F3B702 /* multiplier.png in Resources */ = {isa = PBXBuildFile; fileRef = 6CF64C0A141BA37000F3B702 /* multiplier.png */; }; 6CF64C11141BA84200F3B702 /* Absorption2.wav in Resources */ = {isa = PBXBuildFile; fileRef = 6CF64C10141BA84200F3B702 /* Absorption2.wav */; }; + 6CF64C1D141BFA9600F3B702 /* FallingObjectFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 6CF64C1C141BFA9600F3B702 /* FallingObjectFactory.m */; }; DC6640030F83B3EA000B3E49 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC6640020F83B3EA000B3E49 /* AudioToolbox.framework */; }; DC6640050F83B3EA000B3E49 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC6640040F83B3EA000B3E49 /* OpenAL.framework */; }; DCCBF1B70F6022AE0040855A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DCCBF1B60F6022AE0040855A /* CoreGraphics.framework */; }; @@ -354,18 +349,10 @@ 3F6C7C4813D5DEDB00C038FE /* Item1.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = Item1.wav; sourceTree = ""; }; 3F6C7C4D13D5E1B600C038FE /* FallingObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FallingObject.h; sourceTree = ""; }; 3F6C7C4E13D5E1B600C038FE /* FallingObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FallingObject.m; sourceTree = ""; }; - 3F6C7C6B13D5E51800C038FE /* Cherry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Cherry.h; sourceTree = ""; }; - 3F6C7C6C13D5E51800C038FE /* Cherry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Cherry.m; sourceTree = ""; }; - 3F6C7C6E13D5E54E00C038FE /* Bottle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Bottle.h; sourceTree = ""; }; - 3F6C7C6F13D5E54E00C038FE /* Bottle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Bottle.m; sourceTree = ""; }; - 3F6C7C7113D5E57100C038FE /* OneUp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OneUp.h; sourceTree = ""; }; - 3F6C7C7213D5E57100C038FE /* OneUp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OneUp.m; sourceTree = ""; }; 3F6C7E9B13D6315D00C038FE /* helvetica.fnt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = helvetica.fnt; sourceTree = ""; }; 3F6C7EAC13D6323600C038FE /* helvetica.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = helvetica.png; sourceTree = ""; }; 3F6C7EC513D6335A00C038FE /* 1up.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = 1up.wav; sourceTree = ""; }; 3F6C7EE013D636BE00C038FE /* rock.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = rock.png; sourceTree = ""; }; - 3F6C7EE213D636CF00C038FE /* Rock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Rock.h; sourceTree = ""; }; - 3F6C7EE313D636CF00C038FE /* Rock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Rock.m; sourceTree = ""; }; 3F6C7EE713D6377D00C038FE /* GameOverScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameOverScene.h; sourceTree = ""; }; 3F6C7EE813D6377D00C038FE /* GameOverScene.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameOverScene.m; sourceTree = ""; }; 3F6C7F2313D63E6500C038FE /* SeaBeach.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = SeaBeach.png; sourceTree = ""; }; @@ -424,8 +411,6 @@ 50F4144510692EE7002A0D5E /* fps_images.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = fps_images.png; sourceTree = ""; }; 50F4144610692EE7002A0D5E /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = ""; }; 50F4144710692EE7002A0D5E /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 6C0C140C13F1C3EC003A31B2 /* ValuableObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ValuableObject.h; sourceTree = ""; }; - 6C0C140D13F1C3EC003A31B2 /* ValuableObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ValuableObject.m; sourceTree = ""; }; 6C0C140F13F2099B003A31B2 /* Cart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Cart.h; sourceTree = ""; }; 6C0C141013F2099B003A31B2 /* Cart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Cart.m; sourceTree = ""; }; 6C0C141213F20E98003A31B2 /* GameMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameMode.h; sourceTree = ""; }; @@ -474,10 +459,10 @@ 6CC89DE013F3197F003704F7 /* FallingObjectDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FallingObjectDelegate.h; sourceTree = ""; }; 6CDBE80B14092DB00072F287 /* ledge.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ledge.png; sourceTree = ""; }; 6CDBE80E140936CF0072F287 /* CartDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CartDelegate.h; sourceTree = ""; }; - 6CF64C07141B9FA300F3B702 /* PointMultiplier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PointMultiplier.h; sourceTree = ""; }; - 6CF64C08141B9FA300F3B702 /* PointMultiplier.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PointMultiplier.m; sourceTree = ""; }; 6CF64C0A141BA37000F3B702 /* multiplier.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = multiplier.png; sourceTree = ""; }; 6CF64C10141BA84200F3B702 /* Absorption2.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = Absorption2.wav; sourceTree = ""; }; + 6CF64C1B141BFA9600F3B702 /* FallingObjectFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FallingObjectFactory.h; sourceTree = ""; }; + 6CF64C1C141BFA9600F3B702 /* FallingObjectFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FallingObjectFactory.m; sourceTree = ""; }; DC6640020F83B3EA000B3E49 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; DC6640040F83B3EA000B3E49 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; }; DCCBF1B60F6022AE0040855A /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -968,22 +953,12 @@ children = ( 3F6C7C4D13D5E1B600C038FE /* FallingObject.h */, 3F6C7C4E13D5E1B600C038FE /* FallingObject.m */, - 3F6C7C6B13D5E51800C038FE /* Cherry.h */, - 3F6C7C6C13D5E51800C038FE /* Cherry.m */, - 3F6C7C6E13D5E54E00C038FE /* Bottle.h */, - 3F6C7C6F13D5E54E00C038FE /* Bottle.m */, - 3F6C7C7113D5E57100C038FE /* OneUp.h */, - 3F6C7C7213D5E57100C038FE /* OneUp.m */, - 3F6C7EE213D636CF00C038FE /* Rock.h */, - 3F6C7EE313D636CF00C038FE /* Rock.m */, - 6C0C140C13F1C3EC003A31B2 /* ValuableObject.h */, - 6C0C140D13F1C3EC003A31B2 /* ValuableObject.m */, + 6CC89DE013F3197F003704F7 /* FallingObjectDelegate.h */, + 6CF64C1B141BFA9600F3B702 /* FallingObjectFactory.h */, + 6CF64C1C141BFA9600F3B702 /* FallingObjectFactory.m */, 6C0C140F13F2099B003A31B2 /* Cart.h */, 6C0C141013F2099B003A31B2 /* Cart.m */, - 6CC89DE013F3197F003704F7 /* FallingObjectDelegate.h */, 6CDBE80E140936CF0072F287 /* CartDelegate.h */, - 6CF64C07141B9FA300F3B702 /* PointMultiplier.h */, - 6CF64C08141B9FA300F3B702 /* PointMultiplier.m */, ); name = Items; sourceTree = ""; @@ -1523,16 +1498,11 @@ E0F81038120A173C005866B8 /* RootViewController.m in Sources */, 3FE79CD413D4DE37001A6B93 /* ClassicGameMode.m in Sources */, 3F6C7C4F13D5E1B600C038FE /* FallingObject.m in Sources */, - 3F6C7C6D13D5E51800C038FE /* Cherry.m in Sources */, - 3F6C7C7013D5E54E00C038FE /* Bottle.m in Sources */, - 3F6C7C7313D5E57100C038FE /* OneUp.m in Sources */, - 3F6C7EE413D636CF00C038FE /* Rock.m in Sources */, 3F6C7EE913D6377D00C038FE /* GameOverScene.m in Sources */, 3F83955313D739B10059AEE8 /* MainMenuLayer.m in Sources */, 3F03221613D78F8C00E6A708 /* HighscoreListController.m in Sources */, 3F03221913D7904E00E6A708 /* Highscore.m in Sources */, 6C29041013EAEB590032DA0F /* TutorialBubble.m in Sources */, - 6C0C140E13F1C3EC003A31B2 /* ValuableObject.m in Sources */, 6C0C141113F2099B003A31B2 /* Cart.m in Sources */, 6C0C141413F20E98003A31B2 /* GameMode.m in Sources */, 6CC89DDF13F31413003704F7 /* TutorialMode.m in Sources */, @@ -1546,7 +1516,7 @@ 6C85834014055A44009EF100 /* CCNotifications.m in Sources */, 6C85834414055B2E009EF100 /* notificationDesign.m in Sources */, 6C4400041415080800A9E1D7 /* ZoomFadeTransition.m in Sources */, - 6CF64C09141B9FA300F3B702 /* PointMultiplier.m in Sources */, + 6CF64C1D141BFA9600F3B702 /* FallingObjectFactory.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; 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