For my game,
Everything inherits from Entity, then other things like Player, PhysicsObject, etc, inherit from Entity. The physics engine sends collision callbacks which has an Entity* to the B that A collided on. Then, lets say A is a Bullet, A tries to cast the entity as a player, if it succeeds, it reduces the player’s health.
Is this a good design?
Thanks
I believe that messaging system is somehow better suits your “world”.
In this case you will not need neither dynamic casts nor to check result of dynamic cast.
Update, here is an example:
Entity::handle(uint message, Entity* the_thing)implementation can be wrapped intoMSG_MAP_START, MSG_MAP_END and HANDLE_MSG(msg) macros so your code will look like:
Many variations of this are possible.
By the way Objective-C has this kind of messaging built-in into the language. With extremely ugly notation but still.