public void Draw(Graphics g)
        {
            Camera.cameraMatrix.Transform(arrayNet);
            Camera.cameraMatrix.Transform(array);
            Camera.cameraMatrix.Transform(arrayOutline);
            Camera.cameraMatrix.Transform(arrayLine);

            Point[] netArray      = Camera.Transform(arrayNet);
            Point[] canvasArray   = Camera.Transform(array);
            Point[] canvasOutline = Camera.Transform(arrayOutline);
            Point[] lineArray     = Camera.Transform(arrayLine);

            if (childBall.zIndex == 0) //if behind enemy paddle
            {
                childBall.Draw(g);
            }

            //draw enemy paddle
            opponentPaddle.Draw(g);

            if (childBall.zIndex == 1) //if between table and enemy paddle
            {
                childBall.Draw(g);
            }

            //draw table
            g.FillPolygon(Brushes.White, canvasOutline);
            g.FillPolygon(Brushes.Blue, canvasArray);
            g.FillPolygon(Brushes.White, lineArray);

            if (childBall.zIndex == 2) //if after net
            {
                childBall.Draw(g);
            }

            //draw net
            g.FillPolygon(new HatchBrush(HatchStyle.SmallGrid, Color.White, Color.Blue), netArray);
            g.DrawPolygon(new Pen(Color.White, 2), netArray);

            if (childBall.zIndex == 3) // if before net
            {
                childBall.Draw(g);
            }

            // draw paddle
            ourPaddle.Draw(g);

            if (childBall.zIndex == 4) //if before paddle
            {
                childBall.Draw(g);
            }

            fillArrays();  //reset the transformed arrays
        }
Exemple #2
0
        public static void Run()
        {
            //on startup
            SetWindowSize();
            SetColor();
            Showbanner();
            Player.SetInitialPositon(player1);
            Player.SetInitialPositon(player2);
            Ball.SetInitialPoisition(ball);

            bool end = false;

            while (end == false)
            {
                //game
                Player.Move(player1, ball);
                Player.Move(player2, ball);
                Ball.Move(ball, player1, player2);

                Console.Clear();

                Player.DrawPosition1(player1);
                Player.DrawPosition2(player2);
                Ball.Draw(ball);

                Player.PrintScore(player1, player2);
                SlowDown();
                end = Outcome.Determine(player1, player2);
            }
        }
 protected override void Draw()
 {
     _player1.Draw();
     _player2.Draw();
     _ball.Draw();
     base.Draw();
     _gameField.PrintScore(String.Format("Player1       {0} : {1}       Player2", _score1, _score2));
 }
Exemple #4
0
        private void timer2_Tick(object sender, EventArgs e)
        {
            leftPad.Draw();
            rightPad.Draw();


            ball.ClearDraw();
            ball.Move(leftPad, rightPad);
            ball.Draw();
        }
Exemple #5
0
        private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.FillRectangle(Brushes.Black, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height);
            TheScore.Draw(g);
            TheScore2.Draw(g);
            ThePaddle.Draw(g);
            ThePaddle2.Draw(g);
            TheBall.Draw(g);

            if (Brick1.Visible == true)
            {
                Brick1.Draw(g);
            }
            if (Brick2.Visible == true)
            {
                Brick2.Draw(g);
            }
            if (Brick3.Visible == true)
            {
                Brick3.Draw(g);
            }
            if (Brick4.Visible == true)
            {
                Brick4.Draw(g);
            }
            if (Brick5.Visible == true)
            {
                Brick5.Draw(g);
            }
            if (Brick6.Visible == true)
            {
                Brick6.Draw(g);
            }
            if (Brick7.Visible == true)
            {
                Brick7.Draw(g);
            }
            if (Brick8.Visible == true)
            {
                Brick8.Draw(g);
            }
            if (Brick9.Visible == true)
            {
                Brick9.Draw(g);
            }
            if (Brick10.Visible == true)
            {
                Brick10.Draw(g);
            }
        }
Exemple #6
0
        public void timer1_Tick(object sender, EventArgs e)
        {
            gfx.Clear(Color.LightBlue);



            paddle1.draw(gfx);
            paddle2.draw(gfx);
            ball.Draw(gfx);
            if (ball.game)
            {
                ball.Move(ClientSize.Width, ClientSize.Height, paddle1, paddle2);
            }
            if (paddle1.drawHitBox == true && paddle2.drawHitBox == true)
            {
                //paddle1 hitbox
                gfx.DrawRectangle(bluePen, paddle1.hitbox.X, paddle1.hitbox.Y, paddle1.hitbox.Width, paddle1.hitbox.Height);

                //paddle2 hitbox right
                gfx.DrawRectangle(bluePen, paddle2.hitbox.X, paddle2.hitbox.Y, paddle2.hitbox.Width, paddle2.hitbox.Height);
            }
            if (bot)
            {
                if (ball.y < ClientSize.Height - 100 && ball.y > 5)
                {
                    paddle2.y        = ball.hitbox.Y;
                    paddle2.hitbox.Y = paddle2.y;
                }
            }


            greenPen.DashPattern = new float[] { 4.0F, 2.0F, 1.0F, 3.0F };
            // Draw a line.

            gfx.DrawLine(greenPen, ball.left, 0, paddle1.x - 40, ClientSize.Height);
            gfx.DrawLine(greenPen, ball.right, 0, ball.right, ClientSize.Height);


            // Change the SmoothingMode to none.
            gfx.SmoothingMode =
                System.Drawing.Drawing2D.SmoothingMode.None;

            drawText(gfx, "Rally: " + ball.rally, 48, 296, 9);
            drawText(gfx, "Paddle 1: " + ball.score1, 20, 23, 37);
            drawText(gfx, "Paddle 2: " + ball.score2, 20, 707, 37);

            if (ball.x <= ball.left)
            {
                //if ball is on left wall, point to right player
                ball.rally = 0;
                Console.Beep(300, 500);
                ball.game = false;
                ball.score2++;
                paddle1.y = ClientSize.Height / 2;
                paddle2.y = ClientSize.Height / 2;
                ball.x    = ClientSize.Width / 2;
                ball.y    = ClientSize.Height / 2;
                if (ball.score2 == 3)
                {
                    MessageBox.Show("Player 2 Won!");
                }
                else
                {
                    MessageBox.Show("Player 2 Won 1 Point");
                }
                paddle1.hitbox.Y = paddle1.y;
                paddle2.hitbox.Y = paddle2.y;
                ball.game        = true;
            }
            if (ball.x >= ball.right)
            {
                //if ball is on right wall, point is to left player
                ball.rally = 0;
                Console.Beep(300, 500);
                ball.game = false;
                ball.score1++;
                paddle1.y = ClientSize.Height / 2;
                paddle2.y = ClientSize.Height / 2;
                ball.x    = ClientSize.Width / 2;
                ball.y    = ClientSize.Height / 2;
                if (ball.score1 == 3)
                {
                    timer1.Enabled = false;
                    MessageBox.Show("Player 1 Won!");
                    ball.x    = ClientSize.Width / 2;
                    ball.y    = ClientSize.Height / 2;
                    paddle1.y = ClientSize.Height / 2;
                    paddle2.y = ClientSize.Height / 2;

                    ball.score1    = 0;
                    ball.score2    = 0;
                    ball.rally     = 0;
                    timer1.Enabled = true;
                }
                else
                {
                    MessageBox.Show("Player 1 Won 1 Point");
                }

                paddle1.hitbox.Y = paddle1.y;
                paddle2.hitbox.Y = paddle2.y;
                ball.game        = true;
            }

            if (ball.score2 == 3)
            {
                timer1.Enabled = false;
                MessageBox.Show("Player 2 Won!");
                ball.x    = ClientSize.Width / 2;
                ball.y    = ClientSize.Height / 2;
                paddle1.y = ClientSize.Height / 2;
                paddle2.y = ClientSize.Height / 2;

                ball.score1    = 0;
                ball.score2    = 0;
                ball.rally     = 0;
                timer1.Enabled = true;
            }
        }