Creating Modular Powerup Systems

Rob George
2 min readApr 13, 2021

Day 16 — Aspiring Game Creator

2D Game Dev: Galaxy Shooter

Player activating both Triple Shot & Speed Boost power-ups!

Objective: Create a powerup class which uniquely identifies each power-up class and communicates that power-up back to the player class.

Pseudo Code:

  • Define an enum for each power-up type
  • Modify existing variables & method names to generic names
  • Create a method to pass power-up type to player class

After creating the Triple Shot power-up & starting to work on the Speed power up it’s clearly evident that EVERYTHING in the Triple Shot class would be in the Speed Power-Up class so it’s time to create a Power-Up class which will contain more generalized variable names and methods names to work with both power-ups and any additional power-ups down the road.

To easily define the power-up type an enum will be used:

After creating the Speed power-up game object and adding the PowerUp script the enum will allow an easy drop down selector for assigning the power-up type.

Choosing Speed Enum drop down

And finally, the OnTrigger collision detection on the power-up will simply destroy the power-up game object.

Where the communication between classes happens is in the Player class colliding with the Power-Up class.

The Player class will pass the power-up string type to the generic ActivatePowerUp method — sure, the numerical representation of the enum could be used as well, but this was the chosen technique — and the appropriate power-up will be enabled on the player.

--

--