Hello,
I need help. I am trying to add a second while loop that places 10 bubbles in a horizontal line starting at x=300, y=100 with X increasing by 40 each loop and Y being constant. I included code from the world and the bubble, but I guess I should focus on using the second bubble constructor for this. I appreciate your feedback!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | /** * Create a bubble. */ private void createBubbles() { int i = 0 ; while (i < 11 ) { Actor bubble = new Bubble(); this .addObject( new Bubble(), Greenfoot.getRandomNumber( 900 ), Greenfoot.getRandomNumber( 600 ) ); //i*107, 200); this .addObject( new Bubble(), this .getWidth() / 2 , this .getHeight() / 2 ); //addObject (new Bubble(), 0, 30, 60, 90); i = i + 1 ; } int direction = 10 ; while (i < 10 ) { if ((direction < 0 && getX() == 0 ) || (direction > 0 && getX() == getWorld().getWidth()- 1 )) direction = -direction; move(direction); } //int worldWidth = this.getWidth() / 2,; //int worldHeight = this.getHeight(); } /** * 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); } |