Exemple #1
0
    protected void Update()
    {
        if (useOutsideTouchControl)
        {
            return;
        }

        // only do our touch processing if we have some touches
        if (Input.touchCount > 0)
        {
            // Examine all current touches
            for (int i = 0; i < Input.touchCount; i++)
            {
                lookAtTouch(Input.GetTouch(i));
            }
        }         // end if Input.touchCount
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER
        else
        {
            // no touches. so check the mouse input if we are in the editor

            // check for each mouse state in turn, no elses here. They can all occur on the same frame!
            if (Input.GetMouseButtonDown(0))
            {
                lookAtTouch(UITouchMaker.createTouchFromInput(UIMouseState.DownThisFrame, ref lastMousePosition));
            }

            if (Input.GetMouseButton(0))
            {
                lookAtTouch(UITouchMaker.createTouchFromInput(UIMouseState.HeldDown, ref lastMousePosition));
            }

            if (Input.GetMouseButtonUp(0))
            {
                lookAtTouch(UITouchMaker.createTouchFromInput(UIMouseState.UpThisFrame, ref lastMousePosition));
            }

            // handle hover states
            // if we have a previously hovered sprite unhover it
            for (int i = 0, totalTouchables = _touchableSprites.Count; i < totalTouchables; i++)
            {
                if (_touchableSprites[i].hoveredOver)
                {
                    _touchableSprites[i].hoveredOver = false;
                }
            }

            var fixedMousePosition = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
            var hoveredSprite      = getButtonForScreenPosition(fixedMousePosition);
            if (hoveredSprite != null)
            {
                if (!hoveredSprite.highlighted)
                {
                    hoveredSprite.hoveredOver = true;
                }
            }
        }
#endif
    }
Exemple #2
0
    void Update()
    {
        // Handle Touch / Mouse input
        if (Input.touchCount > 0)
        {
            // Examine all current touches
            for (int i = 0; i < Input.touchCount; i++)
            {
                myTouch t = new myTouch();
                t.set(Input.GetTouch(i));
                CheckTouch(t);
            }
        }
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER || UNITY_WEBGL
        else
        {
            if (Input.GetMouseButtonDown(0))
            {
                CheckTouch(UITouchMaker.createTouchFromInput(UIMouseState.DownThisFrame, ref lastMousePosition));
            }
            if (Input.GetMouseButton(0))
            {
                CheckTouch(UITouchMaker.createTouchFromInput(UIMouseState.HeldDown, ref lastMousePosition));
            }
            if (Input.GetMouseButtonUp(0))
            {
                CheckTouch(UITouchMaker.createTouchFromInput(UIMouseState.UpThisFrame, ref lastMousePosition));
            }
        }
#endif

        // If game is playing
        if (gameState == GameState.Play)
        {
            // Count game time.
            gameTime     += Time.deltaTime;
            respawnTimer -= Time.deltaTime;

            // Remove destroyed bricks from brick array.
            //for (int i = 0; i < bricks.Count; i++)
            //    if (bricks[i] == null) bricks.Remove(bricks[i]);

            // Fade out the buff info text.
            if (textBuffRenderer.material.color.a > 0.01f)
            {
                Color temp = textBuffRenderer.material.color;
                temp.a -= Time.deltaTime / 3;
                textBuffRenderer.material.color = temp;
            }
            else
            {
                textBuffRenderer.enabled = false;
            }

            // Magnet Button Cooldown timer.
            if (cooldownMagnetCurrent < gameDifficulty.magnetCooldown)
            {
                guiMagnetButton.GetComponent <Renderer>().material.SetFloat("_Cutoff", cooldownMagnetCurrent / gameDifficulty.magnetCooldown);
                cooldownMagnetCurrent += Time.deltaTime;
            }
            else
            {
                guiMagnetButton.usable = true;
            }

            // Buff Spawn Cooldown timer.
            if (cooldownBuffCurrent > 0)
            {
                cooldownBuffCurrent -= Time.deltaTime;
            }


            if (gameMode == GameMode.FreePlay)   // [FreePlay] only logic.
            // Respawn Brick - minimum brick limit.
            {
                if (bricksActive.Count <= 15 && brickSpawns.Count > 0)
                {
                    int   bPos = brickSpawns[Random.Range(0, brickSpawns.Count)];
                    Brick b    = brickLevel.bricks[bPos];
                    //b.life = Random.Range(1, 6);
                    BrickSpawn(b, bPos);
                }
                // Respawn Brick - random time respawn.
                if (respawnTimer <= 0 && brickSpawns.Count > 0)
                {
                    respawnTimer = Random.Range(8, 15);
                    int   bPos = brickSpawns[Random.Range(0, brickSpawns.Count)];
                    Brick b    = brickLevel.bricks[bPos];
                    //b.life = Random.Range(1, 6);
                    BrickSpawn(b, bPos);
                }
            }
            else     // [Campaign] and [KidMode] logic.
            // Woo we won the game!
            {
                if (bricksActive.Count <= 0)
                {
                    WinGame();
                    gameState = GameState.Win;
                }
            }
        }

        // Update Game Info text on screen.
        floatingScore   = Mathf.Lerp(floatingScore, points, Time.deltaTime * 5);
        textScore.text  = floatingScore.ToString("F0");
        textTime.text   = gameTime.ToString("f1");
        textBlocks.text = bricksActive.Count + " Blocks Remaining";
        textLives.text  = gameOverBar.life.ToString();
        textCombo.text  = "+" + combo;

        // Escape is the back button on Android.
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            TogglePause();
        }

        // M can pull the ball towards the paddle.
        if (Input.GetKeyDown(KeyCode.M))
        {
            MagnetBall();
        }

        // B explodes and damages all bricks in a radius
        if (Input.GetKeyDown(KeyCode.B))
        {
            BombBall();
        }
    }