Hi!
I have been stuck on scenario 6.34 for a while and can not figure it out.... "Remove the existing loops from your setup() method. Write a new while loop that does the following: it creates 18 bubbles. The bubbles are all placed in the center of the world, and have sizes starting from 190, decreasing by 10. The last bubble has size 10. Make sure to create the largest first, and the smallest last, so that you have bubbles of sizes 190, 180, 170, etc. all lying on top of each other. Use the third constructor of Bubble - the one with two parameters. It also lets you specify the initial direction. Set the direction as follows: the first bubble has direction 0, the next 20, the next 40, etc. That is, the direction between each two bubbles increases by 20 degrees.
Here is my code:
public class Bubble extends Actor
{
private int speed;
/**
* Create a Bubble that floats, with random size and random color.
*/
public Bubble()
{
// create a random size, between 10 and 110 pixels
this(Greenfoot.getRandomNumber(100) + 10);
}
/**
* Create a Bubble that floats, with a given size and random color.
*/
public Bubble(int size)
{
GreenfootImage img = new GreenfootImage(size, size);
// create a random color, with every color channel between 30 and 230
int red = Greenfoot.getRandomNumber(200) + 30;
int green = Greenfoot.getRandomNumber(200) + 30;
int blue = Greenfoot.getRandomNumber(200) + 30;
int alpha = Greenfoot.getRandomNumber(190) + 60;
img.setColor(new Color(red, green, blue, alpha));
img.fillOval(0, 0, size-1, size-1);
setImage(img);
// random speed: 1 to 4
speed = Greenfoot.getRandomNumber(4) + 1;
}
/**
* Create a Bubble that floats, with given size and initial float direction.
*/
public Bubble(int size, int direction)
{
this(size);
setRotation(direction);
}
/**
* Float.
*/
public void act()
{
if (isAtEdge()) {
turn(180);
}
move(speed);
if (Greenfoot.getRandomNumber(100) < 50) {
turn(Greenfoot.getRandomNumber(5) - 2); // -2 to 2
}
}
}