summary refs log tree commit diff stats
path: root/Classes
diff options
context:
space:
mode:
Diffstat (limited to 'Classes')
-rwxr-xr-xClasses/Bottle.h18
-rwxr-xr-xClasses/Bottle.m32
-rwxr-xr-xClasses/Cherry.h18
-rwxr-xr-xClasses/Cherry.m32
-rwxr-xr-xClasses/ClassicGameMode.h3
-rwxr-xr-xClasses/ClassicGameMode.m111
-rwxr-xr-xClasses/FallingObject.h8
-rwxr-xr-xClasses/FallingObject.m20
-rw-r--r--Classes/FallingObjectFactory.h20
-rw-r--r--Classes/FallingObjectFactory.m70
-rw-r--r--Classes/GameMode.h5
-rw-r--r--Classes/GameMode.m24
-rw-r--r--Classes/GameModeInfo.h38
-rw-r--r--Classes/GameModeInfo.m126
-rw-r--r--Classes/GameModeManager.h20
-rw-r--r--Classes/GameModeManager.m68
-rw-r--r--Classes/GameModeSelection.h16
-rw-r--r--Classes/GameModeSelection.m123
-rw-r--r--Classes/GameModeSelectionLayer.m51
-rwxr-xr-xClasses/GameOverScene.h7
-rwxr-xr-xClasses/GameOverScene.m31
-rw-r--r--Classes/JumpGameMode.h5
-rw-r--r--Classes/JumpGameMode.m84
-rwxr-xr-xClasses/OneUp.h18
-rwxr-xr-xClasses/OneUp.m36
-rw-r--r--Classes/PointMultiplier.h15
-rw-r--r--Classes/PointMultiplier.m36
-rwxr-xr-xClasses/Rock.h18
-rwxr-xr-xClasses/Rock.m37
-rw-r--r--Classes/TutorialMode.h2
-rw-r--r--Classes/TutorialMode.m114
-rw-r--r--Classes/ValuableObject.h15
-rw-r--r--Classes/ValuableObject.m46
33 files changed, 670 insertions, 597 deletions
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 @@
1//
2// Bottle.h
3// Cart Collect
4//
5// Created by iD Student Account on 7/19/11.
6// Copyright 2011 __MyCompanyName__. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10#import "ValuableObject.h"
11
12@interface Bottle : ValuableObject {
13
14}
15
16- (id)init;
17
18@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 @@
1//
2// Bottle.m
3// Cart Collect
4//
5// Created by iD Student Account on 7/19/11.
6// Copyright 2011 __MyCompanyName__. All rights reserved.
7//
8
9#import "Bottle.h"
10
11
12@implementation Bottle
13
14- (id)init
15{
16 self = [super init];
17
18 if (nil != self)
19 {
20 sprite = [CCSprite spriteWithFile:@"bottle.png"];
21 weight = 6;
22 }
23
24 return self;
25}
26
27- (int)pointValue
28{
29 return 25;
30}
31
32@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 @@
1//
2// Cherry.h
3// Cart Collect
4//
5// Created by iD Student Account on 7/19/11.
6// Copyright 2011 __MyCompanyName__. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10#import "ValuableObject.h"
11
12@interface Cherry : ValuableObject {
13
14}
15
16- (id)init;
17
18@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 @@
1//
2// Cherry.m
3// Cart Collect
4//
5// Created by iD Student Account on 7/19/11.
6// Copyright 2011 __MyCompanyName__. All rights reserved.
7//
8
9#import "Cherry.h"
10
11
12@implementation Cherry
13
14- (id)init
15{
16 self = [super init];
17
18 if (nil != self)
19 {
20 sprite = [CCSprite spriteWithFile:@"cherry.png"];
21 weight = 5;
22 }
23
24 return self;
25}
26
27- (int)pointValue
28{
29 return 10;
30}
31
32@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 @@
9#import <Foundation/Foundation.h> 9#import <Foundation/Foundation.h>
10#import "cocos2d.h" 10#import "cocos2d.h"
11#import "GameMode.h" 11#import "GameMode.h"
12#import "FallingObjectDelegate.h"
12 13
13@interface ClassicGameMode : GameMode { 14@interface ClassicGameMode : GameMode <FallingObjectDelegate> {
14 float addSpeed; 15 float addSpeed;
15} 16}
16 17
diff --git a/Classes/ClassicGameMode.m b/Classes/ClassicGameMode.m index 46ad337..00bf049 100755 --- a/Classes/ClassicGameMode.m +++ b/Classes/ClassicGameMode.m
@@ -8,17 +8,36 @@
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"
18#import "TestFlight.h"
19 13
20@implementation ClassicGameMode 14@implementation ClassicGameMode
21 15
16typedef enum {
17 kCherryObject = 0,
18 kEnergyDrinkObject,
19 kOneUpObject,
20 kRockObject
21} FallingObjects;
22
23static GameModeInfo* info;
24
25+ (GameModeInfo*)info
26{
27 if (info == nil)
28 {
29 info = [[GameModeInfo alloc] initWithName:@"Collect"
30 location:@"Paris"
31 numOfStars:3
32 imageFilename:[[NSBundle mainBundle] pathForResource:@"paris" ofType:@"png"]
33 unlocked:YES
34 gameClass:[ClassicGameMode class]
35 globalHighscoreKey:@"Classic"];
36 }
37
38 return info;
39}
40
22- (void)tick:(ccTime)dt 41- (void)tick:(ccTime)dt
23{ 42{
24 int lastScore = score; 43 int lastScore = score;
@@ -29,7 +48,7 @@
29 { 48 {
30 [self unscheduleAllSelectors]; 49 [self unscheduleAllSelectors];
31 50
32 [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverScene sceneWithScore:score gameMode:@"Collect"]]]; 51 [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverScene sceneWithScore:score gameMode:[ClassicGameMode info]]]];
33 } else if (score > lastScore) 52 } else if (score > lastScore)
34 { 53 {
35 if ((lastScore < 6500) && (score >= 6500)) 54 if ((lastScore < 6500) && (score >= 6500))
@@ -42,24 +61,14 @@
42 [self unschedule:@selector(randomlyAddObject:)]; 61 [self unschedule:@selector(randomlyAddObject:)];
43 [self schedule:@selector(randomlyAddObject:) interval:0.7f]; 62 [self schedule:@selector(randomlyAddObject:) interval:0.7f];
44 addSpeed = 0.7f; 63 addSpeed = 0.7f;
45 } else if ((lastScore < 3000) && (score >= 3000))
46 {
47 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
48
49 if (![defaults boolForKey:@"unlockedJumpMode"])
50 {
51 [[CCNotifications sharedManager] addWithTitle:@"Jump" message:@"You've unlocked a new game mode!" image:@"venice.png"];
52
53 [defaults setBool:YES forKey:@"unlockedJumpMode"];
54 [defaults synchronize];
55
56 [TestFlight passCheckpoint:@"Unlocked Jump Mode"];
57 }
58 } else if ((lastScore < 2500) && (score >= 2500)) 64 } else if ((lastScore < 2500) && (score >= 2500))
59 { 65 {
60 [self unschedule:@selector(randomlyAddObject:)]; 66 [self unschedule:@selector(randomlyAddObject:)];
61 [self schedule:@selector(randomlyAddObject:) interval:0.8f]; 67 [self schedule:@selector(randomlyAddObject:) interval:0.8f];
62 addSpeed = 0.8f; 68 addSpeed = 0.8f;
69 } else if ((lastScore < 2000) && (score >= 2000))
70 {
71 [[ClassicGameMode info] setStar:1 withMessage:@"Get 2000 points"];
63 } else if ((lastScore < 1500) && (score >= 1500)) 72 } else if ((lastScore < 1500) && (score >= 1500))
64 { 73 {
65 [self unschedule:@selector(randomlyAddObject:)]; 74 [self unschedule:@selector(randomlyAddObject:)];
@@ -70,6 +79,8 @@
70 [self unschedule:@selector(randomlyAddObject:)]; 79 [self unschedule:@selector(randomlyAddObject:)];
71 [self schedule:@selector(randomlyAddObject:) interval:1.0f]; 80 [self schedule:@selector(randomlyAddObject:) interval:1.0f];
72 addSpeed = 1.0f; 81 addSpeed = 1.0f;
82
83 [[ClassicGameMode info] setStar:0 withMessage:@"Get 500 points"];
73 } else if ((lastScore < 150) && (score >= 150)) 84 } else if ((lastScore < 150) && (score >= 150))
74 { 85 {
75 [self unschedule:@selector(randomlyAddObject:)]; 86 [self unschedule:@selector(randomlyAddObject:)];
@@ -83,6 +94,7 @@
83{ 94{
84 FallingObject* object; 95 FallingObject* object;
85 int oneuppercent = 98 - (lives == 1 ? 1 : 0); 96 int oneuppercent = 98 - (lives == 1 ? 1 : 0);
97 int recipeIdentifier;
86 98
87 if (score < 1000) 99 if (score < 1000)
88 { 100 {
@@ -90,31 +102,33 @@
90 102
91 if (randomval < 65) 103 if (randomval < 65)
92 { 104 {
93 object = [[Cherry alloc] init]; 105 recipeIdentifier = kCherryObject;
94 } else if (randomval < oneuppercent) 106 } else if (randomval < oneuppercent)
95 { 107 {
96 object = [[Bottle alloc] init]; 108 recipeIdentifier = kEnergyDrinkObject;
97 } else { 109 } else {
98 object = [[OneUp alloc] init]; 110 recipeIdentifier = kOneUpObject;
99 } 111 }
100 } else { 112 } else {
101 int randomval = arc4random()%100; 113 int randomval = arc4random()%100;
102 114
103 if (randomval < 40) 115 if (randomval < 40)
104 { 116 {
105 object = [[Cherry alloc] init]; 117 recipeIdentifier = kCherryObject;
106 } else if (randomval < 70) 118 } else if (randomval < 70)
107 { 119 {
108 object = [[Rock alloc] init]; 120 recipeIdentifier = kRockObject;
109 } else if (randomval < oneuppercent) 121 } else if (randomval < oneuppercent)
110 { 122 {
111 object = [[Bottle alloc] init]; 123 recipeIdentifier = kEnergyDrinkObject;
112 } else { 124 } else {
113 object = [[OneUp alloc] init]; 125 recipeIdentifier = kOneUpObject;
114 } 126 }
115 } 127 }
116 128
117 int objectX = arc4random()%448+16; 129 int objectX = arc4random()%448+16;
130 object = [[objectFactory buildFallingObjectWithRecipeIdentifier:recipeIdentifier] retain];
131 object.delegate = self;
118 object.sprite.position = ccp(objectX, 360); 132 object.sprite.position = ccp(objectX, 360);
119 object.sprite.scale = 1; 133 object.sprite.scale = 1;
120 [self addChild:object.sprite]; 134 [self addChild:object.sprite];
@@ -126,8 +140,8 @@
126 { 140 {
127 if (arc4random() % 100 > 80) 141 if (arc4random() % 100 > 80)
128 { 142 {
129 object = [[Rock alloc] init]; 143 object = [[objectFactory buildFallingObjectWithRecipeIdentifier:kRockObject] retain];
130 144 object.delegate = self;
131 objectX = arc4random()%448+16; 145 objectX = arc4random()%448+16;
132 object.sprite.position = ccp(objectX, 360); 146 object.sprite.position = ccp(objectX, 360);
133 object.sprite.scale = 1; 147 object.sprite.scale = 1;
@@ -142,8 +156,8 @@
142 { 156 {
143 if (arc4random() % 100 > 80) 157 if (arc4random() % 100 > 80)
144 { 158 {
145 object = [[Rock alloc] init]; 159 object = [[objectFactory buildFallingObjectWithRecipeIdentifier:kRockObject] retain];
146 160 object.delegate = self;
147 objectX = arc4random()%448+16; 161 objectX = arc4random()%448+16;
148 object.sprite.position = ccp(objectX, 360); 162 object.sprite.position = ccp(objectX, 360);
149 object.sprite.scale = 1; 163 object.sprite.scale = 1;
@@ -166,6 +180,11 @@
166 [self addChild:backgroundImage z:-1]; 180 [self addChild:backgroundImage z:-1];
167 181
168 addSpeed = 2.5f; 182 addSpeed = 2.5f;
183
184 [objectFactory createRecipeWithIdentifier:kCherryObject spriteFilename:@"cherry.png" weight:5];
185 [objectFactory createRecipeWithIdentifier:kEnergyDrinkObject spriteFilename:@"bottle.png" weight:6];
186 [objectFactory createRecipeWithIdentifier:kOneUpObject spriteFilename:@"oneup.png" weight:10];
187 [objectFactory createRecipeWithIdentifier:kRockObject spriteFilename:@"rock.png" weight:7];
169 } 188 }
170 189
171 return self; 190 return self;
@@ -178,4 +197,34 @@
178 [self schedule:@selector(randomlyAddObject:) interval:addSpeed]; 197 [self schedule:@selector(randomlyAddObject:) interval:addSpeed];
179} 198}
180 199
200- (void)didCatchItem:(FallingObject *)item
201{
202 if (item.objectType == kCherryObject)
203 {
204 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]];
205 self.score += 10;
206 } else if (item.objectType == kEnergyDrinkObject)
207 {
208 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]];
209 self.score += 25;
210 } else if (item.objectType == kOneUpObject)
211 {
212 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]];
213 self.lives++;
214 } else if (item.objectType == kRockObject)
215 {
216 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]];
217 self.lives--;
218 }
219}
220
221- (void)didMissItem:(FallingObject *)item
222{
223 if ((item.objectType == kCherryObject) || (item.objectType == kEnergyDrinkObject))
224 {
225 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]];
226 self.lives--;
227 }
228}
229
181@end 230@end
diff --git a/Classes/FallingObject.h b/Classes/FallingObject.h index 6cb0c14..d9406d5 100755 --- a/Classes/FallingObject.h +++ b/Classes/FallingObject.h
@@ -15,14 +15,16 @@
15 int weight; 15 int weight;
16 id<FallingObjectDelegate> delegate; 16 id<FallingObjectDelegate> delegate;
17 BOOL flags[4]; 17 BOOL flags[4];
18 int objectType;
18} 19}
19 20
20@property (readonly) CCSprite* sprite; 21@property (readonly) CCSprite* sprite;
21@property (readonly) int weight; 22@property (readonly) int weight;
23@property (readonly) int objectType;
22@property (nonatomic,retain) id<FallingObjectDelegate> delegate; 24@property (nonatomic,retain) id<FallingObjectDelegate> delegate;
23- (id)init; 25- (id)initWithSpriteFilename:(NSString*)filename weight:(int)weight objectType:(int)objectType;
24- (BOOL)tick; 26- (BOOL)tick;
25- (void)collideWithCart; 27- (BOOL)flag:(int)flag;
26- (void)collideWithFloor; 28- (void)setFlag:(int)flag withValue:(BOOL)value;
27 29
28@end 30@end
diff --git a/Classes/FallingObject.m b/Classes/FallingObject.m index 85ea902..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,14 +81,14 @@
83 return NO; 81 return NO;
84} 82}
85 83
86- (void)collideWithCart 84- (BOOL)flag:(int)flag
87{ 85{
88 86 return flags[flag];
89} 87}
90 88
91- (void)collideWithFloor 89- (void)setFlag:(int)flag withValue:(BOOL)value
92{ 90{
93 91 flags[flag] = value;
94} 92}
95 93
96- (void)dealloc 94- (void)dealloc
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 @@
1//
2// FallingObjectFactory.h
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 <Foundation/Foundation.h>
10#import "FallingObject.h"
11
12@interface FallingObjectFactory : NSObject {
13 NSMutableDictionary* recipes;
14}
15
16- (id)init;
17- (void)createRecipeWithIdentifier:(int)identifier spriteFilename:(NSString*)filename weight:(int)weight;
18- (FallingObject*)buildFallingObjectWithRecipeIdentifier:(int)identifier;
19
20@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 @@
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
diff --git a/Classes/GameMode.h b/Classes/GameMode.h index 2fcf275..e208d49 100644 --- a/Classes/GameMode.h +++ b/Classes/GameMode.h
@@ -8,6 +8,8 @@
8 8
9#import "CCLayer.h" 9#import "CCLayer.h"
10#import "Cart.h" 10#import "Cart.h"
11#import "FallingObjectFactory.h"
12#import "GameModeInfo.h"
11#import <CoreMotion/CoreMotion.h> 13#import <CoreMotion/CoreMotion.h>
12 14
13#define GAME_SCENE 436 15#define GAME_SCENE 436
@@ -19,6 +21,7 @@
19 int lives; 21 int lives;
20 int pointMultiplier; 22 int pointMultiplier;
21 Cart* cart; 23 Cart* cart;
24 FallingObjectFactory* objectFactory;
22 25
23 CCLayerColor* shadedLayer; 26 CCLayerColor* shadedLayer;
24 CCLayer* pauseLayer; 27 CCLayer* pauseLayer;
@@ -40,7 +43,6 @@
40@property (nonatomic,assign) int lives; 43@property (nonatomic,assign) int lives;
41@property (nonatomic,assign) int pointMultiplier; 44@property (nonatomic,assign) int pointMultiplier;
42@property (readonly) BOOL isPaused; 45@property (readonly) BOOL isPaused;
43+ (CCScene*)scene;
44- (void)tick:(ccTime)dt; 46- (void)tick:(ccTime)dt;
45- (BOOL)canPause; 47- (BOOL)canPause;
46- (void)pause; 48- (void)pause;
@@ -48,6 +50,7 @@
48- (void)mainmenu; 50- (void)mainmenu;
49- (void)scheduleDelayedAction:(void(^)(void))delayedAction delay:(float)delay; 51- (void)scheduleDelayedAction:(void(^)(void))delayedAction delay:(float)delay;
50- (void)runDelayedAction; 52- (void)runDelayedAction;
53+ (GameModeInfo*)info;
51- (void)setPitch:(double)m_pitch; 54- (void)setPitch:(double)m_pitch;
52 55
53@end 56@end
diff --git a/Classes/GameMode.m b/Classes/GameMode.m index e45ddfe..49d0053 100644 --- a/Classes/GameMode.m +++ b/Classes/GameMode.m
@@ -14,19 +14,6 @@
14 14
15@synthesize cart, score, lives, isPaused, pointMultiplier; 15@synthesize cart, score, lives, isPaused, pointMultiplier;
16 16
17+ (CCScene*)scene
18{
19 CCScene* scene = [CCScene node];
20
21 GameMode* layer = [self node];
22 layer.tag = GAME_LAYER;
23 [scene addChild:layer];
24
25 scene.tag = GAME_SCENE;
26
27 return scene;
28}
29
30- (id)init 17- (id)init
31{ 18{
32 self = [super init]; 19 self = [super init];
@@ -52,6 +39,8 @@
52 score = 0; 39 score = 0;
53 lives = 3; 40 lives = 3;
54 pointMultiplier = 1; 41 pointMultiplier = 1;
42
43 objectFactory = [[FallingObjectFactory alloc] init];
55 44
56 if ([self canPause]) 45 if ([self canPause])
57 { 46 {
@@ -259,10 +248,17 @@
259 } 248 }
260} 249}
261 250
251+ (GameModeInfo*)info
252{
253 [NSException raise:@"Unimplemented method" format:@"Method -info of GameMode subclasses must be overridden"];
254
255 return nil;
256}
257
262- (void)setPitch:(double)m_pitch 258- (void)setPitch:(double)m_pitch
263{ 259{
264 pitch = m_pitch; 260 pitch = m_pitch;
265 261
266 [cart deviceDidRotate:pitch]; 262 [cart deviceDidRotate:pitch];
267} 263}
268 264
diff --git a/Classes/GameModeInfo.h b/Classes/GameModeInfo.h new file mode 100644 index 0000000..7d60645 --- /dev/null +++ b/Classes/GameModeInfo.h
@@ -0,0 +1,38 @@
1//
2// GameModeInfo.h
3// Cartographic
4//
5// Created by Starla Insigna on 11/28/11.
6// Copyright (c) 2011 Four Island. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10#import "cocos2d.h"
11
12@interface GameModeInfo : NSObject {
13 NSString* name;
14 NSString* location;
15 BOOL* stars;
16 int numOfStars;
17 BOOL unlocked;
18 UIImage* image;
19 NSString* unlockCondition;
20 Class gameClass;
21 NSString* globalHighscoreKey;
22}
23
24@property (readonly) NSString* name;
25@property (readonly) NSString* location;
26@property (readonly) int numOfStars;
27@property (readonly) UIImage* image;
28@property (readonly) BOOL unlocked;
29@property (readonly) NSString* globalHighscoreKey;
30- (id)initWithName:(NSString*)m_name location:(NSString*)m_location numOfStars:(int)m_numOfStars imageFilename:(NSString*)m_imageFilename unlocked:(BOOL)m_unlocked gameClass:(Class)m_gameClass globalHighscoreKey:(NSString*)m_globalHighscoreKey;
31- (void)setStar:(int)star_id withMessage:(NSString*)message;
32- (BOOL)star:(int)star_id;
33- (int)starsCollected;
34- (CCScene*)scene;
35- (void)unlock;
36- (void)dealloc;
37
38@end
diff --git a/Classes/GameModeInfo.m b/Classes/GameModeInfo.m new file mode 100644 index 0000000..1f85978 --- /dev/null +++ b/Classes/GameModeInfo.m
@@ -0,0 +1,126 @@
1//
2// GameModeInfo.m
3// Cartographic
4//
5// Created by Starla Insigna on 11/28/11.
6// Copyright (c) 2011 Four Island. All rights reserved.
7//
8
9#import "GameModeInfo.h"
10#import "CCNotifications.h"
11#import "GameMode.h"
12#import "GameModeManager.h"
13#import "TestFlight.h"
14
15@implementation GameModeInfo
16
17@synthesize name, location, numOfStars, image, unlocked, globalHighscoreKey;
18
19- (id)initWithName:(NSString*)m_name location:(NSString*)m_location numOfStars:(int)m_numOfStars imageFilename:(NSString*)m_imageFilename unlocked:(BOOL)m_unlocked gameClass:(Class)m_gameClass globalHighscoreKey:(NSString*)m_globalHighscoreKey
20{
21 self = [super init];
22
23 if (nil != self)
24 {
25 name = m_name;
26 location = m_location;
27 numOfStars = m_numOfStars;
28 image = [[UIImage alloc] initWithContentsOfFile:m_imageFilename];
29 globalHighscoreKey = m_globalHighscoreKey;
30
31 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
32 unlocked = [defaults boolForKey:[NSString stringWithFormat:@"gameModeUnlocked-%@", name]];
33 if (!unlocked)
34 {
35 unlocked = m_unlocked;
36 }
37
38 stars = (BOOL*) calloc(numOfStars, sizeof(BOOL));
39 for (int i=0; i<numOfStars; i++)
40 {
41 stars[i] = [defaults boolForKey:[NSString stringWithFormat:@"gameModeStar-%@-%d", name, i]];
42 }
43
44 if ([m_gameClass isSubclassOfClass:[GameMode class]])
45 {
46 gameClass = m_gameClass;
47 } else {
48 [NSException raise:@"Invalid gameClass value" format:@"gameClass must be a subclass of GameMode"];
49 }
50 }
51
52 return self;
53}
54
55- (void)setStar:(int)star_id withMessage:(NSString*)message
56{
57 if (!stars[star_id])
58 {
59 stars[star_id] = YES;
60
61 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
62 [defaults setBool:YES forKey:[NSString stringWithFormat:@"gameModeStar-%@-%d", name, star_id]];
63
64 [[CCNotifications sharedManager] addWithTitle:@"Star Achieved!" message:message image:[NSString stringWithFormat:@"star_%d.png", star_id+1]];
65
66 [GameModeManager sharedInstance].stars++;
67 }
68}
69
70- (BOOL)star:(int)star_id
71{
72 return stars[star_id];
73}
74
75- (int)starsCollected
76{
77 int result = 0;
78
79 for (int i=0; i<numOfStars; i++)
80 {
81 if (stars[i])
82 {
83 result++;
84 }
85 }
86
87 return result;
88}
89
90- (CCScene*)scene
91{
92 CCScene* scene = [CCScene node];
93
94 GameMode* layer = [[((GameMode*) [gameClass alloc]) init] autorelease];
95 layer.tag = GAME_LAYER;
96 [scene addChild:layer];
97
98 scene.tag = GAME_SCENE;
99
100 return scene;
101}
102
103- (void)unlock
104{
105 if (!unlocked)
106 {
107 unlocked = YES;
108
109 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
110 [defaults setBool:YES forKey:[NSString stringWithFormat:@"gameModeUnlocked-%@", name]];
111
112 CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:image];
113 [[CCNotifications sharedManager] addWithTitle:name message:@"You've unlocked a new game mode!" texture:texture];
114 [texture release];
115
116 [TestFlight passCheckpoint:[NSString stringWithFormat:@"Unlocked %@ Mode", name]];
117 }
118}
119
120- (void)dealloc
121{
122 free(stars);
123 [super dealloc];
124}
125
126@end
diff --git a/Classes/GameModeManager.h b/Classes/GameModeManager.h new file mode 100644 index 0000000..fdaae60 --- /dev/null +++ b/Classes/GameModeManager.h
@@ -0,0 +1,20 @@
1//
2// GameModeManager.h
3// Cartographic
4//
5// Created by Starla Insigna on 11/29/11.
6// Copyright (c) 2011 Four Island. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10
11@interface GameModeManager : NSObject {
12 NSArray* gameModes;
13 int stars;
14}
15
16@property (readonly) NSArray* gameModes;
17@property (assign) int stars;
18+ (GameModeManager*)sharedInstance;
19
20@end
diff --git a/Classes/GameModeManager.m b/Classes/GameModeManager.m new file mode 100644 index 0000000..d7cd21e --- /dev/null +++ b/Classes/GameModeManager.m
@@ -0,0 +1,68 @@
1//
2// GameModeManager.m
3// Cartographic
4//
5// Created by Starla Insigna on 11/29/11.
6// Copyright (c) 2011 Four Island. All rights reserved.
7//
8
9#import "GameModeManager.h"
10#import "GameModeInfo.h"
11#import "TutorialMode.h"
12#import "ClassicGameMode.h"
13#import "JumpGameMode.h"
14
15@implementation GameModeManager
16
17@synthesize gameModes;
18
19static GameModeManager* sharedInstance = nil;
20
21+ (GameModeManager*)sharedInstance
22{
23 if (sharedInstance == nil)
24 {
25 sharedInstance = [[GameModeManager alloc] init];
26 }
27
28 return sharedInstance;
29}
30
31- (id)init
32{
33 self = [super init];
34
35 if (nil != self)
36 {
37 gameModes = [[NSArray alloc] initWithObjects:
38 [TutorialMode info],
39 [ClassicGameMode info],
40 [JumpGameMode info],
41 nil];
42
43 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
44 stars = [defaults integerForKey:@"stars"];
45 }
46
47 return self;
48}
49
50- (void)setStars:(int)m_stars
51{
52 if (stars != m_stars)
53 {
54 stars = m_stars;
55
56 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
57 [defaults setInteger:m_stars forKey:@"stars"];
58
59 // Here, unlock game modes that have reached enough stars
60 }
61}
62
63- (int)stars
64{
65 return stars;
66}
67
68@end
diff --git a/Classes/GameModeSelection.h b/Classes/GameModeSelection.h index bdb38fb..ec6d5ad 100644 --- a/Classes/GameModeSelection.h +++ b/Classes/GameModeSelection.h
@@ -8,23 +8,17 @@
8 8
9#import "cocos2d.h" 9#import "cocos2d.h"
10#import "GameModeSelectionDelegate.h" 10#import "GameModeSelectionDelegate.h"
11#import "GameModeInfo.h"
11 12
12@interface GameModeSelection : CCMenuItem { 13@interface GameModeSelection : CCMenuItem {
13 NSString* name; 14 GameModeInfo* gameMode;
14 NSString* location;
15 BOOL unlocked;
16 NSString* unlockCondition;
17 id<GameModeSelectionDelegate> delegate; 15 id<GameModeSelectionDelegate> delegate;
18} 16}
19 17
20@property (readonly) NSString* name; 18@property (readonly) GameModeInfo* gameMode;
21@property (readonly) NSString* location;
22@property (readonly) BOOL unlocked;
23@property (nonatomic,retain) id<GameModeSelectionDelegate> delegate; 19@property (nonatomic,retain) id<GameModeSelectionDelegate> delegate;
24+ (id)selectionWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked; 20+ (id)selectionWithGameModeInfo:(GameModeInfo*)m_gameMode;
25+ (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition; 21- (id)initWithGameModeInfo:(GameModeInfo*)m_gameMode;
26- (id)initWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked;
27- (id)initWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition;
28- (void)buttonTapped; 22- (void)buttonTapped;
29 23
30@end 24@end
diff --git a/Classes/GameModeSelection.m b/Classes/GameModeSelection.m index 40981b1..ea5f45b 100644 --- a/Classes/GameModeSelection.m +++ b/Classes/GameModeSelection.m
@@ -13,42 +13,34 @@
13 13
14@implementation GameModeSelection 14@implementation GameModeSelection
15 15
16@synthesize name, location, unlocked, delegate; 16@synthesize gameMode, delegate;
17 17
18+ (id)selectionWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked 18+ (id)selectionWithGameModeInfo:(GameModeInfo*)m_gameMode
19{ 19{
20 return [[[GameModeSelection alloc] initWithName:name location:location filename:filename unlocked:unlocked] autorelease]; 20 return [[[GameModeSelection alloc] initWithGameModeInfo:m_gameMode] autorelease];
21} 21}
22 22
23+ (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition 23- (id)initWithGameModeInfo:(GameModeInfo*)m_gameMode
24{
25 return [[[GameModeSelection alloc] initWithName:name location:location filename:filename unlockCondition:unlockCondition] autorelease];
26}
27
28- (id)initWithName:(NSString*)m_name location:(NSString*)m_location filename:(NSString*)filename unlocked:(BOOL)m_unlocked;
29{ 24{
30 self = [super initWithTarget:nil selector:nil]; 25 self = [super initWithTarget:nil selector:nil];
31 26
32 if (nil != self) 27 if (nil != self)
33 { 28 {
29 if (!m_gameMode.unlocked)
30 {
31 @throw [NSException exceptionWithName:NSInvalidArgumentException
32 reason:@"Game mode must be unlocked to appear on selection screen"
33 userInfo:nil];
34 }
35
34 self.anchorPoint = CGPointMake(0.5f, 0.5f); 36 self.anchorPoint = CGPointMake(0.5f, 0.5f);
35 37
36 name = m_name; 38 gameMode = m_gameMode;
37 location = m_location;
38 unlocked = m_unlocked;
39 39
40 contentSize_ = CGSizeMake(128, 320); 40 contentSize_ = CGSizeMake(128, 320);
41 41
42 NSString* filenameMod; 42 NSString* name = gameMode.name;
43 43 NSString* location = gameMode.location;
44 if (unlocked)
45 {
46 filenameMod = [NSString stringWithFormat:@"%@-unlocked", filename];
47 } else {
48 filenameMod = [NSString stringWithFormat:@"%@-locked", filename];
49 name = [@"" stringByPaddingToLength:name.length withString:@"?" startingAtIndex:0];
50 location = [@"" stringByPaddingToLength:location.length withString:@"?" startingAtIndex:0];
51 }
52 44
53 // First, create the frame that we will put the level picture inside 45 // First, create the frame that we will put the level picture inside
54 CGImageRef framestuff = [[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"framestuff" ofType:@"png"]] CGImage]; 46 CGImageRef framestuff = [[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"framestuff" ofType:@"png"]] CGImage];
@@ -93,7 +85,7 @@
93 UIImage* selectionBackground = UIGraphicsGetImageFromCurrentImageContext(); 85 UIImage* selectionBackground = UIGraphicsGetImageFromCurrentImageContext();
94 86
95 // Now we want to put the level image inside the frame without messing up the frame itself 87 // Now we want to put the level image inside the frame without messing up the frame itself
96 UIImage* innerPicture = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:filename ofType:@"png"]]; 88 UIImage* innerPicture = gameMode.image;
97 CGContextClipToMask(context, CGRectMake(0, 0, boxSize.width, boxSize.height), [[selectionBackground opaqueMaskFromWhiteImage] CGImage]); 89 CGContextClipToMask(context, CGRectMake(0, 0, boxSize.width, boxSize.height), [[selectionBackground opaqueMaskFromWhiteImage] CGImage]);
98 [innerPicture drawInRect:CGRectMake(6, 6, 128, 128)]; 90 [innerPicture drawInRect:CGRectMake(6, 6, 128, 128)];
99 selectionBackground = UIGraphicsGetImageFromCurrentImageContext(); 91 selectionBackground = UIGraphicsGetImageFromCurrentImageContext();
@@ -104,26 +96,13 @@
104 context = UIGraphicsGetCurrentContext(); 96 context = UIGraphicsGetCurrentContext();
105 CGContextSaveGState(context); 97 CGContextSaveGState(context);
106 98
107 if (unlocked) 99 CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f);
108 { 100 [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height)];
109 CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f);
110 [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height)];
111 } else {
112 // Draw the picture in grayscale if the level has not yet been unlocked
113 CGContextClipToMask(context, CGRectMake(10, 0, boxSize.width, boxSize.height), [selectionBackground CGImage]);
114 CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
115 CGContextFillRect(context, CGRectMake(10, 0, boxSize.width, boxSize.height));
116 CGContextRestoreGState(context);
117
118 CGContextSaveGState(context);
119 CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f);
120 [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height) blendMode:kCGBlendModeLuminosity alpha:1.0];
121 }
122 101
123 CGContextRestoreGState(context); 102 CGContextRestoreGState(context);
124 CGImageRef pictureRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; 103 CGImageRef pictureRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage];
125 104
126 CCSprite* picture = [CCSprite spriteWithCGImage:pictureRef key:[NSString stringWithFormat:@"gms-%@", filenameMod]]; 105 CCSprite* picture = [CCSprite spriteWithCGImage:pictureRef key:[NSString stringWithFormat:@"gms-%@", name]];
127 106
128 // We're also going to need a "selected" image state for the button 107 // We're also going to need a "selected" image state for the button
129 CGContextSaveGState(context); 108 CGContextSaveGState(context);
@@ -133,7 +112,7 @@
133 CGContextRestoreGState(context); 112 CGContextRestoreGState(context);
134 CGImageRef selectedButtonRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; 113 CGImageRef selectedButtonRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage];
135 UIGraphicsEndImageContext(); 114 UIGraphicsEndImageContext();
136 CCSprite* selectedButton = [CCSprite spriteWithCGImage:selectedButtonRef key:[NSString stringWithFormat:@"gms-%@-selected", filenameMod]]; 115 CCSprite* selectedButton = [CCSprite spriteWithCGImage:selectedButtonRef key:[NSString stringWithFormat:@"gms-%@-selected", name]];
137 116
138 CCMenuItemSprite* pictureMenuItem = [CCMenuItemSprite itemFromNormalSprite:picture selectedSprite:selectedButton target:self selector:@selector(buttonTapped)]; 117 CCMenuItemSprite* pictureMenuItem = [CCMenuItemSprite itemFromNormalSprite:picture selectedSprite:selectedButton target:self selector:@selector(buttonTapped)];
139 NMPanelMenu* theMenu = [NMPanelMenu menuWithItems:pictureMenuItem, nil]; 118 NMPanelMenu* theMenu = [NMPanelMenu menuWithItems:pictureMenuItem, nil];
@@ -155,64 +134,42 @@
155 134
156 CGImageRef titleImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; 135 CGImageRef titleImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage];
157 UIGraphicsEndImageContext(); 136 UIGraphicsEndImageContext();
158 CCSprite* titleSprite = [CCSprite spriteWithCGImage:titleImage key:[NSString stringWithFormat:@"gms-%@-title", filenameMod]]; 137 CCSprite* titleSprite = [CCSprite spriteWithCGImage:titleImage key:[NSString stringWithFormat:@"gms-%@-title", name]];
159 titleSprite.position = ccp(-10, (boxSize.height)/2+(combinedTitleSize.height)/2); 138 titleSprite.position = ccp(-10, (boxSize.height)/2+(combinedTitleSize.height)/2);
160 [self addChild:titleSprite]; 139 [self addChild:titleSprite];
161 140
162 if (unlocked) 141 Highscore* localHighscore = [Highscore localHighscoreForGameMode:name];
142
143 if (localHighscore != nil)
163 { 144 {
164 Highscore* localHighscore = [Highscore localHighscoreForGameMode:name]; 145 // Render the highscore label
146 NSString* highscoreString = [NSString stringWithFormat:@"Highscore: %d", localHighscore.score];
147 UIFont* highscoreFont = [UIFont fontWithName:@"AmericanTypewriter" size:16.0f];
148 CGSize highscoreSize = [highscoreString sizeWithFont:highscoreFont];
149
150 UIGraphicsBeginImageContext(CGSizeMake(highscoreSize.width+10, highscoreSize.height+10));
151 CGContextRef context = UIGraphicsGetCurrentContext();
152 CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f);
153 [highscoreString drawInRect:CGRectMake(10, 0, highscoreSize.width, highscoreSize.height) withFont:highscoreFont];
165 154
166 if (localHighscore != nil) 155 CGImageRef highscoreImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage];
167 { 156 UIGraphicsEndImageContext();
168 // Render the highscore label 157 CCSprite* highscoreSprite = [CCSprite spriteWithCGImage:highscoreImage key:[NSString stringWithFormat:@"gms-%@-highscore-%d", name, localHighscore.score]];
169 NSString* highscoreString = [NSString stringWithFormat:@"Highscore: %d", localHighscore.score]; 158 highscoreSprite.position = ccp(-5, 0-64-(highscoreSize.height)/2-10);
170 UIFont* highscoreFont = [UIFont fontWithName:@"AmericanTypewriter" size:16.0f]; 159 [self addChild:highscoreSprite];
171 CGSize highscoreSize = [highscoreString sizeWithFont:highscoreFont];
172
173 UIGraphicsBeginImageContext(CGSizeMake(highscoreSize.width+10, highscoreSize.height+10));
174 CGContextRef context = UIGraphicsGetCurrentContext();
175 CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f);
176 [highscoreString drawInRect:CGRectMake(10, 0, highscoreSize.width, highscoreSize.height) withFont:highscoreFont];
177
178 CGImageRef highscoreImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage];
179 UIGraphicsEndImageContext();
180 CCSprite* highscoreSprite = [CCSprite spriteWithCGImage:highscoreImage key:[NSString stringWithFormat:@"gms-%@-highscore-%d", filename, localHighscore.score]];
181 highscoreSprite.position = ccp(-5, 0-64-(highscoreSize.height)/2-10);
182 [self addChild:highscoreSprite];
183 }
184 } 160 }
185 } 161 }
186 162
187 return self; 163 return self;
188} 164}
189 165
190- (id)initWithName:(NSString *)m_name location:(NSString *)m_location filename:(NSString *)m_filename unlockCondition:(NSString*)m_unlockCondition
191{
192 self = [self initWithName:m_name location:m_location filename:m_filename unlocked:NO];
193
194 if (nil != self)
195 {
196 unlockCondition = m_unlockCondition;
197 }
198
199 return self;
200}
201
202- (void)buttonTapped 166- (void)buttonTapped
203{ 167{
204 if (unlocked) 168 if (delegate != nil)
205 { 169 {
206 if (delegate != nil) 170 [delegate didSelectGameMode:self];
207 {
208 [delegate didSelectGameMode:self];
209 } else {
210 NSLog(@"I don't have a GameModeSelectionDelegate to call for some reason...");
211 }
212 } else { 171 } else {
213 UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"To unlock this game mode:" message:unlockCondition delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; 172 NSLog(@"I don't have a GameModeSelectionDelegate to call for some reason...");
214 [alertView show];
215 [alertView release];
216 } 173 }
217} 174}
218 175
diff --git a/Classes/GameModeSelectionLayer.m b/Classes/GameModeSelectionLayer.m index 03af89d..4e51357 100644 --- a/Classes/GameModeSelectionLayer.m +++ b/Classes/GameModeSelectionLayer.m
@@ -11,11 +11,10 @@
11#import <sqlite3.h> 11#import <sqlite3.h>
12#import "Cart_CollectAppDelegate.h" 12#import "Cart_CollectAppDelegate.h"
13#import "MainMenuLayer.h" 13#import "MainMenuLayer.h"
14#import "TutorialMode.h"
15#import "ClassicGameMode.h"
16#import "NMPanelMenu.h" 14#import "NMPanelMenu.h"
17#import "JumpGameMode.h"
18#import "ZoomFadeTransition.h" 15#import "ZoomFadeTransition.h"
16#import "GameModeInfo.h"
17#import "GameModeManager.h"
19 18
20@implementation GameModeSelectionLayer 19@implementation GameModeSelectionLayer
21 20
@@ -44,31 +43,14 @@
44 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; 43 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
45 gameModes = [[NSMutableArray alloc] init]; 44 gameModes = [[NSMutableArray alloc] init];
46 45
47 GameModeSelection* tutorialSelection = [GameModeSelection selectionWithName:@"Tutorial" location:@"Florence" filename:@"florence" unlocked:YES]; 46 for (GameModeInfo* info in [[GameModeManager sharedInstance] gameModes])
48 [gameModes addObject:tutorialSelection];
49
50 GameModeSelection* collectSelection;
51
52 collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" unlocked:YES];
53/* if ([defaults boolForKey:@"hasDoneTutorial"])
54 {
55 collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" unlocked:YES];
56 } else {
57 collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" unlockCondition:@"Beat the tutorial!"];
58 }*/
59
60 [gameModes addObject:collectSelection];
61
62 GameModeSelection* jumpSelection;
63 jumpSelection = [GameModeSelection selectionWithName:@"Jump" location:@"Venice" filename:@"venice" unlocked:YES];
64/* if ([defaults boolForKey:@"unlockedJumpMode"])
65 { 47 {
66 jumpSelection = [GameModeSelection selectionWithName:@"Jump" location:@"Venice" filename:@"venice" unlocked:YES]; 48 if (info.unlocked)
67 } else { 49 {
68 jumpSelection = [GameModeSelection selectionWithName:@"Jump" location:@"Venice" filename:@"venice" unlockCondition:@"Get 3000 points in Collect!"]; 50 GameModeSelection* selection = [GameModeSelection selectionWithGameModeInfo:info];
69 }*/ 51 [gameModes addObject:selection];
70 52 }
71 [gameModes addObject:jumpSelection]; 53 }
72 54
73 CCMenu* menu = [CCMenu menuWithItems:nil]; 55 CCMenu* menu = [CCMenu menuWithItems:nil];
74 float onePanelWide = 128; 56 float onePanelWide = 128;
@@ -132,24 +114,15 @@
132 [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; 114 [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]];
133} 115}
134 116
135- (void)didSelectGameMode:(GameModeSelection *)gameMode 117- (void)didSelectGameMode:(GameModeSelection *)selection
136{ 118{
137 [scrollView setScrollEnabled:NO]; 119 [scrollView setScrollEnabled:NO];
138 [pageControl removeFromSuperview]; 120 [pageControl removeFromSuperview];
139 121
140 CGPoint opp = [scrollView convertPoint:gameMode.position toView:[[CCDirector sharedDirector] openGLView]]; 122 CGPoint opp = [scrollView convertPoint:selection.position toView:[[CCDirector sharedDirector] openGLView]];
141 CGPoint endPosition = ccp(0-(opp.x+158), opp.y); 123 CGPoint endPosition = ccp(0-(opp.x+158), opp.y);
142 124
143 if ([gameMode.name isEqual:@"Tutorial"]) 125 [[CCDirector sharedDirector] replaceScene:[ZoomFadeTransition transitionWithDuration:5.0f scene:[selection.gameMode scene] position:endPosition]];
144 {
145 [[CCDirector sharedDirector] replaceScene:[ZoomFadeTransition transitionWithDuration:5.0f scene:[TutorialMode scene] position:endPosition]];
146 } else if ([gameMode.name isEqual:@"Collect"])
147 {
148 [[CCDirector sharedDirector] replaceScene:[ZoomFadeTransition transitionWithDuration:5.0f scene:[ClassicGameMode scene] position:endPosition]];
149 } else if ([gameMode.name isEqual:@"Jump"])
150 {
151 [[CCDirector sharedDirector] replaceScene:[ZoomFadeTransition transitionWithDuration:5.0f scene:[JumpGameMode scene] position:endPosition]];
152 }
153} 126}
154 127
155@end 128@end
diff --git a/Classes/GameOverScene.h b/Classes/GameOverScene.h index f596211..5987c20 100755 --- a/Classes/GameOverScene.h +++ b/Classes/GameOverScene.h
@@ -8,6 +8,7 @@
8 8
9#import <Foundation/Foundation.h> 9#import <Foundation/Foundation.h>
10#import "cocos2d.h" 10#import "cocos2d.h"
11#import "GameModeInfo.h"
11 12
12@interface GameOverScene : CCScene <UITextFieldDelegate, UIAlertViewDelegate> { 13@interface GameOverScene : CCScene <UITextFieldDelegate, UIAlertViewDelegate> {
13 CCLayer* theLayer; 14 CCLayer* theLayer;
@@ -19,12 +20,12 @@
19 UIButton* backButton; 20 UIButton* backButton;
20 UIButton* playButton; 21 UIButton* playButton;
21 int score; 22 int score;
22 NSString* gameMode; 23 GameModeInfo* gameMode;
23 BOOL playAgain; 24 BOOL playAgain;
24} 25}
25 26
26+ (GameOverScene*)sceneWithScore:(int)score gameMode:(NSString*)gameMode; 27+ (GameOverScene*)sceneWithScore:(int)score gameMode:(GameModeInfo*)gameMode;
27- (id)initWithScore:(int)score gameMode:(NSString*)gameMode; 28- (id)initWithScore:(int)score gameMode:(GameModeInfo*)gameMode;
28- (void)newgame:(id)sender; 29- (void)newgame:(id)sender;
29- (void)submitScore; 30- (void)submitScore;
30- (void)exit; 31- (void)exit;
diff --git a/Classes/GameOverScene.m b/Classes/GameOverScene.m index a56aeac..07186c2 100755 --- a/Classes/GameOverScene.m +++ b/Classes/GameOverScene.m
@@ -11,17 +11,15 @@
11#import <sqlite3.h> 11#import <sqlite3.h>
12#import "cocoslive.h" 12#import "cocoslive.h"
13#import "MainMenuLayer.h" 13#import "MainMenuLayer.h"
14#import "ClassicGameMode.h"
15#import "JumpGameMode.h"
16 14
17@implementation GameOverScene 15@implementation GameOverScene
18 16
19+ (GameOverScene*)sceneWithScore:(int)score gameMode:(NSString*)gameMode 17+ (GameOverScene*)sceneWithScore:(int)score gameMode:(GameModeInfo*)gameMode
20{ 18{
21 return [[[GameOverScene alloc] initWithScore:score gameMode:gameMode] autorelease]; 19 return [[[GameOverScene alloc] initWithScore:score gameMode:gameMode] autorelease];
22} 20}
23 21
24- (id)initWithScore:(int)score2 gameMode:(NSString*)gameMode2 22- (id)initWithScore:(int)m_score gameMode:(GameModeInfo*)m_gameMode
25{ 23{
26 self = [super init]; 24 self = [super init];
27 25
@@ -37,8 +35,8 @@
37 backgroundImage.position = ccp(240, 160); 35 backgroundImage.position = ccp(240, 160);
38 [theLayer addChild:backgroundImage z:0]; 36 [theLayer addChild:backgroundImage z:0];
39 37
40 score = score2; 38 score = m_score;
41 gameMode = gameMode2; 39 gameMode = m_gameMode;
42 40
43 movingLayer = [[UIView alloc] initWithFrame:CGRectMake(0, -320, 480, 320)]; 41 movingLayer = [[UIView alloc] initWithFrame:CGRectMake(0, -320, 480, 320)];
44 movingLayer.backgroundColor = [UIColor clearColor]; 42 movingLayer.backgroundColor = [UIColor clearColor];
@@ -47,7 +45,7 @@
47 scoreField = [[UILabel alloc] initWithFrame:CGRectMake(205, 320-200, 0, 0)]; 45 scoreField = [[UILabel alloc] initWithFrame:CGRectMake(205, 320-200, 0, 0)];
48 [scoreField setFont:[UIFont systemFontOfSize:20.0f]]; 46 [scoreField setFont:[UIFont systemFontOfSize:20.0f]];
49 [scoreField setBackgroundColor:[UIColor clearColor]]; 47 [scoreField setBackgroundColor:[UIColor clearColor]];
50 [scoreField setText:[NSString stringWithFormat:@"%d", score2]]; 48 [scoreField setText:[NSString stringWithFormat:@"%d", score]];
51 CGSize labelSize = [scoreField.text sizeWithFont:scoreField.font constrainedToSize:CGSizeMake(160, 31) lineBreakMode:UILineBreakModeClip]; 49 CGSize labelSize = [scoreField.text sizeWithFont:scoreField.font constrainedToSize:CGSizeMake(160, 31) lineBreakMode:UILineBreakModeClip];
52 [scoreField setFrame:CGRectMake(scoreField.frame.origin.x, scoreField.frame.origin.y, labelSize.width, labelSize.height)]; 50 [scoreField setFrame:CGRectMake(scoreField.frame.origin.x, scoreField.frame.origin.y, labelSize.width, labelSize.height)];
53 [movingLayer addSubview:scoreField]; 51 [movingLayer addSubview:scoreField];
@@ -103,7 +101,7 @@
103 textField.enabled = NO; 101 textField.enabled = NO;
104 submitSwitch.enabled = NO; 102 submitSwitch.enabled = NO;
105 103
106 const char* sqlQuery = [[NSString stringWithFormat:@"INSERT INTO highscores (name, score, gameMode) VALUES (\"%@\",%d,\"%@\")", [textField text], score, gameMode] UTF8String]; 104 const char* sqlQuery = [[NSString stringWithFormat:@"INSERT INTO highscores (name, score, gameMode) VALUES (\"%@\",%d,\"%@\")", [textField text], score, gameMode.name] UTF8String];
107 sqlite3_stmt* compiled_statement; 105 sqlite3_stmt* compiled_statement;
108 106
109 if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) 107 if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK)
@@ -128,14 +126,7 @@
128 126
129 CLScoreServerPost* server = [[CLScoreServerPost alloc] initWithGameName:@"Cart Collect" gameKey:@"38f440a074b3264386455a36b2706d8f" delegate:self]; 127 CLScoreServerPost* server = [[CLScoreServerPost alloc] initWithGameName:@"Cart Collect" gameKey:@"38f440a074b3264386455a36b2706d8f" delegate:self];
130 NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; 128 NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
131 129 [dict setObject:gameMode.globalHighscoreKey forKey:@"cc_category"];
132 if ([gameMode isEqual:@"Collect"])
133 {
134 [dict setObject:@"Classic" forKey:@"cc_category"];
135 } else {
136 [dict setObject:gameMode forKey:@"cc_category"];
137 }
138
139 [dict setObject:[textField text] forKey:@"cc_playername"]; 130 [dict setObject:[textField text] forKey:@"cc_playername"];
140 [dict setObject:[NSNumber numberWithInt:score] forKey:@"cc_score"]; 131 [dict setObject:[NSNumber numberWithInt:score] forKey:@"cc_score"];
141 [server sendScore:dict]; 132 [server sendScore:dict];
@@ -224,13 +215,7 @@
224 215
225 if (playAgain) 216 if (playAgain)
226 { 217 {
227 if ([gameMode isEqual:@"Collect"]) 218 [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:3.0f scene:[gameMode scene] withColor:ccc3(0, 0, 0)]];
228 {
229 [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:3.0f scene:[ClassicGameMode scene] withColor:ccc3(0, 0, 0)]];
230 } else if ([gameMode isEqual:@"Jump"])
231 {
232 [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:3.0f scene:[JumpGameMode scene] withColor:ccc3(0, 0, 0)]];
233 }
234 } else { 219 } else {
235 [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; 220 [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]];
236 } 221 }
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 @@
7// 7//
8 8
9#import "GameMode.h" 9#import "GameMode.h"
10#import "FallingObjectDelegate.h"
10 11
11@class LedgeFactory; 12@class LedgeFactory;
12 13
13@interface JumpGameMode : GameMode <CCStandardTouchDelegate> { 14@interface JumpGameMode : GameMode <CCStandardTouchDelegate, FallingObjectDelegate> {
14 CCSprite* water; 15 CCSprite* water;
15 int waterTick; 16 int waterTick;
16 BOOL wave; 17 BOOL wave;
@@ -20,7 +21,7 @@
20 BOOL jump; 21 BOOL jump;
21 float expectedAngle; 22 float expectedAngle;
22 NSMutableSet* ledges; 23 NSMutableSet* ledges;
23 LedgeFactory* factory; 24 LedgeFactory* ledgeFactory;
24 int ledgeScrollSpeed; 25 int ledgeScrollSpeed;
25 float ledgeAccelerationRate; 26 float ledgeAccelerationRate;
26 float addSpeed; 27 float addSpeed;
diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index eb552a2..f3e690c 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m
@@ -9,12 +9,7 @@
9#import "JumpGameMode.h" 9#import "JumpGameMode.h"
10#import "SimpleAudioEngine.h" 10#import "SimpleAudioEngine.h"
11#import "FallingObject.h" 11#import "FallingObject.h"
12#import "Cherry.h"
13#import "Bottle.h"
14#import "OneUp.h"
15#import "Rock.h"
16#import "GameOverScene.h" 12#import "GameOverScene.h"
17#import "PointMultiplier.h"
18 13
19#define kMinimumGestureLength 25 14#define kMinimumGestureLength 25
20 15
@@ -46,6 +41,30 @@
46 41
47@implementation JumpGameMode 42@implementation JumpGameMode
48 43
44typedef enum {
45 kRockObject = 0,
46 kOneUpObject,
47 kPointMultiplierObject
48} FallingObjects;
49
50static GameModeInfo* info;
51
52+ (GameModeInfo*)info
53{
54 if (info == nil)
55 {
56 info = [[GameModeInfo alloc] initWithName:@"Jump"
57 location:@"Venice"
58 numOfStars:3
59 imageFilename:[[NSBundle mainBundle] pathForResource:@"venice" ofType:@"png"]
60 unlocked:YES
61 gameClass:[JumpGameMode class]
62 globalHighscoreKey:@"Jump"];
63 }
64
65 return info;
66}
67
49- (id)init 68- (id)init
50{ 69{
51 self = [super init]; 70 self = [super init];
@@ -69,9 +88,9 @@
69 waterTick = 0; 88 waterTick = 0;
70 wave = NO; 89 wave = NO;
71 90
72 factory = [[LedgeFactory alloc] init]; 91 ledgeFactory = [[LedgeFactory alloc] init];
73 ledges = [[NSMutableSet alloc] init]; 92 ledges = [[NSMutableSet alloc] init];
74 CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:6 height:2]]; 93 CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[ledgeFactory createLedgeWithWidth:6 height:2]];
75 CCSprite* ledge = [CCSprite spriteWithTexture:texture]; 94 CCSprite* ledge = [CCSprite spriteWithTexture:texture];
76 ledge.position = ccp(80, 32); 95 ledge.position = ccp(80, 32);
77 [self addChild:ledge]; 96 [self addChild:ledge];
@@ -79,7 +98,7 @@
79 [texture release]; 98 [texture release];
80 99
81 CCSprite* firstLedge = ledge; 100 CCSprite* firstLedge = ledge;
82 texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:10 height:2]]; 101 texture = [[CCTexture2D alloc] initWithImage:[ledgeFactory createLedgeWithWidth:10 height:2]];
83 ledge = [CCSprite spriteWithTexture:texture]; 102 ledge = [CCSprite spriteWithTexture:texture];
84 ledge.position = ccp(80 + firstLedge.boundingBox.size.width/2 + ledge.boundingBox.size.width/2+64, 32); 103 ledge.position = ccp(80 + firstLedge.boundingBox.size.width/2 + ledge.boundingBox.size.width/2+64, 32);
85 [self addChild:ledge]; 104 [self addChild:ledge];
@@ -89,6 +108,10 @@
89 ledgeScrollSpeed = 0; 108 ledgeScrollSpeed = 0;
90 ledgeAccelerationRate = 20.0f; 109 ledgeAccelerationRate = 20.0f;
91 addSpeed = 2.5f; 110 addSpeed = 2.5f;
111
112 [objectFactory createRecipeWithIdentifier:kRockObject spriteFilename:@"rock.png" weight:7];
113 [objectFactory createRecipeWithIdentifier:kOneUpObject spriteFilename:@"oneup.png" weight:10];
114 [objectFactory createRecipeWithIdentifier:kPointMultiplierObject spriteFilename:@"multiplier.png" weight:8];
92 } 115 }
93 116
94 return self; 117 return self;
@@ -172,7 +195,7 @@
172 { 195 {
173 int ledgeWidth = arc4random() % 9 + 1; 196 int ledgeWidth = arc4random() % 9 + 1;
174 int ledgeDistance = arc4random() % (ledgeScrollSpeed*ledgeScrollSpeed+1)*3/2; 197 int ledgeDistance = arc4random() % (ledgeScrollSpeed*ledgeScrollSpeed+1)*3/2;
175 CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[factory createLedgeWithWidth:ledgeWidth height:2]]; 198 CCTexture2D* texture = [[CCTexture2D alloc] initWithImage:[ledgeFactory createLedgeWithWidth:ledgeWidth height:2]];
176 CCSprite* ledge = [CCSprite spriteWithTexture:texture]; 199 CCSprite* ledge = [CCSprite spriteWithTexture:texture];
177 ledge.position = ccp(rightmost + rightwidth + ledge.boundingBox.size.width/2+64+ledgeDistance, 32); 200 ledge.position = ccp(rightmost + rightwidth + ledge.boundingBox.size.width/2+64+ledgeDistance, 32);
178 [self addChild:ledge]; 201 [self addChild:ledge];
@@ -214,7 +237,7 @@
214 { 237 {
215 [self unscheduleAllSelectors]; 238 [self unscheduleAllSelectors];
216 239
217 [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverScene sceneWithScore:score gameMode:@"Jump"]]]; 240 [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverScene sceneWithScore:score gameMode:[JumpGameMode info]]]];
218 } 241 }
219 242
220 if (wave) 243 if (wave)
@@ -355,23 +378,22 @@
355 378
356- (void)randomlyAddObject:(ccTime)dt 379- (void)randomlyAddObject:(ccTime)dt
357{ 380{
358 FallingObject* object; 381 int recipeIdentifier;
359
360 int randomval = arc4random()%100; 382 int randomval = arc4random()%100;
361 int pmChance = (5-pointMultiplier)*5 + 30; 383 int pmChance = (5-pointMultiplier)*5 + 30;
362 384
363 if (randomval < 30) 385 if (randomval < 30)
364 { 386 {
365 object = [[OneUp alloc] init]; 387 recipeIdentifier = kOneUpObject;
366 } else if (randomval < pmChance) 388 } else if (randomval < pmChance)
367 { 389 {
368 object = [[PointMultiplier alloc] init]; 390 recipeIdentifier = kPointMultiplierObject;
369 } else { 391 } else {
370 object = [[Rock alloc] init]; 392 recipeIdentifier = kRockObject;
371 } 393 }
372 394
395 FallingObject* object = [[objectFactory buildFallingObjectWithRecipeIdentifier:recipeIdentifier] retain];
373 int objectX; 396 int objectX;
374
375 CGSize first = [cart.sprite boundingBox].size; 397 CGSize first = [cart.sprite boundingBox].size;
376 CGSize second = [object.sprite boundingBox].size; 398 CGSize second = [object.sprite boundingBox].size;
377 399
@@ -395,6 +417,7 @@
395 break; 417 break;
396 } 418 }
397 419
420 object.delegate = self;
398 object.sprite.position = ccp(objectX, 360); 421 object.sprite.position = ccp(objectX, 360);
399 object.sprite.scale = 1; 422 object.sprite.scale = 1;
400 object.fellDuringWave = waterTick > 0; 423 object.fellDuringWave = waterTick > 0;
@@ -407,7 +430,7 @@
407 { 430 {
408 if (arc4random() % 100 > 80) 431 if (arc4random() % 100 > 80)
409 { 432 {
410 object = [[Rock alloc] init]; 433 object = [[objectFactory buildFallingObjectWithRecipeIdentifier:kRockObject] retain];
411 434
412 for (;;) 435 for (;;)
413 { 436 {
@@ -429,6 +452,7 @@
429 break; 452 break;
430 } 453 }
431 454
455 object.delegate = self;
432 object.sprite.position = ccp(objectX, 360); 456 object.sprite.position = ccp(objectX, 360);
433 object.sprite.scale = 1; 457 object.sprite.scale = 1;
434 object.fellDuringWave = waterTick > 0; 458 object.fellDuringWave = waterTick > 0;
@@ -443,7 +467,7 @@
443 { 467 {
444 if (arc4random() % 100 > 80) 468 if (arc4random() % 100 > 80)
445 { 469 {
446 object = [[Rock alloc] init]; 470 object = [[objectFactory buildFallingObjectWithRecipeIdentifier:kRockObject] retain];
447 471
448 for (;;) 472 for (;;)
449 { 473 {
@@ -465,6 +489,7 @@
465 break; 489 break;
466 } 490 }
467 491
492 object.delegate = self;
468 object.sprite.position = ccp(objectX, 360); 493 object.sprite.position = ccp(objectX, 360);
469 object.sprite.scale = 1; 494 object.sprite.scale = 1;
470 object.fellDuringWave = waterTick > 0; 495 object.fellDuringWave = waterTick > 0;
@@ -493,11 +518,28 @@
493 } 518 }
494} 519}
495 520
521- (void)didCatchItem:(FallingObject *)item
522{
523 if (item.objectType == kRockObject)
524 {
525 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]];
526 self.lives--;
527 } else if (item.objectType == kOneUpObject)
528 {
529 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]];
530 self.lives++;
531 } else if (item.objectType == kPointMultiplierObject)
532 {
533 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Absorption2" ofType:@"wav"]];
534 self.pointMultiplier++;
535 }
536}
537
496- (void)setPitch:(double)m_pitch 538- (void)setPitch:(double)m_pitch
497{ 539{
498 [super setPitch:m_pitch]; 540 [super setPitch:m_pitch];
499 541
500 expectedAngle = pitch*M_PI_2; 542 expectedAngle = pitch*M_PI_2;
501} 543}
502 544
503@end 545@end
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 @@
1//
2// OneUp.h
3// Cart Collect
4//
5// Created by iD Student Account on 7/19/11.
6// Copyright 2011 __MyCompanyName__. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10#import "FallingObject.h"
11
12@interface OneUp : FallingObject {
13
14}
15
16- (id)init;
17
18@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 @@
1//
2// OneUp.m
3// Cart Collect
4//
5// Created by iD Student Account on 7/19/11.
6// Copyright 2011 __MyCompanyName__. All rights reserved.
7//
8
9#import "OneUp.h"
10#import "GameMode.h"
11#import "SimpleAudioEngine.h"
12
13@implementation OneUp
14
15- (id)init
16{
17 self = [super init];
18
19 if (nil != self)
20 {
21 sprite = [CCSprite spriteWithFile:@"oneup.png"];
22 weight = 10;
23 }
24
25 return self;
26}
27
28- (void)collideWithCart
29{
30 GameMode* gameLayer = ((GameMode*) sprite.parent);
31 [gameLayer setLives:gameLayer.lives+1];
32
33 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]];
34}
35
36@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 @@
1//
2// PointMultiplier.h
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 "FallingObject.h"
10
11@interface PointMultiplier : FallingObject
12
13- (id)init;
14
15@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 @@
1//
2// PointMultiplier.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 "PointMultiplier.h"
10#import "GameMode.h"
11#import "SimpleAudioEngine.h"
12
13@implementation PointMultiplier
14
15- (id)init
16{
17 self = [super init];
18
19 if (nil != self)
20 {
21 sprite = [CCSprite spriteWithFile:@"multiplier.png"];
22 weight = 8;
23 }
24
25 return self;
26}
27
28- (void)collideWithCart
29{
30 GameMode* gameLayer = ((GameMode*) sprite.parent);
31 [gameLayer setPointMultiplier:gameLayer.pointMultiplier+1];
32
33 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Absorption2" ofType:@"wav"]];
34}
35
36@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 @@
1//
2// Rock.h
3// Cart Collect
4//
5// Created by iD Student Account on 7/19/11.
6// Copyright 2011 __MyCompanyName__. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10#import "FallingObject.h"
11
12@interface Rock : FallingObject {
13
14}
15
16- (id)init;
17
18@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 @@
1//
2// Rock.m
3// Cart Collect
4//
5// Created by iD Student Account on 7/19/11.
6// Copyright 2011 __MyCompanyName__. All rights reserved.
7//
8
9#import "Rock.h"
10#import "GameMode.h"
11#import "SimpleAudioEngine.h"
12
13@implementation Rock
14
15- (id)init
16{
17 self = [super init];
18
19 if (nil != self)
20 {
21 sprite = [CCSprite spriteWithFile:@"rock.png"];
22 weight = 7;
23 }
24
25 return self;
26}
27
28- (void)collideWithCart
29{
30 GameMode* gameLayer = ((GameMode*) sprite.parent);
31 [gameLayer setLives:gameLayer.lives-1];
32
33 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]];
34}
35
36
37@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 @@
18 18
19@property (nonatomic,retain) TutorialBubble* currentTutorial; 19@property (nonatomic,retain) TutorialBubble* currentTutorial;
20- (void)endTutorial; 20- (void)endTutorial;
21- (FallingObject*)dropSpecificItem:(FallingObject*)item; 21- (FallingObject*)dropSpecificItem:(int)objectType;
22- (FallingObject*)dropRandomItem; 22- (FallingObject*)dropRandomItem;
23- (void)randomlyAddObject:(ccTime)dt; 23- (void)randomlyAddObject:(ccTime)dt;
24 24
diff --git a/Classes/TutorialMode.m b/Classes/TutorialMode.m index 3c70a46..3f37505 100644 --- a/Classes/TutorialMode.m +++ b/Classes/TutorialMode.m
@@ -8,11 +8,10 @@
8 8
9#import "TutorialMode.h" 9#import "TutorialMode.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 "GameModeSelectionLayer.h" 11#import "GameModeSelectionLayer.h"
12#import "SimpleAudioEngine.h"
13#import "ClassicGameMode.h"
14#import "JumpGameMode.h"
16 15
17// Item tags: 16// Item tags:
18// 2000 - first dropped item 17// 2000 - first dropped item
@@ -22,10 +21,35 @@
22// 2009 - rock 21// 2009 - rock
23// 2010 - random item dropped after death from first rock 22// 2010 - random item dropped after death from first rock
24 23
24typedef enum {
25 kCherryObject = 0,
26 kEnergyDrinkObject,
27 kOneUpObject,
28 kRockObject
29} FallingObjects;
30
25@implementation TutorialMode 31@implementation TutorialMode
26 32
27@synthesize currentTutorial; 33@synthesize currentTutorial;
28 34
35static GameModeInfo* info;
36
37+ (GameModeInfo*)info
38{
39 if (info == nil)
40 {
41 info = [[GameModeInfo alloc] initWithName:@"Tutorial"
42 location:@"Florence"
43 numOfStars:0
44 imageFilename:[[NSBundle mainBundle] pathForResource:@"florence" ofType:@"png"]
45 unlocked:YES
46 gameClass:[TutorialMode class]
47 globalHighscoreKey:nil];
48 }
49
50 return info;
51}
52
29- (id)init 53- (id)init
30{ 54{
31 self = [super init]; 55 self = [super init];
@@ -38,6 +62,11 @@
38 62
39 showedDeathBubble = NO; 63 showedDeathBubble = NO;
40 randomItemsDropped = 0; 64 randomItemsDropped = 0;
65
66 [objectFactory createRecipeWithIdentifier:kCherryObject spriteFilename:@"cherry.png" weight:5];
67 [objectFactory createRecipeWithIdentifier:kEnergyDrinkObject spriteFilename:@"bottle.png" weight:6];
68 [objectFactory createRecipeWithIdentifier:kOneUpObject spriteFilename:@"oneup.png" weight:10];
69 [objectFactory createRecipeWithIdentifier:kRockObject spriteFilename:@"rock.png" weight:7];
41 } 70 }
42 71
43 return self; 72 return self;
@@ -79,6 +108,24 @@
79 108
80- (void)didCatchItem:(FallingObject *)item 109- (void)didCatchItem:(FallingObject *)item
81{ 110{
111 if (item.objectType == kCherryObject)
112 {
113 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]];
114 self.score += 10;
115 } else if (item.objectType == kEnergyDrinkObject)
116 {
117 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]];
118 self.score += 25;
119 } else if (item.objectType == kOneUpObject)
120 {
121 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]];
122 self.lives++;
123 } else if (item.objectType == kRockObject)
124 {
125 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]];
126 self.lives--;
127 }
128
82 if (item.sprite.tag == 2000) 129 if (item.sprite.tag == 2000)
83 { 130 {
84 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"]; 131 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 +141,12 @@
94 141
95- (void)didMissItem:(FallingObject *)item 142- (void)didMissItem:(FallingObject *)item
96{ 143{
144 if ((item.objectType == kCherryObject) || (item.objectType == kEnergyDrinkObject))
145 {
146 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]];
147 self.lives--;
148 }
149
97 if (item.sprite.tag == 2000) 150 if (item.sprite.tag == 2000)
98 { 151 {
99 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"]; 152 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 +164,6 @@
111 [self scheduleDelayedAction:^{ 164 [self scheduleDelayedAction:^{
112 FallingObject* object = [self dropRandomItem]; 165 FallingObject* object = [self dropRandomItem];
113 object.sprite.tag = 2002; 166 object.sprite.tag = 2002;
114 [object release];
115 } delay:1.0f]; 167 } delay:1.0f];
116 } 168 }
117} 169}
@@ -181,7 +233,6 @@
181 [self scheduleDelayedAction:^{ 233 [self scheduleDelayedAction:^{
182 FallingObject* object = [self dropRandomItem]; 234 FallingObject* object = [self dropRandomItem];
183 object.sprite.tag = 2000; 235 object.sprite.tag = 2000;
184 [object release];
185 } delay:3.0f]; 236 } delay:3.0f];
186 } else if ([currentTutorial.name isEqual:@"caught-first"]) 237 } else if ([currentTutorial.name isEqual:@"caught-first"])
187 { 238 {
@@ -198,29 +249,24 @@
198 } 249 }
199 250
200 object.sprite.tag = 2001; 251 object.sprite.tag = 2001;
201
202 [object release];
203 } delay:1.0f]; 252 } delay:1.0f];
204 } else if ([currentTutorial.name isEqual:@"missed-first"]) 253 } else if ([currentTutorial.name isEqual:@"missed-first"])
205 { 254 {
206 [self scheduleDelayedAction:^{ 255 [self scheduleDelayedAction:^{
207 FallingObject* object = [self dropRandomItem]; 256 FallingObject* object = [self dropRandomItem];
208 object.sprite.tag = 2002; 257 object.sprite.tag = 2002;
209 [object release];
210 } delay:1.0f]; 258 } delay:1.0f];
211 } else if (([currentTutorial.name isEqual:@"caught-second"]) || ([currentTutorial.name isEqual:@"missed-second"])) 259 } else if (([currentTutorial.name isEqual:@"caught-second"]) || ([currentTutorial.name isEqual:@"missed-second"]))
212 { 260 {
213 [self scheduleDelayedAction:^{ 261 [self scheduleDelayedAction:^{
214 FallingObject* object = [self dropSpecificItem:[[OneUp alloc] init]]; 262 FallingObject* object = [self dropSpecificItem:kOneUpObject];
215 object.sprite.tag = 2003; 263 object.sprite.tag = 2003;
216 [object release];
217 } delay:2.0f]; 264 } delay:2.0f];
218 } else if ([currentTutorial.name isEqual:@"gameover-rock"]) 265 } else if ([currentTutorial.name isEqual:@"gameover-rock"])
219 { 266 {
220 [self scheduleDelayedAction:^{ 267 [self scheduleDelayedAction:^{
221 FallingObject* object = [self dropRandomItem]; 268 FallingObject* object = [self dropRandomItem];
222 object.sprite.tag = 2010; 269 object.sprite.tag = 2010;
223 [object release];
224 } delay:1.0f]; 270 } delay:1.0f];
225 } else if ([currentTutorial.name isEqual:@"intense"]) 271 } else if ([currentTutorial.name isEqual:@"intense"])
226 { 272 {
@@ -254,8 +300,9 @@
254 } 300 }
255} 301}
256 302
257- (FallingObject*)dropSpecificItem:(FallingObject*)object 303- (FallingObject*)dropSpecificItem:(int)objectType
258{ 304{
305 FallingObject* object = [[objectFactory buildFallingObjectWithRecipeIdentifier:objectType] retain];
259 int objectX = arc4random()%448+16; 306 int objectX = arc4random()%448+16;
260 object.sprite.position = ccp(objectX, 360); 307 object.sprite.position = ccp(objectX, 360);
261 object.sprite.scale = 1; 308 object.sprite.scale = 1;
@@ -265,27 +312,27 @@
265 312
266 [objects addObject:object]; 313 [objects addObject:object];
267 314
268 return object; 315 return [object autorelease];
269} 316}
270 317
271- (FallingObject*)dropRandomItem 318- (FallingObject*)dropRandomItem
272{ 319{
273 FallingObject* object;
274 int randomval = arc4random()%100; 320 int randomval = arc4random()%100;
321 int recipeIdentifier;
275 322
276 if (randomval < 65) 323 if (randomval < 65)
277 { 324 {
278 object = [[Cherry alloc] init]; 325 recipeIdentifier = kCherryObject;
279 } else { 326 } else {
280 object = [[Bottle alloc] init]; 327 recipeIdentifier = kEnergyDrinkObject;
281 } 328 }
282 329
283 return [self dropSpecificItem:object]; 330 return [self dropSpecificItem:recipeIdentifier];
284} 331}
285 332
286- (void)randomlyAddObject:(ccTime)dt 333- (void)randomlyAddObject:(ccTime)dt
287{ 334{
288 FallingObject* object; 335 int recipeIdentifier;
289 336
290 if (randomItemsDropped < 5) 337 if (randomItemsDropped < 5)
291 { 338 {
@@ -293,17 +340,16 @@
293 340
294 if (randomval < 65) 341 if (randomval < 65)
295 { 342 {
296 object = [[Cherry alloc] init]; 343 recipeIdentifier = kCherryObject;
297 } else if (randomval < 98) 344 } else if (randomval < 98)
298 { 345 {
299 object = [[Bottle alloc] init]; 346 recipeIdentifier = kEnergyDrinkObject;
300 } else { 347 } else {
301 object = [[OneUp alloc] init]; 348 recipeIdentifier = kOneUpObject;
302 } 349 }
303 } else if (randomItemsDropped == 5) 350 } else if (randomItemsDropped == 5)
304 { 351 {
305 object = [[Rock alloc] init]; 352 recipeIdentifier = kRockObject;
306 object.sprite.tag = 2009;
307 353
308 [self unschedule:@selector(randomlyAddObject:)]; 354 [self unschedule:@selector(randomlyAddObject:)];
309 } else if (randomItemsDropped < 15) { 355 } else if (randomItemsDropped < 15) {
@@ -311,15 +357,15 @@
311 357
312 if (randomval < 40) 358 if (randomval < 40)
313 { 359 {
314 object = [[Cherry alloc] init]; 360 recipeIdentifier = kCherryObject;
315 } else if (randomval < 70) 361 } else if (randomval < 70)
316 { 362 {
317 object = [[Rock alloc] init]; 363 recipeIdentifier = kRockObject;
318 } else if (randomval < 98) 364 } else if (randomval < 98)
319 { 365 {
320 object = [[Bottle alloc] init]; 366 recipeIdentifier = kEnergyDrinkObject;
321 } else { 367 } else {
322 object = [[OneUp alloc] init]; 368 recipeIdentifier = kOneUpObject;
323 } 369 }
324 } else if (randomItemsDropped == 15) 370 } else if (randomItemsDropped == 15)
325 { 371 {
@@ -331,8 +377,8 @@
331 377
332 [self unschedule:@selector(randomlyAddObject:)]; 378 [self unschedule:@selector(randomlyAddObject:)];
333 379
334 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; 380 [[ClassicGameMode info] unlock];
335 [defaults setBool:YES forKey:@"hasDoneTutorial"]; 381 [[JumpGameMode info] unlock];
336 382
337 return; 383 return;
338 } else { 384 } else {
@@ -341,8 +387,12 @@
341 return; 387 return;
342 } 388 }
343 389
344 [self dropSpecificItem:object]; 390 FallingObject* object = [self dropSpecificItem:recipeIdentifier];
345 [object release]; 391
392 if (randomItemsDropped == 5)
393 {
394 object.sprite.tag = 2009;
395 }
346 396
347 randomItemsDropped++; 397 randomItemsDropped++;
348} 398}
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 @@
1//
2// ValuableObject.h
3// Cart Collect
4//
5// Created by Starla Insigna on 8/9/11.
6// Copyright 2011 Four Island. All rights reserved.
7//
8
9#import "FallingObject.h"
10
11@interface ValuableObject : FallingObject
12
13- (int)pointValue;
14
15@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 @@
1//
2// ValuableObject.m
3// Cart Collect
4//
5// Created by Starla Insigna on 8/9/11.
6// Copyright 2011 Four Island. All rights reserved.
7//
8
9#import "ValuableObject.h"
10#import "GameMode.h"
11#import "SimpleAudioEngine.h"
12
13@implementation ValuableObject
14
15- (id)init
16{
17 self = [super init];
18 if (self) {
19 // Initialization code here.
20 }
21
22 return self;
23}
24
25- (void)collideWithCart
26{
27 GameMode* gameLayer = ((GameMode*) sprite.parent);
28 [gameLayer setScore:gameLayer.score+self.pointValue];
29
30 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]];
31}
32
33- (void)collideWithFloor
34{
35 GameMode* gameLayer = ((GameMode*) sprite.parent);
36 [gameLayer setLives:gameLayer.lives-1];
37
38 [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]];
39}
40
41- (int)pointValue
42{
43 @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] userInfo:nil];
44}
45
46@end