Hand a sprite to the arrow keys with move with buttons, and choose how fast it goes across and down.
In every game you have played, a button press becomes movement on the screen. One block makes that link.
What you should already know:
Sprites on the screen· Put pictures called sprites on the game screen, and place each one with x and y.
Last lesson every sprite stood still. Now the player steers one. move with buttons (in Controller) hands a sprite to the arrow keys (or W, A, S, D). Click the + on the block to show its two numbers: the speed across and the speed up and down, in pixels per second.
Click the simulator first, so it hears the keyboard. The A button is space (or Z) on the keyboard.
How this lesson works: Predict, Run, Investigate, Modify, Make
Predict: Read the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.
Run: Run it and compare the result with your prediction.
Investigate: Trace how each line of code connects to what you see.
Modify: Change the code on purpose and check the result.
Make: Build something new using what you have learned. Expect a few tries; that is normal.
Make your prediction first. Help opens once you've locked it in.
PredictRead the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.
Students hand a sprite to the arrow keys with move with buttons, and see that its two numbers are speeds across and down, not a place. About 40 minutes.
I can let the player steer a sprite with the arrow keys.
I can choose which way a sprite can move, and how fast.
I can keep a sprite on the screen.
Before class
move with buttons (Controller) hands a sprite to the arrow keys: it moves while a key is held. Its two numbers (click + to show them) are the speeds across and up and down, in pixels per second; 0 stops movement that way. They are not a position. on A button pressed is an event: it runs each time A (space or Z) is pressed. Students must click the simulator before it hears keys.
Running the lesson
Predict: some students read the numbers as a place (100, 0). Ask what happens while a key is held.
Run: all four arrows. Up and down do nothing.
Investigate: Kim's cloud shows that the block steers only the sprite it names.
Modify: the dash changes x by 30: a position change, once per press.
Make: speeds 100 and 0, plus stay in screen.
The hard part (on purpose)
Reading the two numbers as speeds, not a place. Ask what each number does while a key is held.
When students get stuck
The arrow keys do nothing. Ask: Did you click the simulator? Is there a move with buttons block? Fix: Click once on the game screen so it hears the keyboard, and check move with buttons names the right sprite.
The sprite flies off the edge. Ask: What stops it at the edge? Fix: Add set stay in screen for that sprite.
The sprite moves up and down when it should not. Ask: Which number is the speed up and down? Fix: Click + on move with buttons; set the second number to 0.
Stretch and support
Stretch: Make A dash right and B dash left, and make the ship faster across than the plane was.
Support: Give students the ship with move with buttons already in, and ask them only to set the two speeds and keep it on the screen.
Where it leads
Next lesson: a speed the engine applies by itself, so a sprite keeps moving with nobody pressing anything.
What each step is for
Investigate: move with buttons links the arrow keys to one sprite, and its two numbers are its speeds across and down: a speed of 0 means it cannot move that way.
Modify: The two numbers set which way the player can move, and how fast. A position change in an event moves a sprite once per press.