r/howdidtheycodeit • • Jul 03 '22

Question How do they code rogue like upgrades??

I’m looking at making a game with a roguelike progression style. The main thing that is confusing me is how having such a wide variety of effects would work.

For example, stat bonuses would be easy. But say I’m making effects that add new mechanics to projectiles, new mechanics to movement, or more complex things. How would I handle coding that?

I assume I would have a database of all the upgrades and their effects, but on the actual classes do I just need 1000 boolean variables for if it has that effect or not and check all of them one by one in the events? How could I approach that? By

53 Upvotes

24 comments sorted by

View all comments

Show parent comment

2

u/Flohhhhhh Jul 03 '22

I was thinking this just now. I use Unreal, theoretically I could add the upgrades as actor components, which is sorta just like adding a function to a class externally. I could just have these objects execute something extra whenever the needed event is triggered. That way there’s no checking, just extra functionality added on.

This wouldn’t work for everything but it’s a good step in the right direction.

3

u/CarniverousSock Jul 03 '22

So IIRC in unreal, objects in the scene have to be actors. So you could make an actor class that has a public list<powerupbehavior*> member, where powerupbehavior is just an abstract class with a pure virtual function. When it comes time to add the power up, you just instantiate the correct subclass of powerupbehavior and add it to the list.

3

u/CarniverousSock Jul 03 '22

An important thing to consider, though, is when/how to allocate these. If you attach behaviors to a lot of short-lived actors, it would be better to have a single system keep the list, which propagates the effects to each new actor.

That way, you could use object pools for actor creation without having to allocate behaviors for all of them.