-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameplayController.swift
More file actions
82 lines (59 loc) · 1.83 KB
/
Copy pathGameplayController.swift
File metadata and controls
82 lines (59 loc) · 1.83 KB
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
//
// GameplayController.swift
// jackTheGiant
//
// Created by Leon on 14/12/16.
// Copyright © 2016 Leon. All rights reserved.
//
import Foundation
import SpriteKit
struct ColliderType {
static let PLAYER: UInt32 = 0
static let CLOUD: UInt32 = 1
static let DARK_CLOUD_AND_COLLECTABLES: UInt32 = 2
}
/// Contains data for the labels of Distance score, Coin score, and life
/// Uses GameDataManager to know if it should reset score
class GameplayController {
// Singleton
static let instance = GameplayController()
private init() {}
var scoreText: SKLabelNode?
var coinText: SKLabelNode?
var lifeText: SKLabelNode?
var score: Int = 0
var coin: Int = 0
var life: Int = 0
func initializeVariables() {
if GameDataManager.instance.gameStartedFromMainMenu {
GameDataManager.instance.gameStartedFromMainMenu = false
score = -1
coin = 0
life = 3
scoreText?.text = "\(score)"
coinText?.text = "x\(coin)"
lifeText?.text = "x\(life)"
} else if GameDataManager.instance.gameRestartedPlayerDied {
GameDataManager.instance.gameRestartedPlayerDied = false
scoreText?.text = "\(score)"
coinText?.text = "x\(coin)"
lifeText?.text = "x\(life)"
}
}
func incrementScore() {
score += 1
scoreText?.text = "\(score)"
}
func incrementCoin() {
coin += 1
score += 200
coinText?.text = "x\(coin)"
scoreText?.text = "\(score)"
}
func incrementLife() {
life += 1
score += 300
lifeText?.text = "x\(life)"
scoreText?.text = "\(score)"
}
}