(First, open the Leaf class. Take a look at the act() method. It calls
two methods – falling() and checkForMiss(). The falling() method
causes the leaves to flutter downwards. The checkForMiss() method
checks to see if the baby missed the leaf – in other words, the leaf
has hit the bottom without being caught. Add code to play the
“fallenthing” sound (look in the images folder to find the file for this
sound). This will go inside the IF clause. Test – everytime a leaf hits the
bottom, you should hear this noise.)
Above is part of my assignment, i cannot get the sound to compile it gives me an error saying cannot find symbol
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Leaf here. * * @author (your name) * @version (a version number or a date) */ public class Leaf extends Actor { private GreenfootImage leaf0 = new GreenfootImage("cutoutleaf0.png"); private GreenfootImage leaf1 = new GreenfootImage("cutoutleaf1.png"); private GreenfootImage leaf2 = new GreenfootImage("cutoutleaf2.png"); private GreenfootImage leaf3 = new GreenfootImage("cutoutleaf3.png"); private int speed; //set the speed of each leaf public Leaf() { /* Change the image of the leaf depending on whether the random * number is 0, 1, 2, or 3. Also, rotate the object a random amount * to create the appearance of many leaves */ speed = (Greenfoot.getRandomNumber(2)+1);//plus 1 to take care of speed 0 } /** * Act - do whatever the Leaf wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { falling(); checkForMiss(); } /** * falling - simulate the leaf falling to the ground. Slowly rotate, change * course just a little horizontally each time through */ public void falling() { int newX = Greenfoot.getRandomNumber(7) - 3; //gives me a # between -5 & 5 setLocation(getX() + newX, getY()+speed); setRotation(getRotation() - 1); // have leaf slowly rotate } /** * checkForMiss - if the leaf hits the ground, it means the Catcher * did not catch the leaf. Remove the leaf object and do whatever you want */ public void checkForMiss(){ if (getY()> getWorld().getHeight() - 25) { getWorld().removeObject(this); Greenfoot.playsound("fallenthing.wav"); } } }