Jump to content
  • Advertisement


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


Projectiles... arrays?

This topic is 6068 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

hello, i am ready to add some projectiles to my game, and i was wondering how the best way to do this would be... would my best bet be somthing along theese lines? Psuedo code --Mouse is Clicked-- //check for assigned projectiles... // d = max ammount of live projectiles allowed for(int d=0; d<1000; d++ { if (gun_proj[d] == 0)//using 0 as null indicating that projectile is not active. gun_proj[0] = 1; // make it active } then after i do that, i will have to set that individule projectiles heading to another array... does that sound about right, or am i going about this all wrong? Edited by - dirtypope on November 5, 2001 11:38:30 PM

Share this post

Link to post
Share on other sites
I would personally use a linked list for projectiles. Forexample in the ''RocketLauncher'' class I would have a linked list of ''Rocket'' objects. Everytime the player clicks the mouse button you add a ''Rocket'' object to the list, and when the rocket explodes you remove it from the list. Then all you have to do every frame, is to traverse the list and update each rocket and render it.

I''m yet to master writing my own template class for linked lists. But you can always use the ''vector'' or ''list'' template classes.

I don''t really see anything wrong with your method either. The Pro''s are: you don''t have to keep creating and destorying objects which could mean more efficiency. The Con''s are: You don''t exactly know how many projectiles are gonna be alive at one time. If you make your array too big then you are wasting memory.

Hope that helps

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!