Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

klio

c++ classes of game objects

This topic is 5751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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:


// psuedocode
CUnit* 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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
wtf?

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]

Share this post


Link to post
Share on other sites
Um, krez essentially covered that, buddy.

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
}
}

Share this post


Link to post
Share on other sites
Alright... Its seems to me there''s a misunderstanding... I will ask another way. Are there any open-source (c++ coded) RTS at all???

Share this post


Link to post
Share on other sites

This topic is 5751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!