Ejemplo n.º 1
0
    void GenerateLevel()
    {
        for (int i = 0; i < GameSettings.instance.countBrickRows; i++)
        {
            //Random count of bricks in current row (from range)
            int countBricksInCurrentRow = Random.Range(GameSettings.instance.minCountBricksInRow, GameSettings.instance.maxCountBricksInRow + 1);

            for (int j = 0; j < countBricksInCurrentRow; j++)
            {
                //Calculate object position
                float xPositionShift     = (j - ((float)countBricksInCurrentRow / 2 - 1)) * 0.8f;
                float xPositionCorrector = -0.4f;

                //Get balanced index of brick
                int balancedNum = GetBalanceNum(balanceValues);
                if (GameSettings.instance.brickTypes[balancedNum].prefab != null)
                {
                    //Instantiate brick object
                    BrickController brick = Instantiate(GameSettings.instance.brickTypes[balancedNum].prefab, transform);
                    //Check for correct count health and set it to brick object
                    brick.countHealth = GameSettings.instance.brickTypes[balancedNum].countHealth >= 1 ? GameSettings.instance.brickTypes[balancedNum].countHealth : 1;
                    //Set brick position
                    brick.transform.localPosition = new Vector2(xPositionShift + xPositionCorrector, -i * 0.6f);
                }
                else
                {
                    Debug.LogError("Brick type number[" + balancedNum + "] is empty!");
                }
            }
        }
    }
Ejemplo n.º 2
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.name == "Paddle")
        {
            // (ball position - paddle position) / paddle width
            float x = (_rigidbody2D.position.x - collision.rigidbody.position.x) / collision.collider.bounds.size.x;

            // Calculate direction, set length to 1
            Vector2 dir = new Vector2(x, 1).normalized;

            // Set Velocity with dir * speed
            _rigidbody2D.velocity = dir * _rigidbody2D.velocity.magnitude;

            _audioSource.PlayOneShot(_paddleHitClip);
        }
        else if (collision.gameObject.name == "Tilemap")
        {
            BrickController controller = collision.gameObject.GetComponent <BrickController>();

            controller.HandleBrickCollision(collision, _rigidbody2D.velocity.magnitude);
        }
        else // walls and ceiling
        {
            _audioSource.PlayOneShot(_wallHitClip);
        }
    }
    public void setState(int x)
    {
        state = GameObject.Find("AnyText").GetComponent <Text> ();
        end   = GameObject.Find("EndText").GetComponent <Text> ();
        BrickController bc = new BrickController();

        end.text   = "";
        state.text = "";
        if (x >= 1)
        {
            state.text = "LIFE: " + (x).ToString();
        }
        else if (x == 0)
        {
            end.fontSize = 8;
            end.text     = "GAME OVER!";
            state.text   = "Score:" + bc.getScore().ToString();
            StartCoroutine(End(bc.getScore()));
        }
        else if (x == -1)
        {
            end.fontSize = 8;
            end.text     = "YOU WON!!!";
            StartCoroutine(End(bc.getScore()));
        }
        else if (x == -2)
        {
            end.fontSize = 8;
            end.text     = "TIME IS UP!";
            state.text   = "Score:" + bc.getScore().ToString();
            StartCoroutine(End(bc.getScore()));
        }
    }
Ejemplo n.º 4
0
    public static void BrickBroken(int points)
    {
        instance.score         += points;
        instance.scoreText.text = "Score: " + instance.score;
        if (Random.value < instance.powerupChance)
        {
            instance.CreatePowerup();
        }
        bool hasWon = true;

        for (int i = 0; i < instance.brickList.Count; i++)
        {
            BrickController brick = instance.brickList[i];
            if (brick.gameObject.activeSelf)
            {
                hasWon = false;
                break;
            }
        }

        if (hasWon)
        {
            instance.winText.text = "You Win!";
            instance.winText.gameObject.SetActive(true);

            PlayerPrefs.SetInt("HighScore", instance.score);

            instance.music.Stop();
            instance.music.clip = instance.winSound;
            instance.music.Play();
            HighScoreSaved();
        }
    }
