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.