Jump to content

  • Log In with Google      Sign In   
  • Create Account


How should I structure my projectiles?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 MisterFuzzy   Banned   -  Reputation: 161

Like
0Likes
Like

Posted 30 October 2012 - 12:29 PM

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 should 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?

"Only idiots quote themselves" - MisterFuzzy

 


Sponsor:

#2 Burnt_Fyr   Members   -  Reputation: 1201

Like
0Likes
Like

Posted 30 October 2012 - 01:11 PM

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".

#3 Suspense   Members   -  Reputation: 449

Like
1Likes
Like

Posted 30 October 2012 - 01:46 PM

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.

#4 MisterFuzzy   Banned   -  Reputation: 161

Like
0Likes
Like

Posted 30 October 2012 - 07:36 PM

What you need is an object that manages the lifetimes of said projectiles.

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...Posted Image The whole idea of "objects" is pretty new to me, and still difficult for me to fully grasp...

"Only idiots quote themselves" - MisterFuzzy

 





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS