From fbbdc46b5caeb4c7e09c22b06287c533bcfb6e9c Mon Sep 17 00:00:00 2001 From: ClairePeta Date: Wed, 11 Sep 2019 15:23:34 +1000 Subject: [PATCH] Two people cant choose the same animal, even if one is selected before another peson connects. Life is now lost/deducted once at the end of the round instead of one per move (causing multiple lifes lost if in the pit) when lives reach zero players die --- Assets/Scripts/Character.cs | 9 ++++++++- .../Scripts/GameMode/ColorGameMode/ColorGameMode.cs | 8 ++++---- .../GameMode/ColorGameMode/RacetrackGameMode.cs | 7 ++++--- Assets/Scripts/GameMode/GameMode.cs | 8 ++++++++ Assets/Scripts/Managers/GameManager.cs | 6 ++++++ .../Scripts/Networking/Client/ClientLoginManager.cs | 1 + Assets/Scripts/UI/Client/LoginUIManager.cs | 13 +++++++++++-- 7 files changed, 42 insertions(+), 10 deletions(-) diff --git a/Assets/Scripts/Character.cs b/Assets/Scripts/Character.cs index 7d99184..a4c75a7 100644 --- a/Assets/Scripts/Character.cs +++ b/Assets/Scripts/Character.cs @@ -69,7 +69,14 @@ public class Character : MonoBehaviour characterAnimator = GetComponentInChildren(); } - + private void Update() + { + if(lives < 1) + { + this.enabled = false; + gameObject.SetActive(false); + } + } #endregion Unity Functions diff --git a/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs b/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs index 7a07b56..2a2708c 100644 --- a/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs +++ b/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs @@ -170,15 +170,15 @@ public class ColorGameMode : GameMode { character.stuck = true; } - + Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck); + } + protected override void OnPlayerKilled(Character character, ClientData client) + { if (character.inPit) { character.lives -= 1; character.ClientLink.Lives = character.lives; } - - Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck); - } private IEnumerator AnimateBlock(Material mat, float time) diff --git a/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs b/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs index 21a2bf0..e4ef42a 100644 --- a/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs +++ b/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs @@ -187,15 +187,16 @@ public class RacetrackGameMode : GameMode { character.stuck = true; } + Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck); + } + protected override void OnPlayerKilled(Character character, ClientData client) + { if (character.inPit) { character.lives -= 1; character.ClientLink.Lives = character.lives; } - - Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck); - } private IEnumerator AnimateBlock(Material mat, float time) diff --git a/Assets/Scripts/GameMode/GameMode.cs b/Assets/Scripts/GameMode/GameMode.cs index a8e3902..b813f02 100644 --- a/Assets/Scripts/GameMode/GameMode.cs +++ b/Assets/Scripts/GameMode/GameMode.cs @@ -67,6 +67,9 @@ public abstract class GameMode : ScriptableObject /// Block which the character finished on protected virtual void OnPlayerMoved(Character character, ClientData client, Block currentBlock) { } + + protected virtual void OnPlayerKilled(Character character, ClientData client) { } + /// /// Called once after every player has finished one move /// @@ -150,6 +153,11 @@ public abstract class GameMode : ScriptableObject OnPlayerMoved(player.character, player.client, player.character.CurrentBlock); } + public void PlayerKilled(PlayerData player) + { + OnPlayerKilled(player.character, player.client); + } + public void AllPlayersMoved(PlayerData[] allPlayers) { OnAllPlayersMoved(allPlayers); diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs index 63d5008..0e498ef 100644 --- a/Assets/Scripts/Managers/GameManager.cs +++ b/Assets/Scripts/Managers/GameManager.cs @@ -126,6 +126,12 @@ public class GameManager : MonoBehaviour //Let Gamemode know all players have moved gameMode.AllPlayersMoved(playerDataAsArray.ToArray()); + //decrease lives here!! + foreach(PlayerData player in playerDataAsArray) + { + gameMode.PlayerKilled(player); + } + playerDataAsArray.ForEach(p => p.client.SendLives()); //Update the players score //if Game is over break out of loop diff --git a/Assets/Scripts/Networking/Client/ClientLoginManager.cs b/Assets/Scripts/Networking/Client/ClientLoginManager.cs index 144e4e4..2cc1817 100644 --- a/Assets/Scripts/Networking/Client/ClientLoginManager.cs +++ b/Assets/Scripts/Networking/Client/ClientLoginManager.cs @@ -47,6 +47,7 @@ namespace Networking.Client [Tooltip("Send prefilled Player settings after connecting")] private bool IdentifyOnConnect = false; + ConnectedClients clients; #endregion Inspector Fields #region Events diff --git a/Assets/Scripts/UI/Client/LoginUIManager.cs b/Assets/Scripts/UI/Client/LoginUIManager.cs index 79e76d0..98d7460 100644 --- a/Assets/Scripts/UI/Client/LoginUIManager.cs +++ b/Assets/Scripts/UI/Client/LoginUIManager.cs @@ -8,7 +8,7 @@ public class LoginUIManager : MonoBehaviour { public int conn; public int maxPlayers = 2; - ConnectedClients clients; + public ConnectedClients clients; [Header("References")] [SerializeField] private ClientLoginManager clientManager; @@ -54,6 +54,15 @@ public class LoginUIManager : MonoBehaviour private void Update() { conn = GetComponent().count; + clients = GetComponent().Clients; + foreach (ClientData cli in clients.AllClients) + { + if (playerAnimal == cli.characterAnimal) + { + playerAnimal = null; + animalSelected = false; + } + } } private void OnEnable() { @@ -78,7 +87,6 @@ public class LoginUIManager : MonoBehaviour OnLoginFail(); } - #endregion Unity Functions @@ -151,6 +159,7 @@ public class LoginUIManager : MonoBehaviour { if (colorSelected == true && animalSelected == true && playerName != "") { + clientManager.SendPlayerDetails(playerName, playerColor, playerAnimal); PlayerPrefs.SetString("LastUsedName", playerName); }