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:
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.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'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)





)
Reply With Quote