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
|
//
// 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"
@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)
{
gameModes = [[NSMutableArray alloc] init];
CCMenu* menu = [CCMenu menuWithItems:nil];
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
float onePanelWide = 128;
GameModeSelection* tutorialSelection = [GameModeSelection selectionWithName:@"Tutorial" location:@"Florence" filename:@"florence" unlocked:YES];
[gameModes addObject:tutorialSelection];
GameModeSelection* collectSelection;
if ([defaults boolForKey:@"hasDoneTutorial"])
{
const char* sqlQuery = "SELECT * FROM highscores ORDER BY score DESC LIMIT 1";
sqlite3_stmt* compiled_statement;
int score = 0;
if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(compiled_statement) == SQLITE_ROW)
{
score = sqlite3_column_int(compiled_statement, 2);
}
}
collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" highscore:score];
} else {
collectSelection = [GameModeSelection selectionWithName:@"Collect" location:@"Paris" filename:@"paris" unlockCondition:@"Beat the tutorial!"];
}
[gameModes addObject:collectSelection];
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);
[[[CCDirector sharedDirector] openGLView] addSubview:pageControl];
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];
[[[CCDirector sharedDirector] openGLView] addSubview:touchDelegatingView];
[[[CCDirector sharedDirector] openGLView] addSubview:scrollView];
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)onExit
{
[touchDelegatingView removeFromSuperview];
[scrollView removeFromSuperview];
[pageControl removeFromSuperview];
}
- (void)mainmenu
{
[[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]];
}
- (void)didSelectGameMode:(GameModeSelection *)gameMode
{
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults setInteger:[gameModes indexOfObject:gameMode] forKey:@"lastSelectedMode"];
if ([gameMode.name isEqual:@"Tutorial"])
{
[[CCDirector sharedDirector] replaceScene:[TutorialMode scene]];
} else if ([gameMode.name isEqual:@"Collect"])
{
[[CCDirector sharedDirector] replaceScene:[ClassicGameMode scene]];
}
}
@end
|