示例#1
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.LeftArrow))
     {
         Debug.LogWarning("Closest food" + findClosestFood());
         transform.position -= new Vector3(1f, 0);
         checkBounds();
         myfoodgenerator.eatFood(this.transform.position);
         Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));
     }
     if (Input.GetKeyDown(KeyCode.RightArrow))
     {
         Debug.LogWarning("Closest food" + findClosestFood());
         transform.position += new Vector3(1f, 0);
         checkBounds();
         myfoodgenerator.eatFood(this.transform.position);
         Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));
     }
     if (Input.GetKeyDown(KeyCode.UpArrow))
     {
         Debug.LogWarning("Closest food" + findClosestFood());
         transform.position += new Vector3(0, 1f);
         checkBounds();
         myfoodgenerator.eatFood(this.transform.position);
         Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));
     }
     if (Input.GetKeyDown(KeyCode.DownArrow))
     {
         Debug.LogWarning("Closest food" + findClosestFood());
         transform.position -= new Vector3(0, 1f);
         checkBounds();
         myfoodgenerator.eatFood(this.transform.position);
         Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));
     }           //Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));
 }
示例#2
0
    public IEnumerator generateFood()
    {
        while (true)
        {
            if (getVisibleFood() < 6)
            {
                Vector3 randomLocation;
                do
                {
                    yield return(new WaitForSeconds(0.5f));

                    foodPosition = new positionRecord();

                    float randomX = Mathf.Floor(Random.Range(-14f, 14f));

                    float randomY = Mathf.Floor(Random.Range(-14f, 14f));

                    randomLocation = new Vector3(randomX + 0.5f, randomY + 0.5f);
                }while (Physics2D.OverlapCircleAll(randomLocation, 0.1f).Length != 0);


                //don't allow the food to be spawned on other food

                foodPosition.Position = randomLocation;
                //print("Disance: "+ allTheFood.Equals(foodPosition));

                if (!allTheFood.Contains(foodPosition) && !sn.hitTail(foodPosition.Position, sn.snakelength))
                {
                    foodPosition.BreadcrumbBox = Instantiate(foodObject, randomLocation, Quaternion.Euler(0f, 0f, 45f));


                    //make the food half the size
                    foodPosition.BreadcrumbBox.transform.localScale = new Vector3(0.5f, 0.5f);


                    foodPosition.BreadcrumbBox.GetComponent <SpriteRenderer>().color = Color.red;

                    foodPosition.BreadcrumbBox.transform.localScale = new Vector3(0.5f, 0.5f);

                    foodPosition.BreadcrumbBox.name = "Food Object";

                    allTheFood.Add(foodPosition);
                }

                yield return(null);
            }


            yield return(null);
        }
    }
示例#3
0
    public IEnumerator generateFood()
    {
        while (true)
        {
            if (getVisibleFood() < 6)
            {
                yield return(new WaitForSeconds(1f /*(Random.Range(1f, 3f)*/));

                foodPosition = new positionRecord();

                float randomX = Mathf.Floor(Random.Range(-9f, 9f));

                float randomY = Mathf.Floor(Random.Range(-9f, 9f));

                Vector3 randomLocation = new Vector3(randomX, randomY);

                //don't allow the food to be spawned on other food
                foodPosition.Position = randomLocation;

                if (!allTheFood.Contains(foodPosition) && !sn.hitTail(foodPosition.Position, sn.snakelength))
                {
                    if (Physics2D.OverlapCircleAll(randomLocation, 0.1f).Length == 0)
                    {
                        foodPosition.BreadcrumbBox = Instantiate(foodObject, randomLocation, Quaternion.Euler(0f, 0f, 45f));

                        foodPosition.BreadcrumbBox.transform.parent = GameObject.Find("FoodParent").transform;

                        //make the food half the size
                        foodPosition.BreadcrumbBox.transform.localScale = new Vector3(0.5f, 0.5f);


                        foodPosition.BreadcrumbBox.GetComponent <SpriteRenderer>().color = Random.ColorHSV();

                        foodPosition.BreadcrumbBox.transform.localScale = new Vector3(0.5f, 0.5f);

                        foodPosition.BreadcrumbBox.name = "Food Object";

                        allTheFood.Add(foodPosition);
                    }
                }
                yield return(null);
            }
            if (allTheFood.Count == 6)
            {
                generateEnemey = true;
                yield return(null);
            }
            yield return(null);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (mysnakegenerator.getLength() >= 8)
        {
            portal.GetComponent <SpriteRenderer>().color = Color.green;
        }



        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            //Debug.LogWarning("Closest food" + findClosestFood());
            transform.position -= new Vector3(1f, 0);
            checkBounds();
            myfoodgenerator.eatFood(this.transform.position);
            // mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength);
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            //Debug.LogWarning("Closest food" + findClosestFood());
            transform.position += new Vector3(1f, 0);
            checkBounds();
            myfoodgenerator.eatFood(this.transform.position);
            // mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength);
        }
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            //Debug.LogWarning("Closest food" + findClosestFood());
            transform.position += new Vector3(0, 1f);
            checkBounds();
            myfoodgenerator.eatFood(this.transform.position);
            //mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength);
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            //Debug.LogWarning("Closest food" + findClosestFood());
            transform.position -= new Vector3(0, 1f);
            checkBounds();
            myfoodgenerator.eatFood(this.transform.position);
            //mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength);
        }



        mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength);
    }
