Project 550: Racing Road

4. Design and program a scrolling road

Let's create an illusion of a scrolling road. Design a sprite to be a single road divider line, and then program it so it scrolls downwards. It should scroll based off your "speed" variable. (You'll want to keep your speed variable a postive number, so how would you force it to be negative in this new code?)
Starting point file for this challenge

Your goal

Steps

1. Create a road divider line sprite

Put your mouse over the blue cat face and click on the paintbrush tool that pops up. Use the rectangle tool to draw a little road divider line. Remember, you can resize the sprite in the sprite properties if it looks too big or small. 

2. Set the sprite's starting position

Add a "when green flag clicked" block into the new sprite's code. Then, add a "go to x: __ y:__" block. The top middle of your screen in Scratch would be (0, 170)

3. Tell it to clone itself at the start of the game

Grab a "control" block called "create clone of myself" and connect it to your code. 

4. Create clones forever

Put a "forever" loop, from the "control" section, around the clone block.

5. Add a delay

 Add a "wait __ seconds" block from the "control" section into the forever loop. Without this block, the sprites would clone way too fast. 

6. Tell the clones to appear behind the car

Add a "when I start as a clone" block from "control" and put it somewhere else in your code. Then, grab a "looks" block called "go to back layer" and connect it on. 

This code will tell your road divider lines to be beneath your car instead of floating on top. 

7. Tell the clones to move based off speed

Grab a "change Y by __" block from "motion" and connect it on. You want the clones to be moving based off speed, so grab an orange "speed" bubble from "variables" and drop it in the blank. 

8. Use an operators block to make speed negative

You'll want the clone's Y position to change by a negative number so they scroll down instead of up, but right now speed is a positive number. 

Grab an "operators" block called " __ * __" which is a multiplication block. Put this in the "change Y by __" blank. Put the orange "speed" bubble in the first green blank. Then in the second, type -1. 

9. Repeat the movement until the clones reach the bottom of the screen

 Put a "repeat until ___" loop around the motion block. 

To check if they're at the bottom of the screen, grab an "operators" block called " __ < __" and put it in the "until" blank. 

Then, drop a "motion" bubble called "y position" in the first blank. In the second, type -170. 

10. Delete the clones after they finish moving

Put a "delete this clone" from the "control" section after the repeat loop. 

11. Hide the parent

Put a "looks" block called "hide" at the top of the parent's code.

12. Show the clones

Put a "looks" block called "show" at the top of the clone's code.