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

2020/5/17

Terminal error :/

Weeb2.exe Weeb2.exe

2020/5/17

#
ok so i have a terminal error when my boss dies
java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:713) at greenfoot.Actor.isTouching(Actor.java:978) at Boss.IntersectingBullet(Boss.java:49) at Boss.act(Boss.java:41) at greenfoot.core.Simulation.actActor(Simulation.java:567) at greenfoot.core.Simulation.runOneLoop(Simulation.java:530) at greenfoot.core.Simulation.runContent(Simulation.java:193) at greenfoot.core.Simulation.run(Simulation.java:183)
and the code for boss
public class Boss extends EnemyCharacters
{
    private GreenfootImage Boss = new GreenfootImage("Boss.png"); 
    private GreenfootImage Boss2 = new GreenfootImage("Boss2.png");
    private GreenfootImage BossA1S1= new GreenfootImage("BossA1S1.png"); 
    private GreenfootImage BossA1S2= new GreenfootImage("BossA1S2.png");
    private GreenfootImage BossA2S1= new GreenfootImage("BossA2S1.png"); 
    private GreenfootImage BossA2S2= new GreenfootImage("BossA2S2.gif");
    private GreenfootImage BossFA1= new GreenfootImage("BossFA1.png"); 
    private GreenfootImage BossFA2= new GreenfootImage("BossFA2.png");
    private GreenfootImage BossFF= new GreenfootImage("BossFF.png");
    private GreenfootImage BossFFA1S1= new GreenfootImage("BossFFA1S1.png");
    private GreenfootImage BossFFA1S2= new GreenfootImage("BossFFA1S2.png");
    private GreenfootImage Defeat= new GreenfootImage("BossDefeated.png");
    private GreenfootImage Defeat2= new GreenfootImage("BossDefeated2.png");
    private int animatecounter;
    public int lives = 50;
    /**
     * Act - do whatever the Boss wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        NormalAnimation();
        Attack1Animation();
        Attack2Animation();
        FA();
        FF();
        FFA();
        Defeat();
        Attack2();
        FinalAttack();
        IntersectingBullet();
    }
    public void BossHealth()
    {
        lives--;
    }
    public void IntersectingBullet()
    {
        if (isTouching(Bullet.class))
        {
            removeTouching(Bullet.class);
            BossHealth();
        }
    }
    private void NormalAnimation()
    {

        if (lives == 50){
            animatecounter++;
            if (animatecounter > 5) {
                animatecounter = 0;
                if (getImage() == Boss) {
                    setImage(Boss2);
                }
                else {
                    setImage(Boss); }
            }
        }

    }

    private void Attack1Animation()
    {

        if (lives <= 49)
        {
            animatecounter++;
            if (animatecounter > 10) {
                animatecounter = 0;
                if (getImage() == BossA1S1) {
                    setImage(BossA1S2);
                }
                else {
                    setImage(BossA1S1); }
            }
        }

    }
    private void Attack2()
    {
        if (lives == 40)
        {
            setImage(BossA2S1);
        }
    }
    private void Attack2Animation()
    {
        if (lives <= 39)
        {
            animatecounter++;
            if(animatecounter > 10) 
            {
                animatecounter = 0;
                if (getImage() == BossA2S1)
                {
                    setImage(BossA2S2);
                }
                else
                {
                    setImage(BossA2S1);
                }
            }
        }
    }
    private void FinalAttack()
    {
        if (lives == 30)
        {
            setImage(BossFA1);
        }
    }
    private void FA()
    {

        if (lives <= 29)
        {
            animatecounter++;
            if(animatecounter > 10) 
            {
                animatecounter = 0;
                if (getImage() == BossFA1)
                {
                    setImage(BossFA2);
                }
                else
                {
                    setImage(BossFA1);
                }
            }
        }
    }
    public void FF()
    {
        if (lives == 20)
        {
            setImage(BossFF);
        }
    }
    private void FFA()
    {

        if (lives == 19)
        {
            animatecounter++;
            if(animatecounter > 10) 
            {
                animatecounter = 0;
                if (getImage() == BossFFA1S1)
                {
                    setImage(BossFFA1S2);
                }
                else
                {
                    setImage(BossFFA1S1);
                }
            }
        }
    }
    public void Defeat()
    {
        if (lives == 0)
        {
            animatecounter++;
            if(animatecounter > 5) 
            {
                animatecounter = 0;
                if (getImage() == Defeat)
                {
                    setImage(Defeat2);
                }
                else
                {
                    setImage(Defeat);
                }
            }
            Greenfoot.delay(5);
            getWorld().removeObject(this);
        }
        
    }
    
}
danpost danpost

2020/5/17

#
Move line 30 to end of act method.
Weeb3.exe Weeb3.exe

2020/5/18

#
ok so just lost another account to the link thing :/ anyway it worked thank you but i have another problem there is another problem with the boss i will put my code down here
private void Attack1Animation()
    {

        if (lives <= 49)
        {
            animatecounter++;
            if (animatecounter > 10) {
                animatecounter = 0;
                if (getImage() == BossA1S1) {
                    setImage(BossA1S2);
                }
                else {
                    setImage(BossA1S1); }
            }
        }

    }
    private void Attack2()
    {
        if (lives == 40)
        {
            setImage(BossA2S1);
        }
    }
    private void Attack2Animation()
    {
        if (lives <= 39)
        {
            animatecounter++;
            if(animatecounter > 10) 
            {
                animatecounter = 0;
                if (getImage() == BossA2S1)
                {
                    setImage(BossA2S2);
                }
                else
                {
                    setImage(BossA2S1);
                }
            }
        }
    }
is there anyway to make it like 50 lives - 40 lives then if its 39 lives it won't continue the animation will go to the other animation
danpost danpost

2020/5/18

#
Use 'if, else-if, else-if, etc.' structure in act the invoke the different animation methods (remove if structures from the methods being invoked).
Weeb3.exe Weeb3.exe

2020/5/18

#
like this?
public void act() 
    {
        IntersectingBullet();
        if (lives == 50)
        {
            NormalAnimation();
        }
        else if (lives == 49)
        {
            Attack1Animation();
        }
        else if (lives ==40)
        {
            Attack2Animation();
        }
        else if (lives == 30)
        {
            FA();
        }
        else if (lives == 21)
        {
            FF();
        }
        else if (lives == 20)
        {
            FFA();
        }
        else if (lives == 0)
        {
            Defeat();
        }
    }
or like this?
public void act() 
    {
        IntersectingBullet();
        if (lives == 50)
        {
            NormalAnimation();
        }
        else if (lives <= 49)
        {
            Attack1Animation();
        }
        else if (lives <=40)
        {
            Attack2Animation();
        }
        else if (lives <= 30)
        {
            FA();
        }
        else if (lives <= 21)
        {
            FF();
        }
        else if (lives <= 20)
        {
            FFA();
        }
        else if (lives == 0)
        {
            Defeat();
        }
    }
if so neither of those given above work
danpost danpost

2020/5/18

#
Use, like lives > 40, lives > 30 etc.
Weeb3.exe Weeb3.exe

2020/5/18

#
it worked thank you again :)
You need to login to post a reply.