his code didn't work but this is my code
if (Greenfoot.getRandomNumber(100) < 60)
{
Bomb Bomb = new Bomb();
addObject(Bomb,getX(), getY());
}
add object is not compiling
is this what you mean
public void randomSpawn() {
if (Greenfoot.getRandomNumber(100) < 60)
{
int x=Greenfoot.getRandomNumber(getWidth());
int y=Greenfoot.getRandomNumber(getHeight());
Bomb bm=new Bomb();
addObject(bm,x,y);
}
First, it must be written in the code of the world, and second, x,y are variables, they must be declared!
x=Greenfoot.getRandomNumber(getWorld().getWidth());
y=Greenfoot.getRandomNumber(getWorld().getHeight());
Bomb bm=new Bomb();
addObject(bm,x,y);
public void act(){
randomSpawn();
}
public void randomSpawn() {
if (Greenfoot.getRandomNumber(100) < 60)
{
int x=Greenfoot.getRandomNumber(getWidth());
int y=Greenfoot.getRandomNumber(getHeight());
Bomb bm=new Bomb();
addObject(bm,x,y);
}
}