- Home /
Best practice for powerup implementations
Hi all,
I'm making a space shooter game, and I'd like to implement a lot of different buffs / debuffs in the game.
Some example: - Take Damage over time (x damage per second) - Double all damage dealt - Reverse controls
My first thought was to use "if" statement in my existing scripts and check for flags to see if a specific powerup is active, but that doesn't feel right in terms of code maintenance.
Moreover I'll probably think of a lot of other powerup ideas over the course of time, and it could quickly become a mess in this way. Not to mention that some powerups could mess with very different things, so their implementation would be scattered in the code. And I might also want to make them stackable.
Ideally I was hoping to find a way to make each buff/debuff as a prefab that would be instantiated as a child of the affected character. But how can I mess with the character's controls in this way.
I guess powerups are part of a lot of games, so I was hoping perhaps you guys can show me to a nice ressource where someone explains how those things are usually handled.
thanks in advance
Answer by Ngoc Ngo · Jul 04, 2014 at 10:39 AM
I would recommend Strategy Pattern, then use a Factory to cover it. "Head First Design Patterns" described these clearly. Hope it helps!
Oh my god, I've read that book like 4 times... I'm ashamed now that I didn't even think of this pattern... There I was trying to solve this with Observer pattern and delegates.
Flying rubber ducks FTW. Too bad they're not publishing Head First anymore.
Thanks
Your answer
Follow this Question
Related Questions
Component-based design: Do I have the right idea? 1 Answer
How do I pass data up nested IEnumerators? 1 Answer
Modular ability creation in editor 1 Answer
Swapping between weapons within an isometric. 0 Answers
ramdomised weapon pickup 1 Answer