// Update is called once per frame
    void Update()
    {
        if (lives == 0)
        {
            centipedeController = GameObject.Find("centipedeBody(Clone)").GetComponent <CentipedeController>();
            centipedeController.centipedeSpeed = 0;
            Debug.Log("centipede u should stop already");
        }

        if (gameOver)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                SceneManager.LoadScene("SampleScene");
                gameOver = false;
                gameOverText.gameObject.SetActive(false);
            }
        }

        GameObject[] centipedeToBeDetroyed;
        centipedeToBeDetroyed = GameObject.FindGameObjectsWithTag("Centipede");
        if (centipedeToBeDetroyed.Length == 0)
        {
            GameOver();
        }
    }
示例#2
0
    public void LevelControllContinue()
    {
        if (!gameOver)
        {
            CentipedeController centipedeController = CreateCentipede().GetComponentInChildren <CentipedeController>();

            for (int i = 0; i < crntLevel - 1; i++)
            {
                var lastSegment = centipedeController.centBody[centipedeController.centBody.Count - 1]; //Получаем последний сегмент.

                centipedeController.centBody.Remove(lastSegment);                                       //Удаляем из списка.
                Destroy(lastSegment);                                                                   //Удаляем со сцены.

                GameObject head = Instantiate(centipedeHeadPrefab);                                     //Создаем дополнительную голову.
                head.GetComponentInChildren <CentipedeHead>().speed += (crntLevel - 1) * 0.5f;          //За каждый уровень увеличиваем скорость дополнительных голов на 0.5.
                head.transform.position = new Vector3(Random.Range(0, 24), 0, 0);
                head.GetComponentInChildren <CentipedeHead>().offset = 1;

                if (i == 8) //Если оставшихся частей меньше 2 - выход из цикла.
                {
                    break;
                }
            }

            levelStarted      = true;
            spawnAntCoroutine = StartCoroutine(SpawnAnt());
        }
        else
        {
            lossPanel.SetActive(true);
        }
    }
示例#3
0
    // Splitting the centipede in two relative the deadSectionIndex
    public void Split(int deadSectionIndex)
    {
        StopAllCoroutines();

        Transform[] firstTail  = tail.Take(deadSectionIndex).ToArray();
        Transform[] secondTail = tail.Skip(deadSectionIndex).ToArray();

        tail          = firstTail;
        _sectionCount = tail.Length;
        RemoveExcessPoint();
        StartCoroutine(MoveCentipede());

        if (secondTail.Length > 0)
        {
            CentipedeController cc = secondTail.First().gameObject.AddComponent <CentipedeController>();
            cc.SetDirection(_direction);
            Transform[] tmpArray = new Transform[secondTail.Length];
            Array.Copy(secondTail, tmpArray, secondTail.Length);
            List <Transform> list = tmpArray.ToList();
            list.RemoveAt(0);

            cc.SetTail(list.ToArray());
            cc.SetUpdateTime(positionUpdateTime - positionUpdateTime * timeCoefficient);

            for (int i = secondTail.Length - 1; i >= 0; i--)
            {
                cc.AddNewWayPoint(secondTail[i].position);
            }
            cc.AddNewWayPoint(secondTail.First().position);
        }
    }
示例#4
0
    // Method for creating new centipede with defined body length and speed
    public void CreateNewCentipede(int sectionCount, float positionUpdateTime)
    {
        List <Transform> sections = new List <Transform>();
        Vector3          size     = GlobalVariables.CELL_SIZE * 0.35f;

        // Creating tail of the new centipede
        for (int i = 0; i < sectionCount - 1; i++)
        {
            GameObject go = Instantiate
                                (_sectionPrefab, _spawnTransform.position, Quaternion.identity, _parentTransform);
            sections.Add(go.transform);
            go.transform.localScale = size;
        }

        // Creating the head of centipede
        // Setting direction, tail and speed (time btw changing position)
        GameObject head = Instantiate
                              (_sectionPrefab, _spawnTransform.position, Quaternion.identity, _parentTransform);

        head.transform.localScale = size;
        CentipedeController cc = head.AddComponent <CentipedeController>();

        cc.SetDirection(Vector2.right);
        cc.SetTail(sections.ToArray());
        cc.SetUpdateTime(positionUpdateTime);
    }
