Is this part of a game loop? I ask because there are waits and spofs with inputs.
You should isolate each action as input->update(Detect collition, apply gravity, damage)->render(Move sprite, draw graphics)
Also, search for a concept called Indent Style.
Okay, wait. Did you program game physics? (Like gravity and velocity) Or are you just trying program and manually animate for every possible scenario? Because the latter is the 100% wrong way to go about something like this.
Than your cording,
==
IF B==n THEN (command) (command) (command)...
==
Please rewrite below:
==
IF B==n THEN
(command)
(command)
(command)
:
ENDIF
==
This is easy to debug.