1 of 8

Collision Detection

@BootstrapWorld

#BootstrapCS

2 of 8

Problem Decomposition Returns!

  • How do we know when these circles are touching?
  • How does the distance help us determine a collision?
  • What functions would be useful to write here?
  • Top-Down, Bottom-Up!

@BootstrapWorld

#BootstrapCS

3 of 8

Problem Decomposition Returns!

You 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.

@BootstrapWorld

#BootstrapCS

4 of 8

Problem Decomposition Returns!

A retractable pole starts out 24 inches tall, and grows 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.

Turn to Top Down, Bottom Up (Page 57) in your student workbook, and solve this word problem using any order you like!

@BootstrapWorld

#BootstrapCS

5 of 8

Problem Decomposition Returns!

Which strategy did you use? Top-Down or Bottom-Up?

Did you start out with one, and then switch to another?

Which was easier for you?

@BootstrapWorld

#BootstrapCS

6 of 8

Collision Detection

We already have a function that will tell us how close together two points are. What is that function called?

Knowing how far apart our characters are is only the first step! We still need the computer to be asking: "Are they close enough to collide?"

@BootstrapWorld

#BootstrapCS

7 of 8

Collision Detection

  • Use the Design Recipe to write collide? (Page 58), which that takes in two coordinates (four numbers) of the player (px, py) and a character (cx, cy), and returns true if they are within 50 pixels of each other.
  • Fix the collide? function in your game file, and click Run!

@BootstrapWorld

#BootstrapCS

8 of 8

Collision Detection

You started by writing the distance function first, and then collide? Is this Top-Down or Bottom-Up decomposition?

collide? function was easy to write, because we could re-use the distance function.

Have we done anything like this before?

@BootstrapWorld

#BootstrapCS