Please update your browser
Your browser version is not supported by this site. CS First may not work properly.
In many platform games, the main character
falls to their doom when the player loses.
In this video, you'll program your own losing condition.
To start, create a dangerous place
to fall, like water or lava.
You could draw your dangerous place right on the
game backdrop, but creating a new sprite makes it
easier to position the danger element
on the screen, edit it, and program it.
Click draw new sprite.
In this example, the dangerous place is a blue line
that looks like water, but you can draw
any kind of dangerous place you want.
Next, program something to happen if the character
touches the dangerous place sprite.
Code the losing condition next to the winning
condition to keep your code organized.
Click control and place an if statement inside your
forever loop below the winning condition.
Go to sensing and drag out a touching block.
Tinch the value to the name of the dangerous sprite.
Next, add code inside the if statement
to indicate that the player lost the game.
This example says you lose, and stops
the rest of the program from running.
Add your own messaging code to program
the losing condition for your game.
Now it's your turn.
Create a dangerous place sprite, then make something
happen if the player's sprite touches the
dangerous place sprite using if and touching blocks.