Browse Source

Character lives displayed inplace of score, removed scenescore as not being used

added line so character and client lives update
tested with one client
Josh_Dev_branch
ClairePeta 5 years ago
parent
commit
8bd42e3aa7
14 changed files with 47 additions and 76 deletions
  1. +2
    -2
      Assets/Scenes/Client Scenes/ClientScene.unity
  2. +1
    -5
      Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs
  3. +3
    -2
      Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs
  4. +2
    -2
      Assets/Scripts/GameMode/ColorGameMode/ScoreDisplay.cs
  5. +1
    -1
      Assets/Scripts/GameMode/GameMode.cs
  6. +2
    -1
      Assets/Scripts/Managers/GameManager.cs
  7. +15
    -6
      Assets/Scripts/Networking/Client/ClientObject.cs
  8. +2
    -5
      Assets/Scripts/Networking/Core/Protocols/LogicProtocols.cs
  9. +9
    -9
      Assets/Scripts/Networking/Server/ClientList.cs
  10. +2
    -2
      Assets/Scripts/PortalSetup.cs
  11. +2
    -2
      Assets/Scripts/UI/LeadPlayerUI.cs
  12. +2
    -8
      Assets/Scripts/UI/NetworkedUIManager.cs
  13. +4
    -4
      Assets/Scripts/blockSpawn.cs
  14. +0
    -27
      Assets/Scripts/portalTesting.cs

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

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d7258afade2696f1f0e60c62feee99dad86bdbf347b9fc27b33b5adb1fa5343a
size 38163
oid sha256:84240e58ab2849433e76c59c022a3e864b4001184f0a8159450e06dfeb4bae36
size 38360

+ 1
- 5
Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs View File

@ -136,11 +136,6 @@ public class ColorGameMode : GameMode
* It's not needed from move to move, so we clear it
*/
player.character.justMoved = false;
if (BlocksOwned.ContainsKey(player.client))
player.client.SceneScore = BlocksOwned[player.client].Count;
else
player.client.SceneScore = 0;
}
}
@ -179,6 +174,7 @@ public class ColorGameMode : GameMode
if (character.inPit)
{
character.lives -= 1;
character.ClientLink.Lives = character.lives;
}
Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck);

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

@ -137,10 +137,10 @@ public class RacetrackGameMode : GameMode
*/
player.character.justMoved = false;
if (BlocksOwned.ContainsKey(player.client))
/* if (BlocksOwned.ContainsKey(player.client))
player.client.SceneScore = BlocksOwned[player.client].Count;
else
player.client.SceneScore = 0;
player.client.SceneScore = 0;*/
}
}
@ -179,6 +179,7 @@ public class RacetrackGameMode : GameMode
if (character.inPit)
{
character.lives -= 1;
character.ClientLink.Lives = character.lives;
}
Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck);

+ 2
- 2
Assets/Scripts/GameMode/ColorGameMode/ScoreDisplay.cs View File

