Example #1
0
    public void CreateCentipede(Vector2 position, int length)
    {
        GameObject head = Object.Instantiate(_centipedeHeadPrefab);

        head.transform.position = position;
        head.name      = "Head_" + CentipedeManager.CentipedeCount;
        _centipedeHead = new CentipedeHead();
        _centipedeHead.Init();
        _centipedeHead.NewCentipedeHead(head);

        _centipedeTailsList = new List <CentipedeTail>();
        Vector2 pos = head.transform.position;

        for (int i = 0; i < length - 1; i++)
        {
            pos = pos + Vector2.left;
            GameObject tail = Object.Instantiate(_centipedeTailPrefab);
            tail.transform.position = pos;
            tail.name = head.name + "_tail_" + (i);

            CentipedeTail centipedeTail = new CentipedeTail();
            centipedeTail.Init(tail, i == 0 ? (IBodyPart)_centipedeHead : _centipedeTailsList[i - 1], i);
            _centipedeTailsList.Add(centipedeTail);
        }
    }
Example #2
0
    private void AssignNewHead()
    {
        if (_centipedeTailsList.Count <= 0)
        {
            GameClient.Get <ICentipedeManager>().RemoveCentipede(this);
            _centipedeHead = null;
            return;
        }

        HorizontalDirection horizontalDirection = _centipedeHead.HorizontalDirection;
        VerticalDirection   verticalDirection   = _centipedeHead.VerticalDirection;

        // make next tail to new head
        CentipedeTail tail = _centipedeTailsList[0];

        tail.GetTailObject().name = "Head_" + CentipedeManager.CentipedeCount;

        _centipedeHead = new CentipedeHead();
        _centipedeHead.Init();
        _centipedeHead.SetNewHeadGameObject(tail.GetTailObject(), tail.LastPosition, horizontalDirection,
                                            verticalDirection);

        // remove this tail from tail list, because its a head now
        _centipedeTailsList.Remove(tail);

        //change indexing according to new head
        for (int i = 0; i < _centipedeTailsList.Count; i++)
        {
            _centipedeTailsList[i].AssignNewLeader(i == 0 ? (IBodyPart)_centipedeHead : _centipedeTailsList[i - 1], i);
            _centipedeTailsList[i].GetTailObject().name = "Head_" + CentipedeManager.CentipedeCount + "_tail_" + i;
        }
    }
Example #3
0
    }//UpdateHead

    void UpdateTail(Vector2 moveVec)
    {
        CentipedeTail pointer = tail;

        while (pointer != null)
        {
            pointer.MoveTo(pointer.pos + moveVec);
            pointer = pointer.tailBehind;
        }//while
    }//UpdateTail
Example #4
0
	}//Awake

    void SpawnTail()
    {
        CentipedeTail tempTail = null;
        //Spawn first tail piece and link it
        tail = Instantiate<CentipedeTail>(tailPrefab, pos + Vector2.left * size, Quaternion.identity);
        tail.gameObject.name = "Tail_" + 0;
        tempTail = tail;

        //Then spawn the rest
        for (int i = 1; i < tailLength; i++)
        {
            CentipedeTail newTail = Instantiate<CentipedeTail>(tailPrefab, pos + Vector2.left * size * (i + 1), Quaternion.identity);
            newTail.gameObject.name = "Tail_" + i;

            //Previous tailpiece needs to know what's behind it
            tempTail.tailBehind = newTail;

            //This new tail piece needs to know what's ahead
            newTail.tailAhead = tempTail;
            tempTail = newTail;
        }//for
    }//SpawnTail
Example #5
0
    public void DestroyCentipedeBodyPart(IntVector2 position)
    {
        if (_centipedeHead != null)
        {
            GameObject headGameObject = _centipedeHead.GetHeadGameObject();
            IntVector2 headPosition   = new IntVector2((int)headGameObject.transform.position.x, (int)headGameObject.transform.position.y);
            if (headPosition == position)
            {
                Object.Destroy(headGameObject);
                _levelManager.ClearCell(position);

                AssignNewHead();
            }
        }

        //Debug.LogWarning("list count = " + _centipedeTailsList.Count);
        for (int i = _centipedeTailsList.Count - 1; i >= 0; i--)
        {
            //Debug.Log("index = " + i);
            CentipedeTail tail           = _centipedeTailsList[i];
            GameObject    tailGameObject = tail.GetTailObject();
            IntVector2    tailPosition   = new IntVector2((int)tailGameObject.transform.position.x, (int)tailGameObject.transform.position.y);
            if (tailPosition == position)
            {
                _levelManager.ClearCell(position);
                if (i == _centipedeTailsList.Count - 1)
                {
                    Object.Destroy(tailGameObject);
                    _centipedeTailsList.Remove(tail);
                }
                else
                {
                    Object.Destroy(tailGameObject);
                    DivideCentipedeFrom(tail, tailPosition);
                }
                break;
            }
        }
    }
Example #6
0
    private void DivideCentipedeFrom(CentipedeTail destroyedTail, IntVector2 tailPosition)
    {
        //spawn mushroom at destroyed tail position
        GameClient.Get <IMushroomManager>().SpawnMushroom(tailPosition);

        //create new head
        CentipedeTail tail              = _centipedeTailsList[destroyedTail.TailIndex + 1];
        Vector2       lastPosition      = tail.LastPosition;
        GameObject    newHeadGameObject = tail.GetTailObject();

        // tails
        List <CentipedeTail> remainingTail = new List <CentipedeTail>();

        int index = destroyedTail.TailIndex + 2;

        for (int i = index; i < _centipedeTailsList.Count; i++)
        {
            remainingTail.Add(_centipedeTailsList[i]);
        }

        // remove from old tail list
        for (int i = 0; i < remainingTail.Count; i++)
        {
            CentipedeTail oldTail = _centipedeTailsList.Find(x => x == remainingTail[i]);
            if (oldTail != null)
            {
                _centipedeTailsList.Remove(oldTail);
            }
        }
        _centipedeTailsList.Remove(destroyedTail);
        _centipedeTailsList.Remove(tail);

        // create new centipede
        GameClient.Get <ICentipedeManager>().CreateNewCentipede(newHeadGameObject, lastPosition,
                                                                remainingTail, _centipedeHead.HorizontalDirection, _centipedeHead.VerticalDirection);
    }
Example #7
0
 // жизнь 1.
 private void Start()
 {
     HP            = 1;
     CentipedeTail = GetComponentInParent <CentipedeTail>();
 }