Browse Source

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!)
master
ClairePeta 4 years ago
parent
commit
e52227703c
27 changed files with 112 additions and 171 deletions
  1. +1
    -1
      Assets/Data/Inventory/BaseInventory.asset
  2. +3
    -0
      Assets/Data/Logic Blocks/Diagonal L.asset
  3. +0
    -0
      Assets/Data/Logic Blocks/Diagonal L.asset.meta
  4. +0
    -3
      Assets/Data/Logic Blocks/Diagonal Left.asset
  5. +3
    -0
      Assets/Data/Logic Blocks/Diagonal R.asset
  6. +0
    -0
      Assets/Data/Logic Blocks/Diagonal R.asset.meta
  7. +0
    -3
      Assets/Data/Logic Blocks/Diagonal Right.asset
  8. +0
    -3
      Assets/Data/Logic Blocks/For x2.asset
  9. +0
    -3
      Assets/Data/Logic Blocks/For x3.asset
  10. +0
    -8
      Assets/Data/Logic Blocks/For x3.asset.meta
  11. +3
    -0
      Assets/Data/Logic Blocks/Rotate L.asset
  12. +0
    -0
      Assets/Data/Logic Blocks/Rotate L.asset.meta
  13. +0
    -3
      Assets/Data/Logic Blocks/Rotate Left.asset
  14. +3
    -0
      Assets/Data/Logic Blocks/Rotate R.asset
  15. +1
    -1
      Assets/Data/Logic Blocks/Rotate R.asset.meta
  16. +0
    -3
      Assets/Data/Logic Blocks/Rotate Right.asset
  17. +0
    -8
      Assets/Data/Logic Blocks/Rotate Right.asset.meta
  18. +32
    -0
      Assets/Prefabs/GameManager.prefab
  19. +1
    -1
      Assets/Prefabs/Traps/InGroundTrap.prefab
  20. +2
    -2
      Assets/Scenes/Menus/Lobby.unity
  21. +1
    -1
      Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs
  22. +1
    -1
      Assets/Scripts/LevelBlocks/Water.cs
  23. +10
    -2
      Assets/Scripts/Managers/GameManager.cs
  24. +1
    -1
      Assets/Scripts/Networking/Server/ServerObject.cs
  25. +1
    -1
      Assets/Scripts/Traps/ConveyorBelt.cs
  26. +1
    -1
      Assets/Scripts/UI/Lobby/LobbyUIController.cs
  27. +48
    -125
      Assets/Scripts/blockSpawn.cs

+ 1
- 1
Assets/Data/Inventory/BaseInventory.asset View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:fb7987d63a59b05fb303834051f410599c5ebebb77dd2c8047b930403e9aac3f
oid sha256:ffe4ea933ab9da92364324d81c2749faee272a1748758219ee2fa21b503e5044
size 1059

+ 3
- 0
Assets/Data/Logic Blocks/Diagonal L.asset View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8ab0be1c04b5733f302cf6294b114f646c748d72a57b95620f0e4476e557d576
size 871

Assets/Data/Logic Blocks/Diagonal Left.asset.meta → Assets/Data/Logic Blocks/Diagonal L.asset.meta View File


+ 0
- 3
Assets/Data/Logic Blocks/Diagonal Left.asset View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7f00c98133cb05b40b3c72c41c5452d27952c118a795de5260f8dcad6fff2bd3
size 874

+ 3
- 0
Assets/Data/Logic Blocks/Diagonal R.asset View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:648c6ffd9ee4e98f5e736340c5636353e3f8329bf8f5663f785aa8124ed741a9
size 871

Assets/Data/Logic Blocks/Diagonal Right.asset.meta → Assets/Data/Logic Blocks/Diagonal R.asset.meta View File


+ 0
- 3
Assets/Data/Logic Blocks/Diagonal Right.asset View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:237c1f27581952747a883ad421b895ac34a794eff2abb2749fb2c4ff4052bb2a
size 875

+ 0
- 3
Assets/Data/Logic Blocks/For x2.asset View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:393d8fb1306335f183f74173908fb0c1e76fe2bf1979a837f371a508947102a1
size 550

+ 0
- 3
Assets/Data/Logic Blocks/For x3.asset View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9582bbfac99debbc49e0a67fd4d9ca5252d6c8311d8348724aac41f13a7ba5ea
size 572

