1
\$\begingroup\$

Summary: What approach should I take to allow custom inputs saved in a file be interpreted in the engine?

So I am making a game engine similar to Mugen where I want characters to have their own special combo inputs. Similar to how Kage has the Shun Goku Satsu. Where its just a combination of multiple keys pressed in quick succession. The thing is I want to give the ability to create these combinations to the character creators and let the engine handle the rest.

I already parsed the list of moves from the character file, so now I got an in-memory list of valid input sequences for each character and what moves they trigger. But I don't really know how to interpret a valid sequence.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ It's not really clear to me where your problem with this is. Are you asking how to structure your file format? Or how to represent these input sequences in memory? Or how to detect when a player has entered a valid sequence? Answering all of these questions would be far too broad, so please try to be specific about what part you need help with. \$\endgroup\$
    – Philipp
    Nov 16, 2020 at 13:16
  • \$\begingroup\$ Yeah sorry about that I didn't really know how to ask but basically how do I detect a valid sequence? \$\endgroup\$ Nov 16, 2020 at 13:18
  • \$\begingroup\$ Can we I assume that after parsing the character moves from the file you got them into some data structure representing a list of input sequences and what move they trigger for that character? \$\endgroup\$
    – Philipp
    Nov 16, 2020 at 13:20
  • \$\begingroup\$ Yeah thats what I was planning. \$\endgroup\$ Nov 16, 2020 at 13:21

1 Answer 1

2
\$\begingroup\$

What you basically need to do is have a list of the input sequences of the character and a counter for each sequence which states at what step of that input sequence they are currently on. For example, let's assume that the list of input sequences of the player-character is the following:

punch, punch, kick
punch, kick, punch, forward
kick, punch, backward

At the start of the game, the player did not make any inputs yet, so the counter for all three sequences would be at 0.

When the player presses "punch", then you would check all three sequences and notice that it matches the currently expected input for sequences 0 and 1. So you increment the counters for those two sequences by one. Now the list of sequences with their counters look like this:

1    punch, punch, kick
1    punch, kick, punch, forward
0    kick, punch, backward

Now the player presses "kick". The first sequence expects a punch, so this was a wrong input for it. Its counter gets reset to 0. But kick matches the next expected entry for sequence 1, so its counter gets incremented to 2. It also matches the first input of sequence 2, so it gets incremented to 1:

0    punch, punch, kick
2    punch, kick, punch, forward
1    kick, punch, backward

Next input is "punch", which actually matches the next expected input of all three sequences:

1    punch, punch, kick
3    punch, kick, punch, forward
2    kick, punch, backward

Now there are four possible options which could happen next:

  1. The player might press "punch" again, advancing the sequence 0 but resetting all others
  2. The player might press "forward" completing sequence 1 and resetting all others
  3. The player might press "backward", completing sequence 2 and resetting all others
  4. The player might press something entirely different, resetting them all.

When the player actually completed a sequence, then they just entered a valid move sequence. Their character performs that move and all the sequence gets reset to 0.

When you implemented this successfully, then there are a couple other things you might want to take care of next:

  • When the player doesn't make any inputs for a while, then you might also want to reset all the sequence counters back to 0. This can be easily accomplished by sending a "null input" to the system which does not match any input the content creators can define.
  • What happens when the character gets hit while the player is performing an input sequence? Does it interrupt those sequences? And what happens when a sequence finished, but the character is currently in a state where they can not perform this move? This is more of a game design question, so you will have to find your own answer for these questions (or open a new one).
  • The content creators might create sequences which are prefixes for others. For example, they might create one sequence "punch, punch, kick" and another "punch, punch, kick, punch". When a player entered the first sequence, then there is no way to tell if they are finished inputting the first sequence or want to continue with the second. You have to decide how to handle that situation. You might disallow that, you might wait for a 4th input before executing the move, or you might start the first action but then abort it and continue with the other on the 4th input.
  • The content creators might create sequences which are suffixes of others. This might lead to ambiguous situations where the player completed two sequences at the same time. Like "punch, punch, kick" and "kick, punch, punch, kick". When the player completes the second sequence, they also completed the first. In that case you should give precedent to the longest sequence. When two sequences have the same length... well, then the content creator created a duplicate entry, and you should smack them for that reject the character file with an error message.
\$\endgroup\$
1
  • \$\begingroup\$ "smack them for that" xD thanks for the answer this is going to help me a lot 😊 \$\endgroup\$ Nov 16, 2020 at 14:06

You must log in to answer this question.

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