sprite collision

Started by
59 comments, last by JTippetts 4 years, 7 months ago

Yes, it is executed when there is an overlap.

Tested with


float x = 1.0f;
float y = 1.0f;
float oWidth = 5.0f;
float oHeight = 5.0f;
//draw plane
float xTwo = 0.0f;
float yTwo = 0.0f;
float oTwoWidth = 10.0f;
float oTwoHeight = 10.0f;

 

Advertisement

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;
	}
}

 

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.

Senior software developer with a passion for games, still hoping to break into the industry after all these years...

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);
}

 

hey anyone do you have input on my question?

Does it work now, Phil? If not, what have you tried (besides posting here)?

-- Tom Sloper -- sloperama.com

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. 

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?

Senior software developer with a passion for games, still hoping to break into the industry after all these years...

I like that you use OpenGL now. But it is legacy/deprecated OpenGL. You should use OpenGL 3. I like to use OpenGL with C#. You can start with this step-by-step OpenTK instruction: https://opentk.net/learn/chapter1/1-creating-a-window.html

This topic is closed to new replies.

Advertisement