Until now, I know 2 bullets’ algorithms/configurations : (I mean 2 ways of logically creating a bullet class)
Make a bullet class and create only one instance from it that represents the bullet.
The bullet hides under the player’s image until he shoots it. Then, he won’t be able to shoot again before it reaches the end of the screen and then hides again under the player’s sprite.
(This configuration uses only one bullet instance for every bullet type, it means that the player cannot shoot multiple bullets of the same type at once)
Make a bullet class and repeatedly create new instances of it as much as the player needs and as long as he can shoot. (depending on the firerate)
Personally, I like the second algorithm, however, I think that creating many instances does slow the performance especially when the number of these instances becomes bigger and bigger (especially at an advanced stage of the game).
So I have some questions in this topic:
Will using numpy arrays instead of lists (in order to store the instances) decrease the risk of slowing the game performance ?
Will deleting some instances regularly prevent from losing the performance ?
pseudocode for this :
if len(bullets_list) >= 5: del bullets_list(:4)
Btw I want to know what happens exactly (technically) when an instance is deleted from a list in Python/Pygame.
And if there is already an answer for this, just attach it with your answer 😉
Are there any other algorithms to develop a bullet class ?
Are there any improvements to the previous algorithms in order to have a good & stable performance and to ensure a good UX ?
Finally, how can I choose which configuration/algorithm to use depending on my game ?
(What are the standards to follow to determine the answer to this question)