   Pong Clone using XNA/C#
  I've been working on a clone of pong as my first real project. So far, I have the player paddle working, and the ball moving along with collision.I want to add more features to it, but I'm still inexperienced so I'm unsure of how to actually implement them.I want to:- Have the ball reset if it goes out of bounds- Add a way to change the speed of the ball's rebound if it hits a paddle- Some kind of simple AI for the other paddle- A means of keeping score. (And have the score displayed on screen)   
Quote:Original post by Slateboard- Have the ball reset if it goes out of boundsFirst, write a test to see whether the ball has gone out of bounds or not; then, if it has, reset its position.Quote:- Add a way to change the speed of the ball's rebound if it hits a paddleDecide the way in which you want to change the speed of the ball, and apply that change in the point where the rebound with the paddle is detected.Quote:- Some kind of simple AI for the other paddleSimple position tracking is easiest: If the ball is to the left of the paddle, move left; if the ball is to the right of the paddle, move right.Quote:- A means of keeping score. (And have the score displayed on screen)You'll need a variable to store the score in, you'll need to increment it when you score a point, and you'll need to somehow display the value of it when you are rendering everything.;  I Currently have it set to rebound if it goes out of bounds.if (Position3.X < 0) BallVelocity.X = +3;I tried to change it so that instead of rebounding, I'd change it's position.It worked, but it still maintained it's Y Momentum and would often move out of the paddle's reach. How can I have it reset and stop it's momentum?;  Just set all the values you care about. I'd recommend that you declare a couple of constants, BallStartPosition and BallStartVelocity, to store the initial position and velocity of the ball, and then you can just do:if(Position3.X < 0){  BallVelocity = BallStartVelocity;  Position3 = BallStartPosition;};  I've got it to reset the ball if it goes out of bounds.I have simple collision for the game, but I'd like to make it better.Presently, it simply rebounds in the direction it came from. I want to make it less predictable, but I'm unsure of how.;  When I make Pong, I detect where the ball collides with the paddle. If it's close to the edge, I increase the y velocity and decrease the x velocity. If it's toward the middle, I do the converse. Obviously, the more sectors you split your paddle into the more interesting bounces you'll get.   ;Quote:Original post by SlateboardPresently, it simply rebounds in the direction it came from. I want to make it less predictable, but I'm unsure of how.So, having it rebound completely in the way it came from - velocityAfter = -velocityBefore - is as if it's hit a surface 'head on,' a surface with a normal vector that is pointing exactly in the opposite direction to which the ball is travelling.If you just mean that you flip the X coordinate and leave the Y unchanged, then it's as if the ball is hitting a surface that is perfectly vertical - the normal of the surface is pointing dead right (or dead left).It'd be a good idea to generalise this. When the ball collides with a surface, you want to reflect the ball's velocity vector around the normal of the surface. Given that you're using XNA, you can use the Vector2.Reflect method to achieve this.Once that's written, you can vary the collision direction by varying the normal. For example, you could make it so the normal is dead-horizontal in the middle of the paddle, but pointed slightly down towards the bottom of the paddle and pointed slightly up towards the top of the paddle. The easiest way to do this is to take a vector from the center of the paddle to the center of the ball and use that as the normal. (You will probably want to normalize it, and you may want to scale the Y component of it by some value between 0 and 1 to stop the effect from being too extreme).Another thing you can do is to look at the System.Random class. You can use it to produce random numbers that you could use to make the normal slightly or entirely random.