summary refs log tree commit diff stats
path: root/Classes/Cart_CollectAppDelegate.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
committerStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
commit9cd57b731ab1c666d4a1cb725538fdc137763d12 (patch)
tree5bac45ae5157a1cb10c6e45500cbf72789917980 /Classes/Cart_CollectAppDelegate.m
downloadcartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.gz
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.bz2
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.zip
Initial commit (version 0.2.1)
Diffstat (limited to 'Classes/Cart_CollectAppDelegate.m')
-rwxr-xr-xClasses/Cart_CollectAppDelegate.m212
1 files changed, 212 insertions, 0 deletions
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