(Using another tool? Please select it now: Pyret.)
Students define functions that control the movement of the target and danger in their games.
Lesson Goals |
Students will be able to:
|
Student-Facing Lesson Goals |
|
Materials |
|
Preparation |
This lesson involves a roleplay in which students will act out character animation along a number line representing the x-axis. Decide where this roleplay will take place in your classroom and whether you will project, draw or make a number-line (from 0 to 1000) for your volunteers to move along. |
Key Points for the Facilitator |
|
🔗Animation
Overview
Students connect the behavior of functions with changing coordinate values, ultimately leading to animation.
Launch
-
How does a flip-book animation work?
-
Each page of the book is slightly different, and the pages go so fast that the motion looks smooth.
-
Why do we see movement from still images?
-
Our eyes fill in the gaps between rapidly changing images.
-
How might this apply to our game?
-
If we change image coordinates a little bit at a time, they will appear to move.
We are going to write a function, called update-target
, that will be responsible for changing the x-coordinate of the TARGET
location.
Note: In our game, there is hidden code that will randomly generate the y-coordinate for where the TARGET
enters the screen.
-
Draw a number line on the board, running from 0 to 1000 (you can also lay tape on the floor, or use a tile floor as a coordinate plane!) Make sure spacing is such that a student will be able to visibly move along it in increments of 50.
-
Select a student volunteer to be the
TARGET
.
-
Before we write our
update-target
function, let’s have a volunteer act it out! -
For this roleplay, we will have our
update-target
function move ourTARGET
left across the x-axis by 50 (pixels) each time the function is called.-
When the
TARGET
hears "update target" followed by their current location, they take a step in the negative direction, moving left across the x-axis by 50 (pixels).
-
-
Let’s have our
TARGET
start at 800. -
To get them moving, we’ll call
(update-target 800)
. -
To make them move again, we’ll need to call the function and new location. What will our new function call be?
Crowdsource the function calls to move the TARGET
several more times.
-
How could we change our
update-target
function to move theTARGET
across the classroom more quickly? -
We could have the
TARGET
move by more pixels each time, for example by 100 instead of 50. -
What did you notice about the movement of TARGET? What was changing?
-
Answers will vary: they were moving horizontally, their x-coordinates were changing, they were moving one step at a time, etc.
-
If we want to write another function called
update-danger
and have it move theDANGER
50 pixels to the right, how will the function work? -
It will take in the x and y-coordinate and add 50 to x.
Investigate
-
Sign in to WeScheme and open your saved Game Starter Files, or make a new copy.
-
Examine the
update-danger
function. Identify the Contract, and interpret what the function is currently doing. -
With your partner, complete the first word problem on Danger and Target Movement.
-
Transfer the code to your Game Starter File and click "Run" to load the code.
The workingupdate-danger
function should automatically move theDANGER
image across the screen! -
Then complete the second word problem on Danger and Target Movement.
-
Transfer the code to your Game Starter File and click "Run".
Now you should see theDANGER
andTARGET
moving across the screen independently!
Extension Activities
Once students have successfully gotten update-target
and update-danger
working, they can change those functions to make their targets and dangers move in whichever direction and whatever speed they want to make the game the most fun to play! They should be sure to modify their purpose statements and examples if they change their functions.
Students may ask about animating their player and we won’t get to that until a future lesson on 🎮 Player Animation. You can point out that the player will need to be able to move both up and down, and right now they don’t know the math or programming for a function to have two completely different behaviors.
Synthesize
Connecting the code to the underlying math is important - especially if you want to customize your game!
-
What part of the function controls the character’s speed?
-
What part of the function controls the character’s direction?
-
If you wanted the characters to move in 2 dimensions (diagonally, for example), would anything have to change about the Domain? What about the Range?
These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, 1738598, 2031479, and 1501927).
Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.