Commit c77f78df by Tim Reiter

implemented back to menu from game over panel.

parent 3df54979
......@@ -7,7 +7,11 @@ public class GameMaster : MonoBehaviour
{
DeserializedLevelsLoader levelLoader;
public PlayerControl[] playerPrefabs;
public GameObject gameUIPanel;
public GameObject gameOverPanel;
public GameObject menuBloomPanel;
public GameObject menuPanel;
public Text rankingText;
private GameStateTracker gameStateTracker;
......@@ -27,21 +31,31 @@ public class GameMaster : MonoBehaviour
level = Random.Range(0, levelLoader.getLevelCount());
levelLoader.loadLevel(level);
deleteAllPlayers();
destroyDynamicObjects();
spawnPlayers(numberOfPlayers);
}
private void deleteAllPlayers()
private void deleteAllLevelObjects()
{
GameObject level = GameObject.Find("XmlItems");
Destroy(level);
destroyDynamicObjects();
}
//deletes all objects spawned during the game:
private void destroyDynamicObjects()
{
foreach (Transform child in deleteAllChildrenAtRestart.transform)
{
if (child != deleteAllChildrenAtRestart.gameObject)
{
Destroy(child.gameObject,0f);
Destroy(child.gameObject, 0f);
}
}
}
private void spawnPlayers(int count)
{
Debug.Log("spawning " + count + " players");
......@@ -103,21 +117,38 @@ public class GameMaster : MonoBehaviour
}
private void restartGame()
{
gameStateTracker.reset();
loadLevel(gameStateTracker.getNumberOfPlayers()); //loads a new level randomly
rankingText.text = "";
gameOverPanel.SetActive(false);
}
private void goToMenu()
{
rankingText.text = "";
deleteAllLevelObjects();
menuBloomPanel.SetActive(true);
menuPanel.SetActive(true);
menuPanel.GetComponent<Menu>().reset();
gameOverPanel.SetActive(false);
gameUIPanel.SetActive(false);
}
void Update()
{
if (gameOverPanel.activeSelf)
{
if (Input.GetKeyDown(KeyCode.Space))
{
gameStateTracker.reset();
loadLevel(gameStateTracker.getNumberOfPlayers()); //loads a new level randomly
rankingText.text = "";
gameOverPanel.SetActive(false);
restartGame();
}
else if (Input.GetKeyDown(KeyCode.Return))
{
goToMenu();
}
}
}
......
......@@ -17,6 +17,22 @@ public class Menu : MonoBehaviour
private bool WASDAdded, ArrowAdded, GP1Added, GP2Added, GP3Added, GP4Added;
public void reset()
{
//resets the number of players:
numberOfRegisteredPlayers = 0;
p1Image.SetActive(false);
p2Image.SetActive(false);
p3Image.SetActive(false);
p4Image.SetActive(false);
WASDAdded = false;
ArrowAdded = false;
GP1Added = false;
GP2Added = false;
GP3Added = false;
GP4Added = false;
}
void Start()
{
#region init bools
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment