This site requires JavaScript, please enable it in your browser!
Greenfoot back
mariq_rasyid29
mariq_rasyid29 wrote ...

2021/2/27

how only in the world can play the backsound?

mariq_rasyid29 mariq_rasyid29

2021/2/27

#
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;
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();
    }
}
the world code
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);       
    }
}
Player Code
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);  
    }
        
    }
i mean if player in Clift World only can doing howl
danpost danpost

2021/2/27

#
How about just putting in player class:
if (getWorld() instanceof Clift) Greeenfoot.playSound("wolfhowl.wav");
mariq_rasyid29 mariq_rasyid29

2021/2/27

#
THX that is helping for me, in void act() right?
mariq_rasyid29 mariq_rasyid29

2021/2/27

#
ok, now how to stop it the howl?
danpost danpost

2021/2/27

#
mariq_rasyid29 wrote...
ok, now how to stop it the howl?
Put a condition on it (put it inside another if block, applying some other condition to howl). When do you want the actor to howl while in the Clift world?
mariq_rasyid29 mariq_rasyid29

2021/2/27

#
after from from this world
/**
 * Write a description of class PlaygameHome here.
 * 
 * @author (Muhamad Ariq Rasyid) 
 * @version (1.0 19 Feb 2021)
 */
public class PlaygameHome extends World
{
    /**
     * Constructor for objects of class PlaygameHome.
     * 
     */

    public PlaygameHome()
    {    
        // Create a new world with 800x600 cells with a cell size of 1x1 pixels.
        super(800, 600, 1);  
        /**
         * NPC
         */
        //WolfLink
        WolfLink wolfLink = new WolfLink();
        addObject(wolfLink,419,68);
        //Cerberus
        Cerberus cerberus = new Cerberus();
        addObject(cerberus,704,525);
        Werewolf werewolf = new Werewolf();
        addObject(werewolf,33,533);
        Ryuza ryuza = new Ryuza();
        addObject(ryuza,451,535);

        /**
         * Dens
         */
        //Player home
        Den den = new Den();
        addObject(den,65,67);
        //Pack Den
        Den2 den2 = new Den2();
        addObject(den2,764,38);

        /**
         * Player
         */
        //Player
        Player player = new Player();
        addObject(player,291,163);

        /**
         * MapsAttribute
         */
        //River
        River river = new River();
        addObject(river,238,564);
        //Stone
        Stone stone = new Stone();
        addObject(stone,386,577);
        Stone2 stone2 = new Stone2();
        addObject(stone2,384,534);
        Stone3 stone3 = new Stone3();
        addObject(stone3,351,509);
        Stone4 stone4 = new Stone4();
        addObject(stone4,304,508);
        Stone5 stone5 = new Stone5();
        addObject(stone5,254,510);
        Stone6 stone6 = new Stone6();
        addObject(stone6,205,513);
        Stone7 stone7 = new Stone7();
        addObject(stone7,155,517);
        Stone9 stone9 = new Stone9();
        addObject(stone9,106,513);
        Stone10 stone10 = new Stone10();
        addObject(stone10,86,550);
        Stone11 stone11 = new Stone11();
        addObject(stone11,86,580);
        //Trees
        Pine1 pine1 = new Pine1();
        addObject(pine1,109,19);
        Pine2 pine2 = new Pine2();
        addObject(pine2,13,48);
        //Flatfrom
        Flatfrom1 flatfrom1 = new Flatfrom1();
        addObject(flatfrom1,24,582);
        Flatfrom2 flatfrom2 = new Flatfrom2();
        addObject(flatfrom2,452,582);
        Flatfrom3 flatfrom3 = new Flatfrom3();
        addObject(flatfrom3,701,578);
        Flatfrom4 flatfrom4 = new Flatfrom4();
        addObject(flatfrom4,416,21);
        //WolfSatue
        WolfStatue wolfStatue = new WolfStatue();
        addObject(wolfStatue,426,254);
if i touching flatfrom 1 i'll be to Clift world
danpost danpost

2021/2/27

#
danpost wrote...
When do you want the actor to howl while in the Clift world?
mariq_rasyid29 mariq_rasyid29

2021/2/28

#
after im press the key "H"
danpost danpost

2021/2/28

#
mariq_rasyid29 wrote...
after im press the key "H"
Add a field to track the key state and use one for the sound:
private GreenfootSound howl = new GreenfootSound("howl.wav");
private boolean hKeyDown;
Then you can use:
if (( getWorld() instanceof Clift) && (hKeyDown != Greenfoot.isKeyDown("h")) )
{
    hKeyDown = ! hKeyDown;
    if (hKeyDown && !howl.isPlaying()) howl.play();
}
mariq_rasyid29 mariq_rasyid29

2021/2/28

#
wow, thx sir
You need to login to post a reply.