This is a demo that shows you how to use State Machines to code a character that can do multiple things. Use the A and D keys to move, and Space to attack. Notice how the attack animation locks the character in place, but it's possible to cancel the end of the animation by holding a movement key. Notice also that we are preventing the player from attacking while running. If we wanted the player to be able to do that, we could add a separate "rush attack" move that can only be triggered by pressing the attack key while running.
Characters from Craftpix: https://craftpix.net/freebies/free-characters-with-melee-attack-pixel-art/ For more information on State Machines: https://en.wikipedia.org/wiki/Finite-state_machine