From 941f5df196697b83bdf93bc2e99220af4e9b6d25 Mon Sep 17 00:00:00 2001 From: Claire Peta Date: Thu, 3 Oct 2019 16:20:01 +1000 Subject: [PATCH] Tested code that works for block spawning also commented out some debug.log stuff --- Assets/Scenes/Levels/RaceTrack Beta.unity | 4 +- Assets/Scripts/Character.cs | 6 ++- .../ColorGameMode/RacetrackGameMode.cs | 4 +- .../Scripts/Networking/Server/ClientList.cs | 2 +- Assets/Scripts/blockSpawn.cs | 37 ++++++++++++------- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/Assets/Scenes/Levels/RaceTrack Beta.unity b/Assets/Scenes/Levels/RaceTrack Beta.unity index 27bb9d1..fb6d2f0 100644 --- a/Assets/Scenes/Levels/RaceTrack Beta.unity +++ b/Assets/Scenes/Levels/RaceTrack Beta.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:dd7c1363d42eae1aa8086b72ecf7e2ed28f926aaaaa1fd5562c12d6d1fcb5edd -size 33424 +oid sha256:34f4ddc3b7c7bec2e062a4fc81494f4173b18acadb589f7ad805b4589ec939e7 +size 35308 diff --git a/Assets/Scripts/Character.cs b/Assets/Scripts/Character.cs index e351270..bf4735d 100644 --- a/Assets/Scripts/Character.cs +++ b/Assets/Scripts/Character.cs @@ -8,6 +8,7 @@ using Networking.Server; public class Character : MonoBehaviour { public enum Animation { Walk, Run, Jump, Sit, Attack, Hit } + public blockSpawn spawn; public string nextScene; Animator characterAnimator; @@ -58,6 +59,7 @@ public class Character : MonoBehaviour private void Start() { + spawn = GameObject.Find("GameManager").GetComponent(); if (Inventory != null && CloneInventoryOnStart) Inventory = Inventory.Clone(Inventory); @@ -305,7 +307,6 @@ public class Character : MonoBehaviour void OnTriggerEnter(Collider other) { Collectable collectable = other.GetComponentInChildren(); - blockSpawn spawn = GetComponent(); if (collectable != null) { @@ -323,7 +324,8 @@ public class Character : MonoBehaviour } average /= livePlayerCount; float tosend = lives + (transform.position.x - average); - + Debug.Log(transform.position.x + " - " + average + " =" + (transform.position.x - average)); + Debug.Log("Value to send: " + tosend); spawn.assignLogicBlock(collectable.gameObject, tosend); collectable.OnCollect(this); diff --git a/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs b/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs index 320b859..61fec17 100644 --- a/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs +++ b/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs @@ -10,7 +10,7 @@ using System.Linq; public class RacetrackGameMode : GameMode { public MapManager mapManager; - public blockSpawn spawn; + public GameObject spawn; public int MaxRound = 999; public string nextScene = "ServerTestScene"; @@ -110,7 +110,7 @@ public class RacetrackGameMode : GameMode //We check for track sections we need to add/remove mapManager.checkTrack(); - spawn.wakeup(); + spawn.GetComponent().wakeup(); //Move the camera forward at a steady rate each round /*if (scrollSpeed > 0.0f) diff --git a/Assets/Scripts/Networking/Server/ClientList.cs b/Assets/Scripts/Networking/Server/ClientList.cs index aec3080..0bc4efa 100644 --- a/Assets/Scripts/Networking/Server/ClientList.cs +++ b/Assets/Scripts/Networking/Server/ClientList.cs @@ -134,7 +134,7 @@ namespace Networking.Server } else { - Debug.Log("new Connection: " + loginMsg.Name); + //Debug.Log("new Connection: " + loginMsg.Name); newClient = new ClientData(); newClient.Inventory = Inventory.Clone(StartInventory); } diff --git a/Assets/Scripts/blockSpawn.cs b/Assets/Scripts/blockSpawn.cs index a5c0db7..4d72434 100644 --- a/Assets/Scripts/blockSpawn.cs +++ b/Assets/Scripts/blockSpawn.cs @@ -13,9 +13,9 @@ public class blockSpawn : MonoBehaviour List ConnectedClients; public ClientList clientDataList; - public Block[] SpawnBlocks; + public List SpawnBlocks; List spawnedLocations; - List possibleSpawnLocations; + public List possibleSpawnLocations; int spawnNumber = 2; void Awake() @@ -26,8 +26,8 @@ public class blockSpawn : MonoBehaviour } public void wakeup() { - SpawnBlocks.ToList().Clear(); - SpawnBlocks = FindObjectsOfType().Where(p => p.isCollectableSpawnable).ToArray(); + SpawnBlocks.Clear(); + SpawnBlocks = FindObjectsOfType().Where(p => p.isCollectableSpawnable).ToList(); } public void Spawn() @@ -36,13 +36,15 @@ public class blockSpawn : MonoBehaviour ConnectedClients.Sort((b, a) => a.playerCharacter.transform.position.x.CompareTo(b.playerCharacter.transform.position.x)); //add two to each to set bounds - int min_x = (int)ConnectedClients[ConnectedClients.Count - 1].playerCharacter.transform.position.x + 3; - int max_x = (int)ConnectedClients[0].playerCharacter.transform.position.x + 2; + int min_x = (int)ConnectedClients[ConnectedClients.Count - 1].playerCharacter.transform.position.x; + int max_x = (int)ConnectedClients[0].playerCharacter.transform.position.x +2; + //Debug.Log("Min x: " + min_x + " max x: " + max_x); //Check points within the bounds of players foreach(Block point in SpawnBlocks) { - if(point.transform.position.x > min_x && point.transform.position.x < max_x) + //Debug.Log("Position: " + point.transform.position.x + " and " + point.transform.position.z); + if(point.transform.position.x >= min_x && point.transform.position.x <= max_x) { possibleSpawnLocations.Add(point); } @@ -50,14 +52,21 @@ public class blockSpawn : MonoBehaviour //pick a random value from those available, checks the location //then removes it to remove the possibility of duplicates - while(spawnNumber > 0) + //Debug.Log(possibleSpawnLocations.Count); + if(possibleSpawnLocations.Count > 0) { - int choice = Random.Range(0, possibleSpawnLocations.Count - 1); - bool spawned = checkLocation(possibleSpawnLocations[choice].transform.position); - if (spawned == true) + while (spawnNumber > 0) { - possibleSpawnLocations.RemoveAt(choice); - spawnNumber--; + if(possibleSpawnLocations.Count > 0){ + int choice = Random.Range(0, possibleSpawnLocations.Count - 1); + bool spawned = checkLocation(possibleSpawnLocations[choice].transform.position); + if (spawned == true) + { + possibleSpawnLocations.RemoveAt(choice); + spawnNumber--; + } + } + } } spawnNumber = 2; @@ -123,6 +132,6 @@ public class blockSpawn : MonoBehaviour int number = Random.Range(0, listtoUse.Length-1); block.GetComponent().Collectable.element = listtoUse[number].element; - block.GetComponent().Collectable.Count = listtoUse[number].Count; + block.GetComponent().Collectable.Count = 1; } } \ No newline at end of file