@ -35,12 +35,12 @@ public class ScoreDisplay : MonoBehaviour
public void levelComplete()
{
ConnectedClients = clientDataList.ConnectedClients;
ConnectedClients.Sort((a, b) => b.SceneScore.CompareTo(a.SceneScore));
ConnectedClients.Sort((a, b) => b.Lives.CompareTo(a.Lives));
for (int i = 0; i < ConnectedClients.Count; i++)
{
players[i].GetComponent<TextMeshProUGUI>().text = ConnectedClients[i].Name;
scores[i].GetComponent<TextMeshProUGUI>().text = ConnectedClients[i].SceneScore.ToString();
scores[i].GetComponent<TextMeshProUGUI>().text = ConnectedClients[i].Lives.ToString();
}
int assignedPoints = 3;
for (int i = 0; i < ConnectedClients.Count; i++)

+ 1
- 1
Assets/Scripts/GameMode/GameMode.cs View File

@ -117,7 +117,7 @@ public abstract class GameMode : ScriptableObject
for (int i = 0; i < allPlayers.Length; i++)
{
allPlayers[i].client.SceneScore = 0;
allPlayers[i].client.Lives = 3;
}
OnGameStart(allPlayers);
GameStartEvent?.Invoke();

+ 2
- 1
Assets/Scripts/Managers/GameManager.cs View File

@ -84,6 +84,7 @@ public class GameManager : MonoBehaviour
//Spawn Characters and tell let the GameMode do anything with the characters it might want
SpawnCharacters();
playerDataAsArray.ForEach(p => p.client.SendLives());
gameMode.GameStart(playerDataAsArray);
//Loop until the GameMode lets us know the game is over
@ -119,7 +120,7 @@ public class GameManager : MonoBehaviour
//Let Gamemode know all players have moved
gameMode.AllPlayersMoved(playerDataAsArray.ToArray());
playerDataAsArray.ForEach(p => p.client.SendScore()); //Update the players score
playerDataAsArray.ForEach(p => p.client.SendLives()); //Update the players score
//if Game is over break out of loop
if (gameMode.isGameOver(playerDataAsArray))

+ 15
- 6
Assets/Scripts/Networking/Client/ClientObject.cs View File

@ -49,19 +49,21 @@ namespace Networking.Client
[Tooltip("Current Score in Round")]
public float RoundScore;
[SerializeField]
[Tooltip("Remaining Lives")]
public float RemainingLives;
[SerializeField]
[Tooltip("A list of all connected clients")]
public ConnectedClients ConnectedClients;
#endregion Inspector Fields
#region ReadOnly Variables
public NetworkClient client { get; private set; }
public bool isConnected { get { return client != null && client.isConnected; } }
#endregion ReadOnly Variables
public void Connect(string serverAddress,int port)
{
Debug.Log("Connecting to server: " + serverAddress + ", " + port);
@ -81,6 +83,7 @@ namespace Networking.Client
client.RegisterHandler(MsgType.Disconnect, OnDisconnect);
client.RegisterHandler(LogicProtocols.SendRoundTime, UpdateTime);
client.RegisterHandler(LogicProtocols.SendScore, UpdateScore);
client.RegisterHandler(LogicProtocols.SendLives, UpdateLives);
}
public void Stop()
@ -97,7 +100,6 @@ namespace Networking.Client
this.PlayerColor = PlayerColor;
}
public void RecieveInventory(NetworkMessage msg)
{
Debug.Log("Recieving Inventory");
@ -132,8 +134,7 @@ namespace Networking.Client
if (!msg.TryRead(out floatMsg))
return;
RoundTime = floatMsg.Float;
RoundTime = floatMsg.Float;
}
public void UpdateScore(NetworkMessage msg)
@ -144,6 +145,14 @@ namespace Networking.Client
RoundScore = floatMsg.Float;
}
}
public void UpdateLives(NetworkMessage msg)
{
LogicProtocols.FloatMsg floatMsg;
if (!msg.TryRead(out floatMsg))
return;
RemainingLives = floatMsg.Float;
}
}
}

+ 2
- 5
Assets/Scripts/Networking/Core/Protocols/LogicProtocols.cs View File

@ -12,7 +12,8 @@ namespace Networking
public const short SendInventory = 201;
public const short SendRoundTime = 202;
public const short SendNotification = 203;
public const short SendScore = 204;
public const short SendScore = 205;
public const short SendLives = 204;
public class LogicMsg : MessageBase
@ -100,10 +101,6 @@ namespace Networking
bagItems[i].isInfinit = reader.ReadBoolean();
}
}
}
public class FloatMsg : MessageBase

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

@ -157,7 +157,7 @@ namespace Networking.Server
newClient.conn.Send(LoginProtocols.LoginSuccess, new LoginProtocols.LoginMsg(newClient.Name, newClient.Color, newClient.characterAnimal));
OnClientsChange.Invoke(ConnectedClients);
newClient.SendInventory();
newClient.SendScore();
newClient.SendLives();
newClient.ChangeScene("WaitScene");
@ -209,15 +209,15 @@ namespace Networking.Server
/// </summary>
public int Score;
/// <summary>
/// Clients character animal - needed for instantiation
/// </summary>
public string characterAnimal = "Bear";
/// <summary>
/// Clients Current Lives
/// </summary>
public int Lives;
/// <summary>
/// Clients number of collected items - for colelction level
/// Clients character animal - needed for instantiation
/// </summary>
public int SceneScore = 0;
public string characterAnimal = "Bear";
/// <summary>
/// Network connection ID
@ -242,9 +242,9 @@ namespace Networking.Server
conn.SendByChannel(LogicProtocols.SendInventory, new LogicProtocols.InventoryMsg(Inventory), TransportConfigure.ReliableFragmented);
}
public void SendScore()
public void SendLives()
{
conn.Send(LogicProtocols.SendScore, new LogicProtocols.FloatMsg(SceneScore));
conn.Send(LogicProtocols.SendLives, new LogicProtocols.FloatMsg(Lives));
}
public void ChangeScene(string scene, bool Additive = false)

