Original Post
Hello sir or madam or sirs or madams,
So, I am working on a game that has some special moves that are invoked through button sequences, much like a fighting game. So far, I've just got this ButtonSequence class that holds a list of the buttons that the player pressed, in the order that they pressed them.
Every time the player presses a button on the controller, that button press is added to the list. Then, the last N button presses in the list are checked against each special move combo for any matches.
If there is a match, then the special move is executed and a new, empty ButtonSequence object is created.
Additionally, if there is more than 250ms between button presses, the ButtonSequence is broken and a new, empty ButtonSequence is created.
And this is all well and good for special move combos involving a simple series of button presses, but as I think about the fighting games that I have played in the past, it is never this simple. There are other considerations:
1. Some special moves involve holding a button down. While the button is being held, the player often (but not always) has to press other buttons in a certain order. The timing is varied. Sometimes, the initial press of the 'held' button(s) is part of the sequence, and must be quickly followed by the rest of the sequence or else the sequence is broken. Sometimes, it doesn't matter -- as long as you were holding the button while performing the rest of the sequence, it works, even if you started holding the button several minutes ago. Sometimes, the button must be held for a specific amount of time, e.g. Liu Kang's bicycle kick. Sometimes this time must be precise, and sometimes it can be held as long as you want as long as it exceeds some minimum.
2. Many buttons sequences seem to have buttons that can be ignored. For instance, with Liu Kang's bicycle kick, it doesn't matter if you press other buttons while holding down LowKick. In fact, you can even execute other special moves while holding down LowKick. As long as you hold LowKick for 5 seconds before releasing it, you're golden. But with other moves, it very much matters. Pressing a button that isn't in the sequence will break the sequence.
So it gets very complicated. I have a lot of ideas about how to approach this, but I'm sort of overwhelmed by the hairyness of it all. I am hoping that, since this topic is almost as old as the video game medium itself, there will already be some solid algorithms in place. Something like, perhaps, what DFA's are to regular expressions (I actually explored this route for button presses a bit, but it wasn't obvious to me how to get it to work, with all of the button holds and timing issues).
So, I am working on a game that has some special moves that are invoked through button sequences, much like a fighting game. So far, I've just got this ButtonSequence class that holds a list of the buttons that the player pressed, in the order that they pressed them.
Every time the player presses a button on the controller, that button press is added to the list. Then, the last N button presses in the list are checked against each special move combo for any matches.
If there is a match, then the special move is executed and a new, empty ButtonSequence object is created.
Additionally, if there is more than 250ms between button presses, the ButtonSequence is broken and a new, empty ButtonSequence is created.
And this is all well and good for special move combos involving a simple series of button presses, but as I think about the fighting games that I have played in the past, it is never this simple. There are other considerations:
1. Some special moves involve holding a button down. While the button is being held, the player often (but not always) has to press other buttons in a certain order. The timing is varied. Sometimes, the initial press of the 'held' button(s) is part of the sequence, and must be quickly followed by the rest of the sequence or else the sequence is broken. Sometimes, it doesn't matter -- as long as you were holding the button while performing the rest of the sequence, it works, even if you started holding the button several minutes ago. Sometimes, the button must be held for a specific amount of time, e.g. Liu Kang's bicycle kick. Sometimes this time must be precise, and sometimes it can be held as long as you want as long as it exceeds some minimum.
2. Many buttons sequences seem to have buttons that can be ignored. For instance, with Liu Kang's bicycle kick, it doesn't matter if you press other buttons while holding down LowKick. In fact, you can even execute other special moves while holding down LowKick. As long as you hold LowKick for 5 seconds before releasing it, you're golden. But with other moves, it very much matters. Pressing a button that isn't in the sequence will break the sequence.
So it gets very complicated. I have a lot of ideas about how to approach this, but I'm sort of overwhelmed by the hairyness of it all. I am hoping that, since this topic is almost as old as the video game medium itself, there will already be some solid algorithms in place. Something like, perhaps, what DFA's are to regular expressions (I actually explored this route for button presses a bit, but it wasn't obvious to me how to get it to work, with all of the button holds and timing issues).