Sign in to follow this  
yewbie

Random musings on (Npc, object, light) management

Recommended Posts

Basically I am just looking for some advice / thoughts on managing all of this.

I was considering making a ENTITY class that encompasses all 3 of these (Npc, Object, lightsource);

Where npc = Anything that uses AI;
Where Object = Is anything that is not a lightsource or a npc
Where Lightsource = a light source;

And static world items are not encompassed at all

and creating the classes like so

class CEntity
{
public:
private:

//only put things here that every entity will have
int LocX; //X location
int LocY; //Y location
int IDNum; //this is the ID number (this should be unique)
string Name;

CEntity(); //Constructor
};
class NPC : public CEntity
{
public:
int Health;
int NpcType;

//functions
NPC();//Constructor
};






Would I just be better making a individual class for each type, It feels like doing it this way would make accessing generic information a lot easier.

Sorry for no real "questions" here but I am just looking for some input on what everyone else does for object/npc/lightsource management.

Also some basic information:
I am programming a fully 2d game from a top down perspective.
I am programing the world to be non linear.

Share this post


Link to post
Share on other sites
I'm not sure what having a base class ( your CEntity ) does for you, in your case. Other than a location and name, I would think an NPC, a light and some undescribed "object" might have nothing else in common. E.g., it's not likely they'll be rendered the same.

Base classes should solve a problem, usually with respect to some attributes or functions that several types of objects have in common. It appears you're trying to use a base class for the sake of using one.

If it serves a purpose, having a base NPC class might be useful - all NPC's might be rendered the same, be given the same commands, etc.

Share this post


Link to post
Share on other sites
I'd strongly recommend going with a component-based system rather than any sort of extensive (or even not so extensive) inheritance hierarchy. It might require more work up front, but would likely pay off in the long run, IMO.

(Also, I recommend not using the 'C' prefix for class names.)

Share this post


Link to post
Share on other sites
Quote:
Original post by Buckeye
Base classes should solve a problem, usually with respect to some attributes or functions that several types of objects have in common. It appears you're trying to use a base class for the sake of using one.

If it serves a purpose, having a base NPC class might be useful - all NPC's might be rendered the same, be given the same commands, etc.


Yeah I can see what you mean I think I might just make a class for each type NPC, Object, and light it would actually be easier for me this way.

Quote:
Original post by jyk
(Also, I recommend not using the 'C' prefix for class names.)


I always wondered why people say that, is it just because its unneeded/extra typing?

I end up accidentally putting some of the microsoft naming conventions in my code, but I have been trying to get away from it =p

Edit: Also I forgot to mention thank you guys for your input, I have never really looked over the code for how any of the other games manage stuff like this.. So its just interesting to me to see how people do it. =)

[Edited by - yewbie on December 8, 2010 12:27:15 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by yewbie
Quote:
Original post by Buckeye
(Also, I recommend not using the 'C' prefix for class names.)


I always wondered why people say that, is it just because its unneeded/extra typing?
That was actually from my post, rather than Buckeye's.

This is discussed fairly frequently, so if you're curious I'd recommend searching the forums for 'c prefix' or 'hungarian notation'.

Some people still use (and advocate for) Hungarian notation and variants thereof, but I think there's a pretty clear move away from such notational schemes. One thing you might ask yourself is, in what way does the 'C' prefix benefit you? What useful information does it provide?

(Again though, there's lots of information to be found in the many previous threads on the topic.)

Share this post


Link to post
Share on other sites
Thanks a lot jyk I really appreciate the input.

Have a Merry Christmas / Whatever your holiday may be =)

edit: also sorry about misquote, I have fixed it =p

[Edited by - yewbie on December 8, 2010 12:29:56 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this