About the only way is have a fixed drawing order to your images, and not a lot else. For example;
1. draw underlying things...
2. draw main & secondary characters...
3. draw overlying things....
<sync image to the screen.>
There is no priority other than this, except "draw to front" or "draw to back" as set by these commands. You can issolate sprites by "draw sprites first" where everything gets laid on top on them, but it's only drawing order that really determines when you can, or cannot, go behind or in front of the images.
Any truly great code should be indisguishable from magic.