-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLostScene.swift
95 lines (68 loc) · 3.08 KB
/
LostScene.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
//
// LostScene.swift
// Horse Racing
//
// Created by Masood Zafar on 29.04.2021.
//
import SpriteKit
class LostScene: SKScene {
//Grab the HUD sprite atlas:
let textureAtlas: SKTextureAtlas = SKTextureAtlas(named:"Menu")
//Instantiate a sprite node for the start button and horses
let restartButton = SKSpriteNode()
let menuButton = SKSpriteNode()
let winText = SKLabelNode(fontNamed: "AvenirNext-Heavy")
let instructText = SKLabelNode(fontNamed: "AvenirNext-Regular")
//Sound
let click = SKAction.playSoundFileNamed("Sound/click.aif", waitForCompletion: false)
override func didMove(to view: SKView){
self.anchorPoint = CGPoint(x: 0.5, y: 0.5)
self.backgroundColor = UIColor(red: 0.97, green: 0.96, blue: 0.88, alpha: 1.00)
//Title of the game
winText.text = "Better luck next time!"
winText.fontColor = UIColor(red: 0.00, green: 0.38, blue: 0.66, alpha: 1.00)
winText.position = CGPoint(x: 0, y: 100)
winText.fontSize = 60
//Instruction
let instructText = SKLabelNode(fontNamed: "AvenirNext-Regular")
instructText.text = "You can choose to restart or go back to main menu"
instructText.fontColor = UIColor(red: 0.00, green: 0.38, blue: 0.66, alpha: 1.00)
instructText.position = CGPoint(x: 0, y: 50)
instructText.fontSize = 30
//Restart game button
restartButton.texture = textureAtlas.textureNamed("button-restart")
restartButton.size = CGSize(width: 100, height: 100)
restartButton.name = "RestartBtn"
restartButton.position = CGPoint(x: -100, y: -50)
//Menu game button
menuButton.texture = textureAtlas.textureNamed("button-menu")
menuButton.size = CGSize(width: 100, height: 100)
menuButton.name = "MenuBtn"
menuButton.position = CGPoint(x: 100, y: -50)
// Giving the winText a pulse
let pulseAction = SKAction.sequence([SKAction.fadeAlpha(to: 0.5, duration: 0.9),SKAction.fadeAlpha(to: 1, duration: 0.9)])
winText.run(SKAction.repeatForever(pulseAction))
self.addChild(winText)
self.addChild(instructText)
self.addChild(restartButton)
self.addChild(menuButton)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in (touches) {
// Find the location of the touch:
let location = touch.location(in: self)
// Locate the node at this location:
let nodeTouched = atPoint(location)
switch nodeTouched.name {
case "RestartBtn":
self.run(click)
self.view?.presentScene(GameScene(size: self.size))
case "MenuBtn":
self.run(click)
self.view?.presentScene(MenuScene(size: self.size))
default:
break
}
}
}
}