Esempio n. 1
0
        private void CheckPush()
        {
            for (int brick = 0; brick < _numBricks; brick++)
            {
                if (BrickCollection[brick].BrickFill != FillColorRed)
                {
                    continue;
                }

                InterectSide whichSide = IntersectsAt(BrickCollection[brick].BrickRectangle, _ballRectangle);
                switch (whichSide)
                {
                case InterectSide.NONE:
                    break;

                case InterectSide.TOP:
                    BrickCollection[brick].BrickCanvasTop += _pushMove;
                    break;

                case InterectSide.BOTTOM:
                    BrickCollection[brick].BrickCanvasTop -= _pushMove;
                    break;

                case InterectSide.LEFT:
                    BrickCollection[brick].BrickCanvasLeft += _pushMove;
                    break;

                case InterectSide.RIGHT:
                    BrickCollection[brick].BrickCanvasLeft -= _pushMove;
                    break;
                }
            }
        }
Esempio n. 2
0
        void check()
        {
            InterectSide side = IntersectsAt(_paddleRectangle, _ballRectangle);

            if (PaddleFill == RedColor)
            {
                switch (side)
                {
                case InterectSide.NONE:
                    break;

                case InterectSide.TOP:
                    paddleCanvasTop += 10;
                    _paddleRectangle = new System.Drawing.Rectangle((int)paddleCanvasLeft, (int)paddleCanvasTop, (int)paddleWidth, (int)paddleHeight);
                    break;

                case InterectSide.BOTTOM:
                    paddleCanvasTop -= 10;
                    _paddleRectangle = new System.Drawing.Rectangle((int)paddleCanvasLeft, (int)paddleCanvasTop, (int)paddleWidth, (int)paddleHeight);
                    break;

                case InterectSide.RIGHT:
                    paddleCanvasLeft -= 10;
                    _paddleRectangle  = new System.Drawing.Rectangle((int)paddleCanvasLeft, (int)paddleCanvasTop, (int)paddleWidth, (int)paddleHeight);
                    break;

                case InterectSide.LEFT:
                    paddleCanvasLeft += 10;
                    _paddleRectangle  = new System.Drawing.Rectangle((int)paddleCanvasLeft, (int)paddleCanvasTop, (int)paddleWidth, (int)paddleHeight);
                    break;
                }
            }
        }
Esempio n. 3
0
        private void CheckPush()
        {
            if (BrickFill != FillColorRed)
            {
                return;
            }

            InterectSide whichSide = IntersectsAt(BrickRectangle, _BallRectangle);

            switch (whichSide)
            {
            case InterectSide.NONE:
                break;

            case InterectSide.TOP:
                BrickCanvasTop += _pushMove;
                break;

            case InterectSide.BOTTOM:
                BrickCanvasTop -= _pushMove;
                break;

            case InterectSide.LEFT:
                BrickCanvasLeft += _pushMove;
                break;

            case InterectSide.RIGHT:
                BrickCanvasLeft -= _pushMove;
                break;
            }
        }
Esempio n. 4
0
        private void CheckCollision()
        {
            for (int brick = 0; brick < _numBricks; brick++)
            {
                InterectSide whichSide = IntersectsAt(BrickCollection[brick].BrickRectangle, _ballRectangle);
                switch (whichSide)
                {
                case InterectSide.NONE:
                    break;

                case InterectSide.TOP:
                    // Hidde the brick that is hit
                    BrickCollection[brick].BrickVisible = Visibility.Hidden;
                    // Delete the brick that is hit
                    BrickCollection[brick].BrickRectangle = Rectangle.Empty;
                    // Play the hit brick sound effect
                    HitBrick.Play();
                    Score += 1;
                    numBricksHit++;
                    // Call function CheckWin to determine user win the game or not
                    CheckWin();
                    break;

                case InterectSide.BOTTOM:
                    BrickCollection[brick].BrickVisible   = Visibility.Hidden;
                    BrickCollection[brick].BrickRectangle = Rectangle.Empty;
                    HitBrick.Play();
                    Score += 1;
                    numBricksHit++;
                    CheckWin();
                    break;

                case InterectSide.LEFT:
                    BrickCollection[brick].BrickVisible   = Visibility.Hidden;
                    BrickCollection[brick].BrickRectangle = Rectangle.Empty;
                    HitBrick.Play();
                    Score += 1;
                    numBricksHit++;
                    CheckWin();
                    break;

                case InterectSide.RIGHT:
                    BrickCollection[brick].BrickVisible   = Visibility.Hidden;
                    BrickCollection[brick].BrickRectangle = Rectangle.Empty;
                    HitBrick.Play();
                    Score += 1;
                    numBricksHit++;
                    CheckWin();
                    break;
                }
            }
        }
