(Also available in WeScheme)
Students use function composition and the distance formula to detect when characters in their games collide.
Lesson Goals |
Students will be able to:
|
Student-Facing Lesson Goals |
|
Materials |
|
Preparation |
|
Key Points for the Facilitator |
|
Click here to see the prior unit-based version
- circle of evaluation
-
a 'sentence diagram' of the structure of a mathematical expression
- pixel
-
the smallest unit that makes up a digital image. The more pixels, the more detailed an image or video can appear.
🔗Problem Decomposition Returns! 20 minutes
Launch
Students should have their workbook, pencil, and be logged into code.pyret.org on their computer.
Problem Decomposition is a powerful tool, which lets us break apart complex problems into simpler ones that we can solve, test, and then glue together into a complex solution.
Students may remember that there are two strategies for doing this:
-
Top-Down: Describe the problem at a high level, then fill in the details later
-
Bottom-Up: Focus on the smaller parts that you’re sure of, then build them together to get the big picture
Problem Decomposition is the focus of an entire Bootstrap lesson, is used to solve “onscreen?”, and build up the 2-dimensional distance function.
Investigate
For the following complex word problem, have students first decide which strategy they want to use, and then apply the Design Recipe to build the functions they need.
A retractable flag pole starts out 24 inches tall, and can grow at a rate of 0.6in/sec. An elastic is tied to the top of the pole and anchored 200 inches from the base, forming a right triangle. Define functions that compute the height of the pole and the area of the triangle after a given number of seconds.
Have students complete the Top Down / Bottom Up worksheet, using Problem Decomposition and the Design Recipe to solve this problem!
Synthesize
-
Which strategy did students use?
-
Did they start out with one, and then switch to another?
🔗Collision Detection 20 minutes
Overview
Students once again see function composition at work, as they compose a simple inequality with the distance
function they’ve created.
Launch
Knowing how far apart our characters are is the first step. We still need the computer to be asking: "True or False: is there a collision?"
Investigate
Using Word Problem: is-collision, have students write a function that takes in two coordinate pairs (four numbers) of the PLAYER
and a character ((px, py)
and (cx, cy)
), and and returns true
if they are within 50 pixels of each other.
Synthesize
-
You started by writing the
distance
function first, and thenis-collision
Is this Top-Down or Bottom-Up decomposition? -
Explicitly point out that this function is easy to write because we can re-use the distance function.
-
Connect this back to
profit
,revenue
,cost
andonscreen
from previous lessons. Problem Decomposition is powerful!
🔗Additional Exercises:
-
For teachers who’ve already introduced your class to flags, the Flag of Trinidad and Tobago Starter Code (Pyret) makes use of Pythagorean Theorem and could make for an interesting connection to this lesson.
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.