Help with collision testing
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?
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 mapx = 100; // some valuey = 100;speedX = 1;speedY = 1;mapX = 640; // size of mapmapY = 480;while(1){ x += speedX; y += speedY; if(x < 0 || x > mapX) speedX *= -1; if(y < 0 || y > mapY) speedY *= -1;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement