My goal is for each animal to play a different when they are pressed on or reach the end of the world. Right now whenever the animal enters the screen it will play the noise associated with it over and over again.
Thanks,
Sam
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
playHitSound();
((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();
}
abstract public class Animals extends FrogsHit
{
public abstract void act(); //abstract for act
public abstract int getCount(); //abstract for getCount
public abstract void playHitSound();//
}
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
}
playHitSound();
// 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 void playHitSound(){
Greenfoot.playSound("Ribbit.wav");
//((FrogWorld) getWorld()).countHit(this);
(getWorld().removeObject(this));
}
}
public class Fish extends Animals
{
boolean remove = false; //sets boolean variable to false
private int distance; //initializes distance variable
public void act(){
distance++; //increments distance
setLocation(getX(), getY() -4); // sets x and increases speed of y by 4
if(distance%5 == 0){
setLocation(getX()-1, getY()); //moves fish left as they go up
}
if (getY() == 0) {
remove = true; //if removed
FrogHitter(); //removes the animal once it reaches the end of the world
}
playHitSound();
}
public int getCount(){
if(remove != true){
return 2; // if you press on animal before it crosses you get 2 points
}
return 0; //if reaches end of world, you lose nothing
}
public void playHitSound(){
Greenfoot.playSound("Fish.wav");
((FrogWorld) getWorld()).countHit(this);
getWorld().removeObject(this);
}
}