Browse Source

Tested code that works for block spawning

also commented out some debug.log stuff
master
Claire Peta 5 years ago
parent
commit
941f5df196
5 changed files with 32 additions and 21 deletions
  1. +2
    -2
      Assets/Scenes/Levels/RaceTrack Beta.unity
  2. +4
    -2
      Assets/Scripts/Character.cs
  3. +2
    -2
      Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs
  4. +1
    -1
      Assets/Scripts/Networking/Server/ClientList.cs
  5. +23
    -14
      Assets/Scripts/blockSpawn.cs

+ 2
- 2
Assets/Scenes/Levels/RaceTrack Beta.unity View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:dd7c1363d42eae1aa8086b72ecf7e2ed28f926aaaaa1fd5562c12d6d1fcb5edd
size 33424
oid sha256:34f4ddc3b7c7bec2e062a4fc81494f4173b18acadb589f7ad805b4589ec939e7
size 35308

+ 4
- 2
Assets/Scripts/Character.cs View File

@ -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<blockSpawn>();
if (Inventory != null && CloneInventoryOnStart)
Inventory = Inventory.Clone(Inventory);
@ -305,7 +307,6 @@ public class Character : MonoBehaviour
void OnTriggerEnter(Collider other)
{
Collectable collectable = other.GetComponentInChildren<Collectable>();
blockSpawn spawn = GetComponent<blockSpawn>();
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);

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

@ -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<blockSpawn>().wakeup();
//Move the camera forward at a steady rate each round
/*if (scrollSpeed > 0.0f)

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

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

+ 23
- 14
Assets/Scripts/blockSpawn.cs View File

@ -13,9 +13,9 @@ public class blockSpawn : MonoBehaviour
List<ClientData> ConnectedClients;
public ClientList clientDataList;
public Block[] SpawnBlocks;
public List<Block> SpawnBlocks;
List<Vector3> spawnedLocations;
List<Block> possibleSpawnLocations;
public List<Block> possibleSpawnLocations;
int spawnNumber = 2;
void Awake()
@ -26,8 +26,8 @@ public class blockSpawn : MonoBehaviour
}
public void wakeup()
{
SpawnBlocks.ToList().Clear();
SpawnBlocks = FindObjectsOfType<Block>().Where(p => p.isCollectableSpawnable).ToArray();
SpawnBlocks.Clear();
SpawnBlocks = FindObjectsOfType<Block>().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<LogicCollectable_Multiplayer>().Collectable.element = listtoUse[number].element;
block.GetComponent<LogicCollectable_Multiplayer>().Collectable.Count = listtoUse[number].Count;
block.GetComponent<LogicCollectable_Multiplayer>().Collectable.Count = 1;
}
}

Loading…
Cancel
Save