Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (!isRunning || gameOver)
        {
            gemMan.animateWithoutUpdating();
            return;
        }
        if (marbles.Count == 0)
        {
            gameOver = true;
            return;
        }

        timeSinceLastGem += Time.deltaTime;
        if (gemMan.shouldSpawnGem(timeSinceLastGem))
        {
            gemMan.addGem();
            timeSinceLastGem = 0.0f;
        }
        gemMan.updateOnFrame();
        elMan.updateOnFrame();
        foreach (Marble tm in marbles)
        {
            tm.updatePosition();
        }
        int mb = -1;

        if (Input.GetMouseButtonDown(0))
        {
            mb = 0;
        }
        else if (Input.GetMouseButtonDown(1))
        {
            mb = 1;
        }
        if (mb != -1)
        {
            Vector3 worldCoords   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            int     x             = Mathf.RoundToInt(worldCoords.x) + boardWidth / 2;
            int     y             = Mathf.RoundToInt(worldCoords.y) + boardHeight / 2;
            bool    isTrainOnTile = false;
            foreach (Marble tm in marbles)
            {
                if (tm.currX == x && tm.currY == y)
                {
                    isTrainOnTile = true;
                    break;
                }
            }
            if (!isTrainOnTile && x >= 0 && x < boardWidth && y >= 0 && y < boardHeight)
            {
                Tile t = board[x, y];
                t.rotateTurn(1 - mb);                 // left click = clockwise, right click = counterclockwise
            }
        }
    }