4.2 Maze Code - IF touch wall Day2

Students will repeatedly test if a sprite touches the wall. If the sprite does touch wall, do something. If the sprite makes it to the end of maze, create a reward.

OBJECTIVES:

OBJECTIVES: By the end of this lesson, students will:

    • observe that code can branches down different paths using an "if statement".

    • recognize that an IF will only be tested once in sequential code, and that a common pitfall is to forget to repeatedly test it.

    • apply game play concepts: so that user is rewarded when they reach the end of a level and penalized when they bump into a wall.

Standards

    • CSTA 2-AP-12: Design and iteratively develop programs that combine control structures, including nested loops and compound conditionals.

    • CSTA 2-AP-17: Systematically test and refine programs using a range of test cases.

CSTA

DO NOW:

Maze Game

Do Now Diversity in Technology (5 minutes)

TEACHER GUIDANCE:


    • Robin stays away from video games with violence, instead focusing on creating empathy between people or understanding how people behave with video games.

    • Making a video game encompasses lots of creative activities: writing and drawing, painting, making sketches, watching videos, and thinking about different problems.

    • Stories, Art, Invention, bringing your unique perspective and voice into the game.

Mini-Lesson

Using student handout which has a pseudocode scaffold, students make something happen when the sprite touches the wall, and when it touches an end sprite.
To explore different ways to make controls, use the teacher slides.

Project (20-30 minutes)

Repeatedly test a condition. - Main object of lesson.

Conditions evaluate to either true or false. Conditions are useful, when paired with an IF statement. <If <condition true>, do something" .
Normally, we want to repeatedly test a condition, so that when the condition becomes true, it can trigger an action.
A good way to achieve this is by putting the condition into a
Forever Loop. (Test the condition repeatedly and if it becomes true, do something.)


In “Race to the Finish, Unit 3.3” students continually test: if < at finish line > say “ You win! ”. Each time the user pressed the forward key, the condition was tested.

Now, we want to test if the hero is bumping into a wall. We could put the conditional test in all four movement blocks: up, down, right and left so that it is continually tested , but this is less efficient than using a forever loop. See comparison here.

Sensing Blocks. Touch is one of our five senses. Therefore the conditions: <touching color>, <touching end sprite> - are blue sense commands.

Color Selection.
T
his 24 second video, shows how to select the correct color. CorrectColorEyedropTool.

Scratch colors translate into Hexadecimal: Red(0-255) Green(0-255) Blue (0-255), which is 2563 (16,777,216) different color variations. It is impossible to eyeball the correct shade, hue and saturation with so many variations. Scratch does try to help, by selecting one of the colors from your stage as the initial default. If this is not the color you need, then you need to use the eyedrop tool. Choosing a color that looks the same, but is not an exact match, is a common error that is hard to detect.

Wait Until Block


Do these control structures do the same thing. (yes.)
Look inside this Scratch project to see both constructs in action.


There is always more than one way to program!

  • <if, then> TRUE, go into the statement, FALSE, skip statement, continue onward.

  • <wait until> wait until the condition is true. Other threads will continue to run. Parallelism.

Close-Out (5 minutes)

Close-Out (5 minutes)

    1. Discuss the following questions:

      • Why should you repeatedly test a condition?

      • Touching color, touching sprite etc, are found under which block?

      • Why do you need to use the eye-drop tool, when using the command <touching color>?

Potential Responses

  • You need to repeatedly test a condition, so that when that when the condition becomes true, it can trigger an action. e.g. In the maze, the sprite is not always touching the wall, but when it is we want it to bounce back.

  • Touching commands reside in blue sensing commands.

  • Scratch colors translate into 2563 (16,777,216) different color variations. In order to get the right color, you must use the eye-drop tool.