Jump to content
  • Advertisement
Sign in to follow this  

(XNA) beginner code questions

This topic is 4162 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm writing a pong clone as my first game and everything is fine up to this point. My first question is..I have 3 images, two paddles and a ball. I need to check a collision for a maximum Y coordinate that the images can move to. Since my paddles are different sizes than my balls, does this mean I have to create seperate variables..for example this is what I have.
int maxY = Window.ClientBounds.Height - 90;
int ballMaxY = Window.ClientBounds.Height - 50;
is there anyway where I can just have one variable and somehow determine how much to subtract from the Window.ClientBounds.Height? My second question has to do with the ball movement and collision. I did write a pong program in Blitz Basic if any of you have used that, but I forgot how I did it. I remember I had to use ballXVelocity or something in the math part. Can someone give me a quick template to look at? Thanks!! Mark

Share this post

Link to post
Share on other sites
Your best bet is going to be creating what is called a bounding box.
In a 2d game you are looking at 2 2d vectors describing the min and max values for the game objects. These are members of your object class and are used when testing for collisions.

For instance

struct BBox
Vector2 min;
Vector2 max;

The min is the offset from the center of your object to the lower left corner, and the max is the offset from the center of your object to the upper right. (Or if you have flipped your axis ie. your Y value increases as you go down the screen, you can reverse the min and max to make more sense).

After that, you will simply test collisions by using the X,Y position of your object + the bounding offsets. This makes for less code and less headaches trying to keep it straight which side of the object you should be testing.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!