Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


need some help on shooting..

This topic is 5492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

this is my code in DrawGLScene()....
          if(bulletFired == true) {
		glTranslatef(bulletStartPos, bulletSpeed, 0.0f);
		glRotatef(0, 0.0, 0.0, 0.0);	
		glBegin(GL_QUADS); // bullet
			glColor3f(1.0, 0.0, 0.0);
			glVertex3f(0, 50, 0);
			glVertex3f(3, 63, 0);
			glVertex3f(0, 70, 0);
			glVertex3f(-3, 63, 0);
			bulletFired = false;
			bulletSpeed = 0;
...the problem is that only a SINGLE bullet can be fired at a single time.... i've only been doing this for about a month and all this stuff is really new to me. any help would be appreciated. [edited by - rotaerc on November 28, 2003 9:35:13 AM]

Share this post

Link to post
Share on other sites
You need to keep an array (or vector) of bullets. This allows you to iterate through and draw each bullet in turn. Using an array means there is an upper limit on the number of bullets you can use at any one time. Managing an array is also more difficult. Each bullet will need to know its bulletStartPos and bulletSpeed. It is probably best (easiest) if you store your bullet information in a class (or struct).

I would recommend using a vector to store your bullets:
std::vector<Bullet> bullets;
// when firing a bullet
bullets.push_back(Bullet(x, y));
// when drawing
std::for_each(bullets.begin(), bullets.end(), drawBullet);

For this you would need a drawBullet function that takes a Bullet as it's argument and does the drawing as shown below. You would also need to put your bullet invalidation code (bulletFired = false) after the drawing and remove each bullet from the vector as they get used up.

PS. please don't crosspost. It wastes database space and often results in people expending effort answering a question that has already been answered.


EDIT: angle brackets in std::vector declaration.

[edited by - Enigma on November 28, 2003 12:18:49 PM]

Share this post

Link to post
Share on other sites
thank you for your reply!

i''ve used arrays before but it''s my first time seeing ''vector'' so i don''t know what it is.

can you explain real quick? a simple example would be wonderful.

PS. i won''t crosspost. it was actually a mistake and i couldn''t figure out how to delete the former post.

Share this post

Link to post
Share on other sites
A vector is kind of like an array without an upper bound (it can grow as long as you need it). You can push values onto it (like a stack) and pop values off of it.

Say you have the following values:
4 1 6 9 3

Now you can push values onto the back of the vector (say, 8 and 2), which gives you:
4 1 6 9 3 8 2

You don''t need to (manually) dynamically allocate more memory, the vector STL (Standard Template Library) class takes care of it for you.

Hope that helps!

K-1 Productions: Come visit us here.

Share this post

Link to post
Share on other sites

i did my homework.

which one?

i can't find the article.

[edited by - rotaerc on November 28, 2003 12:09:01 PM]

Share this post

Link to post
Share on other sites
I would create a new class named missile and then make linked lists in your player class, it works very good and you can create a very dynamic system with that!

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!