This is from memory so excuse any errors (I''m at work and my code is at home).
class CPresence {public: //place dimensions and position of entity here...};class CEntity:public CObject {private: static CPresence presence[MAX_ENTITIES]; static short counter;protected: CPresence *self; void Init ();public: short SetPosition (long x, long y, long z); void SetDimensions (...); long GetX (); long GetY (); long GetZ (); virtual short Move (long speed);};class CAsteroid:public CEntity { //place asteroid specific interface here...public: CAsteroid (); //calls CEntity::Init() short Move (...); void Update (...);};
Okay, this ain''t pretty... I can post the actual header file tomorrow morning if you''re interested. (Notice I use integers for everything... I''m old-school =b) I''ll explain all this in better detail:
CPresence just holds whatever data your game objects require. CEntity is the parent class of all your game objects and holds an array of CPresence objects. This is very important: the array is both static and private. This means that all of your objects can view the data in the array ONLY if the methods allow it but no CEntity derivative can access it directly. CEntity has no idea what other "entities" are doing unless those entities allow that information to be passed. It is in fact very controlled.
The "counter" property simply counts how many of our CPresence objects have been used so we know what the next available presence is.
The "self" pointer points to its own presence in the array. This allows direct access only to its own data. Notice that this property is protected. This means that CAsteroid and other derivatives of CEntity can access their own data but only theirs and no other object can access it directly.
The Init() method (also protected) assigns a presence to the object. In reality, it only assigns presence[counter++] to *self.
SetPosition() does as its name implies but not without first checking for collisions. It returns true if there is a collision.
Move() accepts a parameter for speed in units per second. This is adjusted to the current framerate and the new position is calculated. That position is sent to SetPosition() where the collision is checked.
The other methods simply allow the outside world to "set" or "get" properties of the CPresence object that *self points to.
The CAsteroid object contains all asteroid specific properties and methods. Notice the constructor. This calls the CEntity::Init() method to snatch up a presence.
This very off-the-cuff. My actual header file includes a LOT more than this and would probably be more confusing. The presence array is actually organized into a two-dimensional array of linked lists (the b!tch can handle 8,000 entities at 66 fps! WOOHOO! ...on a P$ 1.4GHz, btw). Anywayz... is this clear?
btw, I think the CEntity constructor assigns the presence... not sure =/
- Jay
"I have head-explody!!!" - NNY
Get Tranced!