In the previous screencast, you should have added one sprites to the starting project.
If you haven’t done this yet, please pause this screencast and do so now.
In this screencast, you’ll program the player sprite to “launch,” or repeatedly moveforward, when the spacebar is pressed and program the arrow keys to control left andright turns. Go ahead and watch this screencast first to learn how to do it, then you’llget the chance to try it on your own. First, you need to create a program thatwill cause the sprite to move when someone presses the spacebar.
You can do this by adding a “when space key pressed” event and a “move 10 steps” block.
Test that code to see how it works.
Good! But, you want the sprite to “launch”when the space key is pressed, meaning that it will keep moving forward without stopping.
Click on control.
You don’t need the sprite to repeat moving forward forever, just untilit reaches the finish line. So select a “repeat until” block, and place it around the“move 10 steps” block. The sprite should repeat moving forward untilit touches the finish line. Click the sensing menu, drag a “touching” block into the“repeat until” block, and change the value to “finish line.”
Check what happens when you test the code.
The sprite moves forward and stops once it reaches the finish line.
That’s fine. But how could the game be played again?
Sometimes problems become obvious when you test your code. As a computer scientist,it’s important to test your code often so these kinds of problems.
To make it so the player can continue playing the game,you can use a “go-to” block to move the sprite back to the start.
Drag the sprite to where you want it to start, then place the “go-to” block below the“repeat until” block.
Now, when you press the spacebar, the sprite moves forward untilit reaches the finish line, then it goes back to the start.
In the next screencast, you’ll program the sprite to turn left and right with the arrow keys.