示例#5
0
    private void OnTriggerStay(Collider other)
    {
        if (other.gameObject.CompareTag(GameData.Layers.Entity.ToString()))
        {
            CentipedeController centi = other.gameObject.GetComponentInParent <CentipedeController>();
            if (centi)
            {
                /*
                 * if (mySelf)
                 *  mySelf.CentipedeInLamp(centi);
                 * if (me)
                 *  me.CentipedeInLamp(centi);
                 */
                if (centi.iaCentiped.IsPasiveAndReadyToGetAngry())
                {
                    centi.SetAttacking(true);
                    Debug.Log(centi.gameObject.name);
                }
                return;
                //lampManager.CentipedeInLamp(centi);
            }
            RedEyes redEye = other.gameObject.GetComponentInParent <RedEyes>();
            if (redEye && killEye)
            {
                redEye.TryToKill();
                return;
            }

            /*
             * SpawnRedEyes spawn = other.gameObject.GetComponentInParent<SpawnRedEyes>();
             * if (spawn)
             * {
             *  spawn.Kill();
             * }
             */
        }
    }
示例#6
0
    /*TODO: 1. Create List to store instantiateCentipede
     *      2. When part of centipede body got shot it will return the part number to Split Function
     *      3. In Split Function, it will check if centipede is moving left or right
     *      4. compare the rest of number with the midpoint of the sceen to determine whether it's on the left or right of the screen
     *      4. then split the centipede to move towards left and right*/
    public void InitCells()
    {
        centipedeNumber = gameController.numOfCentipedeUnit;
        GameObject cellObject       = new GameObject();
        GameObject instanceMushroom = new GameObject();

        //creates an empty object and adds a sprite renderer component -> set the sprite to cellSprite
        cellObject.AddComponent <SpriteRenderer>().sprite = cellSprite;
        //catch the size of the sprite
        cellSize = cellSprite.bounds.size;

        Vector2 newCellSite = new Vector2(gridSize.x / (float)cols, gridSize.y / (float)rows);

        //Get the scale so you can scale the cells and change their size to fit the grid
        cellScale.x = newCellSite.x / cellSize.x;
        cellScale.y = newCellSite.y / cellSize.y;

        cellSize = newCellSite; //the size will be replaced by the new computed size, we just use cellsize for computing the scale

        cellObject.transform.localScale = new Vector2(cellScale.x, cellScale.y);

        //fix the cells to the grid by getting half of the grid and cells add and minus experiment
        gridOffset.x = -(gridSize.x / 2) + cellSize.x / 2;
        gridOffset.y = -(gridSize.y / 2) + cellSize.y / 2;



        //fill the grid with cells by using Instantiate
        for (int row = 0; row < rows; row++)
        {
            for (int col = 0; col < cols; col++)
            {
                //add the cell size so that no two cells will have the same position of x and y
                Vector2 pos = new Vector2(col * cellSize.x + gridOffset.x + transform.position.x, row * cellSize.y + gridOffset.y + transform.position.y);

                //Instantiate the game object, at position pos, with rotation set to identity
                GameObject instanceGridCell = Instantiate(cellObject, pos, Quaternion.identity) as GameObject;
                randomSpawn = Random.Range(0f, 10f);


                if (randomSpawn > 8 && row < rows - 2f && row > 2f && col < cols - 1f && col > 0.5f)
                {
                    instanceMushroom = Instantiate(mushroomPrefab, pos, Quaternion.identity) as GameObject;
                }

                if (row > rows - 2)
                {
                    if (centipedeNumber > 1)
                    {
                        GameObject instanceCentipede = Instantiate(centipedeSprite, pos, Quaternion.identity);
                        //instanceCentipede.Add(tempCentipede);
                        centipedeNumber--;
                    }
                    else
                    {
                        if (centipedeNumber == 1)
                        {
                            //instanceCentipede.Add(Instantiate(centipedeSprite, pos, Quaternion.identity) as GameObject);
                            GameObject          instanceCentipede   = Instantiate(centipedeSprite, pos, Quaternion.identity);
                            CentipedeController centipedeController = instanceCentipede.GetComponent <CentipedeController>();
                            centipedeController.centipedeHead         = true;
                            centipedeController.spriteRenderer.sprite = centipedeController.headSprite;
                            centipedeNumber--;
                        }
                    }
                }

                //set the parent of the cell to GRID so you can move the cells together with the grid
                instanceGridCell.transform.parent = transform;
                instanceMushroom.transform.parent = transform;
            }
        }


        //destroy the object used to instantiate the cells
        Destroy(cellObject);

        topCollider.size   = new Vector2(gridSize.x, 1f);
        topCollider.offset = new Vector2(0f, (gridSize.y / 2) + 0.2f);

        leftCollider.size   = new Vector2(1f, gridSize.y);
        leftCollider.offset = new Vector2(-(gridSize.x / 2) - 0.2f, 0f);

        rightCollider.size   = new Vector2(1f, gridSize.y);
        rightCollider.offset = new Vector2((gridSize.x / 2), 0f);

        bottomCollider.size   = new Vector2(gridSize.x, 1f);
        bottomCollider.offset = new Vector2(0f, -(gridSize.y / 2));
    }