Jump to content
  • Advertisement
Sign in to follow this  
kingpinzs

Help with collision testing

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

here is what I have while( bugy <= mapy ) { bugy += 4; bugx += 4; cout << bugy << "\n"; if (bugx <= mapx) { cout <<bugx<<"\n"; } } now when it does = mapy or mapx I want it to go the other direction tell it = 0 for x and 0 for y then change direction again. How would I accomplish that?

Share this post


Link to post
Share on other sites
Advertisement
Here's a simple solution

[source lang='cpp']

float speedX, speedY;
float x, y;
float mapX, mapY; // assume these two variables are right and bottom corners of the map

x = 100; // some value
y = 100;
speedX = 1;
speedY = 1;
mapX = 640; // size of map
mapY = 480;

while(1)
{
x += speedX;
y += speedY;

if(x < 0 || x > mapX) speedX *= -1;
if(y < 0 || y > mapY) speedY *= -1;
}


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!