Browse Source

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

Josh_Dev_branch
ClairePeta 5 years ago
parent
commit
fbbdc46b5c
7 changed files with 42 additions and 10 deletions
  1. +8
    -1
      Assets/Scripts/Character.cs
  2. +4
    -4
      Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs
  3. +4
    -3
      Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs
  4. +8
    -0
      Assets/Scripts/GameMode/GameMode.cs
  5. +6
    -0
      Assets/Scripts/Managers/GameManager.cs
  6. +1
    -0
      Assets/Scripts/Networking/Client/ClientLoginManager.cs
  7. +11
    -2
      Assets/Scripts/UI/Client/LoginUIManager.cs

+ 8
- 1
Assets/Scripts/Character.cs View File

@ -69,7 +69,14 @@ public class Character : MonoBehaviour
characterAnimator = GetComponentInChildren<Animator>(); characterAnimator = GetComponentInChildren<Animator>();
} }
private void Update()
{
if(lives < 1)
{
this.enabled = false;
gameObject.SetActive(false);
}
}
#endregion Unity Functions #endregion Unity Functions

+ 4
- 4
Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs View File

@ -170,15 +170,15 @@ public class ColorGameMode : GameMode
{ {
character.stuck = true; 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) if (character.inPit)
{ {
character.lives -= 1; character.lives -= 1;
character.ClientLink.Lives = character.lives; character.ClientLink.Lives = character.lives;
} }
Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck);
} }
private IEnumerator AnimateBlock(Material mat, float time) private IEnumerator AnimateBlock(Material mat, float time)

+ 4
- 3
Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs View File

@ -187,15 +187,16 @@ public class RacetrackGameMode : GameMode
{ {
character.stuck = true; 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) if (character.inPit)
{ {
character.lives -= 1; character.lives -= 1;
character.ClientLink.Lives = character.lives; character.ClientLink.Lives = character.lives;
} }
Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck);
} }
private IEnumerator AnimateBlock(Material mat, float time) private IEnumerator AnimateBlock(Material mat, float time)

+ 8
- 0
Assets/Scripts/GameMode/GameMode.cs View File

@ -67,6 +67,9 @@ public abstract class GameMode : ScriptableObject
/// <param name="currentBlock">Block which the character finished on</param> /// <param name="currentBlock">Block which the character finished on</param>
protected virtual void OnPlayerMoved(Character character, ClientData client, Block currentBlock) { } protected virtual void OnPlayerMoved(Character character, ClientData client, Block currentBlock) { }
protected virtual void OnPlayerKilled(Character character, ClientData client) { }
/// <summary> /// <summary>
/// Called once after every player has finished one move /// Called once after every player has finished one move
/// </summary> /// </summary>
@ -150,6 +153,11 @@ public abstract class GameMode : ScriptableObject
OnPlayerMoved(player.character, player.client, player.character.CurrentBlock); OnPlayerMoved(player.character, player.client, player.character.CurrentBlock);
} }
public void PlayerKilled(PlayerData player)
{
OnPlayerKilled(player.character, player.client);
}
public void AllPlayersMoved(PlayerData[] allPlayers) public void AllPlayersMoved(PlayerData[] allPlayers)
{ {
OnAllPlayersMoved(allPlayers); OnAllPlayersMoved(allPlayers);

+ 6
- 0
Assets/Scripts/Managers/GameManager.cs View File

@ -126,6 +126,12 @@ public class GameManager : MonoBehaviour
//Let Gamemode know all players have moved //Let Gamemode know all players have moved
gameMode.AllPlayersMoved(playerDataAsArray.ToArray()); 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 playerDataAsArray.ForEach(p => p.client.SendLives()); //Update the players score
//if Game is over break out of loop //if Game is over break out of loop

+ 1
- 0
Assets/Scripts/Networking/Client/ClientLoginManager.cs View File

@ -47,6 +47,7 @@ namespace Networking.Client
[Tooltip("Send prefilled Player settings after connecting")] [Tooltip("Send prefilled Player settings after connecting")]
private bool IdentifyOnConnect = false; private bool IdentifyOnConnect = false;
ConnectedClients clients;
#endregion Inspector Fields #endregion Inspector Fields
#region Events #region Events

+ 11
- 2
Assets/Scripts/UI/Client/LoginUIManager.cs View File

@ -8,7 +8,7 @@ public class LoginUIManager : MonoBehaviour
{ {
public int conn; public int conn;
public int maxPlayers = 2; public int maxPlayers = 2;
ConnectedClients clients;
public ConnectedClients clients;
[Header("References")] [Header("References")]
[SerializeField] [SerializeField]
private ClientLoginManager clientManager; private ClientLoginManager clientManager;
@ -54,6 +54,15 @@ public class LoginUIManager : MonoBehaviour
private void Update() private void Update()
{ {
conn = GetComponent<animalSelection>().count; conn = GetComponent<animalSelection>().count;
clients = GetComponent<animalSelection>().Clients;
foreach (ClientData cli in clients.AllClients)
{
if (playerAnimal == cli.characterAnimal)
{
playerAnimal = null;
animalSelected = false;
}
}
} }
private void OnEnable() private void OnEnable()
{ {
@ -78,7 +87,6 @@ public class LoginUIManager : MonoBehaviour
OnLoginFail(); OnLoginFail();
} }
#endregion Unity Functions #endregion Unity Functions
@ -151,6 +159,7 @@ public class LoginUIManager : MonoBehaviour
{ {
if (colorSelected == true && animalSelected == true && playerName != "") if (colorSelected == true && animalSelected == true && playerName != "")
{ {
clientManager.SendPlayerDetails(playerName, playerColor, playerAnimal); clientManager.SendPlayerDetails(playerName, playerColor, playerAnimal);
PlayerPrefs.SetString("LastUsedName", playerName); PlayerPrefs.SetString("LastUsedName", playerName);
} }

Loading…
Cancel
Save