🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

plane game

Started by
7 comments, last by Alberth 3 years, 5 months ago

Well I am working on a plane game, I have drawn a plane sprite at the bottom of the screen and it moves left and right and shoot bullets up the screen. I also have another plane sprite which moves from the top of the screen to the bottom of the screen. What I am trying to do is when the bullet hits the moving plane sprite it draws an animated collision sprite. What I have got is that when the bullet hits the plane sprite it makes the plane to disappear and then reappear momentarily.

Advertisement

Phil, you have to provide a question and sufficient information so that it can be answered. You have done neither.

-- Tom Sloper -- sloperama.com

I am trying to get a bullet to hit a plane sprite and then draw an animated collision sprite. so far I have got the bullet sprite to hit the plane sprite and then the plane sprite disappears and then reappears. In my code I am using an AABB collision routine to get the bullet to hit the enemy plane which it does but does not draw the collision sprite. here is the code I am working on.

void drawEnemyPlaneCollision()
{
	glEnable(GL_TEXTURE_2D);
	glPushMatrix();
	glBindTexture(GL_TEXTURE_2D, texture[3]);
	glBegin(GL_POLYGON);
	glTexCoord3f(0.0f + screen, 0.0f, 0.0f);

	glVertex3f(-12.5f, 80.0f + move_down, 0.0f);
	glTexCoord3f(0.1667f + screen, 0.0f, 0.0f);

	glVertex3f(12.5f, 80.0f + move_down, 0.0f);
	glTexCoord3f(0.1667f + screen, 1.0f, 0.0f);

	glVertex3f(12.5f, 100.0f + move_down, 0.0f);
	glTexCoord3f(0.0f + screen, 1.0f, 0.0f);

	glVertex3f(-12.5f, 100.0f + move_down, 0.0f);
	glEnd();
	glPopMatrix();
	glDisable(GL_TEXTURE_2D);
}

void coll_ship_one()
{
	//draw bullet
	float x = -2.0f+move_sprite;
	float y = -80.0f + shoot_up;
	float oWidth = 4.0f;
	float oHeight = 4.0f;
	//draw ship
	float xTwo = -12.5f;
	float yTwo = 80.0f+move_down;
	float oTwoWidth = 25.0f;
	float oTwoHeight = 20.0f;

	if (checkCollide(x, y, oWidth, oHeight, xTwo, yTwo, oTwoWidth, oTwoHeight) == 1)
	{
		drawEnemyPlaneCollision();
	}
}

void renderScene(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	glPushMatrix();
	drawPlane();
	drawBulletSprite();
	drawEnemyPlane();
	coll_ship_one();
	glPopMatrix();
	glutSwapBuffers();
}

well I have made some progress on my game. I have got my enemy plane to draw a animated sprite for collision between my enemy plane and the bullet. my question is how do I get the enemy plane to be not drawn after it the bullet hits it. here is my updated code.

void coll_ship_one()
{
	//draw bullet
	float x = -2.0f+move_sprite;
	float y = -80.0f + shoot_up;
	float oWidth = 4.0f;
	float oHeight = 4.0f;
	//draw ship
	float xTwo = -12.5f;
	float yTwo = 80.0f+move_down;
	float oTwoWidth = 25.0f;
	float oTwoHeight = 20.0f;

	if (checkCollide(x, y, oWidth, oHeight, xTwo, yTwo, oTwoWidth, oTwoHeight) == 1)
	{
		glPushMatrix();
		coll(0);
		drawEnemyPlaneCollision();
		glPopMatrix();
	}
}

pbivens67 said:
my question is how do I get the enemy plane to be not drawn after it the bullet hits it

Have a flag “enemy_has_been_hit” which becomes true when the enemy plane has taken a bullet.

Then, somewhere in your code you paint the enemy plane. Wrap an if statement around it:

if (enemy_has_been_hit == false) {
    // Enemy is still alive, paint its plane.
    drawEnemyPlane();
}

well I took your advice alberth and it worked, YEAH!!!

If you don't want something to displayed, don't draw it.

One way to “don't draw it" is to skip over the code that does the rendering.

This topic is closed to new replies.

Advertisement