Entity Component System pattern
We will now spend five minutes wallowing in the misery of an apparently unsolvable muddle. Then, we will see how the entity-component pattern comes to the rescue.
Why lots of diverse object types are hard to manage
In the previous projects, we coded a class for each object. We had classes such as Bat
, Ball
, Crawler
, and Zombie
. Then, in the update
function, we would update them, and in the draw
function, we would draw them. Each object decides how updating and drawing take place.
We could just get started and use this same structure for Run. It would work, but we are trying to learn something more manageable so that our games can grow in complexity.
Another problem with this approach is that we cannot take advantage of inheritance. For example, all the zombies, the bullets, and the player character from the zombie game draw themselves in an identical way, but unless we change how we do things, we will end up with three draw
functions...