Jump to content
  • Advertisement
Sign in to follow this  
SSJCORY

Collision Problem

This topic is 4775 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 have 2 players when they collide i have my program remove the players from the vector holding all the objects to render and that works. Before i remove them i have their differences in x and y stored in variables. Then what i do is figure out which ones x is bigger and which ones y is bigger whatever is bigger i store that x + the x difference and that y + the y difference to get a central point between the two. Then i try to blit a yellow bitmap to show explosion and it always blits in the wrong place can someone help me figure out the problem? Here's my source
int diffx;
				int diffy;
				int boomx;
				int boomy;
				if(players.getX() >= players[j].getX()){
					diffx = players.getX() - players[j].getX();
					boomx = players[j].getX() + diffx;
				}
				else{
					diffx = players[j].getX() - players.getX();
					boomx = players.getX() + diffx;
				}
				if(players.getY() >= players[j].getY()){
					diffy = players.getY() - players[j].getY();
					boomy = players[j].getY() + diffy;
				}
				else{
					diffy = players[j].getY() - players.getY();
					boomy = players.getY() + diffy;
				}
				cmap.removeplayer(i);
				cmap.removeplayer(j-1);
				HBITMAP boom = (HBITMAP)LoadImage(0,"boom.bmp",IMAGE_BITMAP,50,50,LR_LOADFROMFILE);
				HDC idc = CreateCompatibleDC(hdc);
				SelectObject(idc,boom);
				BitBlt(hdc,boomx,boomy,50,50,idc,0,0,SRCCOPY);



note that this is within my display method. I'm positive that didcollide works but i am unsure why this doesnt work. also note that eventually i will be implementing an animation class to do all teh work :-) Thanks for any help you can offer me, -Cory Fisher

Share this post


Link to post
Share on other sites
Advertisement
I believe your method of calculating the centre point is wrong and should be like this:


// Calculate the vector between player i and player j
int diffx = players.getX() - players[j].getX();
int diffy = players.getY() - players[j].getY();

// Find the midpoint along the vector from player j to player i
// I.e. move half the distance from player j to player i
// Note if you didn't have the divide by 2 you'd end of with the position of
// player i
boomx = players[j].getX() + (diffx /2);
boomy = players[j].getY() + (diffy /2);



It may help to sketch out what this code is doing. Try having player j at (0,0) and player i at (10,10)

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!