Let's now add some additional event handlers, so that you can do more with your car.
For example, we can't reverse our car! We might lose the car off the screen less often if we could reverse!
So, let's add an event handler to do this. How shall we set it up? Would pressing the down arrow, for reverse, be ok? Yes, let's do that.
In the Events pane, click on create new event, and select the When a key is typed option.
You should now see a new event handler at the bottom of the list:
Just now, the event handler is 'listening' for any key - but we want this event handler to be listening for the down arrow key - so click on the any key label and pick the down arrow.
We now need to create a method to reverse the car. This is the method that will get called when the down arrow key is pressed.
[Q6.4.1]: Try writing this method yourself. Give it a try! It is pretty much the same as the car go forward method - take a look at that one if you are unsure what to do. What do you think the code for this new method car go backward will look like? Write the Pseudocode.
If you're not sure where to start, that's fine - just read on. Making sure world in the top left pane is selected, hit create new method in the bottom left pane - and name the new method car go backward. The easiest way to add in the necessary move instruction is to view the code for car go forward and drag the move instruction up to the clipboard in the top right of the window. Then view the code for car go backward again, and drag the move instruction from the clipboard down into the method code. Be sure to change the forward in the move instruction to backward.
Once you've created your new car go backward method, go back to your new event handler. Right now, it says that when the down arrow is pressed, do nothing. Click on the Nothing label and select your new car go backward method.
Run it to see if it all works as you expected.
Additional project: Create a "wheelie" method that is called when the space bar is pressed. The instruction turn with backwards selected will make the car front go up and the back go down, a bit like a wheelie.
Save your finished Car World as LastNameFirstName-6.4CarWorld.a2w
It should have 2 new events:
When the ↓ is typed
When the space is typed
And 2 new methods
car go backwards
car do a wheelie or wheelie