Unit 10Collision Detection and Completing Your Game
Unit Overview

Using the distance and is-collision functions they wrote for their Ninja Cat games, students complete collision detection in their own games, and return to the lists of questions to ask their world from the previous unit to complete their video games.

Product Outcomes:
• Students will use different Ask branches to identify collisions in their games

Standards and Evidence Statements:

Standards with prefix BS are specific to Bootstrap; others are from the Common Core. Mouse over each standard to see its corresponding evidence statements. Our Standards Document shows which units cover each standard.

Length: 90 minutes

Materials:
• Pens/pencils for the students, fresh whiteboard markers for teachers

• Class poster (List of rules, design recipe, course calendar)

• Editing environment (Pyret Editor)

• Student workbooks

• Language Table

Preparation:
• Seating arrangements: ideally clusters of desks/tables

 Types Functions Number + - * / num-sqr num-sqrt num-expt String string-append string-length Image rectangle circle triangle ellipse radial-star scale rotate put-image Boolean = > < string-equal and or

Introduction

Overview

Learning Objectives

Evidence Statements

Product Outcomes

Materials

• Pens/pencils for the students, fresh whiteboard markers for teachers

• Class poster (List of rules, design recipe, course calendar)

• Editing environment (Pyret Editor)

• Student workbooks

• Language Table

Preparation

• Seating arrangements: ideally clusters of desks/tables

Introduction (Time 5 minutes)

• Welcome to the home stretch! You’ve learned a LOT in this class, including a brand new programming language, concepts like data structures event-driven programming, and even extended your knowledge of piecewise functions. In the last unit, you’ll finish implementing the tests you listed in the last unit, and collision detection for your game. Let’s get started.

Collision Detection in Your Game

Overview

Learning Objectives

• Students will write their own distance and is-collision function to detect collisions of characters in their games.

Evidence Statements

Product Outcomes

• Students will use different Ask branches to identify collisions in their games

Materials

Preparation

Collision Detection in Your Game (Time 35 minutes)

• The final addition that everyone will need in their games is collision detection! What should happen when your player collides with your danger, or target? Do you have a score as part of your world structure? Thankfully, you’ve already completed the Design Recipe for the functions you’ll need to add to your game.

Turn to Page 27 in your workbook. Starting with line-length, add your line-length, distance, and is-collision functions into your game file.

Pay careful attention to the order in which the coordinates are given to the distance function. The player’s x-coordinate (px) must be given first, followed by the player’s y (py), character’s x (cx), and character’s y (cy). Inside the body of the function, line-length can only calculate lengths on the same axis (line-length(px, cx) and line-length(cx, cy)). Just like with making data structures, order matters, and the distance function will not work otherwise. Also be sure to check that students are using num-sqr and num-sqrt in the correct places.

• Now that you have all the necessary functions to check whether characters are colliding, you can add to your next-world function to modify the world when this happens. Remember what you wrote for the Ninja Cat game: first, you checked whether the cat and dog were colliding. Maybe you want to check if the player has reached a goal at certain coordinates, or if your player and danger have collided.
• What function checks if two thing are colliding?

• What do the inputs need to be?

• What dot-accessots will you need to use?

• What should happen when these two things collide? What will your new world structure look like after this collision?

• add your new ask branchest to next-world so that the world changes when characters collide.

Work with students in pairs or small groups to complete these activities.

Branches in next-world

Overview

Learning Objectives

Evidence Statements

Product Outcomes

Materials

Preparation

Branches in next-world (Time 45 minutes)

• Now you’ve programmed your games to respond when different characters collide, and your games are almost finished! Think about what else you want to add: a scoring system? More dangers, targets, or players? Levels? Remember that for everything that changes in your game, you’ll need to add to your world structure, and this is your chance:

Turn to Page 41 in your workbook and finish adding the things on your list to your game file.

Remember, if you want to change the appearance of your games, you’ll need to change your draw-world function to a piecewise function. You can write the tests and results you’ll need for this function on Page 43.

Work in pairs or small groups to assist students with completing their games.

Closing

Overview

Learning Objectives

Evidence Statements

Product Outcomes

Materials

Preparation

Closing (Time 5 minutes)

• Congratulations! You started from scratch, and now have a complete, working videogame! We hope you’ll continue working on these games yourself, keep hacking, and keep learning!

Have students show off their completed games!