示例#1
0
        private void EnteredWaypoint(int index, bool checkpoint)
        {
            var count  = WaypointGroup.Instance.WPs.Count;
            var nextWp = (int)Mathf.Repeat(_wpCount + 1, count);

            if (nextWp != index)
            {
                return;
            }
            _wpCount = nextWp;

            if (index != 0)
            {
                return;
            }
            LapCount++;
            SplitTimes.Add(RaceManager.RaceTime);

            if (LapCount <= RaceManager.GetLapCount())
            {
                return;
            }

            Debug.Log($"Boat {name} finished {RaceUI.OrdinalNumber(Place)} with time:{RaceUI.FormatRaceTime(SplitTimes.Last())}");
            RaceManager.BoatFinished(_playerIndex);
            MatchComplete = true;
        }
示例#2
0
        public DoRaceScreen(Track track)
        {
            _track = track;
            _car   = new DrivableVehicle(GameConfig.SelectedVehicle);

            _playerDriver     = new PlayerDriver(_car);
            _car.AudioEnabled = true;

            _race = new Race(_track.IsOpenRoad ? 1 : 3, _track, _playerDriver);
            for (int i = 0; i < 10; i++)
            {
                int j = Engine.Instance.Random.Next(VehicleDescription.Descriptions.Count);
                _race.AddDriver(new RacingAIDriver(VehicleDescription.Descriptions[j]));
            }
            //_race.AddDriver(new AIDriver(VehicleDescription.Descriptions.Find(a => a.Name == "Viper")));
            //_race.AddDriver(new AIDriver(VehicleDescription.Descriptions.Find(a => a.Name == "Viper")));
            //_race.AddDriver(new AIDriver(VehicleDescription.Descriptions.Find(a => a.Name == "Viper")));
            //_race.AddDriver(new AIDriver(VehicleDescription.Descriptions.Find(a => a.Name == "Viper")));
            _playerUI = new PlayerUI(_car);

            /*
             * d = new AIDriver(VehicleDescription.Descriptions.Find(a => a.Name == "911"));
             * _aiDrivers.Add(d);
             * _track.AddDriver(d);
             * d = new AIDriver(VehicleDescription.Descriptions.Find(a => a.Name == "Viper"));
             * _aiDrivers.Add(d);
             * _track.AddDriver(d);
             * d = new AIDriver(VehicleDescription.Descriptions.Find(a => a.Name == "Diablo"));
             * _aiDrivers.Add(d);
             * _track.AddDriver(d);
             * d = new AIDriver(VehicleDescription.Descriptions.Find(a => a.Name == "F512"));
             * _aiDrivers.Add(d);
             * _track.AddDriver(d);
             * d = new AIDriver(VehicleDescription.Descriptions.Find(a => a.Name == "ZR1"));
             * _aiDrivers.Add(d);
             * _track.AddDriver(d);
             * d = new AIDriver(VehicleDescription.Descriptions.Find(a => a.Name == "NSX"));
             * _aiDrivers.Add(d);
             * _track.AddDriver(d);
             */

            _raceUI = new RaceUI(_race);
            _race.StartCountdown();

            _raceViewport = new Viewport(0, 0, 640, 400);
            _uiViewport   = new Viewport(0, 0, 640, 480);
        }
示例#3
0
 public void Initialise(GameLogic gameLogic)
 {
     m_GameLogic = gameLogic;
     m_RaceUI    = GetComponent <RaceUI>();
     if (m_RaceUI == null)
     {
         Debug.LogError("m_raceUI is NULL");
         return;
     }
     m_RaceUI.Initialise(gameLogic);
     m_RaceLogic.Initialise(m_RaceUI.NumberOfCubes, m_RaceUI,
                            m_GameLogic.GetCubesRemainingCount,
                            m_GameLogic.NextCube,
                            m_GameLogic.AddCubeToPlayer,
                            m_GameLogic.DiscardCard,
                            m_GameLogic.FinishRace);
 }
