예제 #1
0
    private void AddPointAndCheckIfCrossed(Vector3 newPoint)
    {
        _trailPoints.Add(newPoint);
        _trailTimes.Add(DateTime.Now);

        if (_trailPoints.Count < 4)
        {
            return;
        }
        var penultimatePoint = _trailPoints[_trailPoints.Count - 2];

        GameDataManager.I.TotalTrailLength += (newPoint - penultimatePoint).magnitude / 100f;

        for (var i = 0; i < _trailPoints.Count - 2; i++)
        {
            if (MyMaths.AreLinesIntersecting(_trailPoints[i], _trailPoints[i + 1], penultimatePoint, newPoint))
            {
                var shapePoints = _trailPoints.Skip(i).ToList();

                if (MyMaths.IsClockwise(shapePoints))
                {
                    shapePoints.Reverse();
                    // Can't have Clockwise shape, the walls then are generated inside out
                }

                _dynamicGround.UpdateGround(shapePoints);
                DrawArea(i);

                // Cut off all tail
                CutTailAtIndex(_trailPoints.Count - 1);
                _trailRendererCutting.Clear();
                SoundManager.I.Play("vaporize", 1f, true);
                return;
            }
        }

        // Debug.Log($"trail.Count={trailPoints.Count}");
    }