Creating Your Own Game or A Two Horse Race


You have learnt sufficient commands to create your own game. The following procedures allow different keys to control different turtles as with keycontrol. You will create a racing game that two people can play.

Draw an obstacle course. An example is shown below. You can make it as difficult as you like. The obstacles can be drawn in different colours and these colours can be programmed with different "penalties. For example red could have the instruction bk 100 rt 180 as a penalty, green could have the penalty setpos [-200 0] to move the turtle back to the starting position, black could have the instruction bk 5 for a small penalty while you could even have some obstacles with a bonus eg fd 10.

The finish line should be another colour with the instruction announce [Winner]
Make sure that you have two turtles and that they are called t1 and t2.
Write the procedures getchoice, paddles and startgame shown below.

to getchoice
   make "answer readchar

to paddles
    if :answer = "i [fd 10]
    if :answer = "m [bk 10]
    if :answer = "j [lt 10]
    if :answer = "l [rt 10]
    if :answer = "w [fd 10]
    if :answer = "z [bk 10]
    if :answer = "a [lt 10]
    if :answer = "s [rt 10]

to startgame
     t1, setpos [-200 0] seth 90
     t2, setpos [-200 20] seth 90

Create a button with the instruction startrace.

If everything works you should be able to use the keys to control the turtles separately and have a race to the finish.

An extra instruction transparent "text1 Makes the text box called text1 transparent. This was used to create the words FINISH in the obstacle course shown above.






Created by Geoff Adcock
Last Update: 04-Dec-2006