summary refs log tree commit diff stats
path: root/Classes/ClassicGameMode.m
blob: 46ad337b64fe130f3957f8aa10f41767cc9fab99 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//
//  GameLayer.m
//  Cart Collect
//
//  Created by iD Student Account on 7/18/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ClassicGameMode.h"
#import "FallingObject.h"
#import "Cherry.h"
#import "Bottle.h"
#import "OneUp.h"
#import "Rock.h"
#import "GameOverScene.h"
#import "SimpleAudioEngine.h"
#import "CCNotifications.h"
#import "TestFlight.h"

@implementation ClassicGameMode

- (void)tick:(ccTime)dt
{
	int lastScore = score;
	
	[super tick:dt];
	
	if (lives <= 0)
	{
        [self unscheduleAllSelectors];

        [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverScene sceneWithScore:score gameMode:@"Collect"]]];
	} else if (score > lastScore)
	{
		if ((lastScore < 6500) && (score >= 6500))
		{
			[self unschedule:@selector(randomlyAddObject:)];
			[self schedule:@selector(randomlyAddObject:) interval:0.6f];
			addSpeed = 0.6f;
        } else if ((lastScore < 4500) && (score >= 4500))
		{
			[self unschedule:@selector(randomlyAddObject:)];
			[self schedule:@selector(randomlyAddObject:) interval:0.7f];
			addSpeed = 0.7f;
		} else if ((lastScore < 3000) && (score >= 3000))
        {
            NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
            
            if (![defaults boolForKey:@"unlockedJumpMode"])
            {
                [[CCNotifications sharedManager] addWithTitle:@"Jump" message:@"You've unlocked a new game mode!" image:@"venice.png"];
                
                [defaults setBool:YES forKey:@"unlockedJumpMode"];
                [defaults synchronize];
                
                [TestFlight passCheckpoint:@"Unlocked Jump Mode"];
            }
		} else if ((lastScore < 2500) && (score >= 2500))
		{
			[self unschedule:@selector(randomlyAddObject:)];
			[self schedule:@selector(randomlyAddObject:) interval:0.8f];
			addSpeed = 0.8f;
		} else if ((lastScore < 1500) && (score >= 1500))
		{
			[self unschedule:@selector(randomlyAddObject:)];
			[self schedule:@selector(randomlyAddObject:) interval:0.9f];
			addSpeed = 0.9f;
		} else if ((lastScore < 500) && (score >= 500))
		{
			[self unschedule:@selector(randomlyAddObject:)];
			[self schedule:@selector(randomlyAddObject:) interval:1.0f];
			addSpeed = 1.0f;
		} else if ((lastScore < 150) && (score >= 150))
		{
			[self unschedule:@selector(randomlyAddObject:)];
			[self schedule:@selector(randomlyAddObject:) interval:2.0f];
			addSpeed = 2.0f;
		}
	}
}

- (void)randomlyAddObject:(ccTime)dt
{
	FallingObject* object;
    int oneuppercent = 98 - (lives == 1 ? 1 : 0);

	if (score < 1000)
	{
		int randomval = arc4random()%100;
		
		if (randomval < 65)
		{
			object = [[Cherry alloc] init];
		} else if (randomval < oneuppercent)
		{
			object = [[Bottle alloc] init];
		} else {
			object = [[OneUp alloc] init];
		}
	} else {
		int randomval = arc4random()%100;
		
		if (randomval < 40)
		{
			object = [[Cherry alloc] init];
		} else if (randomval < 70)
		{
			object = [[Rock alloc] init];
		} else if (randomval < oneuppercent)
		{
			object = [[Bottle alloc] init];
		} else {
			object = [[OneUp alloc] init];
		}
	}
	
	int objectX = arc4random()%448+16;
	object.sprite.position = ccp(objectX, 360);
	object.sprite.scale = 1;
	[self addChild:object.sprite];
	
	[objects addObject:object];
    [object release];
	
	if (score >= 2000)
	{
		if (arc4random() % 100 > 80)
		{
			object = [[Rock alloc] init];
			
			objectX = arc4random()%448+16;
			object.sprite.position = ccp(objectX, 360);
			object.sprite.scale = 1;
			[self addChild:object.sprite];
			
			[objects addObject:object];
            [object release];
		}
	}
	
	if (score >= 4000)
	{
		if (arc4random() % 100 > 80)
		{
			object = [[Rock alloc] init];
			
			objectX = arc4random()%448+16;
			object.sprite.position = ccp(objectX, 360);
			object.sprite.scale = 1;
			[self addChild:object.sprite];
			
			[objects addObject:object];
            [object release];
		}
	}
}

- (id)init
{
	self = [super init];
	
	if (nil != self)
	{
		CCSprite* backgroundImage = [CCSprite spriteWithFile:@"SeaBeach.png"];
		backgroundImage.position = ccp(240, 160);
		[self addChild:backgroundImage z:-1];
		
		addSpeed = 2.5f;
	}
	
	return self;
}

- (void)onEnterTransitionDidFinish
{
	[super onEnterTransitionDidFinish];
	
    [self schedule:@selector(randomlyAddObject:) interval:addSpeed];
}

@end