Esempio n. 1
0
    void Update()
    {
        if (!notUsingBed)
        {
            Debug.Log("#it has been " + (Time.time - lastAnotherTimerMark));
        }
        if (!notUsingBed && Time.time - lastAnotherTimerMark > anotherTimer)
        {
            Debug.Log("DESTROY");
            bedManager.destroyBed(foreHeadPosition);
            notUsingBed          = true;
            lastAnotherTimerMark = Time.time;
        }
        if (Input.GetKeyDown(KeyCode.Space))
        {
            makeASweetHome(headPosition + new Vector2(0, 4));
        }
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            for (int i = 0; i < 5; i++)
            {
                addBody(Constants.SPRITE_STONE);
            }
        }
        if (Input.GetKeyDown(KeyCode.W))
        {
            headDirection = Constants.HEAD_DIRECTION_UP;
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            headDirection = Constants.HEAD_DIRECTION_LEFT;
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            headDirection = Constants.HEAD_DIRECTION_DOWN;
        }
        if (Input.GetKeyDown(KeyCode.D))
        {
            headDirection = Constants.HEAD_DIRECTION_RIGHT;
        }
        render();
        if (frameTime > Time.time - lastTimeMark)
        {
            return;
        }
        ///slow update
        if (notUsingBed)
        {
            move();
        }
        updateLogic();

        lastTimeMark = Time.time;
    }
Esempio n. 2
0
    void Update()
    {
        if (!notUsingBed)
        {
            Debug.Log("#it has been " + (Time.time - lastAnotherTimerMark));
        }
        if (!notUsingBed && Time.time - lastAnotherTimerMark > anotherTimer)
        {
            Debug.Log("DESTROY");
            bedManager.destroyBed(foreHeadPosition);
            notUsingBed          = true;
            lastAnotherTimerMark = Time.time;
        }
        //////
        ///AI PART
        if (Time.time - AILogicLastTimemark > AILogicUpdateTime)
        {
            int x = UnityEngine.Random.Range(0, 100);
            if (x < 23)
            {
                status = 0;//up
            }
            else if (x < 46)
            {
                status = 1;//right
            }
            else if (x < 23 * 3)
            {
                status = 2;//down
            }
            else if (x < 23 * 4)
            {
                status = 3;//left
            }
            else
            {
                status = 4;
            }
            switch (status)
            {
            case 0:
                headDirection = Constants.HEAD_DIRECTION_UP;
                break;

            case 1:
                headDirection = Constants.HEAD_DIRECTION_RIGHT;
                break;

            case 2:
                headDirection = Constants.HEAD_DIRECTION_DOWN;
                break;

            case 3:
                headDirection = Constants.HEAD_DIRECTION_LEFT;
                break;

            case 4:
                makeASweetHome(headPosition + new Vector2(-2, 3));
                break;
            }
            AILogicLastTimemark = Time.time;
        }
        ///ENDAI
        ///
        render();
        if (frameTime > Time.time - lastTimeMark)
        {
            return;
        }
        ///slow update
        if (notUsingBed)
        {
            move();
        }
        updateLogic();

        lastTimeMark = Time.time;
    }