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 3
Download
8 KB


Goal:   Make the car change its color every other bounce.


Screenshot


Vocabulary:   if, > (greater than sign), shape

Code
Shapes
Project Map

code


Notes

We can make the car change colors as it bounces back and forth.   This project refers to shapes by number, not name.   So it is important that the shapes be placed in the right positions in the Shapes center.   In this sample project, the car changes color six times.

  1. If the racecar1 shape is not yet positioned as shape 1, copy and paste it into that location now.   In the same way, copy and paste the racecar2 shape into shape 2.   It does not matter that you are "wiping out" other shapes.   You won't need them in this project.

  2. Next, click once on the closed shape 1 (the first race car) and copy it (Edit -> Copy or ctrl-C/command-C) and paste it into shape 3, shape 5, shape 7, shape 9, and shape 11 (click once on each closed shape and press Edit -> Paste or ctrl-V/command-V).  

  3. Copy shape 2 (the flipped version of the first race car shape) and paste it into shapes 4, 6, 8, 10, and 12.  

  4. Open each of the new shapes and spill a new color of paint onto each pair of shapes.   (In this sample project, shapes 1 and 2 are the pair of yellow cars; shapes 3 and 4 are the pair of orange cars; and so on.)

  5. In the changeshape procedure, rt 180 will reverse the direction of the moving car.  

  6. We cannot tell the car to change to one specific shape, because we are going to need it to change between a lot of different shapes.

    Setsh shape + 1 means: "Whatever shape you are now, change to the next shape in the shapes center."  

    It does not matter what the names of the shapes are - every shape also has a number, and that is all we are looking at now.   But after the turtle changes to shape 12 (the last car), we do not want it to change to shape 13.   We want it to go back to the first car shape.

    If shape > 12 [setsh 1] means: "If the number of your shape is greater than 12, turn into shape 1."

    So as soon as the car turns into shape 13, it will turn into shape 1, which is the first car shape, and every time it hits a wall, it will turn into the next shape again, until it reaches shape 13 again.   We never actually see it become shape 13, because it changes again so quickly that it seems to go straight from shape 12 to shape 1.   And that is what we want.

  7. Program the colors red and orange with the procedure name, changeshape.  

  8. Now when we press the go button, the car should change colors when it bounces between the walls.  




What If?
The instructions for the colors in the changeshape procedure include the command setsh shape + 1 -- what happens if you change the 1 to a 2? a 3?


Challenge
Right now the car hits two walls before it changes color.   Can you rearrange the order of the shapes so that the car will change color (and direction) every time it hits a wall?


On Your Own - Project Ideas
Can you add a few more car shapes after shape 12 and change the programming of the colors to include those new shapes? (It would be funny to see the car start to look smashed up! Or it could turn into more colors, or different kinds of cars.)





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