Ejemplo n.º 1
0
    public void UpdatePlayerBuoys()
    {
        bool passingLine = false;

        if (_buoyIndicator < 2 || _buoyIndicator >= _currentTrack.GetWaypointOrder().Count - 2)
        {
            passingLine = _playerBoat.CheckIfPassedThroughLineBetween(_buoys[_currentTrack.GetWaypointOrder()[_buoyIndicator]],
                                                                      _buoys[_currentTrack.GetWaypointOrder()[_buoyIndicator + 1]]);
        }

        if ((_playerBoat.CheckIfBuoyPassed() && _buoyIndicator > 1 && _buoyIndicator < _currentTrack.GetWaypointOrder().Count - 2) ||
            passingLine)
        {
            if (passingLine)
            {
                _buoyIndicator++;
            }
            _buoyIndicator++;
            if (_buoyIndicator > _currentTrack.GetWaypointOrder().Count - 2)
            {
                _raceFinishedPanel.SetActive(true);

                _playerBoat.canMove = false;
                _finishedRace       = true;
                _finishOrder.Add(_playerBoat);
                _finishPlaceText.text = "" + _finishOrder.Count;
                int gold = (_opponenents.Count - _finishOrder.Count + 2) * 10;
                _goldReceivedText.text = string.Format(MainGameController.instance.localizationManager.GetLocalizedValue("finished_race_gold_text"), gold);
                MainGameController.instance.player.GiveGold(gold);
            }
            else
            {
                WaypointBuoy newBuoy = _buoys[_currentTrack.GetWaypointOrder()[_buoyIndicator]].GetComponent <WaypointBuoy>();
                if (newBuoy.transform.position.y > _playerBoat.transform.position.y)
                {
                    _playerBoat.target = newBuoy.upwindTarget;
                }
                else
                {
                    _playerBoat.target = newBuoy.downwindTarget;
                }
                _playerTargetBuoy = _playerBoat.target;
            }
        }
    }
Ejemplo n.º 2
0
    public void CheckTargetPassed()
    {
        if (_keepGoingSameDirection)
        {
            return;
        }
        bool passingLine = false;

        if (_targetCounter < 2 || _targetCounter >= _trackOrder.Count - 2)
        {
            passingLine = CheckIfPassedThroughLineBetween(_buoys[_trackOrder[_targetCounter]],
                                                          _buoys[_trackOrder[_targetCounter + 1]]);
        }
        if ((CheckIfBuoyPassed() && _targetCounter > 1 && _targetCounter < _trackOrder.Count - 2) || passingLine)
        {
            if (passingLine)
            {
                _targetCounter++;
            }
            _targetCounter++;
            if (_targetCounter > _trackOrder.Count - 2)
            {
                RaceSceneController.instance.OpponentFinished(this);
                _keepGoingSameDirection = true;
                _target = _finishTarget;
            }
            else
            {
                WaypointBuoy newBuoy = _buoys[_trackOrder[_targetCounter]].GetComponent <WaypointBuoy>();
                if (newBuoy.transform.localPosition.y > this.transform.localPosition.y)
                {
                    this.target = newBuoy.upwindTarget;
                }
                else
                {
                    this.target = newBuoy.downwindTarget;
                }
            }
        }
    }
Ejemplo n.º 3
0
// Use this for initialization
    void Start()
    {
        GetWeather();
        instance = this;
        _buoys   = new List <GameObject>();
        MainGameController.instance.canGoBack = false;

        _currentTrack = MainGameController.instance.databaseController.connection.Table <Track>().Where(x => x.id == _currentRace.TrackId).First();
        DrawTrack(_currentTrack);

        //_waypointsPanel.transform.localPosition = -(Vector3.Lerp(_currentTrack.GetWaypoints()[0], _currentTrack.GetWaypoints()[1], 0.5f) - new Vector3(0, 500, 0));

        _buoyIndicator = 0;

        List <Person> _avaliablePersons = MainGameController.instance.databaseController.connection.Table <Person>().Where(x =>

                                                                                                                           x.LocationId == _currentRace.LocationId &&
                                                                                                                           x.BoatId == _currentRace.BoatsUsedId &&
                                                                                                                           x.OpponentSetupId != -1

                                                                                                                           ).ToList();

        int playerPosition = Random.Range(0, _avaliablePersons.Count);

        for (int i = 0; i < _avaliablePersons.Count + 1; i++)
        {
            if (i != playerPosition)
            {
                int newi = i;
                if (i > playerPosition)
                {
                    newi -= 1;
                }
                Person     p        = _avaliablePersons[newi];
                GameObject opponent = GameObject.Instantiate(_opponentPrefab);
                opponent.name = "Opponent " + p.Name;
                opponent.transform.SetParent(_opponentsParent.transform);
                opponent.transform.localScale    = Vector3.one;
                opponent.transform.localPosition = Vector3.zero;
                OpponentRaceAi ora = opponent.GetComponentInChildren <OpponentRaceAi>();

                Boat b = MainGameController.instance.databaseController.connection.Table <Boat>().Where(x => x.id == p.BoatId).First();

                ora.gameObject.transform.position = _buoys[0].transform.position + new Vector3((i + 2) * opponent.GetComponent <RectTransform>().sizeDelta.x * 1.5f, -500);

                OpponentSetup os = MainGameController.instance.databaseController.connection.Table <OpponentSetup>().Where(x => x.id == p.OpponentSetupId).First();
                ora.SetOpponentValues(p, os.TackingAccuracy, os.TackingExtra, os.TackingSpeed, b.GetNGZLimit(), os.BestUpwindAngle);
                _opponenents.Add(ora);

                _minmapController.AddOpponent(opponent);
            }
            else
            {
                Vector3 pos = -(_currentTrack.GetWaypoints()[0] + new Vector2((i + 2) * _playerBoat.GetComponent <RectTransform>().sizeDelta.x * 1.5f, -500));
                _waypointsPanel.transform.localPosition = pos;
            }
        }
        WaypointBuoy newBuoy = _buoys[_currentTrack.GetWaypointOrder()[_buoyIndicator]].GetComponent <WaypointBuoy>();

        if (newBuoy.transform.position.y > _playerBoat.transform.position.y)
        {
            _playerBoat.target = newBuoy.upwindTarget;
        }
        else
        {
            _playerBoat.target = newBuoy.downwindTarget;
        }
        _playerTargetBuoy = _playerBoat.target;

        if (_windSpeed > _playerBoat.GetMaxWindSpeedSails())
        {
            StartCoroutine(_playerBoat.ReceiveDamage());
        }
        foreach (OpponentRaceAi ora in _opponenents)
        {
            ora.SetFinishTarget(_finishedRaceTarget);
            ora.buoys      = _buoys;
            ora.trackOrder = _currentTrack.GetWaypointOrder();
            if (newBuoy.transform.position.y > ora.transform.position.y)
            {
                ora.target = newBuoy.upwindTarget;
            }
            else
            {
                ora.target = newBuoy.downwindTarget;
            }
        }

        //Vector3 euler = Vector3.zero;
        //euler.z = _windAngle;
        //_waypointsPanel.transform.localEulerAngles = euler;

        _minmapController.DrawTrack(_currentTrack);

        StartCoroutine(CountDown(5));

#if UNITY_EDITOR
        //GetWayPointsTemp();
#endif
    }