Ejemplo n.º 5
0
    void createBricks()
    {
        RectTransform   PlaneRect       = Plane.GetComponent <RectTransform>();
        GridLayoutGroup gridLayoutGroup = Plane.GetComponent <GridLayoutGroup>();

        //RectTransform BrickRect = Brick.GetComponent<RectTransform>();

        row    = (int)(PlaneRect.rect.height / (gridLayoutGroup.cellSize.y + gridLayoutGroup.spacing.y));
        column = (int)(PlaneRect.rect.width / (gridLayoutGroup.cellSize.x + gridLayoutGroup.spacing.x));

        bricks = new BrickController[row, column];

        for (int i = 0; i < row; i++)
        {
            for (int j = 0; j < column; j++)
            {
                GameObject      NewBrick        = createBrick(Plane);
                BrickController brickController = NewBrick.GetComponent <BrickController>();
                brickController.i = i;
                brickController.j = j;
                //brickController.setShow(false, Color.white);

                bricks[i, j] = brickController;
            }

            //createDividerVertical(SnareVertical);
        }
    }
Ejemplo n.º 6
0
        public void ItCreatesABrick()
        {
            var comm       = new BluetoothCommunication("COM4");
            var controller = new BrickController(comm);

            Assert.IsNotNull(controller.Brick);
        }
Ejemplo n.º 7
0
    private void SpawnBrick(Brick brickData)
    {
        Vector3    pos   = new Vector3(brickData.x * 16, brickData.y * -8);
        GameObject brick = Instantiate(brickPrefab, Vector3.zero, Quaternion.identity);

        brick.transform.parent        = this.gameObject.transform;
        brick.transform.localPosition = pos;
        Color color;

        if (ColorUtility.TryParseHtmlString(brickData.color, out color))
        {
            brick.GetComponent <SpriteRenderer>().color = color;
            BrickController controller = brick.GetComponent <BrickController>();
            controller.SetGameController(_gameController);
            controller.SetHitPoint(brickData.hitPoints);

            if (brickData.powerUp.name != null)
            {
                PowerUpObject pu = powerupMap[brickData.powerUp.name];

                if (pu != null)
                {
                    pu.duration        = brickData.powerUp.duration;
                    controller.powerUp = pu;
                }
            }
        }
    }
Ejemplo n.º 8
0
        public void ItCreatesABrick()
        {
            var comm       = new MockCommunication();
            var controller = new BrickController(comm);

            Assert.IsNotNull(controller.Brick);
        }
Ejemplo n.º 9
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.tag == "brick" && counter == 0)
     {
         //Destroy(collision.gameObject);
         velo.y  = -velo.y;
         counter = 1;
         brick   = collision.gameObject.GetComponent <BrickController>();;
         brick.SetHitPoints(brick.GetHitPoints() - 1);
     }
     if (counter == 0 && collision.gameObject.tag == "UpperWall")
     {
         velo.y  = -velo.y;
         counter = 1;
     }
     else if (counter == 0 && collision.gameObject.CompareTag("Player"))
     {
         velo.y = -velo.y;
         float deviateValue;
         deviateValue  = transform.position.x - collision.gameObject.transform.position.x;
         deviateValue /= collision.collider.bounds.size.x / 2f;
         deviateValue *= deviateFactor;
         velo.x       += deviateValue;
         counter       = 1;
     }
     if (collision.gameObject.tag == "walls" && counter == 0)
     {
         velo.x = -velo.x;
     }
 }
Ejemplo n.º 10
0
 public static void OnBrickGotHit(BrickController brick)
 {
     if (onBrickGotHit != null)
     {
         onBrickGotHit(brick);
     }
 }
Ejemplo n.º 11
0
        public void ItCanConnect()
        {
            var comm       = new BluetoothCommunication("COM4");
            var controller = new BrickController(comm);

            controller.Connect();
        }
