1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
//
// 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 <sqlite3.h>
#import "Cart_CollectAppDelegate.h"
#import "MainMenuLayer.h"
#import "TutorialMode.h"
#import "ClassicGameMode.h"
#import "NMPanelMenu.h"
#import "JumpGameMode.h"
#import "ZoomFadeTransition.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)
{
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
gameModes = [[NSMutableArray alloc] init];
GameModeSelection* tutorialSelection = [GameModeSelection selectionWithName:@"Tutorial" location:@"Florence" filename:@"florence" unlocked:YES];
[gameModes addObject:tutorialSelection];
GameModeSelection* collectSelection;
if ([defaults boolForKey:@"hasDoneTutorial"])
{
collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" unlocked:YES];
} else {
collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" unlockCondition:@"Beat the tutorial!"];
}
[gameModes addObject:collectSelection];
GameModeSelection* jumpSelection;
if ([defaults boolForKey:@"unlockedJumpMode"])
{
jumpSelection = [GameModeSelection selectionWithName:@"Jump" location:@"Venice" filename:@"venice" unlocked:YES];
} else {
jumpSelection = [GameModeSelection selectionWithName:@"Jump" location:@"Venice" filename:@"venice" unlockCondition:@"Get 3000 points in Collect!"];
}
[gameModes addObject:jumpSelection];
CCMenu* menu = [CCMenu menuWithItems:nil];
float onePanelWide = 128;
float padding = 15;
float totalPanelWidth = onePanelWide + padding*2;
float numberOfPanels = [gameModes count];
float totalWidth = numberOfPanels * totalPanelWidth;
int currentWorldOffset = [defaults integerForKey:@"lastSelectedMode"];
CCLayer* panels = [CCLayer node];
for (GameModeSelection* gameMode in gameModes)
{
[gameMode setDelegate:self];
[menu addChild:gameMode];
}
[menu alignItemsHorizontallyWithPadding:padding*2];
[panels addChild:menu];
[self addChild:panels];
pageControl = [[UIPageControl alloc] init];
pageControl.numberOfPages = numberOfPanels;
pageControl.currentPage = currentWorldOffset;
pageControl.frame = CGRectMake(0, 250, 480, 20);
menu.position = ccpAdd(menu.position, ccp(totalWidth/2 - totalPanelWidth/2, 320));
touchDelegatingView = [[TouchDelegatingView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)];
scrollView = [[CocosOverlayScrollView alloc] initWithFrame:CGRectMake(0, 0, totalPanelWidth, 320) numPages:numberOfPanels width:totalPanelWidth layer:panels pageControl:pageControl];
touchDelegatingView.scrollView = scrollView;
[scrollView setContentOffset:CGPointMake(currentWorldOffset*totalPanelWidth+1,0) animated:NO];
CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back2.png" target:self selector:@selector(mainmenu)];
NMPanelMenu* myMenu = [NMPanelMenu menuWithItems:newgameMenuItem, nil];
myMenu.position = ccp(240, 30);
[self addChild:myMenu];
}
return self;
}
- (void)onEnterTransitionDidFinish
{
[super onEnterTransitionDidFinish];
[[[CCDirector sharedDirector] openGLView] addSubview:pageControl];
[[[CCDirector sharedDirector] openGLView] addSubview:touchDelegatingView];
[[[CCDirector sharedDirector] openGLView] addSubview:scrollView];
}
- (void)onExit
{
[super onExit];
[touchDelegatingView removeFromSuperview];
[scrollView removeFromSuperview];
[pageControl removeFromSuperview];
}
- (void)mainmenu
{
[[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]];
}
- (void)didSelectGameMode:(GameModeSelection *)gameMode
{
[scrollView setScrollEnabled:NO];
[pageControl removeFromSuperview];
CGPoint opp = [scrollView convertPoint:gameMode.position toView:[[CCDirector sharedDirector] openGLView]];
CGPoint endPosition = ccp(0-(opp.x+158), opp.y);
if ([gameMode.name isEqual:@"Tutorial"])
{
[[CCDirector sharedDirector] replaceScene:[ZoomFadeTransition transitionWithDuration:5.0f scene:[TutorialMode scene] position:endPosition]];
} else if ([gameMode.name isEqual:@"Collect"])
{
[[CCDirector sharedDirector] replaceScene:[ZoomFadeTransition transitionWithDuration:5.0f scene:[ClassicGameMode scene] position:endPosition]];
} else if ([gameMode.name isEqual:@"Jump"])
{
[[CCDirector sharedDirector] replaceScene:[ZoomFadeTransition transitionWithDuration:5.0f scene:[JumpGameMode scene] position:endPosition]];
}
}
@end
|