How do i implement a hit box system in a fighting game?

In a fighting game a move that you execute is basically just a series of hit boxes that are enabled and disabled at certain times. I want to know how do you create this hit box system. I have no idea as to how to make a flexible system where I can enable and disable a hit box on any frame of a move and also adding additional frame data. All I can think of is having a list that is the size of the amount of frames of the move, and add all of the enables, disables, and frame data as one list item. The problem with that is that a list item can only be one object so I have to somehow make all my frame data and hit box enables & disables into one object. If I can have as many hit boxes in a move as I want then this list item object needs to have a list as well, which I don't think is a good way of doing it. So I just want to know all of the good ways of implementing a hit box system in a fighting game.

• You can make a list of list. Start with that, if it's fast enough you're done. You only have 2 players so the CPU load shouldn't be that large. – Stephane Hockenhull May 12 '16 at 3:25
• Paragraphs and a concrete example of what you're stuck on would be appreciated. – Anko May 15 '16 at 23:49
• Guaranteed that a list of lists will be fast enough for any two person fighter on any platform more beefy than an embedded LCD game on a watch. – Patrick Hughes Jun 25 '16 at 19:09

There's a couple of ways you could go about such a system, as with anything. I'll try to describe the core of one such system in a pretty general sense here:

An animation consists of AnimationFrames. An animation frame contains a bunch of data.

struct AnimationFrame
{
//The graphic for this frame
Sprite * sprite;

//Duration (for example, in milliseconds)
unsigned int duration;

Hitbox hitboxes[N];
Hitbox hurtboxes[N];
};


So each frame has a list of hitboxes and hurtboxes. Inside the game, they would look like something like this: http://ensabahnur.free.fr/BastonNew/hitboxesDisplay.php?sMode=f&iChar=2&sMoveType=fd_normals&sAction=w&iMove=6

What, then, is a hitbox or a hurtbox? Of course its a rectangle with four values (offsets from the character's world position), but it also holds additional data.

Every frame you will be polling whether each hitbox of each character's current animation's current frame collides with a hurtbox of another character. But what happens when the rects do collide is up to the hitbox. There's a couple of ways to imlement this. Say you have a generic hitbox struct:

struct Hitbox
{
int x, y, w, h;
//...other data
};


What is the other data in addition to the rectangle's dimensions? It could be a function pointer (say, to a function that deals damage to the current opponent.) It could also be an integer ID. Each Strike or Ability a character had would define what happened if a Hitbox of a given ID during a certain frame collided. Additionally, the AnimationFrames themselves could have an ID, a function pointer or similar event appointed to them.

Lastly, each animation is simply a list of AnimationFrames. Its up to other systems how these are updated or handled.

I hope that gives you at least some ideas.

What comes to my mind would be to have a list of each collision box per frame of the attack, then advance each hit box every frame and check if it collides with any enemy. If so, set the attack hit to true so the enemy doesn't get hit twice or more times for the same attack. If this doesn't make sense, here's an example of the code in Java:

public void updateEntity()
{
if(isAttacking && !attacked)
{
if(attackFrame++ < attackBoxes.length)
{
for(int i = 0; i < entities.size(); i++)
{
if(entities.get(i).bounds.intersects(attackBoxes[i]))
{
attacked = true;
entities.get(i).damage(...);
}
}
}
else
{
attacked = isAttacking = false;
attackFrame = 0;
}
}
}


The attackFrame variable is also what you can use to render each animation frame for the attack. The attackBoxes variable can be an array to hold each collision box for each frame, which you will have to set on each attack.