The Basics?

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

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 on other sites
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++.

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 31
• 16
• 11
• 10
• 12
• Forum Statistics

• Total Topics
634116
• Total Posts
3015598
×