Skip to content

Please update your browser

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

Transcript

In the core project, you enabled to 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 the 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 a 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 a sprite to the trees.

Nice!

The sprite can't move into the trees.

To make this right, we act to the other obstacles, duplicate the if block.

Program this code outside the forever loop first to make it easier to select the 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 gray in the house.

Test this out by moving the sprite to the house.

Cool!

Now I can't move into the house, but I 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 it backdrop name block on the left.

Type town, or the name of the backdrop on the right.

Now, these colors rules only apply when the backdrop name equals town.

Use the same method to make the sprite bump into obstacles in 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 only work 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

Peek-a-boo

Make the game more challenging by showing the object only if the character is nearby.

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.

Attributions
  • The song “Magic Marker” is © YouTube-- CC-BY-SA 4.0 does not apply.