if (weapon1.hitTest(enemy2) == true)
{
enemy2.takeDamage(weapon1.damage);
}
I could do something like this:
Message newMsg* = new Message("attack", "enemy2", weapon1.damage);
MessageHandler->dispatch(newMsg);
That way the objects aren't coupled too tightly and it leaves a lot of freedom in design. You can let objects just check their messages periodically and react to them instead of each object serially searching through object lists and invoking direct functions. That's a design style I'd probably have never thought of, and it leaves me a lot of questions. My brief search on Wikipedia said that message passing in gaming is often just relegated to networked multiplayer to allow a server to decide what really happens when considering lag and all. That makes great sense, but the impression I've gotten is that at least some games use it throughout their design in a manner like I presented above. Is that really true? It seems to me that it's a neat way to abstract things and make it more extensible / modular, but it also sort of seems inefficient and potentially error prone or complicated. I'm still in the phases of designing my next game project, and if this really is a common design pattern then I'd like to use this as an opportunity to learn about it. Thanks for any input.