Jump to content
  • Advertisement
Sign in to follow this  
Don_Wuh

The Basics?

This topic is 4839 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

can anyone tell me how to create a big black box with two white smaller boxs bouncing around in side and if they hit the wall or each other then they bounce off in the other direction

Share this post


Link to post
Share on other sites
Advertisement
This is more of a physics question than an AI question however, it's not a difficult question. Basically your objects will have an x and a y speed, so if they hit say the top or bottom of the box, multiply the y speed by -1, if they hit the left or right side multiply the x speed by -1. You must also make sure you make conditions for the 4 corners where both speeds would be mutliplied by -1. Now this is very simplified, and will only work when working with hit testing perfect squares, otherwise you'll have to brush up on some trig/elastic collisions. To do the hit testing, just keep checking whether or not a side of your square is outside the playing field. If you are unsure how to draw the squares, I would suggest you look at SDL (www.libsdl.org). Mind you, I'm assuming you would be programming this in C/C++.

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!