Classes group code and data together
Finally, we made it to one of the most important revolutions in computer science, something that shook the world of programming languages in the mid-60s: classes.
Some smart computer engineers thought about how we use data and functions and saw that we often use a select set of functions on a select set of data. This led them to group these two together so that they would live very closely with one another. Such a group is called a class.
In games, classes often model specific separate entities. We could have a class for the following:
- The player
- Enemies
- Collectibles
- Obstacles
Each of these classes contains and manages its own data. The player class could manage the health and inventory of the player, while the collectibles manage what kind of collectibles they are and what effect they have on the player.
In essence, each class is a custom data type, just like the ones we saw before. But now, we put in the data...