Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

share|improve this answer
1  
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. –  FxIII Jul 28 '11 at 7:12

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.

share|improve this answer
    
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. –  IronGiraffe Jul 27 '11 at 7:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.