示例#5
0
    public IEnumerator generateFood()
    {
        while (true)
        {
            if (getVisibleFood() < 6)
            {
                yield return(new WaitForSeconds(Random.Range(1f, 3f)));

                foodPosition = new positionRecord();

                float randomX = Mathf.Floor(Random.Range(-9f, 9f));

                float randomY = Mathf.Floor(Random.Range(-9f, 9f));

                Vector3 randomLocation = new Vector3(randomX, randomY);

                //don't allow the food to be spawned on other food

                foodPosition.Position = randomLocation;

                if (!allTheFood.Contains(foodPosition) && !sn.hitTail(foodPosition.Position, sn.snakelength))

                {
                    foodPosition.BreadcrumbBox = Instantiate(foodObject, randomLocation, Quaternion.Euler(0f, 0f, 45f));

                    foodPosition.BreadcrumbBox.GetComponent <SpriteRenderer>().color = Random.ColorHSV();

                    foodPosition.BreadcrumbBox.transform.localScale = new Vector3(0.5f, 0.5f);

                    foodPosition.BreadcrumbBox.name = "Food Object";

                    allTheFood.Add(foodPosition);
                }

                yield return(null);
            }


            yield return(null);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            transform.position -= new Vector3(1f, 0);
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            transform.position += new Vector3(1f, 0);
        }
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            transform.position += new Vector3(0, 1f);
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            transform.position -= new Vector3(0, 1f);
        }

        Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));
    }
    public IEnumerator automoveCoroutine()
    {
        while (true)
        {
            Vector3 closestFoodPosition = findClosestFood();

            if (mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength))
            {
                SceneManager.LoadScene("endScene");
            }

            if (this.transform.position.x < closestFoodPosition.x)
            {
                //   Debug.LogWarning("Closest food" + findClosestFood());
                mysnakegenerator.savePosition();
                transform.position += new Vector3(1f, 0);
                mysnakegenerator.drawTail(mysnakegenerator.snakelength);
                checkBounds();
                myfoodgenerator.eatFood(this.transform.position);
                Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));
            }

            else if (this.transform.position.x > closestFoodPosition.x)
            {
                // Debug.LogWarning("Closest food" + findClosestFood());
                mysnakegenerator.savePosition();
                transform.position -= new Vector3(1f, 0);
                mysnakegenerator.drawTail(mysnakegenerator.snakelength);
                checkBounds();
                myfoodgenerator.eatFood(this.transform.position);
                Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));
            }

            else if (this.transform.position.y < closestFoodPosition.y)
            {
                // Debug.LogWarning("Closest food" + findClosestFood());
                mysnakegenerator.savePosition();
                transform.position += new Vector3(0, 1f);
                mysnakegenerator.drawTail(mysnakegenerator.snakelength);
                checkBounds();
                myfoodgenerator.eatFood(this.transform.position);
                Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));
            }

            else if (this.transform.position.y > closestFoodPosition.y)
            {
                //Debug.LogWarning("Closest food" + findClosestFood());
                mysnakegenerator.savePosition();
                transform.position -= new Vector3(0, 1f);
                mysnakegenerator.drawTail(mysnakegenerator.snakelength);
                checkBounds();
                myfoodgenerator.eatFood(this.transform.position);
                Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));
            }

            yield return(new WaitForSeconds(1f));
        }
    }
    // Update is called once per frame
    void Update()
    {
        /*if (this.transform.position == targetLocation.position)
         * {
         *  //print("Snake Reached Target");
         *
         * }*/


        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            //Debug.LogWarning("Closest food" + findClosestFood());
            transform.position -= new Vector3(1f, 0);
            checkBounds();
            myfoodgenerator.eatFood(this.transform.position);
            Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));

            if (mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength))
            {
                print("DIE!");
                SceneManager.LoadScene("DeathScene");
            }
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            //Debug.LogWarning("Closest food" + findClosestFood());
            transform.position += new Vector3(1f, 0);
            checkBounds();
            myfoodgenerator.eatFood(this.transform.position);
            Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));

            if (mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength))
            {
                print("DIE!");
                SceneManager.LoadScene("DeathScene");
            }
        }
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            //Debug.LogWarning("Closest food" + findClosestFood());
            transform.position += new Vector3(0, 1f);
            checkBounds();
            myfoodgenerator.eatFood(this.transform.position);
            Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));

            if (mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength))
            {
                print("DIE!");
                SceneManager.LoadScene("DeathScene");
            }
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            //Debug.LogWarning("Closest food" + findClosestFood());
            transform.position -= new Vector3(0, 1f);
            checkBounds();
            myfoodgenerator.eatFood(this.transform.position);
            Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));

            if (mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength))
            {
                print("DIE!");
                SceneManager.LoadScene("DeathScene");
            }
        }



        //Debug.Log(mysnakegenerator.hitTail(this.transform.position, mysnakegenerator.snakelength));
    }