Implementing Power-Ups with the Visitor Pattern

In this chapter, we are going to implement a power-up mechanic for our game. Power-ups have been a core ingredient of video games since their early inception. One of the first games that implemented power-ups is Pac-Man from 1980. In the game, you could eat Power Pellets that would give Pac-Man temporary invincibility. Another classic example is the mushrooms in Mario Bros., which made Mario taller and more robust.

The power-up ingredients that we will build will be similar to the classics but with a little more granularity. Instead of having a power-up boost a singular ability of an entity, we can create combos that give out multiple benefits at once. For instance, we could have a power-up ...

Get Game Development Patterns with Unity 2021 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.