Skip to content

Commit a6f4c06

Browse files
committed
Added end game animations. Cleaned up UI and end game manager scripting
1 parent 083ac62 commit a6f4c06

9 files changed

Lines changed: 27642 additions & 12 deletions
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class AreaExplosionSpawner : MonoBehaviour {
6+
7+
public GameObject explosion;
8+
public float width;
9+
public float height;
10+
public float rate;
11+
public float amount;
12+
13+
private float timer;
14+
15+
private void Update() {
16+
if (timer < 0) {
17+
var x = transform.position.x + Random.Range(0f, width);
18+
var z = transform.position.z + Random.Range(0f, height);
19+
20+
Instantiate(explosion, new Vector3(x, 0.5f, z), Quaternion.identity);
21+
22+
timer = rate;
23+
} else {
24+
timer -= Time.deltaTime;
25+
}
26+
27+
}
28+
}

Assets/EC2018/AreaExplosionSpawner.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/EC2018/GameManager.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class GameManager : MonoBehaviour {
2424

2525
public int startRound;
2626

27+
private bool gameFinished;
28+
2729
void Start () {
2830
instantiator = GetComponent<Instantiator> ();
2931
uiManager = GameObject.FindGameObjectWithTag (Constants.Tags.UIHolder).GetComponent<UIManager> ();
@@ -50,7 +52,9 @@ public void NavigateToReplayMenu() {
5052

5153
public void ReplayFinished() {
5254
uiManager.DisplayFinalGameMessage (LoadFinalGameResults());
53-
HaltAllGameObects ();
55+
HaltAllGameObects();
56+
gameStateManager.EndGame();
57+
gameFinished = true;
5458
}
5559

5660
string LoadFinalGameResults() {
@@ -71,11 +75,8 @@ void HaltAllGameObects() {
7175
}
7276

7377
void AttemptToStartReplay() {
74-
if (gameStateManager.CanIncrementRound()) {
78+
if(!gameFinished) {
7579
InvokeRepeating(StartReplayMethod, 0.5f, 0.5f);
76-
} else if (gameStateManager.IsGameFinished()) {
77-
StopReplay();
78-
ReplayFinished();
7980
}
8081
}
8182

Assets/EC2018/GameStateManager.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ public bool CanIncrementRound() {
5252
return currentRound < maxRounds;
5353
}
5454

55-
public bool IsGameFinished() {
56-
return currentRound >= maxRounds;
55+
public void EndGame() {
56+
if(gameState.Players[0].Health < gameState.Players[1].Health) {
57+
instantiator.InstantiateEndGameAnimations(PlayerType.A);
58+
} else if(gameState.Players[0].Health > gameState.Players[1].Health) {
59+
instantiator.InstantiateEndGameAnimations(PlayerType.B);
60+
}
5761
}
5862

5963
void PopulateSceneFromGameMap() {
@@ -86,7 +90,7 @@ public void PlayCurrentState() {
8690
ProcessIronCurtainHitList(gameState.Players);
8791
if (CanIncrementRound()) {
8892
currentRound++;
89-
} else if (IsGameFinished()) {
93+
} else {
9094
gameManager.ReplayFinished();
9195
}
9296
}

Assets/EC2018/Instantiator.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public class Instantiator : MonoBehaviour {
1717

1818
public GameObject lightningBolt;
1919

20+
public GameObject playerADestructionAnimation;
21+
public GameObject playerBDestructionAnimation;
22+
2023
public void ClearScene() {
2124
ClearGameObjectsWithTag (Constants.Tags.Missile);
2225
ClearGameObjectsWithTag (Constants.Tags.Attack);
@@ -102,6 +105,15 @@ public void DeactivateIronCurtain(PlayerType playerType) {
102105
obj.SetActive(false);
103106
}
104107

108+
public void InstantiateEndGameAnimations(PlayerType playerType) {
109+
if(playerType == PlayerType.A) {
110+
playerADestructionAnimation.SetActive(true);
111+
} else {
112+
playerBDestructionAnimation.SetActive(true);
113+
}
114+
115+
}
116+
105117
GameObject GetPrefabForBuilding(Building building, PlayerType playerType) {
106118
switch (building.BuildingType) {
107119
case BuildingType.Attack:

0 commit comments

Comments
 (0)