1 of 8

Lesson 2.6.E: Break Out Game demonstration

Microsoft Philanthropies TEALS Program

Introduction to Computer Science

2 of 8

Let's look at the starter code.

3 of 8

How do we know when the ball goes out of bounds?

  1. We could watch the y position. When it gets too low we say the ball is out of bounds.
  2. We could create a sprite that covers the out of bounds area. When the ball touches that sprite it is out of bounds.
  3. We could track the direction of the ball before if on edge, bounce and compare it to after. Let’s not even consider this.

4 of 8

The first option is easy enough. So let’s look at how to do the second.

Use the sprite paint tool to create a simple black band.

5 of 8

Position it at the very bottom edge of our game area.

Auto adjust the size to fit perfectly.

Always the back most layer. You don’t want it to show in front of the ball.

6 of 8

When the ball touches out of bounds stop the game.

Remember to broadcast show score whenever something changes.

You lose a life every time the ball goes out of bounds.

Putting stop game into all of our loops makes it easy now.

7 of 8

Design: Why make an extra sprite for out of bounds?

  1. For some people this just makes more sense. That is a good enough reason.
  2. The code for moving the ball is already complex. Adding more stuff to it will be harder to debug.
  3. “Lots of little pieces.” The code to handle out of bounds is trivial. I can almost know it works by looking at it.

Should I make the ball motion script easier to understand? Yes! In unit 3 we will learn how to do that.

8 of 8

2.6.E: Debrief