3
\$\begingroup\$

I'm working on my combo system and I keep getting this weird problem. It's a pretty basic setup: when the player hits the attack button it changes the character's current action to "attack", if the player hits an enemy then an int (f) is set to the next combo number, after the attack finishes the character's current action turns to "standing" and an if statement makes the combo int equal to f.

So basically it reads like this:

switch (action)
{
    case "attack":
        if (combo == 0)
        {
            if (enemy.Hit(playerSquare))
            {
                f = 1;
            }
            else
            {
                f = 0;
            }
            if (animationDone)
            {
                action = "stand";
            }
        }
        else if (combo == 1)
        {
            same
        }
        else if (combo == 2)
        {
            same
        }
        break;
}

if (action != "attack")
{
    combo = f;
}

My setup works, however, if I press the attack button too quickly it either doesn't add to the combo int (keeping it at the same number as before) or adds to it twice (depending on whether or not I slow it's update rate.) I'm sure there's probably an easy way to fix this and I'm not seeing it or maybe there's a better way to do this that I haven't considered yet, so I'm hoping you guys can help out. Any suggestions?

\$\endgroup\$

2 Answers 2

5
\$\begingroup\$

I strongly suggest you to use a state machine to model your combo system. If your state machine library does not have it, you can add a timestamp to process your transition or timeout to force a status change. Using a state machine you can model every complex combo without big troubles.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ With the second upvote to this response I earned my first thousand reputation points! Thank you all for your trust and appreciation of my efforts. \$\endgroup\$
    – FxIII
    Commented Jul 28, 2011 at 7:12
0
\$\begingroup\$

I don't really understand how your states work, but your code seems like a really complicated way to do this. Why not do something like:

switch (action)
{
    case "attack":
        if (animationDone){
            action = "attackComplete";
            break;
        }

        if(enemy.Hit(playerSquare)){
            f++; // increase f with every successful hit
        } else {
            f = 0; // reset the combo-counter
        }
        break;

    case "attackComplete":
        combo = f; // store previous combo
        f = 0; // reset f
        action = "stand";
        break;

    case "stand":
        // do whatever here
        break;
}

But this might not solve your problem at all, since the way f is increased entirely depends on when and where you call that code.

\$\endgroup\$
1
  • \$\begingroup\$ The problem with that is I actually use the increasing combo number to play a different animation while in the "attack" state. So each if combo statement is actually the next animation in the combo sequence. I definitely agree with you that I made this is more complicated than it needs to be, but this is the first time I've made a combo system so I'm trying my best. \$\endgroup\$ Commented Jul 27, 2011 at 7:44

You must log in to answer this question.

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