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/FallingObject.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/FallingObject.m')
-rwxr-xr-x | Classes/FallingObject.m | 22 |
1 files changed, 5 insertions, 17 deletions
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 @@ | |||
11 | 11 | ||
12 | @implementation FallingObject | 12 | @implementation FallingObject |
13 | 13 | ||
14 | @synthesize sprite, weight, delegate; | 14 | @synthesize sprite, weight, objectType, delegate; |
15 | 15 | ||
16 | - (id)init | 16 | - (id)initWithSpriteFilename:(NSString*)filename weight:(int)m_weight objectType:(int)m_objectType |
17 | { | 17 | { |
18 | self = [super init]; | 18 | self = [super init]; |
19 | 19 | ||
20 | if (nil != self) | 20 | if (nil != self) |
21 | { | 21 | { |
22 | 22 | sprite = [CCSprite spriteWithFile:filename]; | |
23 | weight = m_weight; | ||
24 | objectType = m_objectType; | ||
23 | } | 25 | } |
24 | 26 | ||
25 | return self; | 27 | return self; |
@@ -44,8 +46,6 @@ | |||
44 | { | 46 | { |
45 | if (gameLayer.cart.sprite.position.y < (sprite.position.y + second.height/2 + first.height/2)) | 47 | if (gameLayer.cart.sprite.position.y < (sprite.position.y + second.height/2 + first.height/2)) |
46 | { | 48 | { |
47 | [self collideWithCart]; | ||
48 | |||
49 | if ((delegate != nil) && ([delegate respondsToSelector:@selector(didCatchItem:)])) | 49 | if ((delegate != nil) && ([delegate respondsToSelector:@selector(didCatchItem:)])) |
50 | { | 50 | { |
51 | [delegate didCatchItem:self]; | 51 | [delegate didCatchItem:self]; |
@@ -65,8 +65,6 @@ | |||
65 | // Collision detection with floor | 65 | // Collision detection with floor |
66 | if (sprite.position.y - (sprite.contentSize.height/2) < 0) | 66 | if (sprite.position.y - (sprite.contentSize.height/2) < 0) |
67 | { | 67 | { |
68 | [self collideWithFloor]; | ||
69 | |||
70 | if ((delegate != nil) && ([delegate respondsToSelector:@selector(didMissItem:)])) | 68 | if ((delegate != nil) && ([delegate respondsToSelector:@selector(didMissItem:)])) |
71 | { | 69 | { |
72 | [delegate didMissItem:self]; | 70 | [delegate didMissItem:self]; |
@@ -83,16 +81,6 @@ | |||
83 | return NO; | 81 | return NO; |
84 | } | 82 | } |
85 | 83 | ||
86 | - (void)collideWithCart | ||
87 | { | ||
88 | |||
89 | } | ||
90 | |||
91 | - (void)collideWithFloor | ||
92 | { | ||
93 | |||
94 | } | ||
95 | |||
96 | - (BOOL)flag:(int)flag | 84 | - (BOOL)flag:(int)flag |
97 | { | 85 | { |
98 | return flags[flag]; | 86 | return flags[flag]; |