Ejemplo n.º 12
0
    public static void BrickBroken(int points)
    {
        instance.score += points;
        instance.pointParticle.Play();
        instance.scoreUI.text = "Score: " + instance.score;

        if (Random.value < instance.powerUpChance)
        {
            instance.DropPowerUp();
        }

        bool hasWon = true;

        for (int i = 0; i < instance.brickList.Count; i++)
        {
            BrickController brick = instance.brickList[i];
            if (brick.gameObject.activeSelf)
            {
                hasWon = false;
                break;
            }
        }

        if (hasWon)
        {
            instance.sound.Stop();
            instance.sound.clip = instance.winner;
            instance.sound.Play();
            instance.level++;
            instance.leveltype = instance.level % 4;
            instance.CreateBricks();
        }
    }
Ejemplo n.º 13
0
 void Update()
 {
     if (!fbc.Visible())
     {
         BrickController bc = new BrickController();
         int             y  = GameObject.Find("Ball").GetComponent <BallController> ().getLife();
         int             z  = GameObject.Find("TimeText").GetComponent <Timer> ().getTime();
         if (bc.getScore() == 50 || (y == 2 && bc.getScore() == 200) || z == 10)
         {
             yapayZeka.transform.position = new Vector3(0.0f, 0.0f, 22.0f);
             isVisible(true);
         }
         if (yapayZeka.transform.position.z <= 3.0f)
         {
             Vector3 x = new Vector3(yapayZeka.transform.position.x, yapayZeka.transform.position.y, -3.0f);
             yapayZeka.destination = x;
         }
         else
         {
             yapayZeka.destination = player.transform.position;
         }
     }
     if (fbc.Visible())
     {
         isVisible(false);
     }
 }
Ejemplo n.º 14
0
    public void moveUp()
    {
        if (getNewBricks(Move.down) == null)
        {
            moveCurrentBricks(Move.down);
        }

        // Change row eat
        if (listEatingRows.Count > 0)
        {
            foreach (List <int> eatingRows in listEatingRows)
            {
                for (int i = eatingRows.Count - 1; i >= 0; i--)
                {
                    eatingRows[i]--;
                }
            }
        }

        // Copy Brick
        for (int i = 1; i < row; i++)
        {
            for (int j = 0; j < column; j++)
            {
                BrickController brick = bricks[i, j];
                if (brick.isShow && !currentBricks.Contains(brick))
                {
                    brick.setShow(false);
                    if (!usingSprite)
                    {
                        bricks[i - 1, j].setShow(true, brick.color);
                    }
                    else
                    {
                        bricks[i - 1, j].setShow(true, brick.sprite);
                    }
                }
            }
        }

        // Create Last Row
        for (int j = 0; j < column; j++)
        {
            bool isShow = Random.Range(0, 3) < 2 ? true : false;
            if (!usingSprite)
            {
                bricks[row - 1, j].setShow(isShow, colors[Random.Range(0, 7)]);
            }
            else
            {
                bricks[row - 1, j].setShow(isShow, sprites[Random.Range(0, 7)]);
            }
        }

        if (checkEat(row - 1))
        {
            bricks[row - 1, Random.Range(0, column)].setShow(false);
        }
    }
Ejemplo n.º 15
0
 private void OnBrickDestroy(BrickController brick)
 {
     _bricksOnLevel.Remove(brick);
     if (_bricksOnLevel.Count == 0)
     {
         _levelCompletedSignal.Fire();
     }
 }
Ejemplo n.º 16
0
        public async Task ItCanConnect()
        {
            var comm       = new MockCommunication();
            var controller = new BrickController(comm);
            await controller.Connect();

            Assert.AreEqual(1, comm.ReceivedData.Count);
        }
Ejemplo n.º 17
0
 public static void HitBrick(GameObject brick)
 {
     if (brick.CompareTag("Breakable"))
     {
         BrickController bc = brick.GetComponent <BrickController>();
         bc.handleHits();
     }
 }
Ejemplo n.º 18
0
 bool checkNewBrick(BrickController NewBrick)
 {
     if (NewBrick.isShow && !currentBricks.Contains(NewBrick))
     {
         return(false);
     }
     return(true);
 }
 void OnCollisionExit2D(Collision2D other)
 {
     if (other.gameObject.CompareTag("Brick"))
     {
         // Destroy(other.gameObject);
         brickC = other.gameObject.GetComponent <BrickController>();
         brickC.DestroyBrick();
     }
 }
Ejemplo n.º 20
0
        public async Task ItCanTurnMotor()
        {
            var comm       = new BluetoothCommunication("COM4");
            var controller = new BrickController(comm);

            controller.Connect();

            await controller.TurnMotorAsync(OutputPort.C, 50, 1);
        }
Ejemplo n.º 21
0
        public async Task ItCanTurnMotor()
        {
            var comm       = new MockCommunication();
            var controller = new BrickController(comm);
            await controller.Connect();

            await controller.TurnMotorAsync(OutputPort.A, 50, 1);

            Assert.AreEqual(2, comm.ReceivedData.Count);
        }
Ejemplo n.º 22
0
    // Brick layouts block
    private void InitBrick(GameObject brick)
    {
        BrickController bc = brick.GetComponent <BrickController>();

        PowerUpStatus(brick);         // determine if this brick has a power up
        if (bc.brick.isDestructable)
        {
            destructableBrickCount++;   // count bricks to be destroyed to complete level
        }
        brick.SetActive(true);
    }
Ejemplo n.º 23
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Destroy(gameObject);
        if (collision.gameObject.name == "Tilemap")
        {
            BrickController controller = collision.gameObject.GetComponent <BrickController>();


            controller.HandleBrickCollision(collision, _rigidbody2D.velocity.magnitude);
        }
    }
Ejemplo n.º 24
0
    private IEnumerator FixBrickDelay(BrickController brick)
    {
        if (brick.SpeedFall == 0)
        {
            yield break;
        }

        if (FixedBrickBeforeEvent != null)
        {
            FixedBrickBeforeEvent(this, null);
        }

        brick.SpeedFall = 0;

        var boxes = brick.GetBoxes();

        brick.DetachBoxes();

        foreach (GameObject box in boxes)
        {
            var pos = box.transform.localPosition;

            var x = Mathf.RoundToInt(pos.x);
            var y = Mathf.RoundToInt(pos.y);

            if (x < 0 || x >= Size.x || y < 0)
            {
                Destroy(box);
                continue;
            }
            else if (y >= Size.y)
            {
                continue;
            }

            pos.x = x;
            pos.y = y;
            box.transform.localPosition = pos;

            _field[x, y] = box;
        }

        yield return(StartCoroutine(DestroyLines()));

        if (!GameOver())
        {
            NewBrick();
        }

        if (FixedBrickAfterEvent != null)
        {
            FixedBrickAfterEvent(this, null);
        }
    }
Ejemplo n.º 25
0
        public async Task ItCanSendTankCommands()
        {
            var comm       = new MockCommunication();
            var controller = new BrickController(comm);

            Console.WriteLine("Connecting...");
            await controller.Connect();

            Console.WriteLine("Tank Move...");
            controller.TankMove(50, 50, 1);
            controller.TankMove(-50, -50, 1);
        }
Ejemplo n.º 26
0
        public void ItCanSendTankCommands()
        {
            var comm       = new BluetoothCommunication("COM4");
            var controller = new BrickController(comm);

            Console.WriteLine("Connecting...");
            controller.Connect();

            controller.TankMove(50, 50, 2);
            controller.TankMove(50, -50, 2);
            controller.TankMove(-50, -50, 2);
        }
Ejemplo n.º 27
0
        async void Button_OnClicked(object sender, EventArgs e)
        {
            var comm = DependencyService.Get <IXamarinCommunication>();

            var devices = await comm.GetDeviceList();

            var selection = await DisplayActionSheet("Select Bluetooth Device", "Cancel",
                                                     null, devices);

            comm.SelectDevice(selection);
            _controller = new BrickController(comm);
            await _controller.Connect();
        }
