0
\$\begingroup\$

Suppose you're making a 3D platformer like Super Mario, if you jump on a Goomba, does Mario (the class) know that it just landed on a Goomba and then tell that Goomba to die, or does the Goomba realize that he is being smashed and dies ?

I want to go with the first approach but it will end up with a huge If/then (or Switch/Case) script, also the reason why this is "problematic" is that many objects will make the player have a "reaction", for example if you land on a Goomba, you don't just kill it, but it forces you to jump, that jump event, what's the best way to handle it ?

Thanks

\$\endgroup\$
2

1 Answer 1

1
\$\begingroup\$

This is a fairly timeless question I think, which means that the answer is going to depend on what exactly you need to do, if something needs to be optimized (only if it's running slow!) and other case-dependent issues.

The question DMGregory linked has a lot of good information, but I'd like to address this specific line in your question:

for example if you land on a Goomba, you don't just kill it, but it forces you to jump, that jump event, what's the best way to handle it ?

Your question up to that point might have a single perfect answer, which is suddenly not the right answer when you add this requirement. This is particularly an issue in game development when your prototyping phase is defined by the vague requirement of "what feels fun to play?"

So the answer I'm suggesting is similar to optimization. First narrow down your requirements, and just plan refactoring your code into your prototyping.

I recently had the same issue, and the solution that worked best was to implement every game mechanic in the easiest way possible. Using inefficient methods like SendMessage makes it vastly simpler to get a mechanic working and find out if it's even worth implementing or needs changing. As you continue to implement mechanics, you'll see what requirements you need to focus on, but you'll also find which connections are used less often than you expected and don't need to be super-robust. Even more importantly, you'll find those that are critical and not only need to be optimized, but maybe need to be written in a particular way that makes your design work easier (for example, customizing enemy types without rewriting a lot of boilerplate code).

\$\endgroup\$
1
  • 1
    \$\begingroup\$ hey thanks a lot for your input and sorry for the late reply, i must have missed the notification \$\endgroup\$ Commented Apr 30, 2021 at 23:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .