summary refs log tree commit diff stats
path: root/Classes/GameModeSelectionLayer.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-08-23 07:52:24 -0400
committerStarla Insigna <starla4444@gmail.com>2011-08-23 07:52:24 -0400
commitc9337218ef1660360097928c753bde1c79775618 (patch)
tree3cd6f9926cbe092c98776673800b830eef27ca01 /Classes/GameModeSelectionLayer.m
parent2ac50443ddbf69b7594808ba4e6de49eecbc0b84 (diff)
downloadcartcollect-c9337218ef1660360097928c753bde1c79775618.tar.gz
cartcollect-c9337218ef1660360097928c753bde1c79775618.tar.bz2
cartcollect-c9337218ef1660360097928c753bde1c79775618.zip
Added scrolling to level selection screen
Using http://www.xcombinator.com/2010/09/08/a-paging-uiscrollview-in-cocos2d-with-previews/ as a base, I was able to implement a paging scroller for the level selection screen so players can swipe through available levels and choose one to play.

At this point, the level selection screen is practically done--the only other thing I want to add is a UIPageControl to interact with the scrolling and give the player an indication of how many levels there are.

Refs #207
Diffstat (limited to 'Classes/GameModeSelectionLayer.m')
-rw-r--r--Classes/GameModeSelectionLayer.m66
1 files changed, 57 insertions, 9 deletions
diff --git a/Classes/GameModeSelectionLayer.m b/Classes/GameModeSelectionLayer.m index a90606e..9875d41 100644 --- a/Classes/GameModeSelectionLayer.m +++ b/Classes/GameModeSelectionLayer.m
@@ -11,6 +11,8 @@
11#import <sqlite3.h> 11#import <sqlite3.h>
12#import "Cart_CollectAppDelegate.h" 12#import "Cart_CollectAppDelegate.h"
13#import "MainMenuLayer.h" 13#import "MainMenuLayer.h"
14#import "TutorialMode.h"
15#import "ClassicGameMode.h"
14 16
15@implementation GameModeSelectionLayer 17@implementation GameModeSelectionLayer
16 18
@@ -36,12 +38,14 @@
36 38
37 if (nil != self) 39 if (nil != self)
38 { 40 {
39 // Initialization code here. 41 gameModes = [[NSMutableArray alloc] init];
40 GameModeSelection* tutorialSelection = [[[GameModeSelection alloc] initWithName:@"Tutorial" location:@"Florence" filename:@"florence" unlocked:YES] autorelease]; 42 CCMenu* menu = [CCMenu menuWithItems:nil];
41 tutorialSelection.position = ccp(160-32,160);
42 [self addChild:tutorialSelection];
43
44 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; 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
45 GameModeSelection* collectSelection; 49 GameModeSelection* collectSelection;
46 50
47 if ([defaults boolForKey:@"hasDoneTutorial"]) 51 if ([defaults boolForKey:@"hasDoneTutorial"])
@@ -58,13 +62,37 @@
58 } 62 }
59 } 63 }
60 64
61 collectSelection = [[[GameModeSelection alloc] initWithName:@"Collect" location:@"Paris" filename:@"paris" highscore:score] autorelease]; 65 collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" highscore:score];
62 } else { 66 } else {
63 collectSelection = [[[GameModeSelection alloc] initWithName:@"Collect" location:@"Paris" filename:@"paris" unlockCondition:@"Beat the tutorial!"] autorelease]; 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];
64 } 83 }
65 84
66 collectSelection.position = ccp(320+32,160); 85 [menu alignItemsHorizontallyWithPadding:padding*2];
67 [self addChild:collectSelection]; 86 [panels addChild:menu];
87 [self addChild:panels];
88
89 menu.position = ccpAdd(menu.position, ccp(totalWidth/2 - totalPanelWidth/2, 320));
90 touchDelegatingView = [[TouchDelegatingView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)];
91 scrollView = [[CocosOverlayScrollView alloc] initWithFrame:CGRectMake(0, 0, totalPanelWidth, 320) numPages:numberOfPanels width:totalPanelWidth layer:panels];
92 touchDelegatingView.scrollView = scrollView;
93 [scrollView setContentOffset:CGPointMake(currentWorldOffset*totalPanelWidth+1,0) animated:NO];
94 [[[CCDirector sharedDirector] openGLView] addSubview:touchDelegatingView];
95 [[[CCDirector sharedDirector] openGLView] addSubview:scrollView];
68 96
69 CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back2.png" target:self selector:@selector(mainmenu)]; 97 CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back2.png" target:self selector:@selector(mainmenu)];
70 CCMenu* myMenu = [CCMenu menuWithItems:newgameMenuItem, nil]; 98 CCMenu* myMenu = [CCMenu menuWithItems:newgameMenuItem, nil];
@@ -75,9 +103,29 @@
75 return self; 103 return self;
76} 104}
77 105
106- (void)onExit
107{
108 [touchDelegatingView removeFromSuperview];
109 [scrollView removeFromSuperview];
110}
111
78- (void)mainmenu 112- (void)mainmenu
79{ 113{
80 [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]]; 114 [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]];
81} 115}
82 116
117- (void)didSelectGameMode:(GameModeSelection *)gameMode
118{
119 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
120 [defaults setInteger:[gameModes indexOfObject:gameMode] forKey:@"lastSelectedMode"];
121
122 if ([gameMode.name isEqual:@"Tutorial"])
123 {
124 [[CCDirector sharedDirector] replaceScene:[TutorialMode scene]];
125 } else if ([gameMode.name isEqual:@"Collect"])
126 {
127 [[CCDirector sharedDirector] replaceScene:[ClassicGameMode scene]];
128 }
129}
130
83@end 131@end