+ 2
- 2
Assets/Scripts/PortalSetup.cs View File

@ -51,10 +51,10 @@ public class PortalSetup : MonoBehaviour
void Update()
{
if (!collectedFive && (ConnectedClients[0].SceneScore >= collectAmount || ConnectedClients[1].SceneScore >= collectAmount || ConnectedClients[2].SceneScore >= collectAmount || ConnectedClients[3].SceneScore >= collectAmount)){
/*if (!collectedFive && (ConnectedClients[0].SceneScore >= collectAmount || ConnectedClients[1].SceneScore >= collectAmount || ConnectedClients[2].SceneScore >= collectAmount || ConnectedClients[3].SceneScore >= collectAmount)){
collectedFive = true;
StartCoroutine (ColorChange ());
}
}*/
}
private void Awake ()

+ 2
- 2
Assets/Scripts/UI/LeadPlayerUI.cs View File

@ -35,8 +35,8 @@ public class LeadPlayerUI : MonoBehaviour
ColorImage.gameObject.SetActive(true);
}
ClientData lead = Clients.maxBy(p => p.SceneScore);
ScoreText.text = lead.SceneScore.ToString();
ClientData lead = Clients.maxBy(p => p.Lives);
ScoreText.text = lead.Lives.ToString();
ColorImage.color = lead.Color;
}

+ 2
- 8
Assets/Scripts/UI/NetworkedUIManager.cs View File

@ -14,7 +14,7 @@ public class NetworkedUIManager : PlayerUIManager
[SerializeField]
private RectTransform Title;
[SerializeField]
private TMPro.TextMeshProUGUI ScoreText;
private TMPro.TextMeshProUGUI LivesText;
[Header("Debug")]
[SerializeField]
@ -31,12 +31,10 @@ public class NetworkedUIManager : PlayerUIManager
TrayUI.SetBlockReader(reader);
StartTime = Time.time;
ShowPosition.y -= Title.rect.height;
ScoreText.text = "Score: " + Client.RoundScore;
LivesText.text = "Lives: " + Client.RemainingLives;
OnClick_Show();
}
private void Update()
{
if (!isTimePaused)
@ -67,8 +65,4 @@ public class NetworkedUIManager : PlayerUIManager
else
TimeText.color = Color.black;
}
}

+ 4
- 4
Assets/Scripts/blockSpawn.cs View File

@ -37,14 +37,14 @@ public class blockSpawn : MonoBehaviour
private void getPlayerScores()
{
ConnectedClients.Sort((b, a) => a.SceneScore.CompareTo(b.SceneScore));
ConnectedClients.Sort((b, a) => a.Lives.CompareTo(b.Lives));
int totalScores = 0;
scoreDifference = ConnectedClients[0].SceneScore + ConnectedClients[ConnectedClients.Count-1].SceneScore;
scoreDifference = ConnectedClients[0].Lives + ConnectedClients[ConnectedClients.Count-1].Lives;
//Debug.Log("score difference " + scoreDifference);
for(int i = 0; i < ConnectedClients.Count; i++)
{
totalScores += ConnectedClients[i].SceneScore;
totalScores += ConnectedClients[i].Lives;
}
average = totalScores / ConnectedClients.Count;
//Debug.Log("score average " + average);
@ -140,7 +140,7 @@ public class blockSpawn : MonoBehaviour
float[] difAvg = new float[clients.Length];
for (int i = 0; i < clients.Length; i++)
{
difAvg[i] = clients[i].SceneScore - average;
difAvg[i] = clients[i].Lives - average;
}
float[] ratio = new float[clients.Length];

+ 0
- 27
Assets/Scripts/portalTesting.cs View File

@ -18,33 +18,6 @@ public class portalTesting : MonoBehaviour
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.A)){
ConnectedClients[0].SceneScore++;
if(ConnectedClients[0].SceneScore >= 5){
ps.validIndex.Add(0);
}
}
if(Input.GetKeyDown(KeyCode.B)){
ConnectedClients[1].SceneScore++;
if(ConnectedClients[1].SceneScore >= 5){
ps.validIndex.Add(1);
}
}
if(Input.GetKeyDown(KeyCode.C)){
ConnectedClients[2].SceneScore++;
if(ConnectedClients[2].SceneScore >= 5){
ps.validIndex.Add(2);
}
}
if(Input.GetKeyDown(KeyCode.D)){
ConnectedClients[3].SceneScore++;
if(ConnectedClients[3].SceneScore >= 5){
ps.validIndex.Add(3);
}
}
}

Loading…
Cancel
Save