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

2021/6/3

how to do brodcast command

1
2
hackeplayz124 hackeplayz124

2021/6/3

#
i need to know how to brodcast to other actors
Roshan123 Roshan123

2021/6/3

#
if(getWorld()!=null && getWorld().getObjects(hackepalyz.class).size()> 0)
{
  
Actor user=(Actor)getWorld().getObjects(hackeplayz.class).get(0);
user.move(72726728283);

}
  
I think you mean this?!
danpost danpost

2021/6/3

#
hackeplayz124 wrote...
i need to know how to brodcast to other actors
Need details and attempted code.
hackeplayz124 hackeplayz124

2021/6/4

#
i am making school project and it is is a flappy bird game i wan t to brodcast from the up bootom pipe to do somthig
hackeplayz124 hackeplayz124

2021/6/4

#
this is my cod for the up pipe
hackeplayz124 hackeplayz124

2021/6/4

#
 void prepare2(){
       spawnTimer = (spawnTimer+1)%720;
    if (spawnTimer%45 == 0){ 
     
     
     
     switch(getRandomNumber(0,2))
    {
        default:
            break;
        case 0:
         getWorld().addObject(new pipe_up(), 280, 3);// want to do brod cast command after this line to the other
         //pipe
            break;
        case 1:
           getWorld(). addObject(new pipe_up(), 280, 65);
            break;
        case 2:
          getWorld().addObject(new pipe_up(), 280, 33);
            break;
            }
    }    

}
hackeplayz124 hackeplayz124

2021/6/4

#
this is full code
hackeplayz124 hackeplayz124

2021/6/4

#
import greenfoot.*;

/**
 * Write a description of class pipe_up here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class pipe_up extends Actor
{
    /**
     * Act - do whatever the pipe_up wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    private int spawnTimer;
    public void act() 
    {
        kill_da_bird();
        iamcommingforu();
        prepare2();
  
   }    
   void kill_da_bird(){
       Actor bird = getOneIntersectingObject(bird.class);
    if(bird != null){
    getWorld().removeObject(bird); 
       
    }
}
void iamcommingforu(){
move(-5);
}
 void prepare2(){
       spawnTimer = (spawnTimer+1)%720;
    if (spawnTimer%45 == 0){ 
     
     
     
     switch(getRandomNumber(0,2))
    {
        default:
            break;
        case 0:
         getWorld().addObject(new pipe_up(), 280, 3);// want to do brod cast command after this line to the other
         //pipe
            break;
        case 1:
           getWorld(). addObject(new pipe_up(), 280, 65);
            break;
        case 2:
          getWorld().addObject(new pipe_up(), 280, 33);
            break;
            }
    }    

}
private int getRandomNumber(int start, int range)
{
        return start + (int)Greenfoot.getRandomNumber(range-start+1);
}

}



hackeplayz124 hackeplayz124

2021/6/4

#
for pipe up
danpost danpost

2021/6/4

#
Spawning of pipes should be done in your world class (you can have an act method there, also).
hackeplayz124 hackeplayz124

2021/6/4

#
ok
hackeplayz124 hackeplayz124

2021/6/4

#
it says getworld does not work
hackeplayz124 hackeplayz124

2021/6/4

#
in world class
hackeplayz124 hackeplayz124

2021/6/4

#
import greenfoot.*;

/**
 * Write a description of class flappyworld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class flappyworld extends World
{
   public static int Score= 0;
   flappyworld thisgame;
   private int spawnTimer;
    /**
     * Constructor for objects of class flappyworld.
     * 
     */
    public flappyworld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
         Score= 0;
        prepare();
        
    }
 
    public void act()
    {
    showText("Score: " + Score, 50, 25);
    prepare2();
    }
    void prepare2(){
       spawnTimer = (spawnTimer+1)%720;
    if (spawnTimer%45 == 0){ 
     
     
     
     switch(getRandomNumber(0,2))
    {
        default:
            break;
        case 0:
         getworld().addObject(new pipe_up(), 280, 3);// want to do brod cast command after this line to the other
         //pipe
            break;
        case 1:
           getWorld(). addObject(new pipe_up(), 280, 65);
            break;
        case 2:
          getWorld().addObject(new pipe_up(), 280, 33);
            break;
            }
    }    

}
private int getRandomNumber(int start, int range)
{
        return start + (int)Greenfoot.getRandomNumber(range-start+1);
}


    
    
    
    
    
    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {
        bird bird = new bird();
        addObject(bird, 66, 211);
        bird.setLocation(61, 193);
        line line = new line();
        addObject(line, 19, 199);
        line.setLocation(16, 194);
        line.setLocation(16, 194);
        line.setLocation(16, 194);
        line.setLocation(16, 194);
        line.setLocation(16, 194);
        line.setLocation(16, 194);
        line.setLocation(16, 194);
        line.setLocation(16, 194);
        line.setLocation(16, 194);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(7, 190);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(4, 221);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
        line.setLocation(0, 197);
    }
}
hackeplayz124 hackeplayz124

2021/6/4

#
i think i should put it in pipe up class
There are more replies on the next page.
1
2