Example #1
0
        private void BulletMMTimerCallback(IntPtr pWhat, bool success)
        {
            if (!_moveBullet)
            {
                return;
            }

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

            if (BulletCanvasTop > 0)
            {
                BulletCanvasTop -= _bulletSpeed;
            }

            if (BulletCanvasTop <= 0)
            {
                BulletVisibility = System.Windows.Visibility.Hidden;
                _moveBullet      = false;
            }

            _bulletRectangle = new System.Drawing.Rectangle((int)BulletCanvasLeft, (int)BulletCanvasTop, (int)BulletWidth, (int)BulletHeight);
            _bulletHiResTimer.DoneExecutingCallback();
        }
        private void PaddelMMTimerCallback(IntPtr pWhat, bool success)
        {
            // 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 (!_paddelHiResTimer.ExecutingCallback())
            {
                Console.WriteLine("Aborting timer callback.");
                return;
            }

            if (_movePaddelLeft && PaddelCanvasLeft > 0)
            {
                PaddelCanvasLeft -= 2;
            }
            else if (_movePaddelRight && PaddelCanvasLeft < _windowWidth - PaddelWidth)
            {
                PaddelCanvasLeft += 2;
            }

            _paddelRectangle = new System.Drawing.Rectangle((int)PaddelCanvasLeft, (int)PaddelCanvasTop, (int)PaddelWidth, (int)PaddelHeight);


            // done in callback. OK to delete timer
            _paddelHiResTimer.DoneExecutingCallback();
        }
        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;
            }

            // see if we hit the paddle
            _ballRectangle = new System.Drawing.Rectangle((int)BallCanvasLeft, (int)BallCanvasTop, (int)BallWidth, (int)BallHeight);
            if (_ballRectangle.IntersectsWith(_paddelRectangle))
            {
                // 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();
        }
Example #4
0
        private void EnemyMMTimerCallback(IntPtr pWhat, bool success)
        {
            if (!_enemyOnScreen)
            {
                return;
            }

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

            if (EnemyCanvasTop < _windowHeight)
            {
                EnemyCanvasTop += _enemySpeed;
            }

            if (_enemyRectangle.IntersectsWith(_bulletRectangle) &&
                BulletVisibility == System.Windows.Visibility.Visible &&
                EnemyVisibility == System.Windows.Visibility.Visible)
            {
                EnemyVisibility  = System.Windows.Visibility.Hidden;
                BulletVisibility = System.Windows.Visibility.Hidden;
                Points          += 1;
                (new System.Media.SoundPlayer("../../sounds/death.wav")).Play();
                setEnemyStartPos();
            }

            if ((_enemyRectangle.IntersectsWith(_paddleRectangle) ||
                 EnemyCanvasTop >= _windowHeight) &&
                EnemyVisibility == System.Windows.Visibility.Visible)
            {
                EnemyVisibility = System.Windows.Visibility.Hidden;
                Gameover();
            }

            _enemyRectangle = new System.Drawing.Rectangle((int)EnemyCanvasLeft, (int)EnemyCanvasTop, (int)EnemyWidth, (int)EnemyHeight);

            try
            {
                _enemyHiResTimer.DoneExecutingCallback();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #5
0
        /*       private void homeMadeTimer() {
         *         while (_moveBall)
         *         {
         *             if (ticks > 1000)
         *             {
         *                 GameTime++;
         *                 Gametimed = GameTime.ToString();
         *             }
         *
         *         }
         *
         *
         *     } */


        private void allTimeMMTimerCallback(IntPtr pWhat, bool success)
        {
            if (!_moveBall)
            {
                return;
            }
            if (_moveBall)
            {
                ticks++;
            }


            if (ticks > 1000)
            {
                GameTime++;
                Gametimed = GameTime.ToString();
            }


            // 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 (!_timerAll.ExecutingCallback())
            {
                Console.WriteLine("Aborting timer callback.");
                return;
            }


            if (ballCanvasTop + BallWidth >= _windowHeight)
            {
                // we hit bottom. stop moving the ball reset the timer
                ticks = 0;
            }



            _timerAll.DoneExecutingCallback();
        }
Example #6
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;
                }
            }
        }
Example #7
0
        private void BallMMTimerCallback(IntPtr pWhat, bool success)
        {
            var         GameMusics = Resources.PaddleFX;
            SoundPlayer paddle     = new SoundPlayer(GameMusics);

            GameMusics = Resources.WallFX;
            SoundPlayer wall = new SoundPlayer(GameMusics);

            GameMusics = Resources.FailedFX;
            SoundPlayer failed = new SoundPlayer(GameMusics);

            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;
                wall.Play();
            }

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

            // check to see if ball has hit the bottom of the drawing element
            if (ballCanvasTop + ballWidth >= _windowHeight)
            {
                // we hit bottom. stop moving the ball
                _moveBall = false;
                hitBottom++;
                if (hitBottom >= 3)
                {
                    failed.Play();
                    GameOver  = Visibility.Visible;
                    hitBottom = 0;
                }
            }

            // see if we hit the paddle
            _ballRectangle = new System.Drawing.Rectangle((int)ballCanvasLeft, (int)ballCanvasTop, (int)ballWidth, (int)ballHeight);
            if (_ballRectangle.IntersectsWith(_paddleRectangle))
            {
                paddle.Play();
                // 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);
            }

            //see if we hit a brick
            CheckTouch();

            // done in callback. OK to delete timer
            _ballHiResTimer.DoneExecutingCallback();
        }
Example #8
0
        private void BallMMTimerCallback(IntPtr pWhat, bool success)
        {
            var uiContext = SynchronizationContext.Current;

            if (!_moveBall)
            {
                return;
            }

            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;
                GameOver  = "Game Over";
                dotNetDispatchTimer.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);
            }

            // see if we hit the brick
            CheckTouch();

            // done in callback. OK to delete timer
            _ballHiResTimer.DoneExecutingCallback();
        }
Example #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();
        }