From e03b0951cdf484b0b0fe0f1d2c874db702f58395 Mon Sep 17 00:00:00 2001 From: ClairePeta Date: Fri, 6 Sep 2019 16:54:22 +1000 Subject: [PATCH] Player is 'dead' when lives reach zero, client scene stays in 'waiting for players' server doesnt wait for 'dead' players move list character for now dissappears --- Assets/Scenes/Client Scenes/LoginScreen.unity | 4 +- Assets/Scripts/Character.cs | 65 +++++-------------- .../GameMode/ColorGameMode/ColorGameMode.cs | 8 +-- .../ColorGameMode/RacetrackGameMode.cs | 6 +- Assets/Scripts/Logic/BlockReader.cs | 2 +- Assets/Scripts/Managers/GameManager.cs | 53 +++++++++++++-- .../Scripts/Networking/Server/ClientList.cs | 4 -- Assets/Scripts/Traps/ConveyorBelt.cs | 8 +-- 8 files changed, 76 insertions(+), 74 deletions(-) diff --git a/Assets/Scenes/Client Scenes/LoginScreen.unity b/Assets/Scenes/Client Scenes/LoginScreen.unity index 6bbc340..7e86f26 100644 --- a/Assets/Scenes/Client Scenes/LoginScreen.unity +++ b/Assets/Scenes/Client Scenes/LoginScreen.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d62fbbd19c357e8a8f7dc643cb14fd4912694dcb56997edb1736298346b4bf9a -size 260483 +oid sha256:6666536f6305b3cb778fc9bcd3272f2e863a182d5a5d756a50e8a72ffbfef2ac +size 260470 diff --git a/Assets/Scripts/Character.cs b/Assets/Scripts/Character.cs index 7d99184..e40d642 100644 --- a/Assets/Scripts/Character.cs +++ b/Assets/Scripts/Character.cs @@ -69,9 +69,13 @@ public class Character : MonoBehaviour characterAnimator = GetComponentInChildren(); } - - - + private void Update() + { + if (lives < 1) + { + this.enabled = false; + } + } #endregion Unity Functions #region Class Implementation @@ -305,7 +309,7 @@ public class Character : MonoBehaviour } } - public void conveyorMoveForward(Direction direction, float speed) + public void conveyorMove(Direction direction, float speed) { Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted Block hit; //output of block detection @@ -318,43 +322,6 @@ public class Character : MonoBehaviour } } - public void conveyorMoveBackward(Direction direction, float speed) - { - Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted - Block hit; //output of block detection - Block moveTo = _currentBlock; //block we'll actually move to - if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) - { - moveTo = hit; - _currentBlock = moveTo; - StartCoroutine(MoveConveyorBackwardCoroutine(_currentBlock, transform, speed, 0.3f)); - } - } - public void conveyorMoveLeft(Direction direction, float speed) - { - Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted - Block hit; //output of block detection - Block moveTo = _currentBlock; //block we'll actually move to - if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) - { - moveTo = hit; - _currentBlock = moveTo; - StartCoroutine(MoveConveyorLeftCoroutine(_currentBlock, transform, speed, 0.3f)); - } - } - public void conveyorMoveRight(Direction direction, float speed) - { - Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted - Block hit; //output of block detection - Block moveTo = _currentBlock; //block we'll actually move to - if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) - { - moveTo = hit; - _currentBlock = moveTo; - StartCoroutine(MoveConveyorRightCoroutine(_currentBlock, transform, speed, 0.3f)); - } - } - public void CannonRMove(float speed) { Direction direction = Direction.Right; @@ -403,10 +370,10 @@ public class Character : MonoBehaviour Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z); if (Block.isBlockAtPosition(currentPos, 1, ~Ignore, out currentBlock)) //Does a block exist here? { - Debug.Log("Block exists"); + //Debug.Log("Block exists"); if (currentBlock.isWalkable(~Ignore)) //If so, can we walk on it? { - Debug.Log("Block is walkable"); + //Debug.Log("Block is walkable"); //Don't yet have a check for whether it's occupied break; //If it is, we stop here } @@ -417,10 +384,10 @@ public class Character : MonoBehaviour Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z); if (Block.isBlockAtPosition(currentPos, 1, ~Ignore, out currentBlock)) //Does a block exist here? { - Debug.Log("Block exists"); + //Debug.Log("Block exists"); if (currentBlock.isWalkable(~Ignore)) //If so, can we walk on it? { - Debug.Log("Block is walkable"); + //Debug.Log("Block is walkable"); //Don't yet have a check for whether it's occupied break; //If it is, we stop here } @@ -429,10 +396,10 @@ public class Character : MonoBehaviour Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z); if (Block.isBlockAtPosition(currentPos, 1, ~Ignore, out currentBlock)) //Does a block exist here? { - Debug.Log("Block exists"); + //Debug.Log("Block exists"); if (currentBlock.isWalkable(~Ignore)) //If so, can we walk on it? { - Debug.Log("Block is walkable"); + //Debug.Log("Block is walkable"); //Don't yet have a check for whether it's occupied break; //If it is, we stop here } @@ -448,11 +415,11 @@ public class Character : MonoBehaviour this.transform.position = currentBlock.VisualPosition; this.inPit = false; this._currentBlock = currentBlock; - Debug.Log("Moved " + this.name + " to " + /*Debug.Log("Moved " + this.name + " to " + this.transform.position.x + ", " + this.transform.position.y + ", " + this.transform.position.z + ", " - + " inPit = " + inPit); + + " inPit = " + inPit);*/ } else { diff --git a/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs b/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs index 7a07b56..1e8be44 100644 --- a/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs +++ b/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs @@ -28,11 +28,11 @@ public class ColorGameMode : GameMode if (scrollSpeed > 0.0f) { Camera.main.transform.Translate(scrollSpeed, 0, 0, Space.World); - Debug.Log("New camera position at x = " + Camera.main.transform.position.x); + //Debug.Log("New camera position at x = " + Camera.main.transform.position.x); } else { - Debug.Log("Not scrolling"); + //Debug.Log("Not scrolling"); } //At the end of each round, any stuck players are freed to resume moving next round @@ -40,7 +40,7 @@ public class ColorGameMode : GameMode { player.character.stuck = false; - if (player.character.inPit) + if (player.character.inPit && player.client.Lives >0) { player.character.respawnCharacter(); } @@ -177,7 +177,7 @@ public class ColorGameMode : GameMode character.ClientLink.Lives = character.lives; } - Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck); + //Debug.Log(character.name + " inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck); } diff --git a/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs b/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs index 76a5a13..7b6b7d3 100644 --- a/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs +++ b/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs @@ -28,11 +28,11 @@ public class RacetrackGameMode : GameMode if (scrollSpeed > 0.0f) { Camera.main.transform.Translate(scrollSpeed, 0, 0, Space.World); - Debug.Log("New camera position at x = " + Camera.main.transform.position.x); + //Debug.Log("New camera position at x = " + Camera.main.transform.position.x); } else { - Debug.Log("Not scrolling"); + //Debug.Log("Not scrolling"); } //At the end of each round, any stuck players are freed to resume moving next round @@ -40,7 +40,7 @@ public class RacetrackGameMode : GameMode { player.character.stuck = false; - if (player.character.inPit) + if (player.character.inPit && player.client.Lives > 0) { player.character.respawnCharacter(); } diff --git a/Assets/Scripts/Logic/BlockReader.cs b/Assets/Scripts/Logic/BlockReader.cs index f04e89f..6ce0257 100644 --- a/Assets/Scripts/Logic/BlockReader.cs +++ b/Assets/Scripts/Logic/BlockReader.cs @@ -69,7 +69,7 @@ public class BlockReader } else { - Debug.Log("Character is not stuck"); + //Debug.Log("Character is not stuck"); } //return that this is done if no more blocks left in chain diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs index bfdd420..0e2cfba 100644 --- a/Assets/Scripts/Managers/GameManager.cs +++ b/Assets/Scripts/Managers/GameManager.cs @@ -102,6 +102,12 @@ public class GameManager : MonoBehaviour gameMode.GameEnd(playerDataAsArray); } + void removePlayer(PlayerData player) + { + player.client.ChangeScene("WaitScene"); + player.isDead = true; + } + private IEnumerator RoundRoutine() { //Tell the gamemode that we are starting a round @@ -130,13 +136,29 @@ public class GameManager : MonoBehaviour //Let GameMode know that Round is Over gameMode.RoundEnd(playerDataAsArray.ToArray()); - //Reset some player Data + + //check is anyone has 0 lives remaining + //remove them from the array + //force them back to the waiting for players screen foreach (PlayerData player in playerDataAsArray) { - player.blockReader.Reset(); - player.client.SendInventory(); + if(player.client.Lives == 0) + { + Debug.Log("Remove: " + player.client.characterAnimal); + removePlayer(player); + } } + + //Reset some player Data + foreach (PlayerData player in playerDataAsArray) + { + if(player.client.Lives > 0) + { + player.blockReader.Reset(); + player.client.SendInventory(); + } + } } private IEnumerator WaitForPlayerInput() @@ -144,19 +166,35 @@ public class GameManager : MonoBehaviour //send round length to players //#TODO make this only happen after first input LogicProtocols.FloatMsg RoundTime = new LogicProtocols.FloatMsg(gameMode.GetRoundTime()); - playerDataAsArray.ForEach(p => p.client.conn.Send(LogicProtocols.SendRoundTime, RoundTime)); + + //playerDataAsArray.ForEach(p => p.client.conn.Send(LogicProtocols.SendRoundTime, RoundTime)); + foreach (PlayerData player in playerDataAsArray) + { + if (player.client.Lives > 0) + { + player.client.conn.Send(LogicProtocols.SendRoundTime, RoundTime); + } + } //Send players to input Scene - ClientList.ForEach(p => p.ChangeScene("ClientScene")); + //ClientList.ForEach(p => p.ChangeScene("ClientScene")); + foreach (ClientData client in ClientList) + { + if(client.Lives > 0){client.ChangeScene("ClientScene");} + } //Let gamemode know clients are input-ing gameMode.InputStart(playerDataAsArray); //wait for all players to - yield return new WaitUntil(() => playerData.All(p => p.Value.recievedList)); + yield return new WaitUntil(() => playerData.All(p => p.Value.recievedList || p.Value.isDead)); //reset - playerDataAsArray.ForEach(p => p.recievedList = false); //reset all players list + //playerDataAsArray.ForEach(p => p.recievedList = false); //reset all players list + foreach (PlayerData player in playerDataAsArray) + { + if (player.client.Lives > 0){player.recievedList = false;} + } //Let gamemode know all inputs have been recieved gameMode.InputEnd(playerDataAsArray); @@ -269,6 +307,7 @@ public class PlayerData public ClientData client; public bool recievedList; + public bool isDead = false; public PlayerData(Character character, ClientData client) { diff --git a/Assets/Scripts/Networking/Server/ClientList.cs b/Assets/Scripts/Networking/Server/ClientList.cs index 3b7a06c..1965eab 100644 --- a/Assets/Scripts/Networking/Server/ClientList.cs +++ b/Assets/Scripts/Networking/Server/ClientList.cs @@ -159,10 +159,6 @@ namespace Networking.Server newClient.SendInventory(); newClient.SendLives(); newClient.ChangeScene("WaitScene"); - - - - } diff --git a/Assets/Scripts/Traps/ConveyorBelt.cs b/Assets/Scripts/Traps/ConveyorBelt.cs index 3a8fe3a..a7cb109 100644 --- a/Assets/Scripts/Traps/ConveyorBelt.cs +++ b/Assets/Scripts/Traps/ConveyorBelt.cs @@ -48,19 +48,19 @@ public class ConveyorBelt : MonoBehaviour if(forward == true) { - player.GetComponent().conveyorMoveForward(Direction.Forward, 1.0f); + player.GetComponent().conveyorMove(Direction.Forward, 1.0f); } else if (forward == false) { - player.GetComponent().conveyorMoveBackward(Direction.Back, 1.0f); + player.GetComponent().conveyorMove(Direction.Back, 1.0f); } if (left == true) { - player.GetComponent().conveyorMoveLeft(Direction.Left, 1.0f); + player.GetComponent().conveyorMove(Direction.Left, 1.0f); } else if (left == false) { - player.GetComponent().conveyorMoveRight(Direction.Right, 1.0f); + player.GetComponent().conveyorMove(Direction.Right, 1.0f); } } }