示例#4
0
        private void DrawDebugInfo(Boat boat)
        {
            _debugHeaderBool = EditorGUILayout.BeginFoldoutHeaderGroup(_debugHeaderBool, "Debug Information");
            if (_debugHeaderBool)
            {
                if (Application.isPlaying)
                {
                    Repaint();
                }

                EditorGUI.indentLevel++;

                EditorGUILayout.LabelField("Place", boat.Place.ToString());
                EditorGUILayout.LabelField("Lap Percentage", boat.LapPercentage.ToString(CultureInfo.InvariantCulture));
                EditorGUILayout.LabelField("Lap Count", boat.LapCount.ToString());
                EditorGUILayout.LabelField("Match Status", boat.MatchComplete ? "Complete" : "Incomplete");

                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                EditorGUILayout.LabelField("Split", "Time", EditorStyles.boldLabel);
                if (Application.isPlaying)
                {
                    var i = 0;
                    foreach (var split in boat.SplitTimes)
                    {
                        EditorGUILayout.LabelField($"Split {i}:", RaceUI.FormatRaceTime(split));
                        i++;
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("Null:", "00:00.000");
                }
                EditorGUILayout.EndVertical();


                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndFoldoutHeaderGroup();
        }
示例#5
0
    public void Initialise(int numberOfCubes, RaceUI raceUI,
                           CubesRemainingInBagDelegate cubesRemainingInBag,
                           NextCubeDelegate nextCube,
                           AddCubeToPlayerDelegate addCubeToPlayer,
                           DiscardCardDelegate discardCard,
                           FinishRaceDelegate finishRace)
    {
        m_CubesRemainingInBag = cubesRemainingInBag;
        m_NextCube            = nextCube;
        m_AddCubeToPlayer     = addCubeToPlayer;
        m_DiscardCard         = discardCard;
        m_FinishRace          = finishRace;

        m_RaceUI         = raceUI;
        NumberOfCubes    = numberOfCubes;
        State            = RaceState.Finished;
        Winner           = Player.Unknown;
        m_Cards          = new Card [GameLogic.PlayerCount, NumberOfCubes];
        m_CardsPlayed    = new int [GameLogic.PlayerCount];
        m_CardsRemaining = new int [GameLogic.PlayerCount, GameLogic.CubeTypeCount];
        m_Cubes          = new CupCardCubeColour [NumberOfCubes];
    }
示例#6
0
    // Use this for initialization
    void Start()
    {
        GameOptions.LoadGameSettings();
        GameSettings.CapFPS(GameSettings.GS_FRAMECAP);

        RaceSettings.trackData = trackData;

        trackData.FindSpawnTiles();

        SetRaceSettings();
        IndexSections();
        SetRaceShips();

        // HUD
        GameObject hudUI = Instantiate(Resources.Load("UI/HUD") as GameObject) as GameObject;
        ui = hudUI.GetComponent<RaceUI>();
        //ui.ship = RaceSettings.ships[0];

        // Menu de pausa
        //GameObject pauseUI = Instantiate(Resources.Load("UI/OPTIONS") as GameObject) as GameObject;
        //pause = pauseUI.GetComponent<PauseManager>();
        //pauseUI.SetActive(false);

        // Resultados
        GameObject ResultsUI = Instantiate(Resources.Load("UI/Results") as GameObject) as GameObject;
        results = ResultsUI.GetComponent<PauseManager>();
        ResultsUI.SetActive(false);

        SetManagers();
        AddImageEffects();
    }
    void Update()
    {
        if (hasRaceStarted && !isRaceOver)
        {
            if (true /*PhotonNetwork.OfflineMode*/)
            {
                if (TeamManager.Instance.TotalNumberOfTeams > 1)
                {
                    // Team ranking in the race
                    //if (!ranksPanel.activeSelf) ranksPanel.SetActive(true);

                    //int teamsTotal = TeamManager.Instance.TotalNumberOfTeams;
                    List <int> teamPlaceRanks = new List <int>(new int[indicesOfTeamsStillRacing.Count]);
                    List <int> checkpointSortedIndicesOfTeams = new List <int>(new int[indicesOfTeamsStillRacing.Count]);

                    // Get first place
                    for (int i = 0; i < indicesOfTeamsStillRacing.Count; i++)
                    {
                        int idxOfTeam = indicesOfTeamsStillRacing[i];
                        // ======================================= Find which team is at a later checkpoint =======================================
                        if (currCheckpoint[idxOfTeam] == startingCheckpoint[idxOfTeam % 2])
                        {
                            teamPlaceRanks[i] = 0;
                        }
                        else
                        {
                            if (allCheckpoints.Contains(currCheckpoint[idxOfTeam]))
                            {
                                teamPlaceRanks[i] = allCheckpoints.IndexOf(currCheckpoint[idxOfTeam]) + 1;
                            }
                            else
                            {
                                Debug.LogWarning("Something's wrong with the checkpoints lists. Double click this warning and debug the Update() function");
                                teamPlaceRanks[i] = -1;    // something is wrong, fix this
                            }
                        }
                    }

                    // This uses System.Linq. https://stackoverflow.com/a/53479678
                    // Select() lambdas can take both value and index in the form of (x,i).
                    // Select is like the MAP function in many languages
                    var sorted = teamPlaceRanks
                                 .Select((x, i) => new { Checkpoint = x, TeamIndex = indicesOfTeamsStillRacing[i] }) // Map the value and index to a new ANONYMOUS type
                                 .OrderByDescending(x => x.Checkpoint)                                               // Sort this new data type in the descending order of the value (meaning, teamPlaceRanks) [each checkpoint is at a greater index than its previous one]
                                 .ToList();                                                                          // Convert this to a list

                    // Now, we can get the indices of each team, ordered by their ranks in the race
                    teamPlaceRanks                 = sorted.Select(x => x.Checkpoint).ToList();
                    TeamIndicesOrderedByRank       = sorted.Select(x => x.TeamIndex).ToList();
                    checkpointSortedIndicesOfTeams = sorted.Select(x => x.TeamIndex).ToList();


                    List <float> distancesRanks = new List <float>(new float[TeamIndicesOrderedByRank.Count]);

                    for (int i = 0; i <= allCheckpoints.Count; i++)
                    {
                        int idxA = teamPlaceRanks.IndexOf(i);            // find the first index of teams that are on this checkpoint
                        int idxB = teamPlaceRanks.LastIndexOf(i);        // find the last index of teams that are on this checkpoint

                        if (idxA >= 0 && idxB >= idxA)
                        {
                            List <int>   tmp       = teamPlaceRanks.GetRange(idxA, idxB - idxA + 1);
                            List <float> distances = new List <float>(new float[tmp.Count]);

                            for (int j = 0; j < tmp.Count; j++)
                            {
                                // Debug.Log(j + " " + (j + idxA));
                                int teamIdx = checkpointSortedIndicesOfTeams[j + idxA];
                                distances[j] = TeamManager.Instance.SqrMagnitudeBetweenTeamAndVector(teamIdx, nextCheckpoint[teamIdx].position);
                            }

                            var sortedNew = distances
                                            .Select((x, idx) => new { DistanceToNextCheckpoint = x, TeamIndex = checkpointSortedIndicesOfTeams[idx + idxA] })
                                            .OrderBy(x => x.DistanceToNextCheckpoint)
                                            .ToList();

                            distances = sortedNew.Select(x => x.DistanceToNextCheckpoint).ToList();
                            List <int> indices = sortedNew.Select(x => x.TeamIndex).ToList();

                            for (int j = 0; j < distances.Count; j++)
                            {
                                // Debug.Log(j + " + " + idxA + " " + idxB);
                                TeamIndicesOrderedByRank[j + idxA] = indices[j];
                                distancesRanks[j + idxA]           = distances[j];
                            }
                        }
                    }

                    // Add any indices that have already won to the front of this list!
                    indicesOfTeamsStillRacingRanked = new List <int>(TeamIndicesOrderedByRank);
                    TeamIndicesOrderedByRank.InsertRange(0, FinalTeamIndicesOrderedByRank);
                    TeamIndicesOrderedByRank.InsertRange(TeamIndicesOrderedByRank.Count, indicesOfTeamsThatQuit);
                    // distances = tmp.Select((x, idx) => x = TeamManager.Instance.SqrMagnitudeBetweenTeamAndVector(idx + idxA, nextCheckpoint[idx + idxA - 1].position));

                    // Display the ranks!
                    for (int j = 0; j < TeamManager.Instance.TeamsOnThisClient; j++)
                    {
                        int teamIdx = TeamManager.Instance.IndicesOfTeamsOnThisClient[j];
                        int rank    = TeamIndicesOrderedByRank.IndexOf(teamIdx);

                        int side = TeamManager.Instance.SpawnSideOfTeamsOnThisClient[j]; // == 2? teamIdx % 2 : 0;

                        RaceUI.UpdateTeamRank(side, rank);
                    }
                }
            }
        }

        bool pauseStateChangedThisFrame = false;

        // Change pause status of the game
        if (systemPlayer.GetButtonDown("Pause"))
        {
            bool wasInputFromKeyboard = systemPlayer.controllers.GetLastActiveController().type == ControllerType.Keyboard;

            int idxA = TeamManager.Instance.IndicesOfTeamsOnThisClient[0];

            if (IsRaceUIAnimationOver && (PhotonNetwork.OfflineMode || PhotonNetwork.IsMasterClient))
            {
                MetaManager.Instance.LoadNextLevel();
            }
            if (hasTeamFinishedRace[idxA] || (TeamManager.Instance.IndicesOfTeamsOnThisClient.Count > 1 && hasTeamFinishedRace[TeamManager.Instance.IndicesOfTeamsOnThisClient[1]]))
            {
                ForceFinishRace();
            }
            else if (wasInputFromKeyboard)  // was the input from keyboard? // we have to do this extra check because the ESC key is BOTH "Pause" and "Back" on the keyboard. This would lead to an issue where right after pausing the game would unpause
            {
                if (isPaused)
                {
                    CheckSettingsMenuAndUnpause();
                }
                else
                {
                    TogglePauseMenu();
                }
                pauseStateChangedThisFrame = true;
            }
            else    // the input was from a controller
            {
                if (!SettingsMenuManager.Instance.IsActive)
                {
                    TogglePauseMenu();
                    pauseStateChangedThisFrame = true;
                }
            }
        }
        // If player wants to go BACK, and the game is paused AND didn't pause the game this exact frame
        if (systemPlayer.GetButtonDown("Back") && isPaused && !pauseStateChangedThisFrame)
        {
            CheckSettingsMenuAndUnpause();
        }

        /* ================ REMOVE WHEN NOT USING DEVMODE SCREEN MODE CHANGE ================ */
        if (DevScript.Instance.DevMode)
        {
            if (systemPlayer.GetButtonDown("ChangeSplitScreenStatus") && TeamManager.Instance.TeamsOnThisClient == 2)
            {
                Rect[] camRects;
                //if (PlayerPrefs.GetInt("screenMode") == 0)
                if (MenuData.LobbyScreenData.ScreenMode == 0)
                {
                    //PlayerPrefs.SetInt("screenMode", 1);
                    MenuData.LobbyScreenData.ScreenMode = 1;
                    RaceUI.SetSplitScreenActive(true);
                }
                else
                {
                    //PlayerPrefs.SetInt("screenMode", 0);
                    MenuData.LobbyScreenData.ScreenMode = 0;
                    camRects = new Rect[] { new Rect(0, 0, 1f, 1f), new Rect(0.5f, 0, 0.0f, 0.0f) };
                    RaceUI.SetSplitScreenActive(false);
                }
            }

            // If paused, return to main menu
            if (systemPlayer.GetButtonDown("Select"))
            {
                if (IsRaceUIAnimationOver && (PhotonNetwork.OfflineMode || PhotonNetwork.IsMasterClient))
                {
                    // MetaManager.Instance.LoadMainMenu();
                    ReturnToLevelSelect();
                }
                else if (isPaused)
                {
                    TogglePauseMenu();                 // get rid of the pause panel and change timescale to 1
                    // MetaManager.Instance.LoadMainMenu();
                }
            }

            if (systemPlayer.GetButtonDown("Restart"))
            {
                if (IsRaceUIAnimationOver && (PhotonNetwork.OfflineMode) /* || PhotonNetwork.IsMasterClient)*/)
                {
                    RestartLevel();
                }
            }
        }
    }
示例#8
0
 void Awake()
 {
     instance = this;
 }
示例#9
0
 private void Start()
 {
     raceUI = FindObjectOfType <RaceUI>();
     startCheckpoint.gameObject.SetActive(false);
 }