Step 5: Gravity

This is a simple method of simulating gravity. On each loop, if an Enemy is not overlapping an obstacle, it will be moved down one pixel, and if it is overlapping an obstace, it will be moved up one pixel. The number of times you run the loop, is the total number of pixels the object can rise or fall per frame.
Test the application and you will see each Enemy now sticks to the ground.

8