I want to do a spaceship battle (2 planes, lots of bullets) and I have a few doubts... | SoloLearn: Learn to code for FREE!


I want to do a spaceship battle (2 planes, lots of bullets) and I have a few doubts...

I was thinking that I need 2 classes, one for the plane and one for the bullets. I wanted to create new bullets on keypress. The plane moves left and right, using a and d. How do I create and delete an object? I was thinking that a solution could be storing them in a huge vector, but I doubt that this solution is good. How do I check the collision between 2 objects? Is there any way I can do that using a class method? Or do I need to use getters in a timer to check colision for every bullet with the planes? I'm making it in C#, but any information is useful.

5/15/2020 11:51:51 AM

💜 Alex Tușinean 🍇

3 Answers

New Answer


On bullets: If you can draw the same bullet multiple times ("at once") on screen, it would suffice to have one bullet obj plus a list or sth that stores where the bullet is, if it is still active (flying, hit other plane, missed other plane) Maybe should set an upper limit for the number of bullets on screen.


On collision detection: Think of the collider as a circle around a plane or a bullet. Then you can check regularly if a bullet circle overlaps with the plane circle -- if it does, the plane is hit by the bullet! You could properly use a timer to predict when a plane is hit by a bullet, but that would only work if your planes never move.


Hey bro, As for bullets I will suggest to make a array of fixed size for bullet object with a max cap and reuse the bullets object in the array ( btw this method is called "pooling" it is used to optimise particle effects in games ) For collision detection make a hit-box arround the objects chose the shape of hit-box as per the objects . Circles are the easiest to implement Ping me if need more help Happy coding , : )