Pong?

This is a discussion on Pong? within the Game Programming forums, part of the General Programming Boards category; I've been programming in C++ for about 2 months, then I decided to take a break to keep my grades ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    3

    Pong?

    I've been programming in C++ for about 2 months, then I decided to take a break to keep my grades high. Now, I'm almost in high school and I've decided to take a Java class. So, I decided to get back into programming. I tried to make a pong game in C++ but just couldn't do it. Any help or suggestions or anything to start me off would be MUCH appreciated.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Start with something simpler then.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    ---
    Join Date
    May 2004
    Posts
    1,379
    What's simpler than pong?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    tic-tac-toe maybe?
    hangman
    various guessing games

    > I tried to make a pong game in C++ but just couldn't do it.
    Well that's vague - which bit was the problem?
    Choosing a graphics library?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    Don't go with java, C++ would be better.
    If you can deal with C++, you should move on to DirectX or OpenGL. I personal like OpenGL. pong game only take me 10 to 15 mins to make with opengl. It's your choice then.
    Hello, testing testing. Everthing is running perfectly...for now

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    3
    Actually, Java is the only programming class at that school, other that QBASIC which I don't want to take. The problem is, I just don't know how to start. Like, how do I make the ball bounce, how do I make the "walls" for the ball to bounce off of, how do I make the ball bounce off the paddles and etc. etc.. Oh, yeah I also have a question. Do I need to use some kind of graphics library like OpenGL or is it possible to program the whole entire game in just C++ using Dev-C++?

    And I've already made a few Hangman and Tic-Tac-Toe games but Pong is just stumping me for some reason.

  7. #7
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    You can make pong using Dev. It has an openGL project option - look under new project, click the mulit-media tab. Learning OpenGl is tricky, it involvs mainly windows programming, which is tough anyway. If you have a good handle on the basics of C++, and the more advanced topics like pointers, OOP , templates and vectors, then learning OpenGL should not be too tough. Read the tutorial on this site about openGl to get you started.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    > Do I need to use some kind of graphics library like OpenGL
    > or is it possible to program the whole entire game in just C++ using Dev-C++?
    Well if you want everything drawn with printable text, then some kind of graphics is in order.
    Dev-c++ has a downloadable package of libsdl (http://www.libsdl.org/index.php), which is a bit like opengl-lite.

    If you make your way through the tutorials on that site, you should be in good shape.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    If you want the ball to bounce :
    Declare float X, Y, dir;
    X,Y - current position
    dir - current angle
    the ball should go like this
    X += cos(dir);
    Y += sin(dir);
    when the ball hits something, just change the dir
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Actually you will want something like this so you don't have to mess with angles except to set the initial x,y vector amounts for the ball. This also allows you to account for frame rendering time as well as ball speed which you can alter at will to increase/decrease the difficulty of the game.

    Code:
    class Ball
    {
      float m_fVx,m_fVy;
      float m_fSpeed;
      float m_fX,m_fY;
      public:
        ...
        void SetAngle(float angle)
        {
           m_fVx=cosf(angle);
           m_fVy=sinf(angle);
        }
        
        void Update(float fTimeElapsed)
        {
           m_fX+=(m_fVx*m_fSpeed*fTimeElapsed);
           m_fY+=(m_fVy*m_fSpeed*fTimeElapsed);
        }
        ....
    };
    For collision with walls and response you can do several things:

    1. Simple collision detection based on position (x>wall.x, y>wall.y, etc..)
    2. Collision using dot product and normals for response.
    3. Per-pixel collision detection via time intervals instead of option 1. Compute the time at which the objects will collide. If interval is empty or infinite, objects will not collide in next frame.
    4. For response, create triangle using last x,y of ball and wall hit x,y for ball. Use trig to determine resulting vector. Set last x,y of ball to current x,y, wash, rinse, repeat.

  11. #11
    Banned SniperSAS's Avatar
    Join Date
    Aug 2005
    Posts
    175
    i posted a thread dealing with a problem regarding my pong game, after mr wizard helped me out i posted the working code

    My pong game stops painting

    it's pretty messy but maybe it will help you out

    edit- put the actual URL in
    Last edited by SniperSAS; 05-12-2006 at 02:43 PM.

  12. #12
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    I remember this thread, that was you or just the wrong link?

  13. #13
    Banned SniperSAS's Avatar
    Join Date
    Aug 2005
    Posts
    175
    d'oh! i copy and pasted the wrong thing!

    also hell no that guy was retarded, and i stick to FYAD pretty much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Space Pong (Debug) Release
    By Jeremy G in forum Game Programming
    Replies: 6
    Last Post: 10-02-2005, 07:14 PM
  2. The Story Of Pong (my game cookie)
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 05-16-2005, 11:14 PM
  3. pong
    By lambs4 in forum Game Programming
    Replies: 2
    Last Post: 06-02-2003, 04:00 PM
  4. Battle Pong
    By DOlson in forum Game Programming
    Replies: 13
    Last Post: 01-08-2003, 10:32 PM
  5. God pong -update
    By gamegod3001 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-03-2001, 09:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21