-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainMenuScene.swift
104 lines (77 loc) · 3.33 KB
/
MainMenuScene.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
101
102
103
104
//
// MainMenuScene.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 MainMenuScene: SKScene {
var highscoreBtn: SKSpriteNode?;
var optionsBtn: SKSpriteNode?;
var startGameBtn: SKSpriteNode?;
var quitGameBtn: SKSpriteNode?;
var soundBtn: SKSpriteNode?;
private let musicOn = SKTexture(imageNamed: "Music On Button");
private let musicOff = SKTexture(imageNamed: "Music Off Button");
override func didMove(to view: SKView) {
GameManager.instance.initializeGameData();
highscoreBtn = self.childNode(withName: "Highscore") as? SKSpriteNode!;
optionsBtn = self.childNode(withName: "Options") as? SKSpriteNode!;
startGameBtn = self.childNode(withName: "Start Game") as? SKSpriteNode!;
soundBtn = self.childNode(withName: "Music") as? SKSpriteNode!;
quitGameBtn = self.childNode(withName: "Quit") as? SKSpriteNode!;
setMusic();
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self);
let nodeAtLocation = self.atPoint(location);
GameManager.instance.gameStartedFromMainMenu = true;
if nodeAtLocation == highscoreBtn {
print("Highscore");
let scene = HighscoreScene(fileNamed: "HighscoreScene");
scene!.scaleMode = .aspectFill
self.view?.presentScene(scene!, transition: SKTransition.doorsOpenVertical(withDuration: 1));
}
if nodeAtLocation == optionsBtn {
let scene = OptionScene(fileNamed: "OptionScene");
scene!.scaleMode = .aspectFill
self.view?.presentScene(scene!, transition: SKTransition.doorsOpenVertical(withDuration: 1));
}
if nodeAtLocation == startGameBtn {
let scene = GameplayScene(fileNamed: "GameplayScene");
scene!.scaleMode = .aspectFill
self.view?.presentScene(scene!);
}
if nodeAtLocation == soundBtn {
handleMusicButton()
}
if nodeAtLocation == quitGameBtn {
exit(0);
}
}
}
private func setMusic() {
if GameManager.instance.getIsMusicOn() {
if AudioManager.instance.isAudioPlayerInitialized() {
AudioManager.instance.playBGMusic();
soundBtn?.texture = musicOff;
}
} else {
soundBtn?.texture = musicOn;
}
}
private func handleMusicButton() {
if GameManager.instance.getIsMusicOn() {
AudioManager.instance.stopBGMusic();
GameManager.instance.setIsMusicOn(isMusicOn: false);
soundBtn?.texture = musicOn;
} else {
AudioManager.instance.playBGMusic();
GameManager.instance.setIsMusicOn(isMusicOn: true);
soundBtn?.texture = musicOff;
}
GameManager.instance.saveData();
}
}