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

2015/10/13

level switching

hoothoot hoothoot

2015/10/13

#
I moved my level switching code to my world because it seemed appropriate, but it doesn't switch levels
public void levelchange()
    {
        if(level == 1)
        {
            if (cHlth<=4000)
            {
                level = 2;
                setBackground (image2);
            }
            else    setBackground (image1);
        }
        else if (level == 2)
        {
            if (cHlth<=4000)
            {
                setBackground (image3);
                level = 3;
            }
            else setBackground (image2);
        }
    }
danpost danpost

2015/10/13

#
hoothoot wrote...
I moved my level switching code to my world because it seemed appropriate, but it doesn't switch levels < Code Omitted >
It seems that your condition to change levels is that the value of 'cHlth' is not greater than '4000'. Unless you use a different value for each level or make the value greater than that number when changing levels, you will skip over the levels.
hoothoot hoothoot

2015/10/13

#
that's not the problem right now though, i'm just using that number as a placeholder. the problem is that the levels won't change i will have a code to set his health back to full once he hits 0
danpost danpost

2015/10/13

#
hoothoot wrote...
that's not the problem right now though, i'm just using that number as a placeholder. the problem is that the levels won't change i will have a code to set his health back to full once he hits 0
Please post the entire class code so that we can have a better idea of what is going on. Then, it might be more apparent where the issue resides.
hoothoot hoothoot

2015/10/13

#
alright,
import greenfoot.*;

/**
 * Write a description of class Galaxy here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Galaxy extends World
{
    Cell cell = new Cell();
    int cHlth = cell.getHealth();
    Bar cbar = new Bar("Cell", "Power", cHlth, cHlth);
    
    
    Gohan gohan = new Gohan();
    int gHlth = gohan.getHealth();
    Bar gbar = new Bar("Gohan", "Power", gHlth, gHlth);
    //stardest.jpg, dark alley.jpg, 
    public int level;
    private GreenfootImage image1;
    private GreenfootImage image2;
    private GreenfootImage image3;
    /**
     * Constructor for objects of class Galaxy.
     * 
     */
    public Galaxy()
    {    
        super(850, 550, 1, false); 
        prepare();
        levelchange();
    }
        private void prepare ()
    {
        addObject(gohan, 100, 425);
        addObject(cell, 725, 375);
        addObject(cbar, 625, 20);
        addObject(gbar, 170, 20);
        Fight fight = new Fight();
        addObject(fight, 450, 300);
        vs vs = new vs();
        addObject(vs, 425, 20);
    }
    public void levelchange()
    {
        if(level == 1)
        {
            if (cHlth<=4000)
            {
                level = 2;
                setBackground (image2);
            }
            else    setBackground (image1);
        }
        else if (level == 2)
        {
            if (cHlth<=4000)
            {
                setBackground (image3);
                level = 3;
            }
            else setBackground (image2);
        }
    }
}
danpost danpost

2015/10/13

#
Okay. The first problem is that you are calling 'changeLevel' from the constructor of the world -- which is executed once, before you even click on the 'Run' button. Maybe you are calling the method elsewhere, like from your Cell class -- I do not know. The other possible issue is that you are setting the value of 'cHlth' immediately after creating the Cell object that is added to the world. Its value does not appear to be updated -- at least not in the world class (again, you could be doing that from within the Cell class as well). Please post the entire Cell class code, so that these issues could be investigated.
hoothoot hoothoot

2015/10/13

#
nope that was the problem i think. i would rather not post the code as its really long and unorganized currently. i forgot to call it within another character.
You need to login to post a reply.