Beispiel #1
0
 void Start()
 {
     nearbyObj     = new List <GameObject>();
     NearbyEnemies = new List <GameObject>();
     uiManager     = ReferenceContainer.UiManager;
     ReferenceContainer.SnakeController = this;
     Targets.AddFirst(transform.position);
 }
Beispiel #2
0
    public override void ChangeDirection()
    {
        List <Vector3> possibleMovement = new List <Vector3>()
        {
            Vector3.left,
            Vector3.right,
            Vector3.forward,
            Vector3.back
        };

        for (int i = 0; i < possibleMovement.Count; i++)
        {
            bool isCorrect = CheckPossitionAccess(possibleMovement[i]);
            if (!isCorrect)
            {
                possibleMovement[i] = Vector3.zero;
            }
        }
        possibleMovement.RemoveAll(item => item == Vector3.zero);

        Vector3 offset;

        if (possibleMovement.Count != 0)
        {
            offset = possibleMovement[Random.Range(0, possibleMovement.Count)];
        }
        else
        {
            return;
        }

        Targets.AddFirst(transform.position + offset);
        if (Targets.Count == 2)
        {
            Targets.RemoveLast();
            LinkedListNode <Vector3> node = Targets.First;
            for (int i = 0; i < TailsLength; i++)
            {
                if (i == 0)
                {
                    Targets.AddAfter(node, transform.position);
                }
                else
                {
                    Targets.AddAfter(node, Tails[i - 1].transform.position);
                }
                node = node.Next;
            }
        }
        if (Targets.Count > TailsLength + 1)
        {
            Targets.RemoveLast();
        }
    }
Beispiel #3
0
    public override void ChangeDirection()
    {
        Vector3 offset      = Vector3.zero;
        bool    isBonusNear = false;

        List <Vector3> possibleMovement = new List <Vector3>()
        {
            Vector3.left,
            Vector3.right,
            Vector3.forward,
            Vector3.back
        };

        for (int i = 0; i < possibleMovement.Count; i++)
        {
            bool isCorrect = CheckPossitionAccess(possibleMovement[i]);
            if (!isCorrect)
            {
                possibleMovement[i] = Vector3.zero;
            }
            if (nearbyObj.Find(p => p.transform.position == transform.position + possibleMovement[i]) != null)
            {
                isBonusNear = true;
                offset      = possibleMovement[i];
            }
        }
        if (!isBonusNear)
        {
            possibleMovement.RemoveAll(item => item == Vector3.zero);
            if (possibleMovement.Count != 0)
            {
                offset = possibleMovement[Random.Range(0, possibleMovement.Count)];
            }
            else
            {
                SnakeController.Die(gameObject);
                return;
            }
        }

        Targets.AddFirst(transform.position + offset);
        if (Targets.Count == 2)
        {
            Targets.RemoveLast();
            LinkedListNode <Vector3> node = Targets.First;
            for (int i = 0; i < TailsLength; i++)
            {
                if (i == 0)
                {
                    Targets.AddAfter(node, transform.position);
                }
                else
                {
                    Targets.AddAfter(node, Tails[i - 1].transform.position);
                }
                node = node.Next;
            }
        }
        if (Targets.Count > TailsLength + 1)
        {
            addTailPossition = Targets.Last.Value;
            Targets.RemoveLast();
        }
    }
Beispiel #4
0
 void Start()
 {
     nearbyObj     = new List <GameObject>();
     NearbyEnemies = new List <GameObject>();
     Targets.AddFirst(transform.position);
 }