Exemplo n.º 1
0
    // Start is called before the first frame update

    /*<summary>
     * Starts creating a new gamefield, and creating first snake.
     * Then it's adjusting an game speed interval, and special food time.
     * </summary>
     */
    void Start()
    {
        //to be sure if it's set up
        GameManager.instance.gameOver = false;

        //interval from options
        interval = GameManager.instance.GameSpeed;

        nextFrameTime        = Time.time + interval;
        timeToNewSpecialFood = Random.Range(0f, maxTimeToNewSpecialFood); //generating time to instantiate a new special food object

        //generate GameField
        Field field = fieldPrefab.gameObject.GetComponent <Field>();

        field.CreateField();

        //create wall;
        Wall wall = wallPrefab.gameObject.GetComponent <Wall>();

        wall.BuildWall(field);

        //snake initialization
        snake = new List <SnakeElement>();

        SnakeElement head = headPrefab.gameObject.GetComponent <SnakeHead>();

        head.AddElement(snake);

        for (int i = 0; i < 4; i++)
        {
            SnakeElement tail = tailPrefab.gameObject.GetComponent <SnakeTail>();
            tail.AddElement(snake);
            SnakeElement.MoveTail(snake);
            SnakeElement.MoveHead(snake);
        }


        //food creation
        Food food = foodPrefab.gameObject.GetComponent <Food>();

        food.AddNewOne();
    }