if i press h can play the back sound, but only the this world only
i was making actor is Sound ,
this is the code;
the world code
Player Code
i mean if player in Clift World only can doing howl
public class Sound extends Actor { /** * Act - do whatever the Sound wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { Howl(); } public void Howl() {GreenfootSound WolfHowls= new GreenfootSound( "wolfhowl.wav" ); if(Greenfoot.isKeyDown("H")) WolfHowls.play(); } }
public class Clift extends World { /** * Constructor for objects of class Clift. * */ public Clift() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); //player Player player = new Player(); addObject(player,321,212); //Stones Stone12 stone12 = new Stone12(); addObject(stone12,299,251); Stone13 stone13 = new Stone13(); addObject(stone13,344,265); Stone14 stone14 = new Stone14(); addObject(stone14,388,281); Stone15 stone15 = new Stone15(); addObject(stone15,433,286); } }
public class Player extends Actor { /** * Act - do whatever the Player wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { KeyboardCheck(); } public void moveUp() {setLocation (getX(),getY()-5); } public void moveDown() {setLocation (getX(),getY()+5); } public void moveLeft() {setLocation (getX()-5,getY()); } public void moveRight() {setLocation (getX()+5,getY()); } public void KeyboardCheck() {if (Greenfoot.isKeyDown("s")) if(StonesCheck(0,+5)) if(Wall1Check(0,+5)) if(Wall2Check(0,+5)) if(FunitureCheck(0,+5)) moveDown() ; if (Greenfoot.isKeyDown("w")) if(StonesCheck(0,-5)) if(Wall1Check(0,-5)) if(Wall2Check(0,-5)) if(FunitureCheck(0,-5)) moveUp() ; if (Greenfoot.isKeyDown("a")) if(StonesCheck(-5,0)) if(Wall1Check(-5,0)) if(Wall2Check(-5,0)) if(FunitureCheck(-5,0)) moveLeft(); if (Greenfoot.isKeyDown("d")) if(StonesCheck(+5,0)) if(Wall1Check(+5,0)) if(Wall2Check(+5,0)) if(FunitureCheck(+5,0)) moveRight(); } public boolean StonesCheck(int x, int y){ Actor Stones = getOneObjectAtOffset(x, y, Stones.class ); return(Stones==null); } public boolean Wall1Check(int x, int y){ Actor Wall1 = getOneObjectAtOffset(x, y, Wall1.class ); return(Wall1==null); } public boolean Wall2Check(int x, int y){ Actor Wall2= getOneObjectAtOffset(x, y, Wall2.class ); return(Wall2==null); } public boolean FunitureCheck(int x, int y){ Actor Funiture= getOneObjectAtOffset(x, y, funiture.class ); return(Funiture==null); } }