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

2015/10/27

How to drop an actor with the space button?

IsabelSchouten IsabelSchouten

2015/10/27

#
Hi everyone! We are still busy with our Chain Factor game. We have got two other problems... When a ball appears random at the top of the screen, it changes colour and number every second while it has to stay the number it got at the beginning when it appeared. Does anyone know how to keep the ball just one number and colour? Then when the ball appears, it needs to drop with amouseclick or with the space button. We now use the down arrow but it does not really work because it does not drop in one time, we need to click a few times to get it on top of another ball... Can anyone help us? I will insert our code so it might be easier for someone who wants to help us.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Bal here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bal extends Actor
{    
    /**
     * Act - do whatever the Bal wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {   
        bestuurNet();
        spawn();
    }    
    
    public void spawn(){ // Zelf
        int plaatje = Greenfoot.getRandomNumber(7);
        
        if (plaatje == 0) {
          setImage(new GreenfootImage("one.png"));  
        }
        
        if (plaatje == 1) {
          setImage(new GreenfootImage("two.png"));  
        }
        
        if (plaatje == 2) {
          setImage(new GreenfootImage("three.png"));  
        }
        
        if (plaatje == 3) {
          setImage(new GreenfootImage("four.png"));  
        }
        
        if (plaatje == 4) {
          setImage(new GreenfootImage("five.png"));  
        }
        
        if (plaatje == 5) {
          setImage(new GreenfootImage("six.png"));  
        }
        
        if (plaatje == 6) {
          setImage(new GreenfootImage("seven.png"));  
        }
    }
    
    public void bestuurNet(){ // Zelf
        int x = 0; 
        int y = 0; 
        int xN = x; 
        int yN = y;
        
        SpeelVeld speelveld = new SpeelVeld(); // Zo krijgen we toegang tot de variabelen van SpeelVeld.class

        if (Greenfoot.isKeyDown("left")) // Als pijltoets naar links ingedrukt wordt
        {
            x = getX(); // Verkrijg huidige X coördinaat
            y = getY(); // Verkrijg huidige Y coördinaat
            xN = getX() - 1; // Maak nieuwe X en trek één (1) van de huide X af
            setLocation(xN, y); // Verplaats naar nieuwe X en laat Y ongewijzigd 
        }

        if (Greenfoot.isKeyDown("right")) // Als pijltoets naar rechts ingedrukt wordt
        {
            x = getX(); // Verkrijg huidige X coördinaat
            y = getY(); // Verkrijg huidige Y coördinaat
            xN = getX() + 1; // Maak nieuwe X en tel één (1) bij de huidige X op
            setLocation(xN, y); // Verplaats naar nieuwe X en laat Y ongewijzigd 
        }
        
        if (Greenfoot.isKeyDown("down")) // Als pijltoets naar rechts ingedrukt wordt
        {
            x = getX(); // Verkrijg huidige X coördinaat
            
            if (x == 0) {
                setLocation(x, speelveld.x1);   
            }
            
            if (x == 0) { 
                setLocation(x, speelveld.x2);   
            } 
            
            if (x == 0) {
                setLocation(x, speelveld.x3);   
            } 
            
            if (x == 0) { 
                setLocation(x, speelveld.x4);   
            } 
            
            if (x == 0) { 
                setLocation(x, speelveld.x5);   
            } 
            
            if (x == 0) {
                setLocation(x, speelveld.x6);   
            } 
            
            if (x == 0) {
                setLocation(x, speelveld.x7);   
            } 
        }
    }
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Isabel Schouten & Dexter Demmink
 */

public class SpeelVeld extends World
{
    // Hoogtes van ballen
    public int x1 = 8;
    public int x2 = 8;
    public int x3 = 8;
    public int x4 = 8;
    public int x5 = 8;
    public int x6 = 8;
    public int x7 = 8;
    
    /**
     * Constructor for objects of class speelVeld.
     * Code in dit bestand is zelf bedacht.
     */
    
    public SpeelVeld() {    
        // Create a new world with 7x9 cells with a cell size of 60x60 pixels.
        super(7, 9, 60); 
        addObject(new ScoreBoard(), 3, 0);
        addObject(new Bal(), Greenfoot.getRandomNumber(6), 1);
       
        for (int i = 0; i < 15; i++) {
            
            int nummer = Greenfoot.getRandomNumber(9); // Welk nummer wordt gespawned?
            
            if (nummer == 0) { // Één wordt gespawned
                int x = Greenfoot.getRandomNumber(7); // X-waarde van bal
                
                // Zorg voor de juiste hoogte
                if (x == 0) { 
                    addObject(new One(), 0, x1);
                    x1--;
                }
                
                if (x == 1) { 
                    addObject(new One(), 1, x2);
                    x2--;
                }
                
                if (x == 2) { 
                    addObject(new One(), 2, x3);
                    x3--;
                }
                
                if (x == 3) { 
                    addObject(new One(), 3, x4);
                    x4--;
                }
                
                if (x == 4) { 
                    addObject(new One(), 4, x5);
                    x5--;
                }
                
                if (x == 5) { 
                    addObject(new One(), 5, x6);
                    x6--;
                }
                
                if (x == 6) { 
                    addObject(new One(), 6, x7);
                    x7--;
                }
                
            }
        
            if (nummer == 1) { // Twee wordt gespawned
                int x = Greenfoot.getRandomNumber(7);
                
                if (x == 0) { 
                    addObject(new Two(), 0, x1);
                    x1--;
                }
                
                if (x == 1) { 
                    addObject(new Two(), 1, x2);
                    x2--;
                }
                
                if (x == 2) { 
                    addObject(new Two(), 2, x3);
                    x3--;
                }
                
                if (x == 3) { 
                    addObject(new Two(), 3, x4);
                    x4--;
                }
                
                if (x == 4) { 
                    addObject(new Two(), 4, x5);
                    x5--;
                }
                
                if (x == 5) { 
                    addObject(new Two(), 5, x6);
                    x6--;
                }
                
                if (x == 6) { 
                    addObject(new Two(), 6, x7);
                    x7--;
                }
            }
        
            if (nummer == 2) { // Drie wordt gespawned
                int x = Greenfoot.getRandomNumber(7);
                
                if (x == 0) { 
                    addObject(new Three(), 0, x1);
                    x1--;
                }
                
                if (x == 1) { 
                    addObject(new Three(), 1, x2);
                    x2--;
                }
                
                if (x == 2) { 
                    addObject(new Three(), 2, x3);
                    x3--;
                }
                
                if (x == 3) { 
                    addObject(new Three(), 3, x4);
                    x4--;
                }
                
                if (x == 4) { 
                    addObject(new Three(), 4, x5);
                    x5--;
                }
                
                if (x == 5) { 
                    addObject(new Three(), 5, x6);
                    x6--;
                }
                
                if (x == 6) { 
                    addObject(new Three(), 6, x7);
                    x7--;
                }
            }
            
            
            if (nummer == 3) { // Vier wordt gespawned
                int x = Greenfoot.getRandomNumber(7);
                
                if (x == 0) { 
                    addObject(new Four(), 0, x1);
                    x1--;
                }
                
                if (x == 1) { 
                    addObject(new Four(), 1, x2);
                    x2--;
                }
                
                if (x == 2) { 
                    addObject(new Four(), 2, x3);
                    x3--;
                }
                
                if (x == 3) { 
                    addObject(new Four(), 3, x4);
                    x4--;
                }
                
                if (x == 4) { 
                    addObject(new Four(), 4, x5);
                    x5--;
                }
                
                if (x == 5) { 
                    addObject(new Four(), 5, x6);
                    x6--;
                }
                
                if (x == 6) { 
                    addObject(new Four(), 6, x7);
                    x7--;
                }
            }
        
            if (nummer == 4) { // Vijf wordt gespawned
                int x = Greenfoot.getRandomNumber(7);
                
                if (x == 0) { 
                    addObject(new Five(), 0, x1);
                    x1--;
                }
                
                if (x == 1) { 
                    addObject(new Five(), 1, x2);
                    x2--;
                }
                
                if (x == 2) { 
                    addObject(new Five(), 2, x3);
                    x3--;
                }
                
                if (x == 3) { 
                    addObject(new Five(), 3, x4);
                    x4--;
                }
                
                if (x == 4) { 
                    addObject(new Five(), 4, x5);
                    x5--;
                }
                
                if (x == 5) { 
                    addObject(new Five(), 5, x6);
                    x6--;
                }
                
                if (x == 6) { 
                    addObject(new Five(), 6, x7);
                    x7--;
                }
            }
        
            if (nummer == 5) { // Zes wordt gespawned
                int x = Greenfoot.getRandomNumber(7);
                
                if (x == 0) { 
                    addObject(new Six(), 0, x1);
                    x1--;
                }
                
                if (x == 1) { 
                    addObject(new Six(), 1, x2);
                    x2--;
                }
                
                if (x == 2) { 
                    addObject(new Six(), 2, x3);
                    x3--;
                }
                
                if (x == 3) { 
                    addObject(new Six(), 3, x4);
                    x4--;
                }
                
                if (x == 4) { 
                    addObject(new Six(), 4, x5);
                    x5--;
                }
                
                if (x == 5) { 
                    addObject(new Six(), 5, x6);
                    x6--;
                }
                
                if (x == 6) { 
                    addObject(new Six(), 6, x7);
                    x7--;
                }
            }
        
            if (nummer == 6) { // Zeven wordt gespawned
                int x = Greenfoot.getRandomNumber(7);
                
                if (x == 0) { 
                    addObject(new Seven(), 0, x1);
                    x1--;
                }
                
                if (x == 1) { 
                    addObject(new Seven(), 1, x2);
                    x2--;
                }
                
                if (x == 2) { 
                    addObject(new Seven(), 2, x3);
                    x3--;
                }
                
                if (x == 3) { 
                    addObject(new Seven(), 3, x4);
                    x4--;
                }
                
                if (x == 4) { 
                    addObject(new Seven(), 4, x5);
                    x5--;
                }
                
                if (x == 5) { 
                    addObject(new Seven(), 5, x6);
                    x6--;
                }
                
                if (x == 6) { 
                    addObject(new Seven(), 6, x7);
                    x7--;
                }
            }
        
            if (nummer == 7) { // Grijs wordt gespawned
                int x = Greenfoot.getRandomNumber(7);
                
                if (x == 0) { 
                    addObject(new Grijs(), 0, x1);
                    x1--;
                }
                
                if (x == 1) { 
                    addObject(new Grijs(), 1, x2);
                    x2--;
                }
                
                if (x == 2) { 
                    addObject(new Grijs(), 2, x3);
                    x3--;
                }
                
                if (x == 3) { 
                    addObject(new Grijs(), 3, x4);
                    x4--;
                }
                
                if (x == 4) { 
                    addObject(new Grijs(), 4, x5);
                    x5--;
                }
                
                if (x == 5) { 
                    addObject(new Grijs(), 5, x6);
                    x6--;
                }
                
                if (x == 6) { 
                    addObject(new Grijs(), 6, x7);
                    x7--;
                }
            }
        
            if (nummer == 8) { // Cracked wordt gespawned
                int x = Greenfoot.getRandomNumber(7);
                
                if (x == 0) { 
                    addObject(new Cracked(), 0, x1);
                    x1--;
                }
                
                if (x == 1) { 
                    addObject(new Cracked(), 1, x2);
                    x2--;
                }
                
                if (x == 2) { 
                    addObject(new Cracked(), 2, x3);
                    x3--;
                }
                
                if (x == 3) { 
                    addObject(new Cracked(), 3, x4);
                    x4--;
                }
                
                if (x == 4) { 
                    addObject(new Cracked(), 4, x5);
                    x5--;
                }
                
                if (x == 5) { 
                    addObject(new Cracked(), 5, x6);
                    x6--;
                }
                
                if (x == 6) { 
                    addObject(new Cracked(), 6, x7);
                    x7--;
                }
            }
            
        }
    }
}
Super_Hippo Super_Hippo

2015/10/27

#
Okay, a few things. To execute code just once when it is created, use a constructor:
public Bal()
{
    spawn();
}
That's your spawn method:
public void spawn()
{
    switch (Greenfoot.getRandomNumber(7))
    {
        case 0: setImage("one.png"); break;
        case 1: setImage("two.png"); break;
        case 2: setImage("three.png"); break;
        case 3: setImage("four.png"); break;
        case 4: setImage("five.png"); break;
        case 5: setImage("six.png"); break;
        case 6: setImage("seven.png"); break;
    }
}
If you would change your file names to 1.png, 2.png, 3.png, ... instead of one.png, two.png, ... then you could do this:
setImage(Greenfoot.getRandomNumber(7) + ".png");
To the control of the ball. Do I understand that correctly that a ball spawns and you can move it until it is at the bottom of the screen or another ball is below that ball and then you can control the next ball? And if you click the 'down' arrow, it should move down as far is it can?
public void bestuurNet()
{
    //move the ball to the left or right
    int dx=0;
    if (Greenfoot.isKeyDown("left")) dx--;
    if (Greenfoot.isKeyDown("right")) dx++;
    setLocation(getX()+dx, getY());
    //move back if there is already another ball or we reached the end of the world
    if (isTouching(Bal.class) || getX() < 1 || getX() > getWorld().getWidth() - 2) setLocation(getX()-dx, getY());
    
    if (Greenfoot.isKeyDown("down"))
    {
        //fall down
        while (!isTouching(Bal.class) && getY() < getWorld().getHeight() - 2)
        {
            setLocation(getX(), getY()+1);
        }
        setLocation(getX(), getY()-1);
        active = false;
    }
    else
    {
        //move down slowly
        setLocation(getX(), getY()+1);
        if (isTouching(Bal.class) || getY() > getWorld().getHeight() - 2)
        {
            setLocation(getX(), getY()-1);
            active = false;
            ((SpeelVeld) getWorld()).spawnNextBal();
        }
    }
}
Remove the 'act' method and add this line at the beginning:
public boolean active = true;
In your world class:
public void act()
{
    for (Object obj : getObjects(Bal.class))
    {
        Bal b = (Ball) obj;
        if (b.active)
        {
            b.besturrNet();
            break;
        }
    }
}

public void spawnNewBal()
{
    addObject(new Bal(), 1+Greenfoot.getRandomNumber(getWidth()-1), 0);
}
Well, maybe this helps you a bit.
IsabelSchouten IsabelSchouten

2015/10/27

#
Hi Super_Hippo, at first, thank you so much for helping, it really did help. We still got a problem with our ball (actor). When we press the downarrow it should go down all the way to the bottom or on top of the ball underneath, however, sometimes it gets stuck in the middle. It could also happen that the ball gets underneath the ball which is already placed at the bottom of the field. Do you maybe know how to get this problem solved? Thank you a lot!
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Bal here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bal extends Actor
{    
    /**
     * Act - do whatever the Bal wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */

    public boolean active = true;

    public Bal()
    {
        spawn();
    }

    public void spawn()
    {
        switch (Greenfoot.getRandomNumber(7))
        {
            case 0: setImage("one.png"); break;
            case 1: setImage("two.png"); break;
            case 2: setImage("three.png"); break;
            case 3: setImage("four.png"); break;
            case 4: setImage("five.png"); break;
            case 5: setImage("six.png"); break;
            case 6: setImage("seven.png"); break;
        }
    }

    public void bestuurNet()
    {
        //move the ball to the left or right
        int dx=0;
        if (Greenfoot.isKeyDown("left")) dx--;
        if (Greenfoot.isKeyDown("right")) dx++;
        setLocation(getX()+dx, getY());
        //move back if there is already another ball or we reached the end of the world
        //if (isTouching(Bal.class) || getX() < 1 || getX() > getWorld().getWidth() - 2) setLocation(getX()-dx, getY());

        if (Greenfoot.isKeyDown("down"))
        {
            //fall down
            while (!isTouching(Bal.class) && getY() < getWorld().getHeight() - 2)
            {
                setLocation(getX(), getY()+1);
            }
            setLocation(getX(), getY()-1);
            active = false;
            ((SpeelVeld) getWorld()).spawnNewBal();
        }
        //         else
        //         {
        //             //move down slowly
        //             setLocation(getX(), getY()+1);
        //             if (isTouching(Bal.class) || getY() > getWorld().getHeight() - 2)
        //             {
        //                 setLocation(getX(), getY()-1);
        //                 active = false;
        //                 ((SpeelVeld) getWorld()).spawnNewBal();
        //             }
        //         }
    }
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Isabel Schouten & Dexter Demmink
 */

public class SpeelVeld extends World
{
    // Hoogtes van ballen
    public int x1 = 8;
    public int x2 = 8;
    public int x3 = 8;
    public int x4 = 8;
    public int x5 = 8;
    public int x6 = 8;
    public int x7 = 8;

    /**
     * Constructor for objects of class speelVeld.
     * Code in dit bestand is zelf bedacht.
     */
    public void act()
    {
        for (Object obj : getObjects(Bal.class))
        {
            Bal b = (Bal) obj;
            if (b.active)
            {
                b.bestuurNet();
                break;
            }
        }
    }

    public void spawnNewBal()
    {
        addObject(new Bal(), 1+Greenfoot.getRandomNumber(getWidth()-1), 1);
    }

    public SpeelVeld() {    
        // Create a new world with 7x9 cells with a cell size of 60x60 pixels.
        super(7, 9, 60); 
        addObject(new ScoreBoard(), 3, 0);
        addObject(new Bal(), Greenfoot.getRandomNumber(6), 1);

        for (int i = 0; i < 15; i++) {

            int nummer = Greenfoot.getRandomNumber(9); // Welk nummer wordt gespawned?

            if (nummer == 0) { // Één wordt gespawned
                int x = Greenfoot.getRandomNumber(7); // X-waarde van bal

                // Zorg voor de juiste hoogte
                if (x == 0) { 
                    addObject(new One(), 0, x1);
                    x1--;
                }

                if (x == 1) { 
                    addObject(new One(), 1, x2);
                    x2--;
                }

                if (x == 2) { 
                    addObject(new One(), 2, x3);
                    x3--;
                }

                if (x == 3) { 
                    addObject(new One(), 3, x4);
                    x4--;
                }

                if (x == 4) { 
                    addObject(new One(), 4, x5);
                    x5--;
                }

                if (x == 5) { 
                    addObject(new One(), 5, x6);
                    x6--;
                }

                if (x == 6) { 
                    addObject(new One(), 6, x7);
                    x7--;
                }

            }

            if (nummer == 1) { // Twee wordt gespawned
                int x = Greenfoot.getRandomNumber(7);

                if (x == 0) { 
                    addObject(new Two(), 0, x1);
                    x1--;
                }

                if (x == 1) { 
                    addObject(new Two(), 1, x2);
                    x2--;
                }

                if (x == 2) { 
                    addObject(new Two(), 2, x3);
                    x3--;
                }

                if (x == 3) { 
                    addObject(new Two(), 3, x4);
                    x4--;
                }

                if (x == 4) { 
                    addObject(new Two(), 4, x5);
                    x5--;
                }

                if (x == 5) { 
                    addObject(new Two(), 5, x6);
                    x6--;
                }

                if (x == 6) { 
                    addObject(new Two(), 6, x7);
                    x7--;
                }
            }

            if (nummer == 2) { // Drie wordt gespawned
                int x = Greenfoot.getRandomNumber(7);

                if (x == 0) { 
                    addObject(new Three(), 0, x1);
                    x1--;
                }

                if (x == 1) { 
                    addObject(new Three(), 1, x2);
                    x2--;
                }

                if (x == 2) { 
                    addObject(new Three(), 2, x3);
                    x3--;
                }

                if (x == 3) { 
                    addObject(new Three(), 3, x4);
                    x4--;
                }

                if (x == 4) { 
                    addObject(new Three(), 4, x5);
                    x5--;
                }

                if (x == 5) { 
                    addObject(new Three(), 5, x6);
                    x6--;
                }

                if (x == 6) { 
                    addObject(new Three(), 6, x7);
                    x7--;
                }
            }

            if (nummer == 3) { // Vier wordt gespawned
                int x = Greenfoot.getRandomNumber(7);

                if (x == 0) { 
                    addObject(new Four(), 0, x1);
                    x1--;
                }

                if (x == 1) { 
                    addObject(new Four(), 1, x2);
                    x2--;
                }

                if (x == 2) { 
                    addObject(new Four(), 2, x3);
                    x3--;
                }

                if (x == 3) { 
                    addObject(new Four(), 3, x4);
                    x4--;
                }

                if (x == 4) { 
                    addObject(new Four(), 4, x5);
                    x5--;
                }

                if (x == 5) { 
                    addObject(new Four(), 5, x6);
                    x6--;
                }

                if (x == 6) { 
                    addObject(new Four(), 6, x7);
                    x7--;
                }
            }

            if (nummer == 4) { // Vijf wordt gespawned
                int x = Greenfoot.getRandomNumber(7);

                if (x == 0) { 
                    addObject(new Five(), 0, x1);
                    x1--;
                }

                if (x == 1) { 
                    addObject(new Five(), 1, x2);
                    x2--;
                }

                if (x == 2) { 
                    addObject(new Five(), 2, x3);
                    x3--;
                }

                if (x == 3) { 
                    addObject(new Five(), 3, x4);
                    x4--;
                }

                if (x == 4) { 
                    addObject(new Five(), 4, x5);
                    x5--;
                }

                if (x == 5) { 
                    addObject(new Five(), 5, x6);
                    x6--;
                }

                if (x == 6) { 
                    addObject(new Five(), 6, x7);
                    x7--;
                }
            }

            if (nummer == 5) { // Zes wordt gespawned
                int x = Greenfoot.getRandomNumber(7);

                if (x == 0) { 
                    addObject(new Six(), 0, x1);
                    x1--;
                }

                if (x == 1) { 
                    addObject(new Six(), 1, x2);
                    x2--;
                }

                if (x == 2) { 
                    addObject(new Six(), 2, x3);
                    x3--;
                }

                if (x == 3) { 
                    addObject(new Six(), 3, x4);
                    x4--;
                }

                if (x == 4) { 
                    addObject(new Six(), 4, x5);
                    x5--;
                }

                if (x == 5) { 
                    addObject(new Six(), 5, x6);
                    x6--;
                }

                if (x == 6) { 
                    addObject(new Six(), 6, x7);
                    x7--;
                }
            }

            if (nummer == 6) { // Zeven wordt gespawned
                int x = Greenfoot.getRandomNumber(7);

                if (x == 0) { 
                    addObject(new Seven(), 0, x1);
                    x1--;
                }

                if (x == 1) { 
                    addObject(new Seven(), 1, x2);
                    x2--;
                }

                if (x == 2) { 
                    addObject(new Seven(), 2, x3);
                    x3--;
                }

                if (x == 3) { 
                    addObject(new Seven(), 3, x4);
                    x4--;
                }

                if (x == 4) { 
                    addObject(new Seven(), 4, x5);
                    x5--;
                }

                if (x == 5) { 
                    addObject(new Seven(), 5, x6);
                    x6--;
                }

                if (x == 6) { 
                    addObject(new Seven(), 6, x7);
                    x7--;
                }
            }

            if (nummer == 7) { // Grijs wordt gespawned
                int x = Greenfoot.getRandomNumber(7);

                if (x == 0) { 
                    addObject(new Grijs(), 0, x1);
                    x1--;
                }

                if (x == 1) { 
                    addObject(new Grijs(), 1, x2);
                    x2--;
                }

                if (x == 2) { 
                    addObject(new Grijs(), 2, x3);
                    x3--;
                }

                if (x == 3) { 
                    addObject(new Grijs(), 3, x4);
                    x4--;
                }

                if (x == 4) { 
                    addObject(new Grijs(), 4, x5);
                    x5--;
                }

                if (x == 5) { 
                    addObject(new Grijs(), 5, x6);
                    x6--;
                }

                if (x == 6) { 
                    addObject(new Grijs(), 6, x7);
                    x7--;
                }
            }

            if (nummer == 8) { // Cracked wordt gespawned
                int x = Greenfoot.getRandomNumber(7);

                if (x == 0) { 
                    addObject(new Cracked(), 0, x1);
                    x1--;
                }

                if (x == 1) { 
                    addObject(new Cracked(), 1, x2);
                    x2--;
                }

                if (x == 2) { 
                    addObject(new Cracked(), 2, x3);
                    x3--;
                }

                if (x == 3) { 
                    addObject(new Cracked(), 3, x4);
                    x4--;
                }

                if (x == 4) { 
                    addObject(new Cracked(), 4, x5);
                    x5--;
                }

                if (x == 5) { 
                    addObject(new Cracked(), 5, x6);
                    x6--;
                }

                if (x == 6) { 
                    addObject(new Cracked(), 6, x7);
                    x7--;
                }
            }

        }
    }
}
IsabelSchouten IsabelSchouten

2015/10/27

#
And if you have an instagram account, do you want to follow @dexterdemmink. He is a friend of mine and would like to get some friends who like to work with green foot.
Super_Hippo Super_Hippo

2015/10/28

#
You could change the '- 2' to '- 1' or remove it at all to let it fall to the bottom.
            while (!isTouching(Bal.class) && getY() < getWorld().getHeight())// - 2)
            {
                setLocation(getX(), getY()+1);
            }
I don't have Instagram, sorry.
You need to login to post a reply.