Beispiel #1
0
        private void TimerTick(object sender, ElapsedEventArgs e)
        {
            if (GameStage == "Countdown") //countdown to ball launch
            {
                counter++;
                if (counter == 50) //triggers every half second
                {
                    countdown--;
                    counter = 0;
                }
                if (countdown == -1)
                {
                    ball.Launch(BoxWidth);
                    GameStage = "Started";
                }
            }
            if (GameStage == "Started") //round in play
            {
                leftPaddle.UpdatePosition();
                rightPaddle.UpdatePosition();
                ball.UpdatePosition();

                if (ball.Xlocation <= 0 - ball.size) //right scores
                {
                    rightScore++;
                    ToCountdown();
                }
                else if (ball.Xlocation <= 10 + leftPaddle.width && ball.Xlocation >= 10 && ball.Ylocation >= leftPaddle.Ylocation && ball.Ylocation <= leftPaddle.Ylocation + leftPaddle.height)
                {
                    ball.Hit(leftPaddle);
                }
                if (ball.Xlocation >= BoxWidth) //left scores
                {
                    leftScore++;
                    ToCountdown();
                }
                if (ball.Xlocation >= BoxWidth - 10 - rightPaddle.width - ball.size && ball.Xlocation <= BoxWidth - 10 - ball.size && ball.Ylocation >= rightPaddle.Ylocation && ball.Ylocation <= rightPaddle.Ylocation + rightPaddle.height)
                {
                    ball.Hit(rightPaddle);
                }

                if (rightScore == WinScore)
                {
                    clock.Enabled = false;
                    Gameover("RIGHT");
                }
                else if (leftScore == WinScore)
                {
                    clock.Enabled = false;
                    Gameover("LEFT");
                }
            }

            PongBox.Invalidate();
        }
Beispiel #2
0
 private void UpdateInput()
 {
     player1Paddle.UpdatePosition(GraphicsDevice);
     player2Paddle.UpdatePosition(GraphicsDevice);
     ball.UpdatePosition(player1Paddle, player2Paddle);
 }