diff options
Diffstat (limited to 'Classes')
| -rwxr-xr-x | Classes/CocosOverlayScrollView.h | 19 | ||||
| -rwxr-xr-x | Classes/CocosOverlayScrollView.m | 106 | ||||
| -rw-r--r-- | Classes/GameModeSelection.h | 32 | ||||
| -rw-r--r-- | Classes/GameModeSelection.m | 228 | ||||
| -rw-r--r-- | Classes/GameModeSelectionDelegate.h | 17 | ||||
| -rw-r--r-- | Classes/GameModeSelectionLayer.h | 25 | ||||
| -rw-r--r-- | Classes/GameModeSelectionLayer.m | 138 | ||||
| -rwxr-xr-x | Classes/MainMenuLayer.h | 1 | ||||
| -rwxr-xr-x | Classes/MainMenuLayer.m | 17 | ||||
| -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 | 7 | ||||
| -rw-r--r-- | Classes/UIImage+ColorMasking.h | 15 | ||||
| -rw-r--r-- | Classes/UIImage+ColorMasking.m | 77 |
16 files changed, 762 insertions, 15 deletions
| 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..dee9dfe --- /dev/null +++ b/Classes/CocosOverlayScrollView.m | |||
| @@ -0,0 +1,106 @@ | |||
| 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 | [pageControl setCurrentPage:(NSUInteger)([scrollView contentOffset].x / [scrollView frame].size.width)]; | ||
| 104 | } | ||
| 105 | |||
| 106 | @end \ No newline at end of file | ||
| diff --git a/Classes/GameModeSelection.h b/Classes/GameModeSelection.h new file mode 100644 index 0000000..f69ea37 --- /dev/null +++ b/Classes/GameModeSelection.h | |||
| @@ -0,0 +1,32 @@ | |||
| 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 highscore:(int)highscore; | ||
| 26 | + (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition; | ||
| 27 | - (id)initWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked; | ||
| 28 | - (id)initWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename highscore:(int)highscore; | ||
| 29 | - (id)initWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition; | ||
| 30 | - (void)buttonTapped; | ||
| 31 | |||
| 32 | @end | ||
| diff --git a/Classes/GameModeSelection.m b/Classes/GameModeSelection.m new file mode 100644 index 0000000..582c9dd --- /dev/null +++ b/Classes/GameModeSelection.m | |||
| @@ -0,0 +1,228 @@ | |||
| 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 | |||
| 13 | @implementation GameModeSelection | ||
| 14 | |||
| 15 | @synthesize name, location, unlocked, delegate; | ||
| 16 | |||
| 17 | + (id)selectionWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked | ||
| 18 | { | ||
| 19 | return [[[GameModeSelection alloc] initWithName:name location:location filename:filename unlocked:unlocked] autorelease]; | ||
| 20 | } | ||
| 21 | |||
| 22 | + (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename highscore:(int)highscore | ||
| 23 | { | ||
| 24 | return [[[GameModeSelection alloc] initWithName:name location:location filename:filename highscore:highscore] autorelease]; | ||
| 25 | } | ||
| 26 | |||
| 27 | + (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition | ||
| 28 | { | ||
| 29 | return [[[GameModeSelection alloc] initWithName:name location:location filename:filename unlockCondition:unlockCondition] autorelease]; | ||
| 30 | } | ||
| 31 | |||
| 32 | - (id)initWithName:(NSString*)m_name location:(NSString*)m_location filename:(NSString*)filename unlocked:(BOOL)m_unlocked; | ||
| 33 | { | ||
| 34 | self = [super initWithTarget:nil selector:nil]; | ||
| 35 | |||
| 36 | if (nil != self) | ||
| 37 | { | ||
| 38 | self.anchorPoint = CGPointMake(0.5f, 0.5f); | ||
| 39 | |||
| 40 | name = m_name; | ||
| 41 | location = m_location; | ||
| 42 | unlocked = m_unlocked; | ||
| 43 | |||
| 44 | contentSize_ = CGSizeMake(128, 320); | ||
| 45 | |||
| 46 | NSString* filenameMod; | ||
| 47 | |||
| 48 | if (unlocked) | ||
| 49 | { | ||
| 50 | filenameMod = [NSString stringWithFormat:@"%@-unlocked", filename]; | ||
| 51 | } else { | ||
| 52 | filenameMod = [NSString stringWithFormat:@"%@-locked", filename]; | ||
| 53 | name = [@"" stringByPaddingToLength:name.length withString:@"?" startingAtIndex:0]; | ||
| 54 | location = [@"" stringByPaddingToLength:location.length withString:@"?" startingAtIndex:0]; | ||
| 55 | } | ||
| 56 | |||
| 57 | // First, create the frame that we will put the level picture inside | ||
| 58 | CGImageRef framestuff = [[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"framestuff" ofType:@"png"]] CGImage]; | ||
| 59 | CGImageRef topLeftRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(0, 0, 8, 8)); | ||
| 60 | CGImageRef topRightRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(8, 0, 8, 8)); | ||
| 61 | CGImageRef bottomLeftRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(0, 8, 8, 8)); | ||
| 62 | CGImageRef bottomRightRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(8, 8, 8, 8)); | ||
| 63 | CGImageRef topBorderRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(0, 16, 8, 8)); | ||
| 64 | CGImageRef leftBorderRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(8, 16, 8, 8)); | ||
| 65 | CGImageRef rightBorderRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(0, 24, 8, 8)); | ||
| 66 | CGImageRef bottomBorderRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(8, 24, 8, 8)); | ||
| 67 | UIImage* topLeft = [UIImage imageWithCGImage:topLeftRef]; | ||
| 68 | UIImage* topRight = [UIImage imageWithCGImage:topRightRef]; | ||
| 69 | UIImage* bottomLeft = [UIImage imageWithCGImage:bottomLeftRef]; | ||
| 70 | UIImage* bottomRight = [UIImage imageWithCGImage:bottomRightRef]; | ||
| 71 | UIImage* topBorder = [UIImage imageWithCGImage:topBorderRef]; | ||
| 72 | UIImage* leftBorder = [UIImage imageWithCGImage:leftBorderRef]; | ||
| 73 | UIImage* rightBorder = [UIImage imageWithCGImage:rightBorderRef]; | ||
| 74 | UIImage* bottomBorder = [UIImage imageWithCGImage:bottomBorderRef]; | ||
| 75 | CGImageRelease(topLeftRef); | ||
| 76 | CGImageRelease(topRightRef); | ||
| 77 | CGImageRelease(bottomLeftRef); | ||
| 78 | CGImageRelease(bottomRightRef); | ||
| 79 | CGImageRelease(topBorderRef); | ||
| 80 | CGImageRelease(leftBorderRef); | ||
| 81 | CGImageRelease(rightBorderRef); | ||
| 82 | CGImageRelease(bottomBorderRef); | ||
| 83 | |||
| 84 | CGSize boxSize = CGSizeMake(128+12, 128+12); | ||
| 85 | UIGraphicsBeginImageContext(boxSize); | ||
| 86 | CGContextRef context = UIGraphicsGetCurrentContext(); | ||
| 87 | [topLeft drawInRect:CGRectMake(0, 0, 8, 8)]; | ||
| 88 | [topBorder drawInRect:CGRectMake(8, 0, boxSize.width-16, 8)]; | ||
| 89 | [topRight drawInRect:CGRectMake(8+boxSize.width-16, 0, 8, 8)]; | ||
| 90 | [rightBorder drawInRect:CGRectMake(8+boxSize.width-16, 8, 8, boxSize.height-16)]; | ||
| 91 | [bottomRight drawInRect:CGRectMake(8+boxSize.width-16, 8+boxSize.height-16, 8, 8)]; | ||
| 92 | [bottomBorder drawInRect:CGRectMake(8, 8+boxSize.height-16, boxSize.width-16, 8)]; | ||
| 93 | [bottomLeft drawInRect:CGRectMake(0, 8+boxSize.height-16, 8, 8)]; | ||
| 94 | [leftBorder drawInRect:CGRectMake(0, 8, 8, boxSize.height-16)]; | ||
| 95 | CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]); | ||
| 96 | CGContextFillRect(context, CGRectMake(8, 8, boxSize.width-16, boxSize.height-16)); | ||
| 97 | UIImage* selectionBackground = UIGraphicsGetImageFromCurrentImageContext(); | ||
| 98 | |||
| 99 | // Now we want to put the level image inside the frame without messing up the frame itself | ||
| 100 | UIImage* innerPicture = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:filename ofType:@"png"]]; | ||
| 101 | CGContextClipToMask(context, CGRectMake(0, 0, boxSize.width, boxSize.height), [[selectionBackground opaqueMaskFromWhiteImage] CGImage]); | ||
| 102 | [innerPicture drawInRect:CGRectMake(6, 6, 128, 128)]; | ||
| 103 | selectionBackground = UIGraphicsGetImageFromCurrentImageContext(); | ||
| 104 | UIGraphicsEndImageContext(); | ||
| 105 | |||
| 106 | // The frame needs a shadow, so let's redraw it in a new context | ||
| 107 | UIGraphicsBeginImageContext(CGSizeMake(boxSize.width+10, boxSize.height+10)); | ||
| 108 | context = UIGraphicsGetCurrentContext(); | ||
| 109 | CGContextSaveGState(context); | ||
| 110 | |||
| 111 | if (unlocked) | ||
| 112 | { | ||
| 113 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); | ||
| 114 | [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height)]; | ||
| 115 | } else { | ||
| 116 | // Draw the picture in grayscale if the level has not yet been unlocked | ||
| 117 | CGContextClipToMask(context, CGRectMake(10, 0, boxSize.width, boxSize.height), [selectionBackground CGImage]); | ||
| 118 | CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]); | ||
| 119 | CGContextFillRect(context, CGRectMake(10, 0, boxSize.width, boxSize.height)); | ||
| 120 | CGContextRestoreGState(context); | ||
| 121 | |||
| 122 | CGContextSaveGState(context); | ||
| 123 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); | ||
| 124 | [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height) blendMode:kCGBlendModeLuminosity alpha:1.0]; | ||
| 125 | } | ||
| 126 | |||
| 127 | CGContextRestoreGState(context); | ||
| 128 | CGImageRef pictureRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; | ||
| 129 | |||
| 130 | CCSprite* picture = [CCSprite spriteWithCGImage:pictureRef key:[NSString stringWithFormat:@"gms-%@", filenameMod]]; | ||
| 131 | |||
| 132 | // We're also going to need a "selected" image state for the button | ||
| 133 | CGContextSaveGState(context); | ||
| 134 | CGContextClipToMask(context, CGRectMake(10, 0, boxSize.width, boxSize.height), [selectionBackground CGImage]); | ||
| 135 | CGContextSetFillColorWithColor(context, [[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5] CGColor]); | ||
| 136 | CGContextFillRect(context, CGRectMake(10, 0, boxSize.width, boxSize.height)); | ||
| 137 | CGContextRestoreGState(context); | ||
| 138 | CGImageRef selectedButtonRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; | ||
| 139 | UIGraphicsEndImageContext(); | ||
| 140 | CCSprite* selectedButton = [CCSprite spriteWithCGImage:selectedButtonRef key:[NSString stringWithFormat:@"gms-%@-selected", filenameMod]]; | ||
| 141 | |||
| 142 | CCMenuItemSprite* pictureMenuItem = [CCMenuItemSprite itemFromNormalSprite:picture selectedSprite:selectedButton target:self selector:@selector(buttonTapped)]; | ||
| 143 | NMPanelMenu* theMenu = [NMPanelMenu menuWithItems:pictureMenuItem, nil]; | ||
| 144 | theMenu.position = ccp(-5, 0); | ||
| 145 | [self addChild:theMenu]; | ||
| 146 | |||
| 147 | // Render the titles | ||
| 148 | UIFont* titleFont = [UIFont fontWithName:@"AmericanTypewriter-Bold" size:18.0f]; | ||
| 149 | CGSize titleSize = [location sizeWithFont:titleFont constrainedToSize:CGSizeMake(128, 0)]; | ||
| 150 | UIFont* subtitleFont = [UIFont fontWithName:@"AmericanTypewriter" size:18.0f]; | ||
| 151 | CGSize subtitleSize = [name sizeWithFont:subtitleFont constrainedToSize:CGSizeMake(128, 0)]; | ||
| 152 | CGSize combinedTitleSize = CGSizeMake(128, titleSize.height + 10 + subtitleSize.height + 10); | ||
| 153 | |||
| 154 | UIGraphicsBeginImageContext(combinedTitleSize); | ||
| 155 | context = UIGraphicsGetCurrentContext(); | ||
| 156 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); | ||
| 157 | [location drawInRect:CGRectMake(10, 0, 128, titleSize.height) withFont:titleFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter]; | ||
| 158 | [name drawInRect:CGRectMake(10, titleSize.height, 128, subtitleSize.height) withFont:subtitleFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter]; | ||
| 159 | |||
| 160 | CGImageRef titleImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; | ||
| 161 | UIGraphicsEndImageContext(); | ||
| 162 | CCSprite* titleSprite = [CCSprite spriteWithCGImage:titleImage key:[NSString stringWithFormat:@"gms-%@-title", filenameMod]]; | ||
| 163 | titleSprite.position = ccp(-10, (boxSize.height)/2+(combinedTitleSize.height)/2); | ||
| 164 | [self addChild:titleSprite]; | ||
| 165 | } | ||
| 166 | |||
| 167 | return self; | ||
| 168 | } | ||
| 169 | |||
| 170 | - (id)initWithName:(NSString *)m_name location:(NSString *)m_location filename:(NSString *)m_filename highscore:(int)m_highscore | ||
| 171 | { | ||
| 172 | self = [self initWithName:m_name location:m_location filename:m_filename unlocked:YES]; | ||
| 173 | |||
| 174 | if (nil != self) | ||
| 175 | { | ||
| 176 | if (m_highscore != 0) | ||
| 177 | { | ||
| 178 | // Render the highscore label | ||
| 179 | NSString* highscoreString = [NSString stringWithFormat:@"Highscore: %d", m_highscore]; | ||
| 180 | UIFont* highscoreFont = [UIFont fontWithName:@"AmericanTypewriter" size:16.0f]; | ||
| 181 | CGSize highscoreSize = [highscoreString sizeWithFont:highscoreFont]; | ||
| 182 | |||
| 183 | UIGraphicsBeginImageContext(CGSizeMake(highscoreSize.width+10, highscoreSize.height+10)); | ||
| 184 | CGContextRef context = UIGraphicsGetCurrentContext(); | ||
| 185 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); | ||
| 186 | [highscoreString drawInRect:CGRectMake(10, 0, highscoreSize.width, highscoreSize.height) withFont:highscoreFont]; | ||
| 187 | |||
| 188 | CGImageRef highscoreImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; | ||
| 189 | UIGraphicsEndImageContext(); | ||
| 190 | CCSprite* highscoreSprite = [CCSprite spriteWithCGImage:highscoreImage key:[NSString stringWithFormat:@"gms-%@-highscore", m_filename]]; | ||
| 191 | highscoreSprite.position = ccp((128-highscoreSize.width)/2, 0-64-(highscoreSize.height)/2-10); | ||
| 192 | [self addChild:highscoreSprite]; | ||
| 193 | } | ||
| 194 | } | ||
| 195 | |||
| 196 | return self; | ||
| 197 | } | ||
| 198 | |||
| 199 | - (id)initWithName:(NSString *)m_name location:(NSString *)m_location filename:(NSString *)m_filename unlockCondition:(NSString*)m_unlockCondition | ||
| 200 | { | ||
| 201 | self = [self initWithName:m_name location:m_location filename:m_filename unlocked:NO]; | ||
| 202 | |||
| 203 | if (nil != self) | ||
| 204 | { | ||
| 205 | unlockCondition = m_unlockCondition; | ||
| 206 | } | ||
| 207 | |||
| 208 | return self; | ||
| 209 | } | ||
| 210 | |||
| 211 | - (void)buttonTapped | ||
| 212 | { | ||
| 213 | if (unlocked) | ||
| 214 | { | ||
| 215 | if (delegate != nil) | ||
| 216 | { | ||
| 217 | [delegate didSelectGameMode:self]; | ||
| 218 | } else { | ||
| 219 | NSLog(@"I don't have a GameModeSelectionDelegate to call for some reason..."); | ||
| 220 | } | ||
| 221 | } else { | ||
| 222 | UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"To unlock this game mode:" message:unlockCondition delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; | ||
| 223 | [alertView show]; | ||
| 224 | [alertView release]; | ||
| 225 | } | ||
| 226 | } | ||
| 227 | |||
| 228 | @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..ad6a455 --- /dev/null +++ b/Classes/GameModeSelectionLayer.m | |||
| @@ -0,0 +1,138 @@ | |||
| 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 | |||
| 17 | @implementation GameModeSelectionLayer | ||
| 18 | |||
| 19 | + (CCScene*)scene | ||
| 20 | { | ||
| 21 | CCScene* scene = [CCScene node]; | ||
| 22 | |||
| 23 | CCLayer* backgroundLayer = [[[CCLayer alloc] init] autorelease]; | ||
| 24 | CCSprite* backgroundImage = [CCSprite spriteWithFile:@"paintdaubs.png"]; | ||
| 25 | backgroundImage.position = ccp(240,160); | ||
| 26 | [backgroundLayer addChild:backgroundImage]; | ||
| 27 | [scene addChild:backgroundLayer]; | ||
| 28 | |||
| 29 | GameModeSelectionLayer* layer = [GameModeSelectionLayer node]; | ||
| 30 | [scene addChild:layer]; | ||
| 31 | |||
| 32 | return scene; | ||
| 33 | } | ||
| 34 | |||
| 35 | - (id)init | ||
| 36 | { | ||
| 37 | self = [super init]; | ||
| 38 | |||
| 39 | if (nil != self) | ||
| 40 | { | ||
| 41 | gameModes = [[NSMutableArray alloc] init]; | ||
| 42 | CCMenu* menu = [CCMenu menuWithItems:nil]; | ||
| 43 | NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | ||
| 44 | float onePanelWide = 128; | ||
| 45 | |||
| 46 | GameModeSelection* tutorialSelection = [GameModeSelection selectionWithName:@"Tutorial" location:@"Florence" filename:@"florence" unlocked:YES]; | ||
| 47 | [gameModes addObject:tutorialSelection]; | ||
| 48 | |||
| 49 | GameModeSelection* collectSelection; | ||
| 50 | |||
| 51 | if ([defaults boolForKey:@"hasDoneTutorial"]) | ||
| 52 | { | ||
| 53 | const char* sqlQuery = "SELECT * FROM highscores ORDER BY score DESC LIMIT 1"; | ||
| 54 | sqlite3_stmt* compiled_statement; | ||
| 55 | int score = 0; | ||
| 56 | |||
| 57 | if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) | ||
| 58 | { | ||
| 59 | if (sqlite3_step(compiled_statement) == SQLITE_ROW) | ||
| 60 | { | ||
| 61 | score = sqlite3_column_int(compiled_statement, 2); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" highscore:score]; | ||
| 66 | } else { | ||
| 67 | collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" unlockCondition:@"Beat the tutorial!"]; | ||
| 68 | } | ||
| 69 | |||
| 70 | [gameModes addObject:collectSelection]; | ||
| 71 | |||
| 72 | float padding = 15; | ||
| 73 | float totalPanelWidth = onePanelWide + padding*2; | ||
| 74 | float numberOfPanels = [gameModes count]; | ||
| 75 | float totalWidth = numberOfPanels * totalPanelWidth; | ||
| 76 | int currentWorldOffset = [defaults integerForKey:@"lastSelectedMode"]; | ||
| 77 | CCLayer* panels = [CCLayer node]; | ||
| 78 | |||
| 79 | for (GameModeSelection* gameMode in gameModes) | ||
| 80 | { | ||
| 81 | [gameMode setDelegate:self]; | ||
| 82 | [menu addChild:gameMode]; | ||
| 83 | } | ||
| 84 | |||
| 85 | [menu alignItemsHorizontallyWithPadding:padding*2]; | ||
| 86 | [panels addChild:menu]; | ||
| 87 | [self addChild:panels]; | ||
| 88 | |||
| 89 | pageControl = [[UIPageControl alloc] init]; | ||
| 90 | pageControl.numberOfPages = numberOfPanels; | ||
| 91 | pageControl.currentPage = currentWorldOffset; | ||
| 92 | pageControl.frame = CGRectMake(0, 250, 480, 20); | ||
| 93 | [[[CCDirector sharedDirector] openGLView] addSubview:pageControl]; | ||
| 94 | |||
| 95 | menu.position = ccpAdd(menu.position, ccp(totalWidth/2 - totalPanelWidth/2, 320)); | ||
| 96 | touchDelegatingView = [[TouchDelegatingView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)]; | ||
| 97 | scrollView = [[CocosOverlayScrollView alloc] initWithFrame:CGRectMake(0, 0, totalPanelWidth, 320) numPages:numberOfPanels width:totalPanelWidth layer:panels pageControl:pageControl]; | ||
| 98 | touchDelegatingView.scrollView = scrollView; | ||
| 99 | [scrollView setContentOffset:CGPointMake(currentWorldOffset*totalPanelWidth+1,0) animated:NO]; | ||
| 100 | [[[CCDirector sharedDirector] openGLView] addSubview:touchDelegatingView]; | ||
| 101 | [[[CCDirector sharedDirector] openGLView] addSubview:scrollView]; | ||
| 102 | |||
| 103 | CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back2.png" target:self selector:@selector(mainmenu)]; | ||
| 104 | CCMenu* myMenu = [CCMenu menuWithItems:newgameMenuItem, nil]; | ||
| 105 | myMenu.position = ccp(240, 30); | ||
| 106 | [self addChild:myMenu]; | ||
| 107 | } | ||
| 108 | |||
| 109 | return self; | ||
| 110 | } | ||
| 111 | |||
| 112 | - (void)onExit | ||
| 113 | { | ||
| 114 | [touchDelegatingView removeFromSuperview]; | ||
| 115 | [scrollView removeFromSuperview]; | ||
| 116 | [pageControl removeFromSuperview]; | ||
| 117 | } | ||
| 118 | |||
| 119 | - (void)mainmenu | ||
| 120 | { | ||
| 121 | [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; | ||
| 122 | } | ||
| 123 | |||
| 124 | - (void)didSelectGameMode:(GameModeSelection *)gameMode | ||
| 125 | { | ||
| 126 | NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | ||
| 127 | [defaults setInteger:[gameModes indexOfObject:gameMode] forKey:@"lastSelectedMode"]; | ||
| 128 | |||
| 129 | if ([gameMode.name isEqual:@"Tutorial"]) | ||
| 130 | { | ||
| 131 | [[CCDirector sharedDirector] replaceScene:[TutorialMode scene]]; | ||
| 132 | } else if ([gameMode.name isEqual:@"Collect"]) | ||
| 133 | { | ||
| 134 | [[CCDirector sharedDirector] replaceScene:[ClassicGameMode scene]]; | ||
| 135 | } | ||
| 136 | } | ||
| 137 | |||
| 138 | @end | ||
| diff --git a/Classes/MainMenuLayer.h b/Classes/MainMenuLayer.h index 4914b59..439056c 100755 --- a/Classes/MainMenuLayer.h +++ b/Classes/MainMenuLayer.h | |||
| @@ -16,7 +16,6 @@ | |||
| 16 | + (CCScene*)scene; | 16 | + (CCScene*)scene; |
| 17 | - (id)init; | 17 | - (id)init; |
| 18 | - (void)newgame; | 18 | - (void)newgame; |
| 19 | - (void)tutorial; | ||
| 20 | - (void)highscores; | 19 | - (void)highscores; |
| 21 | - (void)feedback; | 20 | - (void)feedback; |
| 22 | 21 | ||
| diff --git a/Classes/MainMenuLayer.m b/Classes/MainMenuLayer.m index 32b85cb..d4a6331 100755 --- a/Classes/MainMenuLayer.m +++ b/Classes/MainMenuLayer.m | |||
| @@ -8,8 +8,7 @@ | |||
| 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 "TestFlight.h" | 13 | #import "TestFlight.h" |
| 15 | 14 | ||
| @@ -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* 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)]; |
| 51 | CCMenuItemImage* feedbackMenuItem = [CCMenuItemImage itemFromNormalImage:@"feedback.png" selectedImage:@"feedback2.png" target:self selector:@selector(feedback)]; | 49 | CCMenuItemImage* feedbackMenuItem = [CCMenuItemImage itemFromNormalImage:@"feedback.png" selectedImage:@"feedback2.png" target:self selector:@selector(feedback)]; |
| 52 | 50 | ||
| 53 | CCMenu* menu = [CCMenu menuWithItems:newgameMenuItem, tutorialMenuItem, highscoresMenuItem, feedbackMenuItem, nil]; | 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,12 +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 | } | 63 | } |
| 71 | 64 | ||
| 72 | - (void)highscores | 65 | - (void)highscores |
| 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 1ada34a..1285597 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 |
| @@ -227,7 +227,7 @@ | |||
| 227 | [self schedule:@selector(randomlyAddObject:) interval:1.0f]; | 227 | [self schedule:@selector(randomlyAddObject:) interval:1.0f]; |
| 228 | } else if ([currentTutorial.name isEqual:@"end"]) | 228 | } else if ([currentTutorial.name isEqual:@"end"]) |
| 229 | { | 229 | { |
| 230 | [[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)]]; |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | self.currentTutorial = nil; | 233 | self.currentTutorial = nil; |
| @@ -331,6 +331,9 @@ | |||
| 331 | 331 | ||
| 332 | [self unschedule:@selector(randomlyAddObject:)]; | 332 | [self unschedule:@selector(randomlyAddObject:)]; |
| 333 | 333 | ||
| 334 | NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | ||
| 335 | [defaults setBool:YES forKey:@"hasDoneTutorial"]; | ||
| 336 | |||
| 334 | return; | 337 | return; |
| 335 | } else { | 338 | } else { |
| 336 | 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 | ||
