-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptionScene.swift
100 lines (79 loc) · 3.36 KB
/
OptionScene.swift
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
//
// OptionScene.swift
// Jack The Giant
//
// Created by Marc Llopart Riera on 12/26/16.
// Copyright © 2016 The Fox Game Studio. All rights reserved.
//
import SpriteKit
class OptionScene: SKScene {
private var easyBtn: SKSpriteNode?;
private var mediumBtn: SKSpriteNode?;
private var hardBtn: SKSpriteNode?;
private var sign: SKSpriteNode?;
override func didMove(to view: SKView) {
initializeVariables();
setSign();
}
func initializeVariables() {
easyBtn = self.childNode(withName: "Easy Button") as? SKSpriteNode!;
mediumBtn = self.childNode(withName: "Medium Button") as? SKSpriteNode!;
hardBtn = self.childNode(withName: "Hard Button") as? SKSpriteNode!;
sign = self.childNode(withName: "Sign") as? SKSpriteNode!;
}
private func setSign() {
if GameManager.instance.getEasyDifficulty() {
sign?.position.y = (easyBtn?.position.y)!;
}
if GameManager.instance.getMediumDifficulty() {
sign?.position.y = (mediumBtn?.position.y)!;
}
if GameManager.instance.getHardDifficulty() {
sign?.position.y = (hardBtn?.position.y)!;
}
}
private func setDifficulty(difficulty: String) {
switch (difficulty) {
case "easy":
GameManager.instance.setEasyDifficulty(easyDifficulty: true);
GameManager.instance.setMediumDifficulty(mediumDifficulty: false);
GameManager.instance.setHardDifficulty(hardDifficulty: false);
break;
case "medium":
GameManager.instance.setEasyDifficulty(easyDifficulty: false);
GameManager.instance.setMediumDifficulty(mediumDifficulty: true);
GameManager.instance.setHardDifficulty(hardDifficulty: false);
break;
case "hard":
GameManager.instance.setEasyDifficulty(easyDifficulty: false);
GameManager.instance.setMediumDifficulty(mediumDifficulty: false);
GameManager.instance.setHardDifficulty(hardDifficulty: true);
break;
default:
break;
}
GameManager.instance.saveData();
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self);
let nodeAtLocation = self.atPoint(location);
if nodeAtLocation == easyBtn {
setDifficulty(difficulty: "easy");
sign?.position.y = (easyBtn?.position.y)!;
} else if nodeAtLocation == mediumBtn {
setDifficulty(difficulty: "medium");
sign?.position.y = (mediumBtn?.position.y)!;
} else if nodeAtLocation == hardBtn {
setDifficulty(difficulty: "hard");
sign?.position.y = (hardBtn?.position.y)!;
}
sign?.zPosition = 4;
if nodeAtLocation.name == "Back Button" {
let scene = MainMenuScene(fileNamed: "MainMenu");
scene!.scaleMode = .aspectFill
self.view?.presentScene(scene!, transition: SKTransition.crossFade(withDuration: 1));
}
}
}
}