Please update your browser
Your browser version is not supported by this site. CS First may not work properly.
In this video, you will learn how to make the androids block each other.
This takes a little more work than other add-ons, so use your courage and persistence!
You can always ask your neighbors and Gurus to help.
First, program the blue android to move only if it isn’t touching the yellow android.
Click on the blue android.
From the “control” menu, drag out an “if/then” block.
Place it around the “repeat until not pressing left arrow key” block.
Fill in the boolean condition - what the program will check for.
From the “sensing” menu, drag out the “touching” block.
From the dropdown, select “yellow android.”
Right now, the code reads “if touching yellow android, repeat moving to the left until the
left arrow key isn’t being pressed anymore.”
But, the blue android should repeat moving if it is Not touching the yellow android.
From the “operators” menu, place a “not” block inside the “if” block.
Then, place the “touching yellow android” block inside the “not” block.
Now, the code reads:
When the left arrow key is pressed,
check if the sprite is not touching the yellow android.
If it isn't, move to the left.
Test the code.
When the yellow android is to the left of the blue android, click the left arrow key.
The blue android should move to the left.
If the blue android touches the yellow android, the blue android will not move.
Now, follow the same steps to program the right arrow key.
From the “control” menu, place an “if” block around the “repeat until not touching
right arrow key” block.
From the “operators” menu, place a “not” inside the “if” block.
From the “sensing” menu, place a “touching” block inside the “not” block, and select
yellow android from the dropdown menu.
To test this code, move the yellow android to the right of the blue android.
Then, press the right arrow key.
The blue android moves to the right if it is not touching the yellow android.
If it touches the yellow android, nothing happens.
Do the same thing for the yellow android.
Change the keypresses, and make sure the yellow android is not touching the blue android before
Keep testing your code.
Now it’s your turn: Program the sprites to move only if they are
not touching the other sprite using “if,” “not,” and “touching color” blocks.
In the next video, you will program the androids to jump over each other.