Exemple #1
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;
        }
    }
Exemple #2
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);
        }
    }
Exemple #3
0
    public void DestroyCentipede()
    {
        if (_centipedeHead != null)
        {
            Object.Destroy(_centipedeHead.GetHeadGameObject());
            _centipedeHead = null;
        }

        for (int i = _centipedeTailsList.Count - 1; i >= 0; i--)
        {
            Object.Destroy(_centipedeTailsList[i].GetTailObject());
            _centipedeTailsList[i] = null;
        }

        _centipedeTailsList = new List <CentipedeTail>();
    }
    public override void manageCollision(Collider2D collision)
    {
        string tag = collision.gameObject.tag;

        if (tag.Equals("PlayerBullet"))
        {
            if (collision.gameObject.GetComponent <Bullet>().hit)
            {
                return;
            }
            collision.gameObject.GetComponent <Bullet>().hit = true;
            collision.gameObject.SetActive(false);
            if (removeLifePoints(40) <= 0)
            {
                if (lastBody != null)
                {
                    GameObject newHead = Instantiate(PrefabManager.Instance.centipedeHead, transform.parent.parent);
                    //GameObject newHead = PhotonNetwork.Instantiate(PrefabManager.Instance.centipedeHead.name, transform.position, Quaternion.identity);
                    newHead.transform.SetParent(transform.parent.parent);
                    GameController.Instance.enemiesCount++;
                    CentipedeHead newCentipedeHead = newHead.transform.GetChild(1).GetComponent <CentipedeHead>();
                    newCentipedeHead.setCentipedeAttributes(0, points);
                    newCentipedeHead.createFixedHead(lastBody.transform);
                    newCentipedeHead.lastBody = lastBody.lastBody;

                    GameObject    last = lastBody.gameObject;
                    CentipedeBody temp = lastBody;

                    if (temp.lastBody != null)
                    {
                        temp.lastBody.nextBody = newCentipedeHead;
                        temp = temp.lastBody;
                        while (temp.lastBody != null)
                        {
                            temp.lastBody.nextBody = temp;
                            temp = temp.lastBody;
                        }
                    }
                    last.transform.GetComponent <CentipedeTail>().canDestroy = true;
                    Destroy(last.gameObject);
                }
                this.canDestroy = true;
                removeEnemy();
            }
        }
    }
Exemple #5
0
    public void CreateCentipede(GameObject head, Vector2 lastPosition, List <CentipedeTail> remainingTail,
                                HorizontalDirection horizontalDirection, VerticalDirection verticalDirection)
    {
        head.name      = "Head_" + CentipedeManager.CentipedeCount;
        _centipedeHead = new CentipedeHead();
        _centipedeHead.Init();
        _centipedeHead.SetNewHeadGameObject(head, head.transform.position, horizontalDirection, verticalDirection);

        _centipedeTailsList = new List <CentipedeTail>();
        for (int i = 0; i < remainingTail.Count; i++)
        {
            GameObject tail = remainingTail[i].GetTailObject();
            tail.name = head.name + "_tail_" + (i);
            remainingTail[i].AssignNewLeader(i == 0 ? (IBodyPart)_centipedeHead : remainingTail[i - 1], i);

            _centipedeTailsList.Add(remainingTail[i]);
        }
    }