|
|
@ -85,9 +85,11 @@ public class RacetrackGameMode : GameMode |
|
|
|
//If there are any players left, it will be the average of their positions
|
|
|
|
//Otherwise, it will be as close to the centre of the screen as possible
|
|
|
|
Vector3 respawnLocation = new Vector3(0.0f, -0.5f, 0.0f); |
|
|
|
//Debug.Log("Initial respawn location: " + respawnLocation);
|
|
|
|
|
|
|
|
if (survivingPlayers.Count > 0) //If any players are not currently waiting to respawn, we get the average of their locations
|
|
|
|
{ |
|
|
|
//Debug.Log("Averaging survivor locations");
|
|
|
|
//We list the positions of all the surviving players
|
|
|
|
List<Vector3> survivingPlayerLocations = new List<Vector3>(); |
|
|
|
foreach (PlayerData player in survivingPlayers) |
|
|
@ -101,19 +103,23 @@ public class RacetrackGameMode : GameMode |
|
|
|
} |
|
|
|
|
|
|
|
respawnLocation = respawnLocation / survivingPlayers.Count; |
|
|
|
//Debug.Log("Averaged survivor locations, new respawn location: " + respawnLocation);
|
|
|
|
} |
|
|
|
else //Otherwise, we go for the middle of the screen
|
|
|
|
{ |
|
|
|
//Debug.Log("Seeking the middle of the screen");
|
|
|
|
//We start in the middle of the track, at the back, and scroll forward until we're past the centre of the camera's view
|
|
|
|
respawnLocation.x = mapManager.startX; |
|
|
|
|
|
|
|
Vector3 respawnLocationVP = Camera.main.WorldToViewportPoint(respawnLocation); |
|
|
|
|
|
|
|
while (respawnLocationVP.x > 0.5f || respawnLocationVP.y > 0.5f) |
|
|
|
while (respawnLocationVP.x < 0.5f || respawnLocationVP.y < 0.5f) |
|
|
|
{ |
|
|
|
respawnLocation.x += 1.0f; |
|
|
|
respawnLocationVP = Camera.main.WorldToViewportPoint(respawnLocation); |
|
|
|
//Debug.Log("respawnLocation = " + respawnLocation + ", viewport = " + respawnLocationVP);
|
|
|
|
} |
|
|
|
//Debug.Log("Found middle of camera view, new respawn location: " + respawnLocation);
|
|
|
|
} |
|
|
|
|
|
|
|
//Now we randomly pick blocks in the vicinity of this point to respawn players on
|
|
|
@ -127,31 +133,61 @@ public class RacetrackGameMode : GameMode |
|
|
|
respawnBlocks = new List<Block>(); |
|
|
|
radius++; |
|
|
|
|
|
|
|
//Debug.Log("Finding respawn blocks at radius = " + radius);
|
|
|
|
|
|
|
|
for (int i = -1 * radius; i <= radius; i++) |
|
|
|
{ |
|
|
|
for (int j = -1 * radius; j <= radius; j++) |
|
|
|
{ |
|
|
|
Block currentBlock; |
|
|
|
|
|
|
|
Vector3 currentPos = new Vector3(respawnLocation.x + i, respawnLocation.y, respawnLocation.z); |
|
|
|
Vector3 currentPos = new Vector3(respawnLocation.x + i, respawnLocation.y, respawnLocation.z + j); |
|
|
|
|
|
|
|
//Debug.Log("Checking position " + currentPos);
|
|
|
|
|
|
|
|
if (Block.isBlockAtPosition(currentPos, 1, ~Ignore, out currentBlock) //Does a block exist here?
|
|
|
|
&& currentBlock.is_Walkable //Are we allowed on this block?
|
|
|
|
&& !(currentBlock.isWater) && !(currentBlock.isPit) //Don't respawn on top of instant traps
|
|
|
|
if (Block.isBlockAtPosition(currentPos, 1, ~Ignore, out currentBlock)) |
|
|
|
{ |
|
|
|
/*Debug.Log("Found block at " + currentPos |
|
|
|
+ ". is_Walkable = " + currentBlock.is_Walkable |
|
|
|
+ ", currentBlock is Water = " + (currentBlock is Water) |
|
|
|
+ ", isPit = " + currentBlock.isPit |
|
|
|
+ ", no currentPlayer = " + (currentBlock.CurrentPlayer == null));*/ |
|
|
|
|
|
|
|
if (currentBlock.is_Walkable //Are we allowed on this block?
|
|
|
|
&& !(currentBlock is Water) && !(currentBlock.isPit) //Don't respawn on top of instant traps
|
|
|
|
&& currentBlock.CurrentPlayer == null) //Block must be unoccupied
|
|
|
|
{ |
|
|
|
respawnBlocks.Add(currentBlock); |
|
|
|
//Debug.Log("Added block at " + currentPos);
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
//Debug.Log("Block at " + currentPos + " invalid");
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
respawnBlocks.Add(currentBlock); |
|
|
|
//Debug.Log("No block at " + currentPos);
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} while (respawnBlocks.Count < respawningPlayers.Count); |
|
|
|
|
|
|
|
//Debug.Log("Possible respawn spots: ");
|
|
|
|
|
|
|
|
/*foreach(Block block in respawnBlocks) |
|
|
|
{ |
|
|
|
Debug.Log(block.transform.position); |
|
|
|
}*/ |
|
|
|
|
|
|
|
foreach (PlayerData player in respawningPlayers) |
|
|
|
{ |
|
|
|
//We randomly pick a block for them to respawn on
|
|
|
|
Block respawnBlock = respawnBlocks[(int)Random.Range(0.0f, (float)respawnBlocks.Count)]; |
|
|
|
Vector3 respawnLocationPlayer = respawnBlock.transform.position; |
|
|
|
player.character.respawnCharacter(respawnLocationPlayer); |
|
|
|
int respawnIndex = (int)Random.Range(0.0f, (float)respawnBlocks.Count); |
|
|
|
//Debug.Log("Respawn index = " + respawnIndex);
|
|
|
|
Block respawnBlock = respawnBlocks[respawnIndex]; |
|
|
|
//Debug.Log("Respawn location = " + respawnBlock.transform.position);
|
|
|
|
player.character.respawnCharacter(respawnBlock); |
|
|
|
|
|
|
|
respawnBlocks.Remove(respawnBlock); //Then we remove it from the list for the next player
|
|
|
|
} |
|
|
|