(Also available in 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 |
|
Key Points for the Facilitator |
|
- coordinate
-
a number describing an object’s location
- design recipe
-
a sequence of steps that helps people document, test, and write functions
- domain
-
the type or set of inputs that a function expects
- function
-
a relation from a set of inputs to a set of possible outputs, where each input is related to exactly one output
- range
-
the type or set of outputs that a function produces
🔗Animation 45 minutes
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.
-
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!). Select 2 student volunteers - one to be TARGET
, one to be DANGER
. Start with just TARGET
. Have the class select a starting x- and y-coordinate for the TARGET
.
The TARGET
starts at a particular position, and then moves by 50 (pixels) to the left on each frame of the game.
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).
-
Make
TARGET
move by calling out(update-target 300)
,(update-target 250)
, etc.
Ask students: what if we wanted the update-target
function to move the TARGET
across the classroom more quickly? How would the function have to change?
Repeat with DANGER
, this time moving right across the x-axis. Then ask: what if we wanted update-danger
to move the DANGER
in the opposite direction?
-
What did you notice about the movement of TARGET and DANGER? What was changing about them?
-
Answers will vary: they were moving horizontally, their x-coordinates were changing, they were not moving smoothly, etc.
-
-
What jobs could we hand over to the computer to make it possible for us to play the game?
-
The computer could handle automatically moving TARGET and DANGER, then we could control the movement of PLAYER.
-
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. -
Complete the first word problem on Danger and Target Movement.
-
Transfer the code to your Game Starter File.
When students click the "Run" button, the working update-danger
function should automatically move the DANGER
image across the screen!
-
Complete the second word problem on Danger and Target Movement.
-
With your partner, transfer the code to your Game Starter File.
-
Click "Run" to see
DANGER
andTARGET
move across the screen independently!
Extension Activities Once students have successfully gotten |
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, and 1738598). 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.