summary refs log tree commit diff stats
path: root/Classes/GameLayer.m
diff options
context:
space:
mode:
Diffstat (limited to 'Classes/GameLayer.m')
-rwxr-xr-xClasses/GameLayer.m284
1 files changed, 0 insertions, 284 deletions
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