Skip to content
https://storage.googleapis.com/files.cs-first.com/sports/sports-icon%402x.png

6. Program the Losing Condition

Transcript

In this video, you will program the backdrop to show game over if the sprite touches an obstacle.

First, select the racer sprite.

The game ends if the racer sprite touches an obstacle.

From the control menu, drag out an if then block and add it to the forever loop.

Remember, an if then block checks if something is true.

Then performs an action if it is.

To check if the sprite is touching an 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 if then 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't even started.

To fix this add a switch backdrop to block right after the when flag clicked block and select the starting backdrop from the 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.

Alright, here's the game plan.

Make the backdrop show game over if the racer touches an obstacle using an if then block, a touching block, and a switch backdrop to block.

Instructions
Make the backdrop display "game over" if the racer touches an obstacle using "if then," "touching," and "switch backdrop to" blocks.