diff options
Diffstat (limited to 'Classes')
| -rwxr-xr-x | Classes/Cart_CollectAppDelegate.m | 44 | ||||
| -rwxr-xr-x | Classes/CocosOverlayScrollView.h | 19 | ||||
| -rwxr-xr-x | Classes/CocosOverlayScrollView.m | 110 | ||||
| -rw-r--r-- | Classes/GameMode.h | 5 | ||||
| -rw-r--r-- | Classes/GameMode.m | 39 | ||||
| -rw-r--r-- | Classes/GameModeSelection.h | 30 | ||||
| -rw-r--r-- | Classes/GameModeSelection.m | 219 | ||||
| -rw-r--r-- | Classes/GameModeSelectionDelegate.h | 17 | ||||
| -rw-r--r-- | Classes/GameModeSelectionLayer.h | 25 | ||||
| -rw-r--r-- | Classes/GameModeSelectionLayer.m | 132 | ||||
| -rwxr-xr-x | Classes/GameOverScene.m | 6 | ||||
| -rwxr-xr-x | Classes/Highscore.h | 2 | ||||
| -rwxr-xr-x | Classes/Highscore.m | 53 | ||||
| -rwxr-xr-x | Classes/HighscoreListController.m | 37 | ||||
| -rwxr-xr-x | Classes/MainMenuLayer.h | 3 | ||||
| -rwxr-xr-x | Classes/MainMenuLayer.m | 31 | ||||
| -rwxr-xr-x | Classes/NMPanelMenu.h | 14 | ||||
| -rwxr-xr-x | Classes/NMPanelMenu.m | 37 | ||||
| -rwxr-xr-x | Classes/TouchDelegatingView.h | 18 | ||||
| -rwxr-xr-x | Classes/TouchDelegatingView.m | 26 | ||||
| -rw-r--r-- | Classes/TutorialMode.m | 58 | ||||
| -rw-r--r-- | Classes/UIImage+ColorMasking.h | 15 | ||||
| -rw-r--r-- | Classes/UIImage+ColorMasking.m | 77 |
23 files changed, 922 insertions, 95 deletions
| diff --git a/Classes/Cart_CollectAppDelegate.m b/Classes/Cart_CollectAppDelegate.m index 158f660..ba9d60b 100755 --- a/Classes/Cart_CollectAppDelegate.m +++ b/Classes/Cart_CollectAppDelegate.m | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #import "GameMode.h" | 13 | #import "GameMode.h" |
| 14 | #import "RootViewController.h" | 14 | #import "RootViewController.h" |
| 15 | #import "MainMenuLayer.h" | 15 | #import "MainMenuLayer.h" |
| 16 | #import "TestFlight.h" | ||
| 16 | 17 | ||
| 17 | @implementation Cart_CollectAppDelegate | 18 | @implementation Cart_CollectAppDelegate |
| 18 | 19 | ||
| @@ -42,6 +43,9 @@ | |||
| 42 | 43 | ||
| 43 | - (void) applicationDidFinishLaunching:(UIApplication*)application | 44 | - (void) applicationDidFinishLaunching:(UIApplication*)application |
| 44 | { | 45 | { |
| 46 | // REMOVE THIS LINE FOR RELEASE BUILDS | ||
| 47 | [TestFlight takeOff:@"66a3925c85c93e7628c14d167ff6c1b7_MjM4MTEyMDExLTA4LTE3IDEzOjEyOjQ4Ljg2NDE2OQ"]; | ||
| 48 | |||
| 45 | [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; | 49 | [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; |
| 46 | 50 | ||
| 47 | NSMutableDictionary* registerDefaults = [NSMutableDictionary dictionaryWithObjectsAndKeys: | 51 | NSMutableDictionary* registerDefaults = [NSMutableDictionary dictionaryWithObjectsAndKeys: |
| @@ -138,6 +142,8 @@ | |||
| 138 | 142 | ||
| 139 | -(void) applicationDidEnterBackground:(UIApplication*)application { | 143 | -(void) applicationDidEnterBackground:(UIApplication*)application { |
| 140 | [[CCDirector sharedDirector] stopAnimation]; | 144 | [[CCDirector sharedDirector] stopAnimation]; |
| 145 | |||
| 146 | [[NSUserDefaults standardUserDefaults] synchronize]; | ||
| 141 | 147 | ||
| 142 | if ([[CCDirector sharedDirector] runningScene].tag == GAME_SCENE) | 148 | if ([[CCDirector sharedDirector] runningScene].tag == GAME_SCENE) |
| 143 | { | 149 | { |
| @@ -190,20 +196,48 @@ | |||
| 190 | { | 196 | { |
| 191 | NSString* databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; | 197 | NSString* databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; |
| 192 | [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; | 198 | [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; |
| 193 | //[fileManager release]; | ||
| 194 | 199 | ||
| 195 | [userDefaults setInteger:1 forKey:@"databaseVersion"]; | 200 | [userDefaults setInteger:2 forKey:@"databaseVersion"]; |
| 201 | } | ||
| 202 | |||
| 203 | if (sqlite3_open([databasePath UTF8String], &database) != SQLITE_OK) | ||
| 204 | { | ||
| 205 | NSLog(@"Failed to open database"); | ||
| 196 | } | 206 | } |
| 197 | 207 | ||
| 208 | // Database migrations! | ||
| 198 | if ([userDefaults integerForKey:@"databaseVersion"] < 1) | 209 | if ([userDefaults integerForKey:@"databaseVersion"] < 1) |
| 199 | { | 210 | { |
| 200 | // Upgrade the database to version 1, which is completely unnecessary as no prior version exists | 211 | // Upgrade the database to version 1, which is completely unnecessary as no prior version exists |
| 201 | } | 212 | } |
| 202 | 213 | ||
| 203 | if (sqlite3_open([databasePath UTF8String], &database) != SQLITE_OK) | 214 | if ([userDefaults integerForKey:@"databaseVersion"] < 2) |
| 204 | { | 215 | { |
| 205 | NSLog(@"Failed to open database"); | 216 | // Database version 2 adds a "gameMode" column to highscores to allow for multiple highscore lists |
| 217 | const char* sqlQuery = "ALTER TABLE highscores ADD gameMode varchar(255)"; | ||
| 218 | sqlite3_stmt* compiled_statement; | ||
| 219 | |||
| 220 | if (sqlite3_prepare_v2(database, sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) | ||
| 221 | { | ||
| 222 | sqlite3_step(compiled_statement); | ||
| 223 | |||
| 224 | sqlQuery = "UPDATE highscores SET gameMode = \"Collect\""; | ||
| 225 | if (sqlite3_prepare_v2(database, sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) | ||
| 226 | { | ||
| 227 | sqlite3_step(compiled_statement); | ||
| 228 | |||
| 229 | NSLog(@"Updated database to version 2."); | ||
| 230 | [userDefaults setInteger:2 forKey:@"databaseVersion"]; | ||
| 231 | } else { | ||
| 232 | NSLog(@"Error while updating database to version 2. '%s'", sqlite3_errmsg(database)); | ||
| 233 | } | ||
| 234 | } else { | ||
| 235 | NSLog(@"Error while updating database to version 2. '%s'", sqlite3_errmsg(database)); | ||
| 236 | } | ||
| 206 | } | 237 | } |
| 238 | |||
| 239 | // It's rather important that the database version gets saved | ||
| 240 | [userDefaults synchronize]; | ||
| 207 | } | 241 | } |
| 208 | 242 | ||
| 209 | return database; | 243 | return database; |
| diff --git a/Classes/CocosOverlayScrollView.h b/Classes/CocosOverlayScrollView.h new file mode 100755 index 0000000..ad8e83f --- /dev/null +++ b/Classes/CocosOverlayScrollView.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | // | ||
| 2 | // CocosOverlayScrollView.h | ||
| 3 | // shapes | ||
| 4 | // | ||
| 5 | // Created by Nate Murray on 8/23/10. | ||
| 6 | // Copyright 2010 LittleHiccup. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import <Foundation/Foundation.h> | ||
| 10 | #import "cocos2d.h" | ||
| 11 | |||
| 12 | @interface CocosOverlayScrollView : UIScrollView <UIScrollViewDelegate> | ||
| 13 | { | ||
| 14 | CCNode* targetLayer; | ||
| 15 | UIPageControl* pageControl; | ||
| 16 | } | ||
| 17 | @property(nonatomic, retain) CCNode* targetLayer; | ||
| 18 | -(id) initWithFrame: (CGRect) frameRect numPages: (int) numPages width: (float) width layer: (CCNode*) layer pageControl:(UIPageControl*)pageControl; | ||
| 19 | @end | ||
| diff --git a/Classes/CocosOverlayScrollView.m b/Classes/CocosOverlayScrollView.m new file mode 100755 index 0000000..9db0575 --- /dev/null +++ b/Classes/CocosOverlayScrollView.m | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | // | ||
| 2 | // CocosOverlayScrollView.m | ||
| 3 | // shapes | ||
| 4 | // | ||
| 5 | // Created by Nate Murray on 8/23/10. | ||
| 6 | // Copyright 2010 LittleHiccup. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import "CocosOverlayScrollView.h" | ||
| 10 | |||
| 11 | @implementation CocosOverlayScrollView | ||
| 12 | @synthesize targetLayer; | ||
| 13 | |||
| 14 | // Configure your favorite UIScrollView options here | ||
| 15 | -(id) initWithFrame: (CGRect) frameRect numPages: (int) numPages width: (float) width layer: (CCNode*) layer pageControl:(UIPageControl *)m_pageControl{ | ||
| 16 | if ((self = [super initWithFrame: frameRect])){ | ||
| 17 | self.contentSize = CGSizeMake(width*numPages, 320); | ||
| 18 | self.bounces = YES; | ||
| 19 | self.delaysContentTouches = NO; | ||
| 20 | self.delegate = self; | ||
| 21 | self.pagingEnabled = YES; | ||
| 22 | self.scrollsToTop = NO; | ||
| 23 | self.showsVerticalScrollIndicator = NO; | ||
| 24 | self.showsHorizontalScrollIndicator = NO; | ||
| 25 | [self setUserInteractionEnabled:TRUE]; | ||
| 26 | [self setScrollEnabled:TRUE]; | ||
| 27 | self.targetLayer = layer; | ||
| 28 | // self.canCancelContentTouches = YES; | ||
| 29 | pageControl = m_pageControl; | ||
| 30 | } | ||
| 31 | return self; | ||
| 32 | } | ||
| 33 | |||
| 34 | -(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event | ||
| 35 | { | ||
| 36 | if (!self.dragging) | ||
| 37 | { | ||
| 38 | // UITouch* touch = [[touches allObjects] objectAtIndex:0]; | ||
| 39 | // CGPoint location = [touch locationInView: [[touch view] superview]]; | ||
| 40 | // CCLOG(@"touch at l.x:%f l.y:%f", location.x, location.y); | ||
| 41 | |||
| 42 | [self.nextResponder touchesBegan: touches withEvent:event]; | ||
| 43 | [[[CCDirector sharedDirector] openGLView] touchesBegan:touches withEvent:event]; | ||
| 44 | } | ||
| 45 | |||
| 46 | [super touchesBegan: touches withEvent: event]; | ||
| 47 | } | ||
| 48 | |||
| 49 | -(void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event | ||
| 50 | { | ||
| 51 | if (!self.dragging) | ||
| 52 | { | ||
| 53 | [self.nextResponder touchesEnded: touches withEvent:event]; | ||
| 54 | [[[CCDirector sharedDirector] openGLView] touchesEnded:touches withEvent:event]; | ||
| 55 | } | ||
| 56 | |||
| 57 | [super touchesEnded: touches withEvent: event]; | ||
| 58 | } | ||
| 59 | |||
| 60 | -(void) touchesCancelled: (NSSet *) touches withEvent: (UIEvent *) event | ||
| 61 | { | ||
| 62 | // if (!self.dragging) | ||
| 63 | // { | ||
| 64 | // CCLOG(@"CocosOverlayScrollView touchesEnded not dragging"); | ||
| 65 | [self.nextResponder touchesCancelled: touches withEvent:event]; | ||
| 66 | [[[CCDirector sharedDirector] openGLView] touchesCancelled:touches withEvent:event]; | ||
| 67 | // } | ||
| 68 | [super touchesCancelled: touches withEvent: event]; | ||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView | ||
| 73 | { | ||
| 74 | // TODO - Custom code for handling deceleration of the scroll view | ||
| 75 | } | ||
| 76 | |||
| 77 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView | ||
| 78 | { | ||
| 79 | CGPoint dragPt = [scrollView contentOffset]; | ||
| 80 | dragPt = [[CCDirector sharedDirector] convertToGL:dragPt]; | ||
| 81 | |||
| 82 | dragPt.y = dragPt.y * -1; | ||
| 83 | dragPt.x = dragPt.x * -1; | ||
| 84 | |||
| 85 | CGPoint newLayerPosition = CGPointMake(dragPt.x, dragPt.y); | ||
| 86 | |||
| 87 | [targetLayer setPosition:newLayerPosition]; | ||
| 88 | } | ||
| 89 | |||
| 90 | - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView | ||
| 91 | { | ||
| 92 | // CGPoint dragPt = [scrollView contentOffset]; | ||
| 93 | // etc. | ||
| 94 | } | ||
| 95 | |||
| 96 | -(void) dealloc { | ||
| 97 | self.targetLayer = nil; | ||
| 98 | [super dealloc]; | ||
| 99 | } | ||
| 100 | |||
| 101 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView | ||
| 102 | { | ||
| 103 | int currentPage = (NSUInteger)(scrollView.contentOffset.x / scrollView.frame.size.width); | ||
| 104 | NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | ||
| 105 | [defaults setInteger:currentPage forKey:@"lastSelectedMode"]; | ||
| 106 | |||
| 107 | [pageControl setCurrentPage:currentPage]; | ||
| 108 | } | ||
| 109 | |||
| 110 | @end \ No newline at end of file | ||
| diff --git a/Classes/GameMode.h b/Classes/GameMode.h index 370550c..53ed9fc 100644 --- a/Classes/GameMode.h +++ b/Classes/GameMode.h | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | #define GAME_SCENE 436 | 12 | #define GAME_SCENE 436 |
| 13 | #define GAME_LAYER 437 | 13 | #define GAME_LAYER 437 |
| 14 | 14 | ||
| 15 | @interface GameMode : CCLayer { | 15 | @interface GameMode : CCLayer <UIAlertViewDelegate> { |
| 16 | NSMutableSet* objects; | 16 | NSMutableSet* objects; |
| 17 | int score; | 17 | int score; |
| 18 | int lives; | 18 | int lives; |
| @@ -25,11 +25,14 @@ | |||
| 25 | CCLabelBMFont* livesLabel; | 25 | CCLabelBMFont* livesLabel; |
| 26 | 26 | ||
| 27 | void (^delayedAction)(void); | 27 | void (^delayedAction)(void); |
| 28 | |||
| 29 | BOOL isPaused; | ||
| 28 | } | 30 | } |
| 29 | 31 | ||
| 30 | @property (readonly) Cart* cart; | 32 | @property (readonly) Cart* cart; |
| 31 | @property (nonatomic,assign) int score; | 33 | @property (nonatomic,assign) int score; |
| 32 | @property (nonatomic,assign) int lives; | 34 | @property (nonatomic,assign) int lives; |
| 35 | @property (readonly) BOOL isPaused; | ||
| 33 | + (CCScene*)scene; | 36 | + (CCScene*)scene; |
| 34 | - (void)tick:(ccTime)dt; | 37 | - (void)tick:(ccTime)dt; |
| 35 | - (BOOL)canPause; | 38 | - (BOOL)canPause; |
| diff --git a/Classes/GameMode.m b/Classes/GameMode.m index 7afbf20..8f695d1 100644 --- a/Classes/GameMode.m +++ b/Classes/GameMode.m | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | 12 | ||
| 13 | @implementation GameMode | 13 | @implementation GameMode |
| 14 | 14 | ||
| 15 | @synthesize cart, score, lives; | 15 | @synthesize cart, score, lives, isPaused; |
| 16 | 16 | ||
| 17 | + (CCScene*)scene | 17 | + (CCScene*)scene |
| 18 | { | 18 | { |
| @@ -60,6 +60,8 @@ | |||
| 60 | [pauseMenu setPosition:ccp(480-8-16, 320-8-16)]; | 60 | [pauseMenu setPosition:ccp(480-8-16, 320-8-16)]; |
| 61 | [self addChild:pauseMenu]; | 61 | [self addChild:pauseMenu]; |
| 62 | } | 62 | } |
| 63 | |||
| 64 | isPaused = NO; | ||
| 63 | } | 65 | } |
| 64 | 66 | ||
| 65 | return self; | 67 | return self; |
| @@ -98,8 +100,10 @@ | |||
| 98 | 100 | ||
| 99 | - (void)pause | 101 | - (void)pause |
| 100 | { | 102 | { |
| 101 | if ([self canPause]) | 103 | if (([self canPause]) && (!isPaused)) |
| 102 | { | 104 | { |
| 105 | isPaused = YES; | ||
| 106 | |||
| 103 | [self pauseSchedulerAndActions]; | 107 | [self pauseSchedulerAndActions]; |
| 104 | 108 | ||
| 105 | shadedLayer = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 127)]; | 109 | shadedLayer = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 127)]; |
| @@ -126,18 +130,25 @@ | |||
| 126 | 130 | ||
| 127 | - (void)unpause | 131 | - (void)unpause |
| 128 | { | 132 | { |
| 129 | [[[CCDirector sharedDirector] runningScene] removeChild:shadedLayer cleanup:YES]; | 133 | if (isPaused) |
| 130 | [[[CCDirector sharedDirector] runningScene] removeChild:pauseLayer cleanup:YES]; | 134 | { |
| 131 | 135 | [[[CCDirector sharedDirector] runningScene] removeChild:shadedLayer cleanup:YES]; | |
| 132 | shadedLayer = nil; | 136 | [[[CCDirector sharedDirector] runningScene] removeChild:pauseLayer cleanup:YES]; |
| 133 | pauseLayer = nil; | 137 | |
| 134 | 138 | shadedLayer = nil; | |
| 135 | [self resumeSchedulerAndActions]; | 139 | pauseLayer = nil; |
| 140 | |||
| 141 | [self resumeSchedulerAndActions]; | ||
| 142 | |||
| 143 | isPaused = NO; | ||
| 144 | } | ||
| 136 | } | 145 | } |
| 137 | 146 | ||
| 138 | - (void)mainmenu | 147 | - (void)mainmenu |
| 139 | { | 148 | { |
| 140 | [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; | 149 | UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Cartographic" message:@"Are you sure you want to quit the currently playing game?" delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No", nil]; |
| 150 | [alert show]; | ||
| 151 | [alert release]; | ||
| 141 | } | 152 | } |
| 142 | 153 | ||
| 143 | - (void)setScore:(int)m_score | 154 | - (void)setScore:(int)m_score |
| @@ -170,6 +181,14 @@ | |||
| 170 | delayedAction = nil; | 181 | delayedAction = nil; |
| 171 | } | 182 | } |
| 172 | 183 | ||
| 184 | - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex | ||
| 185 | { | ||
| 186 | if (buttonIndex == 0) | ||
| 187 | { | ||
| 188 | [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; | ||
| 189 | } | ||
| 190 | } | ||
| 191 | |||
| 173 | - (void)dealloc | 192 | - (void)dealloc |
| 174 | { | 193 | { |
| 175 | [objects release]; | 194 | [objects release]; |
| diff --git a/Classes/GameModeSelection.h b/Classes/GameModeSelection.h new file mode 100644 index 0000000..bdb38fb --- /dev/null +++ b/Classes/GameModeSelection.h | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | // | ||
| 2 | // GameModeSelection.h | ||
| 3 | // Cartographic | ||
| 4 | // | ||
| 5 | // Created by Starla Insigna on 8/18/11. | ||
| 6 | // Copyright 2011 Four Island. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import "cocos2d.h" | ||
| 10 | #import "GameModeSelectionDelegate.h" | ||
| 11 | |||
| 12 | @interface GameModeSelection : CCMenuItem { | ||
| 13 | NSString* name; | ||
| 14 | NSString* location; | ||
| 15 | BOOL unlocked; | ||
| 16 | NSString* unlockCondition; | ||
| 17 | id<GameModeSelectionDelegate> delegate; | ||
| 18 | } | ||
| 19 | |||
| 20 | @property (readonly) NSString* name; | ||
| 21 | @property (readonly) NSString* location; | ||
| 22 | @property (readonly) BOOL unlocked; | ||
| 23 | @property (nonatomic,retain) id<GameModeSelectionDelegate> delegate; | ||
| 24 | + (id)selectionWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked; | ||
| 25 | + (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition; | ||
| 26 | - (id)initWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked; | ||
| 27 | - (id)initWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition; | ||
| 28 | - (void)buttonTapped; | ||
| 29 | |||
| 30 | @end | ||
| diff --git a/Classes/GameModeSelection.m b/Classes/GameModeSelection.m new file mode 100644 index 0000000..69f1ddb --- /dev/null +++ b/Classes/GameModeSelection.m | |||
| @@ -0,0 +1,219 @@ | |||
| 1 | // | ||
| 2 | // GameModeSelection.m | ||
| 3 | // Cartographic | ||
| 4 | // | ||
| 5 | // Created by Starla Insigna on 8/18/11. | ||
| 6 | // Copyright 2011 Four Island. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import "GameModeSelection.h" | ||
| 10 | #import "UIImage+ColorMasking.h" | ||
| 11 | #import "NMPanelMenu.h" | ||
| 12 | #import "Highscore.h" | ||
| 13 | |||
| 14 | @implementation GameModeSelection | ||
| 15 | |||
| 16 | @synthesize name, location, unlocked, delegate; | ||
| 17 | |||
| 18 | + (id)selectionWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked | ||
| 19 | { | ||
| 20 | return [[[GameModeSelection alloc] initWithName:name location:location filename:filename unlocked:unlocked] autorelease]; | ||
| 21 | } | ||
| 22 | |||
| 23 | + (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition | ||
| 24 | { | ||
| 25 | return [[[GameModeSelection alloc] initWithName:name location:location filename:filename unlockCondition:unlockCondition] autorelease]; | ||
| 26 | } | ||
| 27 | |||
| 28 | - (id)initWithName:(NSString*)m_name location:(NSString*)m_location filename:(NSString*)filename unlocked:(BOOL)m_unlocked; | ||
| 29 | { | ||
| 30 | self = [super initWithTarget:nil selector:nil]; | ||
| 31 | |||
| 32 | if (nil != self) | ||
| 33 | { | ||
| 34 | self.anchorPoint = CGPointMake(0.5f, 0.5f); | ||
| 35 | |||
| 36 | name = m_name; | ||
| 37 | location = m_location; | ||
| 38 | unlocked = m_unlocked; | ||
| 39 | |||
| 40 | contentSize_ = CGSizeMake(128, 320); | ||
| 41 | |||
| 42 | NSString* filenameMod; | ||
| 43 | |||
| 44 | if (unlocked) | ||
| 45 | { | ||
| 46 | filenameMod = [NSString stringWithFormat:@"%@-unlocked", filename]; | ||
| 47 | } else { | ||
| 48 | filenameMod = [NSString stringWithFormat:@"%@-locked", filename]; | ||
| 49 | name = [@"" stringByPaddingToLength:name.length withString:@"?" startingAtIndex:0]; | ||
| 50 | location = [@"" stringByPaddingToLength:location.length withString:@"?" startingAtIndex:0]; | ||
| 51 | } | ||
| 52 | |||
| 53 | // First, create the frame that we will put the level picture inside | ||
| 54 | CGImageRef framestuff = [[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"framestuff" ofType:@"png"]] CGImage]; | ||
| 55 | CGImageRef topLeftRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(0, 0, 8, 8)); | ||
| 56 | CGImageRef topRightRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(8, 0, 8, 8)); | ||
| 57 | CGImageRef bottomLeftRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(0, 8, 8, 8)); | ||
| 58 | CGImageRef bottomRightRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(8, 8, 8, 8)); | ||
| 59 | CGImageRef topBorderRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(0, 16, 8, 8)); | ||
| 60 | CGImageRef leftBorderRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(8, 16, 8, 8)); | ||
| 61 | CGImageRef rightBorderRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(0, 24, 8, 8)); | ||
| 62 | CGImageRef bottomBorderRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(8, 24, 8, 8)); | ||
| 63 | UIImage* topLeft = [UIImage imageWithCGImage:topLeftRef]; | ||
| 64 | UIImage* topRight = [UIImage imageWithCGImage:topRightRef]; | ||
| 65 | UIImage* bottomLeft = [UIImage imageWithCGImage:bottomLeftRef]; | ||
| 66 | UIImage* bottomRight = [UIImage imageWithCGImage:bottomRightRef]; | ||
| 67 | UIImage* topBorder = [UIImage imageWithCGImage:topBorderRef]; | ||
| 68 | UIImage* leftBorder = [UIImage imageWithCGImage:leftBorderRef]; | ||
| 69 | UIImage* rightBorder = [UIImage imageWithCGImage:rightBorderRef]; | ||
| 70 | UIImage* bottomBorder = [UIImage imageWithCGImage:bottomBorderRef]; | ||
| 71 | CGImageRelease(topLeftRef); | ||
| 72 | CGImageRelease(topRightRef); | ||
| 73 | CGImageRelease(bottomLeftRef); | ||
| 74 | CGImageRelease(bottomRightRef); | ||
| 75 | CGImageRelease(topBorderRef); | ||
| 76 | CGImageRelease(leftBorderRef); | ||
| 77 | CGImageRelease(rightBorderRef); | ||
| 78 | CGImageRelease(bottomBorderRef); | ||
| 79 | |||
| 80 | CGSize boxSize = CGSizeMake(128+12, 128+12); | ||
| 81 | UIGraphicsBeginImageContext(boxSize); | ||
| 82 | CGContextRef context = UIGraphicsGetCurrentContext(); | ||
| 83 | [topLeft drawInRect:CGRectMake(0, 0, 8, 8)]; | ||
| 84 | [topBorder drawInRect:CGRectMake(8, 0, boxSize.width-16, 8)]; | ||
| 85 | [topRight drawInRect:CGRectMake(8+boxSize.width-16, 0, 8, 8)]; | ||
| 86 | [rightBorder drawInRect:CGRectMake(8+boxSize.width-16, 8, 8, boxSize.height-16)]; | ||
| 87 | [bottomRight drawInRect:CGRectMake(8+boxSize.width-16, 8+boxSize.height-16, 8, 8)]; | ||
| 88 | [bottomBorder drawInRect:CGRectMake(8, 8+boxSize.height-16, boxSize.width-16, 8)]; | ||
| 89 | [bottomLeft drawInRect:CGRectMake(0, 8+boxSize.height-16, 8, 8)]; | ||
| 90 | [leftBorder drawInRect:CGRectMake(0, 8, 8, boxSize.height-16)]; | ||
| 91 | CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]); | ||
| 92 | CGContextFillRect(context, CGRectMake(8, 8, boxSize.width-16, boxSize.height-16)); | ||
| 93 | UIImage* selectionBackground = UIGraphicsGetImageFromCurrentImageContext(); | ||
| 94 | |||
| 95 | // Now we want to put the level image inside the frame without messing up the frame itself | ||
| 96 | UIImage* innerPicture = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:filename ofType:@"png"]]; | ||
| 97 | CGContextClipToMask(context, CGRectMake(0, 0, boxSize.width, boxSize.height), [[selectionBackground opaqueMaskFromWhiteImage] CGImage]); | ||
| 98 | [innerPicture drawInRect:CGRectMake(6, 6, 128, 128)]; | ||
| 99 | selectionBackground = UIGraphicsGetImageFromCurrentImageContext(); | ||
| 100 | UIGraphicsEndImageContext(); | ||
| 101 | |||
| 102 | // The frame needs a shadow, so let's redraw it in a new context | ||
| 103 | UIGraphicsBeginImageContext(CGSizeMake(boxSize.width+10, boxSize.height+10)); | ||
| 104 | context = UIGraphicsGetCurrentContext(); | ||
| 105 | CGContextSaveGState(context); | ||
| 106 | |||
| 107 | if (unlocked) | ||
| 108 | { | ||
| 109 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); | ||
| 110 | [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height)]; | ||
| 111 | } else { | ||
| 112 | // Draw the picture in grayscale if the level has not yet been unlocked | ||
| 113 | CGContextClipToMask(context, CGRectMake(10, 0, boxSize.width, boxSize.height), [selectionBackground CGImage]); | ||
| 114 | CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]); | ||
| 115 | CGContextFillRect(context, CGRectMake(10, 0, boxSize.width, boxSize.height)); | ||
| 116 | CGContextRestoreGState(context); | ||
| 117 | |||
| 118 | CGContextSaveGState(context); | ||
| 119 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); | ||
| 120 | [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height) blendMode:kCGBlendModeLuminosity alpha:1.0]; | ||
| 121 | } | ||
| 122 | |||
| 123 | CGContextRestoreGState(context); | ||
| 124 | CGImageRef pictureRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; | ||
| 125 | |||
| 126 | CCSprite* picture = [CCSprite spriteWithCGImage:pictureRef key:[NSString stringWithFormat:@"gms-%@", filenameMod]]; | ||
| 127 | |||
| 128 | // We're also going to need a "selected" image state for the button | ||
| 129 | CGContextSaveGState(context); | ||
| 130 | CGContextClipToMask(context, CGRectMake(10, 0, boxSize.width, boxSize.height), [selectionBackground CGImage]); | ||
| 131 | CGContextSetFillColorWithColor(context, [[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5] CGColor]); | ||
| 132 | CGContextFillRect(context, CGRectMake(10, 0, boxSize.width, boxSize.height)); | ||
| 133 | CGContextRestoreGState(context); | ||
| 134 | CGImageRef selectedButtonRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; | ||
| 135 | UIGraphicsEndImageContext(); | ||
| 136 | CCSprite* selectedButton = [CCSprite spriteWithCGImage:selectedButtonRef key:[NSString stringWithFormat:@"gms-%@-selected", filenameMod]]; | ||
| 137 | |||
| 138 | CCMenuItemSprite* pictureMenuItem = [CCMenuItemSprite itemFromNormalSprite:picture selectedSprite:selectedButton target:self selector:@selector(buttonTapped)]; | ||
| 139 | NMPanelMenu* theMenu = [NMPanelMenu menuWithItems:pictureMenuItem, nil]; | ||
| 140 | theMenu.position = ccp(-5, 0); | ||
| 141 | [self addChild:theMenu]; | ||
| 142 | |||
| 143 | // Render the titles | ||
| 144 | UIFont* titleFont = [UIFont fontWithName:@"AmericanTypewriter-Bold" size:18.0f]; | ||
| 145 | CGSize titleSize = [location sizeWithFont:titleFont constrainedToSize:CGSizeMake(128, 0)]; | ||
| 146 | UIFont* subtitleFont = [UIFont fontWithName:@"AmericanTypewriter" size:18.0f]; | ||
| 147 | CGSize subtitleSize = [name sizeWithFont:subtitleFont constrainedToSize:CGSizeMake(128, 0)]; | ||
| 148 | CGSize combinedTitleSize = CGSizeMake(128, titleSize.height + 10 + subtitleSize.height + 10); | ||
| 149 | |||
| 150 | UIGraphicsBeginImageContext(combinedTitleSize); | ||
| 151 | context = UIGraphicsGetCurrentContext(); | ||
| 152 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); | ||
| 153 | [location drawInRect:CGRectMake(10, 0, 128, titleSize.height) withFont:titleFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter]; | ||
| 154 | [name drawInRect:CGRectMake(10, titleSize.height, 128, subtitleSize.height) withFont:subtitleFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter]; | ||
| 155 | |||
| 156 | CGImageRef titleImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; | ||
| 157 | UIGraphicsEndImageContext(); | ||
| 158 | CCSprite* titleSprite = [CCSprite spriteWithCGImage:titleImage key:[NSString stringWithFormat:@"gms-%@-title", filenameMod]]; | ||
| 159 | titleSprite.position = ccp(-10, (boxSize.height)/2+(combinedTitleSize.height)/2); | ||
| 160 | [self addChild:titleSprite]; | ||
| 161 | |||
| 162 | if (unlocked) | ||
| 163 | { | ||
| 164 | Highscore* localHighscore = [Highscore localHighscoreForGameMode:name]; | ||
| 165 | |||
| 166 | if (localHighscore != nil) | ||
| 167 | { | ||
| 168 | // Render the highscore label | ||
| 169 | NSString* highscoreString = [NSString stringWithFormat:@"Highscore: %d", localHighscore.score]; | ||
| 170 | UIFont* highscoreFont = [UIFont fontWithName:@"AmericanTypewriter" size:16.0f]; | ||
| 171 | CGSize highscoreSize = [highscoreString sizeWithFont:highscoreFont]; | ||
| 172 | |||
| 173 | UIGraphicsBeginImageContext(CGSizeMake(highscoreSize.width+10, highscoreSize.height+10)); | ||
| 174 | CGContextRef context = UIGraphicsGetCurrentContext(); | ||
| 175 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); | ||
| 176 | [highscoreString drawInRect:CGRectMake(10, 0, highscoreSize.width, highscoreSize.height) withFont:highscoreFont]; | ||
| 177 | |||
| 178 | CGImageRef highscoreImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; | ||
| 179 | UIGraphicsEndImageContext(); | ||
| 180 | CCSprite* highscoreSprite = [CCSprite spriteWithCGImage:highscoreImage key:[NSString stringWithFormat:@"gms-%@-highscore", filename]]; | ||
| 181 | highscoreSprite.position = ccp(-5, 0-64-(highscoreSize.height)/2-10); | ||
| 182 | [self addChild:highscoreSprite]; | ||
| 183 | } | ||
| 184 | } | ||
| 185 | } | ||
| 186 | |||
| 187 | return self; | ||
| 188 | } | ||
| 189 | |||
| 190 | - (id)initWithName:(NSString *)m_name location:(NSString *)m_location filename:(NSString *)m_filename unlockCondition:(NSString*)m_unlockCondition | ||
| 191 | { | ||
| 192 | self = [self initWithName:m_name location:m_location filename:m_filename unlocked:NO]; | ||
| 193 | |||
| 194 | if (nil != self) | ||
| 195 | { | ||
| 196 | unlockCondition = m_unlockCondition; | ||
| 197 | } | ||
| 198 | |||
| 199 | return self; | ||
| 200 | } | ||
| 201 | |||
| 202 | - (void)buttonTapped | ||
| 203 | { | ||
| 204 | if (unlocked) | ||
| 205 | { | ||
| 206 | if (delegate != nil) | ||
| 207 | { | ||
| 208 | [delegate didSelectGameMode:self]; | ||
| 209 | } else { | ||
| 210 | NSLog(@"I don't have a GameModeSelectionDelegate to call for some reason..."); | ||
| 211 | } | ||
| 212 | } else { | ||
| 213 | UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"To unlock this game mode:" message:unlockCondition delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; | ||
| 214 | [alertView show]; | ||
| 215 | [alertView release]; | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | @end | ||
| diff --git a/Classes/GameModeSelectionDelegate.h b/Classes/GameModeSelectionDelegate.h new file mode 100644 index 0000000..854a980 --- /dev/null +++ b/Classes/GameModeSelectionDelegate.h | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | // | ||
| 2 | // GameModeSelectionDelegate.h | ||
| 3 | // Cartographic | ||
| 4 | // | ||
| 5 | // Created by Starla Insigna on 8/23/11. | ||
| 6 | // Copyright 2011 Four Island. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import <Foundation/Foundation.h> | ||
| 10 | |||
| 11 | @class GameModeSelection; | ||
| 12 | |||
| 13 | @protocol GameModeSelectionDelegate <NSObject> | ||
| 14 | |||
| 15 | - (void)didSelectGameMode:(GameModeSelection*)gameMode; | ||
| 16 | |||
| 17 | @end | ||
| diff --git a/Classes/GameModeSelectionLayer.h b/Classes/GameModeSelectionLayer.h new file mode 100644 index 0000000..478a173 --- /dev/null +++ b/Classes/GameModeSelectionLayer.h | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | // | ||
| 2 | // GameModeSelectionLayer.h | ||
| 3 | // Cartographic | ||
| 4 | // | ||
| 5 | // Created by Starla Insigna on 8/18/11. | ||
| 6 | // Copyright 2011 Four Island. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import "cocos2d.h" | ||
| 10 | #import "TouchDelegatingView.h" | ||
| 11 | #import "CocosOverlayScrollView.h" | ||
| 12 | #import "GameModeSelectionDelegate.h" | ||
| 13 | |||
| 14 | @interface GameModeSelectionLayer : CCLayer <GameModeSelectionDelegate> { | ||
| 15 | NSMutableArray* gameModes; | ||
| 16 | TouchDelegatingView* touchDelegatingView; | ||
| 17 | CocosOverlayScrollView* scrollView; | ||
| 18 | UIPageControl* pageControl; | ||
| 19 | } | ||
| 20 | |||
| 21 | + (CCScene*)scene; | ||
| 22 | - (id)init; | ||
| 23 | - (void)mainmenu; | ||
| 24 | |||
| 25 | @end | ||
| diff --git a/Classes/GameModeSelectionLayer.m b/Classes/GameModeSelectionLayer.m new file mode 100644 index 0000000..db08146 --- /dev/null +++ b/Classes/GameModeSelectionLayer.m | |||
| @@ -0,0 +1,132 @@ | |||
| 1 | // | ||
| 2 | // GameModeSelectionLayer.m | ||
| 3 | // Cartographic | ||
| 4 | // | ||
| 5 | // Created by Starla Insigna on 8/18/11. | ||
| 6 | // Copyright 2011 Four Island. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import "GameModeSelectionLayer.h" | ||
| 10 | #import "GameModeSelection.h" | ||
| 11 | #import <sqlite3.h> | ||
| 12 | #import "Cart_CollectAppDelegate.h" | ||
| 13 | #import "MainMenuLayer.h" | ||
| 14 | #import "TutorialMode.h" | ||
| 15 | #import "ClassicGameMode.h" | ||
| 16 | #import "NMPanelMenu.h" | ||
| 17 | |||
| 18 | @implementation GameModeSelectionLayer | ||
| 19 | |||
| 20 | + (CCScene*)scene | ||
| 21 | { | ||
| 22 | CCScene* scene = [CCScene node]; | ||
| 23 | |||
| 24 | CCLayer* backgroundLayer = [[[CCLayer alloc] init] autorelease]; | ||
| 25 | CCSprite* backgroundImage = [CCSprite spriteWithFile:@"paintdaubs.png"]; | ||
| 26 | backgroundImage.position = ccp(240,160); | ||
| 27 | [backgroundLayer addChild:backgroundImage]; | ||
| 28 | [scene addChild:backgroundLayer]; | ||
| 29 | |||
| 30 | GameModeSelectionLayer* layer = [GameModeSelectionLayer node]; | ||
| 31 | [scene addChild:layer]; | ||
| 32 | |||
| 33 | return scene; | ||
| 34 | } | ||
| 35 | |||
| 36 | - (id)init | ||
| 37 | { | ||
| 38 | self = [super init]; | ||
| 39 | |||
| 40 | if (nil != self) | ||
| 41 | { | ||
| 42 | NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | ||
| 43 | gameModes = [[NSMutableArray alloc] init]; | ||
| 44 | |||
| 45 | GameModeSelection* tutorialSelection = [GameModeSelection selectionWithName:@"Tutorial" location:@"Florence" filename:@"florence" unlocked:YES]; | ||
| 46 | [gameModes addObject:tutorialSelection]; | ||
| 47 | |||
| 48 | GameModeSelection* collectSelection; | ||
| 49 | |||
| 50 | if ([defaults boolForKey:@"hasDoneTutorial"]) | ||
| 51 | { | ||
| 52 | collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" unlocked:YES]; | ||
| 53 | } else { | ||
| 54 | collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" unlockCondition:@"Beat the tutorial!"]; | ||
| 55 | } | ||
| 56 | |||
| 57 | [gameModes addObject:collectSelection]; | ||
| 58 | |||
| 59 | CCMenu* menu = [CCMenu menuWithItems:nil]; | ||
| 60 | float onePanelWide = 128; | ||
| 61 | float padding = 15; | ||
| 62 | float totalPanelWidth = onePanelWide + padding*2; | ||
| 63 | float numberOfPanels = [gameModes count]; | ||
| 64 | float totalWidth = numberOfPanels * totalPanelWidth; | ||
| 65 | int currentWorldOffset = [defaults integerForKey:@"lastSelectedMode"]; | ||
| 66 | CCLayer* panels = [CCLayer node]; | ||
| 67 | |||
| 68 | for (GameModeSelection* gameMode in gameModes) | ||
| 69 | { | ||
| 70 | [gameMode setDelegate:self]; | ||
| 71 | [menu addChild:gameMode]; | ||
| 72 | } | ||
| 73 | |||
| 74 | [menu alignItemsHorizontallyWithPadding:padding*2]; | ||
| 75 | [panels addChild:menu]; | ||
| 76 | [self addChild:panels]; | ||
| 77 | |||
| 78 | pageControl = [[UIPageControl alloc] init]; | ||
| 79 | pageControl.numberOfPages = numberOfPanels; | ||
| 80 | pageControl.currentPage = currentWorldOffset; | ||
| 81 | pageControl.frame = CGRectMake(0, 250, 480, 20); | ||
| 82 | |||
| 83 | menu.position = ccpAdd(menu.position, ccp(totalWidth/2 - totalPanelWidth/2, 320)); | ||
| 84 | touchDelegatingView = [[TouchDelegatingView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)]; | ||
| 85 | scrollView = [[CocosOverlayScrollView alloc] initWithFrame:CGRectMake(0, 0, totalPanelWidth, 320) numPages:numberOfPanels width:totalPanelWidth layer:panels pageControl:pageControl]; | ||
| 86 | touchDelegatingView.scrollView = scrollView; | ||
| 87 | [scrollView setContentOffset:CGPointMake(currentWorldOffset*totalPanelWidth+1,0) animated:NO]; | ||
| 88 | |||
| 89 | CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back2.png" target:self selector:@selector(mainmenu)]; | ||
| 90 | NMPanelMenu* myMenu = [NMPanelMenu menuWithItems:newgameMenuItem, nil]; | ||
| 91 | myMenu.position = ccp(240, 30); | ||
| 92 | [self addChild:myMenu]; | ||
| 93 | } | ||
| 94 | |||
| 95 | return self; | ||
| 96 | } | ||
| 97 | |||
| 98 | - (void)onEnterTransitionDidFinish | ||
| 99 | { | ||
| 100 | [super onEnterTransitionDidFinish]; | ||
| 101 | |||
| 102 | [[[CCDirector sharedDirector] openGLView] addSubview:pageControl]; | ||
| 103 | [[[CCDirector sharedDirector] openGLView] addSubview:touchDelegatingView]; | ||
| 104 | [[[CCDirector sharedDirector] openGLView] addSubview:scrollView]; | ||
| 105 | } | ||
| 106 | |||
| 107 | - (void)onExit | ||
| 108 | { | ||
| 109 | [super onExit]; | ||
| 110 | |||
| 111 | [touchDelegatingView removeFromSuperview]; | ||
| 112 | [scrollView removeFromSuperview]; | ||
| 113 | [pageControl removeFromSuperview]; | ||
| 114 | } | ||
| 115 | |||
| 116 | - (void)mainmenu | ||
| 117 | { | ||
| 118 | [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; | ||
| 119 | } | ||
| 120 | |||
| 121 | - (void)didSelectGameMode:(GameModeSelection *)gameMode | ||
| 122 | { | ||
| 123 | if ([gameMode.name isEqual:@"Tutorial"]) | ||
| 124 | { | ||
| 125 | [[CCDirector sharedDirector] replaceScene:[TutorialMode scene]]; | ||
| 126 | } else if ([gameMode.name isEqual:@"Collect"]) | ||
| 127 | { | ||
| 128 | [[CCDirector sharedDirector] replaceScene:[ClassicGameMode scene]]; | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | @end | ||
| diff --git a/Classes/GameOverScene.m b/Classes/GameOverScene.m index bc081ff..94236ff 100755 --- a/Classes/GameOverScene.m +++ b/Classes/GameOverScene.m | |||
| @@ -88,15 +88,15 @@ | |||
| 88 | textField.enabled = NO; | 88 | textField.enabled = NO; |
| 89 | submitSwitch.enabled = NO; | 89 | submitSwitch.enabled = NO; |
| 90 | 90 | ||
| 91 | const char* sqlQuery = [[NSString stringWithFormat:@"INSERT INTO highscores (name, score) VALUES (\"%@\",%d)", [textField text], score] UTF8String]; | 91 | const char* sqlQuery = [[NSString stringWithFormat:@"INSERT INTO highscores (name, score, gameMode) VALUES (\"%@\",%d,\"Collect\")", [textField text], score] UTF8String]; |
| 92 | sqlite3_stmt* compiled_statement; | 92 | sqlite3_stmt* compiled_statement; |
| 93 | 93 | ||
| 94 | if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) | 94 | if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) |
| 95 | { | 95 | { |
| 96 | sqlite3_step(compiled_statement); | 96 | sqlite3_step(compiled_statement); |
| 97 | NSLog(@"awesome, %@", [textField text]); | 97 | NSLog(@"awesome, %@, %d", [textField text], score); |
| 98 | } else { | 98 | } else { |
| 99 | NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg([Cart_CollectAppDelegate database])); | 99 | NSLog(@"Error while adding highscore to local highscore list. '%s'", sqlite3_errmsg([Cart_CollectAppDelegate database])); |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | if (submitSwitch.on) | 102 | if (submitSwitch.on) |
| diff --git a/Classes/Highscore.h b/Classes/Highscore.h index bc6a8fb..fa2ea71 100755 --- a/Classes/Highscore.h +++ b/Classes/Highscore.h | |||
| @@ -17,6 +17,8 @@ | |||
| 17 | @property (readonly) NSString* name; | 17 | @property (readonly) NSString* name; |
| 18 | @property (readonly) int score; | 18 | @property (readonly) int score; |
| 19 | @property (readonly) NSDate* date; | 19 | @property (readonly) NSDate* date; |
| 20 | + (NSArray*)localHighscoreListForGameMode:(NSString*)gameMode; | ||
| 21 | + (Highscore*)localHighscoreForGameMode:(NSString*)gameMode; | ||
| 20 | - (id)initWithName:(NSString*)name score:(int)score date:(NSDate*)date; | 22 | - (id)initWithName:(NSString*)name score:(int)score date:(NSDate*)date; |
| 21 | 23 | ||
| 22 | @end | 24 | @end |
| diff --git a/Classes/Highscore.m b/Classes/Highscore.m index 20ce56f..546cbfe 100755 --- a/Classes/Highscore.m +++ b/Classes/Highscore.m | |||
| @@ -7,11 +7,64 @@ | |||
| 7 | // | 7 | // |
| 8 | 8 | ||
| 9 | #import "Highscore.h" | 9 | #import "Highscore.h" |
| 10 | #import <sqlite3.h> | ||
| 11 | #import "Cart_CollectAppDelegate.h" | ||
| 10 | 12 | ||
| 11 | @implementation Highscore | 13 | @implementation Highscore |
| 12 | 14 | ||
| 13 | @synthesize name, score, date; | 15 | @synthesize name, score, date; |
| 14 | 16 | ||
| 17 | + (NSArray*)localHighscoreListForGameMode:(NSString*)gameMode | ||
| 18 | { | ||
| 19 | NSMutableArray* highscores = [NSMutableArray arrayWithCapacity:15]; | ||
| 20 | const char* sqlQuery = [[NSString stringWithFormat:@"SELECT * FROM highscores WHERE gameMode = \"%@\" ORDER BY score DESC LIMIT 15", gameMode] UTF8String]; | ||
| 21 | sqlite3_stmt* compiled_statement; | ||
| 22 | |||
| 23 | if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) | ||
| 24 | { | ||
| 25 | while (sqlite3_step(compiled_statement) == SQLITE_ROW) | ||
| 26 | { | ||
| 27 | NSString* name = [NSString stringWithUTF8String:(char*)sqlite3_column_text(compiled_statement, 1)]; | ||
| 28 | int score = sqlite3_column_int(compiled_statement, 2); | ||
| 29 | |||
| 30 | NSDate* date = nil; | ||
| 31 | char* dateStr = (char*)sqlite3_column_text(compiled_statement, 3); | ||
| 32 | if (dateStr != NULL) | ||
| 33 | { | ||
| 34 | NSString* theDate = [NSString stringWithUTF8String:dateStr]; | ||
| 35 | NSDateComponents* comps = [[NSDateComponents alloc] init]; | ||
| 36 | [comps setYear:[[theDate substringToIndex:4] intValue]]; | ||
| 37 | [comps setMonth:[[theDate substringWithRange:NSMakeRange(5, 2)] intValue]]; | ||
| 38 | [comps setDay:[[theDate substringWithRange:NSMakeRange(8, 2)] intValue]]; | ||
| 39 | [comps setHour:[[theDate substringWithRange:NSMakeRange(11, 2)] intValue]]; | ||
| 40 | [comps setMinute:[[theDate substringWithRange:NSMakeRange(14, 2)] intValue]]; | ||
| 41 | [comps setSecond:[[theDate substringWithRange:NSMakeRange(17, 2)] intValue]]; | ||
| 42 | date = [[NSCalendar currentCalendar] dateFromComponents:comps]; | ||
| 43 | date = [date dateByAddingTimeInterval:[[NSTimeZone localTimeZone] secondsFromGMT]]; | ||
| 44 | [comps release]; | ||
| 45 | } | ||
| 46 | |||
| 47 | Highscore* highscore = [[Highscore alloc] initWithName:name score:score date:date]; | ||
| 48 | [highscores addObject:highscore]; | ||
| 49 | [highscore release]; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | return [highscores copy]; | ||
| 54 | } | ||
| 55 | |||
| 56 | + (Highscore*)localHighscoreForGameMode:(NSString*)gameMode | ||
| 57 | { | ||
| 58 | NSArray* localHighscores = [Highscore localHighscoreListForGameMode:gameMode]; | ||
| 59 | |||
| 60 | if ([localHighscores count] > 0) | ||
| 61 | { | ||
| 62 | return [localHighscores objectAtIndex:0]; | ||
| 63 | } else { | ||
| 64 | return nil; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 15 | - (id)initWithName:(NSString*)m_name score:(int)m_score date:(NSDate*)m_date | 68 | - (id)initWithName:(NSString*)m_name score:(int)m_score date:(NSDate*)m_date |
| 16 | { | 69 | { |
| 17 | self = [super init]; | 70 | self = [super init]; |
| diff --git a/Classes/HighscoreListController.m b/Classes/HighscoreListController.m index 932b147..d7bffcb 100755 --- a/Classes/HighscoreListController.m +++ b/Classes/HighscoreListController.m | |||
| @@ -10,7 +10,6 @@ | |||
| 10 | #import "Highscore.h" | 10 | #import "Highscore.h" |
| 11 | #import "RootViewController.h" | 11 | #import "RootViewController.h" |
| 12 | #import "cocoslive.h" | 12 | #import "cocoslive.h" |
| 13 | #import <sqlite3.h> | ||
| 14 | #import "Cart_CollectAppDelegate.h" | 13 | #import "Cart_CollectAppDelegate.h" |
| 15 | 14 | ||
| 16 | @implementation HighscoreListController | 15 | @implementation HighscoreListController |
| @@ -23,41 +22,7 @@ | |||
| 23 | // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. | 22 | // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. |
| 24 | self = [super initWithStyle:style]; | 23 | self = [super initWithStyle:style]; |
| 25 | if (self) { | 24 | if (self) { |
| 26 | NSMutableArray* highscores = [NSMutableArray arrayWithCapacity:15]; | 25 | localHighscores = [Highscore localHighscoreListForGameMode:@"Collect"]; |
| 27 | const char* sqlQuery = "SELECT * FROM highscores ORDER BY score DESC LIMIT 15"; | ||
| 28 | sqlite3_stmt* compiled_statement; | ||
| 29 | |||
| 30 | if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) | ||
| 31 | { | ||
| 32 | while (sqlite3_step(compiled_statement) == SQLITE_ROW) | ||
| 33 | { | ||
| 34 | NSString* name = [NSString stringWithUTF8String:(char*)sqlite3_column_text(compiled_statement, 1)]; | ||
| 35 | int score = sqlite3_column_int(compiled_statement, 2); | ||
| 36 | |||
| 37 | NSDate* date = nil; | ||
| 38 | char* dateStr = (char*)sqlite3_column_text(compiled_statement, 3); | ||
| 39 | if (dateStr != NULL) | ||
| 40 | { | ||
| 41 | NSString* theDate = [NSString stringWithUTF8String:dateStr]; | ||
| 42 | NSDateComponents* comps = [[NSDateComponents alloc] init]; | ||
| 43 | [comps setYear:[[theDate substringToIndex:4] intValue]]; | ||
| 44 | [comps setMonth:[[theDate substringWithRange:NSMakeRange(5, 2)] intValue]]; | ||
| 45 | [comps setDay:[[theDate substringWithRange:NSMakeRange(8, 2)] intValue]]; | ||
| 46 | [comps setHour:[[theDate substringWithRange:NSMakeRange(11, 2)] intValue]]; | ||
| 47 | [comps setMinute:[[theDate substringWithRange:NSMakeRange(14, 2)] intValue]]; | ||
| 48 | [comps setSecond:[[theDate substringWithRange:NSMakeRange(17, 2)] intValue]]; | ||
| 49 | date = [[NSCalendar currentCalendar] dateFromComponents:comps]; | ||
| 50 | date = [date dateByAddingTimeInterval:[[NSTimeZone localTimeZone] secondsFromGMT]]; | ||
| 51 | [comps release]; | ||
| 52 | } | ||
| 53 | |||
| 54 | Highscore* highscore = [[Highscore alloc] initWithName:name score:score date:date]; | ||
| 55 | [highscores addObject:highscore]; | ||
| 56 | [highscore release]; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | localHighscores = [highscores copy]; | ||
| 61 | 26 | ||
| 62 | navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; | 27 | navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; |
| 63 | myNavigationItem = [[UINavigationItem alloc] initWithTitle:@"Highscores"]; | 28 | myNavigationItem = [[UINavigationItem alloc] initWithTitle:@"Highscores"]; |
| diff --git a/Classes/MainMenuLayer.h b/Classes/MainMenuLayer.h index c7e3348..439056c 100755 --- a/Classes/MainMenuLayer.h +++ b/Classes/MainMenuLayer.h | |||
| @@ -16,8 +16,7 @@ | |||
| 16 | + (CCScene*)scene; | 16 | + (CCScene*)scene; |
| 17 | - (id)init; | 17 | - (id)init; |
| 18 | - (void)newgame; | 18 | - (void)newgame; |
| 19 | - (void)tutorial; | ||
| 20 | - (void)jump; | ||
| 21 | - (void)highscores; | 19 | - (void)highscores; |
| 20 | - (void)feedback; | ||
| 22 | 21 | ||
| 23 | @end | 22 | @end |
| diff --git a/Classes/MainMenuLayer.m b/Classes/MainMenuLayer.m index cf4b8cf..d4a6331 100755 --- a/Classes/MainMenuLayer.m +++ b/Classes/MainMenuLayer.m | |||
| @@ -8,10 +8,9 @@ | |||
| 8 | 8 | ||
| 9 | #import "MainMenuLayer.h" | 9 | #import "MainMenuLayer.h" |
| 10 | #import "HighscoreListController.h" | 10 | #import "HighscoreListController.h" |
| 11 | #import "ClassicGameMode.h" | 11 | #import "GameModeSelectionLayer.h" |
| 12 | #import "TutorialMode.h" | ||
| 13 | #import "Cart_CollectAppDelegate.h" | 12 | #import "Cart_CollectAppDelegate.h" |
| 14 | #import "JumpGameMode.h" | 13 | #import "TestFlight.h" |
| 15 | 14 | ||
| 16 | @implementation MainMenuLayer | 15 | @implementation MainMenuLayer |
| 17 | 16 | ||
| @@ -35,7 +34,7 @@ | |||
| 35 | backgroundImage.position = ccp(240,160); | 34 | backgroundImage.position = ccp(240,160); |
| 36 | [self addChild:backgroundImage]; | 35 | [self addChild:backgroundImage]; |
| 37 | 36 | ||
| 38 | CCLabelBMFont* titleText = [CCLabelBMFont labelWithString:@"Cart Collect - The Game!" fntFile:@"getoffthatboatrightnowyounglady.fnt"]; | 37 | CCLabelBMFont* titleText = [CCLabelBMFont labelWithString:@"Cartographic - The Game!" fntFile:@"getoffthatboatrightnowyounglady.fnt"]; |
| 39 | titleText.position = ccp(240, 320-64); | 38 | titleText.position = ccp(240, 320-64); |
| 40 | [self addChild:titleText]; | 39 | [self addChild:titleText]; |
| 41 | 40 | ||
| @@ -46,11 +45,10 @@ | |||
| 46 | //CCMenuItemLabel* menuItem2 = [CCMenuItemLabel itemWithLabel:menuItemLabel2 target:self selector:@selector(highscores)]; | 45 | //CCMenuItemLabel* menuItem2 = [CCMenuItemLabel itemWithLabel:menuItemLabel2 target:self selector:@selector(highscores)]; |
| 47 | 46 | ||
| 48 | CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"newgame.png" selectedImage:@"newgame2.png" target:self selector:@selector(newgame)]; | 47 | CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"newgame.png" selectedImage:@"newgame2.png" target:self selector:@selector(newgame)]; |
| 49 | CCMenuItemImage* tutorialMenuItem = [CCMenuItemImage itemFromNormalImage:@"tutorial.png" selectedImage:@"tutorial2.png" target:self selector:@selector(tutorial)]; | ||
| 50 | CCMenuItemImage* jumpMenuItem = [CCMenuItemImage itemFromNormalImage:@"jump.png" selectedImage:@"jump2.png" target:self selector:@selector(jump)]; | ||
| 51 | CCMenuItemImage* highscoresMenuItem = [CCMenuItemImage itemFromNormalImage:@"highscores.png" selectedImage:@"highscores2.png" target:self selector:@selector(highscores)]; | 48 | CCMenuItemImage* highscoresMenuItem = [CCMenuItemImage itemFromNormalImage:@"highscores.png" selectedImage:@"highscores2.png" target:self selector:@selector(highscores)]; |
| 52 | 49 | CCMenuItemImage* feedbackMenuItem = [CCMenuItemImage itemFromNormalImage:@"feedback.png" selectedImage:@"feedback2.png" target:self selector:@selector(feedback)]; | |
| 53 | CCMenu* menu = [CCMenu menuWithItems:newgameMenuItem, tutorialMenuItem, jumpMenuItem, highscoresMenuItem, nil]; | 50 | |
| 51 | CCMenu* menu = [CCMenu menuWithItems:newgameMenuItem, highscoresMenuItem, feedbackMenuItem, nil]; | ||
| 54 | [menu alignItemsVertically]; | 52 | [menu alignItemsVertically]; |
| 55 | menu.position = ccp(240, 100); | 53 | menu.position = ccp(240, 100); |
| 56 | [self addChild:menu]; | 54 | [self addChild:menu]; |
| @@ -61,17 +59,7 @@ | |||
| 61 | 59 | ||
| 62 | - (void)newgame | 60 | - (void)newgame |
| 63 | { | 61 | { |
| 64 | [[CCDirector sharedDirector] replaceScene:[ClassicGameMode scene]]; | 62 | [[CCDirector sharedDirector] replaceScene:[GameModeSelectionLayer scene]]; |
| 65 | } | ||
| 66 | |||
| 67 | - (void)tutorial | ||
| 68 | { | ||
| 69 | [[CCDirector sharedDirector] replaceScene:[TutorialMode scene]]; | ||
| 70 | } | ||
| 71 | |||
| 72 | - (void)jump | ||
| 73 | { | ||
| 74 | [[CCDirector sharedDirector] replaceScene:[JumpGameMode scene]]; | ||
| 75 | } | 63 | } |
| 76 | 64 | ||
| 77 | - (void)highscores | 65 | - (void)highscores |
| @@ -82,4 +70,9 @@ | |||
| 82 | [listController release]; | 70 | [listController release]; |
| 83 | } | 71 | } |
| 84 | 72 | ||
| 73 | - (void)feedback | ||
| 74 | { | ||
| 75 | [TestFlight openFeedbackView]; | ||
| 76 | } | ||
| 77 | |||
| 85 | @end | 78 | @end |
| diff --git a/Classes/NMPanelMenu.h b/Classes/NMPanelMenu.h new file mode 100755 index 0000000..3487849 --- /dev/null +++ b/Classes/NMPanelMenu.h | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | /* | ||
| 2 | * NMPanelMenu.h | ||
| 3 | * shapes | ||
| 4 | * | ||
| 5 | * Created by Nate Murray on 7/29/10. | ||
| 6 | * Copyright 2010 YetiApps. All rights reserved. | ||
| 7 | * | ||
| 8 | */ | ||
| 9 | |||
| 10 | #import "cocos2d.h" | ||
| 11 | @interface NMPanelMenu : CCMenu { | ||
| 12 | } | ||
| 13 | -(CCMenuItem *) itemForTouch: (UITouch *) touch; | ||
| 14 | @end | ||
| diff --git a/Classes/NMPanelMenu.m b/Classes/NMPanelMenu.m new file mode 100755 index 0000000..ee24279 --- /dev/null +++ b/Classes/NMPanelMenu.m | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | /* | ||
| 2 | * NMPanelMenu.m | ||
| 3 | * shapes | ||
| 4 | * | ||
| 5 | * Created by Nate Murray on 7/29/10. | ||
| 6 | * Copyright 2010 YetiApps. All rights reserved. | ||
| 7 | * | ||
| 8 | */ | ||
| 9 | |||
| 10 | #import "NMPanelMenu.h" | ||
| 11 | |||
| 12 | @implementation NMPanelMenu | ||
| 13 | |||
| 14 | -(CCMenuItem *) itemForTouch: (UITouch *) touch | ||
| 15 | { | ||
| 16 | CGPoint touchLocation = [touch locationInView: [[touch view] superview]]; | ||
| 17 | touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation]; | ||
| 18 | |||
| 19 | CCMenuItem* item; | ||
| 20 | CCARRAY_FOREACH(children_, item){ | ||
| 21 | // ignore invisible and disabled items: issue #779, #866 | ||
| 22 | if ( [item visible] && [item isEnabled] ) { | ||
| 23 | |||
| 24 | CGPoint local = [item convertToNodeSpace:touchLocation]; | ||
| 25 | |||
| 26 | CGRect r = [item rect]; | ||
| 27 | r.origin = CGPointZero; | ||
| 28 | |||
| 29 | if( CGRectContainsPoint( r, local ) ) { | ||
| 30 | return item; | ||
| 31 | } | ||
| 32 | } | ||
| 33 | } | ||
| 34 | return nil; | ||
| 35 | } | ||
| 36 | |||
| 37 | @end | ||
| diff --git a/Classes/TouchDelegatingView.h b/Classes/TouchDelegatingView.h new file mode 100755 index 0000000..5ed6884 --- /dev/null +++ b/Classes/TouchDelegatingView.h | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | // | ||
| 2 | // TouchDelegatingView.h | ||
| 3 | // shapes | ||
| 4 | // | ||
| 5 | // Created by Nate Murray on 8/23/10. | ||
| 6 | // Copyright 2010 LittleHiccup. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import <Foundation/Foundation.h> | ||
| 10 | #import "CocosOverLayScrollView.h" | ||
| 11 | |||
| 12 | @interface TouchDelegatingView : UIView { | ||
| 13 | // UIPageControl* pageControl; | ||
| 14 | CocosOverlayScrollView* scrollView; | ||
| 15 | } | ||
| 16 | @property(nonatomic, retain) CocosOverlayScrollView* scrollView; | ||
| 17 | |||
| 18 | @end | ||
| diff --git a/Classes/TouchDelegatingView.m b/Classes/TouchDelegatingView.m new file mode 100755 index 0000000..83bda73 --- /dev/null +++ b/Classes/TouchDelegatingView.m | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | // | ||
| 2 | // TouchDelegatingView.m | ||
| 3 | // Jacob's Shapes | ||
| 4 | // | ||
| 5 | // Created by Nate Murray on 8/23/10. | ||
| 6 | // Copyright 2010 LittleHiccup. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import "TouchDelegatingView.h" | ||
| 10 | |||
| 11 | @implementation TouchDelegatingView | ||
| 12 | @synthesize scrollView; | ||
| 13 | |||
| 14 | - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { | ||
| 15 | if ([self pointInside:point withEvent:event]) { | ||
| 16 | return self.scrollView; | ||
| 17 | } | ||
| 18 | return nil; | ||
| 19 | } | ||
| 20 | |||
| 21 | -(void) dealloc { | ||
| 22 | self.scrollView = nil; | ||
| 23 | [super dealloc]; | ||
| 24 | } | ||
| 25 | |||
| 26 | @end | ||
| diff --git a/Classes/TutorialMode.m b/Classes/TutorialMode.m index ed51648..3c70a46 100644 --- a/Classes/TutorialMode.m +++ b/Classes/TutorialMode.m | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | #import "Bottle.h" | 12 | #import "Bottle.h" |
| 13 | #import "OneUp.h" | 13 | #import "OneUp.h" |
| 14 | #import "Rock.h" | 14 | #import "Rock.h" |
| 15 | #import "MainMenuLayer.h" | 15 | #import "GameModeSelectionLayer.h" |
| 16 | 16 | ||
| 17 | // Item tags: | 17 | // Item tags: |
| 18 | // 2000 - first dropped item | 18 | // 2000 - first dropped item |
| @@ -20,6 +20,7 @@ | |||
| 20 | // 2002 - items that are dropped after you miss first dropped item to demonstrate what happens when you catch | 20 | // 2002 - items that are dropped after you miss first dropped item to demonstrate what happens when you catch |
| 21 | // 2003 - 1-Up | 21 | // 2003 - 1-Up |
| 22 | // 2009 - rock | 22 | // 2009 - rock |
| 23 | // 2010 - random item dropped after death from first rock | ||
| 23 | 24 | ||
| 24 | @implementation TutorialMode | 25 | @implementation TutorialMode |
| 25 | 26 | ||
| @@ -47,7 +48,7 @@ | |||
| 47 | [super onEnterTransitionDidFinish]; | 48 | [super onEnterTransitionDidFinish]; |
| 48 | 49 | ||
| 49 | [self scheduleDelayedAction:^{ | 50 | [self scheduleDelayedAction:^{ |
| 50 | TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"Welcome to Cart Collect. This is a tutorial designed to help you get started playing the game. Below this bubble is a cart. Tilt your device to move it." name:@"cart" spriteReference:cart.sprite]; | 51 | TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"Welcome to Cartographic. This is a tutorial designed to help you get started playing the game. Below this bubble is a cart. Tilt your device to move it." name:@"cart" spriteReference:cart.sprite]; |
| 51 | self.currentTutorial = bubble; | 52 | self.currentTutorial = bubble; |
| 52 | [bubble release]; | 53 | [bubble release]; |
| 53 | } delay:2.0f]; | 54 | } delay:2.0f]; |
| @@ -122,7 +123,30 @@ | |||
| 122 | [self schedule:@selector(randomlyAddObject:) interval:2.5f]; | 123 | [self schedule:@selector(randomlyAddObject:) interval:2.5f]; |
| 123 | } else if (item.sprite.tag == 2009) | 124 | } else if (item.sprite.tag == 2009) |
| 124 | { | 125 | { |
| 125 | TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"As you play, Cart Collect gets progressively more intense. Watch what happens when rocks are added to the mix and the speed is turned up." name:@"intense"]; | 126 | if ((lives < 1) && (!showedDeathBubble)) |
| 127 | { | ||
| 128 | showedDeathBubble = YES; | ||
| 129 | |||
| 130 | TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"You lost all your lives! Normally, you'd be taken to a game over screen where you could submit your score to the highscore list, but we're a bit more forgiving in tutorial mode." name:@"gameover-rock"]; | ||
| 131 | self.currentTutorial = bubble; | ||
| 132 | [bubble release]; | ||
| 133 | } else { | ||
| 134 | TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"As you play, Cartographic gets progressively more intense. Watch what happens when rocks are added to the mix and the speed is turned up." name:@"intense"]; | ||
| 135 | self.currentTutorial = bubble; | ||
| 136 | [bubble release]; | ||
| 137 | } | ||
| 138 | } else if (item.sprite.tag == 2010) | ||
| 139 | { | ||
| 140 | TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"As you play, Cartographic gets progressively more intense. Watch what happens when rocks are added to the mix and the speed is turned up." name:@"intense"]; | ||
| 141 | self.currentTutorial = bubble; | ||
| 142 | [bubble release]; | ||
| 143 | } | ||
| 144 | |||
| 145 | if ((lives < 1) && (!showedDeathBubble)) | ||
| 146 | { | ||
| 147 | showedDeathBubble = YES; | ||
| 148 | |||
| 149 | TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"You lost all your lives! Normally, you'd be taken to a game over screen where you could submit your score to the highscore list, but we're a bit more forgiving in tutorial mode." name:@"gameover"]; | ||
| 126 | self.currentTutorial = bubble; | 150 | self.currentTutorial = bubble; |
| 127 | [bubble release]; | 151 | [bubble release]; |
| 128 | } | 152 | } |
| @@ -191,12 +215,19 @@ | |||
| 191 | object.sprite.tag = 2003; | 215 | object.sprite.tag = 2003; |
| 192 | [object release]; | 216 | [object release]; |
| 193 | } delay:2.0f]; | 217 | } delay:2.0f]; |
| 218 | } else if ([currentTutorial.name isEqual:@"gameover-rock"]) | ||
| 219 | { | ||
| 220 | [self scheduleDelayedAction:^{ | ||
| 221 | FallingObject* object = [self dropRandomItem]; | ||
| 222 | object.sprite.tag = 2010; | ||
| 223 | [object release]; | ||
| 224 | } delay:1.0f]; | ||
| 194 | } else if ([currentTutorial.name isEqual:@"intense"]) | 225 | } else if ([currentTutorial.name isEqual:@"intense"]) |
| 195 | { | 226 | { |
| 196 | [self schedule:@selector(randomlyAddObject:) interval:1.0f]; | 227 | [self schedule:@selector(randomlyAddObject:) interval:1.0f]; |
| 197 | } else if ([currentTutorial.name isEqual:@"end"]) | 228 | } else if ([currentTutorial.name isEqual:@"end"]) |
| 198 | { | 229 | { |
| 199 | [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:3.0f scene:[MainMenuLayer scene] withColor:ccc3(0,0,0)]]; | 230 | [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:3.0f scene:[GameModeSelectionLayer scene] withColor:ccc3(0,0,0)]]; |
| 200 | } | 231 | } |
| 201 | 232 | ||
| 202 | self.currentTutorial = nil; | 233 | self.currentTutorial = nil; |
| @@ -252,20 +283,6 @@ | |||
| 252 | return [self dropSpecificItem:object]; | 283 | return [self dropSpecificItem:object]; |
| 253 | } | 284 | } |
| 254 | 285 | ||
| 255 | - (void)setLives:(int)m_lives | ||
| 256 | { | ||
| 257 | [super setLives:m_lives]; | ||
| 258 | |||
| 259 | if ((lives < 1) && (!showedDeathBubble)) | ||
| 260 | { | ||
| 261 | showedDeathBubble = YES; | ||
| 262 | |||
| 263 | TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"You lost all your lives! Normally, you'd be taken to a game over screen where you could submit your score to the highscore list, but we're a bit more forgiving in tutorial mode." name:@"gameover"]; | ||
| 264 | self.currentTutorial = bubble; | ||
| 265 | [bubble release]; | ||
| 266 | } | ||
| 267 | } | ||
| 268 | |||
| 269 | - (void)randomlyAddObject:(ccTime)dt | 286 | - (void)randomlyAddObject:(ccTime)dt |
| 270 | { | 287 | { |
| 271 | FallingObject* object; | 288 | FallingObject* object; |
| @@ -307,13 +324,16 @@ | |||
| 307 | } else if (randomItemsDropped == 15) | 324 | } else if (randomItemsDropped == 15) |
| 308 | { | 325 | { |
| 309 | [self scheduleDelayedAction:^{ | 326 | [self scheduleDelayedAction:^{ |
| 310 | TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"That's pretty much it! You've completed the tutorial, so now it's time to play an actual game of Cart Collect!" name:@"end"]; | 327 | TutorialBubble* bubble = [[TutorialBubble alloc] initWithText:@"That's pretty much it! You've completed the tutorial, so now it's time to play an actual game of Cartographic!" name:@"end"]; |
| 311 | self.currentTutorial = bubble; | 328 | self.currentTutorial = bubble; |
| 312 | [bubble release]; | 329 | [bubble release]; |
| 313 | } delay:2.0f]; | 330 | } delay:2.0f]; |
| 314 | 331 | ||
| 315 | [self unschedule:@selector(randomlyAddObject:)]; | 332 | [self unschedule:@selector(randomlyAddObject:)]; |
| 316 | 333 | ||
| 334 | NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | ||
| 335 | [defaults setBool:YES forKey:@"hasDoneTutorial"]; | ||
| 336 | |||
| 317 | return; | 337 | return; |
| 318 | } else { | 338 | } else { |
| 319 | NSLog(@"randomItemsDropped in TutorialMode is greater than 15--this should never happen."); | 339 | NSLog(@"randomItemsDropped in TutorialMode is greater than 15--this should never happen."); |
| diff --git a/Classes/UIImage+ColorMasking.h b/Classes/UIImage+ColorMasking.h new file mode 100644 index 0000000..d25fafb --- /dev/null +++ b/Classes/UIImage+ColorMasking.h | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | // | ||
| 2 | // UIImage+ColorMasking.h | ||
| 3 | // Cartographic | ||
| 4 | // | ||
| 5 | // Created by Starla Insigna on 8/22/11. | ||
| 6 | // Copyright 2011 Four Island. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import <UIKit/UIKit.h> | ||
| 10 | |||
| 11 | @interface UIImage (ColorMasking) | ||
| 12 | |||
| 13 | - (UIImage *)opaqueMaskFromWhiteImage; | ||
| 14 | |||
| 15 | @end | ||
| diff --git a/Classes/UIImage+ColorMasking.m b/Classes/UIImage+ColorMasking.m new file mode 100644 index 0000000..e4da8c8 --- /dev/null +++ b/Classes/UIImage+ColorMasking.m | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | // | ||
| 2 | // UIImage+ColorMasking.m | ||
| 3 | // Cartographic | ||
| 4 | // | ||
| 5 | // Created by Starla Insigna on 8/22/11. | ||
| 6 | // Copyright 2011 Four Island. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import "UIImage+ColorMasking.h" | ||
| 10 | |||
| 11 | @implementation UIImage (ColorMasking) | ||
| 12 | |||
| 13 | typedef enum { | ||
| 14 | ALPHA = 0, | ||
| 15 | BLUE = 1, | ||
| 16 | GREEN = 2, | ||
| 17 | RED = 3 | ||
| 18 | } PIXELS; | ||
| 19 | |||
| 20 | - (UIImage *)opaqueMaskFromWhiteImage | ||
| 21 | { | ||
| 22 | CGSize size = [self size]; | ||
| 23 | int width = size.width; | ||
| 24 | int height = size.height; | ||
| 25 | |||
| 26 | // the pixels will be painted to this array | ||
| 27 | uint32_t *pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t)); | ||
| 28 | |||
| 29 | // clear the pixels so any transparency is preserved | ||
| 30 | memset(pixels, 0, width * height * sizeof(uint32_t)); | ||
| 31 | |||
| 32 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | ||
| 33 | |||
| 34 | // create a context with RGBA pixels | ||
| 35 | CGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace, | ||
| 36 | kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast); | ||
| 37 | |||
| 38 | // paint the bitmap to our context which will fill in the pixels array | ||
| 39 | CGContextDrawImage(context, CGRectMake(0, 0, width, height), [self CGImage]); | ||
| 40 | |||
| 41 | for(int y = 0; y < height; y++) { | ||
| 42 | for(int x = 0; x < width; x++) { | ||
| 43 | uint8_t *rgbaPixel = (uint8_t *) &pixels[y * width + x]; | ||
| 44 | |||
| 45 | if ((rgbaPixel[RED] == 255) && (rgbaPixel[GREEN] == 255) && (rgbaPixel[BLUE] == 255) && (rgbaPixel[ALPHA] == 255)) | ||
| 46 | { | ||
| 47 | rgbaPixel[RED] = 255; | ||
| 48 | rgbaPixel[GREEN] = 255; | ||
| 49 | rgbaPixel[BLUE] = 255; | ||
| 50 | rgbaPixel[ALPHA] = 255; | ||
| 51 | } else { | ||
| 52 | rgbaPixel[RED] = 0; | ||
| 53 | rgbaPixel[GREEN] = 0; | ||
| 54 | rgbaPixel[BLUE] = 0; | ||
| 55 | rgbaPixel[ALPHA] = 0; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | // create a new CGImageRef from our context with the modified pixels | ||
| 61 | CGImageRef image = CGBitmapContextCreateImage(context); | ||
| 62 | |||
| 63 | // we're done with the context, color space, and pixels | ||
| 64 | CGContextRelease(context); | ||
| 65 | CGColorSpaceRelease(colorSpace); | ||
| 66 | free(pixels); | ||
| 67 | |||
| 68 | // make a new UIImage to return | ||
| 69 | UIImage *resultUIImage = [UIImage imageWithCGImage:image]; | ||
| 70 | |||
| 71 | // we're done with image now too | ||
| 72 | CGImageRelease(image); | ||
| 73 | |||
| 74 | return resultUIImage; | ||
| 75 | } | ||
| 76 | |||
| 77 | @end | ||
