JoshuaReason 5 years ago
parent
commit
19d90e38c5
2 changed files with 6973 additions and 3194 deletions
  1. +6912
    -3190
      Assets/Prefabs/Map Sections/Start 4-player.prefab
  2. +61
    -4
      Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs

+ 6912
- 3190
Assets/Prefabs/Map Sections/Start 4-player.prefab
File diff suppressed because it is too large
View File


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

@ -35,7 +35,7 @@ public class RacetrackGameMode : GameMode
/// </summary> /// </summary>
protected override void OnRoundEnd(PlayerData[] allPlayers) protected override void OnRoundEnd(PlayerData[] allPlayers)
{ {
cameraCheck();
cameraCheck(allPlayers);
//At the end of each round, any stuck players are freed to resume moving next round //At the end of each round, any stuck players are freed to resume moving next round
foreach (PlayerData player in allPlayers) foreach (PlayerData player in allPlayers)
@ -51,10 +51,67 @@ public class RacetrackGameMode : GameMode
RoundCount++; RoundCount++;
} }
void cameraCheck()
void cameraCheck(PlayerData[] allPlayers)
{ {
//Get the average x-position of all players
float xAvg = 0.0f;
int livePlayerCount = 0;
foreach (PlayerData player in allPlayers)
{
if (player.client.Lives > 0)
{
xAvg += player.character.transform.position.x;
livePlayerCount++;
}
}
xAvg = xAvg / livePlayerCount;
//Turn that position into a vector in viewport space
Vector3 xAvgPos = new Vector3(xAvg, 0.0f, 0.0f);
Vector3 xAvgVP = Camera.main.WorldToViewportPoint(xAvgPos);
//Debug.Log("xAvgPos = " + xAvgPos + ", xAvgVP = " + xAvgVP);
//We move the camera forward by at least one increment
//Keep doing it until the average x-position is roughly centred
do
{
Camera.main.transform.Translate(scrollSpeed, 0, 0, Space.World);
xAvgVP = Camera.main.WorldToViewportPoint(xAvgPos);
//Debug.Log("Camera = " + Camera.main.transform.position + ", xAvgVP = " + xAvgVP);
} while (xAvgVP.x > 0.5f || xAvgVP.y > 0.5f);
//If the foremost player is off the screen, scroll forward to catch up with them
//Find who's furthest ahead
PlayerData playerAhead = allPlayers[0];
foreach (PlayerData player in allPlayers)
{
if (player.client.Lives > 0 && player.character.transform.position.x > playerAhead.character.transform.position.x)
{
playerAhead = player;
}
}
//Turn their position to a viewport vector
Vector3 playerVP = Camera.main.WorldToViewportPoint(playerAhead.character.transform.position);
//If that position is not in view, advance until it is
while (playerVP.x > 1 || playerVP.y > 1)
{
Camera.main.transform.Translate(scrollSpeed, 0, 0, Space.World);
playerVP = Camera.main.WorldToViewportPoint(playerAhead.character.transform.position);
}/**/
//We check for track sections we need to add/remove
mapManager.checkTrack();
//Move the camera forward at a steady rate each round //Move the camera forward at a steady rate each round
if (scrollSpeed > 0.0f)
/*if (scrollSpeed > 0.0f)
{ {
Camera.main.transform.Translate(scrollSpeed, 0, 0, Space.World); Camera.main.transform.Translate(scrollSpeed, 0, 0, Space.World);
mapManager.checkTrack(); mapManager.checkTrack();
@ -68,7 +125,7 @@ public class RacetrackGameMode : GameMode
else else
{ {
//Debug.Log("Not scrolling"); //Debug.Log("Not scrolling");
}
}*/
} }

Loading…
Cancel
Save