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/FallingObject.m | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'Classes/FallingObject.m') 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]; -- cgit 1.4.1