In this video you'll make your
athlete sprite move when the user
presses the arrow keys.
You'll create two conditionals,
one to move the sprite left
and one to move it right.
From the control menu drag out
two if blocks and snap them together.
Go to the sensing menu and drag
a key press block into each conditional.
For the first one select left arrow
in the drop down.
Select right arrow for the second one.
Next, from the motion menu,
place a point in direction block
into each of the conditionals.
The first conditional moves the sprite left,
so select negative 90 in the drop down.
In the second, select 90.
To test it, hold down either the left or right
arrow key and click the block stack.
Try to get the sprite to turn around.
As you can see from the test,
pressing the left arrow flips the sprite
Fortunately, Scratch has a block that will
make the sprite turn side to side
but not upside down.
From the motion menu,
drag out the set rotation style block
and place it at the top of this code stack.
Select left-right from the drop down menu.
Make sure to hold the key
while you click the code.
The sprite stays right side up.
Next, make the sprite move in the direction
Place a move block under each conditional.
Make this code keep running as long as
a key is being pressed.
Snap a forever loop around the block stack.
Click this to test it.
Press the left and right arrow keys
and watch the athlete move from left to right.
Finally, use a when flag clicked event
to start the athletes code.
Snap it on top of the stack.
Then, click the flag to start the game.
Here's the game plan,
make the athlete sprite move left and right
when the left and right arrow keys are pressed
using if blocks and key pressed events.
Then, add a set rotation style block
to keep the sprite from flipping upside down.
Make the sprite move in the direction it's facing
with a move block.
Use a forever loop to make the athlete keep moving
as long as the key is pressed.
Start the game with a when flag clicked event.
Sign in to track your progress and earn badges