I’m starting to plan out my code base for a game I want to work on, and realising that a lot of my classes are going to require the same properties, such as Team ID, Heat/Image/Radar Signature, so on and so forth. I’ve created a child of the ‘Actor’ class called ‘BZGame_GameObject’ class, which would hold all of those values. The problem is, I also want all my Pawns and suchlike to have these properties as well. That way when I come to programming my weapons and various things later, I can simply cast to GameObjects rather than checking against lots of individual classes for the same variables. Here’s an example:
- All of my Objects in the world will have a ‘Heat Signature’, a float variable that determines how much heat that object generates.
- Missiles and other weapons will use that ‘Heat Signature’ to determine what object they should fly towards, and post process will use it for various material effects too.
- Instead of casting or getting heat information from all of my different classes, I could just cast to the ‘GameObject’ master class that has these variables.
Another reason is that I want to avoid creating an identical copy of the ‘Pawn’ class just so that it derives from my master ‘GameObject’ class, it’d be a lot of extra work and if the Pawn class ever changes in code I would have to modify my code too.
So, any suggestions? I basically want to add some functionality and properties to the Actor class without modifying source code, so that I can still use the actor’s child classes.