Sign in to follow this  
Followers 0
phil67rpg

OpenGL
opengl game

19 posts in this topic

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.

0

Share this post


Link to post
Share on other sites

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

1

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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

It depends, you could make your own linked list, but only if it is absolutely necessary. The std::vector does have some overhead, but shouldn't be noticable for this game.

Edited by Solid_Spy
0

Share this post


Link to post
Share on other sites

 

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

It depends, you could make your own linked list, but only if it is absolutely necessary. The std::vector does have some overhead, but shouldn't be noticable for this game.

 

If he stored the textures outside the object, just not drawing them and still allocating the RAM for each invader wouldn't be a big deal, he could just clear the vector at the end of the level and it wouldn't be a huge performance problem. 

1

Share this post


Link to post
Share on other sites

well I got the collision detection to work with the ufo at the top of the screen, but I also want the bullet to collide with the aliens, and then turn off the aliens.

0

Share this post


Link to post
Share on other sites

well I got the collision detection to work with the ufo at the top of the screen, but I also want the bullet to collide with the aliens, and then turn off the aliens.

Because your not really shooting in diagonals, as far as I can tell, check into Axis aligned bounding box collisions, they're pretty easy ex:

struct box
{
float maxx,maxy,minx,miny;
};
bool collision(box* one, box* two)
if (one->maxx < two->minx || one->mazy < two->miny || one->minx > two->maxx || one->miny > two->maxy)
// no collision in any of these cases
return false;
//defaults to colliding
else return true

Of course, you would need to constantly update the boxes position, so you might want to add some kind of offset in there somewhere and add them onto the max,min,etc during the test. If you want something for oriented bounding boxes, boxes that aren't axis aligned, in other words, rotated, look into the separating axis theorem. Its a bit slower, but its fairly simple to implement and its almost pixel perfect.

0

Share this post


Link to post
Share on other sites

so how do I do multiple collision detection using AABB.

AABB being good is kind of ipso-facto, only if you want axis aligned boxes. If you want to test all the boxes against your bullet, you don't want to test all of them in say a loop, while your game is pretty simple and you probably wouldn't notice the difference, you should do at least 2 steps. There are a lot of approaches to the 2 step thing, for more complicated collision detection, there are even upwards of 3. By no means am I an expert, but this is what I would do:

1. loop through all the bounding boxes and check if the center of the bullet is within a relatively small distance to the center of each box. If it is, add it to the next step to be tested for the AABB collision.
2. loop through all the boxes that were passed down and as soon as you find a collision, stop the loop because there is no need to keep checking for possible collisions.

 

To reiterate, this isn't really necessary, but it is going to save you quite a bit of CPU time if you have 30 or 40 enemies, or you are testing multiple bullets per frame.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0