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
}
}
