Hi Guys,
I’ve been lurking these forums for a long time now but it’s my first time actually making the effort to post my own question.
Now to the problem…
Another and myself are trying to create an action adventure game with melee fighting and there are only 2 of us actually working on it, him on the art and myself on game design and programming. I come with questions about how to go about coding a 2d combat game. I don’t need to know specifics about coding I’m familiar enough. I’m talking about how would i go about doing the collisions properly, what kind of system would I use for the combo’s and what would be the best way to make sure that this is still possible to code as a single person while still being efficient.
Now the catch, each of the actions that can be done(combos/attacks) can be done in 3 different states(to the same effect) this is where a state machine gets tricky for me. I’ve thrown away 20 ideas and started from scratch 3 times each time thinking I had it then realizing it was stupid.
Well Initially I was using a system that would register directions of the input axis then combine those with attack inputs to make combos, see streetfighter, however the result was not looking like what I wanted not to mention the code became incomprehensible even to me with the amount of if statements involved that I just had to start again.
Another time i was using a state machine to make sure that each input would begin the state associated with the first input. Slowly I realised that I wouldn’t be able to link commands using this and it was scrapped again.
Now I’m using a state machine again however, I’m setting out the combat in stages of attack where: Stage 1
Input 1 or 2 Stage 2
Input 1 or 2 Stage 3
Input 1 or 2
etc. and there will be different results on each stage depending on the result of the preceeding stage.
This one I think gives me most hope however I’m still not confident i’m going about it the right way because it seems WAAAYYY too hard to get even the most simplest of things to work correctly.
Hmm, this actually looks quite a lot like a weapon switch system I tried once. My solution worked quite well for what I wanted to do, I’m not sure how it translates to a fighter since my solution wasn’t time based nor did it take attack animations into account.
this is roughly how it worked :
I had a State class.
a state had 3 arrays. Weapons, States, Inputs.
and a string that was responsible for containing the most recent user inputs (up to a certain length)
Every time input was registered, it would check the inputs array to see if the most recent inputs matched any of them.
If it did, it would activate the corresponding weapon and go to the corresponding state.
This systems requires very little in actual code because it’s content driven. Just add more states, weapons and inputs, no need to change code.
It’s infinitely recursive, the combo can go on as long as you’d want (do make sure there is an ending or reset point).
I can try to find the source code, allthough I’m afraid it might be lost.
I couldn’t find the exact code. but it looked something like this pseudo code
Keep in mind that his is designed with sequence input in mind. Like the fireballs and stuff in Street fighter. Not so much the combo attacks that you see in dead or alive and soul calibur. Allthough they should work aswell.
string RecentInputs;
If (PressUpKey){
RecentInputs = RecentInputs + "u";
}
If (PressDownKey){
RecentInputs = RecentInputs + "d";
}
If (PressLeftKey){
RecentInputs = RecentInputs + "l";
}
If (PressRightKey){
RecentInputs = RecentInputs + "r";
}
If (PressAttackKey){
RecentInputs = RecentInputs + "a";
}
For each inputcommand in inputcommands array
if RecentInputs ends with inputcommand, do stuff.
It’s probably not the most efficient way to handle this. There’s also a few flaws with the system that may or may not apply to your situation.