|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| Character Class |
|
![]() Protocol 0 Member since: 2/13/2005 From: NSW, Australia - Comprehend The Impossible |
||||
|
|
||||
| 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. |
||||
|
||||
![]() paulecoyote Member since: 7/14/2003 From: Alton, United Kingdom |
||||
|
|
||||
| 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... ); } |
||||
|
||||
![]() kburkhart84 Member since: 6/30/2004 From: Dallas, TX, United States |
||||
|
|
||||
| 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. |
||||
|
||||
![]() johnb003 Member since: 3/14/2004 |
||||
|
|
||||
| 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. |
||||
|
||||
![]() Protocol 0 Member since: 2/13/2005 From: NSW, Australia - Comprehend The Impossible |
||||
|
|
||||
| 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. |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|