1
\$\begingroup\$

I am making a game in which the player character can gain traits that change how their character behaves in my world model or add functionality to it. For example, the character might gain the "feather" trait that changes how fall damage is calculated or the "strong" trait that means the player can now pick up items that were previously just part of the scenery.

I have been hard coding traits in their relevant classes and switching a boolean to change behavior when they come into play, but it is getting rather unmanageable as my trait list grows.(I am also missing out on a lot of the emergence I was hoping to get) There must be a more scalable and decoupled way of doing this.

How would you code such a feature where code behavior changes or expands at runtime? If you are not inclined to do my work for me, which programming patterns would you use to achieve this kind of behavior?

\$\endgroup\$
9
  • 2
    \$\begingroup\$ Entity component system \$\endgroup\$ Commented Mar 17, 2017 at 10:32
  • \$\begingroup\$ The title is fine IMHO, I knew at a glance what you sere talking about. \$\endgroup\$ Commented Mar 17, 2017 at 14:23
  • \$\begingroup\$ Objects in the entity component pattern are initialized at runtime, but once created the pattern doesn't describe how to change the objects at runtime, or add new functionality to it. \$\endgroup\$ Commented Mar 17, 2017 at 14:53
  • \$\begingroup\$ Single- or multiplayer? \$\endgroup\$ Commented Mar 17, 2017 at 16:08
  • \$\begingroup\$ It is a single player game. Is that relevant? \$\endgroup\$ Commented Mar 17, 2017 at 16:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.