This site requires JavaScript, please enable it in your browser!
Greenfoot back
suge5
suge5 wrote ...

2017/5/3

Please Help Me!

suge5 suge5

2017/5/3

#
I want each animal to make a different sound when hit... As of now each animal just makes a ribbit sound, and I don't know how to implement a way for each animal to make a different sound when hit... Also I want a like a gunshot sound or something then the frog makes it to the end of the world and no sound when the other animals do. This make sense??? abstract public class FrogsHit extends Actor { public abstract void act(); //abstract to be used by all subclasses public void FrogHitter(){ Greenfoot.playSound("Ribbit.wav"); //sound to play ((FrogWorld) getWorld()).countHit(this); //plays when hit and records hit getWorld().removeObject(this);} //removes hit ibject public abstract int getCount(); //abstract of getCount for all subclasses } abstract public class Animals extends FrogsHit { public abstract void act(); //abstract for act public abstract int getCount(); //abstract for getCount } public class SwimmingFrog extends Animals { boolean remove=false; //creates a remove vareiable at false private int distance; //intializes speed public void act() { distance++; //increments speed setLocation(getX(), getY() -2); //sets the x value but increases speed by 2 if(distance%5 == 0){ setLocation(getX()-1, getY()); //moves the frog left one for every 5 up } if (getY() == 0) { ((FrogWorld) getWorld()).lose(); //takes away life if a frog crosses remove=true; //if removed FrogHitter(); //removes the animal once it reaches the end of the world } // Greenfoot.playSound("Ribbit.wav"); // ((FrogWorld) getWorld()).countHit(this); // getWorld().removeObject(this); } public int getCount(){ if(remove != true){ return 10; //gain 10 points if a frog crosses } return 0; //lose 0 points if frog crosses } } public class PolarBear extends Animals { boolean remove=false; //creates a remove vareiable at false private int distance; //intializes the varibale distance public void act(){ distance++; //increments distance setLocation(getX(), getY() -3); //sets the x value but increases speed by 3 if(distance%5 == 0) { setLocation(getX()-1, getY()); //moves 1 left, so on diagonal path } if (getY() == 0) { remove=true; //if removed FrogHitter(); //removes the animal once it reaches the end of the world } // Greenfoot.playSound("Ribbit.wav"); // ((FrogWorld) getWorld()).countHit(this); // getWorld().removeObject(this); } public int getCount(){ if(remove = true){ return -10; // if you press on animal before it crosses you get -10 points } return 2; //else you get 2 points for letting it cross pond } }
danpost danpost

2017/5/3

#
Add:
public abstract void playHitSound();
to the FrogsHit and Animals classes. Then change the first line in the FrogHitter method of the FrogHit class to:
playHitSound();
The newly required methods in the subclasses of Animals should play their appropriate sounds.
suge5 suge5

2017/5/4

#
Still Having a little trouble...
  • public class FrogHunter extends Actor { public void act(){ if(Greenfoot.mouseMoved(null)) { //whenever the mouse is moved MouseInfo mouse = Greenfoot.getMouseInfo(); // obtains information from the mouse setLocation(mouse.getX(), mouse.getY()); // sets the locaion of the bat to where the user places the mouse in the world } if(Greenfoot.mouseClicked(null)) { //finds all ibjects int x = -getImage().getWidth()/2; //sets location of bat you can hit animal with int y = getImage().getHeight()/2; //sets location of bat you can hit animal with FrogsHit Fhit = (FrogsHit) getOneObjectAtOffset(x , y, FrogsHit.class); //return one object that is located at the specified cell if(Fhit != null) { //finds the objects Fhit.FrogHitter(); //removes the objects once pressed } } } }
  • abstract public class Animals extends FrogsHit { public abstract void act(); //abstract for act public abstract int getCount(); //abstract for getCount public abstract void playHitSound();// }
  • abstract public class FrogsHit extends Actor { public abstract void act(); //abstract to be used by all subclasses public void FrogHitter(){ //Greenfoot.playSound("Ribbit.wav"); //sound to play ((FrogWorld) getWorld()).countHit(this); //plays when hit and records hit getWorld().removeObject(this);} //removes hit object public abstract int getCount(); //abstract of getCount for all subclasses public abstract void playHitSound(); }
  • public class PolarBear extends Animals { boolean remove=false; //creates a remove vareiable at false private int distance; //intializes the varibale distance public void act(){ distance++; //increments distance setLocation(getX(), getY() -3); //sets the x value but increases speed by 3 if(distance%5 == 0) { setLocation(getX()-1, getY()); //moves 1 left, so on diagonal path } if (getY() == 0) { remove=true; //if removed FrogHitter(); //removes the animal once it reaches the end of the world } // Greenfoot.playSound("Ribbit.wav"); // ((FrogWorld) getWorld()).countHit(this); // getWorld().removeObject(this); } public int getCount(){ if(remove = true){ return -10; // if you press on animal before it crosses you get -10 points } return 2; //else you get 2 points for letting it cross pond } public void playHitSound(){ Greenfoot.playSound("Pop.wav"); ((FrogWorld) getWorld()).countHit(this); getWorld().removeObject(this); } }
You need to login to post a reply.