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

2019/6/19

Hey, want to let platforms spawn randomly in a sector

Lucky Lucky

2019/6/19

#
I started with this:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class World1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class World1 extends World
{

    /**
     * Constructor for objects of class World1.
     * 
     */
    public World1()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(500, 800, 1); 
        this.addObject( new Todesfläche(), 250, 799);
        this.addObject( new Robber(), 250, 700);
        this.addObject( new Fläche(),250, 780);
        this.addObject( new PolizeiKanone() , 250, 74);

         randomSpawn();
    }
    public void prepare()
    {
        Robber robber = new Robber();
        Todesfläche todesfläche = new Todesfläche();
        PolizeiKanone polizeikanone = new PolizeiKanone();
        Fläche fläche = new Fläche();
    }

    public void randomSpawn()
    {
    {
    if(Greenfoot.getRandomNumber(100) == 1)
    {
     
    int x = Greenfoot.getRandomNumber(400);
    int y = Greenfoot.getRandomNumber(300);
     addObject(new Fläche(), x, y);
}
    }
}
}
Super_Hippo Super_Hippo

2019/6/19

#
A method which isn't called won't do anything. You only call the randomSpawn method once when the world is created. Instead, you want to call it every act cycle, so it has to be in the act method or it has to be called from the act method.
You need to login to post a reply.