From 9cd57b731ab1c666d4a1cb725538fdc137763d12 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sat, 30 Jul 2011 11:19:14 -0400 Subject: Initial commit (version 0.2.1) --- Classes/Cart_CollectAppDelegate.m | 212 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100755 Classes/Cart_CollectAppDelegate.m (limited to 'Classes/Cart_CollectAppDelegate.m') 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 @@ +// +// Cart_CollectAppDelegate.m +// Cart Collect +// +// Created by iD Student Account on 7/18/11. +// Copyright __MyCompanyName__ 2011. All rights reserved. +// + +#import "cocos2d.h" + +#import "Cart_CollectAppDelegate.h" +#import "GameConfig.h" +#import "GameLayer.h" +#import "RootViewController.h" +#import "MainMenuLayer.h" + +@implementation Cart_CollectAppDelegate + +@synthesize window, viewController; + +- (void) removeStartupFlicker +{ + // + // THIS CODE REMOVES THE STARTUP FLICKER + // + // Uncomment the following code if you Application only supports landscape mode + // +#if GAME_AUTOROTATION == kGameAutorotationUIViewController + + // CC_ENABLE_DEFAULT_GL_STATES(); + // CCDirector *director = [CCDirector sharedDirector]; + // CGSize size = [director winSize]; + // CCSprite *sprite = [CCSprite spriteWithFile:@"Default.png"]; + // sprite.position = ccp(size.width/2, size.height/2); + // sprite.rotation = -90; + // [sprite visit]; + // [[director openGLView] swapBuffers]; + // CC_ENABLE_DEFAULT_GL_STATES(); + +#endif // GAME_AUTOROTATION == kGameAutorotationUIViewController +} + +- (void) applicationDidFinishLaunching:(UIApplication*)application +{ + [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; + + NSMutableDictionary* registerDefaults = [NSMutableDictionary dictionaryWithObjectsAndKeys: + @"", @"username", + [NSNumber numberWithBool:YES], @"submitScore", + nil]; + [[NSUserDefaults standardUserDefaults] registerDefaults:registerDefaults]; + + // Init the window + window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + + // Try to use CADisplayLink director + // if it fails (SDK < 3.1) use the default director + if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] ) + [CCDirector setDirectorType:kCCDirectorTypeDefault]; + + + CCDirector *director = [CCDirector sharedDirector]; + + // Init the View Controller + viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; + viewController.wantsFullScreenLayout = YES; + + // + // Create the EAGLView manually + // 1. Create a RGB565 format. Alternative: RGBA8 + // 2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like CCPageTurnTransition + // + // + EAGLView *glView = [EAGLView viewWithFrame:[window bounds] + pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8 + depthFormat:0 // GL_DEPTH_COMPONENT16_OES + ]; + + // attach the openglView to the director + [director setOpenGLView:glView]; + +// // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices + //if( ! [director enableRetinaDisplay:YES] ) + // CCLOG(@"Retina Display Not supported"); + + // + // VERY IMPORTANT: + // If the rotation is going to be controlled by a UIViewController + // then the device orientation should be "Portrait". + // + // IMPORTANT: + // By default, this template only supports Landscape orientations. + // Edit the RootViewController.m file to edit the supported orientations. + // +#if GAME_AUTOROTATION == kGameAutorotationUIViewController + [director setDeviceOrientation:kCCDeviceOrientationPortrait]; +#else + [director setDeviceOrientation:kCCDeviceOrientationPortrait]; +#endif + + [director setAnimationInterval:1.0/60]; + //[director setDisplayFPS:YES]; + + + // make the OpenGLView a child of the view controller + [viewController setView:glView]; + + // make the View Controller a child of the main window + [window addSubview: viewController.view]; + + [window makeKeyAndVisible]; + + // Default texture format for PNG/BMP/TIFF/JPEG/GIF images + // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565 + // You can change anytime. + [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888]; + + + // Removes the startup flicker + [self removeStartupFlicker]; + + // Run the intro Scene + [[CCDirector sharedDirector] runWithScene: [MainMenuLayer scene]]; +} + + +- (void)applicationWillResignActive:(UIApplication *)application { + [[CCDirector sharedDirector] pause]; +} + +- (void)applicationDidBecomeActive:(UIApplication *)application { + [[CCDirector sharedDirector] resume]; +} + +- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { + [[CCDirector sharedDirector] purgeCachedData]; +} + +-(void) applicationDidEnterBackground:(UIApplication*)application { + [[CCDirector sharedDirector] stopAnimation]; + + if ([[CCDirector sharedDirector] runningScene].tag == 436) + { + [[CCDirector sharedDirector] replaceScene:[PauseLayer sceneWithScene:[[CCDirector sharedDirector] runningScene]]]; + } +} + +-(void) applicationWillEnterForeground:(UIApplication*)application { + [[CCDirector sharedDirector] startAnimation]; +} + +- (void)applicationWillTerminate:(UIApplication *)application { + CCDirector *director = [CCDirector sharedDirector]; + + sqlite3_close([Cart_CollectAppDelegate database]); + + [[director openGLView] removeFromSuperview]; + + [viewController release]; + + [window release]; + + [director end]; +} + +- (void)applicationSignificantTimeChange:(UIApplication *)application { + [[CCDirector sharedDirector] setNextDeltaTimeZero:YES]; +} + +- (void)dealloc { + //[[CCDirector sharedDirector] release]; + [window release]; + [super dealloc]; +} + ++ (sqlite3*)database +{ + static sqlite3* database = nil; + + if (database == nil) + { + NSString* databaseName = @"cartdata.sqlite3"; + NSArray* documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSString* documentsDir = [documentPaths objectAtIndex:0]; + NSString* databasePath = [documentsDir stringByAppendingPathComponent:databaseName]; + NSFileManager* fileManager = [NSFileManager defaultManager]; + NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; + + if (![fileManager fileExistsAtPath:databasePath]) + { + NSString* databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; + [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; + //[fileManager release]; + + [userDefaults setInteger:1 forKey:@"databaseVersion"]; + } + + if ([userDefaults integerForKey:@"databaseVersion"] < 1) + { + // Upgrade the database to version 1, which is completely unnecessary as no prior version exists + } + + if (sqlite3_open([databasePath UTF8String], &database) != SQLITE_OK) + { + NSLog(@"Failed to open database"); + } + } + + return database; +} + +@end -- cgit 1.4.1