Home » Community » Forums » Game Programming » Character Class
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Character Class
Post New Topic  Post Reply 
Say I have a character. e.g. limbs, head, body etc. Is it a good idea to store him in a class under a function called "drawCharacter"? Then create a function called "moveCharacter" which moves the player, under the public x, y, z values. i.e. OOP.

e.g

class mainCharacter
{
public:
	mainCharacter();

	GLfloat moveX;
	GLfloat moveY;
	GLfloat moveZ;

	//////////////////////////////////////////////////////////////////////

	int drawCharacter ();
	int moveCharacter();
};

Okay, there are realy a few more functions and variables than just this in my class, but this will give you an idea of what I mean.

I have already created it, and it works, though is there a more efficient way? How do the more experience coders do it? Even if you think you're not experienced, I wouldn't mind knowing (for curiosity's sake)?

... I'm just wondering.

 User Rating: 1019   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

You sound pretty keen to get into this OO stuff.

How you orginise your character depends on your game. You've indentified "character" as a concept, and given intuitive sounding data members.

I'd suggest having a base class all your characters derive from, that way you can just keep them in a big list or structure somewhere, and just run "draw" on each of them per frame, and using virtual and that kind of stuff it will automatically call the most derived version of that.

Eg (assuming Cop, Robber and Dame are all derived from base class Character)

Characters[] character = new Characters[4];
character[0] = new Cop();
character[1] = new Robber();
character[2] = new Dame();

...
...
...

for (i=0; i<NUMCHARACTERS; ++i)
{
character[i].draw( ...stuff... );
}

 User Rating: 1643   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

C++(OOP like classes) in reality can be just as fast as plain C, as long as stupid mistakes are not made(not intended to offend or say that one has been made). For example, if you only can have one of a character, only have one instance in memory(a singleton class). As long as certain care is taken in the design, classes are great for organization purposes. I do tend to use them, maybe even too much. I'm no expert though.

 User Rating: 1162   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

it really does depend on your game engine... This is pretty similar to how I do it I suppose. My engine has a draw function an update function and an event handler for the most part. so then a character would have an update and draw function, and they would be called from the engine in a simple example... In my update I just directly set the position of the character, as opposed to having a move function to simply set the values. You can take a look at a simple example I have included with my skeletal animation library. Which btw might also be a good way to do the animation for your character if you haven't considered that yet.



 User Rating: 1027   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Okay, thanks.

At the moment, I have a main character class, and then I have an enemy class - which all other enemies inherit from - saving time and size by not having to create a new class for each object.

It seems to be working good - though was unsure if I was taking the wrong/right route to game development. I know that there is no wrong/right in game development - but there are practices which develop efficiency.

 User Rating: 1019   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: