Start gets the game going.
The first line of start activates a process that continually runs direct. The second line aims the ball at a random heading and gets it moving. It's not clear why + 20 is there. It may have been an attempt to avoid randomly getting a heading of 0, but it doesn't make any difference. Clickon turns on the instruction programmed into the ball turtle: fd 5 many times. The name of the ball turtle is "ball". In MicroWorlds turtles start with names "t1", "t2", "t3", etc., but they can be changed so that a program becomes more readable. Loren does this. Most students don't bother. The two when commands set up processes that check for collisions between the ball and each paddle, and take appropriate action. The left paddle is named "red". The right paddle is named "blue". The bounce off a paddle is essentially the same as bouncing off a vertical wall in the Air Hockey game, but Loren has come up with a new variant of how to code it. Instead of seth 360 - heading he uses seth 180 - heading - 180. Although this may look odd it makes sense if one knows the history. He arrived at it by starting with the instruction for bouncing off the horizontal walls -- seth 180 - heading -- and modifying it to work for the vertical paddles. He hadn't noticed that the 180s could be removed since 180 - 180 = 0. We pointed it out, but he didn't see any good reason to change it. It worked. The horizontal gray bands at the top and bottom of the screen cause the ball to bounce off. The color gray is programmed with the turtle instruction reverse.direction, which looks like this:
Direct controls the paddles.
The red paddle is controlled by pressing the "a" and "z" keys. The blue paddle is controlled by pressing "'" and "/". It was not necessary to use the ascii numbers for these keys. The code could have been:
The ascii numbers are needed only for unprintable characters such as the arrow keys used in the direct procedure of the Air Hockey game. But since Loren modified the older version of direct, the use of ascii numbers remained. The last two lines of direct implement an undocumented feature of the game. They each set up a single-player game by causing one of the paddles to work automatically. The procedure 1player looks like this:
Clickon turns on the instruction programmed into the red paddle turtle, which is forever [sety ask "ball [ycor] wait 1] This causes the red paddle to continually set its y coordinate to be the same as that of the ball. It never misses. The procedure 1playerb is the same as 1player, but it puts the blue paddle on autopilot. If you turn them both on, the game plays itself. Designer Buttons Loren found the built-in MicroWorlds buttons to be dull. He made his own using turtles. For Mega-Pong the turtle shapes were words such as Start, Reset, and Exit. To create these shapes he put the appropriate text in a text box and stamped it onto the background. Then using the select tool in the Drawing Center he copied the stamped text and then pasted it into a shape in the Shapes Center. The turtle with the word Start as its shape has these instructions programmed into it:
Bong is a sound. The next four instructions cause the turtle buttons named Start, Options, Exit, and Begin to shrink. Here's shrink:
The default size for turtles is 40. They may be set to sizes ranging from 5 to 150 using the setsize command. After the buttons shrink and disappear game sends us to the page named game, which is where the action takes place. Start.game.cool starts the cool game. Loren also uses shrinking and growing text-carrying turtles for various messages and titles. Another interesting technique that he developed is to have words fade in and out, as with the message that appears when Red wins.
The shape rwin11 is a black rectangle. Since it is displayed again a black background you can't see it. Shape rwin10 has the words "Red wins !!!" in the deepest shade of red. Shape rwin9 has the same words in a slightly lighter red and so on, up to rwin1, which uses the lightest available shade of red. Blue.lose cycles through these shapes from darkest to lightest and then back to darkest again.
Ball Speed The speed of the ball will vary depending upon the speed of your computer. To change the speed, change the instruction programmed into the ball turtle. It is now fd 5. A smaller input to fd will slow it down. Numbers less than 1 are OK, for example, fd 0.1 will work. The Options button on the opening screen seems to allow you to select a ball speed, but this feature was never implemented, so the selection has no effect.
Spreading the Words The techniques that Loren pioneered in Mega-Pong spread throughout the class. Growing and shrinking buttons, titles and messages moving around and fading in and out were incorporated into many other games.
|
|
|