예제 #1
0
    IEnumerator SnakeGrow()
    {
        i_maxOfInstant = Mathf.RoundToInt(f_SnakeLength / f_SnakeSpeed);

        // The min size of Snake is 1 unit
        if (f_SnakeLength < 1)
        {
            Debug.Log("SnakeLenght < 1!\n");
            yield return(null);
        }

        if (o_SnakeBodyParts == null || o_SnakeBodyPart == null)
        {
            Debug.Log("Something is missing: SnakeBodyPart or RotationHandler");
            yield break;
        }
        // Snake's Growth
        while (oq_Snakes.Count < i_maxOfInstant && sState == "grow")
        {
            if (!RotationHandler.IsRotating() && Time.timeScale != 0)
            {
                oq_Snakes.Enqueue(Instantiate(o_SnakeBodyPart, new Vector3(o_SnakeHead.transform.position.x, o_SnakeHead.transform.position.y, o_SnakeHead.transform.position.z), Quaternion.identity, o_SnakeBodyParts.transform));
                o_SnakeHead.transform.position += f_SnakeSpeed * Vector3.up;
            }
            yield return(null);
        }
        if (oq_Snakes.Count >= i_maxOfInstant)
        {
            UpdateState("move");
        }
    }
예제 #2
0
    IEnumerator SnakeDecrease()
    {
        RotationHandler.Forbidden();
        // float tmp = 0.0f;
        while (sState == "decrease" && oq_Snakes.Count != 0)
        {
            RotationHandler.Forbidden();
            if (o_SnakeBodyParts == null || o_SnakeBodyPart == null)
            {
                Debug.Log("Something is missing: SnakeBodyPart or RotationHandler");
                yield break;
            }

            if (!RotationHandler.IsRotating() && Time.timeScale != 0)
            {
                // while(tmp<0.1f){
                //     tmp += f_SnakeSpeed;
                //     oq_Snakes.Enqueue(Instantiate(o_SnakeBodyPart, new Vector3(o_SnakeHead.transform.position.x, o_SnakeHead.transform.position.y, o_SnakeHead.transform.position.z) ,Quaternion.identity,o_SnakeBodyParts.transform));
                //     o_SnakeHead.transform.position += f_SnakeSpeed * Vector3.up;
                //     Destroy(oq_Snakes.Dequeue());
                //     yield return null;
                // }
                Destroy(oq_Snakes.Dequeue());
            }
            yield return(null);
        }
        o_SnakeHead.transform.position = v3_ObstaclePos;
        UpdateState("wait");
    }
예제 #3
0
 // Update is called once per frame
 void Update()
 {
     if (!RotationHandler.IsRotating())
     {
         if (IsTouchingBody())
         {
             SnakeCollisionHandler.Allowed();
             SnakeCollisionHandler.Handle(this.gameObject);
             SnakeCollisionHandler.Forbidden();
         }
     }
 }
예제 #4
0
 IEnumerator SnakeWait()
 {
     while (sState == "wait")
     {
         RotationHandler.Allowed();
         if (RotationHandler.IsRotating())
         {
             UpdateState("grow");
             yield break;
         }
         yield return(null);
     }
 }
 IEnumerator Leave()
 {
     Debug.Log(this.gameObject.name + ": state(leave)\n");
     while (RotationHandler.IsRotating())
     {
         yield return(null);
     }
     while (oSnakeHead.GetComponent <Collider>().bounds.Intersects(this.gameObject.GetComponent <Collider>().bounds) || RotationHandler.IsRotating())
     {
         yield return(null);
     }
     UpdateState("wait");
 }
 IEnumerator Stay()
 {
     Debug.Log(this.gameObject.name + ": state(Stay)\n");
     while (sState == "stay")
     {
         if (RotationHandler.IsRotating())
         {
             UpdateState("leave");
             yield break;
         }
         yield return(null);
     }
 }
예제 #7
0
 IEnumerator LevelWait()
 {
     Debug.Log("Level State: Wait!\n");
     InputManager.Allowed();
     RotationHandler.Allowed();
     while (sLevelState == "wait")
     {
         if (RotationHandler.IsRotating())
         {
             UpdateLevelState("play");
             yield break;
         }
         yield return(null);
     }
 }
예제 #8
0
 IEnumerator SnakeMove()
 {
     // int currCall = moveCalltimes++;
     while (sState == "move")
     {
         if (o_SnakeBodyParts == null || o_SnakeBodyPart == null)
         {
             Debug.Log("Something is missing: SnakeBodyPart or RotationHandler");
             yield break;
         }
         if (!RotationHandler.IsRotating() && Time.timeScale != 0)
         {
             oq_Snakes.Enqueue(Instantiate(o_SnakeBodyPart, new Vector3(o_SnakeHead.transform.position.x, o_SnakeHead.transform.position.y, o_SnakeHead.transform.position.z), Quaternion.identity, o_SnakeBodyParts.transform));
             o_SnakeHead.transform.position += f_SnakeSpeed * Vector3.up;
             Destroy(oq_Snakes.Dequeue());
         }
         yield return(null);
     }
     // currCall = 0;
 }
 IEnumerator Wait()
 {
     Debug.Log(this.gameObject.name + ": state(wait)\n");
     while (sState == "wait")
     {
         if (oSnakeHead.GetComponent <Collider>().bounds.Intersects(this.gameObject.GetComponent <Collider>().bounds) && !RotationHandler.IsRotating())
         {
             UpdateState("into");
             oSnake.GetComponent <WorldObject_Snake>().UpdateState("decrease");
             yield break;
         }
         yield return(null);
     }
 }