Exemplo n.º 1
0
 protected bool isCar(int x, int y)
 {
     return(myMap.getCarsPosSet().Contains(myMap.TwoDToOneD(x, y)));
 }
Exemplo n.º 2
0
    void Update()
    {
        //Waiting for step1
        if (!dialoguesCompleted[0])
        {
            Vector3 entryPos = myMap.getEntranceBarrierPos();
            if (!myMap.getTrainsPosSet().Contains(myMap.TwoDToOneD((int)entryPos[0] + 1, (int)entryPos[1]))) // Step 1 Fullfiled
            {
                dialoguesCompleted[0] = true;
                // Replace
                dialogues[0].SetActive(false);
                dialogues[1].SetActive(true);
            }
            else
            {
                return;
            }
        }

        //Waiting for step2
        if (!dialoguesCompleted[1])
        {
            Vector3 entryPos = myMap.getEntranceBarrierPos();
            if (!myMap.getCarsPosSet().Contains(myMap.TwoDToOneD((int)entryPos[0], (int)entryPos[1]))) // Step 2 Fullfiled
            {
                dialoguesCompleted[1] = true;
                // Replace
                dialogues[1].SetActive(false);
                dialogues[2].SetActive(true);
            }
            else
            {
                return;
            }
        }

        //Waiting for step3
        if (!dialoguesCompleted[2])
        {
            Vector3 exitPos = myMap.getExitPos();
            if (!myMap.getTrainsPosSet().Contains(myMap.TwoDToOneD((int)exitPos[0] - 1, (int)exitPos[1])) &&
                !myMap.getTrainsPosSet().Contains(myMap.TwoDToOneD((int)exitPos[0] - 2, (int)exitPos[1])))  // Step 3 Fullfiled
            {
                dialoguesCompleted[2] = true;
                // Replace
                dialogues[2].SetActive(false);
                dialogues[3].SetActive(true);
            }
            else
            {
                return;
            }
        }
        //Waiting for step4
        if (!dialoguesCompleted[3])
        {
            if (GameObject.Find("ACarObject0") == null) // Step 4 Fullfiled
            {
                dialoguesCompleted[3] = true;
                // Replace
                dialogues[3].SetActive(false);
                finishDialogues = true;
            }
            else
            {
                return;
            }
        }
    }
Exemplo n.º 3
0
    private void Update()
    {
        animator.SetFloat("moveX", x_dir);
        animator.SetFloat("moveY", y_dir);

        // delta x and delta y.
        int dx = 0;
        int dy = 0;

        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            dx--;
        }
        else if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            dx++;
        }
        else if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            dy++;
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            dy--;
        }

        // 更新玩家的动画。
        // Update player last movement.
        if (dx != 0 || dy != 0)
        {
            // Player movement animation.
            x_dir = dx;
            y_dir = dy;
        }

        // 玩家下个位置。
        // Next position.
        int nx = dx + (int)transform.position.x;
        int ny = dy + (int)transform.position.y;

        // 判断下个位置是不是墙。
        if (isWall(nx, ny))
        {
            return;
        }

        // 判断下个位置是不是盒子。
        if (isBox(nx, ny))
        {
            // 得到玩家的下下个位置。
            // Next next position.
            int nnx = nx + dx;
            int nny = ny + dy;

            // 判断下下个位置是不是墙或者盒子。
            if (isBox(nnx, nny) || isWall(nnx, nny))
            {
                return;
            }

            // 把盒子移到下个位置。
            GameObject box = getBox(nx, ny);
            box.transform.position = new Vector3(nnx, nny);

            // 更新盒子在Map里面的结构。
            myMap.getPosBoxMap().Remove(myMap.TwoDToOneD(nx, ny));
            myMap.getPosBoxMap().Add(myMap.TwoDToOneD(nnx, nny), box);
        }

        // 把玩家移动到下个位置。
        // Move player to next position.
        transform.position = new Vector3(nx, ny);

        // 如果玩家移动,播放音乐。
        if (dx != 0 || dy != 0)
        {
            // Play foot step sound.
            audioSource.Play();
        }

        // 判断是不是赢了。
        checkIfWin();
    }