i just want to confirm that i have understood the basics of it.
is this correct:
say i make a class for friendly NPC's in a game, i would make a class called for example Friendly {} wich would contian all the different things the npc's could do,like one for AI, and the attributes for the NPC's would be stored in a private acces spesiefier.
then i would have a constructor that gave the variables data.
then i would create objects for that class, for example old man, in my main function or somewhere else in my code?
Where ever you want! You can make objects right after you define the class, before the ';' mark after the last '}', or in main, exactly when you want it. You choose!
Yeah, sort of. There's no 'right' way to do things, just different ways of practicing OOP principles.
If it's game development, inheritance is your friend too. For example, say you make a class for a man, a dog and a tree. They may all do different things but, chances are, all of their draw functions will be the same; either drawing a model or sprite to the screen. So it seems silly to have a Draw() function for each of them. You could create a base class called GameObject, which has the Draw() function. Then all other objects could inherit from that class. It makes things like drawing objects much easier:
1 2 3 4 5 6 7 8 9
// Without inheritance
Man theMan;
Dog theDog;
Tree theTree;
// When it comes to drawing
theMan.Draw();
theDog.Draw();
theTree.Draw();
1 2 3 4 5 6 7 8 9 10 11
// Using inheritance
constint MAX_OBJECTS = 1000;
GameObject* theObjects[MAX_OBJECTS];
// You could point to a specific type like this
theObjects[0] = new Man; // Providing 'Man' has inherited from GameObject
for(int i=0; i < MAX_OBJECTS; i++)
{
theObjects[i]->Draw(); // This can draw men, dog, trees, anything.
}
The level of complexity in your game really determines how you'd structure things but, as I said, there's not one right way to do things.
so the way i said was more or less correct then?
btw bad wording i guess, cause i never intended to ask where to put the object, i just explained how i would do things, to see if i had understood it.
so i kinda failed by placing a question mark at the end :/ sorry bout that. but thanks :D