summary refs log tree commit diff stats
path: root/Classes
diff options
context:
space:
mode:
Diffstat (limited to 'Classes')
-rw-r--r--Classes/Cart.h2
-rw-r--r--Classes/Cart.m10
-rwxr-xr-xClasses/Cart_CollectAppDelegate.m4
-rwxr-xr-xClasses/ClassicGameMode.h20
-rwxr-xr-xClasses/ClassicGameMode.m166
-rwxr-xr-xClasses/FallingObject.h3
-rwxr-xr-xClasses/FallingObject.m25
-rw-r--r--Classes/FallingObjectDelegate.h20
-rwxr-xr-xClasses/GameLayer.h31
-rwxr-xr-xClasses/GameLayer.m284
-rw-r--r--Classes/GameMode.h19
-rw-r--r--Classes/GameMode.m112
-rwxr-xr-xClasses/MainMenuLayer.m12
-rw-r--r--Classes/TutorialBubble.m13
-rw-r--r--Classes/TutorialMode.h26
-rw-r--r--Classes/TutorialMode.m349
16 files changed, 763 insertions, 333 deletions
diff --git a/Classes/Cart.h b/Classes/Cart.h index d708d73..0ef1abf 100644 --- a/Classes/Cart.h +++ b/Classes/Cart.h
@@ -12,9 +12,11 @@
12@interface Cart : NSObject { 12@interface Cart : NSObject {
13 CCSprite* sprite; 13 CCSprite* sprite;
14 float accelX; 14 float accelX;
15 BOOL immobile;
15} 16}
16 17
17@property (readonly) CCSprite* sprite; 18@property (readonly) CCSprite* sprite;
19@property (assign) BOOL immobile;
18- (id)initWithSprite:(CCSprite*)sprite; 20- (id)initWithSprite:(CCSprite*)sprite;
19- (void)tick; 21- (void)tick;
20- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration; 22- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration;
diff --git a/Classes/Cart.m b/Classes/Cart.m index 3046be3..45c370c 100644 --- a/Classes/Cart.m +++ b/Classes/Cart.m
@@ -10,7 +10,7 @@
10 10
11@implementation Cart 11@implementation Cart
12 12
13@synthesize sprite; 13@synthesize sprite, immobile;
14 14
15- (id)initWithSprite:(CCSprite*)m_sprite 15- (id)initWithSprite:(CCSprite*)m_sprite
16{ 16{
@@ -19,6 +19,7 @@
19 if (nil != self) 19 if (nil != self)
20 { 20 {
21 sprite = m_sprite; 21 sprite = m_sprite;
22 immobile = NO;
22 } 23 }
23 24
24 return self; 25 return self;
@@ -26,8 +27,11 @@
26 27
27- (void)tick 28- (void)tick
28{ 29{
29 // Move the cart based on acceleration gathered from accelerometer 30 if (!immobile)
30 sprite.position = ccp(MIN(MAX(sprite.position.x+accelX, 16),464), sprite.position.y); 31 {
32 // Move the cart based on acceleration gathered from accelerometer
33 sprite.position = ccp(MIN(MAX(sprite.position.x+accelX, 16),464), sprite.position.y);
34 }
31} 35}
32 36
33- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration 37- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
diff --git a/Classes/Cart_CollectAppDelegate.m b/Classes/Cart_CollectAppDelegate.m index 7547601..158f660 100755 --- a/Classes/Cart_CollectAppDelegate.m +++ b/Classes/Cart_CollectAppDelegate.m
@@ -10,7 +10,7 @@
10 10
11#import "Cart_CollectAppDelegate.h" 11#import "Cart_CollectAppDelegate.h"
12#import "GameConfig.h" 12#import "GameConfig.h"
13#import "GameLayer.h" 13#import "GameMode.h"
14#import "RootViewController.h" 14#import "RootViewController.h"
15#import "MainMenuLayer.h" 15#import "MainMenuLayer.h"
16 16
@@ -141,7 +141,7 @@
141 141
142 if ([[CCDirector sharedDirector] runningScene].tag == GAME_SCENE) 142 if ([[CCDirector sharedDirector] runningScene].tag == GAME_SCENE)
143 { 143 {
144 [((GameLayer*)[[[CCDirector sharedDirector] runningScene] getChildByTag:GAME_LAYER]) pause]; 144 [((GameMode*)[[[CCDirector sharedDirector] runningScene] getChildByTag:GAME_LAYER]) pause];
145 } 145 }
146} 146}
147 147
diff --git a/Classes/ClassicGameMode.h b/Classes/ClassicGameMode.h new file mode 100755 index 0000000..bbce029 --- /dev/null +++ b/Classes/ClassicGameMode.h
@@ -0,0 +1,20 @@
1//
2// GameLayer.h
3// Cart Collect
4//
5// Created by iD Student Account on 7/18/11.
6// Copyright 2011 __MyCompanyName__. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10#import "cocos2d.h"
11#import "GameMode.h"
12
13@interface ClassicGameMode : GameMode {
14 float addSpeed;
15}
16
17- (id)init;
18- (void)randomlyAddObject:(ccTime)dt;
19
20@end
diff --git a/Classes/ClassicGameMode.m b/Classes/ClassicGameMode.m new file mode 100755 index 0000000..eb766a1 --- /dev/null +++ b/Classes/ClassicGameMode.m
@@ -0,0 +1,166 @@
1//
2// GameLayer.m
3// Cart Collect
4//
5// Created by iD Student Account on 7/18/11.
6// Copyright 2011 __MyCompanyName__. All rights reserved.
7//
8
9#import "ClassicGameMode.h"
10#import "FallingObject.h"
11#import "Cherry.h"
12#import "Bottle.h"
13#import "OneUp.h"
14#import "Rock.h"
15#import "GameOverLayer.h"
16#import "SimpleAudioEngine.h"
17
18@implementation ClassicGameMode
19
20- (void)tick:(ccTime)dt
21{
22 int lastScore = score;
23
24 [super tick:dt];
25
26 if (lives == 0)
27 {
28 [self unscheduleAllSelectors];
29
30 [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverLayer sceneWithScore:score]]];
31 } else if (score > lastScore)
32 {
33 if ((lastScore < 6500) && (score >= 6500))
34 {
35 [self unschedule:@selector(randomlyAddObject:)];
36 [self schedule:@selector(randomlyAddObject:) interval:0.6f];
37 addSpeed = 0.6f;
38 } else if ((lastScore < 4500) && (score >= 4500))
39 {
40 [self unschedule:@selector(randomlyAddObject:)];
41 [self schedule:@selector(randomlyAddObject:) interval:0.7f];
42 addSpeed = 0.7f;
43 } else if ((lastScore < 2500) && (score >= 2500))
44 {
45 [self unschedule:@selector(randomlyAddObject:)];
46 [self schedule:@selector(randomlyAddObject:) interval:0.8f];
47 addSpeed = 0.8f;
48 } else if ((lastScore < 1500) && (score >= 1500))
49 {
50 [self unschedule:@selector(randomlyAddObject:)];
51 [self schedule:@selector(randomlyAddObject:) interval:0.9f];
52 addSpeed = 0.9f;
53 } else if ((lastScore < 500) && (score >= 500))
54 {
55 [self unschedule:@selector(randomlyAddObject:)];
56 [self schedule:@selector(randomlyAddObject:) interval:1.0f];
57 addSpeed = 1.0f;
58 } else if ((lastScore < 150) && (score >= 150))
59 {
60 [self unschedule:@selector(randomlyAddObject:)];
61 [self schedule:@selector(randomlyAddObject:) interval:2.0f];
62 addSpeed = 2.0f;
63 }
64 }
65}
66
67- (void)randomlyAddObject:(ccTime)dt
68{
69 FallingObject* object;
70 int oneuppercent = 98 - (lives == 1 ? 1 : 0);
71
72 if (score < 1000)
73 {
74 int randomval = arc4random()%100;
75
76 if (randomval < 65)
77 {
78 object = [[Cherry alloc] init];
79 } else if (randomval < oneuppercent)
80 {
81 object = [[Bottle alloc] init];
82 } else {
83 object = [[OneUp alloc] init];
84 }
85 } else {
86 int randomval = arc4random()%100;
87
88 if (randomval < 40)
89 {
90 object = [[Cherry alloc] init];
91 } else if (randomval < 70)
92 {
93 object = [[Rock alloc] init];
94 } else if (randomval < oneuppercent)
95 {
96 object = [[Bottle alloc] init];
97 } else {
98 object = [[OneUp alloc] init];
99 }
100 }
101
102 int objectX = arc4random()%448+16;
103 object.sprite.position = ccp(objectX, 360);
104 object.sprite.scale = 1;
105 [self addChild:object.sprite];
106
107 [objects addObject:object];
108 [object release];
109
110 if (score >= 2000)
111 {
112 if (arc4random() % 100 > 80)
113 {
114 object = [[Rock alloc] init];
115
116 objectX = arc4random()%448+16;
117 object.sprite.position = ccp(objectX, 360);
118 object.sprite.scale = 1;
119 [self addChild:object.sprite];
120
121 [objects addObject:object];
122 [object release];
123 }
124 }
125
126 if (score >= 4000)
127 {
128 if (arc4random() % 100 > 80)
129 {
130 object = [[Rock alloc] init];
131
132 objectX = arc4random()%448+16;
133 object.sprite.position = ccp(objectX, 360);
134 object.sprite.scale = 1;
135 [self addChild:object.sprite];
136
137 [objects addObject:object];
138 [object release];
139 }
140 }
141}
142
143- (id)init
144{
145 self = [super init];
146
147 if (nil != self)
148 {
149 CCSprite* backgroundImage = [CCSprite spriteWithFile:@"SeaBeach.png"];
150 backgroundImage.position = ccp(240, 160);
151 [self addChild:backgroundImage z:-1];
152
153 addSpeed = 2.5f;
154 }
155
156 return self;
157}
158
159- (void)onEnterTransitionDidFinish
160{
161 [super onEnterTransitionDidFinish];
162
163 [self schedule:@selector(randomlyAddObject:) interval:addSpeed];
164}
165
166@end
diff --git a/Classes/FallingObject.h b/Classes/FallingObject.h index 0bda787..3e28903 100755 --- a/Classes/FallingObject.h +++ b/Classes/FallingObject.h
@@ -8,14 +8,17 @@
8 8
9#import <Foundation/Foundation.h> 9#import <Foundation/Foundation.h>
10#import "cocos2d.h" 10#import "cocos2d.h"
11#import "FallingObjectDelegate.h"
11 12
12@interface FallingObject : NSObject { 13@interface FallingObject : NSObject {
13 CCSprite* sprite; 14 CCSprite* sprite;
14 int weight; 15 int weight;
16 id<FallingObjectDelegate> delegate;
15} 17}
16 18
17@property (readonly) CCSprite* sprite; 19@property (readonly) CCSprite* sprite;
18@property (readonly) int weight; 20@property (readonly) int weight;
21@property (nonatomic,retain) id<FallingObjectDelegate> delegate;
19- (id)init; 22- (id)init;
20- (BOOL)tick; 23- (BOOL)tick;
21- (void)collideWithCart; 24- (void)collideWithCart;
diff --git a/Classes/FallingObject.m b/Classes/FallingObject.m index 515948e..85ea902 100755 --- a/Classes/FallingObject.m +++ b/Classes/FallingObject.m
@@ -11,7 +11,7 @@
11 11
12@implementation FallingObject 12@implementation FallingObject
13 13
14@synthesize sprite, weight; 14@synthesize sprite, weight, delegate;
15 15
16- (id)init 16- (id)init
17{ 17{
@@ -46,6 +46,16 @@
46 { 46 {
47 [self collideWithCart]; 47 [self collideWithCart];
48 48
49 if ((delegate != nil) && ([delegate respondsToSelector:@selector(didCatchItem:)]))
50 {
51 [delegate didCatchItem:self];
52 }
53
54 if ((delegate != nil) && ([delegate respondsToSelector:@selector(didDestroyItem:)]))
55 {
56 [delegate didDestroyItem:self];
57 }
58
49 return YES; 59 return YES;
50 } 60 }
51 } 61 }
@@ -57,6 +67,16 @@
57 { 67 {
58 [self collideWithFloor]; 68 [self collideWithFloor];
59 69
70 if ((delegate != nil) && ([delegate respondsToSelector:@selector(didMissItem:)]))
71 {
72 [delegate didMissItem:self];
73 }
74
75 if ((delegate != nil) && ([delegate respondsToSelector:@selector(didDestroyItem:)]))
76 {
77 [delegate didDestroyItem:self];
78 }
79
60 return YES; 80 return YES;
61 } 81 }
62 82
@@ -75,7 +95,8 @@
75 95
76- (void)dealloc 96- (void)dealloc
77{ 97{
78 [sprite release]; 98 [sprite.parent removeChild:sprite cleanup:YES];
99 [delegate release];
79 [super dealloc]; 100 [super dealloc];
80} 101}
81 102
diff --git a/Classes/FallingObjectDelegate.h b/Classes/FallingObjectDelegate.h new file mode 100644 index 0000000..b5c03fb --- /dev/null +++ b/Classes/FallingObjectDelegate.h
@@ -0,0 +1,20 @@
1//
2// FallingObjectDelegate.h
3// Cart Collect
4//
5// Created by Starla Insigna on 8/10/11.
6// Copyright 2011 Four Island. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10
11@class FallingObject;
12
13@protocol FallingObjectDelegate <NSObject>
14
15@optional
16- (void)didCatchItem:(FallingObject*)item;
17- (void)didMissItem:(FallingObject*)item;
18- (void)didDestroyItem:(FallingObject*)item;
19
20@end
diff --git a/Classes/GameLayer.h b/Classes/GameLayer.h deleted file mode 100755 index 128cbf2..0000000 --- a/Classes/GameLayer.h +++ /dev/null
@@ -1,31 +0,0 @@
1//
2// GameLayer.h
3// Cart Collect
4//
5// Created by iD Student Account on 7/18/11.
6// Copyright 2011 __MyCompanyName__. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10#import "cocos2d.h"
11#import "TutorialBubble.h"
12#import "GameMode.h"
13
14@interface GameLayer : GameMode {
15 CCLabelBMFont* scoreLabel;
16 CCLabelBMFont* livesLabel;
17 float addSpeed;
18 TutorialBubble* currentTutorial;
19
20 CCLayerColor* shadedLayer;
21 CCLayer* pauseLayer;
22}
23
24@property (nonatomic,retain) TutorialBubble* currentTutorial;
25- (id)init;
26- (void)pause;
27- (void)unpause;
28- (void)mainmenu;
29- (void)endTutorial;
30
31@end
diff --git a/Classes/GameLayer.m b/Classes/GameLayer.m deleted file mode 100755 index 95bc83b..0000000 --- a/Classes/GameLayer.m +++ /dev/null
@@ -1,284 +0,0 @@
1//
2// GameLayer.m
3// Cart Collect
4//
5// Created by iD Student Account on 7/18/11.
6// Copyright 2011 __MyCompanyName__. All rights reserved.
7//
8
9#import "GameLayer.h"
10#import "FallingObject.h"
11#import "Cherry.h"
12#import "Bottle.h"
13#import "OneUp.h"
14#import "Rock.h"
15#import "GameOverLayer.h"
16#import "SimpleAudioEngine.h"
17#import "MainMenuLayer.h"
18
19@implementation GameLayer
20
21@synthesize currentTutorial;
22
23- (void)tick:(ccTime)dt
24{
25 int lastScore = score;
26
27 [super tick:dt];
28
29 if (lives == 0)
30 {
31 [self unscheduleAllSelectors];
32
33 [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverLayer sceneWithScore:score]]];
34 } else if (score > lastScore)
35 {
36 if ((lastScore < 6500) && (score >= 6500))
37 {
38 [self unschedule:@selector(randomlyAddObject:)];
39 [self schedule:@selector(randomlyAddObject:) interval:0.6f];
40 addSpeed = 0.6f;
41 } else if ((lastScore < 4500) && (score >= 4500))
42 {
43 [self unschedule:@selector(randomlyAddObject:)];
44 [self schedule:@selector(randomlyAddObject:) interval:0.7f];
45 addSpeed = 0.7f;
46 } else if ((lastScore < 2500) && (score >= 2500))
47 {
48 [self unschedule:@selector(randomlyAddObject:)];
49 [self schedule:@selector(randomlyAddObject:) interval:0.8f];
50 addSpeed = 0.8f;
51 } else if ((lastScore < 1500) && (score >= 1500))
52 {
53 [self unschedule:@selector(randomlyAddObject:)];
54 [self schedule:@selector(randomlyAddObject:) interval:0.9f];
55 addSpeed = 0.9f;
56 } else if ((lastScore < 500) && (score >= 500))
57 {
58 [self unschedule:@selector(randomlyAddObject:)];
59 [self schedule:@selector(randomlyAddObject:) interval:1.0f];
60 addSpeed = 1.0f;
61 } else if ((lastScore < 150) && (score >= 150))
62 {
63 [self unschedule:@selector(randomlyAddObject:)];
64 [self schedule:@selector(randomlyAddObject:) interval:2.0f];
65 addSpeed = 2.0f;
66 }
67 }
68}
69
70- (void)randomlyAddObject:(ccTime)dt
71{
72 FallingObject* object;
73 int oneuppercent = 98 - (lives == 1 ? 1 : 0);
74
75 if (score < 1000)
76 {
77 int randomval = arc4random()%100;
78
79 if (randomval < 65)
80 {
81 object = [[Cherry alloc] init];
82 } else if (randomval < oneuppercent)
83 {
84 object = [[Bottle alloc] init];
85 } else {
86 object = [[OneUp alloc] init];
87 }
88 } else {
89 int randomval = arc4random()%100;
90
91 if (randomval < 40)
92 {
93 object = [[Cherry alloc] init];
94 } else if (randomval < 70)
95 {
96 object = [[Rock alloc] init];
97 } else if (randomval < oneuppercent)
98 {
99 object = [[Bottle alloc] init];
100 } else {
101 object = [[OneUp alloc] init];
102 }
103 }
104
105 int objectX = arc4random()%448+16;
106 object.sprite.position = ccp(objectX, 360);
107 object.sprite.scale = 1;
108 [self addChild:object.sprite];
109
110 [objects addObject:object];
111 [object release];
112
113 if (score >= 2000)
114 {
115 if (arc4random() % 100 > 80)
116 {
117 object = [[Rock alloc] init];
118
119 objectX = arc4random()%448+16;
120 object.sprite.position = ccp(objectX, 360);
121 object.sprite.scale = 1;
122 [self addChild:object.sprite];
123
124 [objects addObject:object];
125 [object release];
126 }
127 }
128
129 if (score >= 4000)
130 {
131 if (arc4random() % 100 > 80)
132 {
133 object = [[Rock alloc] init];
134
135 objectX = arc4random()%448+16;
136 object.sprite.position = ccp(objectX, 360);
137 object.sprite.scale = 1;
138 [self addChild:object.sprite];
139
140 [objects addObject:object];
141 [object release];
142 }
143 }
144}
145
146- (id)init
147{
148 self = [super init];
149
150 int winWidth = [CCDirector sharedDirector].winSize.width;
151 //int winHeight = [CCDirector sharedDirector].winSize.height;
152 int cartScale = 2;
153
154 if (self != nil)
155 {
156 CCSprite* backgroundImage = [CCSprite spriteWithFile:@"SeaBeach.png"];
157 backgroundImage.position = ccp(240, 160);
158 [self addChild:backgroundImage z:0];
159
160 cart = [[Cart alloc] initWithSprite:[CCSprite spriteWithFile:@"cart.png"]];
161 cart.sprite.position = ccp(winWidth/2, 22);
162 cart.sprite.scale = cartScale;
163 [self addChild:cart.sprite];
164
165 scoreLabel = [CCLabelBMFont labelWithString:@"Score: 0" fntFile:@"helvetica2.fnt"];
166 scoreLabel.position = ccp(50, 300);
167 [self addChild:scoreLabel];
168
169 livesLabel = [CCLabelBMFont labelWithString:@"Lives: 3" fntFile:@"helvetica2.fnt"];
170 livesLabel.position = ccp(50, 280);
171 [self addChild:livesLabel];
172
173 score = 0;
174 lives = 3;
175
176 CCMenuItemImage* pauseButton = [CCMenuItemImage itemFromNormalImage:@"pause2.png" selectedImage:@"pause.png" target:self selector:@selector(pause)];
177 CCMenu* pauseMenu = [CCMenu menuWithItems:pauseButton, nil];
178 [pauseMenu setPosition:ccp(480-8-16, 320-8-16)];
179 [self addChild:pauseMenu];
180
181 addSpeed = 2.5f;
182 }
183
184 return self;
185}
186
187- (void)onEnter
188{
189 [super onEnter];
190
191 [self schedule:@selector(randomlyAddObject:) interval:addSpeed];
192}
193
194- (void)setScore:(int)m_score
195{
196 score = m_score;
197
198 [scoreLabel setString:[NSString stringWithFormat:@"Score: %d", score]];
199}
200
201- (void)setLives:(int)m_lives
202{
203 lives = m_lives;
204
205 [livesLabel setString:[NSString stringWithFormat:@"Lives: %d", lives]];
206}
207
208- (void)pause
209{
210 if (self.currentTutorial != nil)
211 {
212 [self.currentTutorial removeFromSuperview];
213 }
214
215 [self pauseSchedulerAndActions];
216
217 shadedLayer = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 127)];
218 [[[CCDirector sharedDirector] runningScene] addChild:shadedLayer];
219
220 pauseLayer = [CCLayer node];
221 CCLabelBMFont* scoreLabel2 = [CCLabelBMFont labelWithString:@"PAUSE" fntFile:@"helvetica.fnt"];
222 scoreLabel2.position = ccp(240,90);
223 [pauseLayer addChild:scoreLabel2];
224
225 CCMenuItemImage* pauseButton = [CCMenuItemImage itemFromNormalImage:@"pause2.png" selectedImage:@"pause.png" target:self selector:@selector(unpause)];
226 CCMenu* pauseMenu = [CCMenu menuWithItems:pauseButton, nil];
227 [pauseMenu setPosition:ccp(480-8-16, 320-8-16)];
228 [pauseLayer addChild:pauseMenu];
229
230 CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back2.png" target:self selector:@selector(mainmenu)];
231 CCMenu* myMenu = [CCMenu menuWithItems:newgameMenuItem, nil];
232 myMenu.position = ccp(240, 60);
233 [pauseLayer addChild:myMenu];
234
235 [[[CCDirector sharedDirector] runningScene] addChild:pauseLayer];
236}
237
238- (void)unpause
239{
240 [[[CCDirector sharedDirector] runningScene] removeChild:shadedLayer cleanup:YES];
241 [[[CCDirector sharedDirector] runningScene] removeChild:pauseLayer cleanup:YES];
242
243 shadedLayer = nil;
244 pauseLayer = nil;
245
246 if (self.currentTutorial != nil)
247 {
248 [[[CCDirector sharedDirector] openGLView] addSubview:self.currentTutorial];
249 } else {
250 [self resumeSchedulerAndActions];
251 }
252}
253
254- (void)mainmenu
255{
256 [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]];
257}
258
259- (void)setCurrentTutorial:(TutorialBubble *)m_currentTutorial
260{
261 @synchronized(self)
262 {
263 if (currentTutorial != m_currentTutorial)
264 {
265 [currentTutorial release];
266 currentTutorial = [m_currentTutorial retain];
267 }
268 }
269
270 if (currentTutorial != nil)
271 {
272 [currentTutorial setTarget:self action:@selector(endTutorial)];
273 [[[CCDirector sharedDirector] openGLView] addSubview:currentTutorial];
274 [self pauseSchedulerAndActions];
275 }
276}
277
278- (void)endTutorial
279{
280 self.currentTutorial = nil;
281 [self resumeSchedulerAndActions];
282}
283
284@end
diff --git a/Classes/GameMode.h b/Classes/GameMode.h index bd47c90..370550c 100644 --- a/Classes/GameMode.h +++ b/Classes/GameMode.h
@@ -17,11 +17,26 @@
17 int score; 17 int score;
18 int lives; 18 int lives;
19 Cart* cart; 19 Cart* cart;
20
21 CCLayerColor* shadedLayer;
22 CCLayer* pauseLayer;
23
24 CCLabelBMFont* scoreLabel;
25 CCLabelBMFont* livesLabel;
26
27 void (^delayedAction)(void);
20} 28}
21 29
22@property (readonly) Cart* cart; 30@property (readonly) Cart* cart;
23@property (assign) int score; 31@property (nonatomic,assign) int score;
24@property (assign) int lives; 32@property (nonatomic,assign) int lives;
33+ (CCScene*)scene;
25- (void)tick:(ccTime)dt; 34- (void)tick:(ccTime)dt;
35- (BOOL)canPause;
36- (void)pause;
37- (void)unpause;
38- (void)mainmenu;
39- (void)scheduleDelayedAction:(void(^)(void))delayedAction delay:(float)delay;
40- (void)runDelayedAction;
26 41
27@end 42@end
diff --git a/Classes/GameMode.m b/Classes/GameMode.m index 6fa31e5..7afbf20 100644 --- a/Classes/GameMode.m +++ b/Classes/GameMode.m
@@ -8,6 +8,7 @@
8 8
9#import "GameMode.h" 9#import "GameMode.h"
10#import "FallingObject.h" 10#import "FallingObject.h"
11#import "MainMenuLayer.h"
11 12
12@implementation GameMode 13@implementation GameMode
13 14
@@ -16,7 +17,7 @@
16+ (CCScene*)scene 17+ (CCScene*)scene
17{ 18{
18 CCScene* scene = [CCScene node]; 19 CCScene* scene = [CCScene node];
19 20
20 GameMode* layer = [self node]; 21 GameMode* layer = [self node];
21 layer.tag = GAME_LAYER; 22 layer.tag = GAME_LAYER;
22 [scene addChild:layer]; 23 [scene addChild:layer];
@@ -35,6 +36,30 @@
35 isAccelerometerEnabled_ = YES; 36 isAccelerometerEnabled_ = YES;
36 37
37 objects = [[NSMutableSet alloc] init]; 38 objects = [[NSMutableSet alloc] init];
39
40 cart = [[Cart alloc] initWithSprite:[CCSprite spriteWithFile:@"cart.png"]];
41 cart.sprite.position = ccp(240, 22);
42 cart.sprite.scale = 2;
43 [self addChild:cart.sprite];
44
45 scoreLabel = [CCLabelBMFont labelWithString:@"Score: 0" fntFile:@"helvetica2.fnt"];
46 scoreLabel.position = ccp(50, 300);
47 [self addChild:scoreLabel];
48
49 livesLabel = [CCLabelBMFont labelWithString:@"Lives: 3" fntFile:@"helvetica2.fnt"];
50 livesLabel.position = ccp(50, 280);
51 [self addChild:livesLabel];
52
53 score = 0;
54 lives = 3;
55
56 if ([self canPause])
57 {
58 CCMenuItemImage* pauseButton = [CCMenuItemImage itemFromNormalImage:@"pause2.png" selectedImage:@"pause.png" target:self selector:@selector(pause)];
59 CCMenu* pauseMenu = [CCMenu menuWithItems:pauseButton, nil];
60 [pauseMenu setPosition:ccp(480-8-16, 320-8-16)];
61 [self addChild:pauseMenu];
62 }
38 } 63 }
39 64
40 return self; 65 return self;
@@ -45,9 +70,9 @@
45 [cart accelerometer:accelerometer didAccelerate:acceleration]; 70 [cart accelerometer:accelerometer didAccelerate:acceleration];
46} 71}
47 72
48- (void)onEnter 73- (void)onEnterTransitionDidFinish
49{ 74{
50 [super onEnter]; 75 [super onEnterTransitionDidFinish];
51 76
52 [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)]; 77 [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)];
53 [self schedule:@selector(tick:) interval:1.0f/60.0f]; 78 [self schedule:@selector(tick:) interval:1.0f/60.0f];
@@ -61,13 +86,90 @@
61 { 86 {
62 if ([object tick]) 87 if ([object tick])
63 { 88 {
64 [object retain];
65 [self removeChild:object.sprite cleanup:YES];
66 [objects removeObject:object]; 89 [objects removeObject:object];
67 } 90 }
68 } 91 }
69} 92}
70 93
94- (BOOL)canPause
95{
96 return YES;
97}
98
99- (void)pause
100{
101 if ([self canPause])
102 {
103 [self pauseSchedulerAndActions];
104
105 shadedLayer = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 127)];
106 [[[CCDirector sharedDirector] runningScene] addChild:shadedLayer];
107
108 pauseLayer = [CCLayer node];
109 CCLabelBMFont* scoreLabel2 = [CCLabelBMFont labelWithString:@"PAUSE" fntFile:@"helvetica.fnt"];
110 scoreLabel2.position = ccp(240,90);
111 [pauseLayer addChild:scoreLabel2];
112
113 CCMenuItemImage* pauseButton = [CCMenuItemImage itemFromNormalImage:@"pause2.png" selectedImage:@"pause.png" target:self selector:@selector(unpause)];
114 CCMenu* pauseMenu = [CCMenu menuWithItems:pauseButton, nil];
115 [pauseMenu setPosition:ccp(480-8-16, 320-8-16)];
116 [pauseLayer addChild:pauseMenu];
117
118 CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back2.png" target:self selector:@selector(mainmenu)];
119 CCMenu* myMenu = [CCMenu menuWithItems:newgameMenuItem, nil];
120 myMenu.position = ccp(240, 60);
121 [pauseLayer addChild:myMenu];
122
123 [[[CCDirector sharedDirector] runningScene] addChild:pauseLayer];
124 }
125}
126
127- (void)unpause
128{
129 [[[CCDirector sharedDirector] runningScene] removeChild:shadedLayer cleanup:YES];
130 [[[CCDirector sharedDirector] runningScene] removeChild:pauseLayer cleanup:YES];
131
132 shadedLayer = nil;
133 pauseLayer = nil;
134
135 [self resumeSchedulerAndActions];
136}
137
138- (void)mainmenu
139{
140 [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]];
141}
142
143- (void)setScore:(int)m_score
144{
145 score = m_score;
146
147 [scoreLabel setString:[NSString stringWithFormat:@"Score: %d", score]];
148}
149
150- (void)setLives:(int)m_lives
151{
152 lives = m_lives;
153
154 [livesLabel setString:[NSString stringWithFormat:@"Lives: %d", lives]];
155}
156
157- (void)scheduleDelayedAction:(void(^)(void))m_delayedAction delay:(float)delay
158{
159 delayedAction = Block_copy([m_delayedAction retain]);
160
161 [self schedule:@selector(runDelayedAction) interval:delay];
162}
163
164- (void)runDelayedAction
165{
166 [self unschedule:@selector(runDelayedAction)];
167
168 delayedAction();
169 [delayedAction release];
170 delayedAction = nil;
171}
172
71- (void)dealloc 173- (void)dealloc
72{ 174{
73 [objects release]; 175 [objects release];
diff --git a/Classes/MainMenuLayer.m b/Classes/MainMenuLayer.m index 11cffd7..50c595f 100755 --- a/Classes/MainMenuLayer.m +++ b/Classes/MainMenuLayer.m
@@ -8,7 +8,8 @@
8 8
9#import "MainMenuLayer.h" 9#import "MainMenuLayer.h"
10#import "HighscoreListController.h" 10#import "HighscoreListController.h"
11#import "GameLayer.h" 11#import "ClassicGameMode.h"
12#import "TutorialMode.h"
12#import "Cart_CollectAppDelegate.h" 13#import "Cart_CollectAppDelegate.h"
13 14
14@implementation MainMenuLayer 15@implementation MainMenuLayer
@@ -57,7 +58,14 @@
57 58
58- (void)newgame 59- (void)newgame
59{ 60{
60 [[CCDirector sharedDirector] replaceScene:[GameLayer scene]]; 61 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
62
63 if ([defaults boolForKey:@"hasDoneTutorial"])
64 {
65 [[CCDirector sharedDirector] replaceScene:[ClassicGameMode scene]];
66 } else {
67 [[CCDirector sharedDirector] replaceScene:[TutorialMode scene]];
68 }
61} 69}
62 70
63- (void)highscores 71- (void)highscores
diff --git a/Classes/TutorialBubble.m b/Classes/TutorialBubble.m index b85aa31..74f667f 100644 --- a/Classes/TutorialBubble.m +++ b/Classes/TutorialBubble.m
@@ -134,6 +134,17 @@
134 boxLoc = CGPointMake(CGRectGetMaxX(spriteBounds), CGRectGetMaxY(spriteBounds) - self.frame.size.height); 134 boxLoc = CGPointMake(CGRectGetMaxX(spriteBounds), CGRectGetMaxY(spriteBounds) - self.frame.size.height);
135 arrowLoc = CGPointMake(0, button.frame.size.height - spriteBounds.size.height/2 + 4); 135 arrowLoc = CGPointMake(0, button.frame.size.height - spriteBounds.size.height/2 + 4);
136 } 136 }
137 } else {
138 arrowRotation = 180;
139
140 if (CGRectGetMidX(spriteBounds) < button.frame.size.width)
141 {
142 boxLoc = CGPointMake(0, CGRectGetMaxY(spriteBounds)-4);
143 arrowLoc = CGPointMake(spriteBounds.origin.x+4, 0);
144 } else {
145 boxLoc = CGPointMake(CGRectGetMaxX(spriteBounds) - self.frame.size.width, CGRectGetMaxY(spriteBounds)-4);
146 arrowLoc = CGPointMake(button.frame.size.width - spriteBounds.size.width/2 + 4, 0);
147 }
137 } 148 }
138 149
139 CGImageRef framestuff = [[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"framestuff" ofType:@"png"]] CGImage]; 150 CGImageRef framestuff = [[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"framestuff" ofType:@"png"]] CGImage];
@@ -153,8 +164,6 @@
153 164
154- (void)buttonPressed:(id)sender 165- (void)buttonPressed:(id)sender
155{ 166{
156 [self removeFromSuperview];
157
158 if (target != nil) 167 if (target != nil)
159 { 168 {
160 [target performSelector:action]; 169 [target performSelector:action];
diff --git a/Classes/TutorialMode.h b/Classes/TutorialMode.h new file mode 100644 index 0000000..17b0c7f --- /dev/null +++ b/Classes/TutorialMode.h
@@ -0,0 +1,26 @@
1//
2// TutorialMode.h
3// Cart Collect
4//
5// Created by Starla Insigna on 8/10/11.
6// Copyright 2011 Four Island. All rights reserved.
7//
8
9#import "GameMode.h"
10#import "TutorialBubble.h"
11#import "FallingObjectDelegate.h"
12
13@interface TutorialMode : GameMode <FallingObjectDelegate> {
14 TutorialBubble* currentTutorial;
15 BOOL showedDeathBubble;
16 int randomItemsDropped;
17}
18
19@property (nonatomic,retain) TutorialBubble* currentTutorial;
20- (void)endTutorial;
21- (FallingObject*)dropSpecificItem:(FallingObject*)item;
22- (FallingObject*)dropRandomItem;
23- (void)randomlyAddObject:(ccTime)dt;
24- (void)skipTutorial;
25
26@end
diff --git a/Classes/TutorialMode.m b/Classes/TutorialMode.m new file mode 100644 index 0000000..37e8bd0 --- /dev/null +++ b/Classes/TutorialMode.m
@@ -0,0 +1,349 @@
1//
2// TutorialMode.m
3// Cart Collect
4//
5// Created by Starla Insigna on 8/10/11.
6// Copyright 2011 Four Island. All rights reserved.
7//
8
9#import "TutorialMode.h"
10#import "FallingObject.h"
11#import "Cherry.h"
12#import "Bottle.h"
13#import "OneUp.h"
14#import "Rock.h"
15#import "ClassicGameMode.h"
16
17// Item tags:
18// 2000 - first dropped item
19// 2001 - item that is dropped after you catch first dropped item to demonstrate what happens when you miss
20// 2002 - items that are dropped after you miss first dropped item to demonstrate what happens when you catch
21// 2003 - 1-Up
22// 2009 - rock
23
24@implementation TutorialMode
25
26@synthesize currentTutorial;
27
28- (id)init
29{
30 self = [super init];
31
32 if (nil != self)
33 {
34 CCSprite* backgroundImage = [CCSprite spriteWithFile:@"SeaBeach.png"];
35 backgroundImage.position = ccp(240, 160);
36 [self addChild:backgroundImage z:-1];
37
38 CCMenuItemImage* menuItem1 = [CCMenuItemImage itemFromNormalImage:@"skiptutorial.png" selectedImage:@"skiptutorial2.png" target:self selector:@selector(skipTutorial)];
39 CCMenu* theMenu = [CCMenu menuWithItems:menuItem1, nil];
40 theMenu.position = ccp(480-16-16-62, 320-8-16);
41 [self addChild:theMenu];
42
43 showedDeathBubble = NO;
44 randomItemsDropped = 0;
45 }
46
47 return self;
48}
49
50- (void)onEnterTransitionDidFinish
51{
52 [super onEnterTransitionDidFinish];
53
54 [self scheduleDelayedAction:^{
55 TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"Welcome to Cart Collect. This is a tutorial designed to help you get started playing the game. Below this bubble is a cart. Tilt your device to move it." name:@"cart" spriteReference:cart.sprite];
56 self.currentTutorial = bubble;
57 [bubble release];
58 } delay:2.0f];
59}
60
61- (void)tick:(ccTime)dt
62{
63 [super tick:dt];
64
65 FallingObject* object = [objects anyObject];
66 if ((object.sprite.tag == 2000) && (object.sprite.position.y == 360-object.weight*14))
67 {
68 TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"This is an item. Try to catch it with your cart." name:@"item" spriteReference:object.sprite];
69 self.currentTutorial = bubble;
70 [bubble release];
71 } else if ((object.sprite.tag == 2003) && (object.sprite.position.y == 360-object.weight*8))
72 {
73 TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"This is a 1-Up. Catch it to gain an extra life. There's no penalty for not catching it, though." name:@"oneup" spriteReference:object.sprite];
74 self.currentTutorial = bubble;
75 [bubble release];
76 } else if ((object.sprite.tag == 2009) && (object.sprite.position.y == 360-object.weight*14))
77 {
78 TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"This is a rock. It would be better for your health if you did not catch this item." name:@"rock" spriteReference:object.sprite];
79 self.currentTutorial = bubble;
80 [bubble release];
81 }
82}
83
84- (void)didCatchItem:(FallingObject *)item
85{
86 if (item.sprite.tag == 2000)
87 {
88 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"];
89 self.currentTutorial = bubble;
90 [bubble release];
91 } else if (item.sprite.tag == 2002)
92 {
93 TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"There you go! If you look at your score, you'll see it increased. Catching items is good." name:@"caught-second"];
94 self.currentTutorial = bubble;
95 [bubble release];
96 }
97}
98
99- (void)didMissItem:(FallingObject *)item
100{
101 if (item.sprite.tag == 2000)
102 {
103 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"];
104 self.currentTutorial = bubble;
105 [bubble release];
106 } else if (item.sprite.tag == 2001)
107 {
108 [cart setImmobile:NO];
109
110 TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"You lost a life! You only have three lives, so try not to miss any items! However..." name:@"missed-second"];
111 self.currentTutorial = bubble;
112 [bubble release];
113 } else if (item.sprite.tag == 2002)
114 {
115 [self scheduleDelayedAction:^{
116 FallingObject* object = [self dropRandomItem];
117 object.sprite.tag = 2002;
118 [object release];
119 } delay:1.0f];
120 }
121}
122
123- (void)didDestroyItem:(FallingObject *)item
124{
125 if (item.sprite.tag == 2003)
126 {
127 [self schedule:@selector(randomlyAddObject:) interval:2.5f];
128 } else if (item.sprite.tag == 2009)
129 {
130 TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"As you play, Cart Collect gets progressively more intense. Watch what happens when rocks are added to the mix and the speed is turned up." name:@"intense"];
131 self.currentTutorial = bubble;
132 [bubble release];
133 }
134}
135
136- (void)setCurrentTutorial:(TutorialBubble *)m_currentTutorial
137{
138 @synchronized(self)
139 {
140 if (currentTutorial != m_currentTutorial)
141 {
142 [currentTutorial removeFromSuperview];
143 [currentTutorial release];
144 currentTutorial = [m_currentTutorial retain];
145 }
146 }
147
148 if (currentTutorial != nil)
149 {
150 [currentTutorial setTarget:self action:@selector(endTutorial)];
151 [[[CCDirector sharedDirector] openGLView] addSubview:currentTutorial];
152 [self pauseSchedulerAndActions];
153 }
154}
155
156- (void)endTutorial
157{
158 [self resumeSchedulerAndActions];
159
160 if ([currentTutorial.name isEqual:@"cart"])
161 {
162 [self scheduleDelayedAction:^{
163 FallingObject* object = [self dropRandomItem];
164 object.sprite.tag = 2000;
165 [object release];
166 } delay:3.0f];
167 } else if ([currentTutorial.name isEqual:@"caught-first"])
168 {
169 [cart setImmobile:YES];
170
171 [self scheduleDelayedAction:^{
172 FallingObject* object = [self dropRandomItem];
173
174 if (cart.sprite.position.x > 240)
175 {
176 object.sprite.position = ccp(20, 360);
177 } else {
178 object.sprite.position = ccp(460, 360);
179 }
180
181 object.sprite.tag = 2001;
182
183 [object release];
184 } delay:1.0f];
185 } else if ([currentTutorial.name isEqual:@"missed-first"])
186 {
187 [self scheduleDelayedAction:^{
188 FallingObject* object = [self dropRandomItem];
189 object.sprite.tag = 2002;
190 [object release];
191 } delay:1.0f];
192 } else if (([currentTutorial.name isEqual:@"caught-second"]) || ([currentTutorial.name isEqual:@"missed-second"]))
193 {
194 [self scheduleDelayedAction:^{
195 FallingObject* object = [self dropSpecificItem:[[OneUp alloc] init]];
196 object.sprite.tag = 2003;
197 [object release];
198 } delay:2.0f];
199 } else if ([currentTutorial.name isEqual:@"intense"])
200 {
201 [self schedule:@selector(randomlyAddObject:) interval:1.0f];
202 } else if ([currentTutorial.name isEqual:@"end"])
203 {
204 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
205 [defaults setBool:YES forKey:@"hasDoneTutorial"];
206
207 [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:3.0f scene:[ClassicGameMode scene] withColor:ccc3(0,0,0)]];
208 }
209
210 self.currentTutorial = nil;
211}
212
213- (void)pause
214{
215 if (self.currentTutorial != nil)
216 {
217 [self.currentTutorial removeFromSuperview];
218 }
219
220 [super pause];
221}
222
223- (void)unpause
224{
225 [super unpause];
226
227 if (self.currentTutorial != nil)
228 {
229 [self pauseSchedulerAndActions];
230 [[[CCDirector sharedDirector] openGLView] addSubview:self.currentTutorial];
231 }
232}
233
234- (FallingObject*)dropSpecificItem:(FallingObject*)object
235{
236 int objectX = arc4random()%448+16;
237 object.sprite.position = ccp(objectX, 360);
238 object.sprite.scale = 1;
239 [self addChild:object.sprite];
240
241 object.delegate = self;
242
243 [objects addObject:object];
244
245 return object;
246}
247
248- (FallingObject*)dropRandomItem
249{
250 FallingObject* object;
251 int randomval = arc4random()%100;
252
253 if (randomval < 65)
254 {
255 object = [[Cherry alloc] init];
256 } else {
257 object = [[Bottle alloc] init];
258 }
259
260 return [self dropSpecificItem:object];
261}
262
263- (void)setLives:(int)m_lives
264{
265 [super setLives:m_lives];
266
267 if ((lives < 1) && (!showedDeathBubble))
268 {
269 showedDeathBubble = YES;
270
271 TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"You lost all your lives! Normally, you'd be taken to a game over screen where you could submit your score to the highscore list, but we're a bit more forgiving in tutorial mode." name:@"gameover"];
272 self.currentTutorial = bubble;
273 [bubble release];
274 }
275}
276
277- (void)randomlyAddObject:(ccTime)dt
278{
279 FallingObject* object;
280
281 if (randomItemsDropped < 5)
282 {
283 int randomval = arc4random()%100;
284
285 if (randomval < 65)
286 {
287 object = [[Cherry alloc] init];
288 } else if (randomval < 98)
289 {
290 object = [[Bottle alloc] init];
291 } else {
292 object = [[OneUp alloc] init];
293 }
294 } else if (randomItemsDropped == 5)
295 {
296 object = [[Rock alloc] init];
297 object.sprite.tag = 2009;
298
299 [self unschedule:@selector(randomlyAddObject:)];
300 } else if (randomItemsDropped < 15) {
301 int randomval = arc4random()%100;
302
303 if (randomval < 40)
304 {
305 object = [[Cherry alloc] init];
306 } else if (randomval < 70)
307 {
308 object = [[Rock alloc] init];
309 } else if (randomval < 98)
310 {
311 object = [[Bottle alloc] init];
312 } else {
313 object = [[OneUp alloc] init];
314 }
315 } else if (randomItemsDropped == 15)
316 {
317 [self scheduleDelayedAction:^{
318 TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"That's pretty much it! You've completed the tutorial, so now it's time to play an actual game of Cart Collect!" name:@"end"];
319 self.currentTutorial = bubble;
320 [bubble release];
321 } delay:2.0f];
322
323 [self unschedule:@selector(randomlyAddObject:)];
324
325 return;
326 } else {
327 NSLog(@"randomItemsDropped in TutorialMode is greater than 15--this should never happen.");
328
329 return;
330 }
331
332 [self dropSpecificItem:object];
333 [object release];
334
335 randomItemsDropped++;
336}
337
338- (void)skipTutorial
339{
340 [self unscheduleAllSelectors];
341 self.currentTutorial = nil;
342
343 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
344 [defaults setBool:YES forKey:@"hasDoneTutorial"];
345
346 [[CCDirector sharedDirector] replaceScene:[CCTransitionFlipY transitionWithDuration:1.0f scene:[ClassicGameMode scene]]];
347}
348
349@end