1
General / Re: Projectile/Bullet help
« on: December 19, 2015, 04:35:46 am »the most optimal method for coding this is.You might want to have a look at std::array so you can use that instead of that normal array
2D shooter, bullets are always firing, are not needed once off the screen.
A fixed-sized array, as you have used - also with std::array, can fall apart when you need "just one more" bullet. What happens when you need 21 bullets? Does one of the earlier bullets get killed even if it's still travelling and visible?
A dynamically-sized array are of use when storing dynamic objects such as bullets. The first port of call for this type of storage is usually an std::vector. This could do your job fine but there are other storage containers that may work better, such as std::list (if the bullets could expire at unordered times or std::queue (if the bullets expire in order).[code=cpp][/code][code=cpp][ */code](and omit the asterisk)
(you can use the [nobbc][/nobbc] tags to display special characters in posts - but not inside code tags)
Neato thanks. I thought about using a dynamic array, but the way it's set up would never allow for that many to spawn, so I'll probably keep it static for simplicity's sake until later.
Also, I believe with how it's set up now it would just not spawn a bullet, so effectively your fire rate would just be slowed by a fixed amount.