python – Pygame – RPG Battle-Style Animation and movement when not controlled by player


Examples: https://www.youtube.com/watch?v=C2cOiFntLY4 https://www.youtube.com/watch?v=iHl1YFkeR78

I am making a small little RPG based on a text-adventure game that I made. This RPG involves a battle system similar to the SNES Final Fantasy games. I am currently limited to the player character and a single enemy, since those are the only actors that were ever present in the text-adventure game.

My battle system involves selecting your choice (attack or run away) and, upon attacking, the damage is calculated, battle text is displayed showing the damage, and then there is a short delay before the enemy attacks in return. This is all fine and good, but I don’t want static images of my player and the enemy.

In the first example above, you can see the enemies jump onto the player for their attacks and you can see that the player runs to the enemy and then swings his sword. In the second example, you can see that the players will run forward a short distance and then either cast a spell or swing their weapon. What I’m looking for is something somewhere in the middle — I want my player sprite to run/jump over to a position directly in front of the enemy, perform an attack animation in that position, and then run/jump back to their starting position.

I don’t have my code in front of me, but I do know that I am currently drawing the sprites in specific locations, basically using standard pygame.draw functionality.

So: Any chance someone could walk me through this? I know how to move my player around when outside of the battle system, but I don’t know how to properly do the same thing when the player is not in control… and adding the Y-axis to the equation (for the jump) just stumps me in this situation. I have (extremely basic) knowledge of tweening/easing functions, which I suspect will be relevant here, but I’ve only ever used them along one axis to make an item bounce up and down in place, so I’m not sure how to apply them to a sprite moving in two different axes.

Any help would be appreciated, especially code examples. Thanks!