Thread: question about classes... maybee

  1. #16
    Registered User
    Join Date
    Jun 2010
    Posts
    13
    well... i cannot have it have clones/instances of the data from Character... unless the vars simply point to the data... the data in Character is too big for me to be able to create copies of it... if i could copy it then i would completely get rid of the Character class and only use Player... I need Player class to "leech" off of the data in Character through pointers or something...

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Then how about this:
    Character (base class which contains all the data that all characters will have) -> Specialized Character (contains data that a special character needs, eg monsters, players).
    Now, your specialized classes can use virtual inheritance to inherit from specific character. Using virtual inheritance will ensure that there will only be one instance of the class you inherit from virtually.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Jun 2010
    Posts
    13
    sounds like the best idea ive heard yet... how would i go about setting something like that up?

    the only problems with that:

    there is no such thing as a "Specialized Character"...
    in saying this i mean that you are either a human or alien... not human or ninja-human
    perhaps you meant to say Player...
    in which case the "special data" would be x,y,z position and rotation, weight, and current weapon...
    then it would work

    Character A and Character B will have almost nothing in common with each other...
    for example:

    Character A may be a seven foot tall cyborg humaniod
    Character B may be a six legged flying insect

    Looking at those explainations it is easy to see that almost everything about their animations and abilities will be different

    let me explain my problem now in a very simple way:

    the characters are like people inside of glass chambers and the players are like clones of those characters which all have their own unique position in space... and they are all performing (can be performing) different actions than both each other and their parent self who is inside of the chamber... like StarWars Clones except the actual Player class only keeps track of their position and other data... like weapon type, or what animation they should be doing

    If you were to restate it like this:
    Character (base class which contains all appearance data of a single character) -> Player (contains data that defines the actions, location, and status of a single player, eg player1, player2).
    Now, your Player classes can use virtual inheritance to inherit from specific character...

    then it would be exactly what i need... the only problem is im not going to learn about virtual inheritance until next semester and i would like to be way past this part of my indie game by then...
    Last edited by gizmo3; 06-09-2010 at 10:34 AM.

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    class Character {};
    class Player: virtual public Character {};
    class Monster: virtual public Character {};
    int main() {}
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User
    Join Date
    Jun 2010
    Posts
    13
    oops... i think it took me too long to edit my previous post... please reread my last post...

  6. #21
    Registered User
    Join Date
    Jun 2010
    Posts
    13
    I think i might be able to do something like this... but i need a constructor... can anyone help me out with this...
    Code:
    class Player (derived from Character)
    {
    public:
    	Character* Model; //pointer to Character class
    	float x; //position on x axis
    	float y; //position on y axis
    	float z; //position on z axis
    	float rx;//rotation on x axis
    	float ry;//rotation on y axis
    	float rz;//rotation on z axis
    };
    Last edited by gizmo3; 06-09-2010 at 11:04 AM.

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    An alien or a monster is obviously not a player. That is why I called it a specialized character.
    At this point, it might also turn out that multiple inheritance can be a good choice.
    You have the data that you don't want to clone for each instance. So this data should be in a special class that you inherit virtually from.
    Then there are other data, such as location, weapon and other stuff that all characters have in common. This should also be in a base class which you inherit from normally.
    So something like:
    Code:
    class CCharacter {};
    class CVirtualStuff {};
    class CPlayer: virtual public CVirtualStuff, public CCharacter {};
    class CMonster: virtual public CVirtualStuff, public CCharacter {};
    int main() {}
    But there's nothing wrong about learning these concepts now. It will save you time later.
    Heck, you shouldn't be coding a game without a proper understanding of all parts of the language first.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Registered User
    Join Date
    Jun 2010
    Posts
    13
    well i figured it would give me better understanding than just doing the same old stupid "Hello World" crap labs that they have you do in class... this way im actually discovering my own ways out of problems... this problem was too hard for that to happen however...

    and just for the fun of it... in the game im working on making, all of the monsters, aliens, and soldiers are players... there is pretty much no AI in this game... its all multiplayer!

    it seems to me that i would only need Character and player... Character would be virtually inherited i would think...


    If someone would help with post 21 it would be awsome...
    Last edited by gizmo3; 06-09-2010 at 10:54 AM.

  9. #24
    Registered User
    Join Date
    Jun 2010
    Posts
    13
    pretty sure i finally managed to get it to work... for now at least

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes question...
    By Raigne in forum C++ Programming
    Replies: 24
    Last Post: 09-12-2006, 01:46 AM
  2. Replies: 2
    Last Post: 07-28-2006, 02:59 PM
  3. Simple Question about Classes
    By Loctan in forum C++ Programming
    Replies: 5
    Last Post: 06-26-2006, 02:40 AM
  4. Classes and Win32 API, and another Question
    By philvaira in forum Windows Programming
    Replies: 10
    Last Post: 04-10-2004, 07:21 PM
  5. Newbie question about the Private type in classes
    By Ryeguy457 in forum C++ Programming
    Replies: 1
    Last Post: 09-07-2002, 10:17 PM

Tags for this Thread