Ejemplo n.º 28
0
    void CreateBricks()
    {
        if (leveltype == 0)
        {
            brickPrefab      = brick1Prefab;
            instance.rows    = 5;
            instance.columns = 10;
        }
        else if (leveltype == 1)
        {
            brickPrefab      = brick2Prefab;
            instance.rows    = Random.Range(3, 6);
            instance.columns = Random.Range(5, 10);
        }
        else if (leveltype == 2)
        {
            brickPrefab      = brick3Prefab;
            instance.rows    = Random.Range(3, 6);
            instance.columns = Random.Range(5, 10);
        }
        else
        {
            brickPrefab      = brick4Prefab;
            instance.rows    = 1;
            instance.columns = 1;
        }

        for (int i = brickList.Count - 1; i >= 0; i--)
        {
            Destroy(brickList[i].gameObject);
        }
        brickList.Clear();

        Vector3 bottomLeft = Camera.main.ViewportToWorldPoint(new Vector3(edgePadding, bottomPadding, 0));
        Vector3 topRight   = Camera.main.ViewportToWorldPoint(new Vector3(1 - edgePadding, 1 - edgePadding, 0));

        bottomLeft.z = 0;
        float w = (topRight.x - bottomLeft.x) / (float)columns;
        float h = (topRight.y - bottomLeft.y) / (float)rows;

        for (int row = 0; row < instance.rows; row++)
        {
            for (int col = 0; col < instance.columns; col++)
            {
                BrickController brick = Instantiate(brickPrefab) as BrickController;
                brick.transform.position = bottomLeft + new Vector3((col + 0.5f) * w, (row + 0.5f) * h, 0);
                brickList.Add(brick);
            }
        }
    }
Ejemplo n.º 29
0
    public void DelBrick(BrickController brick)
    {
        //Remove brick from list
        bricksAtField.Remove(brick);

        //Increase points by brick health
        pointsCount += brick.countHealth;
        GUIManager.instance.RefreshPoints(pointsCount);

        //Check for bricks on the field
        if (bricksAtField.Count <= 0)
        {
            GUIManager.instance.GameOver(true);
        }
    }
Ejemplo n.º 30
0
    void Start()
    {
        boxCollider = gameObject.GetComponentInChildren <BoxCollider2D>();

        bricks          = GameObject.FindGameObjectWithTag("Bricks");
        brickController = bricks.GetComponent <BrickController>();

        Vector2 size       = new Vector2(Screen.width, Screen.height);
        Vector3 cameraSize = Camera.main.ScreenToWorldPoint(size);

        float cameraX = cameraSize.x;
        float cameraY = cameraSize.y;
        float cameraZ = cameraSize.z;

        transform.localScale = new Vector3(cameraX / 26f, cameraY / 16, cameraZ);
    }
Ejemplo n.º 31
0
    private IEnumerator FixBrickDelay(BrickController brick)
    {
        if (brick.SpeedFall == 0)
            yield break;

        if (FixedBrickBeforeEvent != null)
            FixedBrickBeforeEvent(this, null);

        brick.SpeedFall = 0;

        var boxes = brick.GetBoxes();
        brick.DetachBoxes();

        foreach (GameObject box in boxes)
        {
            var pos = box.transform.localPosition;

            var x = Mathf.RoundToInt(pos.x);
            var y = Mathf.RoundToInt(pos.y);

            if (x < 0 || x >= Size.x || y < 0)
            {
                Destroy(box);
                continue;
            }
            else if (y >= Size.y)
                continue;

            pos.x = x;
            pos.y = y;
            box.transform.localPosition = pos;

            _field[x, y] = box;
        }

        yield return StartCoroutine(DestroyLines());

        if (!GameOver())
            NewBrick();

        if (FixedBrickAfterEvent != null)
            FixedBrickAfterEvent(this, null);
    }
Ejemplo n.º 32
0
 public void FixBrick(BrickController brick)
 {
     StartCoroutine(FixBrickDelay(brick));
 }