*/ i want to stop my background music, but i can't, when the hero is die or alive Score are 0, the music is stop, some body to help me? */
import greenfoot.*;
public class MyWorld extends World
{
public static GreenfootSound music = new GreenfootSound("bg.wav");
public void bgMusic()
{
if (MyWorld.aliveScore.getValue()==0)
{
music.stop();
}
else
{
music.playLoop();
}
}
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
prepare();
}
public void act(){
this.createEnemy();
this.createLaserEnemy();
this.bgMusic();
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
public static Counter score = new Counter("Score : ");
public static Alive aliveScore = new Alive ("Alive : ");
private void prepare()
{
Hero hero = new Hero();
addObject(hero,70,200);
addObject(score,50,20);
score.setValue(0);
addObject(aliveScore,150,20);
aliveScore.setValue(5);
}
int enemyCounter=0;
private void createEnemy(){
enemyCounter++;
if (enemyCounter==60){
Enemy enemy = new Enemy(Greenfoot.getRandomNumber(7)+1);
addObject(enemy, 600, Greenfoot.getRandomNumber(400));
enemyCounter = 0;
}
}
int LaserEnemyCounter=0;
private void createLaserEnemy(){
LaserEnemyCounter++;
if (LaserEnemyCounter==60){
LaserEnemy enemy = new LaserEnemy(Greenfoot.getRandomNumber(10)+1);
addObject(enemy, 600, Greenfoot.getRandomNumber(400));
LaserEnemyCounter = 0;
}
}
}

