opengl game

Started by
18 comments, last by BlueSpud 10 years, 8 months ago

well I have decided to work on a space invaders game, any hints on how to start?

Advertisement

here is a screen shot of my game so far

looks like your getting it done! What help do you need with it?

well I need to move the aliens from left to right

well I am attempting to render the aliens on the screen, I want to draw the alien to the screen and move to the right and then erase the sprite and draw a new sprite and moves the sprite to the right again. basically I want to draw a sprite and erase it and redraw a different sprite and then erase it and then draw the previous sprite and have all the sprite to move to the right.

well I am attempting to render the aliens on the screen, I want to draw the alien to the screen and move to the right and then erase the sprite and draw a new sprite and moves the sprite to the right again. basically I want to draw a sprite and erase it and redraw a different sprite and then erase it and then draw the previous sprite and have all the sprite to move to the right.

Thats not exactly what you want to do. Create an object for each alien:


class Invader
{
public:
float x,y,z;
void update()

};

Then create the invaders in whatever way you want best to handle them.

Make a callback for glutIdleFunc().

Put in that callback:


//call onUpdate() for all the invaders
updateInvaders()
//draw a new frame
glutPostRedDisplay();

In the onUpdate() for the invaders, move them left and right using their positions. The render for them would look something like this:



void invader::render()
{
glTranslatef(-x,-y,-z);
//render sprite
renderSprite();
}

Hope that helps

yep it does, any more input would be appreciated.

If you want to update multiple enemies and have a list of them and run a for loop to do the update for each one. You can do this by either using a linked list or...not sure if any one would get mad at me for saying this but you could use a vector.

These are both basically dynamic lists like an array that can change in size...be careful with deleting objects while a loop is running.

http://www.cplusplus.com/reference/vector/vector/

http://www.cplusplus.com/articles/Lw6AC542/

Hope this helps.

so I should use a vector? I am somewhat familiar with vectors.

Hi, phil. How you been?

This topic is closed to new replies.

Advertisement