Esempio n. 5
0
        private void CheckPush()
        {
            timer();
            for (int brick = 0; brick < _numBricks; brick++)
            {
                if (BrickCollection[brick].BrickVisible == Visibility.Hidden)
                {
                    continue;
                }

                InterectSide whichSide = IntersectsAt(BrickCollection[brick].BrickRectangle, _ballRectangle);
                switch (whichSide)
                {
                case InterectSide.NONE:
                    break;

                case InterectSide.TOP:
                    BrickCollection[brick].BrickVisible = Visibility.Hidden;
                    _ballYMove      = -_ballYMove;
                    ballCanvasTop  += 2 * _ballYMove;
                    ballCanvasLeft += _randomNumber.Next(5);
                    Score++;

                    break;

                case InterectSide.BOTTOM:
                    BrickCollection[brick].BrickVisible = Visibility.Hidden;
                    _ballYMove      = -_ballYMove;
                    ballCanvasTop  += 2 * _ballYMove;
                    ballCanvasLeft += _randomNumber.Next(5);
                    Score++;
                    break;

                case InterectSide.LEFT:
                    BrickCollection[brick].BrickVisible = Visibility.Hidden;
                    _ballXMove      = -_ballXMove;
                    ballCanvasTop  += 2 * _ballXMove;
                    ballCanvasLeft += _randomNumber.Next(5);
                    Score++;
                    break;

                case InterectSide.RIGHT:
                    BrickCollection[brick].BrickVisible = Visibility.Hidden;
                    _ballXMove      = -_ballXMove;
                    ballCanvasTop  += 2 * _ballXMove;
                    ballCanvasLeft += _randomNumber.Next(5);
                    Score++;
                    break;
                }
            }
        }
Esempio n. 6
0
        private void CheckTouch()
        {
            //start playing music at the beginning of the game
            var         GameMusics = Resources.BrickFX;
            SoundPlayer GameMusic  = new SoundPlayer(GameMusics);

            for (int brick = 0; brick < _numBricks; brick++)
            {
                if (BrickCollection[brick].BrickVisible != Visibility.Collapsed)
                {
                    InterectSide whichSide = IntersectsAt(BrickCollection[brick].BrickRectangle, _ballRectangle);
                    switch (whichSide)
                    {
                    case InterectSide.NONE:
                        break;

                    case InterectSide.TOP:
                        BrickCollection[brick].BrickVisible = Visibility.Collapsed;
                        _ballYMove    = -_ballYMove;
                        ScoreCounter += 10;
                        GameMusic.Play();
                        Console.WriteLine("Hit the Top Side of Brick #" + brick + "/" + _numBricks);
                        return;

                    case InterectSide.BOTTOM:
                        BrickCollection[brick].BrickVisible = Visibility.Collapsed;
                        _ballYMove    = -_ballYMove;
                        ScoreCounter += 10;
                        GameMusic.Play();
                        Console.WriteLine("Hit the Bottom Side of Brick #" + brick + "/" + _numBricks);
                        return;

                    case InterectSide.LEFT:
                        BrickCollection[brick].BrickVisible = Visibility.Collapsed;
                        _ballXMove    = -_ballXMove;
                        ScoreCounter += 10;
                        GameMusic.Play();
                        Console.WriteLine("Hit the Left Side of Brick #" + brick + "/" + _numBricks);
                        return;

                    case InterectSide.RIGHT:
                        BrickCollection[brick].BrickVisible = Visibility.Collapsed;
                        _ballXMove    = -_ballXMove;
                        ScoreCounter += 10;
                        GameMusic.Play();
                        Console.WriteLine("Hit the Right Side of Brick #" + brick + "/" + _numBricks);
                        return;
                    }
                }
            }
        }
