Ejemplo n.º 1
0
    private void AvoidPlayer(GameObject player)
    {
        Vector2 toPlayer = player.transform.position - this.transform.position;

        if (toPlayer.x >= 0)
        {
            if (toPlayer.y >= 0)
            {
                this.state = cookieState.LEFTDOWN;
            }
            else
            {
                this.state = cookieState.LEFTUP;
            }
        }
        else if (toPlayer.x < 0)
        {
            if (toPlayer.y >= 0)
            {
                this.state = cookieState.RIGHTDOWN;
            }
            else
            {
                this.state = cookieState.RIGHTUP;
            }
        }
    }
Ejemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     this.state = cookieState.INITIAL;
     speed2     = speed / Mathf.Sqrt(2);
     selector   = general;
 }
Ejemplo n.º 3
0
 private void SetStateFromRandom(int num, cookieState[] selection)
 {
     this.state = selection[num];
     return;
 }
Ejemplo n.º 4
0
    void OnTriggerStay2D(Collider2D col)
    {
        int colIndex;

        if (col.tag == "Player")
        {
            AvoidPlayer(col.gameObject);
        }
        else if (col.tag != "GoodFood")
        {
            switch (col.tag)
            {
            case "LowerWall": colIndex = 0;
                break;

            case "UpperWall": colIndex = 1;
                break;

            case "LeftWall": colIndex = 2;
                break;

            case "RightWall": colIndex = 3;
                break;

            default:
                colIndex = 0;
                break;
            }
            switch (state)
            {
            case cookieState.LEFT: state = LEFT[colIndex];
                if (colIndex == 2)
                {
                    selector = forLEFTonLeftWall;
                }
                else if (colIndex == 3)
                {
                    selector = forLEFTonRightWall;
                }
                else
                {
                    selector = general;
                }
                break;

            case cookieState.LEFTUP: state = LEFTUP[colIndex];
                break;

            case cookieState.LEFTDOWN: state = LEFTDOWN[colIndex];
                break;

            case cookieState.RIGHT: state = RIGHT[colIndex];
                if (colIndex == 2)
                {
                    selector = forRIGHTonLeftWall;
                }
                else if (colIndex == 3)
                {
                    selector = forRIGHTonRightWall;
                }
                else
                {
                    selector = general;
                }
                break;

            case cookieState.RIGHTUP: state = RIGHTUP[colIndex];
                break;

            case cookieState.RIGHTDOWN: state = RIGHTDOWN[colIndex];
                break;

            case cookieState.UP: state = UP[colIndex];
                if (colIndex == 0)
                {
                    selector = forUPonLowerWall;
                }
                else if (colIndex == 1)
                {
                    selector = forUPonUpperWall;
                }
                else
                {
                    selector = general;
                }
                break;

            case cookieState.DOWN: state = DOWN[colIndex];
                if (colIndex == 0)
                {
                    selector = forDOWNonLowerWall;
                }
                else if (colIndex == 1)
                {
                    selector = forDOWNonUpperWall;
                }
                else
                {
                    selector = general;
                }
                break;

            default: state = cookieState.RANDOM;
                selector   = general;
                break;
            }
        }
    }