So bear with me here, this is more a question of a best practices, and it's also going to get into the weeds a bit. I'll outline the issue, then outline the options I know of, along with their pro's and con's. Please read the whole post if you have a suggestion.
I'm making an action RPG. Prototyping is going really well! Because the sprites are very simple 2D pixel art, attack animations utilize paper-dolling techniques where I overlay a weapon sprite animation on top of or underneath the player. This function extends to all humanoid enemies as well. Because I want the player to be able to play as and/or recruit any of the creatures they come across, player objects and enemy objects are functionally the same. This is also helpful for/required for other gameplay elements. Players and enemies are all grouped under the same Family I'll refer to from here as "Character Family".
So far this has worked really great! Originally I was pinning the weapon sprite to the Character Family sprite, and then storing the information for the attacks (range, frames where collision detection is necessary to register hits, knockback values, etc) inside those weapon sprites.
Then I hit my snag: This only works for Character Family sprites that use weapons. I have plans for other Character Family sprites (creatures for instance) to not use weapons, and instead call attack animations from their sprite sheet. I can't store all the information for those attacks in an object that they won't have pinned to them.
Here are the options I have come up with so far:
- Store all the instance variables for the weapons inside the Character Family instead, and update them when appropriate. This is going to heavily bloat my Character Family instance variables, so I'd like to avoid it. Right now human players only have 2 attack animations per weapon, but enemies without weapons could potentially have more, which adds up quickly considering how many values each attack needs to store.
- Create "dummy" weapon objects for creatures. The brute force method for doing this would be to create invisible dummy weapons for each creature, but I could easily modify this to instead point to one weapon per enemy attack. It's inelegant but it does keep things relatively well organized.
- Store attack information in an array. This is the obvious one, but it too has some setbacks I can't get around. Specifically, I am trying to automate as much of this work as possible, and as such having been using families and functions a LOT. But if I want to attach an array to an objects container, I can't do so within a family, so I can't reference it easily (unless I can and I just don't know how).
Any help here would be appreciated, and I'll try to explain everything else around this better if needed.