Project Folders
Teacher Resources
Student Resources
How Do I?
Site Map
Our Team
How do I steer the turtle with keyboard keys?
Method 1:   You can write a procedure to teach a turtle to respond to certain keys. See the bumper turtles activity page. The steer procedure below teaches the turtle to respond to the arrow keys. PCs and Macs use different ASCII characters for the arrow keys, so this procedure uses both sets of ascii characters. Ascii characters 37 40 control the arrow keys on a PC; ascii characters 28 31 control the arrow keys on a Mac. Ascii character 32 controls the space bar. See How do I find ASCII numbers? In the steer procedure the space bar can be used to pause and resume the turtle's movement.

You can activate the turtle with a go button. But be careful! In MW Pro, you need to click on the background of the page before the turtle will respond to key commands. So it might be safer to create a fake button by programming a color to activate the go procedure. (Right-click on that color in the graphics area to open its dialogue box.)

Vocabulary: make, ascii, readchar, if, clickon, clickoff, clean, forever and setinstruction.

Right-click HERE to Download
The turtle moves constantly. The keys control its direction.

Method 2:   We can vary these procedures so that the arrow keys cause the turtle to turn and move forward:

Right-click HERE to Download
Pressing an arrow key controls the direction of the turtle and moves it forward 10 steps.

Method 3:   We can program any keys on the keyboard, and we can program two turtles to respond to two sets of keys. In the procedures below, t1 is steered with keys a, s, d, and w; t2 is steered with keys j, k, l, and i. In this way, two players can compete to guide turtles through a maze, for instance. (Can you combine these procedures with the one above to steer a third turtle with the arrow keys?)

Vocabulary: setpos.

Right-click HERE to Download
Race a friend to steer these turtles into the pond without leaving the path.

Also:  A color can be programmed to respond to the moving turtles so that if one turtle strays off of a path, it will be sent back to the start. In this sample program, orange has been programmed so that a mouse-click will launch the go procedure and lime has been programmed so that a turtle passing over it will launch the go-home procedure. The turtles have their pens up (pu) so that they do not draw. The procedures are the same as in the project above, with the addition of go-home:

Vocabulary: who.

Right-click HERE to Download
Keep on the path or you'll be sent home!

« Previous
Next »

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