summary refs log tree commit diff stats
path: root/Classes/FallingObjectFactory.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-09-10 17:07:13 -0400
committerStarla Insigna <starla4444@gmail.com>2011-09-10 17:07:13 -0400
commitfd58a0cde1bb5473e39e6cb82d28113da84b9ae0 (patch)
tree8d36b2fedc3c056c002a881e78340c7b56bbabea /Classes/FallingObjectFactory.m
parent5ccc4fc305f502a552b1ac7e815e576c93a8159a (diff)
downloadcartcollect-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/FallingObjectFactory.m')
-rw-r--r--Classes/FallingObjectFactory.m70
1 files changed, 70 insertions, 0 deletions
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 @@
1//
2// FallingObjectFactory.m
3// Cartographic
4//
5// Created by Starla Insigna on 9/10/11.
6// Copyright (c) 2011 Four Island. All rights reserved.
7//
8
9#import "FallingObjectFactory.h"
10
11@interface FallingObjectRecipe : NSObject {
12 NSString* spriteFilename;
13 int weight;
14}
15
16@property (readonly) NSString* spriteFilename;
17@property (readonly) int weight;
18- (id)initWithSpriteFilename:(NSString*)filename weight:(int)m_weight;
19
20@end
21
22@implementation FallingObjectRecipe
23
24@synthesize spriteFilename, weight;
25
26- (id)initWithSpriteFilename:(NSString*)filename weight:(int)m_weight
27{
28 self = [super init];
29
30 if (nil != self)
31 {
32 spriteFilename = [filename retain];
33 weight = m_weight;
34 }
35
36 return self;
37}
38
39@end
40
41@implementation FallingObjectFactory
42
43- (id)init
44{
45 self = [super init];
46
47 if (nil != self)
48 {
49 recipes = [[NSMutableDictionary alloc] init];
50 }
51
52 return self;
53}
54
55- (void)createRecipeWithIdentifier:(int)identifier spriteFilename:(NSString*)filename weight:(int)weight
56{
57 FallingObjectRecipe* recipe = [[FallingObjectRecipe alloc] initWithSpriteFilename:filename weight:weight];
58 [recipes setObject:recipe forKey:[NSNumber numberWithInt:identifier]];
59 [recipe release];
60}
61
62- (FallingObject*)buildFallingObjectWithRecipeIdentifier:(int)identifier
63{
64 FallingObjectRecipe* recipe = [recipes objectForKey:[NSNumber numberWithInt:identifier]];
65 FallingObject* object = [[FallingObject alloc] initWithSpriteFilename:recipe.spriteFilename weight:recipe.weight objectType:identifier];
66
67 return [object autorelease];
68}
69
70@end