Browse Source

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
Josh_Dev_branch
ClairePeta 5 years ago
parent
commit
e03b0951cd
8 changed files with 76 additions and 74 deletions
  1. +2
    -2
      Assets/Scenes/Client Scenes/LoginScreen.unity
  2. +16
    -49
      Assets/Scripts/Character.cs
  3. +4
    -4
      Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs
  4. +3
    -3
      Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs
  5. +1
    -1
      Assets/Scripts/Logic/BlockReader.cs
  6. +46
    -7
      Assets/Scripts/Managers/GameManager.cs
  7. +0
    -4
      Assets/Scripts/Networking/Server/ClientList.cs
  8. +4
    -4
      Assets/Scripts/Traps/ConveyorBelt.cs

+ 2
- 2
Assets/Scenes/Client Scenes/LoginScreen.unity View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:d62fbbd19c357e8a8f7dc643cb14fd4912694dcb56997edb1736298346b4bf9a
size 260483
oid sha256:6666536f6305b3cb778fc9bcd3272f2e863a182d5a5d756a50e8a72ffbfef2ac
size 260470

+ 16
- 49
Assets/Scripts/Character.cs View File

@ -69,9 +69,13 @@ public class Character : MonoBehaviour
characterAnimator = GetComponentInChildren<Animator>(); characterAnimator = GetComponentInChildren<Animator>();
} }
private void Update()
{
if (lives < 1)
{
this.enabled = false;
}
}
#endregion Unity Functions #endregion Unity Functions
#region Class Implementation #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 Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
Block hit; //output of block detection 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) public void CannonRMove(float speed)
{ {
Direction direction = Direction.Right; Direction direction = Direction.Right;
@ -403,10 +370,10 @@ public class Character : MonoBehaviour
Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z); Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z);
if (Block.isBlockAtPosition(currentPos, 1, ~Ignore, out currentBlock)) //Does a block exist here? 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? 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 //Don't yet have a check for whether it's occupied
break; //If it is, we stop here break; //If it is, we stop here
} }
@ -417,10 +384,10 @@ public class Character : MonoBehaviour
Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z); Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z);
if (Block.isBlockAtPosition(currentPos, 1, ~Ignore, out currentBlock)) //Does a block exist here? 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? 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 //Don't yet have a check for whether it's occupied
break; //If it is, we stop here break; //If it is, we stop here
} }
@ -429,10 +396,10 @@ public class Character : MonoBehaviour
Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z); Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z);
if (Block.isBlockAtPosition(currentPos, 1, ~Ignore, out currentBlock)) //Does a block exist here? 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? 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 //Don't yet have a check for whether it's occupied
break; //If it is, we stop here break; //If it is, we stop here
} }
@ -448,11 +415,11 @@ public class Character : MonoBehaviour
this.transform.position = currentBlock.VisualPosition; this.transform.position = currentBlock.VisualPosition;
this.inPit = false; this.inPit = false;
this._currentBlock = currentBlock; this._currentBlock = currentBlock;
Debug.Log("Moved " + this.name + " to "
/*Debug.Log("Moved " + this.name + " to "
+ this.transform.position.x + ", " + this.transform.position.x + ", "
+ this.transform.position.y + ", " + this.transform.position.y + ", "
+ this.transform.position.z + ", " + this.transform.position.z + ", "
+ " inPit = " + inPit);
+ " inPit = " + inPit);*/
} }
else else
{ {

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

@ -28,11 +28,11 @@ public class ColorGameMode : GameMode
if (scrollSpeed > 0.0f) if (scrollSpeed > 0.0f)
{ {
Camera.main.transform.Translate(scrollSpeed, 0, 0, Space.World); 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 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 //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; player.character.stuck = false;
if (player.character.inPit)
if (player.character.inPit && player.client.Lives >0)
{ {
player.character.respawnCharacter(); player.character.respawnCharacter();
} }
@ -177,7 +177,7 @@ public class ColorGameMode : GameMode
character.ClientLink.Lives = character.lives; 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);
} }

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

@ -28,11 +28,11 @@ public class RacetrackGameMode : GameMode
if (scrollSpeed > 0.0f) if (scrollSpeed > 0.0f)
{ {
Camera.main.transform.Translate(scrollSpeed, 0, 0, Space.World); 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 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 //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; player.character.stuck = false;
if (player.character.inPit)
if (player.character.inPit && player.client.Lives > 0)
{ {
player.character.respawnCharacter(); player.character.respawnCharacter();
} }

+ 1
- 1
Assets/Scripts/Logic/BlockReader.cs View File

@ -69,7 +69,7 @@ public class BlockReader
} }
else 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 //return that this is done if no more blocks left in chain

+ 46
- 7
Assets/Scripts/Managers/GameManager.cs View File

@ -102,6 +102,12 @@ public class GameManager : MonoBehaviour
gameMode.GameEnd(playerDataAsArray); gameMode.GameEnd(playerDataAsArray);
} }
void removePlayer(PlayerData player)
{
player.client.ChangeScene("WaitScene");
player.isDead = true;
}
private IEnumerator RoundRoutine() private IEnumerator RoundRoutine()
{ {
//Tell the gamemode that we are starting a round //Tell the gamemode that we are starting a round
@ -130,13 +136,29 @@ public class GameManager : MonoBehaviour
//Let GameMode know that Round is Over //Let GameMode know that Round is Over
gameMode.RoundEnd(playerDataAsArray.ToArray()); 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) 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() private IEnumerator WaitForPlayerInput()
@ -144,19 +166,35 @@ public class GameManager : MonoBehaviour
//send round length to players //send round length to players
//#TODO make this only happen after first input //#TODO make this only happen after first input
LogicProtocols.FloatMsg RoundTime = new LogicProtocols.FloatMsg(gameMode.GetRoundTime()); 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 //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 //Let gamemode know clients are input-ing
gameMode.InputStart(playerDataAsArray); gameMode.InputStart(playerDataAsArray);
//wait for all players to //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 //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 //Let gamemode know all inputs have been recieved
gameMode.InputEnd(playerDataAsArray); gameMode.InputEnd(playerDataAsArray);
@ -269,6 +307,7 @@ public class PlayerData
public ClientData client; public ClientData client;
public bool recievedList; public bool recievedList;
public bool isDead = false;
public PlayerData(Character character, ClientData client) public PlayerData(Character character, ClientData client)
{ {

+ 0
- 4
Assets/Scripts/Networking/Server/ClientList.cs View File

@ -159,10 +159,6 @@ namespace Networking.Server
newClient.SendInventory(); newClient.SendInventory();
newClient.SendLives(); newClient.SendLives();
newClient.ChangeScene("WaitScene"); newClient.ChangeScene("WaitScene");
} }

+ 4
- 4
Assets/Scripts/Traps/ConveyorBelt.cs View File

@ -48,19 +48,19 @@ public class ConveyorBelt : MonoBehaviour
if(forward == true) if(forward == true)
{ {
player.GetComponent<Character>().conveyorMoveForward(Direction.Forward, 1.0f);
player.GetComponent<Character>().conveyorMove(Direction.Forward, 1.0f);
} }
else if (forward == false) else if (forward == false)
{ {
player.GetComponent<Character>().conveyorMoveBackward(Direction.Back, 1.0f);
player.GetComponent<Character>().conveyorMove(Direction.Back, 1.0f);
} }
if (left == true) if (left == true)
{ {
player.GetComponent<Character>().conveyorMoveLeft(Direction.Left, 1.0f);
player.GetComponent<Character>().conveyorMove(Direction.Left, 1.0f);
} }
else if (left == false) else if (left == false)
{ {
player.GetComponent<Character>().conveyorMoveRight(Direction.Right, 1.0f);
player.GetComponent<Character>().conveyorMove(Direction.Right, 1.0f);
} }
} }
} }

Loading…
Cancel
Save