1
\$\begingroup\$

In my game, I have a player, ennemies and tiles like Mario. And each entity has a different behavior when it touches a tile. For exemple, when my player walks on spike he dies. But a certain type of ennemy can walk on spike without dying.

Is there a good way to write this interaction between objets in OOP. I mean without cast, without breaking OCP principle and not having to write every behavior in every objects. Is there a design pattern for this purpose ?

\$\endgroup\$
  • \$\begingroup\$ I touched on an example like the spikes in an earlier answer using the component pattern to separate things that deal damage on collisions and things that can be damaged (or resist/ignore certain types of damage) \$\endgroup\$ – DMGregory Jun 13 '17 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.