Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

5. Programmer la condition de défaite


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.

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.

arrow_backward Retour
Suivant arrow_forward
À l’aide d’un bloc "Si alors", d’un bloc "Touché" et d’un bloc "Basculer sur l’arrière-plan", fais afficher "Fin de partie" sur l’arrière-plan lorsque le coureur touche un obstacle.