Advertisement

sprite collision

Started by September 01, 2019 10:20 PM
63 comments, last by JTippetts 5 years ago

I  posted all of my code can I please get some input on it.

On 9/10/2019 at 9:13 PM, phil67rpg said:


glutTimerFunc(500, timer, 0);
glutTimerFunc(500, timer_one, 0);

 

You have two "Update" functions: timer() and timer_one(). It is a bad idea. Your Game Loop must have only one "Render()" function and only one "Update()" function.

Advertisement
1 hour ago, 8Observer8 said:

You have two "Update" functions: timer() and timer_one(). It is a bad idea. Your Game Loop must have only one "Render()" function and only one "Update()" function.

well I have adjusted my code.


void update(int value)
{
	down--;
	if (down <= -180.0f)
	{
		down = 0.0f;
	}
	screen += 0.1667f;
	if(screen >= 1.0f)
	{
		screen = 1.0f;
	}
	glutPostRedisplay();
	glutTimerFunc(50, update, 0);
}

 

5 hours ago, phil67rpg said:

I  posted all of my code can I please get some input on it.

Variable 'screen' will get set to 1 almost immediately and never change. This is only part of the problem with your code though.

Your understanding of C++ and OpenGL after many years of supposed learning is underwhelming. It only gets more difficult and complex the further you go. I'm guessing you program by trial and error, changing a variable here, a <= to a > there, compiling, nope, change it back, etc ad nauseam. Regardless, I don't understand how you enjoy programming enough to keep piddling.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

like I said before I am doing this for fun.

4 minutes ago, fleabay said:

I'm guessing you program by trial and error, changing a variable here, a <= to a > there, compiling, nope, change it back, etc ad nauseam. Regardless, I don't understand how you enjoy programming enough to keep piddling.

is there another way to program besides trial and error

17 minutes ago, phil67rpg said:

is there another way to program besides trial and error

Write code that you are almost certain will work as expected and if it doesn't, fix it with the help of a debugger and/or by going through line by line and understanding the problem.

A little trial and error is inevitable but it shouldn't happen very often. It is a miserable way to program.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

Advertisement
3 minutes ago, fleabay said:

going through line by line and understanding the problem.

actually I do this and with a little help from google, I will also  use the debugger  which I have  used before.

well I finally figured out my problem


void drawcollision_one()
{
	screen += 0.1667f;

	if (screen >= 1.0003f)
	{
		screen = 0.0f;
	}

	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, texture[3]);

	glBegin(GL_POLYGON);
	glTexCoord3f(0.0f + screen, 0.0f, 0.0f);

	glVertex3f(10.0f + move_plane, -10.0f + down, 0.0f);
	glTexCoord3f(0.1667f + screen, 0.0f, 0.0f);

	glVertex3f(10.0f + move_plane, 10.0f + down, 0.0f);
	glTexCoord3f(0.1667f + screen, 1.0f, 0.0f);

	glVertex3f(-10.0f + move_plane, 10.0f + down, 0.0f);
	glTexCoord3f(0.0f + screen, 1.0f, 0.0f);

	glVertex3f(-10.0f + move_plane, -10.0f + down, 0.0f);
	glEnd();

	glDisable(GL_TEXTURE_2D);
}

 

what was the problem? Can you elaborate a little on how this fixed it?

 

 

well I have got the ship to shoot a bullet and hit the enemy plane and to draw a collision animated sprite what should I do next.

well my problem was that when a bullet hit a plane it did not draw a animated sprite for collision. however when I put the screen loop in the drawing function it fixed the problem.

This topic is closed to new replies.

Advertisement