In this video, you will program the backdrop to show “game over” if the sprite touchesan obstacle. First, select the racer sprite. The game ends*if* the racer sprite touches an obstacle. From the “control” menu, drag out an “ifthen” block, and add it to the forever loop. Remember, an “if then” block checks ifsomething is true, then performs an action if it is. To check if the sprite is touchingan obstacle, add a “touching” block from the “sensing” menu to the “if then”block. Choose the obstacle sprite from the dropdown menu.
Then, open the “looks” menu and add a “switch backdrop to” block to the “ifthen” block. Choose the “game over” backdrop from the dropdown menu.
Test your code. If the racer touches an obstacle, the backdrop switches to display “game over.”
Try playing the game again. The backdrop still says “game over,” but the game hasn’teven started! To fix this, add a “switch backdrop to”block right after the “when flag clicked” block, and select the starting backdrop fromthe dropdown menu.
Test the code by clicking the flag. The game starts with a backdrop, and switches to the“game over” backdrop only when it hits an obstacle.
Here’s the game plan: Make the backdrop show “game over” ifthe racer touches an obstacle using an “if then” block, a “touching” block, anda “switch backdrop to” block.