diff options
author | Starla Insigna <starla4444@gmail.com> | 2011-09-10 17:07:13 -0400 |
---|---|---|
committer | Starla Insigna <starla4444@gmail.com> | 2011-09-10 17:07:13 -0400 |
commit | fd58a0cde1bb5473e39e6cb82d28113da84b9ae0 (patch) | |
tree | 8d36b2fedc3c056c002a881e78340c7b56bbabea /Classes/ClassicGameMode.m | |
parent | 5ccc4fc305f502a552b1ac7e815e576c93a8159a (diff) | |
download | cartcollect-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/ClassicGameMode.m')
-rwxr-xr-x | Classes/ClassicGameMode.m | 71 |
1 files changed, 56 insertions, 15 deletions
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 @@ | |||
8 | 8 | ||
9 | #import "ClassicGameMode.h" | 9 | #import "ClassicGameMode.h" |
10 | #import "FallingObject.h" | 10 | #import "FallingObject.h" |
11 | #import "Cherry.h" | ||
12 | #import "Bottle.h" | ||
13 | #import "OneUp.h" | ||
14 | #import "Rock.h" | ||
15 | #import "GameOverScene.h" | 11 | #import "GameOverScene.h" |
16 | #import "SimpleAudioEngine.h" | 12 | #import "SimpleAudioEngine.h" |
17 | #import "CCNotifications.h" | 13 | #import "CCNotifications.h" |
@@ -19,6 +15,13 @@ | |||
19 | 15 | ||
20 | @implementation ClassicGameMode | 16 | @implementation ClassicGameMode |
21 | 17 | ||
18 | typedef enum { | ||
19 | kCherryObject = 0, | ||
20 | kEnergyDrinkObject, | ||
21 | kOneUpObject, | ||
22 | kRockObject | ||
23 | } FallingObjects; | ||
24 | |||
22 | - (void)tick:(ccTime)dt | 25 | - (void)tick:(ccTime)dt |
23 | { | 26 | { |
24 | int lastScore = score; | 27 | int lastScore = score; |
@@ -83,6 +86,7 @@ | |||
83 | { | 86 | { |
84 | FallingObject* object; | 87 | FallingObject* object; |
85 | int oneuppercent = 98 - (lives == 1 ? 1 : 0); | 88 | int oneuppercent = 98 - (lives == 1 ? 1 : 0); |
89 | int recipeIdentifier; | ||
86 | 90 | ||
87 | if (score < 1000) | 91 | if (score < 1000) |
88 | { | 92 | { |
@@ -90,31 +94,33 @@ | |||
90 | 94 | ||
91 | if (randomval < 65) | 95 | if (randomval < 65) |
92 | { | 96 | { |
93 | object = [[Cherry alloc] init]; | 97 | recipeIdentifier = kCherryObject; |
94 | } else if (randomval < oneuppercent) | 98 | } else if (randomval < oneuppercent) |
95 | { | 99 | { |
96 | object = [[Bottle alloc] init]; | 100 | recipeIdentifier = kEnergyDrinkObject; |
97 | } else { | 101 | } else { |
98 | object = [[OneUp alloc] init]; | 102 | recipeIdentifier = kOneUpObject; |
99 | } | 103 | } |
100 | } else { | 104 | } else { |
101 | int randomval = arc4random()%100; | 105 | int randomval = arc4random()%100; |
102 | 106 | ||
103 | if (randomval < 40) | 107 | if (randomval < 40) |
104 | { | 108 | { |
105 | object = [[Cherry alloc] init]; | 109 | recipeIdentifier = kCherryObject; |
106 | } else if (randomval < 70) | 110 | } else if (randomval < 70) |
107 | { | 111 | { |
108 | object = [[Rock alloc] init]; | 112 | recipeIdentifier = kRockObject; |
109 | } else if (randomval < oneuppercent) | 113 | } else if (randomval < oneuppercent) |
110 | { | 114 | { |
111 | object = [[Bottle alloc] init]; | 115 | recipeIdentifier = kEnergyDrinkObject; |
112 | } else { | 116 | } else { |
113 | object = [[OneUp alloc] init]; | 117 | recipeIdentifier = kOneUpObject; |
114 | } | 118 | } |
115 | } | 119 | } |
116 | 120 | ||
117 | int objectX = arc4random()%448+16; | 121 | int objectX = arc4random()%448+16; |
122 | object = [[objectFactory buildFallingObjectWithRecipeIdentifier:recipeIdentifier] retain]; | ||
123 | object.delegate = self; | ||
118 | object.sprite.position = ccp(objectX, 360); | 124 | object.sprite.position = ccp(objectX, 360); |
119 | object.sprite.scale = 1; | 125 | object.sprite.scale = 1; |
120 | [self addChild:object.sprite]; | 126 | [self addChild:object.sprite]; |
@@ -126,8 +132,8 @@ | |||
126 | { | 132 | { |
127 | if (arc4random() % 100 > 80) | 133 | if (arc4random() % 100 > 80) |
128 | { | 134 | { |
129 | object = [[Rock alloc] init]; | 135 | object = [[objectFactory buildFallingObjectWithRecipeIdentifier:kRockObject] retain]; |
130 | 136 | object.delegate = self; | |
131 | objectX = arc4random()%448+16; | 137 | objectX = arc4random()%448+16; |
132 | object.sprite.position = ccp(objectX, 360); | 138 | object.sprite.position = ccp(objectX, 360); |
133 | object.sprite.scale = 1; | 139 | object.sprite.scale = 1; |
@@ -142,8 +148,8 @@ | |||
142 | { | 148 | { |
143 | if (arc4random() % 100 > 80) | 149 | if (arc4random() % 100 > 80) |
144 | { | 150 | { |
145 | object = [[Rock alloc] init]; | 151 | object = [[objectFactory buildFallingObjectWithRecipeIdentifier:kRockObject] retain]; |
146 | 152 | object.delegate = self; | |
147 | objectX = arc4random()%448+16; | 153 | objectX = arc4random()%448+16; |
148 | object.sprite.position = ccp(objectX, 360); | 154 | object.sprite.position = ccp(objectX, 360); |
149 | object.sprite.scale = 1; | 155 | object.sprite.scale = 1; |
@@ -166,6 +172,11 @@ | |||
166 | [self addChild:backgroundImage z:-1]; | 172 | [self addChild:backgroundImage z:-1]; |
167 | 173 | ||
168 | addSpeed = 2.5f; | 174 | addSpeed = 2.5f; |
175 | |||
176 | [objectFactory createRecipeWithIdentifier:kCherryObject spriteFilename:@"cherry.png" weight:5]; | ||
177 | [objectFactory createRecipeWithIdentifier:kEnergyDrinkObject spriteFilename:@"bottle.png" weight:6]; | ||
178 | [objectFactory createRecipeWithIdentifier:kOneUpObject spriteFilename:@"oneup.png" weight:10]; | ||
179 | [objectFactory createRecipeWithIdentifier:kRockObject spriteFilename:@"rock.png" weight:7]; | ||
169 | } | 180 | } |
170 | 181 | ||
171 | return self; | 182 | return self; |
@@ -178,4 +189,34 @@ | |||
178 | [self schedule:@selector(randomlyAddObject:) interval:addSpeed]; | 189 | [self schedule:@selector(randomlyAddObject:) interval:addSpeed]; |
179 | } | 190 | } |
180 | 191 | ||
192 | - (void)didCatchItem:(FallingObject *)item | ||
193 | { | ||
194 | if (item.objectType == kCherryObject) | ||
195 | { | ||
196 | [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]]; | ||
197 | self.score += 10; | ||
198 | } else if (item.objectType == kEnergyDrinkObject) | ||
199 | { | ||
200 | [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]]; | ||
201 | self.score += 25; | ||
202 | } else if (item.objectType == kOneUpObject) | ||
203 | { | ||
204 | [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]]; | ||
205 | self.lives++; | ||
206 | } else if (item.objectType == kRockObject) | ||
207 | { | ||
208 | [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]]; | ||
209 | self.lives--; | ||
210 | } | ||
211 | } | ||
212 | |||
213 | - (void)didMissItem:(FallingObject *)item | ||
214 | { | ||
215 | if ((item.objectType == kCherryObject) || (item.objectType == kEnergyDrinkObject)) | ||
216 | { | ||
217 | [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]]; | ||
218 | self.lives--; | ||
219 | } | ||
220 | } | ||
221 | |||
181 | @end | 222 | @end |