@Programmer71
He was given the choice between being a Luddite or a contrarian.
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!
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.
@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.
@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.
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);