Hi,
Is there a way for whenever my actor (Bowser) obtains 10 coins to play a sound indicating that the game is won? Setting up a private integer equal to zero?
Here is my code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Coin here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Coin extends Actor
{
/**
* Act - do whatever the Coin wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(),getY()+5);
if(getY()>getWorld().getHeight()-3) {
getWorld().removeObject(this);
}else{
Actor bowser = getOneIntersectingObject(Bowser.class);
if(bowser !=null) {
Greenfoot.playSound("coin.wav");
getWorld().removeObject(this);
}
}
}
}
