In this add-on, program your characters
to move when you press the arrow keys
so that they can avoid the glitch.
First, move the sprite using blocks from the Motion menu.
To make the sprite move to the right,
click on the Change x By block.
Great, the sprite moves to the right.
Drag this block out.
To make the sprite move to the left,
drag out another Change x By block.
Change the value to a negative number.
Click the block to test.
Nice, the sprite moves in the opposite direction.
Next, program your sprite to jump.
A jumping motion will require the sprite
to move up then down.
Drag out a Change y By block.
Click this block a few times.
The sprite moves up a little bit each time.
Drag down the sprite.
To move the sprite down after it jumps up,
drag out a Change y By block.
Change the value to a negative number.
When the first Change y By block is clicked,
the sprite jumps up.
When the second Change y By block is clicked,
the sprite comes back down.
Next, tell the code when to run.
The code should run if a key is pressed.
Click on the Control menu and place an If block
around each movement block.
Snap them together.
Drag out Key Pressed blocks from the Sensing menu
and place them in the If blocks.
Select a different arrow key from each drop down menu.
In this example, this block stack moves the sprite right
so right arrow is selected.
Select left arrow and up arrow
for the other key press blocks.
Try it out.
Oh no!
The code doesn't work.
This is because the program
is not constantly checking for key presses.
To fix this, drag out a Forever block from the Control menu
and place it around your block stacks.
This makes the code run over and over again
so the sprite moves every time an arrow key is pressed.
But wait, the sprite doesn't jump
when the up arrow key is pressed.
The code is running so fast,
it's difficult to see the sprite jumping.
To fix this, add a Wait block from the Control menu.
Try it again.
Great, the sprite jumps up and down.
Tinker with the values in the Change x By
and Change y By blocks to change the distance
the sprite moves and jumps.
To better time the jump, change the value in the Wait block.
This example uses 0.2 seconds.
Finally, add a When Flag Clicked block
to the top of the block stack
so that the sprite can move in any direction
when the program runs.
Click the green flag and press the arrow keys
to tell your story.
(upbeat music)
Now it's your turn.
Drag out Change x By blocks to move left and right.
Drag out Change y By blocks to move up and down.
Add If and Key Pressed blocks around each block stack.
Add a Forever block to constantly check for key presses.
Add a Wait block to time the jump.
And finally, add a When Flag Clicked block
to start the program.