I've just found out this code doesn't work because of the way Scratch works, so I'm redoing it. These are some custom blocks for dealing with x and y position, a bit like Vector2 libraries you would find in programming languages like Java. Note that "return ID" or "return value" means which variable of the four to put the result in.
All code, and the sprite that isn't even visible in the final product, by me.