+ 0
- 8
Assets/Data/Logic Blocks/For x3.asset.meta View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 57d435792b9c3504caa273c796738050
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

+ 3
- 0
Assets/Data/Logic Blocks/Rotate L.asset View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f51e51a8146405e8694589cab181e716a7163fc9b631e1735bf212abb5aed33a
size 630

Assets/Data/Logic Blocks/Rotate Left.asset.meta → Assets/Data/Logic Blocks/Rotate L.asset.meta View File


+ 0
- 3
Assets/Data/Logic Blocks/Rotate Left.asset View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d41baba051e9b3fd2296d98130f13fcd6ca009d75159fb344e3c081b2a1f35eb
size 651

+ 3
- 0
Assets/Data/Logic Blocks/Rotate R.asset View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d4dc2709949a4748e68da5170dd7c30cfd67987f109ad28214561d6eddc46dd1
size 631

Assets/Data/Logic Blocks/For x2.asset.meta → Assets/Data/Logic Blocks/Rotate R.asset.meta View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: e11629d4fbb1e8246b7d4f003800bfa0
guid: 41f4cb946475b2849a802a8297d81e25
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

+ 0
- 3
Assets/Data/Logic Blocks/Rotate Right.asset View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2b32afa87515fe3c4e3257ab206e53acc8d6233357467015b73535f27b56e2d3
size 652

+ 0
- 8
Assets/Data/Logic Blocks/Rotate Right.asset.meta View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: dbe27449ec71f3e4e8d5d6ada80b1799
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

+ 32
- 0
Assets/Prefabs/GameManager.prefab View File

@ -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}

+ 1
- 1
Assets/Prefabs/Traps/InGroundTrap.prefab View File

@ -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

+ 2
- 2
Assets/Scenes/Menus/Lobby.unity View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:645eb7de71edda6ae053639cdb1fe76431b0b94a13287c4e7e2ff250c83313d5
size 46629
oid sha256:6f20ea3050a82f28cd55b2c1ff133057d302ec2ecec14f3f0b59477598461b08
size 45816

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

@ -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)

+ 1
- 1
Assets/Scripts/LevelBlocks/Water.cs View File

@ -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)
{

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

@ -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<blockSpawn>();
//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<ActiveBlock>();
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;

+ 1
- 1
Assets/Scripts/Networking/Server/ServerObject.cs View File

@ -34,7 +34,7 @@ namespace Networking.Server {
{
LoginHandler.ConnectedClients = new List<ClientData>();
LoginHandler.DisconnectedClients = new List<ClientData>();
Debug.Log("Starting Server on " + port);
//Debug.Log("Starting Server on " + port);
server = new NetworkServerSimple();
server.useWebSockets = useWebSockets;

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

@ -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));
}

+ 1
- 1
Assets/Scripts/UI/Lobby/LobbyUIController.cs View File

@ -42,7 +42,7 @@ public class LobbyUIController : MonoBehaviour
private void DisplayClients(List<ClientData> data)
{
Debug.Log("Updating Connected Clients");
//Debug.Log("Updating Connected Clients");
foreach (Transform child in Content)
if (child.gameObject != ClientTag)
Destroy(child.gameObject);

+ 48
- 125
Assets/Scripts/blockSpawn.cs View File

@ -7,47 +7,68 @@ public class blockSpawn : MonoBehaviour
{
[SerializeField]
public Inventory.Data[] spawnLogicList;
public List<ClientData> ConnectedClients;
List<ClientData> ConnectedClients;
public ClientList clientDataList;
public Block[] SpawnBlocks;
public List<Vector3> spawnedLocations;
int scoreDifference = 0;
float average = 0;
List<Vector3> spawnedLocations;
int min_z = -2, max_z = 2;
Vector3 spawnposition = new Vector3(0, 0, 0);
void Awake()
{
ConnectedClients = clientDataList.ConnectedClients;
SpawnBlocks = FindObjectsOfType<Block>().Where(p => p.is_Walkable).ToArray();
ConnectedClients = clientDataList.ConnectedClients;
spawnedLocations = new List<Vector3>();
}
public void wakeup()
{
SpawnBlocks = FindObjectsOfType<Block>().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<ClientData> lessClients = new List<ClientData>(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<LogicCollectable_Multiplayer>().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));
}
}
}

Loading…
Cancel
Save