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 Obstacle Obstruction


In the core project, you enabled the character sprite to move around the locations. It even moves straight through trees! In this add-on, you’ll make it impossible for the character to walk through some objects. Click on the character sprite. Program it to move backwards if it touches a color that the obstacle contains. Open the “control” menu, and drag out an “if” block. Then, open the “sensing” menu, and drag a “touching color” block into the condition of the “if” block. Click the colored square, then click on an obstacle to select the color. This example uses the dark green on the outside of the trees.

Then, open the motion menu, and add a “move” block into the “if” block. Change the value to negative 10 so that the sprite will move backwards.

To test this, drag the character on top of the trees, then click the stack. The sprite should move backwards 10 steps. Cool! Make the sprite continuously check whether it needs to move backwards by putting a “forever” block around the “if” block. Then, add a “when flag clicked” block on top. Click the flag to test, and use the keyboard to move the sprite to the trees. Nice! The sprite can’t move into the trees.

To make the sprite react to other obstacles, duplicate the “if” block. Program this code outside the forever loop first, to make it easier to select a color. Click on the new color swatch on the “touching color” block, then select a new color unique to an obstacle, such as the light grey in the house. Test this out by moving the sprite to the house. Cool! Now it can’t move into the house, but it can still go through the door.

You may need to tinker with the color a few times to get this to work.

Since each backdrop contains different colors and obstacles, the color rules that work for one backdrop may not work for another. To make these rules only work on the “town” backdrop, put an “if” block around the “if touching color” blocks. Place an “equals” operator in the condition field. Then, click “looks,” and place a “backdrop name” block on the left. Type “town,” or the name of the backdrop, on the right. Now these color rules only apply when the backdrop name equals “town.”

Use the same method to make the sprite bump into obstacles in the other locations of the RPG. It will take some tinkering and creativity to get this to work. Don’t be afraid to make mistakes! Now, it’s your turn!

Make the sprite move backwards when it bumps into obstacles using the “touching color,” “move,” “if,” and “forever” blocks. Ensure that the color rules work only for a specific backdrop using the “backdrop name,” “equals,” and “if” blocks.

Add as many color rules as you like using the same blocks.

Choose an Add-On
Rearranging Furniture
Customize the look of each location.
Make the game more challenging by showing the object only if the character is nearby.
Code a Conclusion
Add some slides to end the story when the player wins.
Musical Objects
Add some interactive items that make sound when the character walks over them
Obstacle Obstruction
Make the maps more realistic by preventing the character from running into obstacles, like trees or buildings.
Hide and Seek
Hide the object in a random location each time.
arrow_backward Back
Next arrow_forward