Volume 7 Number 3 - Summer 1999

Computer Games for Kids, by Kids - Part 2
...continued

<--- previous page || next page --->

Mega-Pong

Loren was an artist and a very competent programmer. He brought a strong sense of design to his projects. The idea of Mega-Pong was straightforward -- two moving paddles bat a ball back and forth in a rectangular enclosure. Many of the basic elements of the game were similar to those found in Air Hockey.

You can visit now by clicking here. You can play the Pong game right in your web browser. You can also download a copy of the game for Macintosh or Windows.

The VGW Website will open in a new window. Close or minimize that window when you want to return to this article. Don't use your browser's back button.

Start gets the game going.

to start
forever [direct readchar]
ball, seth (random 360) + 20 clickon
when [touching? "ball "blue] [ball, seth 180 - heading - 180 bong]
when [touching? "ball "red] [ball, seth 180 - heading - 180 bong]
end

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:

to reverse.direction
seth 180 - heading
end

Direct controls the paddles.

to direct :key
if (ascii :key) = 97 [red, seth 0 repeat 10 [fd 5]]
if (ascii :key) = 122 [red, seth 180 repeat 10 [fd 5]]
if (ascii :key) = 39 [blue, seth 0 repeat 10 [fd 5]]
if (ascii :key) = 47 [blue, seth 180 repeat 10 [fd 5]]
if :key = "` [1player]
if :key = "* [1playerb]
end

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:

if :key = "a [red, seth 0 repeat 10 [fd 5]]
if :key = "z [red, seth 180 repeat 10 [fd 5]]
if :key = "' [blue, seth 0 repeat 10 [fd 5]]
if :key = "/ [blue, seth 180 repeat 10 [fd 5]]

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:

to 1player
red, clickon
end

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
start, shrink
options, shrink
exit, shrink
begin, shrink
game
start.game.cool

Bong is a sound. The next four instructions cause the turtle buttons named Start, Options, Exit, and Begin to shrink. Here's shrink:

to shrink
setsize 40 repeat 35 [setsize size - 1] ht
end

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.

to blue.lose
reset
winner, st setpos [0 75] setsh "rwin11 wait 1 setsh "rwin10 wait 1 setsh "rwin9 wait 1 setsh "rwin8 wait 1 setsh "rwin7 wait 1 setsh "rwin6 wait 1 setsh "rwin5 wait 1 setsh "rwin4 wait 1 setsh "rwin3 wait 1 setsh "rwin2 wait 1 setsh "rwin1 wait 1 setsh "rwin2 wait 1 setsh "rwin3 wait 1 setsh "rwin4 wait 1 setsh "rwin5 wait 1 setsh "rwin6 wait 1 setsh "rwin7 wait 1 setsh "rwin8 wait 1 setsh "rwin9 wait 1 setsh "rwin10 wait 1 setsh "rwin11 ht
reset stopall
end

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.

<--- previous page || next page --->

LOGO UPDATE Vol. 7 No. 3 - FRONT PAGE

WHAT'S NEW || LOGO FOUNDATION HOME || CALENDAR OF EVENTS

ABOUT THE FOUNDATION || WHAT IS LOGO?

FOUNDATION SERVICES || ON LINE PUBLICATIONS

LOGO RESOURCES || LOGO PRODUCTS