20
CS in Algebra | Lesson 20

# The Big Game - Collision Detection

Lesson time: 30-60 Minutes

## Lesson Overview

To finish up their video games, students will apply what they have learned in the last few stages to write the final missing functions. We'll start by using booleans to check whether keys were pressed in order to move the player sprite, then move on to applying the Pythagorean Theorem to determine when sprites are touching.

## Lesson Objectives

### Students will:

• Apply the Distance Formula to detect when two points on a coordinate plane are near each other.

## Anchor Standard

### Common Core Math Standards

• 8.G.7: Apply the Pythagorean Theorem to determine unknown side lengths in right triangles in real-world and mathematical problems in two and three dimensions.

Additional standards alignment can be found at the end of this lesson

# Teaching Guide

## Getting Started

### 1) Introduction

Let's get back into that Big Game from stages 7, 12, and 16.

Previous work with the game has created movement for the danger and target characters, using Booleans to check if they have left the screen. The last time students worked on their game they used a conditional to check which key was pressed and make the player move accordingly. At this point the only thing left to do is to decide when the player is touching either the target or danger. Once students have successfully completed the distance and collide? functions, their score will increase when the player touches the target, and decrease when it touches the danger.

The Pythagorean Theorem studied in the last lesson will be used to determine when the characters have made contact. Students are not required to write their own line-length function, but you may ask them to complete the Design Recipe for it anyway.

Students will first complete the distance function so that it measures the distance between two points, (px, py) and (cx, cy). After the students implement the distance formula, they will need to implement the tests in the collide? function.

Once these last functions are put into place, scoring will automatically update based on collisions between target and danger.

## Activity: The Big Game - Collision Detection

### 2) Online Puzzles

Return to your Big Game to use collision detection logic so that you know when your player is touching the target or the danger. Head to CS in Algebra stage 20 in Code Studio to get started programming.

Standards Alignment

### Common Core Math Standards

• 6.NS.8 - Solve real-world and mathematical problems by graphing points in all four quadrants of the coordinate plane. Include use of coordinates and absolute value to find distances between points with the same first coordinate or the same second coordinate.
• 7.EE.4 - Use variables to represent quantities in a real-world or mathematical problem, and construct simple equations and inequalities to solve problems by reasoning about the quantities.
• 8.EE.2 - Use square root and cube root symbols to represent solutions to equations of the form x2 = p and x3 = p, where p is a positive rational number. Evaluate square roots of small perfect squares and cube roots of small perfect cubes. Know that √2 is irrational.
• 8.F.1 - Understand that a function is a rule that assigns to each input exactly one output. The graph of a function is the set of ordered pairs consisting of an input and the corresponding output.1
• 8.F.2 - Compare properties of two functions each represented in a different way (algebraically, graphically, numerically in tables, or by verbal descriptions). For example, given a linear function represented by a table of values and a linear function represented by an algebraic expression, determine which function has the greater rate of change.
• 8.G.7 - Apply the Pythagorean Theorem to determine unknown side lengths in right triangles in real-world and mathematical problems in two and three dimensions.
• 8.G.8 - Apply the Pythagorean Theorem to find the distance between two points in a coordinate system.

### Common Core Math Practices

• MP.1 - Make sense of problems and persevere in solving them.
• MP.2 - Reason abstractly and quantitatively.
• MP.3 - Construct viable arguments and critique the reasoning of others.
• MP.4 - Model with mathematics.
• MP.5 - Use appropriate tools strategically.
• MP.6 - Attend to precision.
• MP.7 - Look for and make use of structure.
• MP.8 - Look for and express regularity in repeated reasoning.

Derived from