From e52227703c6bd2d9ebddd22bc027b1ca153db1c8 Mon Sep 17 00:00:00 2001 From: ClairePeta Date: Wed, 18 Sep 2019 19:11:56 +1000 Subject: [PATCH] Toggled a whole bunch of debug.Logs because they were killing me and slowing the loading time for the game. Got blocks spawning based on the players locations Removed duplicate logic blocks(Correct colours are back!) --- Assets/Data/Inventory/BaseInventory.asset | 2 +- Assets/Data/Logic Blocks/Diagonal L.asset | 3 + ... Left.asset.meta => Diagonal L.asset.meta} | 0 Assets/Data/Logic Blocks/Diagonal Left.asset | 3 - Assets/Data/Logic Blocks/Diagonal R.asset | 3 + ...Right.asset.meta => Diagonal R.asset.meta} | 0 Assets/Data/Logic Blocks/Diagonal Right.asset | 3 - Assets/Data/Logic Blocks/For x2.asset | 3 - Assets/Data/Logic Blocks/For x3.asset | 3 - Assets/Data/Logic Blocks/For x3.asset.meta | 8 - Assets/Data/Logic Blocks/Rotate L.asset | 3 + ...te Left.asset.meta => Rotate L.asset.meta} | 0 Assets/Data/Logic Blocks/Rotate Left.asset | 3 - Assets/Data/Logic Blocks/Rotate R.asset | 3 + ...{For x2.asset.meta => Rotate R.asset.meta} | 2 +- Assets/Data/Logic Blocks/Rotate Right.asset | 3 - .../Data/Logic Blocks/Rotate Right.asset.meta | 8 - Assets/Prefabs/GameManager.prefab | 32 ++++ Assets/Prefabs/Traps/InGroundTrap.prefab | 2 +- Assets/Scenes/Menus/Lobby.unity | 4 +- .../ColorGameMode/RacetrackGameMode.cs | 2 +- Assets/Scripts/LevelBlocks/Water.cs | 2 +- Assets/Scripts/Managers/GameManager.cs | 12 +- .../Scripts/Networking/Server/ServerObject.cs | 2 +- Assets/Scripts/Traps/ConveyorBelt.cs | 2 +- Assets/Scripts/UI/Lobby/LobbyUIController.cs | 2 +- Assets/Scripts/blockSpawn.cs | 173 +++++------------- 27 files changed, 112 insertions(+), 171 deletions(-) create mode 100644 Assets/Data/Logic Blocks/Diagonal L.asset rename Assets/Data/Logic Blocks/{Diagonal Left.asset.meta => Diagonal L.asset.meta} (100%) delete mode 100644 Assets/Data/Logic Blocks/Diagonal Left.asset create mode 100644 Assets/Data/Logic Blocks/Diagonal R.asset rename Assets/Data/Logic Blocks/{Diagonal Right.asset.meta => Diagonal R.asset.meta} (100%) delete mode 100644 Assets/Data/Logic Blocks/Diagonal Right.asset delete mode 100644 Assets/Data/Logic Blocks/For x2.asset delete mode 100644 Assets/Data/Logic Blocks/For x3.asset delete mode 100644 Assets/Data/Logic Blocks/For x3.asset.meta create mode 100644 Assets/Data/Logic Blocks/Rotate L.asset rename Assets/Data/Logic Blocks/{Rotate Left.asset.meta => Rotate L.asset.meta} (100%) delete mode 100644 Assets/Data/Logic Blocks/Rotate Left.asset create mode 100644 Assets/Data/Logic Blocks/Rotate R.asset rename Assets/Data/Logic Blocks/{For x2.asset.meta => Rotate R.asset.meta} (79%) delete mode 100644 Assets/Data/Logic Blocks/Rotate Right.asset delete mode 100644 Assets/Data/Logic Blocks/Rotate Right.asset.meta diff --git a/Assets/Data/Inventory/BaseInventory.asset b/Assets/Data/Inventory/BaseInventory.asset index 4b215e8..ff3f79a 100644 --- a/Assets/Data/Inventory/BaseInventory.asset +++ b/Assets/Data/Inventory/BaseInventory.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fb7987d63a59b05fb303834051f410599c5ebebb77dd2c8047b930403e9aac3f +oid sha256:ffe4ea933ab9da92364324d81c2749faee272a1748758219ee2fa21b503e5044 size 1059 diff --git a/Assets/Data/Logic Blocks/Diagonal L.asset b/Assets/Data/Logic Blocks/Diagonal L.asset new file mode 100644 index 0000000..50d7cf6 --- /dev/null +++ b/Assets/Data/Logic Blocks/Diagonal L.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8ab0be1c04b5733f302cf6294b114f646c748d72a57b95620f0e4476e557d576 +size 871 diff --git a/Assets/Data/Logic Blocks/Diagonal Left.asset.meta b/Assets/Data/Logic Blocks/Diagonal L.asset.meta similarity index 100% rename from Assets/Data/Logic Blocks/Diagonal Left.asset.meta rename to Assets/Data/Logic Blocks/Diagonal L.asset.meta diff --git a/Assets/Data/Logic Blocks/Diagonal Left.asset b/Assets/Data/Logic Blocks/Diagonal Left.asset deleted file mode 100644 index 94503b7..0000000 --- a/Assets/Data/Logic Blocks/Diagonal Left.asset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:7f00c98133cb05b40b3c72c41c5452d27952c118a795de5260f8dcad6fff2bd3 -size 874 diff --git a/Assets/Data/Logic Blocks/Diagonal R.asset b/Assets/Data/Logic Blocks/Diagonal R.asset new file mode 100644 index 0000000..791b11a --- /dev/null +++ b/Assets/Data/Logic Blocks/Diagonal R.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:648c6ffd9ee4e98f5e736340c5636353e3f8329bf8f5663f785aa8124ed741a9 +size 871 diff --git a/Assets/Data/Logic Blocks/Diagonal Right.asset.meta b/Assets/Data/Logic Blocks/Diagonal R.asset.meta similarity index 100% rename from Assets/Data/Logic Blocks/Diagonal Right.asset.meta rename to Assets/Data/Logic Blocks/Diagonal R.asset.meta diff --git a/Assets/Data/Logic Blocks/Diagonal Right.asset b/Assets/Data/Logic Blocks/Diagonal Right.asset deleted file mode 100644 index 32da4b5..0000000 --- a/Assets/Data/Logic Blocks/Diagonal Right.asset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:237c1f27581952747a883ad421b895ac34a794eff2abb2749fb2c4ff4052bb2a -size 875 diff --git a/Assets/Data/Logic Blocks/For x2.asset b/Assets/Data/Logic Blocks/For x2.asset deleted file mode 100644 index 161bba8..0000000 --- a/Assets/Data/Logic Blocks/For x2.asset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:393d8fb1306335f183f74173908fb0c1e76fe2bf1979a837f371a508947102a1 -size 550 diff --git a/Assets/Data/Logic Blocks/For x3.asset b/Assets/Data/Logic Blocks/For x3.asset deleted file mode 100644 index 46c400d..0000000 --- a/Assets/Data/Logic Blocks/For x3.asset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9582bbfac99debbc49e0a67fd4d9ca5252d6c8311d8348724aac41f13a7ba5ea -size 572 diff --git a/Assets/Data/Logic Blocks/For x3.asset.meta b/Assets/Data/Logic Blocks/For x3.asset.meta deleted file mode 100644 index 8c34b9c..0000000 --- a/Assets/Data/Logic Blocks/For x3.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 57d435792b9c3504caa273c796738050 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Data/Logic Blocks/Rotate L.asset b/Assets/Data/Logic Blocks/Rotate L.asset new file mode 100644 index 0000000..63abac7 --- /dev/null +++ b/Assets/Data/Logic Blocks/Rotate L.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f51e51a8146405e8694589cab181e716a7163fc9b631e1735bf212abb5aed33a +size 630 diff --git a/Assets/Data/Logic Blocks/Rotate Left.asset.meta b/Assets/Data/Logic Blocks/Rotate L.asset.meta similarity index 100% rename from Assets/Data/Logic Blocks/Rotate Left.asset.meta rename to Assets/Data/Logic Blocks/Rotate L.asset.meta diff --git a/Assets/Data/Logic Blocks/Rotate Left.asset b/Assets/Data/Logic Blocks/Rotate Left.asset deleted file mode 100644 index e114718..0000000 --- a/Assets/Data/Logic Blocks/Rotate Left.asset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d41baba051e9b3fd2296d98130f13fcd6ca009d75159fb344e3c081b2a1f35eb -size 651 diff --git a/Assets/Data/Logic Blocks/Rotate R.asset b/Assets/Data/Logic Blocks/Rotate R.asset new file mode 100644 index 0000000..5cbef59 --- /dev/null +++ b/Assets/Data/Logic Blocks/Rotate R.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4dc2709949a4748e68da5170dd7c30cfd67987f109ad28214561d6eddc46dd1 +size 631 diff --git a/Assets/Data/Logic Blocks/For x2.asset.meta b/Assets/Data/Logic Blocks/Rotate R.asset.meta similarity index 79% rename from Assets/Data/Logic Blocks/For x2.asset.meta rename to Assets/Data/Logic Blocks/Rotate R.asset.meta index 74ab781..69e6fa2 100644 --- a/Assets/Data/Logic Blocks/For x2.asset.meta +++ b/Assets/Data/Logic Blocks/Rotate R.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e11629d4fbb1e8246b7d4f003800bfa0 +guid: 41f4cb946475b2849a802a8297d81e25 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/Assets/Data/Logic Blocks/Rotate Right.asset b/Assets/Data/Logic Blocks/Rotate Right.asset deleted file mode 100644 index c2364a6..0000000 --- a/Assets/Data/Logic Blocks/Rotate Right.asset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:2b32afa87515fe3c4e3257ab206e53acc8d6233357467015b73535f27b56e2d3 -size 652 diff --git a/Assets/Data/Logic Blocks/Rotate Right.asset.meta b/Assets/Data/Logic Blocks/Rotate Right.asset.meta deleted file mode 100644 index 7396064..0000000 --- a/Assets/Data/Logic Blocks/Rotate Right.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: dbe27449ec71f3e4e8d5d6ada80b1799 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Prefabs/GameManager.prefab b/Assets/Prefabs/GameManager.prefab index 7b40c0f..9e1242a 100644 --- a/Assets/Prefabs/GameManager.prefab +++ b/Assets/Prefabs/GameManager.prefab @@ -10,6 +10,7 @@ GameObject: m_Component: - component: {fileID: 1698745550996942701} - component: {fileID: 1698745550996942698} + - component: {fileID: 3584776407301914954} m_Layer: 0 m_Name: GameManager m_TagString: Untagged @@ -49,3 +50,34 @@ MonoBehaviour: type: 3} server: {fileID: 11400000, guid: aba6c842adfc9904dba334cb48257361, type: 2} ClientList: {fileID: 11400000, guid: ded0b21c3ef1e7049a1128c12e9401fe, type: 2} + spawnBlock: {fileID: 3584776407301914954} +--- !u!114 &3584776407301914954 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1698745550996942700} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4bedcf540a02cd34886a443a80463285, type: 3} + m_Name: + m_EditorClassIdentifier: + spawnLogicList: + - element: {fileID: 11400000, guid: 752565cc5a95020498b9ed396343f3c0, type: 2} + Count: 1 + minCount: 0 + isInfinit: 0 + - element: {fileID: 11400000, guid: efab8a199b362cb42b3e0bce70dd05f4, type: 2} + Count: 1 + minCount: 0 + isInfinit: 0 + - element: {fileID: 11400000, guid: 8f19e10be0ee35345a97f600791a8747, type: 2} + Count: 1 + minCount: 0 + isInfinit: 0 + - element: {fileID: 11400000, guid: b5887451436a375419e538ef3706ecf9, type: 2} + Count: 1 + minCount: 0 + isInfinit: 0 + clientDataList: {fileID: 11400000, guid: ded0b21c3ef1e7049a1128c12e9401fe, type: 2} diff --git a/Assets/Prefabs/Traps/InGroundTrap.prefab b/Assets/Prefabs/Traps/InGroundTrap.prefab index 6927a08..89fa479 100644 --- a/Assets/Prefabs/Traps/InGroundTrap.prefab +++ b/Assets/Prefabs/Traps/InGroundTrap.prefab @@ -51,7 +51,7 @@ MonoBehaviour: VisualOffset: {x: 0, y: 0, z: 0} is_Walkable: 1 isWater: 0 - isPit: 0 + isPit: 1 isSpawnable: 0 SpawnDirection: 2 --- !u!1001 &61813983148133772 diff --git a/Assets/Scenes/Menus/Lobby.unity b/Assets/Scenes/Menus/Lobby.unity index a56465e..6b28543 100644 --- a/Assets/Scenes/Menus/Lobby.unity +++ b/Assets/Scenes/Menus/Lobby.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:645eb7de71edda6ae053639cdb1fe76431b0b94a13287c4e7e2ff250c83313d5 -size 46629 +oid sha256:6f20ea3050a82f28cd55b2c1ff133057d302ec2ecec14f3f0b59477598461b08 +size 45816 diff --git a/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs b/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs index 917ddeb..880c8b6 100644 --- a/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs +++ b/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs @@ -197,7 +197,7 @@ public class RacetrackGameMode : GameMode { character.stuck = true; } - Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck); + //Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck); } protected override void OnPlayerKilled(Character character, ClientData client) diff --git a/Assets/Scripts/LevelBlocks/Water.cs b/Assets/Scripts/LevelBlocks/Water.cs index de269a3..be15131 100644 --- a/Assets/Scripts/LevelBlocks/Water.cs +++ b/Assets/Scripts/LevelBlocks/Water.cs @@ -51,7 +51,7 @@ public class Water : ActiveBlock public override IEnumerator OnRoundEnd(PlayerData[] allPlayers) { - Debug.Log("reseting water"); + //Debug.Log("reseting water"); if (trappedCharacter != null) { diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs index 4d2c2ba..3cfc23a 100644 --- a/Assets/Scripts/Managers/GameManager.cs +++ b/Assets/Scripts/Managers/GameManager.cs @@ -29,6 +29,8 @@ public class GameManager : MonoBehaviour [SerializeField] private ClientList ClientList; + public blockSpawn spawnBlock; + #endregion Inspector Field #region Private Variables @@ -52,6 +54,7 @@ public class GameManager : MonoBehaviour private void Start() { + spawnBlock = gameObject.GetComponent(); //Start Game StartCoroutine(GameRoutine()); @@ -84,6 +87,9 @@ public class GameManager : MonoBehaviour //Allows game mode to instantiate anything it might need; gameMode.PreGameStart(); + //gets list of items to check spawn locations + spawnBlock.wakeup(); + //Spawn Characters and tell let the GameMode do anything with the characters it might want SpawnCharacters(); playerDataAsArray.ForEach(p => p.client.SendLives()); @@ -98,7 +104,7 @@ public class GameManager : MonoBehaviour //I hate having to do this EnvironmentBlocks = FindObjectsOfType(); - Debug.Log("Active blocks found: " + EnvironmentBlocks.Length); + //Debug.Log("Active blocks found: " + EnvironmentBlocks.Length); //Routine for players movement yield return StartCoroutine(RoundRoutine()); //it's pretty long so it gets it's own coroutine; @@ -167,6 +173,8 @@ public class GameManager : MonoBehaviour removePlayer(player); } } + //spawn collectible logic blocks + spawnBlock.Spawn(); //Reset some player Data @@ -246,7 +254,7 @@ public class GameManager : MonoBehaviour int blockIndex = 0; foreach (Block block in SpawnBlocks) { - Debug.Log("Block #" + blockIndex++ + " (" + block.transform.position.x + ", " + block.transform.position.y + ", " + block.transform.position.z + ")"); + //Debug.Log("Block #" + blockIndex++ + " (" + block.transform.position.x + ", " + block.transform.position.y + ", " + block.transform.position.z + ")"); } //int spawnIndex = 0; diff --git a/Assets/Scripts/Networking/Server/ServerObject.cs b/Assets/Scripts/Networking/Server/ServerObject.cs index 3c888ad..18f7d0e 100644 --- a/Assets/Scripts/Networking/Server/ServerObject.cs +++ b/Assets/Scripts/Networking/Server/ServerObject.cs @@ -34,7 +34,7 @@ namespace Networking.Server { { LoginHandler.ConnectedClients = new List(); LoginHandler.DisconnectedClients = new List(); - Debug.Log("Starting Server on " + port); + //Debug.Log("Starting Server on " + port); server = new NetworkServerSimple(); server.useWebSockets = useWebSockets; diff --git a/Assets/Scripts/Traps/ConveyorBelt.cs b/Assets/Scripts/Traps/ConveyorBelt.cs index db38840..8257d1a 100644 --- a/Assets/Scripts/Traps/ConveyorBelt.cs +++ b/Assets/Scripts/Traps/ConveyorBelt.cs @@ -20,7 +20,7 @@ public class ConveyorBelt : ActiveBlock { if (CurrentPlayer != null) { - Debug.Log("currentPlayer: " + CurrentPlayer); + //Debug.Log("currentPlayer: " + CurrentPlayer); yield return StartCoroutine(Action.Run(CurrentPlayer, 1,true)); } diff --git a/Assets/Scripts/UI/Lobby/LobbyUIController.cs b/Assets/Scripts/UI/Lobby/LobbyUIController.cs index 471fb67..2a5415d 100644 --- a/Assets/Scripts/UI/Lobby/LobbyUIController.cs +++ b/Assets/Scripts/UI/Lobby/LobbyUIController.cs @@ -42,7 +42,7 @@ public class LobbyUIController : MonoBehaviour private void DisplayClients(List data) { - Debug.Log("Updating Connected Clients"); + //Debug.Log("Updating Connected Clients"); foreach (Transform child in Content) if (child.gameObject != ClientTag) Destroy(child.gameObject); diff --git a/Assets/Scripts/blockSpawn.cs b/Assets/Scripts/blockSpawn.cs index 6556d01..abb5140 100644 --- a/Assets/Scripts/blockSpawn.cs +++ b/Assets/Scripts/blockSpawn.cs @@ -7,47 +7,68 @@ public class blockSpawn : MonoBehaviour { [SerializeField] public Inventory.Data[] spawnLogicList; - public List ConnectedClients; + List ConnectedClients; public ClientList clientDataList; public Block[] SpawnBlocks; - public List spawnedLocations; - int scoreDifference = 0; - float average = 0; + List spawnedLocations; + int min_z = -2, max_z = 2; + Vector3 spawnposition = new Vector3(0, 0, 0); void Awake() { - ConnectedClients = clientDataList.ConnectedClients; - SpawnBlocks = FindObjectsOfType().Where(p => p.is_Walkable).ToArray(); + ConnectedClients = clientDataList.ConnectedClients; spawnedLocations = new List(); } + public void wakeup() + { + SpawnBlocks = FindObjectsOfType().Where(p => p.is_Walkable).ToArray(); + } public void Spawn() { - getPlayerScores(); - getPlayerLocations(ConnectedClients.ToArray(), 0.75f); - - //second spawning block only if needed - /* if (scoreDifference > average) + /* + Get all player locations, get leader(biggest x position value) and min value + +2 to each value, set as min and man in random.range() + add locations to a list to ensure no duplicates + check not over pit or hole + */ + + ConnectedClients.Sort((b, a) => a.playerCharacter.transform.position.x.CompareTo(b.playerCharacter.transform.position.x)); + int min_x = (int)ConnectedClients[ConnectedClients.Count - 1].playerCharacter.transform.position.x + 2; + int max_x = (int)ConnectedClients[0].playerCharacter.transform.position.x + 2; + + for(int i = 0; i < 2; i++) { - List lessClients = new List(ConnectedClients); - lessClients.RemoveAt(lessClients.Count - 1); - getPlayerLocations(lessClients.ToArray(), 0.6f); - }*/ + spawnposition = new Vector3(Random.Range(min_x, max_x), -0.5f, Random.Range(min_z, max_z)); + checkLocation(spawnposition); + } + } - private void getPlayerScores() + private void checkLocation(Vector3 spawnposition) { - ConnectedClients.Sort((b, a) => a.Lives.CompareTo(b.Lives)); - int totalScores = 0; - scoreDifference = ConnectedClients[0].Lives + ConnectedClients[ConnectedClients.Count-1].Lives; - //Debug.Log("score difference " + scoreDifference); - - for(int i = 0; i < ConnectedClients.Count; i++) + bool duplicate = checkDuplicatePosition(spawnposition); + if (duplicate == false) + { + bool valid = checkValid(spawnposition); + if (valid == true) + { + spawnBlock(spawnposition); + } + else + { + //Block clostest = Utility.minBy(SpawnBlocks, p => Vector3.Distance(p.transform.position, spawnposition)); + //checkLocation(new Vector3(spawnposition.x, spawnposition.y + 1.5f, spawnposition.z)); + Debug.Log("Fail one"); + } + } + else { - totalScores += ConnectedClients[i].Lives; + //this needs to be changed + //Block clostest = Utility.minBy(SpawnBlocks, p => Vector3.Distance(p.transform.position, spawnposition)); + //checkLocation(new Vector3(spawnposition.x, spawnposition.y + 1.5f, spawnposition.z)); + Debug.Log("Fail two"); } - average = totalScores / ConnectedClients.Count; - //Debug.Log("score average " + average); } private bool checkDuplicatePosition(Vector3 spawnposition) @@ -67,6 +88,7 @@ public class blockSpawn : MonoBehaviour private bool checkValid(Vector3 spawnposition) { + //is over a walkable block for (int i = 0; i < SpawnBlocks.Length; i++) { if (SpawnBlocks[i].position.x == spawnposition.x && SpawnBlocks[i].position.z == spawnposition.z) @@ -81,6 +103,7 @@ public class blockSpawn : MonoBehaviour { GameObject prefab = Resources.Load("Logic Block") as GameObject; GameObject block = Instantiate(prefab); + spawnposition.y += 1.5f; int number = (int)Random.Range(1.0f, spawnLogicList.Length); block.GetComponent().Collectable.element = spawnLogicList[number].element; @@ -89,104 +112,4 @@ public class blockSpawn : MonoBehaviour Debug.Log("Instantiated new logic block: " + spawnLogicList[number].element + " at position: " + block.transform.position); spawnedLocations.Add(spawnposition); } - - private void checkLocation(Vector3 spawnposition) - { - bool duplicate = false; - if (duplicate == false) - { - bool valid = checkValid(spawnposition); - if (valid == true) - { - spawnBlock(spawnposition); - } - else - { - Block clostest = Utility.minBy(SpawnBlocks, p => Vector3.Distance(p.transform.position, spawnposition)); - checkLocation(new Vector3(clostest.position.x, clostest.position.y + 1.5f, clostest.position.z)); - } - } - else - { - //this needs to be changed - Block clostest = Utility.minBy(SpawnBlocks, p => Vector3.Distance(p.transform.position, spawnposition)); - checkLocation(new Vector3(clostest.position.x, clostest.position.y + 1.5f, clostest.position.z)); - } - } - - private void getPlayerLocations(ClientData[] clients, float weightMultiplier) - { - float[] weightings = new float[clients.Length]; - if(clients.Length > 1) - { - Vector3 spawnposition = new Vector3(0, 0, 0); - for (int i = 0; i < clients.Length; i++) - { - spawnposition += clients[i].playerCharacter.CurrentBlock.VisualPosition; - //Debug.Log("currentBlock.VisualPosition " + clients[i].playerCharacter.CurrentBlock.VisualPosition); - } - spawnposition *= (1.0f / clients.Length); - //Debug.Log("spawnposition " + spawnposition); - - Vector3[] direction = new Vector3[clients.Length]; - for (int i = 0; i < clients.Length; i++) - { - direction[i] = (spawnposition - clients[i].playerCharacter.CurrentBlock.VisualPosition); - - //Debug.Log("direction " + i + " " + direction[i]); - } - - //weighting calculations - float[] difAvg = new float[clients.Length]; - for (int i = 0; i < clients.Length; i++) - { - difAvg[i] = clients[i].Lives - average; - } - - float[] ratio = new float[clients.Length]; - - //Debug.Log("difAvg[0] " + difAvg[0]); - - if (difAvg[0] == 0) - { - for (int i = 0; i < clients.Length; i++) - { - weightings[i] = 0.5f * weightMultiplier; - //Debug.Log("weightings " + i + " " + weightings[i]); - } - } - else - { - for (int i = 0; i < clients.Length; i++) - { - ratio[i] = difAvg[i] / difAvg[0]; - ratio[i] /= 2.0f; - ratio[i] += 0.5f; - weightings[i] = ratio[i] * weightMultiplier; - weightings[i] = Mathf.Clamp(weightings[i], 0, 1); - //Debug.Log("weightings " + i + " " + weightings[i]); - } - } - - //multiply weightings by the direction - //take average point and add directions - for (int i = 0; i < clients.Length; i++) - { - spawnposition += (weightings[i] * direction[i]); - //Debug.Log("(weightings[i] * direction[i] " + (weightings[i] * direction[i])); - } - - spawnposition += Vector3.one * 0.5f; - //Debug.Log("spawnposition " + spawnposition); - //spawn first block - checkLocation(spawnposition); - } - else - { - Vector2 playerOne = new Vector2(clients[0].playerCharacter.CurrentBlock.VisualPosition.x, clients[0].playerCharacter.CurrentBlock.VisualPosition.z); - int xVal = (int)Random.Range(-3.0f, 3.0f) + (int)playerOne.x; - int zVal = (int)Random.Range(-3.0f, 3.0f) + (int)playerOne.y; - checkLocation(new Vector3(xVal, 1.0f, zVal)); - } - } } \ No newline at end of file