Lesson 7: The Big Game Booleans

Overview

Using the same logic from the previous lesson, students will write code that checks whether their Target and Danger sprites have left the screen. If their function determines that a sprite is no longer visible on screen, it will be reset to the opposite side.

Agenda

Getting Started

Activity

View on Code Studio

Anchor Standard

Common Core Math Standards

  • 6.EE.9 - Use variables to represent two quantities in a real-world problem that change in relationship to one another; write an equation to express one quantity, thought of as the dependent variable, in terms of the other quantity, thought of as the independent variable. Analyze the relationship between the dependent and independent variables using graphs and tables, and relate these to the equation. For example, in a problem involving motion at constant speed, list and graph ordered pairs of distances and times, and write the equation d = 65t to represent the relationship between distance and time.

Objectives

Students will be able to:

  • Using the same logic from the previous lesson, students will write code that checks whether their Target and Danger sprites have left the screen. If their function determines that a sprite is no longer visible on screen, it will be reset to the opposite s
  • Apply Boolean logic, such as AND, OR, and NOT, to compose complex Boolean comparisons.

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the Students

Support

Report a Bug

Teaching Guide

Getting Started

Introduction

Let's get back into that Big Game that we started in stage 7 and continued in stage 12.

When we last worked on the game, our danger and target were moving off the screen in opposite directions. Unfortunately, their update functions move them in one direction forever, so they never come back on screen once they've left! We'd actually like them to have a recurring role in this game, so we'll use some boolean logic to move them back to their starting points once they go off screen.

Once the students correctly implement on-screen? (and its sub-parts safe-left? and safe-right?), the new behavior of target and danger is that once they are off the screen they return to their starting position but with a new y-value. From this new vertical position they will continue to move across the screen. If one (or both) of the characters go off the screen and never reappear, the most likely source of the error is that one of the newly implemented boolean statements is incorrect.

Activity

Online Puzzles

Return to your Big Game to use Booleans to keep your player character on screen. Head to Course B stage 7 in Code Studio to get started programming.

View on Code Studio

Student Instructions

When you last worked on your game we got our target and danger sprites to fly across the screen, but they never come back. Click "Run" to see how your game is currently working, and then click finish and we'll work on making those sprites reappear on screen after they've left.

View on Code Studio

Student Instructions

We've provided a couple of empty functions for safe-left? and safe-right? The first thing you need to do is complete the onscreen? function so that it checks whether both safe-left? and safe-right? are true.

TIP - even after you add safe-left? and safe-right? your sprites won't return to the screen - why do you think that is?

View on Code Studio

Student Instructions

Now that your onscreen? function is checking safe-left? and safe-right? we need to fix those functions.

When we used them for Sam the Bat we wanted to prevent Sam from leaving the screen, but now we want the Target and Danger to actually go all the way off screen before returning to the opposite side.

Go to the "Functions" section of the toolbox and complete the safe-left? function so that it returns true if the sprite's x coordinate is greater than -50.

If you're successful you should see the Danger go all the way off the left side before returning on the right side.

View on Code Studio

Student Instructions

Now that you've got safe-left? working, let's fix safe-right?

It should take in a sprite's x coordinate and return true if that coordinate is less than 450.

Once your safe-right? is complete you should see the Target go off the right side of the screen and return on the left.

View on Code Studio

Student Instructions

At this point your Danger should run across the screen from right to left, your Target should run across from left to right, and they should both return to the opposite side, repeatedly. Take a minute to make sure your game is working like you want it to, and then click "Finish" to move on.

Standards Alignment

View full course alignment

Common Core Math Standards

EE - Expressions And Equations
  • 6.EE.9 - Use variables to represent two quantities in a real-world problem that change in relationship to one another; write an equation to express one quantity, thought of as the dependent variable, in terms of the other quantity, thought of as the independent va
  • 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.
F - Functions
  • 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
MP - 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
NS - The Number System
  • 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.
OA - Operations And Algebraic Thinking
  • 5.OA.1 - Use parentheses, brackets, or braces in numerical expressions, and evaluate expressions with these symbols.
  • 5.OA.2 - Write simple expressions that record calculations with numbers, and interpret numerical expressions without evaluating them. For example, express the calculation “add 8 and 7, then multiply by 2” as 2 × (8 + 7). Recognize that 3 × (18932 + 921) is three t
Q - Quantities
  • N.Q.1 - Use units as a way to understand problems and to guide the solution of multi-step problems; choose and interpret units consistently in formulas; choose and interpret the scale and the origin in graphs and data displays.
  • N.Q.2 - Define appropriate quantities for the purpose of descriptive modeling.