So I’m currently working on a little personal programming project, I’m trying to make a sort of fighting game prototype to at least understand the programming that goes into making a fighting game. One thing I’m having particular trouble with is the motion inputs. I’ve got a system rigged up where, when an input for a direction is detected, a string representing that input is temporarily added to a list, and then shortly removed. Let’s use a classic quarter-circle forward motion, the Hadouken, as an example. The script checks that “Recent Inputs” list for a down input, then checks if the two inputs that come after it are down-forward and forward, if so, then…hadouken!
foreach (string input in recentInputs)
{
#region Quartercricles
//Quartercircle Forward
if (input == "down")
{
if(input != null)
{
int startingInputIndex = recentInputs.IndexOf(input);
int baseStartingInputIndex = startingInputIndex;
if (recentInputs[startingInputIndex += 1] == "downForward" && recentInputs[startingInputIndex += 1] == "forward")
{
Debug.Log("Hadouken!");
startingInputIndex = baseStartingInputIndex;
}
}
}
This code kind of works, but I feel like it’s really unreliable and inefficient. I mean look how long the code for a half circle is. Imagine if I wanted to do a 360 or a 720, it’d be a nightmare.
if (input == "back")
{
int startingInputIndex = recentInputs.IndexOf(input);
int baseStartingInputIndex = startingInputIndex;
if (recentInputs[startingInputIndex += 1] == "downBack" && recentInputs[startingInputIndex += 1] == "down" && recentInputs[startingInputIndex += 1] == "downForward" && recentInputs[startingInputIndex += 1] == "forward")
{
Debug.Log("Yoga Fire!");
startingInputIndex = baseStartingInputIndex;
}
}
What I would ideally like to do is just set up lists with the motions already in them, and then see if my Recent Inputs list contains that same set of inputs, so if there’s a series of inputs that match up with the QCF list, it runs the Hadoken code, and so on. This would allow me to create a far more universal input system than what I have currently. Is there a way to do that, to see if a list contains the contents of another, in order? Or can you think of some better way to pull off these motion inputs, something more efficient?