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