Skip to content

Please update your browser

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

arrow_back Blocking (Part 1 of 2)

Choose an Add-On
play_circle_filled
It's How You Play the Game
Add a winning condition to your game.
arrow_forward
play_circle_filled
Danger Sprite
Add a sprite that causes you to lose points if you or your friend touches it.
arrow_forward
play_circle_filled
Designer
Learn how to design the sprites.
arrow_forward
play_circle_filled
Blocking (Part 1 of 2)
Force the players to jump over each other.
arrow_forward
play_circle_filled
Blocking (Part 2 of 2)
Force the players to jump over each other.
arrow_forward
play_circle_filled
Make Noise
Add sound to your project.
arrow_forward
play_circle_filled
Hello Friend
Make the sprites react when they touch each other.
arrow_forward
  • 1. Variables Are Everywhere!
  • 2. Let's Move!
  • 3. One Falling Object
  • 4. Many Falling Objects
  • 5. Keeping Score
  • 6. Shared Score
  • 7. Add-Ons
  • 8. Reflection
  • 9. Wrap-up: Work Together to Win
  • 10. Wrap-up: Share Your Project
  • 11. Wrap-up: Show Your Project
arrow_backward Back Next arrow_forward
Transcript

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.

Great!

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.

Great.

Do the same thing for the yellow android.

Change the keypresses, and make sure the yellow android is not touching the blue android before it moves.

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.

Instructions
  1. Choose an Add-On, and click "watch" to learn how to build it.
  2. Once you finish one Add-On, try another one below the video!