Skip to main content
GameDev.net gamedev.net
🔒 Locked

Class objects that contain objects

Started by NogginBoink Dec 30, 2003 at 2:27 PM 0 replies 250+ views
Original Post
NogginBoink
NogginBoink
Can anyone point me to a good tutorial? My game''s Level object will instantiate a Player object, a few BadGuy objects, a few MovingPlatform objects, etc... ...and I can''t seem to wrap my mind around how to implement it. It''s a problem that I''m quite sure has been solved, I just need to be led there. Any pointers are appreciated.
Xai
Xai
the basic key to thinking through these types of ideas, where objects relationships are complex and interelated, is to be very presise in how you talk about these relationships ... use each word to mean only 1 (or at most 2) types of relationships ...

for example: is, has, contains, owns, points to, references, etc ... are all relationship describing words ... but don''t use them loosly ...

some possibly limits I like to use (although the terminology varies depending on context) ...

I say "owns" for only to things ... in programming terms, it means the "owning" object will delete the "owned" object when it wants to, or when it gets deleted ... unless it first transfers that ownership to someone else (which would mean it no longer "owns" the object) ... knowing who OWNS who is very important for writing correct code ...

I also say "owns" differently for in-game use ... don''t confuse the programming use of the word from the in game use ... (for all of these).

I say "references", or "refers to" to mean that the obect "knows about" a particular other object ... such as - "the Player.Target field refers to the Player''s currently targeted enemy". This does not imply ownership (but ownership may be implied by some OTHER aspect of the relationship).

I say "contains", or "has" as generic words ... whose use depends on context and common sense ... if a container object "contains" some things - it usually owns them ...ie "the Player.Inventory contains the Items the player is holding" ... these items might be owned by the player class ... or "the Player has 6 Stats" ... these Stat objects are a part of the Player object ... so they die with it ...

Really, I guess the terms aren''t the key ... just the clear thinking of what object''s depend on what other objects for their existence or meaning ... and which relationships are just transient (aka dynamic) ...

The "Guard 37" object has no permanent relationship with the "Guard Post" he is stationed at ... it is just that he is initialized near it, and perhaps it is set as his "HomeLocation" for the purposes of determining how far he is willing to go to chase a noise, or other such, and where he will return afterward.

I could go on and on, and I wish I had a good link to help you model these relations better ... but feel free to ask specific detail questions here, or if you have an idea you want us to critique for you ...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.