How to play somersault animation like in Contra games in 2D game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robotex

Here is my jumping code:

if is_on_floor():
	if Input.is_action_just_pressed("ui_up"):
		motion.y = JUMP_HEIGHT
	if friction == true:
		motion.x = lerp(motion.x, 0, 0.2)
else:
	if motion.y < 0:
		$Sprite.play("Jump")
	else:
		$Sprite.play("Fall")
	if friction == true:
		motion.x = lerp(motion.x, 0, 0.05)

But I want also add the somersault animation like in Contra games from NES. How can I detect moment where I should play and stop this animation. Should it be related to animation frames count and play speed?