Browse Source

Started a fixed racetrack level with a starting pen, walls, water, and pits.

Josh_Dev_branch
s3607057 (Angus Niven) 5 years ago
parent
commit
8942ea8d9b
6 changed files with 88646 additions and 0 deletions
  1. +73854
    -0
      Assets/Scenes/RaceTrack 2.unity
  2. +7
    -0
      Assets/Scenes/RaceTrack 2.unity.meta
  3. +14578
    -0
      Assets/Scenes/RaceTrack.unity
  4. +7
    -0
      Assets/Scenes/RaceTrack.unity.meta
  5. +189
    -0
      Assets/Scripts/Managers/GameManagerRacetrack.cs
  6. +11
    -0
      Assets/Scripts/Managers/GameManagerRacetrack.cs.meta

+ 73854
- 0
Assets/Scenes/RaceTrack 2.unity
File diff suppressed because it is too large
View File


+ 7
- 0
Assets/Scenes/RaceTrack 2.unity.meta View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: df71f412b867a8d4e870f3ced4eb6dad
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 14578
- 0
Assets/Scenes/RaceTrack.unity
File diff suppressed because it is too large
View File


+ 7
- 0
Assets/Scenes/RaceTrack.unity.meta View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 75383443d04c6964ca178c64186f97cc
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 189
- 0
Assets/Scripts/Managers/GameManagerRacetrack.cs View File

@ -0,0 +1,189 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Networking;
using Networking.Server;
using Networking;
using UnityEngine.SceneManagement;
public class GameManagerRacetrack : MonoBehaviour
{
#region Inspector Field
[Header("Settings")]
[SerializeField]
private float AnimationTime;
[SerializeField]
private GameModeReference CurrentGameMode;
[Header("References")]
[SerializeField]
[Tooltip("Prefab of character for players to play")]
private Character characterPrefab;
[SerializeField]
private ServerObject server;
[SerializeField]
private ClientList ClientList;
#endregion Inspector Field
#region Private Variables
private Dictionary<int, PlayerData> playerData;
private GameMode gamemode;
#endregion Private Variables
#region Read Only
private IEnumerable<PlayerData> playerArray { get { return playerData.Values; } }
#endregion Read Only
public GameObject levelInfo;
public blockSpawn bspawn;
public void Awake()
{
gamemode = CurrentGameMode.Value;
RegisterHandlers();
SpawnCharacters();
ClientList.ForEach(p => p.ChangeScene("ClientScene"));
}
private void Start()
{
StartCoroutine(displayforSeconds(levelInfo, 5.0f));
gamemode.GameStart(playerArray.ToArray());
StartRound();
}
private void Update()
{
server.ServerUpdate();
}
IEnumerator displayforSeconds(GameObject display, float time)
{
display.SetActive (true);
yield return new WaitForSeconds(time);
display.SetActive (false);
}
private void RecieveLogicList(NetworkMessage msg)
{
LogicProtocols.LogicMsg logicMsg;
if (!msg.TryRead(out logicMsg))
return;
Debug.Log("Recieved function from " + msg.conn.connectionId);
playerData[msg.conn.connectionId].blockReader.LogicChain = new List<LogicBlock>(logicMsg.elements);
playerData[msg.conn.connectionId].recievedList = true;
if (playerData.All(p => p.Value.recievedList))
DoRoundRoutine();
}
private void DoRoundRoutine()
{
Debug.Log("Starting Round");
StartCoroutine(RoundRoutine());
}
private void StartRound()
{
gamemode.RoundStart(playerArray.ToArray());
LogicProtocols.FloatMsg RoundTime = new LogicProtocols.FloatMsg( gamemode.GetRoundTime());
bspawn.Spawn();
playerArray.ForEach(p => p.client.conn.Send(LogicProtocols.SendRoundTime, RoundTime));
}
private IEnumerator RoundRoutine()
{
playerArray.ForEach(p => p.recievedList = false);
//Debug.Log("Doing Round Routine");
while (playerArray.Any(p => !p.blockReader.Finished))
{
//Debug.Log("One Move");
foreach (PlayerData player in playerArray)
StartCoroutine(RunOnce(player));
//wait until all players have finished
yield return new WaitUntil(() => playerArray.All(p => p.waiting));
gamemode.FinishedMove(playerArray.ToArray());
playerArray.ForEach(p => p.client.SendScore());
}
if (gamemode.isGameOver(playerArray.ToArray()))
{
Debug.Log("Game Over");
SceneManager.LoadScene("ScoreBoards");
}
gamemode.RoundEnd(playerArray.ToArray());
foreach (PlayerData player in playerArray)
{
player.blockReader.Reset();
player.waiting = false;
player.client.SendInventory();
player.client.ChangeScene("ClientScene");
}
//Debug.Log("Finished Moving");
StartRound();
}
private void SpawnCharacters()
{
playerData = new Dictionary<int, PlayerData>();
Block[] SpawnBlocks = FindObjectsOfType<Block>().Where(p => p.isSpawnable).ToArray();
int spawnIndex = 0;
foreach (ClientData client in ClientList)
{
Character newChar = Instantiate(characterPrefab);
Block startingBlock = SpawnBlocks[(spawnIndex++ % ClientList.ConnectedClients.Count)];
newChar.Initialise(startingBlock, client.Inventory, client.characterAnimal);
newChar.transform.forward = startingBlock.SpawnDirection.ToVector();
playerData.Add(client.ID, new PlayerData(newChar,client));
newChar.ClientLink = client;
client.playerCharacter = newChar;
}
}
private void RegisterHandlers()
{
server.server.RegisterHandler(LogicProtocols.SendLogicList, RecieveLogicList);
}
private IEnumerator RunOnce(PlayerData data)
{
data.waiting = false;
bool blockFinished = false;
float waitTime;
while (!blockFinished && !data.blockReader.Finished)
{
//Debug.Log(data.client + "Moving once");
if (data.blockReader.CurrentBlock != null && !data.blockReader.CurrentBlock.hasBeenRemoved)
{
data.client.Inventory.Remove(data.blockReader.CurrentBlock);
data.blockReader.CurrentBlock.hasBeenRemoved = true;
}
blockFinished = data.blockReader.Read(data.character, AnimationTime,out waitTime);
//Debug.Log("Waiting: " + waitTime);
yield return new WaitForSeconds(waitTime);
gamemode.OnePlayerMoved(data);
}
data.waiting = true;
}
}

+ 11
- 0
Assets/Scripts/Managers/GameManagerRacetrack.cs.meta View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 87e8efe34e51a8e439656a3512097f21
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Loading…
Cancel
Save