Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (begin && !win && !lost)
        {
            if (Time.frameCount - evilTick > evilRate)
            {
                for (int h = 0; h < HEIGHT; h++)
                {
                    map[evilX, h] = 0;
                }
                evilX++;
                evilTick = Time.frameCount;
            }

            int hr = (int)Input.GetAxisRaw("Horizontal");
            int vr = (int)Input.GetAxisRaw("Vertical");

            for (int i = 0; i < Input.touchCount; i++)
            {
                if ((float)Input.GetTouch(i).position.x / (float)Screen.width < .2)
                {
                    hr = 1;
                }
                if ((float)Input.GetTouch(i).position.x / (float)Screen.width > .8)
                {
                    if ((float)Input.GetTouch(i).position.y / (float)Screen.height > .5)
                    {
                        vr = 1;
                    }
                    else
                    {
                        vr = -1;
                    }
                }
            }

            if ((releasedH || Time.frameCount - pastCountH > playerMoveRate) && hr != 0)
            {
                playerPos.x += hr;
                releasedH    = false;
                pastCountH   = Time.frameCount;
            }
            if ((releasedV || Time.frameCount - pastCountV > playerMoveRate) && vr != 0)
            {
                player.moveY(vr);
                playerPos.y += vr;
                releasedV    = false;
                pastCountV   = Time.frameCount;
            }

            if (hr == 0 && !releasedH)
            {
                releasedH = true;
            }
            if (vr == 0 && !releasedV)
            {
                releasedV = true;
            }

            if (playerPos.x < 0)
            {
                playerPos.x = 0;
            }
            if (playerPos.y < 0)
            {
                playerPos.y = 0;
            }
            if (playerPos.y > 8)
            {
                playerPos.y = 8;
            }

            board.UpdateBoard(map, playerPos);
            if (playerPos.x + 8 >= maxWidth)
            {
                win       = true;
                startTime = Time.time;
            }
            if (playerPos.x + 8 < maxWidth && map[(int)playerPos.x + 8, (int)playerPos.y] != 0 && map[(int)playerPos.x + 8, (int)playerPos.y] != 2)
            {
                player.Ouch();
                evilRate       = evilNormRate - 15;
                playerMoveRate = normRate + 5;
            }
            else
            {
                player.resetRate();
                evilRate       = evilNormRate;
                playerMoveRate = normRate;
            }
            if (playerPos.x + 8 < evilX)
            {
                begin = false;
                win   = false;
                lost  = true;
                StartCoroutine(resetScene());
                GameObject go = Instantiate(Resources.Load("Prefabs/gameover") as GameObject);
            }
        }
        else if (!begin && !win && !lost)
        {
            board.UpdateBoard(null, new Vector2(0, 0));
            Destroy(coutDown);
            if (Time.time - startTime < 1)
            {
                coutDown = Instantiate(Resources.Load("Prefabs/3") as GameObject);
                coutDown.transform.position = new Vector3(-.5f, 4, .25f);
            }
            else if (Time.time - startTime > 1 && Time.time - startTime < 2)
            {
                coutDown = Instantiate(Resources.Load("Prefabs/2") as GameObject);
                coutDown.transform.position = new Vector3(-.5f, 5, .25f);
            }
            else if (Time.time - startTime > 2 && Time.time - startTime < 3)
            {
                coutDown = Instantiate(Resources.Load("Prefabs/1") as GameObject);
                coutDown.transform.position = new Vector3(-.5f, 6, .25f);
            }
            else if (Time.time - startTime > 3 && Time.time - startTime < 4)
            {
                coutDown = Instantiate(Resources.Load("Prefabs/start") as GameObject);
                coutDown.transform.position = new Vector3(-.5f, 7, .25f);
            }
            else
            {
                begin = true;
                player.canStart();
            }
        }
        if (win)
        {
            if (Time.time - startTime < 2)
            {
                board.Win();
                board.UpdateBoard(map, playerPos);
            }
            else if (!loaded)
            {
                loaded = true;
                StartCoroutine(loadScene());
                board.ClearTiles();
                GameObject loading = Instantiate(Resources.Load("Models/load") as GameObject);
                loading.transform.localScale = new Vector3(1f / 16f, 1f / 16f, 1f / 16f);
                loading.transform.position   = new Vector3(0, 0, 0);
                loading.transform.Rotate(new Vector3(0, 180, 0));
            }
        }
    }