-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGameManager.cs
129 lines (120 loc) · 4.44 KB
/
GameManager.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
[Header("Max Health/Item Counts")]
[SerializeField] int maxEnergy;
[SerializeField] int maxMissiles;
[SerializeField] int maxSuperMissiles;
[SerializeField] int maxPowerBombs;
[Header("Current Health/Item Counts")]
[SerializeField] int energy = 99;
[SerializeField] int missiles = 0;
[SerializeField] int superMissiles = 0;
[SerializeField] int powerBombs = 0;
[Header("Item Acquisitions")]
[SerializeField] bool hasMorphBall = false;
[SerializeField] bool hasMorphBallBombs = false;
[SerializeField] bool hasHighJump;
[SerializeField] bool hasGrappleBeam = false;
[SerializeField] bool hasIceBeam = false;
[SerializeField] bool hasWaveBeam = false;
[SerializeField] bool hasPlasmaBeam = false;
[SerializeField] bool[,] items;
private void Awake()
{
SetUpSingleton();
maxEnergy = 99; maxMissiles = 0; maxSuperMissiles = 0; maxPowerBombs = 0;
energy = 99; missiles = 0; superMissiles = 0;powerBombs = 0;
hasMorphBall = false; hasMorphBallBombs = false;hasHighJump = false; hasGrappleBeam = false;
items = new bool[100, 10];
for(int i = 0; i < items.GetLength(0); i++)
{
for(int j = 0; j < items.GetLength(1); j++)
{
items[i, j] = true;
}
}
for (int row = 0; row < items.GetLength(0); row++)
{
string ok = "";
for (int col = 0; col < items.GetLength(1); col++)
{
ok = ok + items[row, col] + "";
}
//Debug.Log(ok);
}
}
private void SetUpSingleton()
{
if (FindObjectsOfType<GameManager>().Length > 1){Destroy(gameObject); }
else{DontDestroyOnLoad(gameObject); }
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (FindObjectOfType<PlayerItems>() != null && FindObjectOfType<PlayerItems>().GetIsReadyForStatsUpdate()==true)
{
PlayerItems samus = FindObjectOfType<PlayerItems>();
maxEnergy = samus.GetMaxEnergy();
maxMissiles = samus.GetMaxMissiles();
maxSuperMissiles = samus.GetMaxSuperMissiles();
maxPowerBombs = samus.GetMaxPowerBombs();
energy = samus.GetEnergy();
missiles = samus.GetMissiles();
superMissiles = samus.GetSuperMissiles();
powerBombs = samus.GetPowerBombs();
hasMorphBall = samus.GetHasMorphBall();
hasMorphBallBombs = samus.GetHasMorphBallBombs();
hasHighJump = samus.GetHasHighJump();
hasGrappleBeam = samus.GetHasGrappleBeam();
hasIceBeam = samus.GetHasIceBeam();
hasWaveBeam = samus.GetHasWaveBeam();
hasPlasmaBeam = samus.GetHasPlasmaBeam();
if (samus.GetEnergy() <= 0) { StartCoroutine(ResetGame()); }
}
}
public void RemoveItem(int r, int c)
{
items[r, c] = false;
}
public void StartGame()
{
SceneManager.LoadScene("Scene 1");
}
public void QuitGame()
{
Application.Quit();
}
public IEnumerator ResetGame()
{
yield return new WaitForSeconds(5f);
SceneManager.LoadScene("Start Scene");
Destroy(gameObject);
}
//GETTERS (MAX)
public int GetMaxEnergy() { return maxEnergy; }
public int GetMaxMissiles() { return maxMissiles; }
public int GetMaxSuperMissiles() { return maxSuperMissiles; }
public int GetMaxPowerBombs() { return maxPowerBombs; }
//GETTERS (CONDITIONS)
public bool GetHasMorphBall() { return hasMorphBall; }
public bool GetHasMorphBallBombs() { return hasMorphBallBombs; }
public bool GetHasHighJump() { return hasHighJump; }
public bool GetHasGrappleBeam() { return hasGrappleBeam; }
public bool GetHasIceBeam() { return hasIceBeam; }
public bool GetHasWaveBeam() { return hasWaveBeam; }
public bool GetHasPlasmaBeam() { return hasPlasmaBeam; }
//GETTERS (CURRENT)
public int GetEnergy() { return energy; }
public int GetMissiles() { return missiles; }
public int GetSuperMissiles() { return superMissiles; }
public int GetPowerBombs() { return powerBombs; }
public bool[,] GetItems() { return items; }
}