<< Chapter < Page | Chapter >> Page > |
It may seem strange to say that a round basketball is facing in one direction or the other. However, every sprite has a front, back, top, and bottomeven in those cases where it is not visually obvious. (The orientation would be visually obvious if I were to use an animal for the sprite in place ofthe basketball. You can tell which direction the basketball is facing by observing the curved diagonal lines on the basketball.)
After you drag the blue block labeled point in direction into the center pane, you can click the arrow in the white box to expose the followingfour choices:
As you can see, I selected the choice that causes the basketball to face to the right. As a result, when the user clicks the green flag, the basketballwill move to the origin and turn to face the right.
Image 8 shows all of the code in the center pane that applies to the basketball.
The top script in Image 8 is another image of the script that was shown in Image 7 . At this point, we are interested in the behavior of the bottom script in Image 8 .
The tan block labeled when Basketball clicked specifies that all of the actions produced by the blocks below that block will occur when the userclicks the basketball with the mouse. Furthermore, those actions will occur in top to bottom order.
The blue block labeled move 90 steps causes the basketball to move 90 steps forward (in the direction that it is facing) . Each step constitutes one unit in the Cartesian coordinate system. For example, if you were to change this value from 90 to 240, thatwould cause the basketball to move from the origin to the extreme right edge of the Stage.
As I indicated earlier , the selection structure is sometimes referred to as a decision structure. In other words, this structure causes the program to select or make a decision between two alternatives. The pseudocode in Image 9 describes this process.
Sometimes the second part of the selection process isn't needed. In other words, in some cases, if the specified condition is not true, there is norequirement to do anything at all. That is the case in this program.
This program makes two independent decisions shown by the pseudocode in Image 10 .
These two decisions are implemented by the two tan blocks in Image 8 containing the word if .
The Control group Clicking the tan Control button shown at the upper left in Image 4 exposes a large number of programming blocks. Twoof them are used to create pure selection structures and one is used to create a combination of a loop structure and a selection structure.
Clicking the tan Control button shown at the upper left in Image 4 exposes the blocks shown in Image 11 . The bottom two blocks can be used to create pure selection structures. The top block can be used to create acombination of a loop structure and a selection structure.
Notification Switch
Would you like to follow the 'Teaching beginners to code' conversation and receive update notifications?