Esempio n. 7
0
        private void CheckPush() //----------------------------------------------------------------------------
        {
            for (int brick = 0; brick < numCol * numRow; brick++)
            {
                if (BrickCollection[brick].BrickVisible == Visibility.Hidden)
                {
                    continue;
                }

                InterectSide whichSide = IntersectsAt(BrickCollection[brick].BrickRectangle, _ballRectangle);
                switch (whichSide)
                {
                case InterectSide.NONE:
                    //  BrickCollection[brick].BrickVisible = Visibility.Hidden;
                    //  score++;
                    break;

                case InterectSide.TOP:
                    BrickCollection[brick].BrickVisible = Visibility.Hidden;
                    _ballYMove *= -1;
                    score++;
                    Scored = score.ToString();
                    break;

                case InterectSide.BOTTOM:
                    BrickCollection[brick].BrickVisible = Visibility.Hidden;
                    _ballYMove *= -1;
                    score++;
                    Scored = score.ToString();
                    break;

                case InterectSide.LEFT:
                    BrickCollection[brick].BrickVisible = Visibility.Hidden;
                    _ballXMove *= -1;
                    score++;
                    Scored = score.ToString();
                    break;

                case InterectSide.RIGHT:
                    BrickCollection[brick].BrickVisible = Visibility.Hidden;
                    _ballXMove *= -1;
                    score++;
                    Scored = score.ToString();
                    break;
                }
            }
        }
Esempio n. 8
0
        private void BallMMTimerCallback(IntPtr pWhat, bool success)
        {
            if (!_moveBall)
            {
                return;
            }

            // start executing callback. this ensures we are synched correctly
            // if the form is abruptly closed
            // if this function returns false, we should exit the callback immediately
            // this means we did not get the mutex, and the timer is being deleted.
            if (!_ballHiResTimer.ExecutingCallback())
            {
                Console.WriteLine("Aborting timer callback.");
                return;
            }

            ballCanvasLeft += _ballXMove;
            ballCanvasTop  += _ballYMove;

            // check to see if ball has it the left or right side of the drawing element
            if ((ballCanvasLeft + BallWidth >= _windowWidth) ||
                (ballCanvasLeft <= 0))
            {
                _ballXMove = -_ballXMove;
            }


            // check to see if ball has it the top of the drawing element
            if (ballCanvasTop <= 0)
            {
                _ballYMove = -_ballYMove;
            }

            if (ballCanvasTop + BallWidth >= _windowHeight)
            {
                // we hit bottom. stop moving the ball
                _moveBall = false;
                _mytimer.Stop();
            }

            // see if we hit the paddle
            _ballRectangle = new System.Drawing.Rectangle((int)ballCanvasLeft, (int)ballCanvasTop, (int)BallWidth, (int)BallHeight);
            if (_ballRectangle.IntersectsWith(_paddleRectangle))
            {
                // hit paddle. reverse direction in Y direction
                _ballYMove = -_ballYMove;

                // move the ball away from the paddle so we don't intersect next time around and
                // get stick in a loop where the ball is bouncing repeatedly on the paddle
                ballCanvasTop += 2 * _ballYMove;

                // add move the ball in X some small random value so that ball is not traveling in the same
                // pattern
                ballCanvasLeft += _randomNumber.Next(5);
            }

            // done in callback. OK to delete timer
            _ballHiResTimer.DoneExecutingCallback();


            //UPDATE THE RECTANGLES HERE
            for (int brick = 0; brick < _numBricks; brick++)
            {
                BrickCollection[brick].BrickRectangle = new System.Drawing.Rectangle((int)BrickCollection[brick].BrickCanvasLeft, (int)BrickCollection[brick].BrickCanvasTop, (int)BrickCollection[brick].BrickWidth, (int)BrickCollection[brick].BrickHeight);
                if (BrickCollection[brick].BrickFill != FillColorRed)
                {
                    continue;
                }

                InterectSide whichSide = IntersectsAt(BrickCollection[brick].BrickRectangle, _ballRectangle);
                switch (whichSide)
                {
                case InterectSide.NONE:
                    break;

                case InterectSide.TOP:
                    if (BrickCollection[brick].BrickVisible == System.Windows.Visibility.Visible)
                    {
                        _ballYMove = -_ballYMove;
                        BrickCollection[brick].BrickVisible = System.Windows.Visibility.Hidden;
                        ScoreBlock++;
                    }

                    break;

                case InterectSide.BOTTOM:

                    if (BrickCollection[brick].BrickVisible == System.Windows.Visibility.Visible)
                    {
                        _ballYMove = -_ballYMove;
                        BrickCollection[brick].BrickVisible = System.Windows.Visibility.Hidden;
                        ScoreBlock++;
                    }
                    break;

                case InterectSide.LEFT:

                    if (BrickCollection[brick].BrickVisible == System.Windows.Visibility.Visible)
                    {
                        _ballXMove = -_ballXMove;
                        BrickCollection[brick].BrickVisible = System.Windows.Visibility.Hidden;
                        ScoreBlock++;
                    }
                    break;

                case InterectSide.RIGHT:

                    if (BrickCollection[brick].BrickVisible == System.Windows.Visibility.Visible)
                    {
                        _ballXMove = -_ballXMove;
                        BrickCollection[brick].BrickVisible = System.Windows.Visibility.Hidden;
                        ScoreBlock++;
                    }
                    break;
                }
            }
        }
