Esempio n. 1
0
    public void DrawDirections(DiagonalData dd)
    {
        int[]     limitPoints = new int[] { dd.rightPoints, dd.leftPoints, dd.forwardPoints };
        Vector2[] hitPoints   = new Vector2[] { dd.rightHit, dd.leftHit, dd.forwardHit };

        for (int i = 0; i < _lines.Length; i++)
        {
            _lines[i].ClearPoints();
            _lines[i].AddPoint(Vector2.Zero, 0);
            _lines[i].AddPoint(hitPoints[i]);

            switch (limitPoints[i])
            {
            case 7:
            case 6:
            case 5:
                _lines[i].DefaultColor = Yellow;
                break;

            case 4:
            case 3:
                _lines[i].DefaultColor = Orange;
                break;

            case 2:
            case 1:
                _lines[i].DefaultColor = Red;
                break;

            default:
                _lines[i].DefaultColor = Green;
                break;
            }
        }
    }
Esempio n. 2
0
 public void _onMoveTimerTimeout()
 {
     //GD.Print("Movetimer fired. Direction is " + _aiDirection);
     if (_aiDirection == Direction.FORWARD)
     {
         DiagonalData dd = ScanDiagonals(GlobalPosition);
         //GD.Print("Speed: " + _speed + " MaxSpeed: " + MaxSpeed + " FP: " + dd.forwardPoints + " RP: " + dd.rightPoints + " LP: " + dd.leftPoints + " DIR: " + _aiDirection);
         _randomTurn = true;
         SetTurnDirection(dd);
     }
 }
Esempio n. 3
0
    private void Awake()
    {
        diagonalData = new DiagonalData();

        if (Instance == null)
        {
            Instance = this;
        }


        gridGenerator = GetComponent <GridGenerator>();
    }
Esempio n. 4
0
    private void SetTurnDirection(DiagonalData dd)
    {
        if (_randomTurn)
        {
            _aiDirection = _GetRandomTurnDirection(dd);
            return;
        }

        //GD.Print("LeftPoints: " + dd.leftPoints + " RightPoints: " + dd.rightPoints);

        if (dd.leftPoints > dd.rightPoints || dd.rightPoints <= 2)
        {
            _aiDirection = Direction.LEFT;

            /*if (dd.rightPoints + 5 < dd.leftPoints)
             * {
             *  _aiDirection = Direction.LEFT;
             *  //_turnTimer.Start((float)GD.RandRange(1.0, 2.25));
             *  //GD.Print("Much more space on left " + dd);
             * }
             * else if (dd.rightPoints <= 2 && dd.leftPoints - dd.rightPoints > 1)
             * {
             *  _aiDirection = Direction.LEFT;
             *  //_turnTimer.Start((float)GD.RandRange(1.0, 2.25));
             *  //GD.Print("Low Points - Go Left " + dd);
             * }*/
        }

        else if (dd.rightPoints > dd.leftPoints || dd.leftPoints <= 2)
        {
            _aiDirection = Direction.RIGHT;

            /*if (dd.leftPoints + 5 < dd.rightPoints)
             * {
             *  _aiDirection = Direction.RIGHT;
             *  //_turnTimer.Start((float)GD.RandRange(1.0, 2.25));
             *  //GD.Print("Much more space on right " + dd);
             * }
             * else if (dd.leftPoints <= 2 && dd.rightPoints - dd.leftPoints > 1)
             * {
             *  _aiDirection = Direction.RIGHT;
             *  //_turnTimer.Start((float)GD.RandRange(1.0, 2.25));
             *  //GD.Print("GO Right: " + dd);
             * }*/
        }
        //GD.Print("DIR NOW: " + _aiDirection);
    }
Esempio n. 5
0
 private void SteerSideways(DiagonalData dd)
 {
     if (_aiDirection == Direction.LEFT)
     {
         if (dd.leftPoints < 4)
         {
             _aiDirection = Direction.FORWARD;
             //GD.Print("Switch from left to forward. Leftpoints: " + dd.leftPoints + " RP: " + dd.rightPoints);
         }
     }
     else if (_aiDirection == Direction.RIGHT)
     {
         if (dd.rightPoints < 4)
         {
             _aiDirection = Direction.FORWARD;
             //GD.Print("Switch from right to forward. Rightpoints: " + dd.rightPoints + " LP: " + dd.leftPoints);
         }
     }
     SetSpeed(dd);
 }
Esempio n. 6
0
    private void SteerForward(DiagonalData dd)
    {
        SideSpeed = 0;

        if (_moveTimer.IsStopped())
        {
            _moveTimer.Start();
        }

        if (dd.forwardPoints <= 8 || _rayFront.IsColliding())
        {
            SetTurnDirection(dd);
            return;
        }
        else if (dd.rightPoints <= 2 || dd.leftPoints <= 2)
        {
            SetTurnDirection(dd);
        }

        SetSpeed(dd);
    }
Esempio n. 7
0
    private Direction _GetRandomTurnDirection(DiagonalData dd)
    {
        Direction randomDir  = Direction.FORWARD;
        int       randomizer = Rng.RandiRange(0, 12);

        // If tight on sides, continue forward.
        if (dd.rightPoints < 3 && dd.leftPoints < 3)
        {
            randomDir = Direction.FORWARD;
        }
        else if (dd.rightPoints <= 3 && dd.leftPoints > 3)
        {
            randomDir = Direction.LEFT;
        }
        else if (dd.leftPoints <= 3 && dd.rightPoints > 3)
        {
            randomDir = Direction.RIGHT;
        }
        // If enough space on both sides, get random direction (that may also be forward)
        else if (dd.rightPoints > 3 && dd.leftPoints > 3)
        {
            if (randomizer < 5)
            {
                randomDir = Direction.RIGHT;
            }
            else if (randomizer < 10)
            {
                randomDir = Direction.LEFT;
            }

            _randomTurn = false;
            _turnTimer.Start((float)GD.RandRange(1.5, 2.5));
        }

        return(randomDir);
    }
Esempio n. 8
0
    private void SetSpeed(DiagonalData dd)
    {
        if ((dd.forwardPoints < 6 || _rayFront.IsColliding()) && Speed < MaxSpeed * 0.5f)
        {
            Speed += BrakeDeceleration;
        }
        else if (dd.forwardPoints <= 10 && Speed < MaxSpeed * 0.8f)
        {
            Speed += Deceleration;
        }
        else if (Speed > MaxSpeed)
        {
            Speed -= Acceleration;
        }

        if (_aiDirection == Direction.LEFT)
        {
            SideSpeed = MaxSideSpeed * -1;
        }
        if (_aiDirection == Direction.RIGHT)
        {
            SideSpeed = MaxSideSpeed;
        }
    }
Esempio n. 9
0
    public override void GetControls(float delta)
    {
        DiagonalData dd = ScanDiagonals(GlobalPosition);

        switch (_aiDirection)
        {
        case Direction.FORWARD:
            SteerForward(dd);
            break;

        case Direction.LEFT:
            SteerSideways(dd);
            break;

        case Direction.RIGHT:
            SteerSideways(dd);
            break;

        default:
            SteerForward(dd);
            break;
        }
        //DrawDirections(dd);
    }