πŸŽ‰ 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!

Spaceolopy

Started by
86 comments, last by pbivens67 1Β year, 5Β months ago

@Programmer71

He was given the choice between being a Luddite or a contrarian.

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

Advertisement

I am attempting to draw a bug sprite and then draw a different bug sprite and then draw the original bug sprite in the same spot. I am using the glutTimerFunc function.

void timer(int val)
{
	drawBug_two(0);
	glutPostRedisplay();
	glutTimerFunc(100, timer, 0);
	drawBug_one(0);
}

void renderScene()
{
	srand(time(NULL));
	glClear(GL_COLOR_BUFFER_BIT);
	coll_ship_one();
	go_space();
//	electric_space();
	if (coll == -1)
	{
		timer(0);
//		drawBug_one(0);
	}

	if (coll == 1)
	{
		drawCollision_one(0);
		coll = 0;
	}

	if (coll == 0)
	{
		// no bug
	}

	ship();
	drawBullet();
	drawDice();
	glFinish();
}

pbivens67 said:
drawBug_two(0);

A drawBug function like

drawBug(float x, float y, int bugType);

could draw any type of bug anywhere on the screen.

You just cycle through your array of bugs and draw. It's very, very easy. You're doing it the hard, hard way.

Of course you should be using polymorphism with a base game object and have update and render methods. At least for now with a simple 2D game.

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

can I use a vector instead of an array?

@pbivens67 Sure.

You could duplicate your dice code that makes the sprites and change the textures to bugs, then duplicate and modify the drawing code I refactored and have something working in no time.

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

what do you mean by change textures to bugs?

@pbivens67 You have red and white dice textures loading in. You can change the white dice to load 6 different bug textures instead. Maybe you already have something working.

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

well I already have 2 bug textures loaded in, I just want one bug to draw to the screen and then another bug to draw in the same spot, basically I want the bugs to be drawn alternately one on the top of another.

You clear the screen every time. You don't draw bugs on top of bugs. BTW, the space invaders were aliens, not bugs. Doesn't matter.

drawBug(float POSx, float POSy, int bugType, int bugFrame);

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

fleabay said:
You don't draw bugs on top of bugs.

I meant the screen was to be cleared each time just like you said. I am using bug sprites instead of aliens.

This topic is closed to new replies.

Advertisement