|
@ -40,14 +40,14 @@ public class blockSpawn : MonoBehaviour |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
min_x = (int)ConnectedClients[ConnectedClients.Count - 1].playerCharacter.transform.position.x; |
|
|
min_x = (int)ConnectedClients[ConnectedClients.Count - 1].playerCharacter.transform.position.x; |
|
|
max_x = (int)ConnectedClients[0].playerCharacter.transform.position.x +3; |
|
|
|
|
|
|
|
|
max_x = (int)ConnectedClients[0].playerCharacter.transform.position.x + 4; |
|
|
|
|
|
|
|
|
Debug.Log("count before update " + SpawnBlocks.Count); |
|
|
Debug.Log("count before update " + SpawnBlocks.Count); |
|
|
updatePositions(min_x - 1); |
|
|
|
|
|
updatePlayerPositions(); |
|
|
updatePlayerPositions(); |
|
|
|
|
|
Debug.Log("count mid update " + SpawnBlocks.Count); |
|
|
|
|
|
updatePositions(min_x - 1); |
|
|
Debug.Log("count after update " + SpawnBlocks.Count); |
|
|
Debug.Log("count after update " + SpawnBlocks.Count); |
|
|
|
|
|
|
|
|
Debug.Log("adding possible spawn locations"); |
|
|
|
|
|
//Check points within the bounds of players
|
|
|
//Check points within the bounds of players
|
|
|
possibleSpawnLocations.Clear(); |
|
|
possibleSpawnLocations.Clear(); |
|
|
foreach (Block point in SpawnBlocks) |
|
|
foreach (Block point in SpawnBlocks) |
|
@ -61,7 +61,7 @@ public class blockSpawn : MonoBehaviour |
|
|
|
|
|
|
|
|
//pick a random value from those available, checks the location
|
|
|
//pick a random value from those available, checks the location
|
|
|
//then removes it to remove the possibility of duplicates
|
|
|
//then removes it to remove the possibility of duplicates
|
|
|
Debug.Log("count after add " + possibleSpawnLocations.Count); |
|
|
|
|
|
|
|
|
Debug.Log("possibleSpawnLocations count " + possibleSpawnLocations.Count); |
|
|
|
|
|
|
|
|
int triesCount = 0; |
|
|
int triesCount = 0; |
|
|
|
|
|
|
|
@ -71,9 +71,7 @@ public class blockSpawn : MonoBehaviour |
|
|
{ |
|
|
{ |
|
|
if(possibleSpawnLocations.Count > 0){ |
|
|
if(possibleSpawnLocations.Count > 0){ |
|
|
int choice = Random.Range(0, possibleSpawnLocations.Count - 1); |
|
|
int choice = Random.Range(0, possibleSpawnLocations.Count - 1); |
|
|
Debug.Log("count inside " + possibleSpawnLocations.Count); |
|
|
|
|
|
bool spawned = checkLocation(possibleSpawnLocations[choice].transform.position); |
|
|
bool spawned = checkLocation(possibleSpawnLocations[choice].transform.position); |
|
|
Debug.Log("bool spawned = " + spawned); |
|
|
|
|
|
if (spawned == true) |
|
|
if (spawned == true) |
|
|
{ |
|
|
{ |
|
|
possibleSpawnLocations.RemoveAt(choice); |
|
|
possibleSpawnLocations.RemoveAt(choice); |
|
@ -86,12 +84,11 @@ public class blockSpawn : MonoBehaviour |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
Debug.Log("spawn else"); |
|
|
|
|
|
goto escape; |
|
|
goto escape; |
|
|
} |
|
|
} |
|
|
Debug.Log("spawnNumber " + spawnNumber); |
|
|
|
|
|
|
|
|
//Debug.Log("spawnNumber " + spawnNumber);
|
|
|
} |
|
|
} |
|
|
Debug.Log("SpawnTries: " + triesCount); |
|
|
|
|
|
|
|
|
//Debug.Log("SpawnTries: " + triesCount);
|
|
|
} |
|
|
} |
|
|
escape: |
|
|
escape: |
|
|
spawnNumber = 2; |
|
|
spawnNumber = 2; |
|
@ -99,24 +96,22 @@ public class blockSpawn : MonoBehaviour |
|
|
|
|
|
|
|
|
private bool checkLocation(Vector3 spawnposition) |
|
|
private bool checkLocation(Vector3 spawnposition) |
|
|
{ |
|
|
{ |
|
|
Debug.Log("Check location function"); |
|
|
|
|
|
bool duplicate = checkDuplicatePosition(spawnposition); |
|
|
bool duplicate = checkDuplicatePosition(spawnposition); |
|
|
if (duplicate == false) |
|
|
if (duplicate == false) |
|
|
{ |
|
|
{ |
|
|
spawnBlock(spawnposition); |
|
|
spawnBlock(spawnposition); |
|
|
Debug.Log("spawned at" + spawnposition); |
|
|
|
|
|
|
|
|
//Debug.Log("spawned at" + spawnposition);
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
Debug.Log("Fail to spawn at " + spawnposition); |
|
|
|
|
|
|
|
|
//Debug.Log("Fail to spawn at " + spawnposition);
|
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private bool checkDuplicatePosition(Vector3 spawnposition) |
|
|
private bool checkDuplicatePosition(Vector3 spawnposition) |
|
|
{ |
|
|
{ |
|
|
Debug.Log("Check duplicate function"); |
|
|
|
|
|
if (spawnedLocations.Count > 0) |
|
|
if (spawnedLocations.Count > 0) |
|
|
{ |
|
|
{ |
|
|
for (int k = 0; k < spawnedLocations.Count; k++) |
|
|
for (int k = 0; k < spawnedLocations.Count; k++) |
|
@ -163,12 +158,13 @@ public class blockSpawn : MonoBehaviour |
|
|
block.GetComponent<LogicCollectable_Multiplayer>().Collectable.Count = 1; |
|
|
block.GetComponent<LogicCollectable_Multiplayer>().Collectable.Count = 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void updatePositions(float max) |
|
|
|
|
|
|
|
|
public void updatePositions(int min) |
|
|
{ |
|
|
{ |
|
|
for(int i = SpawnBlocks.Count -1; i>=0; i--) |
|
|
for(int i = SpawnBlocks.Count -1; i>=0; i--) |
|
|
{ |
|
|
{ |
|
|
if(SpawnBlocks[i].transform.position.x <= (int)max) |
|
|
|
|
|
|
|
|
if(SpawnBlocks[i].transform.position.x <= min) |
|
|
{ |
|
|
{ |
|
|
|
|
|
Debug.Log("block to remove position x: " + SpawnBlocks[i].transform.position.x); |
|
|
SpawnBlocks.Remove(SpawnBlocks[i]); |
|
|
SpawnBlocks.Remove(SpawnBlocks[i]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|