4
\$\begingroup\$

Ok guys, I understand how to make a basic input buffer.

Here is my code:

public class InputBuffer : MonoBehaviour {

    public int max_buffer;
    public enum keys { down, up, left, right, X, Y, Z, A, B, C }
    public List<keys> InputPlayer;
    public enum Special { WPunch, MPunch, SPunch, WKick, MKick, SKick, Hadouken, Shoryuken }
    public List<Special> SpecialsPlayer;

    void Start () {
        InputPlayer = new List<keys>();
        SpecialsPlayer = new List<Special>();
    }

    void AddKey(keys key)
    {
        InputPlayer.Add(key);

        if (InputPlayer.Count > max_buffer)
        {
            InputPlayer.RemoveAt(0);
        }
    }

    void CheckSpecial()
    {
        if (InputPlayer[InputPlayer.Count-1] == keys.A)
        {
            if (InputPlayer[InputPlayer.Count-2] == keys.right)
            {
                if (InputPlayer[InputPlayer.Count-3] == keys.down)
                {
                    SpecialsPlayer.Add(Special.Hadouken);
                }
            }
        }
    }
}

This works really well, but then I get repeated keys in the buffer when I keep a key pressed.

I could fix it by having a last keypressed variable and then only calling the inputbuffer.getkey if the key pressed is diferent. But this makes the buffer to behave rather stiff.

I would love to see how can I improve my code so It doesn't recognizes multiples keys when a button is kept pressed, but also allow for charge moves (Guile's sonic boom).

I also would love to see how input shortcuts works (using a previous special command as part of a second one, usually used in cancels to supers).

I would love to see what's the proper way to handle input buffers in kof and SF.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Possible duplicate: gamedev.stackexchange.com/questions/43708/… \$\endgroup\$
    – House
    Commented Mar 13, 2015 at 17:26
  • 1
    \$\begingroup\$ I don't think it's a duplicate. Cristian asked for behaviors not mentioned in the post you linked, such as reuse part of the same inputs in a special and a super. \$\endgroup\$
    – Emir Lima
    Commented Mar 13, 2015 at 19:25
  • 1
    \$\begingroup\$ What makes the input buffer or a normal fighting game different from that of a professional fighting game? \$\endgroup\$
    – JPtheK9
    Commented May 29, 2015 at 17:43

1 Answer 1

-1
\$\begingroup\$

Store the flag for each key and set it true on keydown. Don't add this key to buffer while corresponding flag true. Set flag to false when keyup happens.

\$\endgroup\$

You must log in to answer this question.

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