Book Image

Panda3D 1.7 Game Developer's Cookbook

Book Image

Panda3D 1.7 Game Developer's Cookbook

Overview of this book

Table of Contents (20 chapters)
Panda3D 1.7 Game Developer's Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Decoupling modules using events


Gameplay code can be a complex beast. In many cases, there are complex, many-to-many relationships between all sorts of different game entities. This can be good for the player, as he or she might enjoy the interesting emergent patterns of behavior created by this kind of game object interconnection.

For the programmer (that is you), who has to think about and write all the code that makes this happen, things look different, though. Having the game entity that creates an event which holds references to all the objects that will react to it could be problematic. This could lead to chaotic, messy code and a great deal of unnecessary coupling between otherwise independent and differing types of objects. The more complex the code, the more you need to create a more modular and maintainable design.

From a software engineering point of view, this situation cries out for a form of publish/subscribe design pattern that allows game entities (and other kinds of objects...