Esempio n. 9
0
        private void BallMMTimerCallback(IntPtr pWhat, bool success)
        {
            if (!_moveBall)
            {
                return;
            }

            if (!_ballHiResTimer.ExecutingCallback())
            {
                Console.WriteLine("Aborting timer callback.");
                return;
            }

            BallCanvasLeft += _ballXMove;
            BallCanvasTop  += _ballYMove;

            if (BallCanvasTop + BallWidth >= _windowHeight)
            {
                _moveBall = false;
            }

            _ballRectangle = new System.Drawing.Rectangle((int)BallCanvasLeft, (int)BallCanvasTop, (int)BallWidth, (int)BallHeight);

            if (_ballRectangle.IntersectsWith(_paddleRectangle))
            {
                _ballYMove      = -_ballYMove;
                BallCanvasTop  += 2 * _ballYMove;
                BallCanvasLeft += _randomNumber.Next(5);
            }

            if ((BallCanvasLeft + BallWidth >= _windowWidth) ||
                (BallCanvasLeft <= 0))
            {
                _ballXMove = -_ballXMove;
            }

            if (BallCanvasTop <= 0)
            {
                _ballYMove = -_ballYMove;
            }

            bool found = false;

            //// check to see if we hit a visible block
            for (int brick = 0; brick < BrickCollection.Count; brick++)
            {
                // if the current brick is not visible, just continue on to the next brick
                if (BrickCollection[brick].BrickVisibility == Visibility.Hidden)
                {
                    continue;
                }

                //    // make a rectangle for the current brick so we can
                //    // check for a collision with the ball
                Rectangle brickRectangle = new Rectangle(
                    (int)BrickCollection[brick].BrickCanvasLeft,
                    (int)BrickCollection[brick].BrickCanvasTop,
                    (int)BrickCollection[brick].BrickWidth - 1,
                    (int)BrickCollection[brick].BrickHeight - 1);

                //    // if the brick and ball do not intersect, just keep going
                //    // don't waste time findout out exactly where they intersect, because
                //    // they don'
                if (brickRectangle.IntersectsWith(_ballRectangle) == false)
                {
                    continue;
                }

                //    // ok, find out where they intersect so we can determine which
                //    // direction to bounce the ball
                InterectSide intersection = IntersectsAt(brickRectangle, _ballRectangle);
                switch (intersection)
                {
                case InterectSide.NONE:
                    break;

                case InterectSide.BOTTOM:
                case InterectSide.TOP:
                    if (BrickCollection[brick].BrickVisibility == System.Windows.Visibility.Visible)
                    {
                        BrickCollection[brick].BrickVisibility = System.Windows.Visibility.Hidden;
                        _ballYMove = -_ballYMove;
                        found      = true;
                    }
                    break;

                case InterectSide.LEFT:
                case InterectSide.RIGHT:
                    if (BrickCollection[brick].BrickVisibility == System.Windows.Visibility.Visible)
                    {
                        BrickCollection[brick].BrickVisibility = System.Windows.Visibility.Hidden;
                        _ballXMove = -_ballXMove;
                        found      = true;
                    }
                    break;
                }
                //    // if we found a collision, break;
                if (found)
                {
                    break;
                }
            }
            //// done in callback. OK to delete timer
            _ballHiResTimer.DoneExecutingCallback();
        }