Introduction to Computer Science with Scratch and App Inventor
Introduction to Computer Science with Scratch and App Inventor
Introduction to Computer Science with Scratch and App Inventor
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Now I have my winning condition set. How about a losing condition? I want my player <strong>to</strong> lose when<br />
their score is negative points (less than zero). I can set up the losing condition exactly the same way I set<br />
up the winning condition:<br />
1) Create a new background that displays a losing message<br />
2) Use an if block <strong>to</strong> check for a score that is less than zero<br />
3) When the score is less than zero, display my losing background <strong>and</strong> broadcast the game over<br />
message.<br />
This is just one example of how a player can win or lose a game. Be creative <strong>and</strong> think of what works<br />
best for your game. For example:<br />
You could have the win condition be based on capturing a specific item, or completing a specific<br />
task.<br />
You could use two different variables: a points variable <strong>to</strong> track points <strong>and</strong> determine if the<br />
player wins <strong>and</strong> a health variable that decreases <strong>and</strong> is used <strong>to</strong> determine if a player loses (when<br />
their health variable is zero)<br />
Another option is <strong>to</strong> use a timer. Let’s say that I only want my player <strong>to</strong> win if they can score 10 points<br />
in less than 100 seconds. I can use <strong>Scratch</strong>’s built in time <strong>to</strong> check for this.<br />
The timer is located in the sensing blocks. To use the timer:<br />
1) Click the checkbox next <strong>to</strong> timer <strong>to</strong> show the timer value on the stage<br />
2) Choose when <strong>to</strong> start timing. I want <strong>to</strong> start my timer when the green flag is clicked (as soon as<br />
the game starts). Since I am h<strong>and</strong>ling winning <strong>and</strong> losing in the scripts for my stage, I will control<br />
the timer there as well.<br />
3) Drag a reset timer block <strong>to</strong> where you want <strong>to</strong> start the timer<br />
mbrace Game Development Workbook Page 28