Phase 1 — Camera Shake

The Player needs an indicator too obvious to miss that they’ve taken damage. It might be too late if all I rely on is the visual fires on the sprite or the lives counter. Nothing is more obvious than having the entire screen shake violently.

To do so we will need to deal with the camera, inside the UI Manager.

UI Manager script

First, the UI Manager stores the original position of the camera. When the Player is hit and would lose a life in that hit, it calls the CameraShakeRoutine. For several frames, the camera’s x and y position will randomly change until the elapsed time goes beyond the desired duration. After that, return the camera to its original position. The camera is also returned to its original position if the Player dies and triggers game over.