-
Notifications
You must be signed in to change notification settings - Fork 1
/
MenuScene.m
170 lines (127 loc) · 5.43 KB
/
MenuScene.m
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//
// MenuScene.m
// Cube_Smash
//
// Created by Joshua Howland on 5/19/14.
// Copyright (c) 2014 Shiv Pande. All rights reserved.
//
#import "MenuScene.h"
#import "SKPMyScene.h"
@interface MenuScene()
@property SKEmitterNode *snow;
@property SKSpriteNode *playButton;
@property SKSpriteNode *scoresButton;
@property SKSpriteNode *settingsButton;
@property SKSpriteNode *gameLabel;
@property SKSpriteNode *highScoreLabel;
@property SKSpriteNode *menuButton;
@property SKLabelNode *highScoreText;
@property int treeSum;
@end
@implementation MenuScene
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
/* Setup your scene here */
self.backgroundColor = [SKColor colorWithRed:0 green:0 blue:0 alpha:1.0];
if([[NSUserDefaults standardUserDefaults] integerForKey:@"treeSum"]){
_treeSum = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"TreeSum"];
}else{
_treeSum = 0;
}
_playButton = [[SKSpriteNode alloc] initWithImageNamed:@"play"];
_playButton.size = CGSizeMake(self.size.width*2/3, self.size.height*1/7);
_playButton.position = CGPointMake(self.size.width/2, self.size.height*1.5/3);
_playButton.name = @"playButton";
//[self addChild:_playButton];
_scoresButton = [[SKSpriteNode alloc] initWithImageNamed:@"scores"];
_scoresButton.size = _playButton.size;
_scoresButton.position = CGPointMake(_playButton.position.x, _playButton.position.y-_playButton.size.height*1.2);
_scoresButton.name = @"scoresButton";
_settingsButton = [[SKSpriteNode alloc] initWithImageNamed:@"powerup"];
_settingsButton.size = _playButton.size;
_settingsButton.position = CGPointMake(_playButton.position.x, _playButton.position.y - 1.2*2*_playButton.size.height);
_settingsButton.name = @"settingsButton";
//[self addChild:_settingsButton];
_gameLabel = [[SKSpriteNode alloc] initWithImageNamed:@"Name"];
_gameLabel.size = CGSizeMake(1.2*_playButton.size.width, 1.2*_playButton.size.height);
_gameLabel.position = CGPointMake(_playButton.position.x, _playButton.position.y + 1.4*_playButton.size.height);
// [self addChild:_gameLabel];
[self initMenu];
}
return self;
}
-(void)initMenu{
if([_scoresButton parent]==NULL)
[self addChild:_scoresButton];
if([_settingsButton parent]==NULL)
[self addChild:_settingsButton];
if([_gameLabel parent ] == NULL)
[self addChild:_gameLabel];
if([_playButton parent]==NULL)
[self addChild:_playButton];
}
-(void)removeMenu{
[_scoresButton removeFromParent];
[_settingsButton removeFromParent];
[_playButton removeFromParent];
//[_gameLabel removeFromParent];
}
-(void)fadeIn:(SKSpriteNode*)node{
if([node parent]==NULL)
[self addChild:node];
node.alpha = 0.0;
SKAction *fadeIn = [SKAction fadeInWithDuration:0.14];
[node runAction:[SKAction sequence:@[fadeIn]]];
}
-(void)fadeOut:(SKSpriteNode*)node{
//node.alpha = 0.0;
SKAction *fadeOut = [SKAction fadeOutWithDuration:0.14];
SKAction *remove = [SKAction removeFromParent];
if([node parent] != NULL)
[node runAction:[SKAction sequence:@[fadeOut,remove]]];
}
-(void)displayScores{
_highScoreLabel = [[SKSpriteNode alloc] initWithImageNamed:@"highScoreButton"];
_highScoreLabel.size = _scoresButton.size;
_highScoreLabel.position = _playButton.position;
_menuButton = [[SKSpriteNode alloc] initWithImageNamed:@"Menu"];
_menuButton.size = _scoresButton.size;
_menuButton.position = _scoresButton.position;
_menuButton.name = @"menuButton";
int highScoreTemp = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"HighScore"];
_highScoreText = [[SKLabelNode alloc] initWithFontNamed:@"AvenirNext-Heavy"];
_highScoreText.text = [NSString stringWithFormat:@"%i",(int)highScoreTemp];
_highScoreText.fontSize = self.frame.size.width/8;
_highScoreText.position = CGPointMake(_highScoreLabel.position.x*1.35,0.95*_highScoreLabel.position.y);
_highScoreText.fontColor = [UIColor colorWithRed:58/255.f green:198/255.f blue:239/255.f alpha:1];
[self addChild:_highScoreLabel];
[self addChild:_menuButton];
[self addChild:_highScoreText];
}
-(void)removeScoresDisplay{
if([_highScoreLabel parent]==NULL)
[_highScoreLabel removeFromParent];
if([_menuButton parent]==NULL)
[_menuButton removeFromParent];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
//for (UITouch *touch in touches) {
SKNode *na1 = [self nodeAtPoint:location];
if([na1.name isEqualToString:@"playButton"]){
SKPMyScene *gameScene = [[SKPMyScene alloc] initWithSize:self.size];
[self.view presentScene:gameScene transition:[SKTransition fadeWithColor:[UIColor clearColor] duration:1.0f]];
}else if([na1.name isEqualToString:@"scoresButton"]){
[self removeMenu];
[self displayScores];
}else if([na1.name isEqualToString:@"menuButton"]){
[self removeScoresDisplay];
[self initMenu];
}
}
-(void)update:(CFTimeInterval)currentTime {
/* Called before each frame is rendered */
}
@end