Archived

This topic is now archived and is closed to further replies.

GalaxyQuest

Question about Object classes

Recommended Posts

GalaxyQuest    122
Hello folks. Thanks to school, progress has been pretty shitty lately for my little project, but i do have some concerns about populating objects for this tilebased game... Let me summarize what ive been thinking and developing and hopefully you guys can help me understand things. Oh, and i am using C++ and trying to keep things in an OOP fashion. From some of the articles ive read around the web, i decided to go with having small linked lists at each map point, which would point to all objects on that tile(32x32). In order for this to happen, the linked list would have to point to base class object from which all objects would be derived from. This means i would have to create a base class which would encompass objects like trees, rocks, items(swords,food,etc), as well as the player and all NPC races...shewww! The reason for using these linked lists were for quick access to objects and drawing order when drawing the screen. The actual objects would be held in some kind of structure like a global object tree or something of that nature. But ive been busy lately and now im concerned that this approach may not be that great..only in terms of ALL objects being derived from a base class. This would mean i would need to include all functionality in this base class, even if the method is only ment for, lets say the npc class, such as DoAI(). A food item will have this method, it just wont ever use it. I hope you see what im getting at. On the other hand, i dont want to create a couple different classes for each object and have to create tree structures for each type, this seems waistful..at least at the surface. But maybe i am thinking about this correctly, I JUST DONT KNOW ANYMORE. I just hate when i think about something so much that i confuse myself more then before...ack! Anyways, any comments about your design concerning objects and how i may alter or continue with my design is most appreciated!!

aka John M. Never give up. Never surrender!

Share this post


Link to post
Share on other sites
MuteAngel    122
You could just have say, a CNode class, and inherit a generic CObject from it, adding some functionnalities common to all the graphical objects (like x and y position, etc).

Then inherit your CSprite from CObject (a CSprite wouldn''t have a DoAI() ). Then again, inherit a CCharacter and a CItem from CSprite.

That way you could add a DoAI in CCharacter and not in CItem. The way I''d do it would be to put a pure virtual method in the CCharacter class (like DoAction()) and inherit 2 other classes from CCharacter (pc and npc). In the Cpc class, it would be implemented to react to player input and, in the Cnpc one, to react to AI input.

I hope this makes at least a little sense... I''m not good at explaining that kind of stuff.. Also, this is kind of an overview. You''ll have to figure how to make this fit in your engine.

Share this post


Link to post
Share on other sites
the Dealy Lama    122
(let me qualify this by saying that I have no real experience with this, and am in fact in the exact same boat as you..)

You don't need to include every method in the base class. If the need for the base class is just drawing, then all you really need to do is something like this:
    
class CBase {
public:
virtual void Draw(void) = 0;
};

class CNPC : public CBase {
// etc....


That way your linked list of all objects at a map position would work fine when you're drawing everything. Something like DoAI() would need only be in the NPC class.

*** EDIT ****
Hmmm, seems like you beat me to it, MuteAngel, by a good 5 or 6 minutes.. Huess that's what I get for drinking while posting a reply.. Kinda slows down the mind a little..

Gruad the Dealy Lama

"What sounds to you like a big bloat of trashy old noise
is in fact the brilliant music of a genius--myself" ~ Iggy Pop


Edited by - the Dealy Lama on January 29, 2001 11:59:52 PM

Share this post


Link to post
Share on other sites