Jump to content
  • Advertisement
phil67rpg

OpenGL sprite collision

Recommended Posts

I just don't know why the drawcollision_one() function does not execute when there is an overlap it also outputs the collision string to the screen  using cout and the "collision" string. here is my test code.

void coll_plane_one()
{
	//draw bullet
	float x = -2.5f + move_plane;
	float y = -75.0f + up;
	float oWidth = 5.0f;
	float oHeight = 5.0f;
	//draw plane
	float xTwo = -10.0f + move_plane;
	float yTwo = 100.0f + down;
	float oTwoWidth = 20.0f;
	float oTwoHeight = 20.0f;

	if (checkCollide(x, y, oWidth, oHeight, xTwo, yTwo, oTwoWidth, oTwoHeight) == 1)
	{
		drawcollision_one();
		cout << "Collision" << endl;
	}
}

 

Share this post


Link to post
Share on other sites
Advertisement

We don't know the values of "move_plane", "up", and "down".  If those were all zero, the bullet is at y = -75, and the plane is at +100.  So at the very least, "up" would have to be +170.1 or more for the collision to occur.  Or "down" would have to be -170.1.  Or some combination.

So I think we'd need to see how "up" and "down" are being updated.

Share this post


Link to post
Share on other sites

here is my up and down functions 

void shoot()
{
	up++;
	if (up >= 175.0f)
	{
		up = 0.0f;
		glutIdleFunc(NULL);
	}
	glutPostRedisplay();
}
void timer(int v)
{
	down--;
	if (down <= -180.0f)
	{
		down = 0.0f;
	}
	glutPostRedisplay();
	glutTimerFunc(50, timer, 0);
}

 

Share this post


Link to post
Share on other sites
2 hours ago, phil67rpg said:

hey anyone do you have input on my question?

You haven't asked a question.

Edited by fleabay

Share this post


Link to post
Share on other sites

well it does not work, I have tried using the cout command and it outputs "collision" to the screen but it does not draw the animated sprite to the screen. the problem is probably in the drawcollsion_one() function It looks like it should work  but when the bullet hits the enemy plane it just passes through it but  does not draw the collision animated sprite. 

Share this post


Link to post
Share on other sites

These are the things I'd be checking at this point:

  • Are the vertices being drawn in the correct order?  If the polygon is facing the wrong way, you won't see anything.
  • Is it being drawn off screen?
  • Was the texture loaded properly?

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!