locked
How to create a vintage pong game using C# and the GDIDrawer in visual studio. RRS feed

  • Question

  • Hello everyone, 

    As an aspiring game developer, I have decided to recreate the classic virtual tennis game Pong in Visual Studio using the C# language and GDIDrawer.

    The problem with this is that I have very little programming experience. This is all I have at the moment: (but I still need to create a three sided border and a paddle for the ball to bounce off) any help or tips and tricks on how to complete what is missing would be greatly appreciated.

                                                                                                    

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using GDIDrawer;
    using System.Drawing;

    namespace ping pong practice mode
    {
        class Program
        {
            static void Main(string[] args)
            {
                //x ball position
                int iX = 0;

                //y ball position
                int iY = 0;

                //amount ball moves in x direction for every loop
                int iXVelocity = 5;

                //amount ball moves in y direction for every loop
                int iYVelocity = 5; 

                //create a drawer window with a scale of 10
                CDrawer Canvas = new CDrawer();
                Canvas.Scale = 5;
                //loop until the ball leaves the visible window
                while ((iX < 160) || (iX > 0))
                {
                    //erase the old ball
                    Canvas.Clear();

                    //draw the new ball
                    Canvas.AddEllipse(iX, iY, 1, 1);

                    //time delay to slow down the ball
                    System.Threading.Thread.Sleep(150);

                    //calculate the ball's new position
                    iX += iXVelocity;
                    iY += iYVelocity;

                    //check for bouncing off of the lower edge of the window
                    if ((iY > 120) || (iY < 0))
                        //reverse the y velocity (ball goes up)
                        iYVelocity = -iYVelocity;

                }

            }
        }
    }


    Thursday, October 22, 2020 9:04 PM

Answers

  • There are several examples out there to check out

    https://github.com/goldenshun/ping-pong/tree/master/PingPong

    https://github.com/mara90/PingPong


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Pb4ugo69 Thursday, October 22, 2020 11:15 PM
    Thursday, October 22, 2020 9:51 PM

All replies

  • There are several examples out there to check out

    https://github.com/goldenshun/ping-pong/tree/master/PingPong

    https://github.com/mara90/PingPong


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Pb4ugo69 Thursday, October 22, 2020 11:15 PM
    Thursday, October 22, 2020 9:51 PM
  • Awesome, thank you. Ill definitely check out the link posted.
    Thursday, October 22, 2020 11:15 PM