Project 552: Scratch Walk Cycle

3. Program the simple walk cycle

Program your sprite so it can move left and right. It should animate while it moves.
Starting point file for this challenge

Your goal

Steps

1. Add a "when green flag clicked" block

This is a yellow "Events" block. Any code beneath this block will activate when the game begins. 

2. Add a forever loop

This is a "control" block. You can connect it right onto the yellow block. This block will make sure that the player is able to control their character for the entire game (forever.) 

3. Add an if-statement in the forever loop

This is also a "control" block. It looks like "if __ then ___." It will help us write the sentence, "If I'm pressing the right arrow key, then I'll move right." Put this inside the mouth of the forever loop. 

4. Check if the player's pressing the right arrow key

Use a "sensing" block called "key __ pressed?" inside of the "if" blank. Change this block to say "key right arrow pressed?" 

5. If so, then move the character to the right

Add a "motion" block called "change X by __" into the "then" blank. You can keep it at 10, or experiment with higher or lower numbers and see what happens. 

6. Add another if-statement in the forever loop

Put another if-statement in the loop, right after the first one. 

7. Complete moving left

Check if the player's pressing the left arrow key. Use another "change X by __" block.

8. Test it out!

Click on the green flag on the top of your screen, then use the arrow keys to move your character back and forth. It doesn't animate yet, but we'll add that soon. 

9. Add animation in the movement

Add a "looks" block called "next costume" into each of the "then" blanks. Test this out! Does it feel too fast? The next hint will tell you how to slow it down. 

10. Add a delay

Put a "control" block called "wait __ seconds" in each of the "then" blanks. Try waiting a short time, like 0.1 seconds. 

11. Program flipping the sprite

This looks pretty good, but it'd be nicer if the sprite actually flipped when you moved left and right. Find a "motion" block called "point in direction __." When moving right, point 90 degrees. When moving left, point -90. 

12. Fix the flip

If your blob is turning upside down instead, you'll need to change the direction type from "All Around" to "Left/Right." This is in the sprite properties.