I am making a space invaders - monopoly game, I have drawn a bug sprite at the top of the screen and a spaceship at the bottom of the screen, I have also drawn a bullet that moves from the spaceship to the bug sprite and then it draws a collision sprite and then it disappears leaving a blank spot. What I am working on is drawing a bug sprite and then drawing another bug sprite next to it. It also draws a different bug sprite just like in space invaders.
Spaceolopy
Is it safe to assume that you're going to ask a question, Phil?
-- Tom Sloper -- sloperama.com
yes, I want to know how to move sprites across the screen from one bug to another bug sprite
Have you tried to move sprites from one sprite to another?
-- Tom Sloper -- sloperama.com
pbivens67 said:
yes, I want to know how to move sprites across the screen from one bug to another bug sprite
If you can control where you draw your sprite, in terms of x and y, then you should be able to use those location variables to draw the sprite in different places.
So, if you know where that other bug sprite was in terms of x and y, just change your current bug sprite to that same location.
well, here is my code for drawing a bug
void drawBug_one(int i)
{
Bug bug;
bug.bug_x = -10.0f;
bug.bug_y = 90.0f;
bug.bugWidth = 10.0f;
bug.bugHeight = 10.0f;
bugs.push_back(bug);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[8]);
glBegin(GL_POLYGON);
glTexCoord3f(0.0f, 0.0f, 0.0f);
glVertex3f(bugs[i].bug_x, bugs[i].bug_y, 0.0f);
glTexCoord3f(1.0f, 0.0f, 0.0f);
glVertex3f(bugs[i].bug_x, bugs[i].bug_y + bugs[i].bugHeight, 0.0f);
glTexCoord3f(1.0f, 1.0f, 0.0f);
glVertex3f(bugs[i].bug_x + bugs[i].bugWidth, bugs[i].bug_y + bugs[i].bugHeight, 0.0f);
glTexCoord3f(0.0f, 1.0f, 0.0f);
glVertex3f(bugs[i].bug_x + bugs[i].bugWidth, bugs[i].bug_y, 0.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
}
@pbivens67 : It looks like you are hard coding a bunch of stuff that should change for each bug. Specifically here :
Bug bug;
bug.bug_x = -10.0f;
bug.bug_y = 90.0f;
bug.bugWidth = 10.0f;
bug.bugHeight = 10.0f;
bugs.push_back(bug);
And relating to that point, having a list of bugs is a great idea, but you shouldn't add to that list in the draw function. Instead you should have your list of bugs, (before you start trying to draw anything) initialize that list , based on how many bugs you want to start with. Then, as the game plays out, subtract bugs from the list as they get killed.
The draw function should probably be a member function of the bug class. You would then run through your list of bugs, and draw each bug as you go.
So, start at the beginning of your list,
Go through the list, get each bug
And, for each bug, call CurrBug.Draw();
Your draw function would looks something like this. . .
// This function allows a specific bug to draw itself. . .
void Bug::Draw()
{
glEnable(GL_TEXTURE_2D);
// Note : I'm assuming that you are storing a global list of textures in texture[8],
// but you might want to just have the Bug's texture ID be a member variable instead
//glBindTexture(GL_TEXTURE_2D, texture[8]);
glBindTexture(GL_TEXTURE_2D, TextureID); // this assumes that the bug's texture ID has stored in TextureID
glBegin(GL_POLYGON);
glTexCoord3f(0.0f, 0.0f, 0.0f);
glVertex3f(bug_x, bug_y, 0.0f);
glTexCoord3f(1.0f, 0.0f, 0.0f);
glVertex3f(bug_x, bug_y + bugHeight, 0.0f);
glTexCoord3f(1.0f, 1.0f, 0.0f);
glVertex3f(bug_x + bugWidth, bug_y + bugHeight, 0.0f);
glTexCoord3f(0.0f, 1.0f, 0.0f);
glVertex3f(bug_x + bugWidth, bug_y, 0.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
}
As a side note, I kept most of your naming conventions for consistency with your previous code, however, there are some changes you could make in the variable names. For example, you probably don't need to have bug.bug_x you could probably just do with bug.x instead, although the code will still work either way.
@pbivens67 : a vector is fine too. But the same things I said above would also apply to that as well. . . You should not be adding bugs to your vector in your draw function.