Results 1 to 5 of 5

Thread: Pong in 2D - XNA GS2.0

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member BillGeek's Avatar
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    440

    Pong in 2D - XNA GS2.0

    Hi All

    I'm very new to XNA. I installed it last night, and started coding away. I'm busy writing a classic Pong game just to get my head around the "workings" of XNA, and I believe I'm almost done with it.

    Attached is my current project. The scoring is working, as well as the inputs, though I can't seem to get the collission detection running smoothly just yet.

    As it stands, the ball bounces off the top and bottom sides of the window, and the ball also bounces off the paddles, though what I've noticed is that even if you touch the ball with the back of the paddle (by moving your paddle to such a position that you can "graze" the ball) it still bounces back. I know why this happens, though I can't seem to figure out a workaround.

    The code for the collission at the moment:
    Code:
    if (ballPosition.Y <= 0)
        ballDirection = ballDirectionWay.downwardsLeft;
    else if (ballPosition.Intersects(paddleLeft))
        ballDirection=ballDirectionWay.upwardsRight;
    else if (ballPosition.X < (paddleLeft.X + paddleLeft.Width))
        playerDroppedBall(1);
    break;
    I'm making use of the "intersects" function / method in XNA which basically checks whether two Rectangles are intersecting each other. Like I said: It works, though just not perfectly.

    I've uploaded the source code if you guys want to have a look. I'd be grateful to anyone with suggestions!

    (And here's a screenshot of the game in action )
    Attached Images Attached Images  
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width