Exemplo n.º 1
0
    /// <summary>
    /// Initializes the game
    /// </summary>
    public void InIt()
    {
        allBodyPartMovemetScripts = new List <BodyPartMovemet>();
        allBodyParts = new List <GameObject>();
        //Stores Last update time as current time
        lastUpdateTime          = Time.time;
        lastDirectionUpdateTime = Time.time;
        //Calculating initial pos
        Vector3 initialTailPos = advancedSettings.initialTailPos;

        initialTailPos.x += (advancedSettings.size * (advancedSettings.length - 1));

        //Create head part first
        m_snakeHeadPart = Instantiate(snakeHeadPrefab, transform);
        m_snakeHeadPart.transform.localPosition = initialTailPos;
        m_headMovementScript = m_snakeHeadPart.GetComponent <BodyPartMovemet>();
        allBodyPartMovemetScripts.Add(m_headMovementScript);
        allBodyParts.Add(m_snakeHeadPart);
        m_headPos = m_snakeHeadPart.transform.localPosition;

        initialTailPos.x = initialTailPos.x - advancedSettings.size;
        //Create Snake Body part
        for (int i = 0; i < advancedSettings.length - 2; i++)
        {
            GameObject snakeBodyPart = Instantiate(snakeBodyPrefab, transform);
            snakeBodyPart.transform.localPosition = initialTailPos;
            initialTailPos.x = initialTailPos.x - advancedSettings.size;
            allBodyPartMovemetScripts.Add(snakeBodyPart.GetComponent <BodyPartMovemet>());
            allBodyParts.Add(snakeBodyPart);
        }

        //Create snake tail part
        m_snakeTailPart = Instantiate(snakeTailPrefab, transform);
        m_snakeTailPart.transform.localPosition = initialTailPos;
        initialTailPos.x = initialTailPos.x - advancedSettings.size;
        allBodyPartMovemetScripts.Add(m_snakeTailPart.GetComponent <BodyPartMovemet>());
        allBodyParts.Add(m_snakeTailPart);

        AssignScriptReferenceToEachPart();
        InvokeRepeating("ShowNewApple", 0, 3);
        Direction = MovingDirection.right;
        gameOver  = false;
    }