From 3750d7aa4e307d1f2099eceaa21014151e78d364 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Thu, 18 Aug 2011 15:51:48 -0400 Subject: Started game mode selection screen So far, tapping "New Game" shows a screen with two game modes: the tutorial and the classic collect. They both have pictures and Collect's is grayscale if it hasn't been unlocked yet (a.k.a. the tutorial hasn't been completed yet). Also, Collect's title is replaced with question marks and the text "Beat the tutorial!" is shown if it isn't unlocked--if it is unlocked, the player's highscore, if they have one, is shown. A "Back to Main Menu" button is also present. Neither selection is as of yet tappable, and neither picture yet has a border. You cannot scroll through modes yet either. Refs #207 --- Classes/GameModeSelection.h | 30 ++++++++++++++ Classes/GameModeSelection.m | 88 ++++++++++++++++++++++++++++++++++++++++ Classes/GameModeSelectionLayer.h | 17 ++++++++ Classes/GameModeSelectionLayer.m | 82 +++++++++++++++++++++++++++++++++++++ Classes/MainMenuLayer.h | 1 - Classes/MainMenuLayer.m | 13 ++---- Classes/TutorialMode.m | 3 ++ 7 files changed, 223 insertions(+), 11 deletions(-) create mode 100644 Classes/GameModeSelection.h create mode 100644 Classes/GameModeSelection.m create mode 100644 Classes/GameModeSelectionLayer.h create mode 100644 Classes/GameModeSelectionLayer.m (limited to 'Classes') diff --git a/Classes/GameModeSelection.h b/Classes/GameModeSelection.h new file mode 100644 index 0000000..aadbf36 --- /dev/null +++ b/Classes/GameModeSelection.h @@ -0,0 +1,30 @@ +// +// GameModeSelection.h +// Cartographic +// +// Created by Starla Insigna on 8/18/11. +// Copyright 2011 Four Island. All rights reserved. +// + +#import "cocos2d.h" + +@interface GameModeSelection : CCNode { + NSString* name; + NSString* location; + BOOL unlocked; + int highscore; + NSString* unlockCondition; + + CCLabelBMFont* nameLabel; + CCSprite* picture; + CCLabelBMFont* otherLabel; +} + +@property (readonly) NSString* name; +@property (readonly) NSString* location; +@property (readonly) BOOL unlocked; +@property (nonatomic,assign) int highscore; +@property (nonatomic,retain) NSString* unlockCondition; +- (id)initWithName:(NSString*)name location:(NSString*)location filename:(NSString*)filename unlocked:(BOOL)unlocked; + +@end diff --git a/Classes/GameModeSelection.m b/Classes/GameModeSelection.m new file mode 100644 index 0000000..56e65d9 --- /dev/null +++ b/Classes/GameModeSelection.m @@ -0,0 +1,88 @@ +// +// GameModeSelection.m +// Cartographic +// +// Created by Starla Insigna on 8/18/11. +// Copyright 2011 Four Island. All rights reserved. +// + +#import "GameModeSelection.h" + +@implementation GameModeSelection + +@synthesize name, location, unlocked, highscore, unlockCondition; + +- (id)initWithName:(NSString*)m_name location:(NSString*)m_location filename:(NSString*)filename unlocked:(BOOL)m_unlocked; +{ + self = [super init]; + + if (nil != self) + { + self.anchorPoint = CGPointMake(0.5f, 0.5f); + + name = m_name; + location = m_location; + unlocked = m_unlocked; + + if (!unlocked) + { + name = [@"" stringByPaddingToLength:name.length withString:@"?" startingAtIndex:0]; + location = [@"" stringByPaddingToLength:location.length withString:@"?" startingAtIndex:0]; + } + + nameLabel = [CCLabelBMFont labelWithString:[NSString stringWithFormat:@"%@ (%@)", location, name] fntFile:@"levelnames.fnt"]; + + [self addChild:nameLabel]; + nameLabel.position = ccp(0, -32-nameLabel.contentSize.height); + + UIImage* innerPicture = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:filename ofType:@"png"]]; + UIGraphicsBeginImageContext(CGSizeMake(128, 128)); + CGContextRef context = UIGraphicsGetCurrentContext(); + UIGraphicsPushContext(context); + + if (unlocked) + { + [innerPicture drawInRect:CGRectMake(0, 0, 128, 128)]; + } else { + CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]); + CGContextFillRect(context, CGRectMake(0, 0, 128, 128)); + [innerPicture drawInRect:CGRectMake(0, 0, 128, 128) blendMode:kCGBlendModeLuminosity alpha:1.0]; + } + + UIGraphicsPopContext(); + CGImageRef innerPictureRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; + UIGraphicsEndImageContext(); + + picture = [CCSprite spriteWithCGImage:innerPictureRef key:filename]; + picture.position = ccp(0, 32); + [self addChild:picture]; + } + + return self; +} + +- (void)setHighscore:(int)m_highscore +{ + if (unlocked) + { + highscore = m_highscore; + + otherLabel = [CCLabelBMFont labelWithString:[NSString stringWithFormat:@"Highscore: %d", highscore] fntFile:@"leveldescriptions.fnt"]; + otherLabel.position = ccp(0, -32-nameLabel.contentSize.height-otherLabel.contentSize.height); + [self addChild:otherLabel]; + } +} + +- (void)setUnlockCondition:(NSString *)m_unlockCondition +{ + if (!unlocked) + { + unlockCondition = m_unlockCondition; + + otherLabel = [CCLabelBMFont labelWithString:unlockCondition fntFile:@"leveldescriptions.fnt"]; + otherLabel.position = ccp(0, -32-nameLabel.contentSize.height-otherLabel.contentSize.height); + [self addChild:otherLabel]; + } +} + +@end diff --git a/Classes/GameModeSelectionLayer.h b/Classes/GameModeSelectionLayer.h new file mode 100644 index 0000000..2f57bfb --- /dev/null +++ b/Classes/GameModeSelectionLayer.h @@ -0,0 +1,17 @@ +// +// GameModeSelectionLayer.h +// Cartographic +// +// Created by Starla Insigna on 8/18/11. +// Copyright 2011 Four Island. All rights reserved. +// + +#import "cocos2d.h" + +@interface GameModeSelectionLayer : CCLayer + ++ (CCScene*)scene; +- (id)init; +- (void)mainmenu; + +@end diff --git a/Classes/GameModeSelectionLayer.m b/Classes/GameModeSelectionLayer.m new file mode 100644 index 0000000..3e1995e --- /dev/null +++ b/Classes/GameModeSelectionLayer.m @@ -0,0 +1,82 @@ +// +// GameModeSelectionLayer.m +// Cartographic +// +// Created by Starla Insigna on 8/18/11. +// Copyright 2011 Four Island. All rights reserved. +// + +#import "GameModeSelectionLayer.h" +#import "GameModeSelection.h" +#import +#import "Cart_CollectAppDelegate.h" +#import "MainMenuLayer.h" + +@implementation GameModeSelectionLayer + ++ (CCScene*)scene +{ + CCScene* scene = [CCScene node]; + + CCLayer* backgroundLayer = [[[CCLayer alloc] init] autorelease]; + CCSprite* backgroundImage = [CCSprite spriteWithFile:@"paintdaubs.png"]; + backgroundImage.position = ccp(240,160); + [backgroundLayer addChild:backgroundImage]; + [scene addChild:backgroundLayer]; + + GameModeSelectionLayer* layer = [GameModeSelectionLayer node]; + [scene addChild:layer]; + + return scene; +} + +- (id)init +{ + self = [super init]; + + if (nil != self) + { + // Initialization code here. + GameModeSelection* tutorialSelection = [[[GameModeSelection alloc] initWithName:@"Tutorial" location:@"Florence" filename:@"florence" unlocked:YES] autorelease]; + tutorialSelection.position = ccp(160-32,160); + [self addChild:tutorialSelection]; + + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; + GameModeSelection* collectSelection = [[[GameModeSelection alloc] initWithName:@"Collect" location:@"Paris" filename:@"paris" unlocked:[defaults boolForKey:@"hasDoneTutorial"]] autorelease]; + collectSelection.position = ccp(400-32, 160); + + if (collectSelection.unlocked) + { + const char* sqlQuery = "SELECT * FROM highscores ORDER BY score DESC LIMIT 1"; + sqlite3_stmt* compiled_statement; + + if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) + { + if (sqlite3_step(compiled_statement) == SQLITE_ROW) + { + int score = sqlite3_column_int(compiled_statement, 2); + + [collectSelection setHighscore:score]; + } + } + } else { + [collectSelection setUnlockCondition:@"Beat the tutorial!"]; + } + + [self addChild:collectSelection]; + + CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back2.png" target:self selector:@selector(mainmenu)]; + CCMenu* myMenu = [CCMenu menuWithItems:newgameMenuItem, nil]; + myMenu.position = ccp(240, 30); + [self addChild:myMenu]; + } + + return self; +} + +- (void)mainmenu +{ + [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; +} + +@end diff --git a/Classes/MainMenuLayer.h b/Classes/MainMenuLayer.h index e43c5e1..d8483b3 100755 --- a/Classes/MainMenuLayer.h +++ b/Classes/MainMenuLayer.h @@ -16,7 +16,6 @@ + (CCScene*)scene; - (id)init; - (void)newgame; -- (void)tutorial; - (void)highscores; @end diff --git a/Classes/MainMenuLayer.m b/Classes/MainMenuLayer.m index 8b21fab..06a528c 100755 --- a/Classes/MainMenuLayer.m +++ b/Classes/MainMenuLayer.m @@ -8,8 +8,7 @@ #import "MainMenuLayer.h" #import "HighscoreListController.h" -#import "ClassicGameMode.h" -#import "TutorialMode.h" +#import "GameModeSelectionLayer.h" #import "Cart_CollectAppDelegate.h" @implementation MainMenuLayer @@ -45,10 +44,9 @@ //CCMenuItemLabel* menuItem2 = [CCMenuItemLabel itemWithLabel:menuItemLabel2 target:self selector:@selector(highscores)]; CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"newgame.png" selectedImage:@"newgame2.png" target:self selector:@selector(newgame)]; - CCMenuItemImage* tutorialMenuItem = [CCMenuItemImage itemFromNormalImage:@"tutorial.png" selectedImage:@"tutorial2.png" target:self selector:@selector(tutorial)]; CCMenuItemImage* highscoresMenuItem = [CCMenuItemImage itemFromNormalImage:@"highscores.png" selectedImage:@"highscores2.png" target:self selector:@selector(highscores)]; - CCMenu* menu = [CCMenu menuWithItems:newgameMenuItem, tutorialMenuItem, highscoresMenuItem, nil]; + CCMenu* menu = [CCMenu menuWithItems:newgameMenuItem, highscoresMenuItem, nil]; [menu alignItemsVertically]; menu.position = ccp(240, 100); [self addChild:menu]; @@ -59,12 +57,7 @@ - (void)newgame { - [[CCDirector sharedDirector] replaceScene:[ClassicGameMode scene]]; -} - -- (void)tutorial -{ - [[CCDirector sharedDirector] replaceScene:[TutorialMode scene]]; + [[CCDirector sharedDirector] replaceScene:[GameModeSelectionLayer scene]]; } - (void)highscores diff --git a/Classes/TutorialMode.m b/Classes/TutorialMode.m index 1ada34a..c28bd08 100644 --- a/Classes/TutorialMode.m +++ b/Classes/TutorialMode.m @@ -331,6 +331,9 @@ [self unschedule:@selector(randomlyAddObject:)]; + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; + [defaults setBool:YES forKey:@"hasDoneTutorial"]; + return; } else { NSLog(@"randomItemsDropped in TutorialMode is greater than 15--this should never happen."); -- cgit 1.4.1