c++ classes of game objects
Ok... Now can anybody tell me how are the RTS game entities (units, buildings, resources, etc...) are implemented in c++ (i mean the game objects, i do not need c++ tutorials)? Does anybody have such kind of sources?
What i mean is - every unit in almost any RTS has its own features and characteristics: health, power, speed, etc.
The general questions are:
- What are the best practices using C++ and objects for game development?
- What game elements are best created with C++ classes, and what elements are best created with good old C?
this is one way (which i think is best, but that's not exactly the same as th ebest way):
you could make an abstract base class for units (let's say CUnit), which has data members for things that every unit has (i.e. health, speed, whatever), and all the member functions that will be necessary to make the units do what they must do (i.e. goToPosition(), attack(), etc). make the member functions virtual.
then, you derive unit types from that base class, and override the virtual functions. for example, the infantry attack() function might shoot a machine gun at a target, the grenadeer (sp?) unit throws grenades; all this goes in the overridden virtual functions.
then, you create your units when you need them and add them to your list/array/whatever where you store all the units with pointers to the base class; because the member functions are virtual, the computer decides which to use when you call the function from the base pointer:
or something to that effect. sorry if that doesn't make sense, i am quite overtired at the moment. read up on virtual functions in classes and inheritance.
HTH
[edited by - krez on December 26, 2002 8:55:50 PM]
you could make an abstract base class for units (let's say CUnit), which has data members for things that every unit has (i.e. health, speed, whatever), and all the member functions that will be necessary to make the units do what they must do (i.e. goToPosition(), attack(), etc). make the member functions virtual.
then, you derive unit types from that base class, and override the virtual functions. for example, the infantry attack() function might shoot a machine gun at a target, the grenadeer (sp?) unit throws grenades; all this goes in the overridden virtual functions.
then, you create your units when you need them and add them to your list/array/whatever where you store all the units with pointers to the base class; because the member functions are virtual, the computer decides which to use when you call the function from the base pointer:
// psuedocodeCUnit* UnitArray[NumUnits];for(loop through all units, using int t as the index) { CUnitPointer[t]->attack(); // have all units attack // in their own special way // if this pointer points to an // infantry, the computer calls the infantry attack() method. // if this pointer points to a grenadeer (sp?), // it calls the grenadeer attack(). // etc... };
or something to that effect. sorry if that doesn't make sense, i am quite overtired at the moment. read up on virtual functions in classes and inheritance.
HTH
[edited by - krez on December 26, 2002 8:55:50 PM]
I don''t need c++ programming howtos, i know c++ and its concepts... I want to know about the concrete data structures and classes. How are classes organized in other games?
quote:Original post by klio
I want to know about the concrete data structures and classes.
I want to know about weaponsmithing. I won''t tell you what I want to know about it, you should figure that out for yourself.
See where I''m going with this? If not, give up programming forever.
swift URL | browse my bookmarks [server may not always be on]
Sensimed | Info/download
wtf?
thats totally up to you, thats the design. here is a crappy example:
[edited by - billybob on December 26, 2002 9:44:37 PM]
[edited by - billybob on December 26, 2002 9:45:16 PM]
thats totally up to you, thats the design. here is a crappy example:
+RTSUnit+-+Vehicles| +-+Jeep| +-+Tank| +-+Truck+-+Planes| +-+Jet| +-+Transport| +-+Helicopter+-+People| +-+Riflemen| +-+Worker| +-+Laserdude
[edited by - billybob on December 26, 2002 9:44:37 PM]
[edited by - billybob on December 26, 2002 9:45:16 PM]
Um, krez essentially covered that, buddy.
But since you can''t think for yourself, here''s a psuedo-example for you:
But since you can''t think for yourself, here''s a psuedo-example for you:
robotUnit { Health Armor primaryAttack secondAttack rangeOfVision Move}robotUnit Tank { Move { //roll foward }}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement