Home
Project Folders
Teacher Resources
Student Resources
En ESPAÑOL
How Do I?
Vocabulary
MWForum
Site Map
Search
Our Team

bouncing off walls 1 2 3
Bouncing Off Walls 1
Download
6 KB


Goal:   Change the direction of the car when it touches a colored wall.


Screenshot


Vocabulary:   fd (forward), setsh (setshape), seth (setheading), forever

Code
Shapes
Project Map

code


Notes

  1. Draw a car shape (or click the "Shapes", and copy and paste a car into a shape).   Name it racecar1.

  2. Make a second car shape that is a mirror image of the first, and name it racecar2.   (If you are using the online shapes, you may copy and paste the mirror image race car into a second car shape.)

    If you have drawn your own race car, select and copy the closed shape, then click once on another closed shape and paste (select Edit -> Paste or ctrl-V/command-V).   In the Shape Editor, click the small "horse heads" button to flip to the mirror image, name the shape, and close it.

  3. Draw a background with two walls.   Fill the left wall with a shade of orange and the right wall with a shade of red.

  4. Hatch a turtle and place the racecar1 shape on it.   Position it between the two walls.

  5. In the go procedure, seth 90 means: "No matter what direction you were already facing, face to the right."   (We say it, "set heading 90" and the 90 means 90 degrees.)

  6. Forever means: "Launch a process that keeps doing the commands inside the brackets, over and over again."   It works the same way as making a button and setting it to Forever.   But we do not want to keep setting the heading to 90, because we want the car to move in both directions.   That is why we set the heading once to get started, and then use forever to keep the turtle moving.

  7. Make a button with go instruction, and keep it set to Once.   Whenever you use forever in a procedure, be sure that any button launching the procedure is set to Once.   If you try to launch forever over and over again, the project will crash.

  8. Now we need to program two colors so that when the car hits one color, it will change shape and direction, and when it hits the other color, it will change shape and direction again, back to the way it started out.   This way it can keep bouncing back and forth between the two colors.

    Open the dialog box for the color red (right-click/ctrl-click on red and select Edit red).   In the white space next to turtle, write:
    rt 180 setsh "racecar2

    Now open the dialog for the color orange.   Next to turtle, write:
    rt 180 setsh "racecar1

    Rt 180 means: "Turn 180 degrees to face the opposite direction."

    Setsh means "set shape."   The word after the quotation mark is the name of a shape.

  9. Your car (turtle) is now ready to smash into walls!!




What If?
What happens if you change the number after fd?
What happens if you add the command wait 1 after the fd command inside the brackets?


Challenge
What happens if you use different numbers after rt in the instructions for the colors?


On Your Own - Project Ideas
Use programmed colors to control a different sort of animation (such as a skater on a frozen pond).





© copyright 2001 - 2016  OpenWorld Learning.   All rights reserved.