This is an example of one way to program a variable 'lives' with game characters. If the pink ghost touches the blue dragon then the dragon loses a life. Use arrow keys to move the blue dragon. Note the ghost moves automatically. The maze background has been added and dragon coded to stay within maze walls otherwise it returns to start position.
Sprites from Flaticon.com