diff options
author | Starla Insigna <starla4444@gmail.com> | 2011-07-30 11:19:14 -0400 |
---|---|---|
committer | Starla Insigna <starla4444@gmail.com> | 2011-07-30 11:19:14 -0400 |
commit | 9cd57b731ab1c666d4a1cb725538fdc137763d12 (patch) | |
tree | 5bac45ae5157a1cb10c6e45500cbf72789917980 /Classes | |
download | cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.gz cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.bz2 cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.zip |
Initial commit (version 0.2.1)
Diffstat (limited to 'Classes')
-rwxr-xr-x | Classes/Bottle.h | 19 | ||||
-rwxr-xr-x | Classes/Bottle.m | 32 | ||||
-rwxr-xr-x | Classes/Cart_CollectAppDelegate.h | 23 | ||||
-rwxr-xr-x | Classes/Cart_CollectAppDelegate.m | 212 | ||||
-rwxr-xr-x | Classes/Cherry.h | 19 | ||||
-rwxr-xr-x | Classes/Cherry.m | 32 | ||||
-rwxr-xr-x | Classes/FallingObject.h | 21 | ||||
-rwxr-xr-x | Classes/FallingObject.m | 34 | ||||
-rwxr-xr-x | Classes/GameConfig.h | 45 | ||||
-rwxr-xr-x | Classes/GameLayer.h | 38 | ||||
-rwxr-xr-x | Classes/GameLayer.m | 301 | ||||
-rwxr-xr-x | Classes/GameOverLayer.h | 32 | ||||
-rwxr-xr-x | Classes/GameOverLayer.m | 196 | ||||
-rwxr-xr-x | Classes/Highscore.h | 25 | ||||
-rwxr-xr-x | Classes/Highscore.m | 37 | ||||
-rwxr-xr-x | Classes/HighscoreListController.h | 32 | ||||
-rwxr-xr-x | Classes/HighscoreListController.m | 371 | ||||
-rwxr-xr-x | Classes/MainMenuLayer.h | 24 | ||||
-rwxr-xr-x | Classes/MainMenuLayer.m | 68 | ||||
-rwxr-xr-x | Classes/OneUp.h | 18 | ||||
-rwxr-xr-x | Classes/OneUp.m | 27 | ||||
-rwxr-xr-x | Classes/PauseLayer.h | 22 | ||||
-rwxr-xr-x | Classes/PauseLayer.m | 68 | ||||
-rwxr-xr-x | Classes/Rock.h | 18 | ||||
-rwxr-xr-x | Classes/Rock.m | 27 | ||||
-rwxr-xr-x | Classes/RootViewController.h | 16 | ||||
-rwxr-xr-x | Classes/RootViewController.m | 152 | ||||
-rwxr-xr-x | Classes/ValuableObject.h | 15 |
28 files changed, 1924 insertions, 0 deletions
diff --git a/Classes/Bottle.h b/Classes/Bottle.h new file mode 100755 index 0000000..37c41d5 --- /dev/null +++ b/Classes/Bottle.h | |||
@@ -0,0 +1,19 @@ | |||
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 "FallingObject.h" | ||
11 | #import "ValuableObject.h" | ||
12 | |||
13 | @interface Bottle : FallingObject <ValuableObject> { | ||
14 | |||
15 | } | ||
16 | |||
17 | - (id)init; | ||
18 | |||
19 | @end | ||
diff --git a/Classes/Bottle.m b/Classes/Bottle.m new file mode 100755 index 0000000..bae2716 --- /dev/null +++ b/Classes/Bottle.m | |||
@@ -0,0 +1,32 @@ | |||
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/Cart_CollectAppDelegate.h b/Classes/Cart_CollectAppDelegate.h new file mode 100755 index 0000000..0ef23a7 --- /dev/null +++ b/Classes/Cart_CollectAppDelegate.h | |||
@@ -0,0 +1,23 @@ | |||
1 | // | ||
2 | // Cart_CollectAppDelegate.h | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/18/11. | ||
6 | // Copyright __MyCompanyName__ 2011. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import <UIKit/UIKit.h> | ||
10 | #import <sqlite3.h> | ||
11 | |||
12 | @class RootViewController; | ||
13 | |||
14 | @interface Cart_CollectAppDelegate : NSObject <UIApplicationDelegate> { | ||
15 | UIWindow *window; | ||
16 | RootViewController *viewController; | ||
17 | } | ||
18 | |||
19 | @property (nonatomic, retain) UIWindow *window; | ||
20 | @property (nonatomic, retain) RootViewController* viewController; | ||
21 | + (sqlite3*)database; | ||
22 | |||
23 | @end | ||
diff --git a/Classes/Cart_CollectAppDelegate.m b/Classes/Cart_CollectAppDelegate.m new file mode 100755 index 0000000..201422f --- /dev/null +++ b/Classes/Cart_CollectAppDelegate.m | |||
@@ -0,0 +1,212 @@ | |||
1 | // | ||
2 | // Cart_CollectAppDelegate.m | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/18/11. | ||
6 | // Copyright __MyCompanyName__ 2011. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import "cocos2d.h" | ||
10 | |||
11 | #import "Cart_CollectAppDelegate.h" | ||
12 | #import "GameConfig.h" | ||
13 | #import "GameLayer.h" | ||
14 | #import "RootViewController.h" | ||
15 | #import "MainMenuLayer.h" | ||
16 | |||
17 | @implementation Cart_CollectAppDelegate | ||
18 | |||
19 | @synthesize window, viewController; | ||
20 | |||
21 | - (void) removeStartupFlicker | ||
22 | { | ||
23 | // | ||
24 | // THIS CODE REMOVES THE STARTUP FLICKER | ||
25 | // | ||
26 | // Uncomment the following code if you Application only supports landscape mode | ||
27 | // | ||
28 | #if GAME_AUTOROTATION == kGameAutorotationUIViewController | ||
29 | |||
30 | // CC_ENABLE_DEFAULT_GL_STATES(); | ||
31 | // CCDirector *director = [CCDirector sharedDirector]; | ||
32 | // CGSize size = [director winSize]; | ||
33 | // CCSprite *sprite = [CCSprite spriteWithFile:@"Default.png"]; | ||
34 | // sprite.position = ccp(size.width/2, size.height/2); | ||
35 | // sprite.rotation = -90; | ||
36 | // [sprite visit]; | ||
37 | // [[director openGLView] swapBuffers]; | ||
38 | // CC_ENABLE_DEFAULT_GL_STATES(); | ||
39 | |||
40 | #endif // GAME_AUTOROTATION == kGameAutorotationUIViewController | ||
41 | } | ||
42 | |||
43 | - (void) applicationDidFinishLaunching:(UIApplication*)application | ||
44 | { | ||
45 | [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; | ||
46 | |||
47 | NSMutableDictionary* registerDefaults = [NSMutableDictionary dictionaryWithObjectsAndKeys: | ||
48 | @"", @"username", | ||
49 | [NSNumber numberWithBool:YES], @"submitScore", | ||
50 | nil]; | ||
51 | [[NSUserDefaults standardUserDefaults] registerDefaults:registerDefaults]; | ||
52 | |||
53 | // Init the window | ||
54 | window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | ||
55 | |||
56 | // Try to use CADisplayLink director | ||
57 | // if it fails (SDK < 3.1) use the default director | ||
58 | if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] ) | ||
59 | [CCDirector setDirectorType:kCCDirectorTypeDefault]; | ||
60 | |||
61 | |||
62 | CCDirector *director = [CCDirector sharedDirector]; | ||
63 | |||
64 | // Init the View Controller | ||
65 | viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; | ||
66 | viewController.wantsFullScreenLayout = YES; | ||
67 | |||
68 | // | ||
69 | // Create the EAGLView manually | ||
70 | // 1. Create a RGB565 format. Alternative: RGBA8 | ||
71 | // 2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like CCPageTurnTransition | ||
72 | // | ||
73 | // | ||
74 | EAGLView *glView = [EAGLView viewWithFrame:[window bounds] | ||
75 | pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8 | ||
76 | depthFormat:0 // GL_DEPTH_COMPONENT16_OES | ||
77 | ]; | ||
78 | |||
79 | // attach the openglView to the director | ||
80 | [director setOpenGLView:glView]; | ||
81 | |||
82 | // // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices | ||
83 | //if( ! [director enableRetinaDisplay:YES] ) | ||
84 | // CCLOG(@"Retina Display Not supported"); | ||
85 | |||
86 | // | ||
87 | // VERY IMPORTANT: | ||
88 | // If the rotation is going to be controlled by a UIViewController | ||
89 | // then the device orientation should be "Portrait". | ||
90 | // | ||
91 | // IMPORTANT: | ||
92 | // By default, this template only supports Landscape orientations. | ||
93 | // Edit the RootViewController.m file to edit the supported orientations. | ||
94 | // | ||
95 | #if GAME_AUTOROTATION == kGameAutorotationUIViewController | ||
96 | [director setDeviceOrientation:kCCDeviceOrientationPortrait]; | ||
97 | #else | ||
98 | [director setDeviceOrientation:kCCDeviceOrientationPortrait]; | ||
99 | #endif | ||
100 | |||
101 | [director setAnimationInterval:1.0/60]; | ||
102 | //[director setDisplayFPS:YES]; | ||
103 | |||
104 | |||
105 | // make the OpenGLView a child of the view controller | ||
106 | [viewController setView:glView]; | ||
107 | |||
108 | // make the View Controller a child of the main window | ||
109 | [window addSubview: viewController.view]; | ||
110 | |||
111 | [window makeKeyAndVisible]; | ||
112 | |||
113 | // Default texture format for PNG/BMP/TIFF/JPEG/GIF images | ||
114 | // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565 | ||
115 | // You can change anytime. | ||
116 | [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888]; | ||
117 | |||
118 | |||
119 | // Removes the startup flicker | ||
120 | [self removeStartupFlicker]; | ||
121 | |||
122 | // Run the intro Scene | ||
123 | [[CCDirector sharedDirector] runWithScene: [MainMenuLayer scene]]; | ||
124 | } | ||
125 | |||
126 | |||
127 | - (void)applicationWillResignActive:(UIApplication *)application { | ||
128 | [[CCDirector sharedDirector] pause]; | ||
129 | } | ||
130 | |||
131 | - (void)applicationDidBecomeActive:(UIApplication *)application { | ||
132 | [[CCDirector sharedDirector] resume]; | ||
133 | } | ||
134 | |||
135 | - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { | ||
136 | [[CCDirector sharedDirector] purgeCachedData]; | ||
137 | } | ||
138 | |||
139 | -(void) applicationDidEnterBackground:(UIApplication*)application { | ||
140 | [[CCDirector sharedDirector] stopAnimation]; | ||
141 | |||
142 | if ([[CCDirector sharedDirector] runningScene].tag == 436) | ||
143 | { | ||
144 | [[CCDirector sharedDirector] replaceScene:[PauseLayer sceneWithScene:[[CCDirector sharedDirector] runningScene]]]; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | -(void) applicationWillEnterForeground:(UIApplication*)application { | ||
149 | [[CCDirector sharedDirector] startAnimation]; | ||
150 | } | ||
151 | |||
152 | - (void)applicationWillTerminate:(UIApplication *)application { | ||
153 | CCDirector *director = [CCDirector sharedDirector]; | ||
154 | |||
155 | sqlite3_close([Cart_CollectAppDelegate database]); | ||
156 | |||
157 | [[director openGLView] removeFromSuperview]; | ||
158 | |||
159 | [viewController release]; | ||
160 | |||
161 | [window release]; | ||
162 | |||
163 | [director end]; | ||
164 | } | ||
165 | |||
166 | - (void)applicationSignificantTimeChange:(UIApplication *)application { | ||
167 | [[CCDirector sharedDirector] setNextDeltaTimeZero:YES]; | ||
168 | } | ||
169 | |||
170 | - (void)dealloc { | ||
171 | //[[CCDirector sharedDirector] release]; | ||
172 | [window release]; | ||
173 | [super dealloc]; | ||
174 | } | ||
175 | |||
176 | + (sqlite3*)database | ||
177 | { | ||
178 | static sqlite3* database = nil; | ||
179 | |||
180 | if (database == nil) | ||
181 | { | ||
182 | NSString* databaseName = @"cartdata.sqlite3"; | ||
183 | NSArray* documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | ||
184 | NSString* documentsDir = [documentPaths objectAtIndex:0]; | ||
185 | NSString* databasePath = [documentsDir stringByAppendingPathComponent:databaseName]; | ||
186 | NSFileManager* fileManager = [NSFileManager defaultManager]; | ||
187 | NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; | ||
188 | |||
189 | if (![fileManager fileExistsAtPath:databasePath]) | ||
190 | { | ||
191 | NSString* databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; | ||
192 | [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; | ||
193 | //[fileManager release]; | ||
194 | |||
195 | [userDefaults setInteger:1 forKey:@"databaseVersion"]; | ||
196 | } | ||
197 | |||
198 | if ([userDefaults integerForKey:@"databaseVersion"] < 1) | ||
199 | { | ||
200 | // Upgrade the database to version 1, which is completely unnecessary as no prior version exists | ||
201 | } | ||
202 | |||
203 | if (sqlite3_open([databasePath UTF8String], &database) != SQLITE_OK) | ||
204 | { | ||
205 | NSLog(@"Failed to open database"); | ||
206 | } | ||
207 | } | ||
208 | |||
209 | return database; | ||
210 | } | ||
211 | |||
212 | @end | ||
diff --git a/Classes/Cherry.h b/Classes/Cherry.h new file mode 100755 index 0000000..65437f5 --- /dev/null +++ b/Classes/Cherry.h | |||
@@ -0,0 +1,19 @@ | |||
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 "FallingObject.h" | ||
11 | #import "ValuableObject.h" | ||
12 | |||
13 | @interface Cherry : FallingObject <ValuableObject> { | ||
14 | |||
15 | } | ||
16 | |||
17 | - (id)init; | ||
18 | |||
19 | @end | ||
diff --git a/Classes/Cherry.m b/Classes/Cherry.m new file mode 100755 index 0000000..f53c86e --- /dev/null +++ b/Classes/Cherry.m | |||
@@ -0,0 +1,32 @@ | |||
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/FallingObject.h b/Classes/FallingObject.h new file mode 100755 index 0000000..a1ac56e --- /dev/null +++ b/Classes/FallingObject.h | |||
@@ -0,0 +1,21 @@ | |||
1 | // | ||
2 | // GameObject.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 "cocos2d.h" | ||
11 | |||
12 | @interface FallingObject : NSObject { | ||
13 | CCSprite* sprite; | ||
14 | int weight; | ||
15 | } | ||
16 | |||
17 | @property (readonly) CCSprite* sprite; | ||
18 | @property (readonly) int weight; | ||
19 | - (id)init; | ||
20 | |||
21 | @end | ||
diff --git a/Classes/FallingObject.m b/Classes/FallingObject.m new file mode 100755 index 0000000..297b426 --- /dev/null +++ b/Classes/FallingObject.m | |||
@@ -0,0 +1,34 @@ | |||
1 | // | ||
2 | // GameObject.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 "FallingObject.h" | ||
10 | |||
11 | |||
12 | @implementation FallingObject | ||
13 | |||
14 | @synthesize sprite, weight; | ||
15 | |||
16 | - (id)init | ||
17 | { | ||
18 | self = [super init]; | ||
19 | |||
20 | if (nil != self) | ||
21 | { | ||
22 | |||
23 | } | ||
24 | |||
25 | return self; | ||
26 | } | ||
27 | |||
28 | - (void)dealloc | ||
29 | { | ||
30 | [sprite release]; | ||
31 | [super dealloc]; | ||
32 | } | ||
33 | |||
34 | @end \ No newline at end of file | ||
diff --git a/Classes/GameConfig.h b/Classes/GameConfig.h new file mode 100755 index 0000000..1dd3e99 --- /dev/null +++ b/Classes/GameConfig.h | |||
@@ -0,0 +1,45 @@ | |||
1 | // | ||
2 | // GameConfig.h | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/18/11. | ||
6 | // Copyright __MyCompanyName__ 2011. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #ifndef __GAME_CONFIG_H | ||
10 | #define __GAME_CONFIG_H | ||
11 | |||
12 | // | ||
13 | // Supported Autorotations: | ||
14 | // None, | ||
15 | // UIViewController, | ||
16 | // CCDirector | ||
17 | // | ||
18 | #define kGameAutorotationNone 0 | ||
19 | #define kGameAutorotationCCDirector 1 | ||
20 | #define kGameAutorotationUIViewController 2 | ||
21 | |||
22 | // | ||
23 | // Define here the type of autorotation that you want for your game | ||
24 | // | ||
25 | |||
26 | // 3rd generation and newer devices: Rotate using UIViewController. Rotation should be supported on iPad apps. | ||
27 | // TIP: | ||
28 | // To improve the performance, you should set this value to "kGameAutorotationNone" or "kGameAutorotationCCDirector" | ||
29 | #if defined(__ARM_NEON__) || TARGET_IPHONE_SIMULATOR | ||
30 | #define GAME_AUTOROTATION kGameAutorotationUIViewController | ||
31 | |||
32 | // ARMv6 (1st and 2nd generation devices): Don't rotate. It is very expensive | ||
33 | #elif __arm__ | ||
34 | #define GAME_AUTOROTATION kGameAutorotationNone | ||
35 | |||
36 | |||
37 | // Ignore this value on Mac | ||
38 | #elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) | ||
39 | |||
40 | #else | ||
41 | #error(unknown architecture) | ||
42 | #endif | ||
43 | |||
44 | #endif // __GAME_CONFIG_H | ||
45 | |||
diff --git a/Classes/GameLayer.h b/Classes/GameLayer.h new file mode 100755 index 0000000..88a1406 --- /dev/null +++ b/Classes/GameLayer.h | |||
@@ -0,0 +1,38 @@ | |||
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 "FallingObject.h" | ||
12 | #import "Cherry.h" | ||
13 | #import "Bottle.h" | ||
14 | #import "OneUp.h" | ||
15 | #import "Rock.h" | ||
16 | #import "GameOverLayer.h" | ||
17 | #import "ValuableObject.h" | ||
18 | #import "PauseLayer.h" | ||
19 | #import "CocosDenshion.h" | ||
20 | #import "SimpleAudioEngine.h" | ||
21 | |||
22 | @interface GameLayer : CCLayer { | ||
23 | NSMutableSet* objects; | ||
24 | float accelX; | ||
25 | CCLabelBMFont* scoreLabel; | ||
26 | CCLabelBMFont* livesLabel; | ||
27 | int score; | ||
28 | int lives; | ||
29 | float addSpeed; | ||
30 | CCSprite* cartSprite; | ||
31 | } | ||
32 | |||
33 | + (CCScene*)scene; | ||
34 | - (id)init; | ||
35 | - (void)updateLabels; | ||
36 | - (void)pause; | ||
37 | |||
38 | @end | ||
diff --git a/Classes/GameLayer.m b/Classes/GameLayer.m new file mode 100755 index 0000000..32ca483 --- /dev/null +++ b/Classes/GameLayer.m | |||
@@ -0,0 +1,301 @@ | |||
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 | |||
11 | |||
12 | @implementation GameLayer | ||
13 | |||
14 | + (CCScene*)scene | ||
15 | { | ||
16 | CCScene* scene = [CCScene node]; | ||
17 | |||
18 | CCLayerColor* backgroundLayer = [CCLayerColor layerWithColor:ccc4(255, 255, 255, 255)]; | ||
19 | [scene addChild:backgroundLayer]; | ||
20 | |||
21 | GameLayer* layer = [GameLayer node]; | ||
22 | [scene addChild:layer]; | ||
23 | |||
24 | scene.tag = 436; | ||
25 | |||
26 | return scene; | ||
27 | } | ||
28 | |||
29 | - (void)tick:(ccTime)dt | ||
30 | { | ||
31 | // Move the cart based on acceleration gathered from accelerometer | ||
32 | cartSprite.position = ccp(MIN(MAX(cartSprite.position.x+accelX, 16),464), cartSprite.position.y); | ||
33 | |||
34 | int lastScore = score; | ||
35 | |||
36 | for (FallingObject* object in objects) | ||
37 | { | ||
38 | // Move objects down | ||
39 | object.sprite.position = ccp(object.sprite.position.x, object.sprite.position.y-object.weight); | ||
40 | |||
41 | // Cart collision detection | ||
42 | CGSize first = [cartSprite boundingBox].size; | ||
43 | CGSize second = [object.sprite boundingBox].size; | ||
44 | |||
45 | if (cartSprite.position.x > (object.sprite.position.x - second.width/2 - first.width/2)) | ||
46 | { | ||
47 | if (cartSprite.position.x < (object.sprite.position.x + second.width/2 + first.width/2)) | ||
48 | { | ||
49 | if (cartSprite.position.y > (object.sprite.position.y - second.height/2 - first.height/2)) | ||
50 | { | ||
51 | if (cartSprite.position.y < (object.sprite.position.y + second.height/2 + first.height/2)) | ||
52 | { | ||
53 | [object retain]; | ||
54 | [objects removeObject:object]; | ||
55 | |||
56 | // If a cart collides with an object, it's going to vanish no matter what | ||
57 | [object.sprite.parent removeChild:object.sprite cleanup:YES]; | ||
58 | |||
59 | NSString* audioFile = nil; | ||
60 | if ([object isKindOfClass:[OneUp class]]) | ||
61 | { | ||
62 | audioFile = [[NSBundle mainBundle] pathForResource:@"1up" ofType:@"wav"]; | ||
63 | lives++; | ||
64 | } else if ([object isKindOfClass:[Rock class]]) | ||
65 | { | ||
66 | audioFile = [[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]; | ||
67 | lives--; | ||
68 | } else if ([object conformsToProtocol:@protocol(ValuableObject)]) { | ||
69 | audioFile = [[NSBundle mainBundle] pathForResource:@"Item1" ofType:@"wav"]; | ||
70 | score += [((FallingObject<ValuableObject>*)object) pointValue]; | ||
71 | } | ||
72 | |||
73 | if (audioFile != nil) | ||
74 | { | ||
75 | [[SimpleAudioEngine sharedEngine] playEffect:audioFile]; | ||
76 | } | ||
77 | |||
78 | [self updateLabels]; | ||
79 | |||
80 | continue; // Don't check for collision with floor | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | |||
86 | // Collision detection with floor | ||
87 | if (object.sprite.position.y - (object.sprite.contentSize.height/2) < 0) | ||
88 | { | ||
89 | [object retain]; | ||
90 | [objects removeObject:object]; | ||
91 | |||
92 | [object.sprite.parent removeChild:object.sprite cleanup:YES]; | ||
93 | |||
94 | if ([object conformsToProtocol:@protocol(ValuableObject)]) | ||
95 | { | ||
96 | NSString* audioFile = [[NSBundle mainBundle] pathForResource:@"Damage1" ofType:@"wav"]; | ||
97 | [[SimpleAudioEngine sharedEngine] playEffect:audioFile]; | ||
98 | |||
99 | lives--; | ||
100 | |||
101 | [self updateLabels]; | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | |||
106 | if (lives == 0) | ||
107 | { | ||
108 | [self unschedule:@selector(randomlyAddObject:)]; | ||
109 | [self unschedule:@selector(tick:)]; | ||
110 | [[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInT transitionWithDuration:1.5f scene:[GameOverLayer sceneWithScore:score]]]; | ||
111 | } else if (score > lastScore) | ||
112 | { | ||
113 | if ((lastScore < 6500) && (score >= 6500)) | ||
114 | { | ||
115 | [self unschedule:@selector(randomlyAddObject:)]; | ||
116 | [self schedule:@selector(randomlyAddObject:) interval:0.6f]; | ||
117 | addSpeed = 0.6f; | ||
118 | } else if ((lastScore < 4500) && (score >= 4500)) | ||
119 | { | ||
120 | [self unschedule:@selector(randomlyAddObject:)]; | ||
121 | [self schedule:@selector(randomlyAddObject:) interval:0.7f]; | ||
122 | addSpeed = 0.7f; | ||
123 | } else if ((lastScore < 2500) && (score >= 2500)) | ||
124 | { | ||
125 | [self unschedule:@selector(randomlyAddObject:)]; | ||
126 | [self schedule:@selector(randomlyAddObject:) interval:0.8f]; | ||
127 | addSpeed = 0.8f; | ||
128 | } else if ((lastScore < 1500) && (score >= 1500)) | ||
129 | { | ||
130 | [self unschedule:@selector(randomlyAddObject:)]; | ||
131 | [self schedule:@selector(randomlyAddObject:) interval:0.9f]; | ||
132 | addSpeed = 0.9f; | ||
133 | } else if ((lastScore < 500) && (score >= 500)) | ||
134 | { | ||
135 | [self unschedule:@selector(randomlyAddObject:)]; | ||
136 | [self schedule:@selector(randomlyAddObject:) interval:1.0f]; | ||
137 | addSpeed = 1.0f; | ||
138 | } else if ((lastScore < 150) && (score >= 150)) | ||
139 | { | ||
140 | [self unschedule:@selector(randomlyAddObject:)]; | ||
141 | [self schedule:@selector(randomlyAddObject:) interval:2.0f]; | ||
142 | addSpeed = 2.0f; | ||
143 | } | ||
144 | } | ||
145 | } | ||
146 | |||
147 | - (void)randomlyAddObject:(ccTime)dt | ||
148 | { | ||
149 | FallingObject* object; | ||
150 | int oneuppercent = 98 - (lives == 1 ? 1 : 0); | ||
151 | |||
152 | if (score < 1000) | ||
153 | { | ||
154 | int randomval = arc4random()%100; | ||
155 | |||
156 | if (randomval < 65) | ||
157 | { | ||
158 | object = [[Cherry alloc] init]; | ||
159 | } else if (randomval < oneuppercent) | ||
160 | { | ||
161 | object = [[Bottle alloc] init]; | ||
162 | } else { | ||
163 | object = [[OneUp alloc] init]; | ||
164 | } | ||
165 | } else { | ||
166 | int randomval = arc4random()%100; | ||
167 | |||
168 | if (randomval < 40) | ||
169 | { | ||
170 | object = [[Cherry alloc] init]; | ||
171 | } else if (randomval < 70) | ||
172 | { | ||
173 | object = [[Rock alloc] init]; | ||
174 | } else if (randomval < oneuppercent) | ||
175 | { | ||
176 | object = [[Bottle alloc] init]; | ||
177 | } else { | ||
178 | object = [[OneUp alloc] init]; | ||
179 | } | ||
180 | } | ||
181 | |||
182 | int objectX = arc4random()%448+16; | ||
183 | object.sprite.position = ccp(objectX, 360); | ||
184 | object.sprite.scale = 1; | ||
185 | [self addChild:object.sprite]; | ||
186 | |||
187 | [objects addObject:object]; | ||
188 | [object release]; | ||
189 | |||
190 | if (score >= 2000) | ||
191 | { | ||
192 | if (arc4random() % 100 > 80) | ||
193 | { | ||
194 | object = [[Rock alloc] init]; | ||
195 | |||
196 | objectX = arc4random()%448+16; | ||
197 | object.sprite.position = ccp(objectX, 360); | ||
198 | object.sprite.scale = 1; | ||
199 | [self addChild:object.sprite]; | ||
200 | |||
201 | [objects addObject:object]; | ||
202 | [object release]; | ||
203 | } | ||
204 | } | ||
205 | |||
206 | if (score >= 4000) | ||
207 | { | ||
208 | if (arc4random() % 100 > 80) | ||
209 | { | ||
210 | object = [[Rock alloc] init]; | ||
211 | |||
212 | objectX = arc4random()%448+16; | ||
213 | object.sprite.position = ccp(objectX, 360); | ||
214 | object.sprite.scale = 1; | ||
215 | [self addChild:object.sprite]; | ||
216 | |||
217 | [objects addObject:object]; | ||
218 | [object release]; | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | |||
223 | - (id)init | ||
224 | { | ||
225 | self = [super init]; | ||
226 | |||
227 | int winWidth = [CCDirector sharedDirector].winSize.width; | ||
228 | //int winHeight = [CCDirector sharedDirector].winSize.height; | ||
229 | int cartScale = 2; | ||
230 | |||
231 | if (self != nil) | ||
232 | { | ||
233 | CCSprite* backgroundImage = [CCSprite spriteWithFile:@"SeaBeach.png"]; | ||
234 | backgroundImage.position = ccp(240, 160); | ||
235 | [self addChild:backgroundImage z:0]; | ||
236 | |||
237 | isAccelerometerEnabled_ = YES; | ||
238 | |||
239 | //cart = [[Cart alloc] init]; | ||
240 | cartSprite = [CCSprite spriteWithFile:@"cart.png"]; | ||
241 | cartSprite.position = ccp(winWidth/2, 22); | ||
242 | cartSprite.scale = cartScale; | ||
243 | [self addChild:cartSprite]; | ||
244 | |||
245 | objects = [[NSMutableSet alloc] init]; | ||
246 | |||
247 | score = 0; | ||
248 | lives = 3; | ||
249 | |||
250 | scoreLabel = [CCLabelBMFont labelWithString:@"Score: 0" fntFile:@"helvetica2.fnt"]; | ||
251 | scoreLabel.position = ccp(50, 300); | ||
252 | [self addChild:scoreLabel]; | ||
253 | |||
254 | livesLabel = [CCLabelBMFont labelWithString:@"Lives: 3" fntFile:@"helvetica2.fnt"]; | ||
255 | livesLabel.position = ccp(50, 280); | ||
256 | [self addChild:livesLabel]; | ||
257 | |||
258 | CCMenuItemImage* pauseButton = [CCMenuItemImage itemFromNormalImage:@"pause2.png" selectedImage:@"pause.png" target:self selector:@selector(pause)]; | ||
259 | CCMenu* pauseMenu = [CCMenu menuWithItems:pauseButton, nil]; | ||
260 | [pauseMenu setPosition:ccp(480-8-16, 320-8-16)]; | ||
261 | [self addChild:pauseMenu]; | ||
262 | |||
263 | addSpeed = 2.5f; | ||
264 | } | ||
265 | |||
266 | return self; | ||
267 | } | ||
268 | |||
269 | -(void) onEnter | ||
270 | { | ||
271 | [super onEnter]; | ||
272 | |||
273 | [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)]; | ||
274 | [self schedule:@selector(tick:) interval:1.0f/60.0f]; | ||
275 | [self schedule:@selector(randomlyAddObject:) interval:addSpeed]; | ||
276 | } | ||
277 | |||
278 | - (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration | ||
279 | { | ||
280 | static float prevY=0; | ||
281 | |||
282 | #define kFilterFactor 0.05f | ||
283 | |||
284 | float accelY = -((float) acceleration.y * kFilterFactor + (1- kFilterFactor)*prevY); | ||
285 | |||
286 | prevY = accelY; | ||
287 | accelX = accelY * 750; | ||
288 | } | ||
289 | |||
290 | - (void)updateLabels | ||
291 | { | ||
292 | [scoreLabel setString:[NSString stringWithFormat:@"Score: %d", score]]; | ||
293 | [livesLabel setString:[NSString stringWithFormat:@"Lives: %d", lives]]; | ||
294 | } | ||
295 | |||
296 | - (void)pause | ||
297 | { | ||
298 | [[CCDirector sharedDirector] replaceScene:[PauseLayer sceneWithScene:[[CCDirector sharedDirector] runningScene]]]; | ||
299 | } | ||
300 | |||
301 | @end | ||
diff --git a/Classes/GameOverLayer.h b/Classes/GameOverLayer.h new file mode 100755 index 0000000..ea533ac --- /dev/null +++ b/Classes/GameOverLayer.h | |||
@@ -0,0 +1,32 @@ | |||
1 | // | ||
2 | // GameOverLayer.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 "cocos2d.h" | ||
11 | #import "Cart_CollectAppDelegate.h" | ||
12 | #import <sqlite3.h> | ||
13 | #import "cocoslive.h" | ||
14 | |||
15 | @class MainMenuLayer; | ||
16 | |||
17 | @interface GameOverLayer : CCLayer <UITextFieldDelegate, UIAlertViewDelegate> { | ||
18 | UILabel* scoreField; | ||
19 | UITextField* textField; | ||
20 | UISwitch* submitSwitch; | ||
21 | UIActivityIndicatorView* activityIndicator; | ||
22 | UIButton* backButton; | ||
23 | int score; | ||
24 | } | ||
25 | |||
26 | + (CCScene*)sceneWithScore:(int)score; | ||
27 | - (id)initWithScore:(int)score; | ||
28 | - (void)newgame; | ||
29 | - (void)submitScore; | ||
30 | - (void)exit; | ||
31 | |||
32 | @end | ||
diff --git a/Classes/GameOverLayer.m b/Classes/GameOverLayer.m new file mode 100755 index 0000000..65b11e1 --- /dev/null +++ b/Classes/GameOverLayer.m | |||
@@ -0,0 +1,196 @@ | |||
1 | // | ||
2 | // GameOverLayer.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 "GameOverLayer.h" | ||
10 | |||
11 | |||
12 | @implementation GameOverLayer | ||
13 | |||
14 | + (CCScene*)sceneWithScore:(int)score | ||
15 | { | ||
16 | CCScene* scene = [CCScene node]; | ||
17 | |||
18 | CCLayerColor* backgroundLayer = [CCLayerColor layerWithColor:ccc4(255, 255, 255, 255)]; | ||
19 | [scene addChild:backgroundLayer]; | ||
20 | |||
21 | GameOverLayer* layer = [[[GameOverLayer alloc] initWithScore:score] autorelease]; | ||
22 | [scene addChild:layer]; | ||
23 | |||
24 | return scene; | ||
25 | } | ||
26 | |||
27 | - (id)initWithScore:(int)score2 | ||
28 | { | ||
29 | self = [super init]; | ||
30 | |||
31 | if (nil != self) | ||
32 | { | ||
33 | CCSprite* backgroundImage = [CCSprite spriteWithFile:@"Morning1.png"]; | ||
34 | backgroundImage.position = ccp(240, 160); | ||
35 | [self addChild:backgroundImage z:0]; | ||
36 | |||
37 | score = score2; | ||
38 | |||
39 | scoreField = [[UILabel alloc] initWithFrame:CGRectMake(205, 320-200-320, 0, 0)]; | ||
40 | [scoreField setFont:[UIFont systemFontOfSize:20.0f]]; | ||
41 | [scoreField setBackgroundColor:[UIColor clearColor]]; | ||
42 | [scoreField setText:[NSString stringWithFormat:@"%d", score2]]; | ||
43 | CGSize labelSize = [scoreField.text sizeWithFont:scoreField.font constrainedToSize:CGSizeMake(160, 31) lineBreakMode:UILineBreakModeClip]; | ||
44 | [scoreField setFrame:CGRectMake(scoreField.frame.origin.x, scoreField.frame.origin.y, labelSize.width, labelSize.height)]; | ||
45 | [[[CCDirector sharedDirector] openGLView] addSubview:scoreField]; | ||
46 | |||
47 | textField = [[UITextField alloc] initWithFrame:CGRectMake(205, 320-247-320, 216, 31)]; | ||
48 | [textField setFont:[UIFont systemFontOfSize:20.0f]]; | ||
49 | [textField setBackgroundColor:[UIColor clearColor]]; | ||
50 | [textField setDelegate:self]; | ||
51 | NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | ||
52 | [textField setText:[defaults objectForKey:@"username"]]; | ||
53 | [[[CCDirector sharedDirector] openGLView] addSubview:textField]; | ||
54 | |||
55 | submitSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(211, 320-161-320, 0, 0)]; | ||
56 | [submitSwitch setOn:[defaults boolForKey:@"submitScore"]]; | ||
57 | [[[CCDirector sharedDirector] openGLView] addSubview:submitSwitch]; | ||
58 | |||
59 | activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(480-20-10, 320-20-10, 20, 20)]; | ||
60 | [[[CCDirector sharedDirector] openGLView] addSubview:activityIndicator]; | ||
61 | |||
62 | backButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; | ||
63 | [backButton setFrame:CGRectMake(240-154/2, 320-60-15-320, 154, 31)]; | ||
64 | [backButton setTitle:@"Back to Main Menu" forState:UIControlStateNormal]; | ||
65 | [backButton addTarget:self action:@selector(newgame) forControlEvents:UIControlEventTouchUpInside]; | ||
66 | [backButton.titleLabel setFont:[UIFont systemFontOfSize:16.0]]; | ||
67 | [backButton.titleLabel setTextColor:[UIColor blackColor]]; | ||
68 | |||
69 | [[[CCDirector sharedDirector] openGLView] addSubview:backButton]; | ||
70 | } | ||
71 | |||
72 | return self; | ||
73 | } | ||
74 | |||
75 | - (void)onEnter | ||
76 | { | ||
77 | [UIView beginAnimations:nil context:NULL]; | ||
78 | [UIView setAnimationDuration:1.5f]; | ||
79 | [UIView setAnimationCurve:UIViewAnimationCurveLinear]; | ||
80 | scoreField.transform = CGAffineTransformMakeTranslation(0, 320); | ||
81 | textField.transform = CGAffineTransformMakeTranslation(0, 320); | ||
82 | submitSwitch.transform = CGAffineTransformMakeTranslation(0, 320); | ||
83 | backButton.transform = CGAffineTransformMakeTranslation(0, 320); | ||
84 | [UIView commitAnimations]; | ||
85 | } | ||
86 | |||
87 | - (void)newgame | ||
88 | { | ||
89 | backButton.enabled = NO; | ||
90 | textField.enabled = NO; | ||
91 | submitSwitch.enabled = NO; | ||
92 | |||
93 | const char* sqlQuery = [[NSString stringWithFormat:@"INSERT INTO highscores (name, score) VALUES (\"%@\",%d)", [textField text], score] UTF8String]; | ||
94 | sqlite3_stmt* compiled_statement; | ||
95 | |||
96 | if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) | ||
97 | { | ||
98 | sqlite3_step(compiled_statement); | ||
99 | NSLog(@"awesome, %@", [textField text]); | ||
100 | } else { | ||
101 | NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg([Cart_CollectAppDelegate database])); | ||
102 | } | ||
103 | |||
104 | if (submitSwitch.on) | ||
105 | { | ||
106 | [self submitScore]; | ||
107 | } else { | ||
108 | [self exit]; | ||
109 | } | ||
110 | } | ||
111 | |||
112 | - (void)submitScore | ||
113 | { | ||
114 | [activityIndicator startAnimating]; | ||
115 | |||
116 | CLScoreServerPost* server = [[CLScoreServerPost alloc] initWithGameName:@"Cart Collect" gameKey:@"38f440a074b3264386455a36b2706d8f" delegate:self]; | ||
117 | NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; | ||
118 | [dict setObject:@"Classic" forKey:@"cc_category"]; | ||
119 | [dict setObject:[textField text] forKey:@"cc_playername"]; | ||
120 | [dict setObject:[NSNumber numberWithInt:score] forKey:@"cc_score"]; | ||
121 | [server sendScore:dict]; | ||
122 | [server release]; | ||
123 | [dict release]; | ||
124 | } | ||
125 | |||
126 | - (BOOL)textFieldShouldReturn:(UITextField *)m_textField | ||
127 | { | ||
128 | [m_textField resignFirstResponder]; | ||
129 | |||
130 | return YES; | ||
131 | } | ||
132 | |||
133 | - (void)scorePostOk:(id)sender | ||
134 | { | ||
135 | [activityIndicator stopAnimating]; | ||
136 | |||
137 | // Score post successful | ||
138 | [self exit]; | ||
139 | } | ||
140 | |||
141 | - (void)scorePostFail:(id)sender | ||
142 | { | ||
143 | [activityIndicator stopAnimating]; | ||
144 | |||
145 | // score post failed | ||
146 | tPostStatus status = [sender postStatus]; | ||
147 | if( status == kPostStatusPostFailed ) { | ||
148 | NSLog(@"SERVER ERROR"); | ||
149 | // an error with the server ? | ||
150 | // try again | ||
151 | }else if( status == kPostStatusConnectionFailed ) { | ||
152 | NSLog(@"CONNECTION FAILURE"); | ||
153 | // a error establishing the connection ? | ||
154 | // turn-on wifi, and then try again | ||
155 | } | ||
156 | |||
157 | UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Whoops" message:@"There was an error posting your score. Please make sure you have Internet access." delegate:self cancelButtonTitle:@"Try Again" otherButtonTitles:@"Cancel", nil]; | ||
158 | [alertView show]; | ||
159 | [alertView release]; | ||
160 | } | ||
161 | |||
162 | - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex | ||
163 | { | ||
164 | if (buttonIndex == 0) | ||
165 | { | ||
166 | [self submitScore]; | ||
167 | } else if (buttonIndex == 1) | ||
168 | { | ||
169 | [self exit]; | ||
170 | } | ||
171 | } | ||
172 | |||
173 | - (void)exit | ||
174 | { | ||
175 | NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | ||
176 | [defaults setObject:[textField text] forKey:@"username"]; | ||
177 | [defaults setBool:submitSwitch.on forKey:@"submitScore"]; | ||
178 | |||
179 | [submitSwitch removeFromSuperview]; | ||
180 | [submitSwitch release]; | ||
181 | |||
182 | [textField removeFromSuperview]; | ||
183 | [textField release]; | ||
184 | |||
185 | [scoreField removeFromSuperview]; | ||
186 | [scoreField release]; | ||
187 | |||
188 | [activityIndicator removeFromSuperview]; | ||
189 | [activityIndicator release]; | ||
190 | |||
191 | [backButton removeFromSuperview]; | ||
192 | |||
193 | [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; | ||
194 | } | ||
195 | |||
196 | @end | ||
diff --git a/Classes/Highscore.h b/Classes/Highscore.h new file mode 100755 index 0000000..4cab75f --- /dev/null +++ b/Classes/Highscore.h | |||
@@ -0,0 +1,25 @@ | |||
1 | // | ||
2 | // Highscore.h | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/20/11. | ||
6 | // Copyright 2011 __MyCompanyName__. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import <Foundation/Foundation.h> | ||
10 | #import <sqlite3.h> | ||
11 | #import "Cart_CollectAppDelegate.h" | ||
12 | #import "cocoslive.h" | ||
13 | |||
14 | @interface Highscore : NSObject { | ||
15 | NSString* name; | ||
16 | int score; | ||
17 | NSDate* date; | ||
18 | } | ||
19 | |||
20 | @property (readonly) NSString* name; | ||
21 | @property (readonly) int score; | ||
22 | @property (readonly) NSDate* date; | ||
23 | - (id)initWithName:(NSString*)name score:(int)score date:(NSDate*)date; | ||
24 | |||
25 | @end | ||
diff --git a/Classes/Highscore.m b/Classes/Highscore.m new file mode 100755 index 0000000..7239cca --- /dev/null +++ b/Classes/Highscore.m | |||
@@ -0,0 +1,37 @@ | |||
1 | // | ||
2 | // Highscore.m | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/20/11. | ||
6 | // Copyright 2011 __MyCompanyName__. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import "Highscore.h" | ||
10 | |||
11 | |||
12 | @implementation Highscore | ||
13 | |||
14 | @synthesize name, score, date; | ||
15 | |||
16 | - (id)initWithName:(NSString*)m_name score:(int)m_score date:(NSDate*)m_date | ||
17 | { | ||
18 | self = [super init]; | ||
19 | |||
20 | if (nil != self) | ||
21 | { | ||
22 | name = [m_name retain]; | ||
23 | score = m_score; | ||
24 | date = [m_date retain]; | ||
25 | } | ||
26 | |||
27 | return self; | ||
28 | } | ||
29 | |||
30 | - (void)dealloc | ||
31 | { | ||
32 | [name release]; | ||
33 | [date release]; | ||
34 | [super dealloc]; | ||
35 | } | ||
36 | |||
37 | @end | ||
diff --git a/Classes/HighscoreListController.h b/Classes/HighscoreListController.h new file mode 100755 index 0000000..f673609 --- /dev/null +++ b/Classes/HighscoreListController.h | |||
@@ -0,0 +1,32 @@ | |||
1 | // | ||
2 | // HighscoreListController.h | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/20/11. | ||
6 | // Copyright 2011 __MyCompanyName__. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import <UIKit/UIKit.h> | ||
10 | #import "Highscore.h" | ||
11 | #import "cocoslive.h" | ||
12 | #import "RootViewController.h" | ||
13 | |||
14 | @interface HighscoreListController : UITableViewController { | ||
15 | UINavigationBar* navigationBar; | ||
16 | UINavigationItem* myNavigationItem; | ||
17 | NSArray* localHighscores; | ||
18 | NSArray* globalHighscores; | ||
19 | BOOL showGlobal; | ||
20 | BOOL loadingGlobal; | ||
21 | UIView* loadingView; | ||
22 | UIActivityIndicatorView* activity; | ||
23 | UILabel* statusText; | ||
24 | UITableView* tableView; | ||
25 | } | ||
26 | |||
27 | - (void)back; | ||
28 | - (void)switchLists:(id)sender; | ||
29 | - (void)scoreRequestOk:(id)sender; | ||
30 | - (void)scoreRequestFail:(id)sender; | ||
31 | |||
32 | @end | ||
diff --git a/Classes/HighscoreListController.m b/Classes/HighscoreListController.m new file mode 100755 index 0000000..9980727 --- /dev/null +++ b/Classes/HighscoreListController.m | |||
@@ -0,0 +1,371 @@ | |||
1 | // | ||
2 | // HighscoreListController.m | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/20/11. | ||
6 | // Copyright 2011 __MyCompanyName__. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import "HighscoreListController.h" | ||
10 | |||
11 | |||
12 | @implementation HighscoreListController | ||
13 | |||
14 | |||
15 | #pragma mark - | ||
16 | #pragma mark Initialization | ||
17 | |||
18 | - (id)initWithStyle:(UITableViewStyle)style { | ||
19 | // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. | ||
20 | self = [super initWithStyle:style]; | ||
21 | if (self) { | ||
22 | NSMutableArray* highscores = [NSMutableArray arrayWithCapacity:15]; | ||
23 | const char* sqlQuery = "SELECT * FROM highscores ORDER BY score DESC LIMIT 15"; | ||
24 | sqlite3_stmt* compiled_statement; | ||
25 | |||
26 | if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) | ||
27 | { | ||
28 | while (sqlite3_step(compiled_statement) == SQLITE_ROW) | ||
29 | { | ||
30 | NSString* name = [NSString stringWithUTF8String:(char*)sqlite3_column_text(compiled_statement, 1)]; | ||
31 | int score = sqlite3_column_int(compiled_statement, 2); | ||
32 | |||
33 | NSDate* date = nil; | ||
34 | char* dateStr = (char*)sqlite3_column_text(compiled_statement, 3); | ||
35 | if (dateStr != NULL) | ||
36 | { | ||
37 | NSString* theDate = [NSString stringWithUTF8String:dateStr]; | ||
38 | NSDateComponents* comps = [[NSDateComponents alloc] init]; | ||
39 | [comps setYear:[[theDate substringToIndex:4] intValue]]; | ||
40 | [comps setMonth:[[theDate substringWithRange:NSMakeRange(5, 2)] intValue]]; | ||
41 | [comps setDay:[[theDate substringWithRange:NSMakeRange(8, 2)] intValue]]; | ||
42 | [comps setHour:[[theDate substringWithRange:NSMakeRange(11, 2)] intValue]]; | ||
43 | [comps setMinute:[[theDate substringWithRange:NSMakeRange(14, 2)] intValue]]; | ||
44 | [comps setSecond:[[theDate substringWithRange:NSMakeRange(17, 2)] intValue]]; | ||
45 | date = [[NSCalendar currentCalendar] dateFromComponents:comps]; | ||
46 | date = [date dateByAddingTimeInterval:[[NSTimeZone localTimeZone] secondsFromGMT]]; | ||
47 | [comps release]; | ||
48 | } | ||
49 | |||
50 | Highscore* highscore = [[Highscore alloc] initWithName:name score:score date:date]; | ||
51 | [highscores addObject:highscore]; | ||
52 | [highscore release]; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | localHighscores = [highscores copy]; | ||
57 | |||
58 | navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; | ||
59 | myNavigationItem = [[UINavigationItem alloc] initWithTitle:@"Highscores"]; | ||
60 | UIBarButtonItem* barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(back)]; | ||
61 | myNavigationItem.leftBarButtonItem = barButton; | ||
62 | [barButton release]; | ||
63 | |||
64 | UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Local", @"Global", nil]]; | ||
65 | segmentedControl.selectedSegmentIndex = 0; | ||
66 | segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; | ||
67 | [segmentedControl addTarget:self action:@selector(switchLists:) forControlEvents:UIControlEventValueChanged]; | ||
68 | UIBarButtonItem* barButton2 = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl]; | ||
69 | [segmentedControl release]; | ||
70 | myNavigationItem.rightBarButtonItem = barButton2; | ||
71 | [barButton2 release]; | ||
72 | |||
73 | [navigationBar pushNavigationItem:myNavigationItem animated:NO]; | ||
74 | |||
75 | showGlobal = NO; | ||
76 | loadingGlobal = NO; | ||
77 | |||
78 | tableView = [(UITableView*)self.view retain]; | ||
79 | UIView* parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; | ||
80 | [tableView setFrame:CGRectMake(0, 44, 320, 480-44)]; | ||
81 | [parentView addSubview:navigationBar]; | ||
82 | [parentView addSubview:tableView]; | ||
83 | self.view = parentView; | ||
84 | [parentView release]; | ||
85 | } | ||
86 | return self; | ||
87 | } | ||
88 | |||
89 | |||
90 | #pragma mark - | ||
91 | #pragma mark View lifecycle | ||
92 | |||
93 | /* | ||
94 | - (void)viewDidLoad { | ||
95 | [super viewDidLoad]; | ||
96 | |||
97 | // Uncomment the following line to display an Edit button in the navigation bar for this view controller. | ||
98 | // self.navigationItem.rightBarButtonItem = self.editButtonItem; | ||
99 | } | ||
100 | */ | ||
101 | |||
102 | /* | ||
103 | - (void)viewWillAppear:(BOOL)animated { | ||
104 | [super viewWillAppear:animated]; | ||
105 | } | ||
106 | */ | ||
107 | /* | ||
108 | - (void)viewDidAppear:(BOOL)animated { | ||
109 | [super viewDidAppear:animated]; | ||
110 | } | ||
111 | */ | ||
112 | /* | ||
113 | - (void)viewWillDisappear:(BOOL)animated { | ||
114 | [super viewWillDisappear:animated]; | ||
115 | } | ||
116 | */ | ||
117 | /* | ||
118 | - (void)viewDidDisappear:(BOOL)animated { | ||
119 | [super viewDidDisappear:animated]; | ||
120 | } | ||
121 | */ | ||
122 | /* | ||
123 | // Override to allow orientations other than the default portrait orientation. | ||
124 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { | ||
125 | // Return YES for supported orientations. | ||
126 | return YES; | ||
127 | } | ||
128 | */ | ||
129 | |||
130 | |||
131 | #pragma mark - | ||
132 | #pragma mark Table view data source | ||
133 | |||
134 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | ||
135 | // Return the number of sections. | ||
136 | return 1; | ||
137 | } | ||
138 | |||
139 | |||
140 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | ||
141 | // Return the number of rows in the section. | ||
142 | if (showGlobal) | ||
143 | { | ||
144 | return [globalHighscores count]; | ||
145 | } else { | ||
146 | return [localHighscores count]; | ||
147 | } | ||
148 | } | ||
149 | |||
150 | |||
151 | // Customize the appearance of table view cells. | ||
152 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | ||
153 | { | ||
154 | NSString* cellIdentifier; | ||
155 | Highscore* highscore; | ||
156 | |||
157 | // Configure the cell... | ||
158 | if (showGlobal) | ||
159 | { | ||
160 | cellIdentifier = [NSString stringWithFormat:@"Global %d", [indexPath row]]; | ||
161 | highscore = [globalHighscores objectAtIndex:[indexPath row]]; | ||
162 | } else { | ||
163 | cellIdentifier = [NSString stringWithFormat:@"Local %d", [indexPath row]]; | ||
164 | highscore = [localHighscores objectAtIndex:[indexPath row]]; | ||
165 | } | ||
166 | |||
167 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; | ||
168 | if (cell == nil) { | ||
169 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier] autorelease]; | ||
170 | } | ||
171 | |||
172 | cell.textLabel.text = highscore.name; | ||
173 | |||
174 | if (highscore.date != nil) | ||
175 | { | ||
176 | NSDate* todayDate = [NSDate date]; | ||
177 | double ti = [highscore.date timeIntervalSinceDate:todayDate]; | ||
178 | ti = ti * -1; | ||
179 | |||
180 | if (ti < 1) | ||
181 | { | ||
182 | cell.detailTextLabel.text = @"What is this I don't even"; | ||
183 | } else if (ti < 60) | ||
184 | { | ||
185 | cell.detailTextLabel.text = @"Less than a minute ago"; | ||
186 | } else if (ti < 3600) | ||
187 | { | ||
188 | int diff = round(ti / 60); | ||
189 | cell.detailTextLabel.text = [NSString stringWithFormat:@"%d minutes ago", diff]; | ||
190 | } else if (ti < 86400) | ||
191 | { | ||
192 | int diff = round(ti / 60 / 60); | ||
193 | cell.detailTextLabel.text = [NSString stringWithFormat:@"%d hours ago", diff]; | ||
194 | } else { | ||
195 | NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; | ||
196 | [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; | ||
197 | [dateFormatter setDateStyle:NSDateFormatterLongStyle]; | ||
198 | cell.detailTextLabel.text = [dateFormatter stringFromDate:highscore.date]; | ||
199 | [dateFormatter release]; | ||
200 | } | ||
201 | } | ||
202 | |||
203 | UILabel* scoreLabel = [[UILabel alloc] init]; | ||
204 | scoreLabel.text = [NSString stringWithFormat:@"%d", highscore.score]; | ||
205 | CGSize labelSize = [scoreLabel.text sizeWithFont:scoreLabel.font constrainedToSize:CGSizeMake(160, 44) lineBreakMode:UILineBreakModeClip]; | ||
206 | scoreLabel.frame = CGRectMake(320-10-labelSize.width, 22-labelSize.height/2, labelSize.width, labelSize.height); | ||
207 | [cell addSubview:scoreLabel]; | ||
208 | [scoreLabel release]; | ||
209 | |||
210 | cell.selectionStyle = UITableViewCellSelectionStyleNone; | ||
211 | |||
212 | return cell; | ||
213 | } | ||
214 | |||
215 | |||
216 | /* | ||
217 | // Override to support conditional editing of the table view. | ||
218 | - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { | ||
219 | // Return NO if you do not want the specified item to be editable. | ||
220 | return YES; | ||
221 | } | ||
222 | */ | ||
223 | |||
224 | |||
225 | /* | ||
226 | // Override to support editing the table view. | ||
227 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { | ||
228 | |||
229 | if (editingStyle == UITableViewCellEditingStyleDelete) { | ||
230 | // Delete the row from the data source. | ||
231 | [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; | ||
232 | } | ||
233 | else if (editingStyle == UITableViewCellEditingStyleInsert) { | ||
234 | // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. | ||
235 | } | ||
236 | } | ||
237 | */ | ||
238 | |||
239 | |||
240 | /* | ||
241 | // Override to support rearranging the table view. | ||
242 | - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { | ||
243 | } | ||
244 | */ | ||
245 | |||
246 | |||
247 | /* | ||
248 | // Override to support conditional rearranging of the table view. | ||
249 | - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { | ||
250 | // Return NO if you do not want the item to be re-orderable. | ||
251 | return YES; | ||
252 | } | ||
253 | */ | ||
254 | |||
255 | |||
256 | #pragma mark - | ||
257 | #pragma mark Table view delegate | ||
258 | |||
259 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | ||
260 | // Navigation logic may go here. Create and push another view controller. | ||
261 | /* | ||
262 | <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; | ||
263 | // ... | ||
264 | // Pass the selected object to the new view controller. | ||
265 | [self.navigationController pushViewController:detailViewController animated:YES]; | ||
266 | [detailViewController release]; | ||
267 | */ | ||
268 | } | ||
269 | |||
270 | |||
271 | #pragma mark - | ||
272 | #pragma mark Memory management | ||
273 | |||
274 | - (void)didReceiveMemoryWarning { | ||
275 | // Releases the view if it doesn't have a superview. | ||
276 | [super didReceiveMemoryWarning]; | ||
277 | |||
278 | // Relinquish ownership any cached data, images, etc. that aren't in use. | ||
279 | } | ||
280 | |||
281 | - (void)viewDidUnload { | ||
282 | // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. | ||
283 | // For example: self.myOutlet = nil; | ||
284 | } | ||
285 | |||
286 | |||
287 | - (void)dealloc { | ||
288 | [super dealloc]; | ||
289 | } | ||
290 | |||
291 | - (void)back | ||
292 | { | ||
293 | RootViewController* viewController = [[[UIApplication sharedApplication] delegate] viewController]; | ||
294 | [[[[UIApplication sharedApplication] delegate] window] setRootViewController:viewController]; | ||
295 | } | ||
296 | |||
297 | - (void)switchLists:(id)sender | ||
298 | { | ||
299 | if ([(UISegmentedControl*)sender selectedSegmentIndex] == 0) | ||
300 | { | ||
301 | if (loadingGlobal) | ||
302 | { | ||
303 | [loadingView removeFromSuperview]; | ||
304 | [self.view addSubview:tableView]; | ||
305 | } | ||
306 | |||
307 | showGlobal = NO; | ||
308 | [tableView reloadData]; | ||
309 | } else { | ||
310 | if (globalHighscores == nil) | ||
311 | { | ||
312 | loadingGlobal = YES; | ||
313 | |||
314 | loadingView = [[UIView alloc] initWithFrame:CGRectMake(0, 44, 320, 480-44)]; | ||
315 | activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(150, 228-44, 20, 20)]; | ||
316 | activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; | ||
317 | statusText = [[UILabel alloc] initWithFrame:CGRectMake(0, 256-44, 320, 21)]; | ||
318 | statusText.text = @"Downloading highscores..."; | ||
319 | statusText.textAlignment = UITextAlignmentCenter; | ||
320 | |||
321 | [loadingView addSubview:activity]; | ||
322 | [loadingView addSubview:statusText]; | ||
323 | [loadingView setBackgroundColor:[UIColor whiteColor]]; | ||
324 | [activity startAnimating]; | ||
325 | [tableView removeFromSuperview]; | ||
326 | [self.view addSubview:loadingView]; | ||
327 | |||
328 | CLScoreServerRequest* request = [[CLScoreServerRequest alloc] initWithGameName:@"Cart Collect" delegate:self]; | ||
329 | tQueryFlags flags = kQueryFlagIgnore; | ||
330 | [request requestScores:kQueryAllTime limit:15 offset:0 flags:flags category:@"Classic"]; | ||
331 | [request release]; | ||
332 | } else { | ||
333 | showGlobal = YES; | ||
334 | [tableView reloadData]; | ||
335 | } | ||
336 | } | ||
337 | } | ||
338 | |||
339 | - (void)scoreRequestOk:(id)sender | ||
340 | { | ||
341 | NSArray* highscores = [sender parseScores]; | ||
342 | NSMutableArray* highscoreTemp = [[NSMutableArray alloc] init]; | ||
343 | |||
344 | for (NSDictionary* data in highscores) | ||
345 | { | ||
346 | NSString* name = [data objectForKey:@"cc_playername"]; | ||
347 | int score = [[data objectForKey:@"cc_score"] intValue]; | ||
348 | NSDate* date = [NSDate dateWithTimeIntervalSince1970:[[data objectForKey:@"cc_when"] intValue]]; | ||
349 | Highscore* highscore = [[Highscore alloc] initWithName:name score:score date:date]; | ||
350 | [highscoreTemp addObject:highscore]; | ||
351 | [highscore release]; | ||
352 | } | ||
353 | |||
354 | globalHighscores = [highscoreTemp copy]; | ||
355 | [highscoreTemp release]; | ||
356 | |||
357 | loadingGlobal = NO; | ||
358 | [loadingView removeFromSuperview]; | ||
359 | [self.view addSubview:tableView]; | ||
360 | showGlobal = YES; | ||
361 | [tableView reloadData]; | ||
362 | } | ||
363 | |||
364 | - (void)scoreRequestFail:(id)sender | ||
365 | { | ||
366 | [activity stopAnimating]; | ||
367 | [statusText setText:@"Unable to download highscores."]; | ||
368 | } | ||
369 | |||
370 | @end | ||
371 | |||
diff --git a/Classes/MainMenuLayer.h b/Classes/MainMenuLayer.h new file mode 100755 index 0000000..fc4f82f --- /dev/null +++ b/Classes/MainMenuLayer.h | |||
@@ -0,0 +1,24 @@ | |||
1 | // | ||
2 | // MainMenuLayer.h | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/20/11. | ||
6 | // Copyright 2011 __MyCompanyName__. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import <Foundation/Foundation.h> | ||
10 | #import "cocos2d.h" | ||
11 | #import "HighscoreListController.h" | ||
12 | |||
13 | @class GameLayer; | ||
14 | |||
15 | @interface MainMenuLayer : CCLayer { | ||
16 | |||
17 | } | ||
18 | |||
19 | + (CCScene*)scene; | ||
20 | - (id)init; | ||
21 | - (void)newgame; | ||
22 | - (void)highscores; | ||
23 | |||
24 | @end | ||
diff --git a/Classes/MainMenuLayer.m b/Classes/MainMenuLayer.m new file mode 100755 index 0000000..ac7f4a7 --- /dev/null +++ b/Classes/MainMenuLayer.m | |||
@@ -0,0 +1,68 @@ | |||
1 | // | ||
2 | // MainMenuLayer.m | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/20/11. | ||
6 | // Copyright 2011 __MyCompanyName__. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import "MainMenuLayer.h" | ||
10 | |||
11 | |||
12 | @implementation MainMenuLayer | ||
13 | |||
14 | + (CCScene*)scene | ||
15 | { | ||
16 | CCScene* scene = [CCScene node]; | ||
17 | |||
18 | MainMenuLayer* layer = [MainMenuLayer node]; | ||
19 | [scene addChild:layer]; | ||
20 | |||
21 | return scene; | ||
22 | } | ||
23 | |||
24 | - (id)init | ||
25 | { | ||
26 | self = [super init]; | ||
27 | |||
28 | if (nil != self) | ||
29 | { | ||
30 | CCSprite* backgroundImage = [CCSprite spriteWithFile:@"SeaBeach.png"]; | ||
31 | backgroundImage.position = ccp(240,160); | ||
32 | [self addChild:backgroundImage]; | ||
33 | |||
34 | CCLabelBMFont* titleText = [CCLabelBMFont labelWithString:@"Cart Collect - The Game!" fntFile:@"getoffthatboatrightnowyounglady.fnt"]; | ||
35 | titleText.position = ccp(240, 320-64); | ||
36 | [self addChild:titleText]; | ||
37 | |||
38 | //CCLabelBMFont* menuItemLabel1 = [CCLabelBMFont labelWithString:@"New Game" fntFile:@"getoffthatboatrightnowyounglady.fnt"]; | ||
39 | //CCMenuItemLabel* menuItem1 = [CCMenuItemLabel itemWithLabel:menuItemLabel1 target:self selector:@selector(newgame)]; | ||
40 | |||
41 | //CCLabelBMFont* menuItemLabel2 = [CCLabelBMFont labelWithString:@"Highscores" fntFile:@"getoffthatboatrightnowyounglady.fnt"]; | ||
42 | //CCMenuItemLabel* menuItem2 = [CCMenuItemLabel itemWithLabel:menuItemLabel2 target:self selector:@selector(highscores)]; | ||
43 | |||
44 | CCMenuItemImage* menuItem1 = [CCMenuItemImage itemFromNormalImage:@"newgame.png" selectedImage:@"newgame2.png" target:self selector:@selector(newgame)]; | ||
45 | CCMenuItemImage* menuItem2 = [CCMenuItemImage itemFromNormalImage:@"highscores.png" selectedImage:@"highscores2.png" target:self selector:@selector(highscores)]; | ||
46 | |||
47 | CCMenu* menu = [CCMenu menuWithItems:menuItem1, menuItem2, nil]; | ||
48 | [menu alignItemsVertically]; | ||
49 | menu.position = ccp(240, 100); | ||
50 | [self addChild:menu]; | ||
51 | } | ||
52 | |||
53 | return self; | ||
54 | } | ||
55 | |||
56 | - (void)newgame | ||
57 | { | ||
58 | [[CCDirector sharedDirector] replaceScene:[GameLayer scene]]; | ||
59 | } | ||
60 | |||
61 | - (void)highscores | ||
62 | { | ||
63 | HighscoreListController* listController = [[HighscoreListController alloc] initWithStyle:UITableViewStylePlain]; | ||
64 | [[[[UIApplication sharedApplication] delegate] window] setRootViewController:listController]; | ||
65 | [listController release]; | ||
66 | } | ||
67 | |||
68 | @end | ||
diff --git a/Classes/OneUp.h b/Classes/OneUp.h new file mode 100755 index 0000000..8bd4c66 --- /dev/null +++ b/Classes/OneUp.h | |||
@@ -0,0 +1,18 @@ | |||
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 new file mode 100755 index 0000000..e09935c --- /dev/null +++ b/Classes/OneUp.m | |||
@@ -0,0 +1,27 @@ | |||
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 | |||
11 | |||
12 | @implementation OneUp | ||
13 | |||
14 | - (id)init | ||
15 | { | ||
16 | self = [super init]; | ||
17 | |||
18 | if (nil != self) | ||
19 | { | ||
20 | sprite = [CCSprite spriteWithFile:@"oneup.png"]; | ||
21 | weight = 10; | ||
22 | } | ||
23 | |||
24 | return self; | ||
25 | } | ||
26 | |||
27 | @end | ||
diff --git a/Classes/PauseLayer.h b/Classes/PauseLayer.h new file mode 100755 index 0000000..aae5d6c --- /dev/null +++ b/Classes/PauseLayer.h | |||
@@ -0,0 +1,22 @@ | |||
1 | // | ||
2 | // PauseLayer.h | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/20/11. | ||
6 | // Copyright 2011 __MyCompanyName__. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import <Foundation/Foundation.h> | ||
10 | #import "cocos2d.h" | ||
11 | #import "GameLayer.h" | ||
12 | |||
13 | @interface PauseLayer : CCLayer { | ||
14 | CCScene* game; | ||
15 | } | ||
16 | |||
17 | + (CCScene*)sceneWithScene:(CCScene*)scene; | ||
18 | - (id)initWithScene:(CCScene*)scene; | ||
19 | - (void)unpause; | ||
20 | - (void)newgame; | ||
21 | |||
22 | @end | ||
diff --git a/Classes/PauseLayer.m b/Classes/PauseLayer.m new file mode 100755 index 0000000..53574b2 --- /dev/null +++ b/Classes/PauseLayer.m | |||
@@ -0,0 +1,68 @@ | |||
1 | // | ||
2 | // PauseLayer.m | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/20/11. | ||
6 | // Copyright 2011 __MyCompanyName__. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import "PauseLayer.h" | ||
10 | |||
11 | @implementation PauseLayer | ||
12 | |||
13 | + (CCScene*)sceneWithScene:(CCScene*)scene2 | ||
14 | { | ||
15 | CCScene* scene = [CCScene node]; | ||
16 | |||
17 | CCLayerColor* backgroundLayer = [CCLayerColor layerWithColor:ccc4(255, 255, 255, 255)]; | ||
18 | CCSprite* backgroundImage = [CCSprite spriteWithFile:@"SeaBeach.png"]; | ||
19 | backgroundImage.position = ccp(240,160); | ||
20 | [backgroundLayer addChild:backgroundImage]; | ||
21 | [scene addChild:backgroundLayer]; | ||
22 | |||
23 | CCLayerColor* backgroundLayer2 = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 127)]; | ||
24 | [scene addChild:backgroundLayer2]; | ||
25 | |||
26 | PauseLayer* layer = [[[PauseLayer alloc] initWithScene:scene2] autorelease]; | ||
27 | [scene addChild:layer]; | ||
28 | |||
29 | return scene; | ||
30 | } | ||
31 | |||
32 | - (id)initWithScene:(CCScene*)scene | ||
33 | { | ||
34 | self = [super init]; | ||
35 | |||
36 | if (nil != self) | ||
37 | { | ||
38 | game = [scene retain]; | ||
39 | |||
40 | CCLabelBMFont* scoreLabel = [CCLabelBMFont labelWithString:@"PAUSE" fntFile:@"helvetica.fnt"]; | ||
41 | scoreLabel.position = ccp(240,90); | ||
42 | [self addChild:scoreLabel]; | ||
43 | |||
44 | CCMenuItemImage* pauseButton = [CCMenuItemImage itemFromNormalImage:@"pause2.png" selectedImage:@"pause.png" target:self selector:@selector(unpause)]; | ||
45 | CCMenu* pauseMenu = [CCMenu menuWithItems:pauseButton, nil]; | ||
46 | [pauseMenu setPosition:ccp(480-8-16, 320-8-16)]; | ||
47 | [self addChild:pauseMenu]; | ||
48 | |||
49 | CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back2.png" target:self selector:@selector(newgame)]; | ||
50 | CCMenu* myMenu = [CCMenu menuWithItems:newgameMenuItem, nil]; | ||
51 | myMenu.position = ccp(240, 60); | ||
52 | [self addChild:myMenu]; | ||
53 | } | ||
54 | |||
55 | return self; | ||
56 | } | ||
57 | |||
58 | - (void)unpause | ||
59 | { | ||
60 | [[CCDirector sharedDirector] replaceScene:game]; | ||
61 | } | ||
62 | |||
63 | - (void)newgame | ||
64 | { | ||
65 | [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; | ||
66 | } | ||
67 | |||
68 | @end | ||
diff --git a/Classes/Rock.h b/Classes/Rock.h new file mode 100755 index 0000000..7382d99 --- /dev/null +++ b/Classes/Rock.h | |||
@@ -0,0 +1,18 @@ | |||
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 new file mode 100755 index 0000000..a3b3b9e --- /dev/null +++ b/Classes/Rock.m | |||
@@ -0,0 +1,27 @@ | |||
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 | |||
11 | |||
12 | @implementation Rock | ||
13 | |||
14 | - (id)init | ||
15 | { | ||
16 | self = [super init]; | ||
17 | |||
18 | if (nil != self) | ||
19 | { | ||
20 | sprite = [CCSprite spriteWithFile:@"rock.png"]; | ||
21 | weight = 7; | ||
22 | } | ||
23 | |||
24 | return self; | ||
25 | } | ||
26 | |||
27 | @end | ||
diff --git a/Classes/RootViewController.h b/Classes/RootViewController.h new file mode 100755 index 0000000..956c133 --- /dev/null +++ b/Classes/RootViewController.h | |||
@@ -0,0 +1,16 @@ | |||
1 | // | ||
2 | // RootViewController.h | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/18/11. | ||
6 | // Copyright __MyCompanyName__ 2011. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import <UIKit/UIKit.h> | ||
10 | |||
11 | |||
12 | @interface RootViewController : UIViewController { | ||
13 | |||
14 | } | ||
15 | |||
16 | @end | ||
diff --git a/Classes/RootViewController.m b/Classes/RootViewController.m new file mode 100755 index 0000000..edd67cb --- /dev/null +++ b/Classes/RootViewController.m | |||
@@ -0,0 +1,152 @@ | |||
1 | // | ||
2 | // RootViewController.m | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/18/11. | ||
6 | // Copyright __MyCompanyName__ 2011. All rights reserved. | ||
7 | // | ||
8 | |||
9 | // | ||
10 | // RootViewController + iAd | ||
11 | // If you want to support iAd, use this class as the controller of your iAd | ||
12 | // | ||
13 | |||
14 | #import "cocos2d.h" | ||
15 | |||
16 | #import "RootViewController.h" | ||
17 | #import "GameConfig.h" | ||
18 | |||
19 | @implementation RootViewController | ||
20 | |||
21 | /* | ||
22 | // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. | ||
23 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { | ||
24 | if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { | ||
25 | // Custom initialization | ||
26 | } | ||
27 | return self; | ||
28 | } | ||
29 | */ | ||
30 | |||
31 | /* | ||
32 | // Implement loadView to create a view hierarchy programmatically, without using a nib. | ||
33 | - (void)loadView { | ||
34 | } | ||
35 | */ | ||
36 | |||
37 | /* | ||
38 | // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. | ||
39 | - (void)viewDidLoad { | ||
40 | [super viewDidLoad]; | ||
41 | } | ||
42 | */ | ||
43 | |||
44 | |||
45 | // Override to allow orientations other than the default portrait orientation. | ||
46 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { | ||
47 | |||
48 | // | ||
49 | // There are 2 ways to support auto-rotation: | ||
50 | // - The OpenGL / cocos2d way | ||
51 | // - Faster, but doesn't rotate the UIKit objects | ||
52 | // - The ViewController way | ||
53 | // - A bit slower, but the UiKit objects are placed in the right place | ||
54 | // | ||
55 | |||
56 | #if GAME_AUTOROTATION==kGameAutorotationNone | ||
57 | // | ||
58 | // EAGLView won't be autorotated. | ||
59 | // Since this method should return YES in at least 1 orientation, | ||
60 | // we return YES only in the Portrait orientation | ||
61 | // | ||
62 | return ( interfaceOrientation == kCCDeviceOrientationLandscapeLeft ); | ||
63 | |||
64 | #elif GAME_AUTOROTATION==kGameAutorotationCCDirector | ||
65 | // | ||
66 | // EAGLView will be rotated by cocos2d | ||
67 | // | ||
68 | // Sample: Autorotate only in landscape mode | ||
69 | // | ||
70 | if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) { | ||
71 | [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight]; | ||
72 | } else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight) { | ||
73 | [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft]; | ||
74 | } | ||
75 | |||
76 | // Since this method should return YES in at least 1 orientation, | ||
77 | // we return YES only in the Portrait orientation | ||
78 | return ( interfaceOrientation == UIInterfaceOrientationPortrait ); | ||
79 | |||
80 | #elif GAME_AUTOROTATION == kGameAutorotationUIViewController | ||
81 | // | ||
82 | // EAGLView will be rotated by the UIViewController | ||
83 | // | ||
84 | // Sample: Autorotate only in landscpe mode | ||
85 | // | ||
86 | // return YES for the supported orientations | ||
87 | |||
88 | return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) ); | ||
89 | |||
90 | #else | ||
91 | #error Unknown value in GAME_AUTOROTATION | ||
92 | |||
93 | #endif // GAME_AUTOROTATION | ||
94 | |||
95 | |||
96 | // Shold not happen | ||
97 | return NO; | ||
98 | } | ||
99 | |||
100 | // | ||
101 | // This callback only will be called when GAME_AUTOROTATION == kGameAutorotationUIViewController | ||
102 | // | ||
103 | #if GAME_AUTOROTATION == kGameAutorotationUIViewController | ||
104 | -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration | ||
105 | { | ||
106 | // | ||
107 | // Assuming that the main window has the size of the screen | ||
108 | // BUG: This won't work if the EAGLView is not fullscreen | ||
109 | /// | ||
110 | CGRect screenRect = [[UIScreen mainScreen] bounds]; | ||
111 | CGRect rect; | ||
112 | |||
113 | if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) | ||
114 | rect = screenRect; | ||
115 | |||
116 | else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) | ||
117 | rect.size = CGSizeMake( screenRect.size.height, screenRect.size.width ); | ||
118 | |||
119 | CCDirector *director = [CCDirector sharedDirector]; | ||
120 | EAGLView *glView = [director openGLView]; | ||
121 | float contentScaleFactor = [director contentScaleFactor]; | ||
122 | |||
123 | if( contentScaleFactor != 1 ) { | ||
124 | rect.size.width *= contentScaleFactor; | ||
125 | rect.size.height *= contentScaleFactor; | ||
126 | } | ||
127 | glView.frame = rect; | ||
128 | } | ||
129 | #endif // GAME_AUTOROTATION == kGameAutorotationUIViewController | ||
130 | |||
131 | |||
132 | - (void)didReceiveMemoryWarning { | ||
133 | // Releases the view if it doesn't have a superview. | ||
134 | [super didReceiveMemoryWarning]; | ||
135 | |||
136 | // Release any cached data, images, etc that aren't in use. | ||
137 | } | ||
138 | |||
139 | - (void)viewDidUnload { | ||
140 | [super viewDidUnload]; | ||
141 | // Release any retained subviews of the main view. | ||
142 | // e.g. self.myOutlet = nil; | ||
143 | } | ||
144 | |||
145 | |||
146 | - (void)dealloc { | ||
147 | [super dealloc]; | ||
148 | } | ||
149 | |||
150 | |||
151 | @end | ||
152 | |||
diff --git a/Classes/ValuableObject.h b/Classes/ValuableObject.h new file mode 100755 index 0000000..ccefbbd --- /dev/null +++ b/Classes/ValuableObject.h | |||
@@ -0,0 +1,15 @@ | |||
1 | // | ||
2 | // ValuableObject.h | ||
3 | // Cart Collect | ||
4 | // | ||
5 | // Created by iD Student Account on 7/20/11. | ||
6 | // Copyright 2011 __MyCompanyName__. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import <Foundation/Foundation.h> | ||
10 | |||
11 | @protocol ValuableObject | ||
12 | |||
13 | - (int)pointValue; | ||
14 | |||
15 | @end | ||