Sign in to follow this  

How should I structure my projectiles?

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

I am working on a small project in which the player controls a 2-Dimensional Tank - the problem is, I'm not entirely sure on how I should structure my projectiles. I plan on having three different projectiles - bullets, missiles and lasers (not relevant, but whatevs).

My game's WORLD object holds a TILEMAP, and the TILEMAP holds TILE objects: That's no problem. But my WORLD also holds PLAYER and ENEMY objects, which in turn [u]should[/u] hold PROJECTILE objects - but if I assign the PLAYER or ENEMY objects PROJECTILE objects, won't the PROJECTILE objects be destroyed when the PLAYER or ENEMY object that they belong to gets destroyed?

Share this post


Link to post
Share on other sites
You've already pointed out the error of objects owning their own projectiles. What you need is an object that manages the lifetimes of said projectiles. Think "projectile manager".

Share this post


Link to post
Share on other sites
Just because a game character provides the source position of a projectile doesn't mean the character needs to own the projectile. Once the projectile exists, it lives in the world just like all other entities. Assuming the the World is what manages characters interacting with the environment and with each other, the World should also manage the same interactions for projectiles.

Share this post


Link to post
Share on other sites
[quote]
What you need is an object that manages the lifetimes of said projectiles.
[/quote]
Yeah, I started thinking about that after I posted my initial question (derp). But on that subject, I would need a seperate class(?) to handle each individual projectile, updating each one as they occur in a list(?) of projectile objects. The tutorials I ran through never actually discussed destroying an object (even though there was a section on making a hundred DrawableGameComponents run around on the screen), so I have no idea how to make an object "self destruct" if they hit an obstacle or non-owner (and I use the term owner loosely: I am referring to the value I mentioned earlier that tells other objects what object launched the projectile, so it doesn't hurt friendlies or the player's own tank)... I imagine I could figure something out, but for the sake of education I'd rather know the correct way to go about this. This is my first foray into the world of OOP, so my past procedural code knowledge is sorta useless...[img]http://public.gamedev.net//public/style_emoticons/default/wacko.png[/img] The whole idea of "objects" is pretty new to me, and still difficult for me to fully grasp...

Share this post


Link to post
Share on other sites
Sign in to follow this