First, open the GoldBuggy code window by double-clicking on the GoldBuggy class on the right.
Below the line that says public void act(), delete the line inside the curly brackets that says //Add your action code here and include the code clip above:
Press the 'Close' button at the top of the code window.
Press the 'Compile' button at the lower right hand corner of the Greenfoot window.
Press the 'Run' button, and move your car!
This demo contains a world, called "Sand" and a single actor, called "GoldBuggy." Currently neither the GoldBuggy actor nor the world have any code added. The GoldBuggy is permanently in the world, using the "Save the World" feature.
The act method runs every turn of the game. The code above puts four if statements that check to see if certain keys are pressed. The Greenfoot.isKeyDown() method is part of the Greenfoot module, it returns a True value if the key in the parentheses is pressed, which makes the code inside the curly brackets run. If it isn't pressed, you'll get a False , and it won't run.
The setRotation() command is a method that turns the buggy in a certain direction. The number inside the parentheses is an argument, or information that's passed to the function. This argument is the number of degrees we want it to move.
The move() command is a method that makes the car move forward. The number inside the parentheses is an argument that tells the method how many cells forward to move. Since one cell is one pixel in this world, it will move the car forward 5 pixels.