First, open the GoldBuggy code window by double-clicking on the GoldBuggy class on the right.
At the bottom of the act() method, remove the comment //Code clip: Remove Object on Collision goes here and paste or type in 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 grab some gold!
This demo contains two actors, the GoldBuggy and the Gold . The GoldBuggy moves with the arrow keys (see Code Clip 1: Move With Arrow Keys).
The first line in the code clip is:
The next line is:
The code in the curly brackets is:
The second line calls the removeObject() method, which removes an object from the world. The argument is the variable gold , which was assigned to the intersecting Gold actor by the getOneIntersectingObject() method.