Esempio n. 1
0
    private void handleInput()
    {
        if (gameState.isInputDown() && isCurrentTileOverStack())
        {
            Rect intersection      = getTileIntersection();
            Rect currentTileBounds = getBoundingRectangle(currentTile);

            float xSize;
            float zSize;
            float x;
            float z;
            if (intersection.height == currentTileBounds.height)
            {
                xSize = currentTileBounds.width - intersection.width;
                zSize = intersection.height;

                x = currentTileBounds.x == intersection.x ? intersection.x + intersection.width : currentTileBounds.x;
                z = intersection.y;
            }
            else
            {
                zSize = currentTileBounds.height - intersection.height;
                xSize = intersection.width;

                x = intersection.x;
                z = currentTileBounds.y == intersection.y ? intersection.y + intersection.height : currentTileBounds.y;
            }

            if (xSize > 0.001f && zSize > 0.001f)
            {
                Transform remainder = objectPool.getPooledObject().transform;
                remainder.transform.SetParent(transform);
                remainder.localScale = new Vector3(xSize, tileHeight, zSize);
                remainder.position   = new Vector3(x + xSize / 2, currentTile.position.y, z + zSize / 2);
                remainder.GetComponent <MeshRenderer>().material       = baseMaterial;
                remainder.GetComponent <MeshRenderer>().material.color = colorProvider.getCurrentColor();
                remainder.GetComponent <Rigidbody>().isKinematic       = false;
            }

            currentTile.localScale    = new Vector3(intersection.width, tileHeight, intersection.height);
            currentTile.localPosition = new Vector3(intersection.x + intersection.width / 2, currentTile.localPosition.y, intersection.y + intersection.height / 2);

            previousTile = currentTile;
            currentTile  = null;
            stackSize++;
            gameState.incrementScore();
            gameState.setStackHeight(getStackHeight());
        }
    }
    // Update is called once per frame
    void Update()
    {
        TileColorProvider colorProvider = gameState.getTileColorProvider();
        Color             fromColor     = setColorLook(colorProvider.getPreviousColor());
        Color             toColor       = setColorLook(colorProvider.getCurrentColor());

        cam.backgroundColor = Color.Lerp(fromColor, toColor, Mathf.PingPong(Time.time, rate) / rate);
    }